public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/2] syscalls/nice05: new test for nice()
@ 2022-10-14  3:56 Zhao Gongyi via ltp
  2022-10-14  3:56 ` [LTP] [PATCH 2/2] syscalls/nice06: " Zhao Gongyi via ltp
  2022-10-24 11:07 ` [LTP] [PATCH 1/2] syscalls/nice05: " Richard Palethorpe
  0 siblings, 2 replies; 5+ messages in thread
From: Zhao Gongyi via ltp @ 2022-10-14  3:56 UTC (permalink / raw)
  To: ltp

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


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

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [LTP] [PATCH 2/2] syscalls/nice06: new test for nice()
  2022-10-14  3:56 [LTP] [PATCH 1/2] syscalls/nice05: new test for nice() Zhao Gongyi via ltp
@ 2022-10-14  3:56 ` Zhao Gongyi via ltp
  2022-10-24 11:20   ` Richard Palethorpe
  2022-10-24 11:07 ` [LTP] [PATCH 1/2] syscalls/nice05: " Richard Palethorpe
  1 sibling, 1 reply; 5+ messages in thread
From: Zhao Gongyi via ltp @ 2022-10-14  3:56 UTC (permalink / raw)
  To: ltp

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


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

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [LTP] [PATCH 1/2] syscalls/nice05: new test for nice()
  2022-10-14  3:56 [LTP] [PATCH 1/2] syscalls/nice05: new test for nice() Zhao Gongyi via ltp
  2022-10-14  3:56 ` [LTP] [PATCH 2/2] syscalls/nice06: " Zhao Gongyi via ltp
@ 2022-10-24 11:07 ` Richard Palethorpe
  1 sibling, 0 replies; 5+ messages in thread
From: Richard Palethorpe @ 2022-10-24 11:07 UTC (permalink / raw)
  To: Zhao Gongyi; +Cc: ltp

Hello,

Zhao Gongyi via ltp <ltp@lists.linux.it> writes:

> 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

05 has already been taken. Also this test is very similar to
nice01. Maybe it could be added to that?

>
>  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));

Why not use one of the TST_EXP* macros?

> +	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);

Again, could use TST_EXP* macro. Also just checking TST_ERR is not
strictly correct.

> +}
> +
> +static struct tst_test test = {
> +	.test_all = verify_nice,
> +	.needs_root = 1,
> +};
> --
> 2.17.1

-- 
Thank you,
Richard.

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [LTP] [PATCH 2/2] syscalls/nice06: new test for nice()
  2022-10-14  3:56 ` [LTP] [PATCH 2/2] syscalls/nice06: " Zhao Gongyi via ltp
@ 2022-10-24 11:20   ` Richard Palethorpe
  0 siblings, 0 replies; 5+ messages in thread
From: Richard Palethorpe @ 2022-10-24 11:20 UTC (permalink / raw)
  To: Zhao Gongyi; +Cc: ltp

Hello,

Zhao Gongyi via ltp <ltp@lists.linux.it> writes:

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

This does not require a separate test and EPERM is the only errno that
is listed in the man page.

-- 
Thank you,
Richard.

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [LTP] [PATCH 2/2] syscalls/nice06: new test for nice()
@ 2022-10-26  8:21 zhaogongyi via ltp
  0 siblings, 0 replies; 5+ messages in thread
From: zhaogongyi via ltp @ 2022-10-26  8:21 UTC (permalink / raw)
  To: rpalethorpe@suse.de; +Cc: ltp@lists.linux.it

Hi,

> 
> Hello,
> 
> Zhao Gongyi via ltp <ltp@lists.linux.it> writes:
> 
> > Verify that the errno is nonzero when callling of nice legitimately
> > return -1.
> 
> This does not require a separate test and EPERM is the only errno that is
> listed in the man page.
> 

This testcase is intentionally designed to test the errno is zero when callling of nice legitimately return -1,

For the other testcases of nice, return -1 will report TBROK, shall we need to add a test to check it ? 

Regards,
Gongyi

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-10-26  8:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-14  3:56 [LTP] [PATCH 1/2] syscalls/nice05: new test for nice() Zhao Gongyi via ltp
2022-10-14  3:56 ` [LTP] [PATCH 2/2] syscalls/nice06: " Zhao Gongyi via ltp
2022-10-24 11:20   ` Richard Palethorpe
2022-10-24 11:07 ` [LTP] [PATCH 1/2] syscalls/nice05: " Richard Palethorpe
  -- strict thread matches above, loose matches on Subject: below --
2022-10-26  8:21 [LTP] [PATCH 2/2] syscalls/nice06: " zhaogongyi via ltp

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox