[LTP] [PATCH 1/2] syscalls/nice05: new test for nice()
Zhao Gongyi
zhaogongyi@huawei.com
Fri Oct 14 05:56:14 CEST 2022
Verify that user of root can decrease the nice value of
the process successfully by passing a lower increment
value (< min. applicable limits) to nice() system call.
Signed-off-by: Zhao Gongyi <zhaogongyi@huawei.com>
---
runtest/syscalls | 1 +
testcases/kernel/syscalls/nice/.gitignore | 1 +
testcases/kernel/syscalls/nice/nice05.c | 54 +++++++++++++++++++++++
3 files changed, 56 insertions(+)
create mode 100644 testcases/kernel/syscalls/nice/nice05.c
diff --git a/runtest/syscalls b/runtest/syscalls
index bd74373a4..7db399375 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -902,6 +902,7 @@ nice01 nice01
nice02 nice02
nice03 nice03
nice04 nice04
+nice05 nice05
open01 open01
open01A symlink01 -T open01
diff --git a/testcases/kernel/syscalls/nice/.gitignore b/testcases/kernel/syscalls/nice/.gitignore
index 9d7a1bb43..58d64779e 100644
--- a/testcases/kernel/syscalls/nice/.gitignore
+++ b/testcases/kernel/syscalls/nice/.gitignore
@@ -2,3 +2,4 @@
/nice02
/nice03
/nice04
+/nice05
diff --git a/testcases/kernel/syscalls/nice/nice05.c b/testcases/kernel/syscalls/nice/nice05.c
new file mode 100644
index 000000000..85f10fadf
--- /dev/null
+++ b/testcases/kernel/syscalls/nice/nice05.c
@@ -0,0 +1,54 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright(c) 2022 Huawei Technologies Co., Ltd
+ * Author: Zhao Gongyi <zhaogongyi@huawei.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Verify that user of root can decrease the nice value of
+ * the process successfully by passing a lower increment
+ * value (< min. applicable limits) to nice() system call.
+ */
+#include <unistd.h>
+#include "tst_test.h"
+
+#define NICEINC -50
+#define MIN_PRIO -20
+#define DEFAULT_PRIO 0
+
+static void verify_nice(void)
+{
+ int new_nice;
+
+ TEST(nice(NICEINC));
+ if (TST_RET == -1) {
+ tst_res(TFAIL | TTERRNO, "nice(%d) returned -1", NICEINC);
+ return;
+ }
+
+ if (TST_ERR) {
+ tst_res(TFAIL | TTERRNO, "nice(%d) failed", NICEINC);
+ return;
+ }
+
+ new_nice = SAFE_GETPRIORITY(PRIO_PROCESS, 0);
+
+ if (new_nice != MIN_PRIO) {
+ tst_res(TFAIL,
+ "Process priority %i, expected %i", new_nice, MIN_PRIO);
+ return;
+ }
+
+ tst_res(TPASS, "nice(%d) passed", NICEINC);
+
+ TEST(nice(DEFAULT_PRIO));
+ if (TST_ERR)
+ tst_brk(TBROK | TTERRNO, "nice(%d) failed", DEFAULT_PRIO);
+}
+
+static struct tst_test test = {
+ .test_all = verify_nice,
+ .needs_root = 1,
+};
--
2.17.1
More information about the ltp
mailing list