Skip to contentSkip to conversation

sched_{set, get}attr: Call the syscalls via tst_syscall()

PATCH In review Wake Liu via ltp 2 participants 5 messages Oct 4 – Oct 14

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sched_{set, get}attr: Call the syscalls via tst_syscall()

From: Wake Liu <[email protected]>

The sched_setattr01, sched_setattr02, sched_getattr01 and sched_getattr02 tests call sched_setattr() and sched_getattr(). Depending on the libc, these names resolve either to the lapi fallback wrappers or to the libc functions.

On Bionic, sched_setattr() and sched_getattr() were added in API level
37. When LTP is built against such headers, the test binaries link against the libc symbols. They then fail to start on devices with an older libc:

CANNOT LINK EXECUTABLE "sched_setattr01": cannot locate symbol "sched_setattr"

These are syscall tests, so call the syscalls directly through tst_syscall(), as SAFE_SCHED_SETATTR() already does. This makes the tests independent of libc support, and tst_syscall() reports TCONF if the kernel lacks the syscalls. As a bonus, the negative tests no longer pass NULL to the libc wrappers, whose attr parameter is declared nonnull by glibc and Bionic.

---
 testcases/kernel/syscalls/sched_getattr/sched_getattr01.c | 3 ++-
 testcases/kernel/syscalls/sched_getattr/sched_getattr02.c | 7 ++++---
 testcases/kernel/syscalls/sched_setattr/sched_setattr01.c | 5 +++--
 testcases/kernel/syscalls/sched_setattr/sched_setattr02.c | 3 ++-
 4 files changed, 11 insertions(+), 7 deletions(-)
testcases/kernel/syscalls/sched_getattr/sched_getattr01.c +2 -1
index bd05164ca..2f3bd4a9c 100644
@@ -51,7 +51,8 @@ static void run(void)
 
 	memset((void *)read_attr, 0, sizeof(*read_attr));
 
-	TST_EXP_PASS(sched_getattr(0, read_attr, sizeof(*read_attr), 0),
+	TST_EXP_PASS(tst_syscall(__NR_sched_getattr, 0, read_attr,
+				 sizeof(*read_attr), 0),
 		     "sched_getattr() with valid parameters");
 	if (!TST_PASS)
 		return;
testcases/kernel/syscalls/sched_getattr/sched_getattr02.c +4 -3
index e2c0bf43b..a70b8ac5c 100644
@@ -40,9 +40,10 @@ static void verify_sched_getattr(unsigned int n)
 {
 	struct test_case *tc = &tcase[n];
 
-	TST_EXP_FAIL(sched_getattr(*(tc->pid), tc->attr, tc->size, tc->flags),
-				 tc->exp_errno, "sched_getattr(%d, ..., %d, %d)", *tc->pid,
-				 tc->size, tc->flags);
+	TST_EXP_FAIL(tst_syscall(__NR_sched_getattr, *tc->pid, tc->attr,
+				 tc->size, tc->flags),
+		     tc->exp_errno, "sched_getattr(%d, ..., %d, %d)",
+		     *tc->pid, tc->size, tc->flags);
 }
 
 static void setup(void)
testcases/kernel/syscalls/sched_setattr/sched_setattr01.c +3 -2
index 93e532774..b1fe93735 100644
@@ -51,12 +51,13 @@ static void run(void)
 {
 	struct sched_attr read_attr = { .size = sizeof(read_attr) };
 
-	TST_EXP_PASS(sched_setattr(0, &attr, 0),
+	TST_EXP_PASS(tst_syscall(__NR_sched_setattr, 0, &attr, 0),
 		     "sched_setattr() with valid parameters");
 	if (!TST_PASS)
 		return;
 
-	if (sched_getattr(0, &read_attr, sizeof(read_attr), 0) == -1) {
+	if (tst_syscall(__NR_sched_getattr, 0, &read_attr,
+			sizeof(read_attr), 0) == -1) {
 		tst_res(TFAIL | TERRNO, "sched_getattr() failed");
 		return;
 	}
testcases/kernel/syscalls/sched_setattr/sched_setattr02.c +2 -1
index 9f1ccfcd0..462f182a5 100644
@@ -123,7 +123,8 @@ static void verify_sched_setattr(unsigned int n)
 	 */
 	attr_small.size = SCHED_ATTR_SIZE_VER0 - 1;
 
-	TST_EXP_FAIL(sched_setattr(pid, target_attr, tc->flags),
+	TST_EXP_FAIL(tst_syscall(__NR_sched_setattr, pid, target_attr,
+				 tc->flags),
 		     tc->exp_errno, "%s", tc->desc);
 }
 
Signature · 5 lines
2.56.0.rc1.315.gc6ed9934b7-goog


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

Hi Wake,

Quoted 1 line · Wake Liu

sched_{set, get}attr: Call the syscalls via tst_syscall()

Verdict - Reviewed

---
Note:

The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.

Regards,
LTP AI Reviewer

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw

Hi Wake,

Quoted 1 line

I think I reply to the wrong email. Forget about this RB.

The sched_setattr definition falls back to syscall(__NR_sched_setattr, ..) if it's not present inside the system and if you see that error, it's probably because you are linking to the wrong library locally.

Please confirm it so this patch will be rejected.

--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#4 lore raw

Hi Andrea,

Quoted 3 lines

The sched_setattr definition falls back to syscall(__NR_sched_setattr, ..) if it's not present inside the system and if you see that error, it's probably because you are linking to the wrong library locally.

You're right. The binaries were built against a newer Bionic, which provides sched_setattr() and sched_getattr(), and then run on devices with an older libc that lacks them. That's a mismatch in our build and test setup, not something the tests should work around.

Please drop this patch, and sorry for the noise.

Thanks,
Wake

Quoted 17 lines · Andrea Cervesato

Hi Wake,

Quoted 1 line

I think I reply to the wrong email. Forget about this RB.

The sched_setattr definition falls back to syscall(__NR_sched_setattr, ..) if it's not present inside the system and if you see that error, it's probably because you are linking to the wrong library locally.

Please confirm it so this patch will be rejected.

--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]

Signature · 5 lines
Best Regards,
Wake Liu

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp