All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vinay Kumar <vinay.m.engg@gmail.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v2 03/10] getrusage02: Convert getrusage02 to new API
Date: Wed,  9 Jun 2021 23:05:54 +0530	[thread overview]
Message-ID: <20210609173601.29352-3-vinay.m.engg@gmail.com> (raw)
In-Reply-To: <20210609173601.29352-1-vinay.m.engg@gmail.com>

Signed-off-by: Vinay Kumar <vinay.m.engg@gmail.com>
---
 .../kernel/syscalls/getrusage/getrusage02.c   | 142 ++++--------------
 1 file changed, 27 insertions(+), 115 deletions(-)

diff --git a/testcases/kernel/syscalls/getrusage/getrusage02.c b/testcases/kernel/syscalls/getrusage/getrusage02.c
index 8077606a2..c4b3f0f69 100644
--- a/testcases/kernel/syscalls/getrusage/getrusage02.c
+++ b/testcases/kernel/syscalls/getrusage/getrusage02.c
@@ -1,86 +1,29 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * 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 <saji.kumar@wipro.com>
  */
-/**********************************************************
- *
- *    TEST IDENTIFIER	: getrusage02
- *
- *    EXECUTED BY	: anyone
- *
- *    TEST TITLE	: Tests for error conditions
- *
- *    TEST CASE TOTAL	: 2
- *
- *    AUTHOR		: Saji Kumar.V.R <saji.kumar@wipro.com>
- *
- *    SIGNALS
- * 	Uses SIGUSR1 to pause before test if option set.
- * 	(See the parse_opts(3) man page).
- *
- *    DESCRIPTION
- *	Verify that
- *	1) getrusage() fails with errno EINVAL when an invalid value
- *	   is given for who
- *	2) getrusage() fails with errno EFAULT when an invalid address
- *	   is given for usage
- *
- * 	Setup:
- * 	  Setup signal handling.
- *	  Pause for SIGUSR1 if option specified.
- *
- * 	Test:
- *	 Loop if the proper options are given.
- * 	  Execute system call
- *	  if call failed with expected errno,
- *		Test Passed
- *	  else
- *		Test Failed
- *
- * 	Cleanup:
- * 	  Print errno log and/or timing stats if options given
+
+/*\
+ *[Description]
  *
- * USAGE:  <for command-line>
- *  getrusage02 [-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.
+ * Verify that
+ * 1) getrusage() fails with errno EINVAL when an invalid value
+ *   is given for who
+ * 2) getrusage() fails with errno EFAULT when an invalid address
+ *   is given for usage
  *
- ****************************************************************/
+ */
 
 #include <errno.h>
 #include <sched.h>
 #include <sys/resource.h>
-#include "test.h"
+#include "tst_test.h"
 
 #ifndef RUSAGE_BOTH		/* Removed from user space on RHEL4 */
 #define RUSAGE_BOTH (-2)	/* still works on SuSE      */
 #endif /* so this is a work around */
 
-static void setup();
-static void cleanup();
-
-char *TCID = "getrusage02";
-
 static struct rusage usage;
 
 struct test_cases_t {
@@ -90,56 +33,25 @@ struct test_cases_t {
 } test_cases[] = {
 	{
 	RUSAGE_BOTH, &usage, EINVAL},
-#ifndef UCLINUX
 	{
 	RUSAGE_SELF, (struct rusage *)-1, EFAULT}
-#endif
 };
 
-int TST_TOTAL = ARRAY_SIZE(test_cases);
-
-int main(int ac, char **av)
+static void verify_getrusage(unsigned int i)
 {
-
-	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++) {
-			TEST(getrusage(test_cases[i].who, test_cases[i].usage));
-
-			if (TEST_RETURN == -1 &&
-			    TEST_ERRNO == test_cases[i].exp_errno)
-				tst_resm(TPASS | TTERRNO,
-					 "getrusage failed as expected");
-			else
-				tst_resm(TFAIL | TTERRNO,
-					 "getrusage failed unexpectedly");
-		}
-	}
-
-	cleanup();
-
-	tst_exit();
-
+		TEST(getrusage(test_cases[i].who, test_cases[i].usage));
+
+		if (TST_RET == -1 &&
+		    TST_ERR == test_cases[i].exp_errno)
+			tst_res(TPASS | TTERRNO,
+				"getrusage failed as expected");
+		else
+			tst_res(TFAIL | TTERRNO,
+				"getrusage failed unexpectedly");
 }
 
-void setup(void)
-{
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-}
-
-void cleanup(void)
-{
-
-}
+static struct tst_test test = {
+	.test = verify_getrusage,
+	.tcnt = ARRAY_SIZE(test_cases),
+	.needs_root = 1,
+};
-- 
2.17.1


  parent reply	other threads:[~2021-06-09 17:35 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-07 10:45 [LTP] [PATCH 1/7] getitimer02: Skipped EFAULT tests for libc variant Vinay Kumar
2021-06-07 10:45 ` [LTP] [PATCH 2/7] getrusage02: " Vinay Kumar
2021-06-07 10:45 ` [LTP] [PATCH 3/7] msgctl04: " Vinay Kumar
2021-06-07 10:45 ` [LTP] [PATCH 4/7] semctl03: " Vinay Kumar
2021-06-07 10:45 ` [LTP] [PATCH 5/7] shmctl02: " Vinay Kumar
2021-06-07 10:45 ` [LTP] [PATCH 6/7] sched_rr_get_interval03: " Vinay Kumar
2021-06-07 10:45 ` [LTP] [PATCH 7/7] setitimer02: " Vinay Kumar
2021-06-08 20:43 ` [LTP] [PATCH 1/7] getitimer02: " Petr Vorel
2021-06-09 17:35   ` [LTP] [PATCH v2 01/10] getitimer02 : Convert getitimer02 to new API Vinay Kumar
2021-06-09 17:35     ` [LTP] [PATCH v2 02/10] getitimer02: Skipped EFAULT tests for libc variant Vinay Kumar
2021-06-11 13:43       ` Cyril Hrubis
2021-06-13 16:54         ` [LTP] [PATCH v3] " Vinay Kumar
2021-06-14 14:22           ` Cyril Hrubis
2021-06-09 17:35     ` Vinay Kumar [this message]
2021-06-11 13:49       ` [LTP] [PATCH v2 03/10] getrusage02: Convert getrusage02 to new API Cyril Hrubis
2021-06-13 17:12         ` [LTP] [PATCH v3] " Vinay Kumar
2021-06-09 17:35     ` [LTP] [PATCH v2 04/10] getrusage02: Skipped EFAULT tests for libc variant Vinay Kumar
2021-06-11 13:50       ` Cyril Hrubis
2021-06-13 17:16         ` [LTP] [PATCH v3] " Vinay Kumar
2021-06-14 14:37           ` Cyril Hrubis
2021-06-14 15:14             ` Vinay Kumar
2021-06-14 14:52               ` Cyril Hrubis
2021-06-09 17:35     ` [LTP] [PATCH v2 05/10] setitimer02: Convert setitimer02 to new API Vinay Kumar
2021-06-11 13:57       ` Cyril Hrubis
2021-06-13 17:30         ` [LTP] [PATCH v3] " Vinay Kumar
2021-06-14 14:44           ` Cyril Hrubis
2021-06-09 17:35     ` [LTP] [PATCH v2 06/10] setitimer02: Skipped EFAULT tests for libc variant Vinay Kumar
2021-06-11 14:00       ` Cyril Hrubis
2021-06-13 17:35         ` [LTP] [PATCH v3] " Vinay Kumar
2021-06-14 14:47           ` Cyril Hrubis
2021-06-09 17:35     ` [LTP] [PATCH v2 07/10] msgctl04: " Vinay Kumar
2021-06-11 14:13       ` Cyril Hrubis
2021-06-09 17:35     ` [LTP] [PATCH v2 08/10] semctl03 :Skipped " Vinay Kumar
2021-06-17 11:34       ` Cyril Hrubis
2021-06-09 17:36     ` [LTP] [PATCH v2 09/10] sched_rr_get_interval03: Skipped " Vinay Kumar
2021-06-11 14:36       ` Cyril Hrubis
2021-06-09 17:36     ` [LTP] [PATCH v2 10/10] shmctl02 :Skipped " Vinay Kumar
2021-06-13 17:49       ` [LTP] [PATCH v3] ipc/shmctl02: Make use of TST_EXP_FAIL() Vinay Kumar
2021-06-14 15:55         ` Vinay Kumar
2021-06-17 11:40         ` Cyril Hrubis
2021-06-17 11:38       ` [LTP] [PATCH v2 10/10] shmctl02 :Skipped EFAULT tests for libc variant Cyril Hrubis
2021-06-11 13:41     ` [LTP] [PATCH v2 01/10] getitimer02 : Convert getitimer02 to new API Cyril Hrubis
2021-06-13 16:43       ` [LTP] [PATCH v3] getitimer02: " Vinay Kumar
2021-06-14 14:19         ` Cyril Hrubis
2021-06-09 17:38   ` [LTP] [PATCH 1/7] getitimer02: Skipped EFAULT tests for libc variant Vinay Kumar

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=20210609173601.29352-3-vinay.m.engg@gmail.com \
    --to=vinay.m.engg@gmail.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.