Skip to contentSkip to conversation

syscalls/sched_*: convert to new API and handle ENOSYS errno

PATCH New Alexey Kodanev 2 participants 23 messages Jul 20, 2021 Library code

lore
Share & tools
lore
#0 lore raw

cover syscalls/sched_*: convert to new API and handle ENOSYS errno

The patch-set introduced new tst_sched_* wrappers to handle ENOSYS error that can be returned by libc (musl [1]). In that particular case the wrapper uses syscall directly to test the kernel anyway.

[1]: https://git.musl-libc.org/cgit/musl/commit/?id=1e21e78bf7a5

Alexey Kodanev (16):
lib/tst_sched: add ltp tst_sched_*() syscalls/sched_getparam01: use tst_sched_*() syscalls/sched_getparam03: use tst_sched_*() syscalls/sched_setparam01: convert to new API syscalls/sched_setparam02: convert to new API syscalls/sched_setparam03: convert to new API syscalls/sched_setparam04: convert to new API syscalls/sched_setparam05: convert to new API syscalls/sched_rr_get_interval01: use tst_sched_*() syscalls/sched_rr_get_interval02: use tst_sched_*() syscalls/sched_rr_get_interval03: use tst_sched_*() syscalls/sched_setscheduler01: convert to new API syscalls/sched_setscheduler02: convert to new API syscalls/sched_setscheduler03: use tst_sched_*() syscalls/sched_getscheduler01: convert to new API syscalls/sched_getscheduler02: convert to new API

 include/tst_sched.h                           |  16 ++
 lib/tst_sched.c                               |  36 +++
 .../sched_getparam/sched_getparam01.c         |   6 +-
 .../sched_getparam/sched_getparam03.c         |   4 +-
 .../sched_getscheduler/sched_getscheduler01.c | 141 +++---------
 .../sched_getscheduler/sched_getscheduler02.c | 104 ++-------
 .../sched_rr_get_interval01.c                 |   4 +-
 .../sched_rr_get_interval02.c                 |   4 +-
 .../sched_rr_get_interval03.c                 |   4 +-
 .../sched_setparam/sched_setparam01.c         | 135 ++---------
 .../sched_setparam/sched_setparam02.c         | 195 +++-------------
 .../sched_setparam/sched_setparam03.c         | 215 ++++--------------
 .../sched_setparam/sched_setparam04.c         | 161 +++----------
 .../sched_setparam/sched_setparam05.c         | 186 +++------------
 .../sched_setscheduler/sched_setscheduler01.c | 171 ++++----------
 .../sched_setscheduler/sched_setscheduler02.c | 154 +++----------
 .../sched_setscheduler/sched_setscheduler03.c |  10 +-
 17 files changed, 345 insertions(+), 1201 deletions(-)
 create mode 100644 include/tst_sched.h
 create mode 100644 lib/tst_sched.c
Signature · 1 line
2.25.1
#1 lore raw

cover syscalls/sched_*: convert to new API and handle ENOSYS errno

Hi!

Quoted 3 lines

The patch-set introduced new tst_sched_* wrappers to handle ENOSYS error that can be returned by libc (musl [1]). In that particular case the wrapper uses syscall directly to test the kernel anyway.

Can't we use the test_variants to test both the kernel and libc calls instead?

Quoted 47 lines

[1]: https://git.musl-libc.org/cgit/musl/commit/?id=1e21e78bf7a5

Alexey Kodanev (16):
lib/tst_sched: add ltp tst_sched_*() syscalls/sched_getparam01: use tst_sched_*() syscalls/sched_getparam03: use tst_sched_*() syscalls/sched_setparam01: convert to new API syscalls/sched_setparam02: convert to new API syscalls/sched_setparam03: convert to new API syscalls/sched_setparam04: convert to new API syscalls/sched_setparam05: convert to new API syscalls/sched_rr_get_interval01: use tst_sched_*() syscalls/sched_rr_get_interval02: use tst_sched_*() syscalls/sched_rr_get_interval03: use tst_sched_*() syscalls/sched_setscheduler01: convert to new API syscalls/sched_setscheduler02: convert to new API syscalls/sched_setscheduler03: use tst_sched_*() syscalls/sched_getscheduler01: convert to new API syscalls/sched_getscheduler02: convert to new API

 include/tst_sched.h                           |  16 ++
 lib/tst_sched.c                               |  36 +++
 .../sched_getparam/sched_getparam01.c         |   6 +-
 .../sched_getparam/sched_getparam03.c         |   4 +-
 .../sched_getscheduler/sched_getscheduler01.c | 141 +++---------
 .../sched_getscheduler/sched_getscheduler02.c | 104 ++-------
 .../sched_rr_get_interval01.c                 |   4 +-
 .../sched_rr_get_interval02.c                 |   4 +-
 .../sched_rr_get_interval03.c                 |   4 +-
 .../sched_setparam/sched_setparam01.c         | 135 ++---------
 .../sched_setparam/sched_setparam02.c         | 195 +++-------------
 .../sched_setparam/sched_setparam03.c         | 215 ++++--------------
 .../sched_setparam/sched_setparam04.c         | 161 +++----------
 .../sched_setparam/sched_setparam05.c         | 186 +++------------
 .../sched_setscheduler/sched_setscheduler01.c | 171 ++++----------
 .../sched_setscheduler/sched_setscheduler02.c | 154 +++----------
 .../sched_setscheduler/sched_setscheduler03.c |  10 +-
 17 files changed, 345 insertions(+), 1201 deletions(-)
 create mode 100644 include/tst_sched.h
 create mode 100644 lib/tst_sched.c
Signature · 5 lines
2.25.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 2 lines
Cyril Hrubis
[email protected]
#2 lore raw

cover syscalls/sched_*: convert to new API and handle ENOSYS errno

Hi Cyril,

Quoted 7 lines · Cyril Hrubis

Hi!

Quoted 3 lines

The patch-set introduced new tst_sched_* wrappers to handle ENOSYS error that can be returned by libc (musl [1]). In that particular case the wrapper uses syscall directly to test the kernel anyway.

Can't we use the test_variants to test both the kernel and libc calls instead?

With glibc it seems it would be just a redundant work to call both variants, wouldn't it?

BTW, sched_rr_get_interval* tests already using tst_variants, adding more variants will double them too, right?

Quoted 49 lines
Quoted 48 lines

[1]: https://git.musl-libc.org/cgit/musl/commit/?id=1e21e78bf7a5

Alexey Kodanev (16):
lib/tst_sched: add ltp tst_sched_*() syscalls/sched_getparam01: use tst_sched_*() syscalls/sched_getparam03: use tst_sched_*() syscalls/sched_setparam01: convert to new API syscalls/sched_setparam02: convert to new API syscalls/sched_setparam03: convert to new API syscalls/sched_setparam04: convert to new API syscalls/sched_setparam05: convert to new API syscalls/sched_rr_get_interval01: use tst_sched_*() syscalls/sched_rr_get_interval02: use tst_sched_*() syscalls/sched_rr_get_interval03: use tst_sched_*() syscalls/sched_setscheduler01: convert to new API syscalls/sched_setscheduler02: convert to new API syscalls/sched_setscheduler03: use tst_sched_*() syscalls/sched_getscheduler01: convert to new API syscalls/sched_getscheduler02: convert to new API

 include/tst_sched.h                           |  16 ++
 lib/tst_sched.c                               |  36 +++
 .../sched_getparam/sched_getparam01.c         |   6 +-
 .../sched_getparam/sched_getparam03.c         |   4 +-
 .../sched_getscheduler/sched_getscheduler01.c | 141 +++---------
 .../sched_getscheduler/sched_getscheduler02.c | 104 ++-------
 .../sched_rr_get_interval01.c                 |   4 +-
 .../sched_rr_get_interval02.c                 |   4 +-
 .../sched_rr_get_interval03.c                 |   4 +-
 .../sched_setparam/sched_setparam01.c         | 135 ++---------
 .../sched_setparam/sched_setparam02.c         | 195 +++-------------
 .../sched_setparam/sched_setparam03.c         | 215 ++++--------------
 .../sched_setparam/sched_setparam04.c         | 161 +++----------
 .../sched_setparam/sched_setparam05.c         | 186 +++------------
 .../sched_setscheduler/sched_setscheduler01.c | 171 ++++----------
 .../sched_setscheduler/sched_setscheduler02.c | 154 +++----------
 .../sched_setscheduler/sched_setscheduler03.c |  10 +-
 17 files changed, 345 insertions(+), 1201 deletions(-)
 create mode 100644 include/tst_sched.h
 create mode 100644 lib/tst_sched.c
Signature · 5 lines
2.25.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw

cover syscalls/sched_*: convert to new API and handle ENOSYS errno

Hi!

Quoted 9 lines
Quoted 6 lines
Quoted 3 lines

The patch-set introduced new tst_sched_* wrappers to handle ENOSYS error that can be returned by libc (musl [1]). In that particular case the wrapper uses syscall directly to test the kernel anyway.

Can't we use the test_variants to test both the kernel and libc calls instead?

With glibc it seems it would be just a redundant work to call both variants, wouldn't it?

I do not think so, since the libc wrappers may be more complex than just a syscall(__NR_foo, ...). At least recently the libc variants are switching between foo and foo_time64 syscall variants and convert the timespecs accordingly.

Quoted 2 lines

BTW, sched_rr_get_interval* tests already using tst_variants, adding more variants will double them too, right?

That's true and this makes things slightly more complicated. But as these test just calls a few syscalls and check return values I doubt that doubling the test matrix would be measureable in the test runtime.

Signature · 2 lines
Cyril Hrubis
[email protected]
#4 lore raw

cover syscalls/sched_*: convert to new API and handle ENOSYS errno

In reply to Alexey Kodanev

Hi!

Quoted 2 lines

BTW, sched_rr_get_interval* tests already using tst_variants, adding more variants will double them too, right?

Actually not, since we do run the test for both the libc sched_rr_get_interval and for all possible syscalls variants we don't have to touch these tests at all.

Signature · 2 lines
Cyril Hrubis
[email protected]
#5 lore raw

cover syscalls/sched_*: convert to new API and handle ENOSYS errno

Quoted 7 lines · Cyril Hrubis

Hi!

Quoted 2 lines

BTW, sched_rr_get_interval* tests already using tst_variants, adding more variants will double them too, right?

Actually not, since we do run the test for both the libc sched_rr_get_interval and for all possible syscalls variants we don't have to touch these tests at all.

sched_rr_get_interval works with musl, the one which returns ENOSYS is sched_setscheduler() there, in setup().

#6 lore raw

cover syscalls/sched_*: convert to new API and handle ENOSYS errno

Hi!

Quoted 9 lines
Quoted 6 lines
Quoted 2 lines

BTW, sched_rr_get_interval* tests already using tst_variants, adding more variants will double them too, right?

Actually not, since we do run the test for both the libc sched_rr_get_interval and for all possible syscalls variants we don't have to touch these tests at all.

sched_rr_get_interval works with musl, the one which returns ENOSYS is sched_setscheduler() there, in setup().

Since this is setup we may as well switch to syscall() in the test setup and be done with it, we are not testing sched_setscheduler() in these tests.

Signature · 2 lines
Cyril Hrubis
[email protected]
#7 lore raw

PATCH 1/16 lib/tst_sched: add ltp tst_sched_*()

In reply to Alexey Kodanev

The new tst_sched_*() invoke libc variant first, and if ENOSYS errno has been returned, tries to invoke syscall directly.

musl implementation returns ENOSYS for some sched_*() functions due to commit 1e21e78bf7a5 ("add support for thread scheduling (POSIX TPS option)").

---
 include/tst_sched.h | 16 ++++++++++++++++
 lib/tst_sched.c     | 36 ++++++++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+)
 create mode 100644 include/tst_sched.h
 create mode 100644 lib/tst_sched.c
include/tst_sched.h new file +16 -0
new file mode 100644
index 000000000..0e5d61344
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (c) 2021, BELLSOFT. All rights reserved.
+ */
+
+#ifndef TST_SCHED_H_
+#define TST_SCHED_H_
+
+#include <sched.h>
+
+int tst_sched_setparam(pid_t pid, const struct sched_param *param);
+int tst_sched_getparam(pid_t pid, struct sched_param *param);
+int tst_sched_setscheduler(pid_t pid, int policy, const struct sched_param *param);
+int tst_sched_getscheduler(pid_t pid);
+
+#endif /* TST_SCHED_H_ */
lib/tst_sched.c new file +36 -0
new file mode 100644
index 000000000..d53273d8e
@@ -0,0 +1,36 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2021, BELLSOFT. All rights reserved.
+ */
+
+#include <errno.h>
+#include <unistd.h>
+#include "tst_sched.h"
+#include "lapi/syscalls.h"
+
+#define TST_SCHED_COMMON(SCALL, ...) do {			\
+	int ret = SCALL(__VA_ARGS__);				\
+	if (ret == -1 && errno == ENOSYS)			\
+		return syscall(__NR_##SCALL, __VA_ARGS__);	\
+	return ret;						\
+} while (0)
+
+int tst_sched_setparam(pid_t pid, const struct sched_param *param)
+{
+	TST_SCHED_COMMON(sched_setparam, pid, param);
+}
+
+int tst_sched_getparam(pid_t pid, struct sched_param *param)
+{
+	TST_SCHED_COMMON(sched_getparam, pid, param);
+}
+
+int tst_sched_setscheduler(pid_t pid, int policy, const struct sched_param *param)
+{
+	TST_SCHED_COMMON(sched_setscheduler, pid, policy, param);
+}
+
+int tst_sched_getscheduler(pid_t pid)
+{
+	TST_SCHED_COMMON(sched_getscheduler, pid);
+}
Signature · 1 line
2.25.1
#8 lore raw

PATCH 2/16 syscalls/sched_getparam01: use tst_sched_*()

In reply to Alexey Kodanev
---
 testcases/kernel/syscalls/sched_getparam/sched_getparam01.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
testcases/kernel/syscalls/sched_getparam/sched_getparam01.c +3 -3
index efb697707..c24d1c917 100644
@@ -21,8 +21,8 @@
 #include <stdlib.h>
 #include <sys/types.h>
 #include <unistd.h>
-#include <sched.h>
 #include "tst_test.h"
+#include "tst_sched.h"
 
 static pid_t pids[2] = {0, 0};
 
@@ -35,8 +35,8 @@ static void verify_sched_getparam(unsigned int n)
 
 	child_pid = SAFE_FORK();
 	if (!child_pid) {
-		TST_EXP_PASS_SILENT(sched_getparam(pids[n], &param),
-				    "sched_getparam(%d)", pids[n]);
+		TST_EXP_PASS_SILENT(tst_sched_getparam(pids[n], &param),
+				   "sched_getparam(%d)", pids[n]);
 		if (!TST_PASS)
 			exit(0);
 
Signature · 1 line
2.25.1
#9 lore raw

PATCH 3/16 syscalls/sched_getparam03: use tst_sched_*()

In reply to Alexey Kodanev
---
 testcases/kernel/syscalls/sched_getparam/sched_getparam03.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
testcases/kernel/syscalls/sched_getparam/sched_getparam03.c +2 -2
index 19ecaf147..451bfdc50 100644
@@ -17,8 +17,8 @@
  */
 
 #include <errno.h>
-#include <sched.h>
 #include "tst_test.h"
+#include "tst_sched.h"
 
 static struct sched_param param;
 static pid_t unused_pid;
@@ -43,7 +43,7 @@ static void verify_sched_getparam(unsigned int n)
 {
 	struct test_case_t *tc = &test_cases[n];
 
-	TST_EXP_FAIL(sched_getparam(*(tc->pid), tc->p), tc->exp_errno, "%s", tc->desc);
+	TST_EXP_FAIL(tst_sched_getparam(*(tc->pid), tc->p), tc->exp_errno, "%s", tc->desc);
 }
 
 static void setup(void)
Signature · 1 line
2.25.1
#10 lore raw

PATCH 4/16 syscalls/sched_setparam01: convert to new API

In reply to Alexey Kodanev
---
 .../sched_setparam/sched_setparam01.c         | 135 +++---------------
 1 file changed, 18 insertions(+), 117 deletions(-)
testcases/kernel/syscalls/sched_setparam/sched_setparam01.c +18 -117
index a2272eb18..d677736a1 100644
@@ -1,128 +1,29 @@
+// SPDX-License-Identifier: GPL-2.0-only
 /*
+ * Copyright (c) 2021, BELLSOFT. All rights reserved.
  * Copyright (c) Wipro Technologies Ltd, 2002.  All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
+ * AUTHOR: Saji Kumar.V.R <[email protected]>
  */
-/**********************************************************
- *
- *    TEST IDENTIFIER	: sched_setparam01
- *
- *    EXECUTED BY	: anyone
- *
- *    TEST TITLE	: Basic test for sched_setparam(2)
- *
- *    TEST CASE TOTAL	: 1
- *
- *    AUTHOR		: Saji Kumar.V.R <[email protected]>
- *
- *    SIGNALS
- * 	Uses SIGUSR1 to pause before test if option set.
- * 	(See the parse_opts(3) man page).
- *
- *    DESCRIPTION
- *	This is a Phase I test for the sched_setparam(2) system call.
- *	It is intended to provide a limited exposure of the system call.
- *
- * 	Setup:
- * 	  Setup signal handling.
- *	  Pause for SIGUSR1 if option specified.
- *
- * 	Test:
- *	 Loop if the proper options are given.
- * 	  Execute system call
- *	  Check return code, if system call failed (return=-1)
- *		Log the errno and Issue a FAIL message.
- *	  Otherwise, Issue a PASS message.
- *
- * 	Cleanup:
- * 	  Print errno log and/or timing stats if options given
+
+/*\
+ * [Description]
  *
- * USAGE:  <for command-line>
- *  sched_setparam01 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-h] [-f] [-p]
- *			where,  -c n : Run n copies concurrently.
- *				-e   : Turn on errno logging.
- *				-h   : Show help screen
- *				-f   : Turn off functional testing
- *				-i n : Execute test n times.
- *				-I x : Execute test for x seconds.
- *				-p   : Pause for SIGUSR1 before starting
- *				-P x : Pause for x seconds between iterations.
- *				-t   : Turn on syscall timing.
+ * Basic test for sched_setparam(2)
  *
- ****************************************************************/
-
-#include <errno.h>
-#include <sched.h>
-#include "test.h"
-
-static void setup();
-static void cleanup();
-
-char *TCID = "sched_setparam01";
-int TST_TOTAL = 1;
-
-static struct sched_param param;
-
-int main(int ac, char **av)
-{
-
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		/*
-		 * Call sched_setparam(2) with pid=0 sothat it will
-		 * set the scheduling parameters for the calling process
-		 */
-		TEST(sched_setparam(0, &param));
-
-		if (TEST_RETURN == 0) {
-			tst_resm(TPASS, "sched_setparam() returned %ld",
-				 TEST_RETURN);
-		} else {
-			tst_resm(TFAIL | TTERRNO,
-				 "Test Failed, sched_setparam()" "returned %ld",
-				 TEST_RETURN);
-		}
-	}
+ * Call sched_setparam(2) with pid=0 so that it will
+ * set the scheduling parameters for the calling process
+ */
 
-	cleanup();
-	tst_exit();
-}
+#include "tst_test.h"
+#include "tst_sched.h"
 
-/* setup() - performs all ONE TIME setup for this test */
-void setup(void)
+static void run(void)
 {
+	struct sched_param p = { .sched_priority = 0 };
 
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	param.sched_priority = 0;
-
+	TST_EXP_PASS(tst_sched_setparam(0, &p));
 }
 
-/*
- *cleanup() -  performs all ONE TIME cleanup for this test at
- *		completion or premature exit.
- */
-void cleanup(void)
-{
-}
+static struct tst_test test = {
+	.test_all = run,
+};
Signature · 1 line
2.25.1
#11 lore raw

PATCH 5/16 syscalls/sched_setparam02: convert to new API

In reply to Alexey Kodanev
---
 .../sched_setparam/sched_setparam02.c         | 195 ++++--------------
 1 file changed, 35 insertions(+), 160 deletions(-)
testcases/kernel/syscalls/sched_setparam/sched_setparam02.c +35 -160
index 132cc9d6c..de7ec208e 100644
@@ -1,184 +1,59 @@
+// SPDX-License-Identifier: GPL-2.0-only
 /*
+ * Copyright (c) 2021, BELLSOFT. All rights reserved.
  * Copyright (c) Wipro Technologies Ltd, 2002.  All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * AUTHOR: Saji Kumar.V.R <[email protected]>
  */
-/**********************************************************
- *
- *    TEST IDENTIFIER	: sched_setparam02
- *
- *    EXECUTED BY	: root / superuser
- *
- *    TEST TITLE	: Checks functionality for sched_setparam(2)
- *
- *    TEST CASE TOTAL	: 1
- *
- *    AUTHOR		: Saji Kumar.V.R <[email protected]>
- *
- *    SIGNALS
- * 	Uses SIGUSR1 to pause before test if option set.
- * 	(See the parse_opts(3) man page).
- *
- *    DESCRIPTION
- *	This test changes the scheduling priority for current process
- *	and verifies it by calling sched_getparam().
- *
- * 	Setup:
- * 	  Setup signal handling.
- *	  Pause for SIGUSR1 if option specified.
- *	  Change scheduling policy to SCHED_FIFO
- *
- * 	Test:
- *	 Loop if the proper options are given.
- * 	  Execute system call
- *	  If scheduling priority is set properly,
- *		TEST passed
- *	  else
- *		TEST failed
- *
- * 	Cleanup:
- * 	  Print errno log and/or timing stats if options given
+
+/*\
+ * [Description]
  *
- * USAGE:  <for command-line>
- *  sched_setparam02 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-h] [-f] [-p]
- *			where,  -c n : Run n copies concurrently.
- *				-e   : Turn on errno logging.
- *				-h   : Show help screen
- *				-f   : Turn off functional testing
- *				-i n : Execute test n times.
- *				-I x : Execute test for x seconds.
- *				-p   : Pause for SIGUSR1 before starting
- *				-P x : Pause for x seconds between iterations.
- *				-t   : Turn on syscall timing.
+ * Checks functionality for sched_setparam(2)
  *
- ****************************************************************/
+ * This test changes the scheduling priority for current process
+ * and verifies it by calling sched_getparam().
+ */
 
-#include <errno.h>
-#include <sched.h>
-#include "test.h"
+#include "tst_test.h"
+#include "tst_sched.h"
 
 #define FIFO_OR_RR_PRIO 5
 #define OTHER_PRIO 0
 
-static void setup();
-static void cleanup();
-static int verify_priority(int);
-
-char *TCID = "sched_setparam02";
-
-static struct sched_param param;
-static struct sched_param param1 = { 1 };
-
 static struct test_cases_t {
 	char *desc;
 	int policy;
 	int priority;
-} testcases[] = {
+	int param;
+} tcases[] = {
 	{
-	"Test with policy SCHED_FIFO", SCHED_FIFO, FIFO_OR_RR_PRIO}, {
-	"Test with policy SCHED_RR", SCHED_RR, FIFO_OR_RR_PRIO}, {
-	"Test with SCHED_OTHER", SCHED_OTHER, OTHER_PRIO}
+	"Test with policy SCHED_FIFO", SCHED_FIFO, FIFO_OR_RR_PRIO, 1}, {
+	"Test with policy SCHED_RR", SCHED_RR, FIFO_OR_RR_PRIO, 1}, {
+	"Test with SCHED_OTHER", SCHED_OTHER, OTHER_PRIO, 0}
 };
 
-int TST_TOTAL = sizeof(testcases) / sizeof(testcases[0]);
-
-int main(int ac, char **av)
-{
-
-	int lc, i;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		for (i = 0; i < TST_TOTAL; ++i) {
-
-			if (i == 2) {
-				param1.sched_priority = 0;
-			} else {
-				param1.sched_priority = 1;
-			}
-			if ((sched_setscheduler(0, testcases[i].policy,
-						&param1)) == -1) {
-				tst_brkm(TBROK, cleanup, "sched_setscheduler()"
-					 "  failed");
-			}
-			param.sched_priority = testcases[i].priority;
-			/*
-			 * Call sched_setparam(2) with pid=0 sothat it will
-			 * set the scheduling parameters for the calling process
-			 */
-			TEST(sched_setparam(0, &param));
-
-			if ((TEST_RETURN == 0) && (verify_priority(i))) {
-				tst_resm(TPASS, "%s Passed", testcases[i].desc);
-			} else {
-				tst_resm(TFAIL | TTERRNO,
-					 "%s Failed. sched_setparam()"
-					 " returned %ld", testcases[i].desc,
-					 TEST_RETURN);
-			}
-		}
-	}
-
-	/* cleanup and exit */
-	cleanup();
-
-	tst_exit();
-
-}
-
-/* setup() - performs all ONE TIME setup for this test */
-void setup(void)
+static void run(unsigned int n)
 {
-	tst_require_root();
+	struct test_cases_t *tc = &tcases[n];
+	struct sched_param p = { .sched_priority = tc->param };
 
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
+	TST_EXP_PASS_SILENT(tst_sched_setscheduler(0, tc->policy, &p));
 
-	TEST_PAUSE;
+	p.sched_priority = tc->priority;
+	TST_EXP_PASS_SILENT(tst_sched_setparam(0, &p));
 
-}
+	p.sched_priority = -1;
+	TST_EXP_PASS_SILENT(tst_sched_getparam(0, &p));
 
-/*
- *cleanup() -  performs all ONE TIME cleanup for this test at
- *		completion or premature exit.
- */
-void cleanup(void)
-{
+	if (p.sched_priority == tc->priority)
+		tst_res(TPASS, "got expected priority %d", p.sched_priority);
+	else
+		tst_res(TFAIL, "unexpected priority value %d, expected %d",
+			p.sched_priority, tc->priority);
 }
 
-/*
- * verify_priority() -  This function checks whether the priority is
- *			set correctly
- */
-int verify_priority(int i)
-{
-	struct sched_param p;
-
-	if ((sched_getparam(0, &p)) == 0) {
-		if (p.sched_priority == testcases[i].priority) {
-			return 1;
-		} else {
-			tst_resm(TWARN, "sched_getparam() returned priority"
-				 " value as %d", p.sched_priority);
-			return 0;
-		}
-	}
-
-	tst_resm(TWARN, "sched_getparam() failed");
-	return 0;
-}
+static struct tst_test test = {
+	.needs_root = 1,
+	.test = run,
+	.tcnt = ARRAY_SIZE(tcases),
+};
Signature · 1 line
2.25.1
#12 lore raw

PATCH 6/16 syscalls/sched_setparam03: convert to new API

In reply to Alexey Kodanev
---
 .../sched_setparam/sched_setparam03.c         | 215 ++++--------------
 1 file changed, 40 insertions(+), 175 deletions(-)
testcases/kernel/syscalls/sched_setparam/sched_setparam03.c +40 -175
index 252364e2e..e9571a9b1 100644
@@ -1,196 +1,61 @@
+// SPDX-License-Identifier: GPL-2.0-only
 /*
+ * Copyright (c) 2021, BELLSOFT. All rights reserved.
  * Copyright (c) Wipro Technologies Ltd, 2002.  All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
+ * AUTHOR: Saji Kumar.V.R <[email protected]>
  */
-/**********************************************************
- *
- *    TEST IDENTIFIER	: sched_setparam03
- *
- *    EXECUTED BY	: root / superuser
- *
- *    TEST TITLE	: Checks functionality for sched_setparam(2) for pid!=0
- *
- *    TEST CASE TOTAL	: 1
- *
- *    AUTHOR		: Saji Kumar.V.R <[email protected]>
- *
- *    SIGNALS
- * 	Uses SIGUSR1 to pause before test if option set.
- * 	(See the parse_opts(3) man page).
- *
- *    DESCRIPTION
- *	This test forks a child & changes its parent's scheduling priority
- *
- * 	Setup:
- * 	  Setup signal handling.
- *	  Pause for SIGUSR1 if option specified.
- *	  Change scheduling policy to SCHED_FIFO
- *
- * 	Test:
- *	 Loop if the proper options are given.
- *	 Fork a child
- *
- *	 CHILD:
- *	  Changes scheduling priority for parent
- *
- *	 PARENT:
- *	  If scheduling priority is set properly,
- *		TEST passed
- *	  else
- *		TEST failed
- *
- * 	Cleanup:
- * 	  Print errno log and/or timing stats if options given
+
+/*\
+ * [Description]
  *
- * USAGE:  <for command-line>
- *  sched_setparam03 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-h] [-f] [-p]
- *			where,  -c n : Run n copies concurrently.
- *				-e   : Turn on errno logging.
- *				-h   : Show help screen
- *				-f   : Turn off functional testing
- *				-i n : Execute test n times.
- *				-I x : Execute test for x seconds.
- *				-p   : Pause for SIGUSR1 before starting
- *				-P x : Pause for x seconds between iterations.
- *				-t   : Turn on syscall timing.
+ * Checks functionality for sched_setparam(2) for pid != 0
  *
- ****************************************************************/
-
-#include <err.h>
-#include <errno.h>
-#include <sched.h>
-#include <sys/wait.h>
-#include "test.h"
-
-#define NEW_PRIORITY 5
-
-static void setup();
-static void cleanup();
-static int verify_priority();
+ * This test forks a child and changes its parent's scheduling priority.
+ */
 
-char *TCID = "sched_setparam03";
-int TST_TOTAL = 1;
+#include <stdlib.h>
 
-static struct sched_param param = { NEW_PRIORITY };
+#include "tst_test.h"
+#include "tst_sched.h"
 
-int main(int ac, char **av)
+static void run(void)
 {
-
-	int lc;
-	int status;
+	struct sched_param p5 = { .sched_priority = 5 };
+	struct sched_param p;
 	pid_t child_pid;
 
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
+	child_pid = SAFE_FORK();
 
-		switch (child_pid = FORK_OR_VFORK()) {
-
-		case -1:
-			/* fork() failed */
-			tst_resm(TFAIL, "fork() failed");
-			continue;
-
-		case 0:
-			/* Child */
-
-			/*
-			 * Call sched_setparam(2) with pid = getppid() so that
-			 * it will set the scheduling parameters for parent
-			 * process
-			 */
-			TEST(sched_setparam(getppid(), &param));
-
-			if (TEST_RETURN == -1) {
-				err(0, "sched_setparam returned %ld",
-				    TEST_RETURN);
-			}
-			exit(1);
-
-		default:
-			/* Parent */
-			if ((waitpid(child_pid, &status, 0)) < 0) {
-				tst_resm(TFAIL, "wait() failed");
-				continue;
-			}
-
-			/*
-			 * Verify that parent's scheduling priority has
-			 * changed.
-			 */
-			if ((WIFEXITED(status)) && (WEXITSTATUS(status)) &&
-			    (verify_priority())) {
-				tst_resm(TPASS, "Test Passed");
-			} else {
-				tst_resm(TFAIL, "Test Failed");
-			}
-		}
+	if (!child_pid) {
+		/*
+		 * Call sched_setparam(2) with pid = getppid() so that
+		 * it will set the scheduling parameters for parent
+		 * process
+		 */
+		TST_EXP_PASS_SILENT(tst_sched_setparam(getppid(), &p5));
+		exit(0);
 	}
+	tst_reap_children();
+
+	TST_EXP_PASS_SILENT(tst_sched_getparam(0, &p));
 
-	cleanup();
-	tst_exit();
+	if (p.sched_priority == p5.sched_priority)
+		tst_res(TPASS, "got expected priority %d", p.sched_priority);
+	else
+		tst_res(TFAIL, "got priority %d, expected %d",
+			p.sched_priority, p5.sched_priority);
 }
 
-/* setup() - performs all ONE TIME setup for this test */
 void setup(void)
 {
-	struct sched_param p = { 1 };
-
-	tst_require_root();
-
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	/* Change scheduling policy to SCHED_FIFO */
-	if ((sched_setscheduler(0, SCHED_FIFO, &p)) == -1) {
-		tst_brkm(TBROK, cleanup, "sched_setscheduler() failed");
-	}
+	struct sched_param p = { .sched_priority = 1 };
 
+	TST_EXP_PASS_SILENT(tst_sched_setscheduler(0, SCHED_FIFO, &p));
 }
 
-/*
- *cleanup() -   performs all ONE TIME cleanup for this test at
- *		completion or premature exit.
- */
-void cleanup(void)
-{
-}
-
-/*
- * verify_priority() -  This function checks whether the priority is
- *			set correctly
- */
-int verify_priority(void)
-{
-	struct sched_param p;
-
-	if ((sched_getparam(0, &p)) == 0) {
-		if (p.sched_priority == NEW_PRIORITY) {
-			return 1;
-		} else {
-			tst_resm(TWARN, "sched_getparam() returned priority"
-				 " value as %d", p.sched_priority);
-			return 0;
-		}
-	}
-
-	tst_resm(TWARN, "sched_getparam() failed");
-	return 0;
-}
+static struct tst_test test = {
+	.forks_child = 1,
+	.needs_root = 1,
+	.setup = setup,
+	.test_all = run,
+};
Signature · 1 line
2.25.1
#13 lore raw

PATCH 7/16 syscalls/sched_setparam04: convert to new API

In reply to Alexey Kodanev
---
 .../sched_setparam/sched_setparam04.c         | 161 ++++--------------
 1 file changed, 30 insertions(+), 131 deletions(-)
testcases/kernel/syscalls/sched_setparam/sched_setparam04.c +30 -131
index f6e017d3d..d80fd0d2a 100644
@@ -1,34 +1,14 @@
+// SPDX-License-Identifier: GPL-2.0-only
 /*
+ * Copyright (c) 2021, BELLSOFT. All rights reserved.
  * Copyright (c) Wipro Technologies Ltd, 2002.  All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program;  if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
+ * AUTHOR: Saji Kumar.V.R <[email protected]>
  */
- /*******************************************************************
- *
- *    TEST IDENTIFIER   : sched_setparam04
- *
- *    EXECUTED BY       : anyone
- *
- *    TEST TITLE        : testing error conditions for sched_setparam(2)
- *
- *    TEST CASE TOTAL   : 4
- *
- *    AUTHOR            : Saji Kumar.V.R <[email protected]>
+
+/*\
+ * [Description]
  *
- *    SIGNALS
- *      Uses SIGUSR1 to pause before test if option set.
- *      (See the parse_opts(3) man page).
+ * Testing error conditions for sched_setparam(2)
  *
  * DESCRIPTION
  * 	Verify that,
@@ -41,129 +21,48 @@
  *   4) sched_setparam(2) returns -1 sets errno to EINVAL if the
  *	value for p.sched_priority is other than 0 for scheduling
  *	policy, SCHED_OTHER
- *
- * ALGORITHM
- * Setup:
- *   Setup signal handling.
- *   Pause for SIGUSR1 if option specified.
- *
- *  Test:
- *   Loop if the proper options are given.
- *   Execute system call
- *   Check return code, if (system call failed (return=-1)) &
- *			   (errno set == expected errno)
- *              Issue sys call fails with expected return value and errno.
- *   Otherwise,
- *      Issue sys call returns unexpected value.
- *
- *  Cleanup:
- *        Print errno log and/or timing stats if options given
- *
- * USAGE:  <for command-line>
- *  sched_setparam04 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-h] [-f] [-p]
- *		where,  -c n : Run n copies concurrently.
- *			-e   : Turn on errno logging.
- *			-h   : Show help screen
- *			-f   : Turn off functional testing
- *			-i n : Execute test n times.
- *			-I x : Execute test for x seconds.
- *			-p   : Pause for SIGUSR1 before starting
- *			-P x : Pause for x seconds between iterations.
- *			-t   : Turn on syscall timing.
- *
- *********************************************************************/
-
-#include <errno.h>
-#include <sched.h>
-#include <pwd.h>
-#include "test.h"
+ */
 
-static void cleanup(void);
-static void setup(void);
+#include <stdlib.h>
 
-static struct sched_param param = { 0 };
-static struct sched_param param1 = { 1 };
+#include "tst_test.h"
+#include "tst_sched.h"
 
-char *TCID = "sched_setparam04";
+static struct sched_param p = { .sched_priority = 0 };
+static struct sched_param p1 = { .sched_priority = 1 };
 
 static pid_t unused_pid;
 static pid_t inval_pid = -1;
 static pid_t zero_pid;
 
-static struct test_case_t {
+static struct test_cases_t {
 	char *desc;
 	pid_t *pid;
 	struct sched_param *p;
 	int exp_errno;
-	char err_desc[10];
-} test_cases[] = {
+} tcases[] = {
 	{
-	"test with non-existing pid", &unused_pid, &param, ESRCH, "ESRCH"}, {
-	"test invalid pid value", &inval_pid, &param, EINVAL, "EINVAL"}, {
-	"test with invalid address for p", &zero_pid, NULL, EINVAL, "EINVAL"}, {
-	"test with invalid p.sched_priority", &zero_pid, &param1, EINVAL,
-		    "EINVAL"}
+	"test with non-existing pid", &unused_pid, &p, ESRCH}, {
+	"test invalid pid value", &inval_pid, &p, EINVAL,}, {
+	"test with invalid address for p", &zero_pid, NULL, EINVAL}, {
+	"test with invalid p.sched_priority", &zero_pid, &p1, EINVAL}
 };
 
-int TST_TOTAL = sizeof(test_cases) / sizeof(test_cases[0]);
-
-int main(int ac, char **av)
+static void setup(void)
 {
-	int lc, ind;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();		/* global setup */
-
-	/* The following loop checks looping state if -i option given */
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		/* reset tst_count in case we are looping */
-		tst_count = 0;
-
-		for (ind = 0; ind < TST_TOTAL; ind++) {
-			/*
-			 * call the system call with the TEST() macro
-			 */
-			TEST(sched_setparam(*(test_cases[ind].pid),
-					    test_cases[ind].p));
-
-			if ((TEST_RETURN == -1) &&
-			    (TEST_ERRNO == test_cases[ind].exp_errno)) {
-				tst_resm(TPASS, "expected failure; Got %s",
-					 test_cases[ind].err_desc);
-			} else {
-				tst_resm(TFAIL, "Call failed to produce "
-					 "expected error;  Expected errno: %d "
-					 "Got : %d, %s",
-					 test_cases[ind].exp_errno,
-					 TEST_ERRNO, strerror(TEST_ERRNO));
-			}
-		}
-	}
-
-	cleanup();
-
-	tst_exit();
+	unused_pid = tst_get_unused_pid();
 }
 
-/*
- * setup() - performs all the ONE TIME setup for this test.
- */
-void setup(void)
+static void run(unsigned int n)
 {
-	unused_pid = tst_get_unused_pid(cleanup);
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
+	struct test_cases_t *tc = &tcases[n];
 
+	TST_EXP_FAIL(tst_sched_setparam(*tc->pid, tc->p), tc->exp_errno,
+		     "%s", tc->desc);
 }
 
-/*
- * cleanup() -  performs all the ONE TIME cleanup for this test at completion
- *		or premature exit.
- */
-void cleanup(void)
-{
-
-}
+static struct tst_test test = {
+	.setup = setup,
+	.test = run,
+	.tcnt = ARRAY_SIZE(tcases),
+};
Signature · 1 line
2.25.1
#14 lore raw

PATCH 8/16 syscalls/sched_setparam05: convert to new API

In reply to Alexey Kodanev
---
 .../sched_setparam/sched_setparam05.c         | 186 +++---------------
 1 file changed, 26 insertions(+), 160 deletions(-)
testcases/kernel/syscalls/sched_setparam/sched_setparam05.c +26 -160
index 53db641d7..36d7c4123 100644
@@ -1,176 +1,42 @@
+// SPDX-License-Identifier: GPL-2.0-only
 /*
+ * Copyright (c) 2021, BELLSOFT. All rights reserved.
  * Copyright (c) Wipro Technologies Ltd, 2002.  All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
+ * AUTHOR: Saji Kumar.V.R <[email protected]>
  */
-/**********************************************************
- *
- *    TEST IDENTIFIER	: sched_setparam05
- *
- *    EXECUTED BY	: root/superuser
- *
- *    TEST TITLE	: verify that sched_setparam() fails if the user does
- *			  not have proper privilages
- *
- *    TEST CASE TOTAL	: 1
- *
- *    AUTHOR		: Saji Kumar.V.R <[email protected]>
- *
- *    SIGNALS
- * 	Uses SIGUSR1 to pause before test if option set.
- * 	(See the parse_opts(3) man page).
- *
- *    DESCRIPTION
- *	Verify that sched_setparam() fails if the user does
- *	not have proper privilages
- *
- * 	Setup:
- * 	  Setup signal handling.
- *	  Pause for SIGUSR1 if option specified.
- *
- * 	Test:
- *	 Loop if the proper options are given.
- *	 Fork a child
- *
- *	 CHILD:
- *	  Changes euid to "nobody" user.
- *	  Try to Change scheduling priority for parent
- *	  If call failed with errno = EPERM,
- *		Test passed
- *	  else
- *		Test failed
- *
- *	 PARENT:
- *		wait for child to finish
- *
- * 	Cleanup:
- * 	  Print errno log and/or timing stats if options given
- *
- * USAGE:  <for command-line>
- *  sched_setparam05 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-h] [-f] [-p]
- *			where,  -c n : Run n copies concurrently.
- *				-e   : Turn on errno logging.
- *				-h   : Show help screen
- *				-f   : Turn off functional testing
- *				-i n : Execute test n times.
- *				-I x : Execute test for x seconds.
- *				-p   : Pause for SIGUSR1 before starting
- *				-P x : Pause for x seconds between iterations.
- *				-t   : Turn on syscall timing.
+
+/*\
+ * [Description]
  *
- ****************************************************************/
+ * Verify that sched_setparam() fails if the user does not have proper
+ * privileges.
+ */
 
-#include <errno.h>
-#include <sched.h>
+#include <stdlib.h>
 #include <pwd.h>
-#include <sys/wait.h>
-#include "test.h"
-
-static void setup();
-static void cleanup();
-
-char *TCID = "sched_setparam05";
-int TST_TOTAL = 1;
-
-static struct sched_param param = { 0 };
 
-static char nobody_uid[] = "nobody";
-struct passwd *ltpuser;
+#include "tst_test.h"
+#include "tst_sched.h"
 
-int main(int ac, char **av)
+static void run(void)
 {
+	pid_t child_pid = SAFE_FORK();
 
-	int lc;
-	int status;
-	pid_t child_pid;
+	if (!child_pid) {
+		struct sched_param p = { .sched_priority = 0 };
+		struct passwd *pw = SAFE_GETPWNAM("nobody");
 
-	tst_parse_opts(ac, av, NULL, NULL);
+		SAFE_SETEUID(pw->pw_uid);
+		TST_EXP_FAIL(tst_sched_setparam(getppid(), &p), EPERM);
 
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		switch (child_pid = FORK_OR_VFORK()) {
-
-		case -1:
-			/* fork() failed */
-			tst_resm(TFAIL, "fork() failed");
-			continue;
-
-		case 0:
-			/* Child */
-
-			/* Switch to nobody user */
-			if ((ltpuser = getpwnam(nobody_uid)) == NULL) {
-				tst_brkm(TBROK, NULL, "'%s' user not present", nobody_uid);
-			}
-			if (seteuid(ltpuser->pw_uid) == -1) {
-				tst_resm(TWARN, "seteuid failed to to set the effective uid to %d",
-					 ltpuser->pw_uid);
-				exit(1);
-			}
-
-			/*
-			 * Call sched_setparam(2) with pid = getppid()
-			 */
-			TEST(sched_setparam(getppid(), &param));
-
-			if ((TEST_RETURN == -1) && (TEST_ERRNO == EPERM)) {
-				exit(0);
-			}
-
-			tst_resm(TWARN | TTERRNO,
-				 "Test failed, sched_setparam()"
-				 " returned : %ld", TEST_RETURN);
-			exit(1);
-
-		default:
-			/* Parent */
-			if ((waitpid(child_pid, &status, 0)) < 0) {
-				tst_resm(TFAIL, "wait() failed");
-				continue;
-			}
-			if ((WIFEXITED(status)) && (WEXITSTATUS(status) == 0)) {
-				tst_resm(TPASS, "Test passed, Got EPERM");
-			} else {
-				tst_resm(TFAIL, "Test Failed");
-			}
-		}
+		exit(0);
 	}
 
-	cleanup();
-	tst_exit();
+	tst_reap_children();
 }
 
-/* setup() - performs all ONE TIME setup for this test */
-void setup(void)
-{
-
-	tst_require_root();
-
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-}
-
-/*
- *cleanup() -  performs all ONE TIME cleanup for this test at
- *		completion or premature exit.
- */
-void cleanup(void)
-{
-}
+static struct tst_test test = {
+	.needs_root = 1,
+	.forks_child = 1,
+	.test_all = run,
+};
Signature · 1 line
2.25.1
#15 lore raw

PATCH 9/16 syscalls/sched_rr_get_interval01: use tst_sched_*()

In reply to Alexey Kodanev
---
 .../syscalls/sched_rr_get_interval/sched_rr_get_interval01.c  | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
testcases/kernel/syscalls/sched_rr_get_interval/sched_rr_get_interval01.c +2 -2
index 5da5fe51d..cd6525414 100644
@@ -11,9 +11,9 @@
  * timeslice tuning knob in milliseconds").
  */
 
-#include <sched.h>
 #include "time64_variants.h"
 #include "tst_timer.h"
+#include "tst_sched.h"
 
 #define PROC_SCHED_RR_TIMESLICE_MS	"/proc/sys/kernel/sched_rr_timeslice_ms"
 static int proc_flag;
@@ -41,7 +41,7 @@ static void setup(void)
 
 	tp.type = tv->ts_type;
 
-	if ((sched_setscheduler(0, SCHED_RR, &p)) == -1)
+	if ((tst_sched_setscheduler(0, SCHED_RR, &p)) == -1)
 		tst_res(TFAIL | TERRNO, "sched_setscheduler() failed");
 
 	proc_flag = !access(PROC_SCHED_RR_TIMESLICE_MS, F_OK);
Signature · 1 line
2.25.1
#16 lore raw

PATCH 10/16 syscalls/sched_rr_get_interval02: use tst_sched_*()

In reply to Alexey Kodanev
---
 .../syscalls/sched_rr_get_interval/sched_rr_get_interval02.c  | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
testcases/kernel/syscalls/sched_rr_get_interval/sched_rr_get_interval02.c +2 -2
index 9a0b8673d..f84a58216 100644
@@ -8,9 +8,9 @@
  * for tv_sec & tv_nsec.
  */
 
-#include <sched.h>
 #include "time64_variants.h"
 #include "tst_timer.h"
+#include "tst_sched.h"
 
 static struct tst_ts tp;
 
@@ -35,7 +35,7 @@ static void setup(void)
 
 	tp.type = tv->ts_type;
 
-	if ((sched_setscheduler(0, SCHED_FIFO, &p)) == -1)
+	if ((tst_sched_setscheduler(0, SCHED_FIFO, &p)) == -1)
 		tst_res(TFAIL | TERRNO, "sched_setscheduler() failed");
 }
 
Signature · 1 line
2.25.1
#17 lore raw

PATCH 11/16 syscalls/sched_rr_get_interval03: use tst_sched_*()

In reply to Alexey Kodanev
---
 .../syscalls/sched_rr_get_interval/sched_rr_get_interval03.c  | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
testcases/kernel/syscalls/sched_rr_get_interval/sched_rr_get_interval03.c +2 -2
index a61541b8a..0a486670b 100644
@@ -12,9 +12,9 @@
  *     address specified as &tp is invalid
  */
 
-#include <sched.h>
 #include "time64_variants.h"
 #include "tst_timer.h"
+#include "tst_sched.h"
 
 static pid_t unused_pid;
 static pid_t inval_pid = -1;
@@ -55,7 +55,7 @@ static void setup(void)
 	bad_addr = tst_get_bad_addr(NULL);
 	tp.type = tv->ts_type;
 
-	if ((sched_setscheduler(0, SCHED_RR, &p)) == -1)
+	if ((tst_sched_setscheduler(0, SCHED_RR, &p)) == -1)
 		tst_res(TFAIL | TERRNO, "sched_setscheduler() failed");
 
 	unused_pid = tst_get_unused_pid();
Signature · 1 line
2.25.1
#18 lore raw

PATCH 12/16 syscalls/sched_setscheduler01: convert to new API

In reply to Alexey Kodanev
---
 .../sched_setscheduler/sched_setscheduler01.c | 171 +++++-------------
 1 file changed, 42 insertions(+), 129 deletions(-)
testcases/kernel/syscalls/sched_setscheduler/sched_setscheduler01.c +42 -129
index 1cbce15d0..2feaa60d5 100644
@@ -1,160 +1,73 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) 2021, BELLSOFT. All rights reserved.
+ * Copyright (c) International Business Machines  Corp., 2001
  */
 
-/*
- * NAME
- *	sched_setscheduler01.c
- *
- * DESCRIPTION
- *	Testcase to test whether sched_setscheduler(2) sets the errnos
- *	correctly.
+/*\
+ * [Description]
  *
- * ALGORITHM
- *	1.	Call sched_setscheduler with an invalid pid, and expect
- *	ESRCH to be returned.
- *	2.	Call sched_setscheduler with an invalid scheduling policy,
- *	and expect EINVAL to be returned.
- *	3.	Call sched_setscheduler with an invalid "param" address,
- *	which lies outside the address space of the process, and expect
- *	EFAULT to be returned.
- *	4.	Call sched_setscheduler with an invalid priority value
- *	in "param" and expect EINVAL to be returned
+ * Testcase to test whether sched_setscheduler(2) sets the errnos
+ * correctly.
  *
- * USAGE:  <for command-line>
- *  sched_setscheduler01 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -e   : Turn on errno logging.
- *             -i n : Execute test n times.
- *             -I x : Execute test for x seconds.
- *             -P x : Pause for x seconds between iterations.
- *             -t   : Turn on syscall timing.
+ * [Algorithm]
  *
- * HISTORY
- *	07/2001 Ported by Wayne Boyer
- *
- * RESTRICTIONS
- *	None
+ * 1. Call sched_setscheduler with an invalid pid, and expect
+ * ESRCH to be returned.
+ * 2. Call sched_setscheduler with an invalid scheduling policy,
+ * and expect EINVAL to be returned.
+ * 3. Call sched_setscheduler with an invalid "param" address,
+ * which lies outside the address space of the process, and expect
+ * EFAULT to be returned.
+ * 4.Call sched_setscheduler with an invalid priority value
+ * in "param" and expect EINVAL to be returned
  */
+
 #include <stdio.h>
 #include <errno.h>
-#include <sched.h>
 #include <pwd.h>
-#include "test.h"
 
-#define SCHED_INVALID	99
-
-char *TCID = "sched_setscheduler01";
+#include "tst_test.h"
+#include "tst_sched.h"
 
-struct sched_param param;
-struct sched_param param1 = { 1 };
-
-void setup(void);
-void cleanup(void);
+#define SCHED_INVALID	99
 
+static struct sched_param p;
+static struct sched_param p1 = { .sched_priority = 1 };
 static pid_t unused_pid;
 static pid_t init_pid = 1;
 static pid_t zero_pid;
 
-struct test_case_t {
+struct test_cases_t {
 	pid_t *pid;
 	int policy;
 	struct sched_param *p;
 	int error;
-} TC[] = {
+} tcases[] = {
 	/* The pid is invalid - ESRCH */
-	{
-	&unused_pid, SCHED_OTHER, &param, ESRCH},
-	    /* The policy is invalid - EINVAL */
-	{
-	&init_pid, SCHED_INVALID, &param, EINVAL},
-#ifndef UCLINUX
-	    /* Skip since uClinux does not implement memory protection */
-	    /* The param address is invalid - EFAULT */
-	{
-	&init_pid, SCHED_OTHER, (struct sched_param *)-1, EFAULT},
-#endif
-	    /* The priority value in param invalid - EINVAL */
-	{
-	&zero_pid, SCHED_OTHER, &param1, EINVAL}
+	{&unused_pid, SCHED_OTHER, &p, ESRCH},
+	/* The policy is invalid - EINVAL */
+	{&init_pid, SCHED_INVALID, &p, EINVAL},
+	/* The param address is invalid - EFAULT */
+	{&init_pid, SCHED_OTHER, (struct sched_param *)-1, EFAULT},
+	/* The priority value in param invalid - EINVAL */
+	{&zero_pid, SCHED_OTHER, &p1, EINVAL}
 };
 
-int TST_TOTAL = ARRAY_SIZE(TC);
-
-int main(int ac, char **av)
+static void setup(void)
 {
-	int lc;
-
-	int i;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		/* reset tst_count in case we are looping */
-		tst_count = 0;
-
-		setup();
-
-		/* loop through the test cases */
-		for (i = 0; i < TST_TOTAL; i++) {
-
-			TEST(sched_setscheduler(*(TC[i].pid), TC[i].policy,
-						TC[i].p));
-
-			if (TEST_RETURN != -1) {
-				tst_resm(TFAIL, "call succeeded unexpectedly");
-				continue;
-			}
-
-			if (TEST_ERRNO == TC[i].error) {
-				tst_resm(TPASS, "expected failure - "
-					 "errno = %d : %s", TEST_ERRNO,
-					 strerror(TEST_ERRNO));
-			} else {
-				tst_resm(TFAIL, "unexpected error - %d : %s - "
-					 "expected %d", TEST_ERRNO,
-					 strerror(TEST_ERRNO), TC[i].error);
-			}
-		}
-	}
-	cleanup();
-
-	tst_exit();
-
+	unused_pid = tst_get_unused_pid();
 }
 
-/*
- * setup() - performs all ONE TIME setup for this test.
- */
-void setup(void)
+static void run(unsigned int n)
 {
-	unused_pid = tst_get_unused_pid(cleanup);
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
+	struct test_cases_t *tc = &tcases[n];
 
-	TEST_PAUSE;
+	TST_EXP_FAIL(tst_sched_setscheduler(*tc->pid, tc->policy, tc->p), tc->error);
 }
 
-/*
- * cleanup() - performs all ONE TIME cleanup for this test at
- *	       completion or premature exit.
- */
-void cleanup(void)
-{
-
-}
+static struct tst_test test = {
+	.setup = setup,
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = run,
+};
Signature · 1 line
2.25.1
#19 lore raw

PATCH 13/16 syscalls/sched_setscheduler02: convert to new API

In reply to Alexey Kodanev
---
 .../sched_setscheduler/sched_setscheduler02.c | 154 ++++--------------
 1 file changed, 33 insertions(+), 121 deletions(-)
testcases/kernel/syscalls/sched_setscheduler/sched_setscheduler02.c +33 -121
index 36952d9cb..68afb05c9 100644
@@ -1,148 +1,60 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) 2021, BELLSOFT. All rights reserved.
+ * Copyright (c) International Business Machines  Corp., 2001
  */
 
-/*
- * NAME
- *	sched_setscheduler01.c
+/*\
+ * [Description]
  *
- * DESCRIPTION
- *	Testcase to test whether sched_setscheduler(2) sets the errnos
- *	correctly.
+ * Testcase to test whether sched_setscheduler(2) sets the errnos
+ * correctly.
  *
- * ALGORITHM
- *	1.	Call sched_setscheduler as a non-root uid, and expect EPERM
- *	to be returned.
+ * [Algorithm]
  *
- * USAGE:  <for command-line>
- *  sched_setscheduler02 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -e   : Turn on errno logging.
- *             -i n : Execute test n times.
- *             -I x : Execute test for x seconds.
- *             -P x : Pause for x seconds between iterations.
- *             -t   : Turn on syscall timing.
+ * Call sched_setscheduler as a non-root uid, and expect EPERM
+ * to be returned.
  *
- * HISTORY
- *	07/2001 Ported by Wayne Boyer
- *
- * RESTRICTIONS
- *	Must run test as root.
  */
-#include <stdio.h>
+
+#include <stdlib.h>
 #include <errno.h>
-#include <sched.h>
 #include <pwd.h>
 #include <sys/types.h>
-#include <sys/wait.h>
 
-#include "test.h"
-#include "safe_macros.h"
+#include "tst_test.h"
+#include "tst_sched.h"
 
 #define SCHED_INVALID	99
 #define INVALID_PID	999999
 
-char *TCID = "sched_setscheduler02";
-int TST_TOTAL = 1;
-
-void setup(void);
-void cleanup(void);
-
 static uid_t nobody_uid;
 
-int main(int ac, char **av)
+static void setup(void)
 {
-	int lc;
-	pid_t pid;
-	struct sched_param param;
-	int status;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		/* reset tst_count in case we are looping */
-		tst_count = 0;
-
-		if ((pid = FORK_OR_VFORK()) == -1) {
-			tst_brkm(TBROK, cleanup, "fork failed");
-		}
-
-		if (pid == 0) {	/* child */
-			param.sched_priority = 1;
-
-			SAFE_SETEUID(cleanup, nobody_uid);
-
-			TEST(sched_setscheduler(pid, SCHED_FIFO, &param));
-
-			if (TEST_ERRNO) {
-			}
-
-			if (TEST_RETURN != -1) {
-				tst_resm(TFAIL, "sched_setscheduler(2) passed "
-					 "with non root priveledges");
-			} else if (TEST_ERRNO != EPERM) {
-				tst_resm(TFAIL, "Expected EPERM, got %d",
-					 TEST_ERRNO);
-			} else {
-				tst_resm(TPASS, "got EPERM");
-			}
-		} else {	/* parent */
-			/* let the child carry on */
-			wait(&status);
-			if (WIFEXITED(status) != 0) {	/* Exit with errors */
-				exit(WEXITSTATUS(status));
-			} else {
-				exit(0);
-			}
-		}
-
-		SAFE_SETEUID(cleanup, 0);
-	}
-	cleanup();
-	tst_exit();
+	struct passwd *pw = SAFE_GETPWNAM("nobody");
 
+	nobody_uid = pw->pw_uid;
 }
 
-/*
- * setup() - performs all ONE TIME setup for this test.
- */
-void setup(void)
+static void run(void)
 {
-	struct passwd *pw;
-
-	tst_require_root();
+	pid_t pid = SAFE_FORK();
 
-	pw = SAFE_GETPWNAM(NULL, "nobody");
-	nobody_uid = pw->pw_uid;
-
-	tst_sig(FORK, DEF_HANDLER, cleanup);
+	if (!pid) {
+		struct sched_param p = { .sched_priority = 1 };
 
-	TEST_PAUSE;
+		SAFE_SETEUID(nobody_uid);
+		TST_EXP_FAIL(tst_sched_setscheduler(0, SCHED_FIFO, &p), EPERM);
+		SAFE_SETEUID(0);
+		exit(0);
+	}
+	tst_reap_children();
 }
 
-/*
- * cleanup() - performs all ONE TIME cleanup for this test at
- *	       completion or premature exit.
- */
-void cleanup(void)
-{
-
-}
+static struct tst_test test = {
+	.forks_child = 1,
+	.needs_root = 1,
+	.setup = setup,
+	.test_all = run,
+};
Signature · 1 line
2.25.1
#20 lore raw

PATCH 14/16 syscalls/sched_setscheduler03: use tst_sched_*()

In reply to Alexey Kodanev
---
 .../syscalls/sched_setscheduler/sched_setscheduler03.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
testcases/kernel/syscalls/sched_setscheduler/sched_setscheduler03.c +5 -5
index 9045d0366..af4b29300 100644
@@ -17,13 +17,13 @@
 #include <stdio.h>
 #include <errno.h>
 #include <pwd.h>
-#include <sched.h>
 #include <sys/time.h>
 #include <sys/resource.h>
 #include <sys/wait.h>
 #include <stdlib.h>
 
 #include "tst_test.h"
+#include "tst_sched.h"
 
 #define RLIMIT_NICE_NORMAL 20
 
@@ -96,8 +96,8 @@ static void verify_fn(unsigned int i)
 		"Verifying case[%d]: policy = %d, priority = %d",
 		i + 1, cases[i].policy, cases[i].sched_param->sched_priority);
 
-	TEST(sched_setscheduler(*cases[i].pid, cases[i].policy,
-					cases[i].sched_param));
+	TEST(tst_sched_setscheduler(*cases[i].pid, cases[i].policy,
+				    cases[i].sched_param));
 	if (TST_RET)
 		tst_res(TFAIL | TTERRNO, "case[%d] expected: %d, got: ",
 			i + 1, cases[i].error);
@@ -129,11 +129,11 @@ static void setup(void)
 	l_rlimit_setup(RLIMIT_NICE, &limit);
 
 	tst_res(TINFO, "Setting init sched policy to SCHED_OTHER");
-	if (sched_setscheduler(0, SCHED_OTHER, &param[0]) != 0)
+	if (tst_sched_setscheduler(0, SCHED_OTHER, &param[0]) != 0)
 		tst_res(TFAIL | TERRNO,
 			 "ERROR sched_setscheduler: (0, SCHED_OTHER, param)");
 
-	if (sched_getscheduler(0) != SCHED_OTHER)
+	if (tst_sched_getscheduler(0) != SCHED_OTHER)
 		tst_res(TFAIL | TERRNO, "ERROR sched_setscheduler");
 
 	tst_res(TINFO, "Setting euid to nobody to drop privilege");
Signature · 1 line
2.25.1
#21 lore raw

PATCH 15/16 syscalls/sched_getscheduler01: convert to new API

In reply to Alexey Kodanev
---
 .../sched_getscheduler/sched_getscheduler01.c | 141 +++++-------------
 1 file changed, 37 insertions(+), 104 deletions(-)
testcases/kernel/syscalls/sched_getscheduler/sched_getscheduler01.c +37 -104
index f6bdf1a1b..e0da0510d 100644
@@ -1,129 +1,62 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) 2021, BELLSOFT. All rights reserved.
+ * Copyright (c) International Business Machines  Corp., 2001
  */
 
-/*
- * NAME
- *	sched_getscheduler01.C
+/*\
+ * [Description]
  *
- * DESCRIPTION
- *	Testcase to check sched_getscheduler() returns correct return value
+ * Testcase to check sched_getscheduler() returns correct return value.
  *
- * ALGORTIHM
- *	Call sched_setcheduler() to set the scheduling policy of the current
- *	process. Then call sched_getscheduler() to ensure that this is same
- *	as what set by the previous call to sched_setscheduler().
+ * [Algorithm]
  *
- *	Use SCHED_RR, SCHED_FIFO, SCHED_OTHER as the scheduling policies for
- *	sched_setscheduler().
+ * Call sched_setcheduler() to set the scheduling policy of the current
+ * process. Then call sched_getscheduler() to ensure that this is same
+ * as what set by the previous call to sched_setscheduler().
  *
- * USAGE:  <for command-line>
- *  sched_getscheduler01 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -f   : Turn off functionality Testing.
- *             -i n : Execute test n times.
- *             -I x : Execute test for x seconds.
- *             -P x : Pause for x seconds between iterations.
- *             -t   : Turn on syscall timing.
+ * Use SCHED_RR, SCHED_FIFO, SCHED_OTHER as the scheduling policies for
+ * sched_setscheduler().
  *
- * RESTRICTION
- *	Must run test as root.
  */
 
 #include <errno.h>
-#include <sched.h>
 #include <stdio.h>
-#include "test.h"
-
-char *TCID = "sched_getscheduler01";
-int TST_TOTAL = 3;
 
-void setup(void);
-void cleanup(void);
+#include "tst_test.h"
+#include "tst_sched.h"
 
-struct test_case_t {
-	int prio;
+struct test_cases_t {
+	int priority;
 	int policy;
-} TC[] = {
-	/* set scheduling policy to SCHED_RR */
-	{
-	1, SCHED_RR},
-	    /* set scheduling policy to SCHED_OTHER */
-	{
-	0, SCHED_OTHER},
-	    /* set scheduling policy to SCHED_FIFO */
-	{
-	1, SCHED_FIFO}
+} tcases[] = {
+	{1, SCHED_RR},
+	{0, SCHED_OTHER},
+	{1, SCHED_FIFO}
 };
 
-int main(int ac, char **av)
+static void run(unsigned int n)
 {
-	int lc;
-	int i;
-	struct sched_param param;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		for (i = 0; i < TST_TOTAL; i++) {
+	struct test_cases_t *tc = &tcases[n];
+	struct sched_param p = { .sched_priority = tc->priority };
 
-			param.sched_priority = TC[i].prio;
+	TST_EXP_PASS_SILENT(tst_sched_setscheduler(0, tc->policy, &p));
 
-			if (sched_setscheduler(0, TC[i].policy, &param) == -1)
-				tst_brkm(TBROK, cleanup,
-					 "sched_setscheduler failed");
+	TEST(tst_sched_getscheduler(0));
 
-			TEST(sched_getscheduler(0));
-
-			if (TEST_RETURN == -1) {
-				tst_resm(TFAIL, "call failed unexpectedly");
-				continue;
-			}
-
-			if (TEST_RETURN != TC[i].policy)
-				tst_resm(TFAIL,
-					 "policy value returned is not "
-					 "correct");
-			else
-				tst_resm(TPASS,
-					 "policy value returned is correct");
-		}
+	if (TST_RET == -1) {
+		tst_res(TFAIL, "sched_getscheduler() failed unexpectedly");
+		return;
 	}
 
-	cleanup();
-	tst_exit();
+	if (TST_RET == tc->policy)
+		tst_res(TPASS, "got expected policy %d", tc->policy);
+	else
+		tst_res(TFAIL, "got policy %ld, expected %d", TST_RET, tc->policy);
 }
 
-void setup(void)
-{
-
-	tst_require_root();
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-}
-
-void cleanup(void)
-{
-}
+static struct tst_test test = {
+	.needs_root = 1,
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = run,
+};
Signature · 1 line
2.25.1
#22 lore raw

PATCH 16/16 syscalls/sched_getscheduler02: convert to new API

In reply to Alexey Kodanev
---
 .../sched_getscheduler/sched_getscheduler02.c | 104 +++---------------
 1 file changed, 16 insertions(+), 88 deletions(-)
testcases/kernel/syscalls/sched_getscheduler/sched_getscheduler02.c +16 -88
index c43240108..73c5f58db 100644
@@ -1,106 +1,34 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) 2021, BELLSOFT. All rights reserved.
+ * Copyright (c) International Business Machines  Corp., 2001
  */
 
-/*
- * NAME
- *	sched_getscheduler02.C
- *
- * DESCRIPTION
- *	To check for the errno ESRCH
- *
- * ALGORITHM
- *	Pass an invalid pid to sched_getscheduler() and test for ESRCH.
+/*\
+ * [Description]
  *
- * USAGE:  <for command-line>
- *  sched_getscheduler02 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -e   : Turn on errno logging.
- *             -i n : Execute test n times.
- *             -I x : Execute test for x seconds.
- *             -P x : Pause for x seconds between iterations.
- *             -t   : Turn on syscall timing.
- *
- * RESTRICTION
- *	None
+ * Pass an invalid pid to sched_getscheduler() and test for ESRCH.
  */
 
 #include <stdio.h>
-#include <sched.h>
 #include <errno.h>
-#include "test.h"
 
-char *TCID = "sched_getscheduler02";
-int TST_TOTAL = 1;
+#include "tst_test.h"
+#include "tst_sched.h"
 
 static pid_t unused_pid;
 
-void setup(void);
-void cleanup(void);
-
-int main(int ac, char **av)
+static void setup(void)
 {
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		/* reset tst_count in case we are looping */
-		tst_count = 0;
-
-		TEST(sched_getscheduler(unused_pid));
-
-		if (TEST_RETURN != -1) {
-			tst_resm(TFAIL, "sched_getscheduler(2) passed "
-				 "unexpectedly");
-			continue;
-		}
-
-		if (errno != ESRCH) {
-			tst_resm(TFAIL, "Expected ESRCH, got %d", errno);
-		} else {
-			tst_resm(TPASS, "call failed with ESRCH");
-		}
-	}
-	cleanup();
-	tst_exit();
-
+	unused_pid = tst_get_unused_pid();
 }
 
-/*
- * setup() - performs all ONE TIME setup for this test.
- */
-void setup(void)
+static void run(void)
 {
-	unused_pid = tst_get_unused_pid(cleanup);
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
+	TST_EXP_FAIL(tst_sched_getscheduler(unused_pid), ESRCH);
 }
 
-/*
- * cleanup() - performs all ONE TIME cleanup for this test at
- *	       completion or premature exit.
- */
-void cleanup(void)
-{
-
-}
+static struct tst_test test = {
+	.setup = setup,
+	.test_all = run,
+};
Signature · 1 line
2.25.1