[LTP] [PATCH] syscalls/nice: Adjust the expected priority after calling nice()

Zhao Gongyi zhaogongyi@huawei.com
Thu Aug 25 14:50:54 CEST 2022


If we run test as nice -n -10 ./nice01, it will fail and report:

nice01.c:37: TFAIL: nice(-12) returned -20, expected -22: SUCCESS (0)

for nice01.c/nice02.c: correct log info.

Signed-off-by: Zhao Gongyi <zhaogongyi@huawei.com>
---
 testcases/kernel/syscalls/nice/nice01.c | 14 +++++++++-----
 testcases/kernel/syscalls/nice/nice02.c |  2 +-
 testcases/kernel/syscalls/nice/nice03.c |  7 +++++--
 3 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/testcases/kernel/syscalls/nice/nice01.c b/testcases/kernel/syscalls/nice/nice01.c
index ee360bfbf..876246180 100644
--- a/testcases/kernel/syscalls/nice/nice01.c
+++ b/testcases/kernel/syscalls/nice/nice01.c
@@ -18,19 +18,23 @@
 #include "tst_test.h"

 #define	NICEINC		-12
+#define MIN_PRIO	-20

 static void verify_nice(void)
 {
 	int new_nice;
 	int orig_nice;
+	int exp_nice;

 	orig_nice = SAFE_GETPRIORITY(PRIO_PROCESS, 0);

 	TEST(nice(NICEINC));

-	if (TST_RET != (orig_nice + NICEINC)) {
+	exp_nice = MAX(MIN_PRIO, (orig_nice + NICEINC));
+
+	if (TST_RET != exp_nice) {
 		tst_res(TFAIL | TTERRNO, "nice(%d) returned %li, expected %i",
-			NICEINC, TST_RET, orig_nice + NICEINC);
+			NICEINC, TST_RET, exp_nice);
 		return;
 	}

@@ -41,9 +45,9 @@ static void verify_nice(void)

 	new_nice = SAFE_GETPRIORITY(PRIO_PROCESS, 0);

-	if (new_nice != (orig_nice + NICEINC)) {
+	if (new_nice != exp_nice) {
 		tst_res(TFAIL, "Process priority %i, expected %i",
-		        new_nice, orig_nice + NICEINC);
+				new_nice, orig_nice + NICEINC);
 		return;
 	}

@@ -51,7 +55,7 @@ static void verify_nice(void)

 	TEST(nice(-NICEINC));
 	if (TST_ERR)
-		tst_brk(TBROK | TTERRNO, "nice(-NICEINC) failed");
+		tst_brk(TBROK | TTERRNO, "nice(%d) failed", -NICEINC);
 }

 static struct tst_test test = {
diff --git a/testcases/kernel/syscalls/nice/nice02.c b/testcases/kernel/syscalls/nice/nice02.c
index 1c7103758..b08e1d751 100644
--- a/testcases/kernel/syscalls/nice/nice02.c
+++ b/testcases/kernel/syscalls/nice/nice02.c
@@ -50,7 +50,7 @@ static void verify_nice(void)

 	TEST(nice(DEFAULT_PRIO));
 	if (TST_ERR)
-		tst_brk(TBROK | TTERRNO, "nice(-NICEINC) failed");
+		tst_brk(TBROK | TTERRNO, "nice(%d) failed", DEFAULT_PRIO);
 }

 static struct tst_test test = {
diff --git a/testcases/kernel/syscalls/nice/nice03.c b/testcases/kernel/syscalls/nice/nice03.c
index 8198f2cf0..061592e6c 100644
--- a/testcases/kernel/syscalls/nice/nice03.c
+++ b/testcases/kernel/syscalls/nice/nice03.c
@@ -19,11 +19,13 @@
 #include "tst_test.h"

 #define	NICEINC	2
+#define MAX_PRIO 19

 static void nice_test(void)
 {
 	int new_nice;
 	int orig_nice;
+	int exp_nice;

 	orig_nice = SAFE_GETPRIORITY(PRIO_PROCESS, 0);

@@ -40,10 +42,11 @@ static void nice_test(void)
 	}

 	new_nice = SAFE_GETPRIORITY(PRIO_PROCESS, 0);
+	exp_nice = MIN(MAX_PRIO, (orig_nice + NICEINC));

-	if (new_nice != (orig_nice + NICEINC)) {
+	if (new_nice != exp_nice) {
 		tst_res(TFAIL, "Process priority %i, expected %i",
-		        new_nice, orig_nice + NICEINC);
+				new_nice, exp_nice);
 		return;
 	}

--
2.17.1



More information about the ltp mailing list