All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH 0/5] setdomainname() converted to new API
@ 2019-07-07 19:00 Petr Vorel
  2019-07-07 19:00 ` [LTP] [PATCH 1/5] lib: include <errno.h> in tst_test.h Petr Vorel
                   ` (4 more replies)
  0 siblings, 5 replies; 9+ messages in thread
From: Petr Vorel @ 2019-07-07 19:00 UTC (permalink / raw)
  To: ltp

Hi,

simple to new API + lapi header (fixes for MUSL + (maybe) for Bionic).
Given that sethostname() tests are identical, I'll probably reuse
setdomainname() (compiler time option).

Kind regards,
Petr

Petr Vorel (5):
  lib: include <errno.h> in tst_test.h
  lapi: Add utsname.h
  setdomainname01: Convert to new API
  setdomainname02: Convert to new API
  setdomainname03: Convert to new API

 configure.ac                                  |   1 +
 include/lapi/utsname.h                        |  16 ++
 include/tst_test.h                            |   1 +
 .../syscalls/setdomainname/setdomainname.h    |  58 ++++++
 .../syscalls/setdomainname/setdomainname01.c  | 162 +++-----------
 .../syscalls/setdomainname/setdomainname02.c  | 197 ++++--------------
 .../syscalls/setdomainname/setdomainname03.c  | 195 +++--------------
 7 files changed, 167 insertions(+), 463 deletions(-)
 create mode 100644 include/lapi/utsname.h
 create mode 100644 testcases/kernel/syscalls/setdomainname/setdomainname.h

-- 
2.20.1


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [LTP] [PATCH 1/5] lib: include <errno.h> in tst_test.h
  2019-07-07 19:00 [LTP] [PATCH 0/5] setdomainname() converted to new API Petr Vorel
@ 2019-07-07 19:00 ` Petr Vorel
  2019-07-09 10:55   ` Cyril Hrubis
  2019-07-07 19:00 ` [LTP] [PATCH 2/5] lapi: Add utsname.h Petr Vorel
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 9+ messages in thread
From: Petr Vorel @ 2019-07-07 19:00 UTC (permalink / raw)
  To: ltp

tst_test.h is using errno variable, thus it should include <errno.h>.

Signed-off-by: Petr Vorel <petr.vorel@gmail.com>
---
 include/tst_test.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/tst_test.h b/include/tst_test.h
index 2e8e36352..2e53e68bf 100644
--- a/include/tst_test.h
+++ b/include/tst_test.h
@@ -14,6 +14,7 @@
 #include <unistd.h>
 #include <limits.h>
 #include <string.h>
+#include <errno.h>
 
 #include "tst_common.h"
 #include "tst_res_flags.h"
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [LTP] [PATCH 2/5] lapi: Add utsname.h
  2019-07-07 19:00 [LTP] [PATCH 0/5] setdomainname() converted to new API Petr Vorel
  2019-07-07 19:00 ` [LTP] [PATCH 1/5] lib: include <errno.h> in tst_test.h Petr Vorel
@ 2019-07-07 19:00 ` Petr Vorel
  2019-07-17 16:50   ` Petr Vorel
  2019-07-07 19:00 ` [LTP] [PATCH 3/5] setdomainname01: Convert to new API Petr Vorel
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 9+ messages in thread
From: Petr Vorel @ 2019-07-07 19:00 UTC (permalink / raw)
  To: ltp

Non-standard _UTSNAME_DOMAIN_LENGTH and _UTSNAME_LENGTH constants aren't
defined for MUSL and Bionic.

Signed-off-by: Petr Vorel <petr.vorel@gmail.com>
---
 configure.ac           |  1 +
 include/lapi/utsname.h | 16 ++++++++++++++++
 2 files changed, 17 insertions(+)
 create mode 100644 include/lapi/utsname.h

diff --git a/configure.ac b/configure.ac
index f78db90ce..97991e85f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -57,6 +57,7 @@ AC_CHECK_HEADERS([ \
     sys/prctl.h \
     sys/shm.h \
     sys/ustat.h \
+    sys/utsname.h \
     sys/xattr.h \
 ])
 
diff --git a/include/lapi/utsname.h b/include/lapi/utsname.h
new file mode 100644
index 000000000..6209eac47
--- /dev/null
+++ b/include/lapi/utsname.h
@@ -0,0 +1,16 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2019 Petr Vorel <petr.vorel@gmail.com>
+ */
+
+#ifdef HAVE_SYS_UTSNAME_H
+# include <sys/utsname.h>
+#endif
+
+#ifndef _UTSNAME_LENGTH
+# define _UTSNAME_LENGTH 65
+#endif
+
+#ifndef _UTSNAME_DOMAIN_LENGTH
+# define _UTSNAME_DOMAIN_LENGTH _UTSNAME_LENGTH
+#endif
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [LTP] [PATCH 3/5] setdomainname01: Convert to new API
  2019-07-07 19:00 [LTP] [PATCH 0/5] setdomainname() converted to new API Petr Vorel
  2019-07-07 19:00 ` [LTP] [PATCH 1/5] lib: include <errno.h> in tst_test.h Petr Vorel
  2019-07-07 19:00 ` [LTP] [PATCH 2/5] lapi: Add utsname.h Petr Vorel
@ 2019-07-07 19:00 ` Petr Vorel
  2019-07-07 19:00 ` [LTP] [PATCH 4/5] setdomainname02: " Petr Vorel
  2019-07-07 19:00 ` [LTP] [PATCH 5/5] setdomainname03: " Petr Vorel
  4 siblings, 0 replies; 9+ messages in thread
From: Petr Vorel @ 2019-07-07 19:00 UTC (permalink / raw)
  To: ltp

Functional changes: verify result of setdomainname() with
getdomainname().

Signed-off-by: Petr Vorel <petr.vorel@gmail.com>
---
 .../syscalls/setdomainname/setdomainname.h    |  58 +++++++
 .../syscalls/setdomainname/setdomainname01.c  | 162 +++---------------
 2 files changed, 82 insertions(+), 138 deletions(-)
 create mode 100644 testcases/kernel/syscalls/setdomainname/setdomainname.h

diff --git a/testcases/kernel/syscalls/setdomainname/setdomainname.h b/testcases/kernel/syscalls/setdomainname/setdomainname.h
new file mode 100644
index 000000000..76a72df22
--- /dev/null
+++ b/testcases/kernel/syscalls/setdomainname/setdomainname.h
@@ -0,0 +1,58 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2019 Petr Vorel <petr.vorel@gmail.com>
+ */
+
+#ifndef SETDOMAINNAME_H__
+#define SETDOMAINNAME_H__
+
+#include <string.h>
+#include "lapi/utsname.h"
+#include "lapi/syscalls.h"
+#include "tst_test.h"
+
+#define TST_VALID_DOMAIN_NAME "test_dom"
+
+static char backup[_UTSNAME_DOMAIN_LENGTH];
+
+#define TEST_VARIANTS 2
+
+static void setdomainname_info(void)
+{
+	switch (tst_variant) {
+	case 0:
+		tst_res(TINFO, "Testing libc setdomainname()");
+		break;
+	case 1:
+		tst_res(TINFO, "Testing __NR_setdomainname syscall");
+		break;
+	}
+}
+
+static int do_setdomainname(char *new, size_t len)
+{
+	switch (tst_variant) {
+	case 0:
+		return setdomainname(new, len);
+	break;
+	case 1:
+		return tst_syscall(__NR_setdomainname, new, len);
+	}
+
+	return -1;
+}
+
+static void setup(void)
+{
+	setdomainname_info();
+	if ((getdomainname(backup, sizeof(backup))) < 0)
+		tst_brk(TBROK | TERRNO, "getdomainname() failed");
+}
+
+static void cleanup(void)
+{
+	if ((setdomainname(backup, strlen(backup))) < 0)
+		tst_res(TWARN | TERRNO, "setdomainname() failed ('%s')", backup);
+}
+
+#endif /* SETDOMAINNAME_H__ */
diff --git a/testcases/kernel/syscalls/setdomainname/setdomainname01.c b/testcases/kernel/syscalls/setdomainname/setdomainname01.c
index 7288fca5c..57d58ab42 100644
--- a/testcases/kernel/syscalls/setdomainname/setdomainname01.c
+++ b/testcases/kernel/syscalls/setdomainname/setdomainname01.c
@@ -1,149 +1,35 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
- * 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.
- *
+ * Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved.
+ * Copyright (c) 2019 Petr Vorel <petr.vorel@gmail.com>
+ * Author: Saji Kumar.V.R <saji.kumar@wipro.com>
  */
-/**********************************************************
- *
- *    TEST IDENTIFIER	: setdomainname01
- *
- *    EXECUTED BY	: root / superuser
- *
- *    TEST TITLE	: Basic test for setdomainame(2)
- *
- *    TEST CASE TOTAL	: 1
- *
- *    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
- *	This is a Phase I test for the setdomainname(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.
- *	  Save the current domainname.
- *
- * 	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:
- *	  Restore old domain name.
- * 	  Print errno log and/or timing stats if options given
- *
- * USAGE:  <for command-line>
- *  setdomainname01  [-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 <string.h>
-#include <sys/utsname.h>
-#include "test.h"
+#include "setdomainname.h"
 
-#define MAX_NAME_LEN _UTSNAME_DOMAIN_LENGTH
-
-static void setup();
-static void cleanup();
-
-char *TCID = "setdomainname01";
-int TST_TOTAL = 1;
-
-static char *test_domain_name = "test_dom";
-static char old_domain_name[MAX_NAME_LEN];
-
-int main(int ac, char **av)
+static void do_test(void)
 {
+	char *new = TST_VALID_DOMAIN_NAME;
+	static char tmp[_UTSNAME_DOMAIN_LENGTH];
 
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
+	TEST(do_setdomainname(new, sizeof(new)));
 
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
+	if (TST_RET != 0)
+		tst_brk(TFAIL | TTERRNO, "setdomainname() failed: %d", TST_ERR);
 
-		tst_count = 0;
-
-		/*
-		 * Call setdomainname(2)
-		 */
-		TEST(setdomainname(test_domain_name, sizeof(test_domain_name)));
-
-		/* check return code */
-		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL, "setdomainname() Failed, errno = %d :"
-				 " %s", TEST_ERRNO, strerror(TEST_ERRNO));
-		} else {
-			tst_resm(TPASS, "setdomainname() returned %ld, "
-				 "Domain name set to \"%s\"", TEST_RETURN,
-				 test_domain_name);
-		}
-
-	}
-
-	/* cleanup and exit */
-	cleanup();
-	tst_exit();
+	if (getdomainname(tmp, sizeof(tmp)) != 0)
+		tst_brk(TFAIL | TERRNO, "getdomainname() failed");
 
+	if (strcmp(tmp, new))
+		tst_res(TFAIL, "getdomainname() returned wrong domainname: '%s'", tmp);
+	else
+		tst_res(TPASS, "setdomainname() succeed");
 }
 
-/* setup() - performs all ONE TIME setup for this test */
-void setup(void)
-{
-	tst_require_root();
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	/* Save current domain name */
-	if ((getdomainname(old_domain_name, sizeof(old_domain_name))) < 0) {
-		tst_brkm(TBROK, NULL, "getdomainname() failed while"
-			 " getting current domain name");
-	}
-
-	TEST_PAUSE;
-
-}
-
-/*
- *cleanup() -  performs all ONE TIME cleanup for this test at
- *		completion or premature exit.
- */
-void cleanup(void)
-{
-
-	/* Restore domain name */
-	if ((setdomainname(old_domain_name, strlen(old_domain_name))) < 0) {
-		tst_resm(TWARN, "setdomainname() failed while restoring"
-			 " domainname to \"%s\"", old_domain_name);
-	}
-
-}
+static struct tst_test test = {
+	.needs_root = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = do_test,
+	.test_variants = TEST_VARIANTS,
+};
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [LTP] [PATCH 4/5] setdomainname02: Convert to new API
  2019-07-07 19:00 [LTP] [PATCH 0/5] setdomainname() converted to new API Petr Vorel
                   ` (2 preceding siblings ...)
  2019-07-07 19:00 ` [LTP] [PATCH 3/5] setdomainname01: Convert to new API Petr Vorel
@ 2019-07-07 19:00 ` Petr Vorel
  2019-07-07 19:00 ` [LTP] [PATCH 5/5] setdomainname03: " Petr Vorel
  4 siblings, 0 replies; 9+ messages in thread
From: Petr Vorel @ 2019-07-07 19:00 UTC (permalink / raw)
  To: ltp

Signed-off-by: Petr Vorel <petr.vorel@gmail.com>
---
 .../syscalls/setdomainname/setdomainname02.c  | 197 ++++--------------
 1 file changed, 35 insertions(+), 162 deletions(-)

diff --git a/testcases/kernel/syscalls/setdomainname/setdomainname02.c b/testcases/kernel/syscalls/setdomainname/setdomainname02.c
index 6af09ca40..875ed0c44 100644
--- a/testcases/kernel/syscalls/setdomainname/setdomainname02.c
+++ b/testcases/kernel/syscalls/setdomainname/setdomainname02.c
@@ -1,181 +1,54 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
- * 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
- *
+ * Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved.
+ * Copyright (c) 2019 Petr Vorel <petr.vorel@gmail.com>
+ * Author: Saji Kumar.V.R <saji.kumar@wipro.com>
  */
- /*******************************************************************
- *
- *    TEST IDENTIFIER   : setdomainname02
- *
- *    EXECUTED BY       : root / superuser
- *
- *    TEST TITLE        : test for checking error conditions for setdomainame(2)
- *
- *    TEST CASE TOTAL   : 3
- *
- *    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) setdomainname(2) returns -1 and sets errno to EINVAL if the parameter,
- *	len is less than zero
- *   2) setdomainname(2) returns -1 and sets errno to EINVAL if value of
- *	len is greater than the maximum allowed value
- *   3) setdomainname(2) returns -1 and sets errno to EFAULT for a bad address
- *	for name
- *
- * ALGORITHM
- * Setup:
- *   Setup signal handling.
- *   Pause for SIGUSR1 if option specified.
- *   Save current domainname
- *
- *  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:
- *        Restore old domain name.
- *        Print errno log and/or timing stats if options given
- *  Side Effects :
- *	 setdomainname() is resetting value to NULL, if an invalid address
- *	 is given for name. So, to overcome this problem, domainname is
- *	 resetting to original value as part of cleanup() routine.
- *
- * USAGE:  <for command-line>
- *  setdomainname02  [-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 "test.h"
+#include "setdomainname.h"
 
-#include <errno.h>
-#include <sys/utsname.h>
+#define ERRNO_DESC(x) .exp_errno = x, .errno_desc = #x
 
-#define MAX_NAME_LEN _UTSNAME_DOMAIN_LENGTH - 1
+#define MAX_NAME_LENGTH _UTSNAME_DOMAIN_LENGTH - 1
 
-static void cleanup(void);
-static void setup(void);
-
-char *TCID = "setdomainname02";
-int TST_TOTAL = 3;
-
-static char old_domain_name[MAX_NAME_LEN];
-static struct test_case_t {
+struct test_case {
 	char *desc;
 	char *name;
 	int len;
 	int exp_errno;
-	char err_desc[10];
-} test_cases[] = {
-	{
-	"test with len = -1", "test_dom", -1, EINVAL, "EINVAL"}, {
-	"test with len > allowed maximum", "test_dom", MAX_NAME_LEN + 1,
-		    EINVAL, "EINVAL"}, {
-"test with name = NULL", NULL, MAX_NAME_LEN, EFAULT, "EFAULT"},};
-
-int main(int ac, char **av)
+	char *errno_desc;
+} tcases[] = {
+	{ "len == -1", TST_VALID_DOMAIN_NAME, -1, ERRNO_DESC(EINVAL) },
+	{ "len > allowed maximum", TST_VALID_DOMAIN_NAME, MAX_NAME_LENGTH + 1, ERRNO_DESC(EINVAL) },
+	{ "name == NULL", NULL, MAX_NAME_LENGTH, ERRNO_DESC(EFAULT) }
+};
+
+void verify_setdomainname(unsigned int nr)
 {
-	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;
+	struct test_case *tcase = &tcases[nr];
 
-		for (ind = 0; ind < TST_TOTAL; ind++) {
+	TEST(do_setdomainname(tcase->name, (size_t) tcase->len));
 
-			/*
-			 * call the system call with the TEST() macro
-			 */
-			TEST(setdomainname(test_cases[ind].name,
-					   (size_t) test_cases[ind].len));
-
-			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));
-			}
-		}
+	tst_res(TINFO, "testing %s", tcase->desc);
+	if (TST_RET != -1) {
+		tst_res(TFAIL, "unexpected exit code: %ld", TST_RET);
+		return;
 	}
 
-	cleanup();
-
-	tst_exit();
-
-}
-
-/*
- * setup() - performs all the ONE TIME setup for this test.
- */
-void setup(void)
-{
-	tst_require_root();
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	/* Save current domainname */
-	if ((getdomainname(old_domain_name, MAX_NAME_LEN)) < 0) {
-		tst_brkm(TBROK, NULL, "getdomainname() failed while"
-			 " getting current domain name");
+	if (TST_ERR != tcase->exp_errno) {
+		tst_res(TFAIL | TTERRNO, "unexpected errno: %d, expected: %d",
+			TST_ERR, tcase->exp_errno);
+		return;
 	}
 
-	TEST_PAUSE;
-
+	tst_res(TPASS | TTERRNO, "expected failure");
 }
 
-/*
- * cleanup() - performs all the ONE TIME cleanup for this test at completion
- * 	       or premature exit.
- */
-void cleanup(void)
-{
-
-	/* Restore domain name */
-	if ((setdomainname(old_domain_name, sizeof(old_domain_name)))
-	    < 0) {
-		tst_resm(TWARN, "setdomainname() failed while restoring"
-			 " domainname to \"%s\"", old_domain_name);
-	}
-
-}
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(tcases),
+	.needs_root = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test = verify_setdomainname,
+	.test_variants = TEST_VARIANTS,
+};
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [LTP] [PATCH 5/5] setdomainname03: Convert to new API
  2019-07-07 19:00 [LTP] [PATCH 0/5] setdomainname() converted to new API Petr Vorel
                   ` (3 preceding siblings ...)
  2019-07-07 19:00 ` [LTP] [PATCH 4/5] setdomainname02: " Petr Vorel
@ 2019-07-07 19:00 ` Petr Vorel
  4 siblings, 0 replies; 9+ messages in thread
From: Petr Vorel @ 2019-07-07 19:00 UTC (permalink / raw)
  To: ltp

Use _UTSNAME_LENGTH (65), which is defined in lapi/utsname.h
instead of __NEW_UTS_LEN (64).

Signed-off-by: Petr Vorel <petr.vorel@gmail.com>
---
 .../syscalls/setdomainname/setdomainname03.c  | 195 +++---------------
 1 file changed, 32 insertions(+), 163 deletions(-)

diff --git a/testcases/kernel/syscalls/setdomainname/setdomainname03.c b/testcases/kernel/syscalls/setdomainname/setdomainname03.c
index 82793b878..e53ea8806 100644
--- a/testcases/kernel/syscalls/setdomainname/setdomainname03.c
+++ b/testcases/kernel/syscalls/setdomainname/setdomainname03.c
@@ -1,185 +1,54 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
- * 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
- *
+ * Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved.
+ * Copyright (c) 2019 Petr Vorel <petr.vorel@gmail.com>
+ * Author: Saji Kumar.V.R <saji.kumar@wipro.com>
  */
-/**********************************************************
- *
- *    TEST IDENTIFIER   : setdomainname03
- *
- *    EXECUTED BY       : root / superuser
- *
- *    TEST TITLE        : test for EPERM error value when run as non superuser
- *
- *    TEST CASE TOTAL   : 1
- *
- *    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, setdomainname(2) returns -1 and sets errno to EPERM
- * 	if the effective user id of the caller is not super-user.
- *
- * Algorithm:
- *  Setup:
- *   Setup signal handling.
- *   Pause for SIGUSR1 if option specified.
- *   save current domainname
- *   change effective user id to "nobody" user
- *
- *  Test:
- *   Loop if the proper options are given.
- *   Execute system call
- *   Check return code, 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 fails with unexpected errno.
- *   Otherwise,
- *	Issue sys call returns unexpected value.
- *
- *  Cleanup:
- *   Change effective user id to root
- *   Restore old domainname
- *   Print errno log and/or timing stats if options given
- *
- * Usage:  <for command-line>
- *  setdomainname03 [-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 <string.h>
 #include <errno.h>
 #include <pwd.h>
-#include <linux/utsname.h>
 
-#include "test.h"
+#include "setdomainname.h"
 
-#define MAX_NAME_LEN __NEW_UTS_LEN
-
-char *TCID = "setdomainname03";
-int TST_TOTAL = 1;
-
-static char nobody_uid[] = "nobody";
 struct passwd *ltpuser;
 
-static char test_domain_name[MAX_NAME_LEN] = "test_dom";
-static char old_domain_name[MAX_NAME_LEN];
-
-static void setup();		/* setup function for the tests */
-static void cleanup();		/* cleanup function for the tests */
-
-int main(int ac, char **av)
+static void do_test(void)
 {
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	/*
-	 * Invoke setup function to call individual test setup functions
-	 * for the test which run as root/super-user.
-	 */
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
+	char *new = TST_VALID_DOMAIN_NAME;
 
-		tst_count = 0;
-
-		/*
-		 * Call setdomainname(2)
-		 */
-		TEST(setdomainname(test_domain_name, MAX_NAME_LEN));
-		if ((TEST_RETURN == -1) && (TEST_ERRNO == EPERM)) {
-			tst_resm(TPASS, "expected failure; Got EPERM");
-		} else {
-			tst_resm(TFAIL, "Call failed to produce "
-				 "expected error;  Expected errno: %d "
-				 "Got : %d, %s", EPERM, TEST_ERRNO,
-				 strerror(TEST_ERRNO));
-		}
+	TEST(do_setdomainname(new, sizeof(new)));
 
+	if (TST_RET != -1) {
+		tst_res(TFAIL, "unexpected exit code: %ld", TST_RET);
+		return;
 	}
 
-	/*
-	 * Invoke cleanup() to delete the test directories created
-	 * in the setup().
-	 */
-	cleanup();
-	tst_exit();
+	if (TST_ERR != EPERM) {
+		tst_res(TFAIL | TTERRNO, "unexpected errno: %d, expected: EPERM",
+			TST_ERR);
+		return;
+	}
 
+	tst_res(TPASS | TTERRNO, "expected failure");
 }
 
-/*
- * setup(void) - performs all ONE TIME setup for this test.
- */
-void setup(void)
+void setup_setuid(void)
 {
-	tst_require_root();
-
-	/* Capture unexpected signals */
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	/* Switch to nobody user for correct error code collection */
-	if ((ltpuser = getpwnam(nobody_uid)) == NULL) {
-		tst_brkm(TBROK, NULL, "\"nobody\" user not present");
-	}
-	if (seteuid(ltpuser->pw_uid) == -1) {
-		tst_resm(TWARN, "seteuid failed to "
-			 "to set the effective uid to %d", ltpuser->pw_uid);
-		perror("seteuid");
-	}
-
-	/* Save current domainname */
-	if ((getdomainname(old_domain_name, MAX_NAME_LEN)) < 0) {
-		tst_brkm(TBROK, NULL, "getdomainname() failed while"
-			 " getting current domain name");
-	}
-
-	TEST_PAUSE;
-
+	ltpuser = SAFE_GETPWNAM("nobody");
+	SAFE_SETEUID(ltpuser->pw_uid);
+	setup();
 }
 
-/*
- * cleanup() - Performs all ONE TIME cleanup for this test at
- */
-void cleanup(void)
+static void cleanup_setuid(void)
 {
-
-	/* Set effective user id back to root */
-	if (seteuid(0) == -1) {
-		tst_resm(TWARN, "seteuid failed to "
-			 "to set the effective uid to root");
-		perror("seteuid");
-	}
-
-	/* Restore domain name */
-	if ((setdomainname(old_domain_name, strlen(old_domain_name)))
-	    < 0) {
-		tst_resm(TWARN, "setdomainname() failed while restoring"
-			 " domainname to \"%s\"", old_domain_name);
-	}
-
+	SAFE_SETEUID(0);
+	cleanup();
 }
+
+static struct tst_test test = {
+	.needs_root = 1,
+	.setup = setup_setuid,
+	.cleanup = cleanup_setuid,
+	.test_all = do_test,
+	.test_variants = TEST_VARIANTS,
+};
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [LTP] [PATCH 1/5] lib: include <errno.h> in tst_test.h
  2019-07-07 19:00 ` [LTP] [PATCH 1/5] lib: include <errno.h> in tst_test.h Petr Vorel
@ 2019-07-09 10:55   ` Cyril Hrubis
  2019-07-09 20:51     ` Petr Vorel
  0 siblings, 1 reply; 9+ messages in thread
From: Cyril Hrubis @ 2019-07-09 10:55 UTC (permalink / raw)
  To: ltp

Hi!
> tst_test.h is using errno variable, thus it should include <errno.h>.

Acked, this should have been done quite some time ago...

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [LTP] [PATCH 1/5] lib: include <errno.h> in tst_test.h
  2019-07-09 10:55   ` Cyril Hrubis
@ 2019-07-09 20:51     ` Petr Vorel
  0 siblings, 0 replies; 9+ messages in thread
From: Petr Vorel @ 2019-07-09 20:51 UTC (permalink / raw)
  To: ltp

Hi Cyril,

> Hi!
> > tst_test.h is using errno variable, thus it should include <errno.h>.

> Acked, this should have been done quite some time ago...
Thanks, merged.

Kind regards,
Petr

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [LTP] [PATCH 2/5] lapi: Add utsname.h
  2019-07-07 19:00 ` [LTP] [PATCH 2/5] lapi: Add utsname.h Petr Vorel
@ 2019-07-17 16:50   ` Petr Vorel
  0 siblings, 0 replies; 9+ messages in thread
From: Petr Vorel @ 2019-07-17 16:50 UTC (permalink / raw)
  To: ltp

Hi,

> Non-standard _UTSNAME_DOMAIN_LENGTH and _UTSNAME_LENGTH constants aren't
> defined for MUSL and Bionic.

merged the rest of the patchset.

Kind regards,
Petr

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2019-07-17 16:50 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-07 19:00 [LTP] [PATCH 0/5] setdomainname() converted to new API Petr Vorel
2019-07-07 19:00 ` [LTP] [PATCH 1/5] lib: include <errno.h> in tst_test.h Petr Vorel
2019-07-09 10:55   ` Cyril Hrubis
2019-07-09 20:51     ` Petr Vorel
2019-07-07 19:00 ` [LTP] [PATCH 2/5] lapi: Add utsname.h Petr Vorel
2019-07-17 16:50   ` Petr Vorel
2019-07-07 19:00 ` [LTP] [PATCH 3/5] setdomainname01: Convert to new API Petr Vorel
2019-07-07 19:00 ` [LTP] [PATCH 4/5] setdomainname02: " Petr Vorel
2019-07-07 19:00 ` [LTP] [PATCH 5/5] setdomainname03: " Petr Vorel

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.