diff mbox series

[v2,2/2] syscalls/nice07: new test for nice()

Message ID 20221020125747.231509-3-zhaogongyi@huawei.com
State Rejected
Headers show
Series new test for nice() | expand

Commit Message

Zhao Gongyi Oct. 20, 2022, 12:57 p.m. UTC
Verify that the errno is zero 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/nice07.c   | 46 +++++++++++++++++++++++
 3 files changed, 48 insertions(+)
 create mode 100644 testcases/kernel/syscalls/nice/nice07.c

--
2.17.1
diff mbox series

Patch

diff --git a/runtest/syscalls b/runtest/syscalls
index 557c946ec..7a425439a 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -903,6 +903,7 @@  nice03 nice03
 nice04 nice04
 nice05 nice05
 nice06 nice06
+nice07 nice07

 open01 open01
 open01A symlink01 -T open01
diff --git a/testcases/kernel/syscalls/nice/.gitignore b/testcases/kernel/syscalls/nice/.gitignore
index c96064cdf..a92595f2a 100644
--- a/testcases/kernel/syscalls/nice/.gitignore
+++ b/testcases/kernel/syscalls/nice/.gitignore
@@ -4,3 +4,4 @@ 
 /nice04
 /nice05
 /nice06
+/nice07
diff --git a/testcases/kernel/syscalls/nice/nice07.c b/testcases/kernel/syscalls/nice/nice07.c
new file mode 100644
index 000000000..8d098de60
--- /dev/null
+++ b/testcases/kernel/syscalls/nice/nice07.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 zero 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,
+};