[LTP] [PATCH 2/2] syscalls/nice06: new test for nice()

Zhao Gongyi zhaogongyi@huawei.com
Fri Oct 14 05:56:15 CEST 2022


Verify that the errno is nonzero when callling of nice
legitimately return -1.

Signed-off-by: Zhao Gongyi <zhaogongyi@huawei.com>
---
 runtest/syscalls                          |  1 +
 testcases/kernel/syscalls/nice/.gitignore |  1 +
 testcases/kernel/syscalls/nice/nice06.c   | 46 +++++++++++++++++++++++
 3 files changed, 48 insertions(+)
 create mode 100644 testcases/kernel/syscalls/nice/nice06.c

diff --git a/runtest/syscalls b/runtest/syscalls
index 7db399375..12bf94bff 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -903,6 +903,7 @@ nice02 nice02
 nice03 nice03
 nice04 nice04
 nice05 nice05
+nice06 nice06

 open01 open01
 open01A symlink01 -T open01
diff --git a/testcases/kernel/syscalls/nice/.gitignore b/testcases/kernel/syscalls/nice/.gitignore
index 58d64779e..c96064cdf 100644
--- a/testcases/kernel/syscalls/nice/.gitignore
+++ b/testcases/kernel/syscalls/nice/.gitignore
@@ -3,3 +3,4 @@
 /nice03
 /nice04
 /nice05
+/nice06
diff --git a/testcases/kernel/syscalls/nice/nice06.c b/testcases/kernel/syscalls/nice/nice06.c
new file mode 100644
index 000000000..b4a6fb446
--- /dev/null
+++ b/testcases/kernel/syscalls/nice/nice06.c
@@ -0,0 +1,46 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright(c) 2022 Huawei Technologies Co., Ltd
+ * Author: Zhao Gongyi <zhaogongyi@huawei.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Verify that the errno is nonzero when callling of nice
+ * legitimately return -1.
+ */
+#include <unistd.h>
+#include "tst_test.h"
+
+static void verify_nice(void)
+{
+	int orig_nice;
+	int niceinc;
+
+	orig_nice = SAFE_GETPRIORITY(PRIO_PROCESS, 0);
+	niceinc = -1 - orig_nice;
+
+	TEST(nice(niceinc));
+	if (TST_RET != -1) {
+		tst_res(TFAIL | TTERRNO,
+			"nice(%d) returned %ld", niceinc, TST_RET);
+		return;
+	}
+
+	if (TST_ERR) {
+		tst_res(TFAIL | TTERRNO, "nice(%d) failed", niceinc);
+		return;
+	}
+
+	tst_res(TPASS, "nice(%d) passed", niceinc);
+
+	TEST(nice(-niceinc));
+	if (TST_ERR)
+		tst_brk(TBROK | TTERRNO, "nice(%d) failed", -niceinc);
+}
+
+static struct tst_test test = {
+	.test_all = verify_nice,
+	.needs_root = 1,
+};
--
2.17.1



More information about the ltp mailing list