sched_setscheduler: test SCHED_RESET_ON_FORK
PATCH v2 1/1 sched_setscheduler: test SCHED_RESET_ON_FORK
--- runtest/syscalls | 1 + .../syscalls/sched_setscheduler/.gitignore | 1 + .../sched_setscheduler/sched_setscheduler04.c | 73 +++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 testcases/kernel/syscalls/sched_setscheduler/sched_setscheduler04.c
runtest/syscalls +1 -0
@@ -1204,6 +1204,7 @@ sched_getscheduler02 sched_getscheduler02 sched_setscheduler01 sched_setscheduler01 sched_setscheduler02 sched_setscheduler02 sched_setscheduler03 sched_setscheduler03 +sched_setscheduler04 sched_setscheduler04 sched_yield01 sched_yield01
testcases/kernel/syscalls/sched_setscheduler/.gitignore +0 -0
--- a/testcases/kernel/syscalls/sched_sets cheduler/.gitignore
+++ b/testcases/kernel/syscalls/sched_setscheduler/.gitignore @@ -1,3 +1,4 @@
/sched_setscheduler01
/sched_setscheduler02
/sched_setscheduler03
+/sched_setscheduler04
testcases/kernel/syscalls/sched_setscheduler/sched_setscheduler04.c new file +24 -0
@@ -0,0 +1,73 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2022 Federico Bonfiglio <[email protected]> +*/ + +/* +* [Description] +* +* Testcases that test if sched_setscheduler with flag +* SCHED_RESET_ON_FORK restores children policy to +* SCHED_NORMAL. +* +*/ + +#define _GNU_SOURCE +#include <stdio.h> +#include <stdlib.h> +#include <sched.h> +#include <linux/sched.h> + +#include "tst_test.h" +#include "tst_sched.h" + +struct test_c
ase_t {
+ int policy;
+ char *desc;
+};
+
+static struct test_case_t cases[] = {
+ {
+ .policy = SCHED_FIFO,
+ .desc = "SCHED_FIFO"
+ },
+ {
+ .policy = SCHED_RR,
+ .desc = "SCHED_RR"
+ }
+};
+
+static void test_reset_on_fork(unsigned int i)
+{
+ struct sched_variant *tv = &sched_variants[tst_variant];
+ struct test_case_t *tc = &cases[i];
+
+ tst_res(TINFO, "Testing %s variant", tv->desc);
+ tst_res(TINFO, "Testing %s policy", tc->desc);
+
+ struct sched_param param = { .sched_priority = 1 };
+
+ tv->sched_setscheduler(getpid(), tc->policy | SCHED_RESET_ON_FORK, ¶m);
+
+ pid_t pid = SAFE_FORK();
+
+ if (!pid == 0) {
+ if (sched_getscheduler(pid) == SCHED_NORMAL)
+ tst_res(TPASS, "Policy reset to SCHED_NORMAL");
+ else
+ tst_res(TFAIL, "Policy NOT reset to SCHED_NORMAL");
+ }
+
+ tst_reap_children();
+}
+
+static struct tst_test test = {
+ .forks_child = 1,
+ .caps = (struct tst_cap[]) {
+ TST_CAP(TST_CAP_REQ, CAP_SYS_NICE)
+ },
+ .test_variants = ARRAY_SIZE(sched_variants),
+ .tcnt = ARRAY_SIZE(cases),
+ .test = test_reset_on_fork
+};
+
--
2.38.1
Signature · 2 lines
-- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Quoted 19 lines
testcases/kernel/syscalls/sched_setscheduler/sched_setscheduler04.c new file +19
-0+/* +* [Description] +* +* Testcases that test if sched_setscheduler with flag +* SCHED_RESET_ON_FORK restores children policy to +* SCHED_NORMAL. +* +*/ + +#define _GNU_SOURCE +#include <stdio.h> +#include <stdlib.h> +#include <sched.h> +#include <linux/sched.h> + +#include "tst_test.h" +#include "tst_sched.h" + +struct test_c
Quoted 1 line
ase_t{
^
Looks like the patch was mangled by your email client.
Quoted 12 lines
(quoted diff) +12
-0+ int policy; + char *desc; +}; + +static struct test_case_t cases[] = { + { + .policy = SCHED_FIFO, + .desc = "SCHED_FIFO" + }, + { + .policy = SCHED_RR, + .desc = "SCHED_RR"
Review
Quoted 10 lines
(quoted diff) +10
-0+ } +}; + +static void test_reset_on_fork(unsigned int i) +{ + struct sched_variant *tv = &sched_variants[tst_variant]; + struct test_case_t *tc = &cases[i]; + + tst_res(TINFO, "Testing %s variant", tv->desc); + tst_res(TINFO, "Testing %s policy", tc->desc);
Why two messages? Why not just:
tst_res(TINFO, "Testing %s variant %s policy", tv->desc, tc->desc);
Review
Quoted 7 lines
(quoted diff) +7
-0+ struct sched_param param = { .sched_priority = 1 }; + + tv->sched_setscheduler(getpid(), tc->policy | SCHED_RESET_ON_FORK, ¶m); + + pid_t pid = SAFE_FORK(); + + if (!pid == 0) {
^
Uff, please don't.
That's just if (pid)
Review
Quoted 4 lines
(quoted diff) +4
-0+ if (sched_getscheduler(pid) == SCHED_NORMAL) + tst_res(TPASS, "Policy reset to SCHED_NORMAL"); + else + tst_res(TFAIL, "Policy NOT reset to SCHED_NORMAL");
We should check that the priority was reset to DEFAULT_PRIO as well.
Review
Quoted 3 lines
(quoted diff) +3
-0+ } + + tst_reap_children();
There is no need to call this as long as the child exits normally the test library will pick it up.
Quoted 24 lines
(quoted diff) +12
-1+} + +static struct tst_test test = { + .forks_child = 1, + .caps = (struct tst_cap[]) { + TST_CAP(TST_CAP_REQ, CAP_SYS_NICE) + }, + .test_variants = ARRAY_SIZE(sched_variants), + .tcnt = ARRAY_SIZE(cases), + .test = test_reset_on_fork +}; + --2.38.1
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hello,
I still can't apply this. The problem does not seem to be the PGP signature though.
Quoted 27 lines · Federico Bonfiglio via ltp
[[PGP Signed Part:Undecided]]Signed-off-by Federico Bonfiglio <[email protected]>--- runtest/syscalls | 1 + .../syscalls/sched_setscheduler/.gitignore | 1 + .../sched_setscheduler/sched_setscheduler04.c | 73 +++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 testcases/kernel/syscalls/sched_setscheduler/sched_setscheduler04.cruntest/syscalls +1
-0@@ -1204,6 +1204,7 @@ sched_getscheduler02 sched_getscheduler02 sched_setscheduler01 sched_setscheduler01 sched_setscheduler02 sched_setscheduler02 sched_setscheduler03 sched_setscheduler03 +sched_setscheduler04 sched_setscheduler04 sched_yield01 sched_yield01testcases/kernel/syscalls/sched_setscheduler/.gitignore +0
-1--- a/testcases/kernel/syscalls/sched_setscheduler/.gitignore
+++ b/testcases/kernel/syscalls/sched_setscheduler/.gitignore
testcases/kernel/syscalls/sched_setscheduler/.gitignore line 4
Quoted 4 lines
testcases/kernel/syscalls/sched_setscheduler/.gitignore +1
-0@@ -1,3 +1,4 @@ /sched_setscheduler01 /sched_setscheduler02 /sched_setscheduler03 +/sched_setscheduler04
No new line at end of file or is it missing from the patch?
Quoted 30 lines
testcases/kernel/syscalls/sched_setscheduler/sched_setscheduler04.c new file +24
-0@@ -0,0 +1,73 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2022 Federico Bonfiglio <[email protected]> +*/ + +/* +* [Description] +* +* Testcases that test if sched_setscheduler with flag +* SCHED_RESET_ON_FORK restores children policy to +* SCHED_NORMAL. +* +*/ + +#define _GNU_SOURCE +#include <stdio.h> +#include <stdlib.h> +#include <sched.h> +#include <linux/sched.h> + +#include "tst_test.h" +#include "tst_sched.h" + +struct test_c
Quoted 1 line
ase_t{
Random new line in the patch, stops it from applying.
Quoted 34 lines
testcases/kernel/syscalls/sched_setscheduler/sched_setscheduler04.c new file +33
-0+int policy; +char *desc; +}; + +static struct test_case_t cases[] = { + { + .policy =SCHED_FIFO , + .desc ="SCHED_FIFO" + }, + { + .policy =SCHED_RR , + .desc ="SCHED_RR" + } +}; + +static void test_reset_on_fork (unsigned int i) +{ +struct sched_variant *tv = &sched_variants[tst_variant]; +struct test_case_t *tc = &cases[i]; + +tst_res (TINFO ,"Testing %s variant" , tv->desc); +tst_res (TINFO ,"Testing %s policy" , tc->desc); + +struct sched_param param = { .sched_priority =1 }; + + tv->sched_setscheduler (getpid (), tc->policy |SCHED_RESET_ON_FORK , ¶m); + +pid_t pid =SAFE_FORK (); + +if (!pid ==0 ) { +if (sched_getscheduler (pid) ==SCHED_NORMAL ) +tst_res (TPASS ,"Policy reset to SCHED_NORMAL" ); +else
testcases/kernel/syscalls/sched_setscheduler/sched_setscheduler04.c
Quoted 10 lines
testcases/kernel/syscalls/sched_setscheduler/sched_setscheduler04.c new file +10
-0+tst_res (TFAIL ,"Policy NOT reset to SCHED_NORMAL" ); + } + +tst_reap_children (); +} + +static struct tst_test test = { + .forks_child =1 , + .caps = (struct tst_cap []) { +TST_CAP (TST_CAP_REQ ,CAP_SYS_NICE )
Another random new line, cuts off the end of the patch.
Quoted 12 lines
testcases/kernel/syscalls/sched_setscheduler/sched_setscheduler04.c new file +6
-1+ }, + .test_variants = ARRAY_SIZE(sched_variants), + .tcnt = ARRAY_SIZE(cases), + .test = test_reset_on_fork +}; + --2.38.1
[2. application/pgp-keys; publickey - Federico Bonfiglio - e96ee84c.asc]...
[[End of PGP Signed Part]]
Signature · 5 lines
Thank you, Richard. -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v3 1/1 sched_setscheduler04.c: Test SCHED_RESET_ON_FORK
In reply to Federico Bonfiglio via ltp--- include/lapi/capability.h | 4 + runtest/syscalls | 1 + .../syscalls/sched_setscheduler/.gitignore | 1 + .../sched_setscheduler/sched_setscheduler04.c | 78 +++++++++++++++++++ 4 files changed, 84 insertions(+) create mode 100644 testcases/kernel/syscalls/sched_setscheduler/sched_setscheduler04.c
include/lapi/capability.h +4 -0
@@ -36,6 +36,10 @@# define CAP_SYS_ADMIN 21#endif +#ifndef CAP_SYS_NICE +# define CAP_SYS_NICE 23 +#endif +#ifndef CAP_SYS_TIME # define CAP_SYS_TIME 25#endif
runtest/syscalls +1 -0
@@ -1228,6 +1228,7 @@ sched_getscheduler02 sched_getscheduler02 sched_setscheduler01 sched_setscheduler01 sched_setscheduler02 sched_setscheduler02 sched_setscheduler03 sched_setscheduler03 +sched_setscheduler04 sched_setscheduler04 sched_yield01 sched_yield01
testcases/kernel/syscalls/sched_setscheduler/.gitignore +1 -0
@@ -1,3 +1,4 @@ /sched_setscheduler01 /sched_setscheduler02 /sched_setscheduler03 +/sched_setscheduler04
testcases/kernel/syscalls/sched_setscheduler/sched_setscheduler04.c new file +78 -0
78 lines not on this page · raw message
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Richard Palethorpe
AppliedRe: [LTP] [PATCH v3] sched_setscheduler04.c: Test SCHED_RESET_ON_FORK
Hello,
Merged, thanks!
Quoted 134 lines · Wei Gao via ltp
Signed-off-by Federico Bonfiglio <[email protected]>Signed-off-by Wei Gao <[email protected]>--- include/lapi/capability.h | 4 + runtest/syscalls | 1 + .../syscalls/sched_setscheduler/.gitignore | 1 + .../sched_setscheduler/sched_setscheduler04.c | 78 +++++++++++++++++++ 4 files changed, 84 insertions(+) create mode 100644 testcases/kernel/syscalls/sched_setscheduler/sched_setscheduler04.cinclude/lapi/capability.h +4
-0@@ -36,6 +36,10 @@# define CAP_SYS_ADMIN 21#endif +#ifndef CAP_SYS_NICE +# define CAP_SYS_NICE 23 +#endif +#ifndef CAP_SYS_TIME # define CAP_SYS_TIME 25#endif runtest/syscalls +1
-0@@ -1228,6 +1228,7 @@ sched_getscheduler02 sched_getscheduler02 sched_setscheduler01 sched_setscheduler01 sched_setscheduler02 sched_setscheduler02 sched_setscheduler03 sched_setscheduler03 +sched_setscheduler04 sched_setscheduler04 sched_yield01 sched_yield01testcases/kernel/syscalls/sched_setscheduler/.gitignore +1
-0@@ -1,3 +1,4 @@ /sched_setscheduler01 /sched_setscheduler02 /sched_setscheduler03 +/sched_setscheduler04diff --git
a/testcases/kernel/syscalls/sched_setscheduler/sched_setscheduler04.cb/testcases/kernel/syscalls/sched_setscheduler/sched_setscheduler04.cnew file mode 100644
index 000000000..828d1ec09testcases/kernel/syscalls/sched_setscheduler/sched_setscheduler04.c new file +78
-0@@ -0,0 +1,78 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2022 Federico Bonfiglio <[email protected]> +*/ + +/* +* [Description] +* +* Testcases that test if sched_setscheduler with flag +* SCHED_RESET_ON_FORK restores children policy to +* SCHED_NORMAL. +* +*/ + +#define _GNU_SOURCE +#include <stdio.h> +#include <stdlib.h> +#include <sched.h> +#include <linux/sched.h> + +#include "tst_test.h" +#include "tst_sched.h" + +struct test_case_t { +int policy; +char *desc; +}; + +static struct test_case_t cases[] = { + { + .policy =SCHED_FIFO , + .desc ="SCHED_FIFO" + }, + { + .policy =SCHED_RR , + .desc ="SCHED_RR" + } +}; + +static void test_reset_on_fork (unsigned int i) +{ +struct sched_variant *tv = &sched_variants[tst_variant]; +struct test_case_t *tc = &cases[i]; + +tst_res (TINFO ,"Testing %s variant %s policy" , tv->desc, tc->desc); + +struct sched_param param = { .sched_priority =10 }; + + tv->sched_setscheduler (getpid (), tc->policy |SCHED_RESET_ON_FORK , ¶m); + +pid_t pid =SAFE_FORK (); + +if (pid) { +if (sched_getscheduler (pid) ==SCHED_NORMAL ) +tst_res (TPASS ,"Policy reset to SCHED_NORMAL" ); +else +tst_res (TFAIL ,"Policy NOT reset to SCHED_NORMAL" ); + +sched_getparam (pid, ¶m); + +/* kernel will return sched_priority 0 if task is not RT Policy */ +if (param.sched_priority ==0 ) +tst_res (TPASS ,"Priority set to 0" ); +else +tst_res (TFAIL ,"Priority not set to 0" ); + } +} + +static struct tst_test test = { + .forks_child =1 , + .caps = (struct tst_cap []) { +TST_CAP (TST_CAP_REQ ,CAP_SYS_NICE ), + {} + }, + .test_variants =ARRAY_SIZE (sched_variants), + .tcnt =ARRAY_SIZE (cases), + .test = test_reset_on_fork, +};Signature · 1 line
2.35.3
Signature · 5 lines
Thank you, Richard. -- Mailing list info: https://lists.linux.it/listinfo/ltp