* [LTP] [PATCH v2] syscalls/sched_setscheduler04: new test for sched_setscheduler()
@ 2022-11-16 2:16 Zhao Gongyi via ltp
2022-11-28 12:38 ` Richard Palethorpe
0 siblings, 1 reply; 2+ messages in thread
From: Zhao Gongyi via ltp @ 2022-11-16 2:16 UTC (permalink / raw)
To: ltp
Verify that the scheduling policy and parameters are in fact per-thread
attributes on Linux:
1. Specifying pid as 0 will operate on the attributes of the calling thread
2. The value returned from a call to gettid(2) can be passed in the argument
pid.
3. Passing the value returned from a call to getpid(2) will operate on the
attributes of the main thread of the thread group
Signed-off-by: Zhao Gongyi <zhaogongyi@huawei.com>
---
runtest/syscalls | 1 +
.../syscalls/sched_setscheduler/.gitignore | 1 +
.../syscalls/sched_setscheduler/Makefile | 2 +
.../sched_setscheduler/sched_setscheduler04.c | 101 ++++++++++++++++++
4 files changed, 105 insertions(+)
create mode 100644 testcases/kernel/syscalls/sched_setscheduler/sched_setscheduler04.c
diff --git a/runtest/syscalls b/runtest/syscalls
index 3dc6fa397..ff516af3d 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -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
diff --git a/testcases/kernel/syscalls/sched_setscheduler/.gitignore b/testcases/kernel/syscalls/sched_setscheduler/.gitignore
index aa8ad9695..1b8860d2c 100644
--- a/testcases/kernel/syscalls/sched_setscheduler/.gitignore
+++ b/testcases/kernel/syscalls/sched_setscheduler/.gitignore
@@ -1,3 +1,4 @@
/sched_setscheduler01
/sched_setscheduler02
/sched_setscheduler03
+/sched_setscheduler04
diff --git a/testcases/kernel/syscalls/sched_setscheduler/Makefile b/testcases/kernel/syscalls/sched_setscheduler/Makefile
index 044619fb8..e3d54e33e 100644
--- a/testcases/kernel/syscalls/sched_setscheduler/Makefile
+++ b/testcases/kernel/syscalls/sched_setscheduler/Makefile
@@ -3,6 +3,8 @@
top_srcdir ?= ../../../..
+sched_setscheduler04: CFLAGS += -pthread
+
include $(top_srcdir)/include/mk/testcases.mk
include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/syscalls/sched_setscheduler/sched_setscheduler04.c b/testcases/kernel/syscalls/sched_setscheduler/sched_setscheduler04.c
new file mode 100644
index 000000000..38f5750ba
--- /dev/null
+++ b/testcases/kernel/syscalls/sched_setscheduler/sched_setscheduler04.c
@@ -0,0 +1,101 @@
+// 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 scheduling policy and parameters are in fact per-thread
+ * attributes on Linux:
+ * 1. Specifying pid as 0 will operate on the attributes of the calling thread.
+ * 2. The value returned from a call to gettid(2) can be passed in the argument
+ * pid.
+ * 3. Passing the value returned from a call to getpid(2) will operate on the
+ * attributes of the main thread of the thread group.
+ */
+#include "tst_test.h"
+#include "lapi/syscalls.h"
+#include "tst_safe_pthread.h"
+#include <pthread.h>
+#include <linux/capability.h>
+
+static struct sched_param param;
+static volatile int sched_prio;
+static pid_t pid;
+
+#define ORG_POLICY SCHED_OTHER
+#define EXP_POLICY SCHED_FIFO
+
+static void verify_sched_setscheduler(pid_t tid)
+{
+ int new_policy;
+ pid_t threadid = tst_syscall(__NR_gettid);
+
+ tst_res(TINFO, "Setting of tid: %d", threadid);
+
+ param.sched_priority = sched_prio;
+ if (sched_setscheduler(tid, EXP_POLICY, ¶m)) {
+ tst_brk(TBROK | TERRNO,
+ "sched_setscheduler(%d, %d, ...) failed",
+ tid, EXP_POLICY);
+ }
+
+ tst_res(TINFO, "Getting and checking of tid: %d", threadid);
+
+ new_policy = sched_getscheduler(threadid);
+ if (new_policy < 0)
+ tst_brk(TBROK | TERRNO, "sched_getscheduler() failed");
+
+ if (sched_getparam(threadid, ¶m) != 0)
+ tst_brk(TBROK | TERRNO, "sched_getparam() failed");
+
+ TST_EXP_EQ_LI(param.sched_priority, sched_prio);
+ TST_EXP_EQ_LI(new_policy, EXP_POLICY);
+}
+
+static void *thread_func(LTP_ATTRIBUTE_UNUSED void *arg)
+{
+ pid_t threadid = tst_syscall(__NR_gettid);
+
+ sched_prio++;
+ verify_sched_setscheduler(0);
+ sched_prio++;
+ verify_sched_setscheduler(threadid);
+
+ return NULL;
+}
+
+static void run(void)
+{
+ pthread_t tid;
+
+ sched_prio = sched_get_priority_min(EXP_POLICY);
+
+ sched_prio++;
+ verify_sched_setscheduler(pid);
+
+ SAFE_PTHREAD_CREATE(&tid, NULL, thread_func, NULL);
+ SAFE_PTHREAD_JOIN(tid, NULL);
+}
+
+static void setup(void)
+{
+ pid = getpid();
+
+ if (sched_setscheduler(pid, ORG_POLICY, ¶m)) {
+ tst_brk(TBROK | TERRNO,
+ "sched_setscheduler(%d, %d, ...) failed",
+ pid, ORG_POLICY);
+ }
+}
+
+static struct tst_test test = {
+ .setup = setup,
+ .test_all = run,
+ .caps = (struct tst_cap[]) {
+ TST_CAP(TST_CAP_REQ, CAP_SYS_NICE),
+ {}
+ }
+};
--
2.17.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [LTP] [PATCH v2] syscalls/sched_setscheduler04: new test for sched_setscheduler()
2022-11-16 2:16 [LTP] [PATCH v2] syscalls/sched_setscheduler04: new test for sched_setscheduler() Zhao Gongyi via ltp
@ 2022-11-28 12:38 ` Richard Palethorpe
0 siblings, 0 replies; 2+ messages in thread
From: Richard Palethorpe @ 2022-11-28 12:38 UTC (permalink / raw)
To: Zhao Gongyi; +Cc: ltp
Hello,
Zhao Gongyi via ltp <ltp@lists.linux.it> writes:
> Verify that the scheduling policy and parameters are in fact per-thread
> attributes on Linux:
> 1. Specifying pid as 0 will operate on the attributes of the calling thread
> 2. The value returned from a call to gettid(2) can be passed in the argument
> pid.
> 3. Passing the value returned from a call to getpid(2) will operate on the
> attributes of the main thread of the thread group
>
> Signed-off-by: Zhao Gongyi <zhaogongyi@huawei.com>
> ---
> runtest/syscalls | 1 +
> .../syscalls/sched_setscheduler/.gitignore | 1 +
> .../syscalls/sched_setscheduler/Makefile | 2 +
> .../sched_setscheduler/sched_setscheduler04.c | 101 ++++++++++++++++++
> 4 files changed, 105 insertions(+)
> create mode 100644 testcases/kernel/syscalls/sched_setscheduler/sched_setscheduler04.c
>
> diff --git a/runtest/syscalls b/runtest/syscalls
> index 3dc6fa397..ff516af3d 100644
> --- a/runtest/syscalls
> +++ b/runtest/syscalls
> @@ -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
>
> diff --git a/testcases/kernel/syscalls/sched_setscheduler/.gitignore b/testcases/kernel/syscalls/sched_setscheduler/.gitignore
> index aa8ad9695..1b8860d2c 100644
> --- a/testcases/kernel/syscalls/sched_setscheduler/.gitignore
> +++ b/testcases/kernel/syscalls/sched_setscheduler/.gitignore
> @@ -1,3 +1,4 @@
> /sched_setscheduler01
> /sched_setscheduler02
> /sched_setscheduler03
> +/sched_setscheduler04
> diff --git a/testcases/kernel/syscalls/sched_setscheduler/Makefile b/testcases/kernel/syscalls/sched_setscheduler/Makefile
> index 044619fb8..e3d54e33e 100644
> --- a/testcases/kernel/syscalls/sched_setscheduler/Makefile
> +++ b/testcases/kernel/syscalls/sched_setscheduler/Makefile
> @@ -3,6 +3,8 @@
>
> top_srcdir ?= ../../../..
>
> +sched_setscheduler04: CFLAGS += -pthread
> +
> include $(top_srcdir)/include/mk/testcases.mk
>
> include $(top_srcdir)/include/mk/generic_leaf_target.mk
> diff --git a/testcases/kernel/syscalls/sched_setscheduler/sched_setscheduler04.c b/testcases/kernel/syscalls/sched_setscheduler/sched_setscheduler04.c
> new file mode 100644
> index 000000000..38f5750ba
> --- /dev/null
> +++ b/testcases/kernel/syscalls/sched_setscheduler/sched_setscheduler04.c
> @@ -0,0 +1,101 @@
> +// 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 scheduling policy and parameters are in fact per-thread
> + * attributes on Linux:
No it doesn't. This test would still pass if calling sched_setscheduler
changed the priority of every thread on the system.
NACK.
--
Thank you,
Richard.
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-11-28 13:32 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-16 2:16 [LTP] [PATCH v2] syscalls/sched_setscheduler04: new test for sched_setscheduler() Zhao Gongyi via ltp
2022-11-28 12:38 ` Richard Palethorpe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox