All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexey Kodanev <aleksei.kodanev@bell-sw.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v2 15/16] syscalls/sched_getscheduler01: convert to new API
Date: Fri,  6 Aug 2021 19:47:29 +0300	[thread overview]
Message-ID: <20210806164730.51040-16-aleksei.kodanev@bell-sw.com> (raw)
In-Reply-To: <20210806164730.51040-1-aleksei.kodanev@bell-sw.com>

Signed-off-by: Alexey Kodanev <aleksei.kodanev@bell-sw.com>
---
 .../sched_getscheduler/sched_getscheduler01.c | 154 ++++++------------
 1 file changed, 50 insertions(+), 104 deletions(-)

diff --git a/testcases/kernel/syscalls/sched_getscheduler/sched_getscheduler01.c b/testcases/kernel/syscalls/sched_getscheduler/sched_getscheduler01.c
index f6bdf1a1b..ebef6c3a5 100644
--- a/testcases/kernel/syscalls/sched_getscheduler/sched_getscheduler01.c
+++ b/testcases/kernel/syscalls/sched_getscheduler/sched_getscheduler01.c
@@ -1,129 +1,75 @@
+// 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"
+
+static struct sched_variants variants[] = {
+	{ .sched_setscheduler = libc_sched_setscheduler,
+	  .sched_getscheduler = libc_sched_getscheduler,
+	  .desc = "libc"
+	},
+	{ .sched_setscheduler = sys_sched_setscheduler,
+	  .sched_getscheduler = sys_sched_getscheduler,
+	  .desc = "syscall"
+	},
+};
 
-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;
+	struct sched_variants *tv = &variants[tst_variant];
+	struct test_cases_t *tc = &tcases[n];
+	struct sched_param p = { .sched_priority = tc->priority };
 
-		for (i = 0; i < TST_TOTAL; i++) {
+	TST_EXP_PASS_SILENT(tv->sched_setscheduler(0, tc->policy, &p));
 
-			param.sched_priority = TC[i].prio;
-
-			if (sched_setscheduler(0, TC[i].policy, &param) == -1)
-				tst_brkm(TBROK, cleanup,
-					 "sched_setscheduler failed");
-
-			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");
-		}
-	}
-
-	cleanup();
-	tst_exit();
+	TEST(tv->sched_getscheduler(0));
+	if (TST_RET == tc->policy)
+		tst_res(TPASS, "got expected policy %d", tc->policy);
+	else
+		tst_res(TFAIL | TERRNO, "got policy %ld, expected %d", TST_RET, tc->policy);
 }
 
-void setup(void)
+static void setup(void)
 {
-
-	tst_require_root();
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
+	tst_res(TINFO, "Testing %s variant", variants[tst_variant].desc);
 }
 
-void cleanup(void)
-{
-}
+static struct tst_test test = {
+	.needs_root = 1,
+	.setup = setup,
+	.test_variants = ARRAY_SIZE(variants),
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = run,
+};
-- 
2.25.1


  parent reply	other threads:[~2021-08-06 16:47 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-06 16:47 [LTP] [PATCH v2 00/16] syscalls/sched_*: convert to new API and handle ENOSYS errno Alexey Kodanev
2021-08-06 16:47 ` [LTP] [PATCH v2 01/16] lib/tst_sched: add ltp sys/libc_sched_*() wrappers Alexey Kodanev
2021-08-09  7:55   ` Li Wang
2021-08-09  9:53   ` Cyril Hrubis
2021-08-06 16:47 ` [LTP] [PATCH v2 02/16] syscalls/sched_getparam01: use libc/sys_sched_*() Alexey Kodanev
2021-08-09 10:02   ` Cyril Hrubis
2021-08-06 16:47 ` [LTP] [PATCH v2 03/16] syscalls/sched_getparam03: " Alexey Kodanev
2021-08-09 10:03   ` Cyril Hrubis
2021-08-06 16:47 ` [LTP] [PATCH v2 04/16] syscalls/sched_setparam01: convert to new API Alexey Kodanev
2021-08-09 10:05   ` Cyril Hrubis
2021-08-06 16:47 ` [LTP] [PATCH v2 05/16] syscalls/sched_setparam02: " Alexey Kodanev
2021-08-09 11:19   ` Cyril Hrubis
2021-08-06 16:47 ` [LTP] [PATCH v2 06/16] syscalls/sched_setparam03: " Alexey Kodanev
2021-08-09 11:28   ` Cyril Hrubis
2021-08-06 16:47 ` [LTP] [PATCH v2 07/16] syscalls/sched_setparam04: " Alexey Kodanev
2021-08-09 11:31   ` Cyril Hrubis
2021-08-06 16:47 ` [LTP] [PATCH v2 08/16] syscalls/sched_setparam05: " Alexey Kodanev
2021-08-09 11:34   ` Cyril Hrubis
2021-08-06 16:47 ` [LTP] [PATCH v2 09/16] syscalls/sched_rr_get_interval01: use sys_sched_*() Alexey Kodanev
2021-08-09 11:35   ` Cyril Hrubis
2021-08-06 16:47 ` [LTP] [PATCH v2 10/16] syscalls/sched_rr_get_interval02: " Alexey Kodanev
2021-08-09 11:36   ` Cyril Hrubis
2021-08-06 16:47 ` [LTP] [PATCH v2 11/16] syscalls/sched_rr_get_interval03: " Alexey Kodanev
2021-08-09 11:36   ` Cyril Hrubis
2021-08-06 16:47 ` [LTP] [PATCH v2 12/16] syscalls/sched_setscheduler01: convert to new API Alexey Kodanev
2021-08-09 12:19   ` Cyril Hrubis
2021-08-06 16:47 ` [LTP] [PATCH v2 13/16] syscalls/sched_setscheduler02: " Alexey Kodanev
2021-08-09 12:21   ` Cyril Hrubis
2021-08-06 16:47 ` [LTP] [PATCH v2 14/16] syscalls/sched_setscheduler03: use libc/sys_sched_*() Alexey Kodanev
2021-08-09 12:35   ` Cyril Hrubis
2021-08-06 16:47 ` Alexey Kodanev [this message]
2021-08-09 12:39   ` [LTP] [PATCH v2 15/16] syscalls/sched_getscheduler01: convert to new API Cyril Hrubis
2021-08-06 16:47 ` [LTP] [PATCH v2 16/16] syscalls/sched_getscheduler02: " Alexey Kodanev
2021-08-09 12:44   ` Cyril Hrubis
2021-08-12 13:51 ` [LTP] [PATCH v2 00/16] syscalls/sched_*: convert to new API and handle ENOSYS errno Alexey Kodanev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210806164730.51040-16-aleksei.kodanev@bell-sw.com \
    --to=aleksei.kodanev@bell-sw.com \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.