All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/4] lapi/syscalls: Add syscall numbers for _sysctl
@ 2018-01-26  3:31 Xiao Yang
  2018-01-26  3:31 ` [LTP] [PATCH 2/4] syscalls/sysctl01: Enable && Cleanup Xiao Yang
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Xiao Yang @ 2018-01-26  3:31 UTC (permalink / raw)
  To: ltp

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 include/lapi/syscalls/aarch64.in   | 1 +
 include/lapi/syscalls/arm.in       | 1 +
 include/lapi/syscalls/hppa.in      | 1 +
 include/lapi/syscalls/i386.in      | 1 +
 include/lapi/syscalls/ia64.in      | 1 +
 include/lapi/syscalls/powerpc.in   | 1 +
 include/lapi/syscalls/powerpc64.in | 1 +
 include/lapi/syscalls/s390.in      | 1 +
 include/lapi/syscalls/s390x.in     | 1 +
 include/lapi/syscalls/sh.in        | 1 +
 include/lapi/syscalls/sparc.in     | 1 +
 include/lapi/syscalls/sparc64.in   | 1 +
 include/lapi/syscalls/x86_64.in    | 1 +
 13 files changed, 13 insertions(+)

diff --git a/include/lapi/syscalls/aarch64.in b/include/lapi/syscalls/aarch64.in
index 1f45839..2c8c589 100644
--- a/include/lapi/syscalls/aarch64.in
+++ b/include/lapi/syscalls/aarch64.in
@@ -257,3 +257,4 @@ kcmp 272
 getrandom 278
 memfd_create 279
 copy_file_range 285
+_sysctl 1078
diff --git a/include/lapi/syscalls/arm.in b/include/lapi/syscalls/arm.in
index 1a13661..71a4b71 100644
--- a/include/lapi/syscalls/arm.in
+++ b/include/lapi/syscalls/arm.in
@@ -120,6 +120,7 @@ readv (__NR_SYSCALL_BASE+145)
 writev (__NR_SYSCALL_BASE+146)
 getsid (__NR_SYSCALL_BASE+147)
 fdatasync (__NR_SYSCALL_BASE+148)
+_sysctl (__NR_SYSCALL_BASE+149)
 mlock (__NR_SYSCALL_BASE+150)
 munlock (__NR_SYSCALL_BASE+151)
 mlockall (__NR_SYSCALL_BASE+152)
diff --git a/include/lapi/syscalls/hppa.in b/include/lapi/syscalls/hppa.in
index bb7a694..92aee9f 100644
--- a/include/lapi/syscalls/hppa.in
+++ b/include/lapi/syscalls/hppa.in
@@ -1,3 +1,4 @@
+_sysctl 149
 openat 275
 mkdirat (__NR_openat + 1)
 mknodat (__NR_openat + 2)
diff --git a/include/lapi/syscalls/i386.in b/include/lapi/syscalls/i386.in
index 9cbb139..0f96014 100644
--- a/include/lapi/syscalls/i386.in
+++ b/include/lapi/syscalls/i386.in
@@ -145,6 +145,7 @@ readv 145
 writev 146
 getsid 147
 fdatasync 148
+_sysctl 149
 mlock 150
 munlock 151
 mlockall 152
diff --git a/include/lapi/syscalls/ia64.in b/include/lapi/syscalls/ia64.in
index 1d5b21c..a3abc99 100644
--- a/include/lapi/syscalls/ia64.in
+++ b/include/lapi/syscalls/ia64.in
@@ -118,6 +118,7 @@ readv 1146
 writev 1147
 pread64 1148
 pwrite64 1149
+_sysctl 1150
 mmap 1151
 munmap 1152
 mlock 1153
diff --git a/include/lapi/syscalls/powerpc.in b/include/lapi/syscalls/powerpc.in
index f87192e..11ddca3 100644
--- a/include/lapi/syscalls/powerpc.in
+++ b/include/lapi/syscalls/powerpc.in
@@ -145,6 +145,7 @@ readv 145
 writev 146
 getsid 147
 fdatasync 148
+_sysctl 149
 mlock 150
 munlock 151
 mlockall 152
diff --git a/include/lapi/syscalls/powerpc64.in b/include/lapi/syscalls/powerpc64.in
index f87192e..11ddca3 100644
--- a/include/lapi/syscalls/powerpc64.in
+++ b/include/lapi/syscalls/powerpc64.in
@@ -145,6 +145,7 @@ readv 145
 writev 146
 getsid 147
 fdatasync 148
+_sysctl 149
 mlock 150
 munlock 151
 mlockall 152
diff --git a/include/lapi/syscalls/s390.in b/include/lapi/syscalls/s390.in
index 2526f38..98c861f 100644
--- a/include/lapi/syscalls/s390.in
+++ b/include/lapi/syscalls/s390.in
@@ -107,6 +107,7 @@ readv 145
 writev 146
 getsid 147
 fdatasync 148
+_sysctl 149
 mlock 150
 munlock 151
 mlockall 152
diff --git a/include/lapi/syscalls/s390x.in b/include/lapi/syscalls/s390x.in
index 2526f38..98c861f 100644
--- a/include/lapi/syscalls/s390x.in
+++ b/include/lapi/syscalls/s390x.in
@@ -107,6 +107,7 @@ readv 145
 writev 146
 getsid 147
 fdatasync 148
+_sysctl 149
 mlock 150
 munlock 151
 mlockall 152
diff --git a/include/lapi/syscalls/sh.in b/include/lapi/syscalls/sh.in
index b41b578..c605b14 100644
--- a/include/lapi/syscalls/sh.in
+++ b/include/lapi/syscalls/sh.in
@@ -145,6 +145,7 @@ readv 145
 writev 146
 getsid 147
 fdatasync 148
+_sysctl 149
 mlock 150
 munlock 151
 mlockall 152
diff --git a/include/lapi/syscalls/sparc.in b/include/lapi/syscalls/sparc.in
index 729768b..296d694 100644
--- a/include/lapi/syscalls/sparc.in
+++ b/include/lapi/syscalls/sparc.in
@@ -252,6 +252,7 @@ sched_get_priority_min 247
 sched_rr_get_interval 248
 nanosleep 249
 mremap 250
+_sysctl 251
 getsid 252
 fdatasync 253
 nfsservctl 254
diff --git a/include/lapi/syscalls/sparc64.in b/include/lapi/syscalls/sparc64.in
index 9eb21ee..169347a 100644
--- a/include/lapi/syscalls/sparc64.in
+++ b/include/lapi/syscalls/sparc64.in
@@ -228,6 +228,7 @@ sched_get_priority_min 247
 sched_rr_get_interval 248
 nanosleep 249
 mremap 250
+_sysctl 251
 getsid 252
 fdatasync 253
 nfsservctl 254
diff --git a/include/lapi/syscalls/x86_64.in b/include/lapi/syscalls/x86_64.in
index 29051d4..89db794 100644
--- a/include/lapi/syscalls/x86_64.in
+++ b/include/lapi/syscalls/x86_64.in
@@ -154,6 +154,7 @@ munlockall 152
 vhangup 153
 modify_ldt 154
 pivot_root 155
+_sysctl 156
 prctl 157
 arch_prctl 158
 adjtimex 159
-- 
1.8.3.1




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

* [LTP] [PATCH 2/4] syscalls/sysctl01: Enable && Cleanup
  2018-01-26  3:31 [LTP] [PATCH 1/4] lapi/syscalls: Add syscall numbers for _sysctl Xiao Yang
@ 2018-01-26  3:31 ` Xiao Yang
  2018-01-26  3:31 ` [LTP] [PATCH 3/4] syscalls/sysctl03: " Xiao Yang
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Xiao Yang @ 2018-01-26  3:31 UTC (permalink / raw)
  To: ltp

1) Undefined __NR_sysctl always skips the test even though CONFIG_SYSCTL_SYSCALL
   is built, so enable it by correct __NR__sysctl.
2) Convert to new API.
3) Fix compiler warnings.

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 testcases/kernel/syscalls/sysctl/sysctl01.c | 224 +++++++---------------------
 1 file changed, 57 insertions(+), 167 deletions(-)

diff --git a/testcases/kernel/syscalls/sysctl/sysctl01.c b/testcases/kernel/syscalls/sysctl/sysctl01.c
index c423f47..0a684d0 100644
--- a/testcases/kernel/syscalls/sysctl/sysctl01.c
+++ b/testcases/kernel/syscalls/sysctl/sysctl01.c
@@ -1,196 +1,86 @@
 /*
+ * Copyright (c) International Business Machines  Corp., 2001
+ * Copyright (c) 2018 Xiao Yang <yangx.jy@cn.fujitsu.com>
  *
- *   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 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
+ * 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.
  */
 
 /*
- * NAME
- *	sysctl01.c
- *
- * DESCRIPTION
- *	Testcase for testing the basic functionality of sysctl(2) system call.
- *	This testcase attempts to read the kernel parameters using
- *	sysctl({CTL_KERN, KERN_* }, ...) and compares it with the known
- *	values.
- *
- * USAGE:  <for command-line>
- *  sysctl01 [-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.
- *
- * HISTORY
- *	07/2001 Ported by Wayne Boyer
- *
- * RESTRICTIONS
- *	None
+ * DESCRIPTION:
+ * Testcase for testing the basic functionality of sysctl(2) system call.
+ * This testcase attempts to read the kernel parameters by using
+ * sysctl({CTL_KERN, KERN_* }, ...) and compares it with the known values.
  */
-#include "test.h"
-#include <stdio.h>
+
 #include <errno.h>
-#include <unistd.h>
+#include <stdio.h>
+#include <string.h>
 #include <linux/version.h>
 #include <sys/utsname.h>
 #include <linux/unistd.h>
 #include <linux/sysctl.h>
 
-char *TCID = "sysctl01";
-
-/* This is an older/deprecated syscall that newer arches are omitting */
-#ifdef __NR_sysctl
-
-int TST_TOTAL = 3;
+#include "tst_test.h"
+#include "lapi/syscalls.h"
 
-static int sysctl(int *name, int nlen, void *oldval, size_t * oldlenp,
-		  void *newval, size_t newlen)
-{
-	struct __sysctl_args args =
-	    { name, nlen, oldval, oldlenp, newval, newlen };
-	return syscall(__NR__sysctl, &args);
-}
-
-struct utsname buf;
-char osname[BUFSIZ];
-size_t osnamelth;
+static struct utsname buf;
 
-void setup(void);
-void cleanup(void);
-
-struct test_case_t {
+static struct test_case_t {
 	char *desc;
 	int name[2];
-	int size;
-	char *oldval;
-	size_t *oldlen;
-	void *newval;
-	int newlen;
-	int (*cleanup) ();
-	int exp_retval;
+	char *cmp_str;
 } TC[] = {
-	{
-		"Test for KERN_OSTYPE", {
-	CTL_KERN, KERN_OSTYPE}, 2, osname, &osnamelth, NULL, 0, NULL, 0}, {
-		"Test for KERN_OSRELEASE", {
-	CTL_KERN, KERN_OSRELEASE}, 2,
-		    osname, &osnamelth, NULL, 0, NULL, 0}, {
-		"Test for KERN_VERSION", {
-	CTL_KERN, KERN_VERSION}, 2, osname, &osnamelth, NULL, 0, NULL, 0}
+	{"KERN_OSTYPE", {CTL_KERN, KERN_OSTYPE}, buf.sysname},
+	{"KERN_OSRELEASE", {CTL_KERN, KERN_OSRELEASE}, buf.release},
+	{"KERN_VERSION", {CTL_KERN, KERN_VERSION}, buf.version},
 };
 
-int main(int ac, char **av)
+static void verify_sysctl(unsigned int n)
 {
-	int lc;
-	int i;
-	char *comp_string;
-
-	comp_string = NULL;
-
-	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;
-
-		for (i = 0; i < TST_TOTAL; ++i) {
-
-			osnamelth = sizeof(osname);
-
-			switch (i) {
-			case 0:
-				comp_string = buf.sysname;
-				break;
-			case 1:
-				comp_string = buf.release;
-				break;
-			case 2:
-				comp_string = buf.version;
-				break;
-			}
-
-			TEST(sysctl(TC[i].name, TC[i].size, TC[i].oldval,
-				    TC[i].oldlen, TC[i].newval, TC[i].newlen));
-
-			if (TEST_RETURN != 0) {
-				if (TEST_ERRNO == ENOSYS) {
-					tst_resm(TCONF,
-						 "You may need to make CONFIG_SYSCTL_SYSCALL=y"
-						 " to your kernel config.");
-				} else {
-					tst_resm(TFAIL,
-						 "sysctl(2) failed unexpectedly "
-						 "errno:%d", TEST_ERRNO);
-				}
-				continue;
-			}
-
-			if (strcmp(TC[i].oldval, comp_string) != 0) {
-				tst_resm(TFAIL, "strings don't match - %s : %s",
-					 TC[i].oldval, comp_string);
-			} else {
-				tst_resm(TPASS, "%s is correct", TC[i].desc);
-			}
-			if (TC[i].cleanup) {
-				(void)TC[i].cleanup();
-			}
-		}
+	char osname[BUFSIZ];
+	size_t length = BUFSIZ;
+	struct test_case_t *tc = &TC[n];
+
+	memset(osname, 0, BUFSIZ);
+
+	struct __sysctl_args args = {
+		.name = tc->name,
+		.nlen = ARRAY_SIZE(tc->name),
+		.oldval = osname,
+		.oldlenp = &length,
+	};
+
+	TEST(tst_syscall(__NR__sysctl, &args));
+	if (TEST_RETURN != 0) {
+		tst_res(TFAIL | TTERRNO, "sysctl() failed unexpectedly");
+		return;
 	}
 
-	cleanup();
-	tst_exit();
-}
-
-/*
- * setup() - performs all ONE TIME setup for this test.
- */
-void setup(void)
-{
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	/* get kernel name and information */
-	if (uname(&buf) == -1) {
-		tst_brkm(TBROK, cleanup, "uname() failed");
+	if (strcmp(osname, tc->cmp_str)) {
+		tst_res(TFAIL, "Strings don't match %s : %s",
+			osname, tc->cmp_str);
+	} else {
+		tst_res(TPASS, "Test for %s is correct", tc->desc);
 	}
 }
 
-/*
- * cleanup() - performs all ONE TIME cleanup for this test at
- *	       completion or premature exit.
- */
-void cleanup(void)
+static void setup(void)
 {
-
+	/* get kernel name and information */
+	if (uname(&buf) == -1)
+		tst_brk(TBROK | TERRNO, "uname() failed");
 }
 
-#else
-int TST_TOTAL = 0;
-
-int main(void)
-{
-
-	tst_brkm(TCONF, NULL,
-		 "This test needs a kernel that has sysctl syscall.");
-}
-#endif
+static struct tst_test test = {
+	.setup = setup,
+	.tcnt = ARRAY_SIZE(TC),
+	.test = verify_sysctl,
+};
-- 
1.8.3.1




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

* [LTP] [PATCH 3/4] syscalls/sysctl03: Enable && Cleanup
  2018-01-26  3:31 [LTP] [PATCH 1/4] lapi/syscalls: Add syscall numbers for _sysctl Xiao Yang
  2018-01-26  3:31 ` [LTP] [PATCH 2/4] syscalls/sysctl01: Enable && Cleanup Xiao Yang
@ 2018-01-26  3:31 ` Xiao Yang
  2018-01-26  3:31 ` [LTP] [PATCH 4/4] syscalls/sysctl04,05: " Xiao Yang
  2018-02-12 20:02 ` [LTP] [PATCH 1/4] lapi/syscalls: Add syscall numbers for _sysctl Cyril Hrubis
  3 siblings, 0 replies; 5+ messages in thread
From: Xiao Yang @ 2018-01-26  3:31 UTC (permalink / raw)
  To: ltp

1) Undefined __NR_sysctl always skips the test even though CONFIG_SYSCTL_SYSCALL
   is built, so enable it by correct __NR__sysctl.
2) Convert to new API.
3) Fix compiler warnings and errors.

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 testcases/kernel/syscalls/sysctl/sysctl03.c | 236 ++++++++--------------------
 1 file changed, 67 insertions(+), 169 deletions(-)

diff --git a/testcases/kernel/syscalls/sysctl/sysctl03.c b/testcases/kernel/syscalls/sysctl/sysctl03.c
index 0c8e691..f235aac 100644
--- a/testcases/kernel/syscalls/sysctl/sysctl03.c
+++ b/testcases/kernel/syscalls/sysctl/sysctl03.c
@@ -1,67 +1,41 @@
 /*
+ * Copyright (c) International Business Machines  Corp., 2001
+ * Copyright (c) 2018 Xiao Yang <yangx.jy@cn.fujitsu.com>
  *
- *   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 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
+ * 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.
  */
 
 /*
- * NAME
- *	sysctl03.c
- *
  * DESCRIPTION
- *	Testcase to check that sysctl(2) sets errno to EPERM correctly.
+ * 1) Call sysctl(2) as a root user, and attempt to write data
+ *    to the kernel_table[]. Since the table does not have write
+ *    permissions even for the root, it should fail EPERM.
+ * 2) Call sysctl(2) as a non-root user, and attempt to write data
+ *    to the kernel_table[]. Since the table does not have write
+ *    permission for the regular user, it should fail with EPERM.
  *
- * ALGORITHM
- *	a.	Call sysctl(2) as a root user, and attempt to write data
- *		to the kernel_table[]. Since the table does not have write
- *		permissions even for the root, it should fail EPERM.
- *	b.	Call sysctl(2) as a non-root user, and attempt to write data
- *		to the kernel_table[]. Since the table does not have write
- *		permission for the regular user, it should fail with EPERM.
- *
- * NOTE: There is a documentation bug in 2.6.33-rc1 where unfortunately the
- * behavior of sysctl(2) isn't properly documented, as discussed in detail in
- * the following thread:
+ * NOTE: There is a documentation bug in 2.6.33-rc1 where unfortunately
+ * the behavior of sysctl(2) isn't properly documented, as discussed
+ * in detail in the following thread:
  * http://sourceforge.net/mailarchive/message.php?msg_name=4B7BA24F.2010705%40linux.vnet.ibm.com.
  *
  * The documentation bug is filed as:
- * https://bugzilla.kernel.org/show_bug.cgi?id=15446 . If you want the message
- * removed, please ask your fellow kernel maintainer to fix their documentation.
+ * https://bugzilla.kernel.org/show_bug.cgi?id=15446 . If you want the
+ * message removed, please ask your fellow kernel maintainer to fix their
+ * documentation.
  *
  * Thanks!
  * -Ngie
- *
- * USAGE:  <for command-line>
- *  sysctl03 [-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.
- *
- * HISTORY
- *	07/2001 Ported by Wayne Boyer
- *	02/2010 Updated by shiwh@cn.fujitsu.com
- *
- * RESTRICTIONS
- *	Test must be run as root.
  */
-#include "test.h"
-#include "safe_macros.h"
+
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <stdio.h>
@@ -71,141 +45,65 @@
 #include <linux/sysctl.h>
 #include <pwd.h>
 
-char *TCID = "sysctl03";
-
-/* This is an older/deprecated syscall that newer arches are omitting */
-#ifdef __NR_sysctl
+#include "tst_test.h"
+#include "lapi/syscalls.h"
 
-int TST_TOTAL = 2;
+static int exp_eno;
 
-int sysctl(int *name, int nlen, void *oldval, size_t * oldlenp,
-	   void *newval, size_t newlen)
+static void verify_sysctl(void)
 {
-	struct __sysctl_args args =
-	    { name, nlen, oldval, oldlenp, newval, newlen };
-	return syscall(__NR__sysctl, &args);
-}
-
-#define OSNAMESZ 100
+	char *osname = "Linux";
+	int name[] = {CTL_KERN, KERN_OSTYPE};
+	struct __sysctl_args args = {
+		.name = name,
+		.nlen = ARRAY_SIZE(name),
+		.newval = osname,
+		.newlen = sizeof(osname),
+	};
+
+	TEST(tst_syscall(__NR__sysctl, &args));
+	if (TEST_RETURN != -1) {
+		tst_res(TFAIL, "sysctl(2) succeeded unexpectedly");
+		return;
+	}
 
-void setup(void);
-void cleanup(void);
+	if (TEST_ERRNO == exp_eno)
+		tst_res(TPASS | TTERRNO, "Got expected error");
+	else
+		tst_res(TFAIL | TTERRNO, "Got unexpected error");
+}
 
-int main(int ac, char **av)
+static void setup(void)
 {
-	int exp_eno;
-	int lc;
-
-	char osname[OSNAMESZ];
-	int osnamelth, status;
-	int name[] = { CTL_KERN, KERN_OSTYPE };
-	pid_t pid;
-	struct passwd *ltpuser;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
 	if ((tst_kvercmp(2, 6, 32)) <= 0) {
 		exp_eno = EPERM;
 	} else {
-		/* ^^ Look above this warning. ^^ */
-		tst_resm(TINFO,
+		/* Look above this warning. */
+		tst_res(TINFO,
 			 "this test's results are based on potentially undocumented behavior in the kernel. read the NOTE in the source file for more details");
 		exp_eno = EACCES;
-		exp_enos[0] = EACCES;
 	}
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		/* reset tst_count in case we are looping */
-		tst_count = 0;
-
-		strcpy(osname, "Linux");
-		osnamelth = sizeof(osname);
-
-		TEST(sysctl(name, ARRAY_SIZE(name), 0, 0, osname, osnamelth));
-
-		if (TEST_RETURN != -1) {
-			tst_resm(TFAIL, "sysctl(2) succeeded unexpectedly");
-		} else {
-			if (TEST_ERRNO == exp_eno) {
-				tst_resm(TPASS | TTERRNO, "Got expected error");
-			} else if (errno == ENOSYS) {
-				tst_resm(TCONF,
-					 "You may need to make CONFIG_SYSCTL_SYSCALL=y"
-					 " to your kernel config.");
-			} else {
-				tst_resm(TFAIL | TTERRNO,
-					 "Got unexpected error");
-			}
-		}
-
-		osnamelth = sizeof(osname);
-		if ((ltpuser = getpwnam("nobody")) == NULL) {
-			tst_brkm(TBROK, cleanup, "getpwnam() failed");
-		}
-
-		/* set process ID to "ltpuser1" */
-		SAFE_SETEUID(cleanup, ltpuser->pw_uid);
-
-		if ((pid = FORK_OR_VFORK()) == -1) {
-			tst_brkm(TBROK, cleanup, "fork() failed");
-		}
-
-		if (pid == 0) {
-			TEST(sysctl(name, ARRAY_SIZE(name), 0, 0, osname, osnamelth));
-
-			if (TEST_RETURN != -1) {
-				tst_resm(TFAIL, "call succeeded unexpectedly");
-			} else {
-				if (TEST_ERRNO == exp_eno) {
-					tst_resm(TPASS | TTERRNO,
-						 "Got expected error");
-				} else if (TEST_ERRNO == ENOSYS) {
-					tst_resm(TCONF,
-						 "You may need to make CONFIG_SYSCTL_SYSCALL=y"
-						 " to your kernel config.");
-				} else {
-					tst_resm(TFAIL | TTERRNO,
-						 "Got unexpected error");
-				}
-			}
-
-			cleanup();
-
-		} else {
-			/* wait for the child to finish */
-			wait(&status);
-		}
-
-		/* set process ID back to root */
-		SAFE_SETEUID(cleanup, 0);
-	}
-	cleanup();
-	tst_exit();
 }
 
-void setup(void)
+static void do_test(void)
 {
-	tst_require_root();
-
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-}
+	pid_t pid;
+	struct passwd *ltpuser;
 
-void cleanup(void)
-{
+	pid = SAFE_FORK();
+	if (!pid) {
+		ltpuser = SAFE_GETPWNAM("nobody");
+		SAFE_SETUID(ltpuser->pw_uid);
+		verify_sysctl();
+	} else {
+		SAFE_WAIT(NULL);
+		verify_sysctl();
+	}
 }
 
-#else
-int TST_TOTAL = 0;
-
-int main(void)
-{
-
-	tst_brkm(TCONF, NULL,
-		 "This test needs a kernel that has sysctl syscall.");
-}
-#endif
+static struct tst_test test = {
+	.needs_root = 1,
+	.forks_child = 1,
+	.setup = setup,
+	.test_all = do_test,
+};
-- 
1.8.3.1




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

* [LTP] [PATCH 4/4] syscalls/sysctl04,05: Enable && Cleanup
  2018-01-26  3:31 [LTP] [PATCH 1/4] lapi/syscalls: Add syscall numbers for _sysctl Xiao Yang
  2018-01-26  3:31 ` [LTP] [PATCH 2/4] syscalls/sysctl01: Enable && Cleanup Xiao Yang
  2018-01-26  3:31 ` [LTP] [PATCH 3/4] syscalls/sysctl03: " Xiao Yang
@ 2018-01-26  3:31 ` Xiao Yang
  2018-02-12 20:02 ` [LTP] [PATCH 1/4] lapi/syscalls: Add syscall numbers for _sysctl Cyril Hrubis
  3 siblings, 0 replies; 5+ messages in thread
From: Xiao Yang @ 2018-01-26  3:31 UTC (permalink / raw)
  To: ltp

1) Undefined __NR_sysctl always skips the test even though CONFIG_SYSCTL_SYSCALL
   is built, so enable it by correct __NR__sysctl.
2) Convert to new API.
3) Merge sysctl05 into sysctl04.

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 runtest/ltplite                             |   1 -
 runtest/stress.part3                        |   1 -
 runtest/syscalls                            |   1 -
 testcases/kernel/syscalls/.gitignore        |   1 -
 testcases/kernel/syscalls/sysctl/sysctl04.c | 192 ++++++++-------------------
 testcases/kernel/syscalls/sysctl/sysctl05.c | 193 ----------------------------
 6 files changed, 51 insertions(+), 338 deletions(-)
 delete mode 100644 testcases/kernel/syscalls/sysctl/sysctl05.c

diff --git a/runtest/ltplite b/runtest/ltplite
index 5418495..49d2b11 100644
--- a/runtest/ltplite
+++ b/runtest/ltplite
@@ -915,7 +915,6 @@ sysconf01 sysconf01
 sysctl01 sysctl01
 sysctl03 sysctl03
 sysctl04 sysctl04
-sysctl05 sysctl05
 
 sysfs01 sysfs01
 sysfs02 sysfs02
diff --git a/runtest/stress.part3 b/runtest/stress.part3
index 242b696..004bbad 100644
--- a/runtest/stress.part3
+++ b/runtest/stress.part3
@@ -804,7 +804,6 @@ sysconf01 sysconf01
 sysctl01 sysctl01
 sysctl03 sysctl03
 sysctl04 sysctl04
-sysctl05 sysctl05
 
 sysfs01 sysfs01
 sysfs02 sysfs02
diff --git a/runtest/syscalls b/runtest/syscalls
index 2a4fad0..ca84c10 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -1316,7 +1316,6 @@ sysconf01 sysconf01
 sysctl01 sysctl01
 sysctl03 sysctl03
 sysctl04 sysctl04
-sysctl05 sysctl05
 
 sysfs01 sysfs01
 sysfs02 sysfs02
diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore
index 67211ca..684f5e7 100644
--- a/testcases/kernel/syscalls/.gitignore
+++ b/testcases/kernel/syscalls/.gitignore
@@ -1037,7 +1037,6 @@
 /sysctl/sysctl01
 /sysctl/sysctl03
 /sysctl/sysctl04
-/sysctl/sysctl05
 /sysfs/sysfs01
 /sysfs/sysfs02
 /sysfs/sysfs03
diff --git a/testcases/kernel/syscalls/sysctl/sysctl04.c b/testcases/kernel/syscalls/sysctl/sysctl04.c
index 6339bf2..dff61f8 100644
--- a/testcases/kernel/syscalls/sysctl/sysctl04.c
+++ b/testcases/kernel/syscalls/sysctl/sysctl04.c
@@ -1,166 +1,76 @@
 /*
+ * Copyright (c) International Business Machines  Corp., 200i1
+ * Copyright (c) 2018 Xiao Yang <yangx.jy@cn.fujitsu.com>
  *
- *   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 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
+ * 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.
  */
 
 /*
- * NAME
- *	sysctl04.c
- *
  * DESCRIPTION
- *	Testcase to check that sysctl(2) sets errno to ENOTDIR
- *
- * ALGORITHM
- *	1. Call sysctl(2) with sc_nlen set to 0, and expect ENOTDIR to be set.
- *	2. Call sysctl(2) with sc_nlen greater than CTL_MAXNAME, and expect
- *	   ENOTDIR to be set in the errno.
- *
- * USAGE:  <for command-line>
- *  sysctl04 [-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.
- *
- * HISTORY
- *	07/2001 Ported by Wayne Boyer
- *
- * RESTRICTIONS
- *	None
+ * 1) Call sysctl(2) with nlen set to 0, and expect ENOTDIR.
+ * 2) Call sysctl(2) with nlen greater than CTL_MAXNAME, and expect ENOTDIR.
+ * 3) Call sysctl(2) with the address of oldname outside the address space of
+ *    the process, and expect EFAULT.
+ * 4) Call sysctl(2) with the address of soldval outside the address space of
+ *    the process, and expect EFAULT.
  */
 
-#include "test.h"
 #include <stdio.h>
 #include <errno.h>
 #include <unistd.h>
 #include <linux/unistd.h>
 #include <linux/sysctl.h>
 
-char *TCID = "sysctl04";
-
-/* This is an older/deprecated syscall that newer arches are omitting */
-#ifdef __NR_sysctl
-
-int TST_TOTAL = 2;
+#include "tst_test.h"
+#include "lapi/syscalls.h"
 
-int sysctl(int *name, int nlen, void *oldval, size_t * oldlenp,
-	   void *newval, size_t newlen)
-{
-	struct __sysctl_args args =
-	    { name, nlen, oldval, oldlenp, newval, newlen };
-	return syscall(__NR__sysctl, &args);
-}
+static char osname[BUFSIZ];
+static size_t length = BUFSIZ;
 
-#define OSNAMESZ 100
-
-void setup(void);
-void cleanup(void);
-
-struct test_case_t {
-	int size;
-	int error;
+static struct test_case_t {
+	int name[2];
+	int nlen;
+	void *oldval;
+	size_t *oldlen;
+	int exp_err;
 } TC[] = {
-	/* comment goes here */
-	{
-	0, ENOTDIR},
-	    /* comment goes here */
-	{
-	CTL_MAXNAME + 1, ENOTDIR}
+	{{CTL_KERN, KERN_OSREV}, 0, osname, &length, ENOTDIR},
+	{{CTL_KERN, KERN_OSREV}, CTL_MAXNAME + 1, osname, &length, ENOTDIR},
+	{{CTL_KERN, KERN_OSRELEASE}, 2, (void *) -1, &length, EFAULT},
+	{{CTL_KERN, KERN_VERSION}, 2, osname, (void *) -1, EFAULT},
 };
 
-int main(int ac, char **av)
+static void verify_sysctl(unsigned int n)
 {
-	int lc;
-
-	char osname[OSNAMESZ];
-	int i;
-	size_t osnamelth;
-	int name[] = { CTL_KERN, KERN_OSREV };
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	osnamelth = sizeof(osname);
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		/* reset tst_count in case we are looping */
-		tst_count = 0;
-
-		/* loop through the test cases */
-		for (i = 0; i < TST_TOTAL; i++) {
-
-			TEST(sysctl(name, 0, osname, &osnamelth, 0, 0));
-
-			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 if (TEST_ERRNO == ENOSYS) {
-				tst_resm(TCONF,
-					 "You may need to make CONFIG_SYSCTL_SYSCALL=y"
-					 " to your kernel config.");
-			} else {
-				tst_resm(TFAIL, "unexpected error - %d : %s - "
-					 "expected %d", TEST_ERRNO,
-					 strerror(TEST_ERRNO), TC[i].error);
-			}
-		}
+	struct test_case_t *tc = &TC[n];
+	struct __sysctl_args args = {
+		.name = tc->name,
+		.nlen = tc->nlen,
+		.oldval = tc->oldval,
+		.oldlenp = tc->oldlen,
+	};
+
+	TEST(tst_syscall(__NR__sysctl, &args));
+	if (TEST_RETURN != -1) {
+		tst_res(TFAIL, "sysctl(2) succeeded unexpectedly");
+		return;
 	}
-	cleanup();
-
-	tst_exit();
-}
-
-/*
- * setup() - performs all ONE TIME setup for this test.
- */
-void setup(void)
-{
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-}
-
-/*
- * cleanup() - performs all ONE TIME cleanup for this test at
- *	       completion or premature exit.
- */
-void cleanup(void)
-{
 
+	if (TEST_ERRNO == tc->exp_err)
+		tst_res(TPASS | TTERRNO, "Got expected error");
+	else
+		tst_res(TFAIL | TTERRNO, "Got unexpected error");
 }
 
-#else
-int TST_TOTAL = 0;
-
-int main(void)
-{
-
-	tst_brkm(TCONF, NULL,
-		 "This test needs a kernel that has sysctl syscall.");
-}
-#endif
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(TC),
+	.test = verify_sysctl,
+};
diff --git a/testcases/kernel/syscalls/sysctl/sysctl05.c b/testcases/kernel/syscalls/sysctl/sysctl05.c
deleted file mode 100644
index 85030e7..0000000
--- a/testcases/kernel/syscalls/sysctl/sysctl05.c
+++ /dev/null
@@ -1,193 +0,0 @@
-/*
- *
- *   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
- */
-
-/*
- * NAME
- *	sysctl05.c
- *
- * DESCRIPTION
- *	Testcase to check that sysctl(2) sets errno to EFAULT
- *
- * ALGORITHM
- *	1. Call sysctl(2) with the address of sc_oldname outside the address
- *	   space of the process, and expect EFAULT.
- *	2. Call sysctl(2) with the address of sc_oldval outside the address
- *	   space of the process, and expect EFAULT.
- *
- * USAGE:  <for command-line>
- *  sysctl05 [-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.
- *
- * HISTORY
- *	07/2001 Ported by Wayne Boyer
- *
- * RESTRICTIONS
- *	None
- */
-
-#include "test.h"
-#include <stdio.h>
-#include <unistd.h>
-#include <linux/unistd.h>
-#include <linux/sysctl.h>
-#include <linux/version.h>
-#include <errno.h>
-
-char *TCID = "sysctl05";
-
-/* This is an older/deprecated syscall that newer arches are omitting */
-#ifdef __NR_sysctl
-
-int TST_TOTAL = 2;
-
-int sysctl(int *name, int nlen, void *oldval, size_t * oldlenp,
-	   void *newval, size_t newlen)
-{
-	struct __sysctl_args args =
-	    { name, nlen, oldval, oldlenp, newval, newlen };
-	return syscall(__NR__sysctl, &args);
-}
-
-char osname[BUFSIZ];
-size_t osnamelth;
-
-void setup(void);
-void cleanup(void);
-
-struct testcases {
-	char *desc;
-	int name[2];
-	int size;
-	void *oldval;
-	size_t *oldlen;
-	void *newval;
-	int newlen;
-	int (*cleanup) ();
-	int exp_retval;
-	int exp_errno;
-} testcases[] = {
-	{
-		"Test for EFAULT: invalid oldlen", {
-	CTL_KERN, KERN_OSRELEASE},
-		    2, osname, (void *)-1, NULL, 0, NULL, -1, EFAULT}, {
-		"Test for EFAULT: invalid oldval", {
-	CTL_KERN, KERN_VERSION},
-		    2, (void *)-1, &osnamelth, NULL, 0, NULL, -1, EFAULT}
-};
-
-#if !defined(UCLINUX)
-
-int main(int ac, char **av)
-{
-	int lc;
-	int i;
-	int ret = 0;
-
-	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;
-
-		for (i = 0; i < TST_TOTAL; ++i) {
-
-			osnamelth = sizeof(osname);
-
-			TEST(sysctl(testcases[i].name, testcases[i].size,
-				    testcases[i].oldval, testcases[i].oldlen,
-				    testcases[i].newval, testcases[i].newlen));
-
-			if (TEST_RETURN != testcases[i].exp_retval) {
-				tst_resm(TFAIL, "sysctl(2) returned unexpected "
-					 "retval, expected: %d, got: %d",
-					 testcases[i].exp_retval, ret);
-				continue;
-			}
-
-			if (TEST_ERRNO == ENOSYS) {
-				tst_resm(TCONF,
-					 "You may need to make CONFIG_SYSCTL_SYSCALL=y"
-					 " to your kernel config.");
-			} else if (TEST_ERRNO != testcases[i].exp_errno) {
-				tst_resm(TFAIL, "sysctl(2) returned unexpected "
-					 "errno, expected: %d, got: %d",
-					 testcases[i].exp_errno, errno);
-			} else {
-				tst_resm(TPASS, "sysctl(2) set errno correctly "
-					 "to %d", testcases[i].exp_errno);
-			}
-
-			if (testcases[i].cleanup) {
-				(void)testcases[i].cleanup();
-			}
-		}
-	}
-	cleanup();
-
-	tst_exit();
-}
-
-#else
-
-int main(void)
-{
-	tst_resm(TINFO, "test is not available on uClinux");
-	tst_exit();
-}
-
-#endif /* if !defined(UCLINUX) */
-
-/*
- * setup() - performs all ONE TIME setup for this test.
- */
-void setup(void)
-{
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-}
-
-/*
- * cleanup() - performs all ONE TIME cleanup for this test at
- *	       completion or premature exit.
- */
-void cleanup(void)
-{
-
-}
-
-#else
-int TST_TOTAL = 0;
-
-int main(void)
-{
-
-	tst_brkm(TCONF, NULL,
-		 "This test needs a kernel that has sysctl syscall.");
-}
-#endif
-- 
1.8.3.1




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

* [LTP] [PATCH 1/4] lapi/syscalls: Add syscall numbers for _sysctl
  2018-01-26  3:31 [LTP] [PATCH 1/4] lapi/syscalls: Add syscall numbers for _sysctl Xiao Yang
                   ` (2 preceding siblings ...)
  2018-01-26  3:31 ` [LTP] [PATCH 4/4] syscalls/sysctl04,05: " Xiao Yang
@ 2018-02-12 20:02 ` Cyril Hrubis
  3 siblings, 0 replies; 5+ messages in thread
From: Cyril Hrubis @ 2018-02-12 20:02 UTC (permalink / raw)
  To: ltp

Hi!
Patchset pushed with cosmetic changes (such as printing expected errno
on test failure), thanks.

-- 
Cyril Hrubis
chrubis@suse.cz

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

end of thread, other threads:[~2018-02-12 20:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-26  3:31 [LTP] [PATCH 1/4] lapi/syscalls: Add syscall numbers for _sysctl Xiao Yang
2018-01-26  3:31 ` [LTP] [PATCH 2/4] syscalls/sysctl01: Enable && Cleanup Xiao Yang
2018-01-26  3:31 ` [LTP] [PATCH 3/4] syscalls/sysctl03: " Xiao Yang
2018-01-26  3:31 ` [LTP] [PATCH 4/4] syscalls/sysctl04,05: " Xiao Yang
2018-02-12 20:02 ` [LTP] [PATCH 1/4] lapi/syscalls: Add syscall numbers for _sysctl Cyril Hrubis

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.