All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/5] syscalls/ipc: semctl02: Convert to new API and cleanup
@ 2021-01-06  7:27 Feiyu Zhu
  2021-01-06  7:27 ` [LTP] [PATCH 2/5] syscalls/ipc: semctl03: " Feiyu Zhu
                   ` (4 more replies)
  0 siblings, 5 replies; 11+ messages in thread
From: Feiyu Zhu @ 2021-01-06  7:27 UTC (permalink / raw)
  To: ltp

Also make use of TST_EXP_FAIL

Signed-off-by: Feiyu Zhu <zhufy.jy@cn.fujitsu.com>
---
 testcases/kernel/syscalls/ipc/semctl/Makefile   |   4 +-
 testcases/kernel/syscalls/ipc/semctl/semctl02.c | 155 ++++--------------------
 2 files changed, 28 insertions(+), 131 deletions(-)

diff --git a/testcases/kernel/syscalls/ipc/semctl/Makefile b/testcases/kernel/syscalls/ipc/semctl/Makefile
index c6d8597..f04983d 100644
--- a/testcases/kernel/syscalls/ipc/semctl/Makefile
+++ b/testcases/kernel/syscalls/ipc/semctl/Makefile
@@ -7,7 +7,7 @@ LTPLIBS = ltpipc ltpnewipc
 
 include $(top_srcdir)/include/mk/testcases.mk
 
-semctl01 semctl02 semctl03 semctl04 semctl05 semctl06 semctl07: LTPLDLIBS = -lltpipc
-semctl08 semctl09: LTPLDLIBS = -lltpnewipc
+semctl01 semctl03 semctl04 semctl05 semctl06 semctl07: LTPLDLIBS = -lltpipc
+semctl02 semctl08 semctl09: LTPLDLIBS = -lltpnewipc
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/syscalls/ipc/semctl/semctl02.c b/testcases/kernel/syscalls/ipc/semctl/semctl02.c
index 35051f6..f39b214 100644
--- a/testcases/kernel/syscalls/ipc/semctl/semctl02.c
+++ b/testcases/kernel/syscalls/ipc/semctl/semctl02.c
@@ -1,157 +1,54 @@
+// 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
- */
-
-/*
- * NAME
- *	semctl02.c
+ * Copyright (c) International Business Machines  Corp., 2001
  *
  * DESCRIPTION
  *	semctl02 - test for EACCES error
  *
- * ALGORITHM
- *	create a semaphore set without read/alter permissions
- *	loop if that option was specified
- *	call semctl() attempting an IPC_STAT command
- *	check the errno value
- *	  issue a PASS message if we get EACCES
- *	otherwise, the tests fails
- *	  issue a FAIL message
- *	call cleanup
- *
- * USAGE:  <for command-line>
- *  semctl02 [-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
  *	03/2001 - Written by Wayne Boyer
- *
- * RESTRICTIONS
- *	none
  */
 
-#include "ipcsem.h"
 #include <pwd.h>
+#include "tst_safe_sysv_ipc.h"
+#include "tst_test.h"
+#include "lapi/sem.h"
+#include "libnewipc.h"
 
-char *TCID = "semctl02";
-int TST_TOTAL = 1;
-
-char nobody_uid[] = "nobody";
-struct passwd *ltpuser;
-
-int sem_id_1 = -1;
+static int sem_id = -1;
 
-int main(int ac, char **av)
+static void verify_semctl(void)
 {
-	int lc;
-
 	struct semid_ds sem_ds;
 	union semun un_arg;
 
-	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;
+	un_arg.buf = &sem_ds;
 
-		un_arg.buf = &sem_ds;
-
-		/*
-		 * use the TEST macro to make the call
-		 */
-
-		TEST(semctl(sem_id_1, 0, IPC_STAT, un_arg));
-
-		if (TEST_RETURN != -1) {
-			tst_resm(TFAIL, "call succeeded when error expected");
-			continue;
-		}
-
-		switch (TEST_ERRNO) {
-		case EACCES:
-			tst_resm(TPASS, "expected failure - errno = %d : %s",
-				 TEST_ERRNO, strerror(TEST_ERRNO));
-			break;
-		default:
-			tst_resm(TFAIL, "unexpected error - %d : %s",
-				 TEST_ERRNO, strerror(TEST_ERRNO));
-			break;
-		}
-	}
-
-	cleanup();
-
-	tst_exit();
+	TST_EXP_FAIL(semctl(sem_id, 0, IPC_STAT, un_arg), EACCES,
+		     "semctl(IPC_STAT) with nobody user");
 }
 
-/*
- * setup() - performs all the ONE TIME setup for this test.
- */
-void setup(void)
+static void setup(void)
 {
-	tst_require_root();
+	static key_t semkey;
+	struct passwd *ltpuser = SAFE_GETPWNAM("nobody");
 
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
+	SAFE_SETUID(ltpuser->pw_uid);
 
-	TEST_PAUSE;
+	semkey = GETIPCKEY();
 
-	/* Switch to nobody user for correct error code collection */
-	ltpuser = getpwnam(nobody_uid);
-	if (setuid(ltpuser->pw_uid) == -1) {
-		tst_resm(TINFO, "setuid failed to "
-			 "to set the effective uid to %d", ltpuser->pw_uid);
-		perror("setuid");
-	}
-
-	/*
-	 * Create a temporary directory and cd into it.
-	 * This helps to ensure that a unique msgkey is created.
-	 * See libs/libltpipc/libipc.c for more information.
-	 */
-	tst_tmpdir();
-
-	/* get an IPC resource key */
-	semkey = getipckey();
-
-	/* create a semaphore set without read or alter permissions */
-	if ((sem_id_1 = semget(semkey, PSEMS, IPC_CREAT | IPC_EXCL)) == -1) {
-		tst_brkm(TBROK, cleanup, "couldn't create semaphore in setup");
-	}
+	sem_id = SAFE_SEMGET(semkey, PSEMS, IPC_CREAT | IPC_EXCL);
 }
 
-/*
- * cleanup() - performs all the ONE TIME cleanup for this test at completion
- * 	       or premature exit.
- */
 void cleanup(void)
 {
-	/* if it exists, remove the semaphore resouce */
-	rm_sema(sem_id_1);
-
-	tst_rmdir();
-
+	if (sem_id != -1)
+		SAFE_SEMCTL(sem_id, 0, IPC_RMID);
 }
+
+static struct tst_test test = {
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_root = 1,
+	.test_all = verify_semctl,
+};
-- 
1.8.3.1




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

* [LTP] [PATCH 2/5] syscalls/ipc: semctl03: Convert to new API and cleanup
  2021-01-06  7:27 [LTP] [PATCH 1/5] syscalls/ipc: semctl02: Convert to new API and cleanup Feiyu Zhu
@ 2021-01-06  7:27 ` Feiyu Zhu
  2021-01-26 14:17   ` Cyril Hrubis
  2021-01-06  7:27 ` [LTP] [PATCH 3/5] syscalls/ipc: semctl04: " Feiyu Zhu
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 11+ messages in thread
From: Feiyu Zhu @ 2021-01-06  7:27 UTC (permalink / raw)
  To: ltp

Also make use of TST_EXP_FAIL

Signed-off-by: Feiyu Zhu <zhufy.jy@cn.fujitsu.com>
---
 testcases/kernel/syscalls/ipc/semctl/Makefile   |   4 +-
 testcases/kernel/syscalls/ipc/semctl/semctl03.c | 173 +++++-------------------
 2 files changed, 36 insertions(+), 141 deletions(-)

diff --git a/testcases/kernel/syscalls/ipc/semctl/Makefile b/testcases/kernel/syscalls/ipc/semctl/Makefile
index f04983d..2f64ccf 100644
--- a/testcases/kernel/syscalls/ipc/semctl/Makefile
+++ b/testcases/kernel/syscalls/ipc/semctl/Makefile
@@ -7,7 +7,7 @@ LTPLIBS = ltpipc ltpnewipc
 
 include $(top_srcdir)/include/mk/testcases.mk
 
-semctl01 semctl03 semctl04 semctl05 semctl06 semctl07: LTPLDLIBS = -lltpipc
-semctl02 semctl08 semctl09: LTPLDLIBS = -lltpnewipc
+semctl01 semctl04 semctl05 semctl06 semctl07: LTPLDLIBS = -lltpipc
+semctl02 semctl03 semctl08 semctl09: LTPLDLIBS = -lltpnewipc
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/syscalls/ipc/semctl/semctl03.c b/testcases/kernel/syscalls/ipc/semctl/semctl03.c
index dc851bf..7650355 100644
--- a/testcases/kernel/syscalls/ipc/semctl/semctl03.c
+++ b/testcases/kernel/syscalls/ipc/semctl/semctl03.c
@@ -1,56 +1,18 @@
+// 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
- */
-
-/*
- * NAME
- *	semctl03.c
+ * Copyright (c) International Business Machines  Corp., 2001
  *
  * DESCRIPTION
  *	semctl03 - test for EINVAL and EFAULT errors
  *
- * ALGORITHM
- *	create a semaphore set with read and alter permissions
- *	loop if that option was specified
- *	call semctl() using four different invalid cases
- *	check the errno value
- *	  issue a PASS message if we get EINVAL or EFAULT
- *	otherwise, the tests fails
- *	  issue a FAIL message
- *	call cleanup
- *
- * USAGE:  <for command-line>
- *  semctl03 [-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
  *	03/2001 - Written by Wayne Boyer
- *
- * RESTRICTIONS
- *	none
  */
 
-#include "ipcsem.h"
+#include "tst_safe_sysv_ipc.h"
+#include "tst_test.h"
+#include "lapi/sem.h"
+#include "libnewipc.h"
 
 #ifdef _XLC_COMPILER
 #define SEMUN_CAST
@@ -58,118 +20,51 @@
 #define SEMUN_CAST (union semun)
 #endif
 
-char *TCID = "semctl03";
-int TST_TOTAL = 4;
+static int sem_id = -1;
+static int bad_id = -1;
 
-#ifdef _XLC_COMPILER
-#define SEMUN_CAST
-#else
-#define SEMUN_CAST (union semun)
-#endif
+static struct semid_ds sem_ds;
 
-int sem_id_1 = -1;
-int bad_id = -1;
-
-struct semid_ds sem_ds;
-
-struct test_case_t {
+static struct tcases {
 	int *sem_id;
 	int ipc_cmd;
 	union semun arg;
 	int error;
-} TC[] = {
-	/* EINVAL - the IPC command is not valid */
-	{
-	&sem_id_1, -1, SEMUN_CAST & sem_ds, EINVAL},
-	    /* EINVAL - the semaphore ID is not valid */
-	{
-	&bad_id, IPC_STAT, SEMUN_CAST & sem_ds, EINVAL},
-	    /* EFAULT - the union arg is invalid when expecting "ushort *array" */
-	{
-	&sem_id_1, GETALL, SEMUN_CAST - 1, EFAULT},
-	    /* EFAULT - the union arg is invalid when expecting */
-	    /* "struct semid_ds *buf */
-	{
-	&sem_id_1, IPC_SET, SEMUN_CAST - 1, EFAULT}
+	char *message;
+} tests[] = {
+	{&sem_id, -1, SEMUN_CAST & sem_ds, EINVAL, "invalid IPC command"},
+	{&bad_id, IPC_STAT, SEMUN_CAST & sem_ds, EINVAL, "invalid sem id"},
+	{&sem_id, GETALL, SEMUN_CAST - 1, EFAULT, "invalid union arg"},
+	{&sem_id, IPC_SET, SEMUN_CAST - 1, EFAULT, "invalid union arg"}
 };
 
-int main(int ac, char **av)
+static void verify_semctl(unsigned int n)
 {
-	int lc;
-	int i;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();		/* global setup */
+	struct tcases *tc = &tests[n];
 
-	/* 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 (i = 0; i < TST_TOTAL; i++) {
-
-			TEST(semctl(*(TC[i].sem_id), 0, TC[i].ipc_cmd,
-				    TC[i].arg));
-
-			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",
-					 TEST_ERRNO, strerror(TEST_ERRNO));
-			}
-		}
-	}
-
-	cleanup();
-
-	tst_exit();
+	TST_EXP_FAIL(semctl(*(tc->sem_id), 0, tc->ipc_cmd, tc->arg),
+		     tc->error, "semctl() with %s", tc->message);
 }
 
-/*
- * setup() - performs all the ONE TIME setup for this test.
- */
-void setup(void)
+static void setup(void)
 {
+	static key_t semkey;
 
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
+	semkey = GETIPCKEY();
 
-	TEST_PAUSE;
-
-	/*
-	 * Create a temporary directory and cd into it.
-	 * This helps to ensure that a unique msgkey is created.
-	 * See libs/libltpipc/libipc.c for more information.
-	 */
-	tst_tmpdir();
-
-	/* get an IPC resource key */
-	semkey = getipckey();
-
-	/* create a semaphore set with read and alter permissions */
-	if ((sem_id_1 =
-	     semget(semkey, PSEMS, IPC_CREAT | IPC_EXCL | SEM_RA)) == -1) {
-		tst_brkm(TBROK, cleanup, "couldn't create semaphore in setup");
-	}
+	sem_id = SAFE_SEMGET(semkey, PSEMS, IPC_CREAT | IPC_EXCL | SEM_RA);
 }
 
-/*
- * cleanup() - performs all the ONE TIME cleanup for this test at completion
- * 	       or premature exit.
- */
 void cleanup(void)
 {
-	/* if it exists, remove the semaphore resouce */
-	rm_sema(sem_id_1);
-
-	tst_rmdir();
-
+	if (sem_id != -1)
+		SAFE_SEMCTL(sem_id, 0, IPC_RMID);
 }
+
+static struct tst_test test = {
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_root = 1,
+	.test = verify_semctl,
+	.tcnt = ARRAY_SIZE(tests),
+};
-- 
1.8.3.1




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

* [LTP] [PATCH 3/5] syscalls/ipc: semctl04: Convert to new API and cleanup
  2021-01-06  7:27 [LTP] [PATCH 1/5] syscalls/ipc: semctl02: Convert to new API and cleanup Feiyu Zhu
  2021-01-06  7:27 ` [LTP] [PATCH 2/5] syscalls/ipc: semctl03: " Feiyu Zhu
@ 2021-01-06  7:27 ` Feiyu Zhu
  2021-01-26 15:43   ` Cyril Hrubis
  2021-01-06  7:27 ` [LTP] [PATCH 4/5] syscalls/ipc: semctl05: " Feiyu Zhu
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 11+ messages in thread
From: Feiyu Zhu @ 2021-01-06  7:27 UTC (permalink / raw)
  To: ltp

Also make use of TST_EXP_FAIL

Signed-off-by: Feiyu Zhu <zhufy.jy@cn.fujitsu.com>
---
 testcases/kernel/syscalls/ipc/semctl/Makefile   |   4 +-
 testcases/kernel/syscalls/ipc/semctl/semctl04.c | 212 ++++++------------------
 2 files changed, 49 insertions(+), 167 deletions(-)

diff --git a/testcases/kernel/syscalls/ipc/semctl/Makefile b/testcases/kernel/syscalls/ipc/semctl/Makefile
index 2f64ccf..2a379d9 100644
--- a/testcases/kernel/syscalls/ipc/semctl/Makefile
+++ b/testcases/kernel/syscalls/ipc/semctl/Makefile
@@ -7,7 +7,7 @@ LTPLIBS = ltpipc ltpnewipc
 
 include $(top_srcdir)/include/mk/testcases.mk
 
-semctl01 semctl04 semctl05 semctl06 semctl07: LTPLDLIBS = -lltpipc
-semctl02 semctl03 semctl08 semctl09: LTPLDLIBS = -lltpnewipc
+semctl01 semctl05 semctl06 semctl07: LTPLDLIBS = -lltpipc
+semctl02 semctl03 semctl04 semctl08 semctl09: LTPLDLIBS = -lltpnewipc
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/syscalls/ipc/semctl/semctl04.c b/testcases/kernel/syscalls/ipc/semctl/semctl04.c
index b1f199e..39af8b6 100644
--- a/testcases/kernel/syscalls/ipc/semctl/semctl04.c
+++ b/testcases/kernel/syscalls/ipc/semctl/semctl04.c
@@ -1,200 +1,82 @@
+// 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
- */
-
-/*
- * NAME
- *	semctl04.c
+ * Copyright (c) International Business Machines  Corp., 2001
  *
  * DESCRIPTION
  *	semctl04 - test for EPERM error
  *
- * ALGORITHM
- *	create a semaphore set without read or alter permissions
- *	get the user id for "nobody"
- *	fork a child process
- *	if child
- *	  set the ID of the child process to that of "nobody"
- *	  loop if that option was specified
- *	    call semctl() with two different invalid cases
- *	    check the errno value
- *	      issue a PASS message if we get EPERM
- *	    otherwise, the tests fails
- *	      issue a FAIL message
- *	  call cleanup
- *	if parent
- *	  wait for child to exit
- *	  remove the semaphore set
- *
- * USAGE:  <for command-line>
- *  semctl04 [-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
  *	03/2001 - Written by Wayne Boyer
- *
- * RESTRICTIONS
- *	test must be run as root
  */
 
-#include "ipcsem.h"
-
 #include <pwd.h>
 #include <sys/wait.h>
+#include "tst_safe_sysv_ipc.h"
+#include "tst_test.h"
+#include "lapi/sem.h"
+#include "libnewipc.h"
 
-char *TCID = "semctl04";
-int TST_TOTAL = 2;
+static uid_t ltp_uid;
+static int sem_id = -1;
 
-int sem_id_1 = -1;
+static int tcases[] = { IPC_SET, IPC_RMID };
 
-uid_t ltp_uid;
-char *ltp_user = "nobody";
-
-int TC[] = { IPC_SET, IPC_RMID };
-
-int main(int ac, char **av)
+static void do_child(void)
 {
-	pid_t pid;
-	void do_child(void);
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();		/* global setup */
-
-	if ((pid = FORK_OR_VFORK()) == -1) {
-		tst_brkm(TBROK, cleanup, "could not fork");
-	}
-
-	if (pid == 0) {		/* child */
-		/* set the user ID of the child to the non root user */
-		if (setuid(ltp_uid) == -1) {
-			tst_resm(TBROK, "setuid() failed");
-			exit(1);
-		}
-
-		do_child();
+	int i;
+	union semun arg;
+	struct semid_ds perm;
 
-	} else {
-		if (waitpid(pid, NULL, 0) == -1) {
-			tst_resm(TBROK, "waitpid() failed");
-			tst_resm(TINFO, "waitpid() error = %d : %s", errno,
-				 strerror(errno));
+	for (i = 0; i < 2; i++) {
+		if (tcases[i] == IPC_SET) {
+			arg.buf = &perm;
+			memset(&perm, 0, sizeof(perm));
+			perm.sem_perm.uid = getuid() + 1;
+			perm.sem_perm.gid = getgid() + 1;
+			perm.sem_perm.mode = 0666;
 		}
 
-		/* if it exists, remove the semaphore resouce */
-		rm_sema(sem_id_1);
-
-		tst_rmdir();
+		TST_EXP_FAIL(semctl(sem_id, 0, tcases[i], arg), EPERM,
+			     "semctl() with nobody user in child");
 	}
-	cleanup();
-
-	tst_exit();
 }
 
-/*
- * do_child() - make the TEST call as the child process
- */
-void do_child(void)
+static void verify_semctl(void)
 {
-	int lc;
-	int i;
-	union semun arg;
-	struct semid_ds perm;
-
-	/* 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 (i = 0; i < TST_TOTAL; i++) {
-
-			if (TC[i] == IPC_SET) {
-				arg.buf = &perm;
-				memset(&perm, 0, sizeof perm);
-				perm.sem_perm.uid = getuid() + 1;
-				perm.sem_perm.gid = getgid() + 1;
-				perm.sem_perm.mode = 0666;
-			}
-
-			TEST(semctl(sem_id_1, 0, TC[i], arg));
+	pid_t pid;
 
-			if (TEST_RETURN != -1) {
-				tst_resm(TFAIL, "call succeeded unexpectedly");
-				continue;
-			}
+	pid = SAFE_FORK();
 
-			switch (TEST_ERRNO) {
-			case EPERM:
-				tst_resm(TPASS, "expected failure - errno ="
-					 " %d : %s", TEST_ERRNO,
-					 strerror(TEST_ERRNO));
-				break;
-			default:
-				tst_resm(TFAIL, "unexpected error "
-					 "- %d : %s", TEST_ERRNO,
-					 strerror(TEST_ERRNO));
-				break;
-			}
-		}
+	if (pid == 0) {		/* child */
+		SAFE_SETEUID(ltp_uid);
+		do_child();
+	} else {
+		SAFE_WAITPID(pid, NULL, 0);
 	}
 }
 
-/*
- * setup() - performs all the ONE TIME setup for this test.
- */
-void setup(void)
+static void setup(void)
 {
-	tst_require_root();
-
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
+	static key_t semkey;
 
-	/*
-	 * Create a temporary directory and cd into it.
-	 * This helps to ensure that a unique msgkey is created.
-	 * See libs/libltpipc/libipc.c for more information.
-	 */
-	tst_tmpdir();
+	semkey = GETIPCKEY();
 
-	/* get an IPC resource key */
-	semkey = getipckey();
+	sem_id = SAFE_SEMGET(semkey, PSEMS, IPC_CREAT | IPC_EXCL);
 
-	/* create a semaphore set without read or alter permissions */
-	if ((sem_id_1 = semget(semkey, PSEMS, IPC_CREAT | IPC_EXCL)) == -1) {
-		tst_brkm(TBROK, cleanup, "couldn't create semaphore in setup");
-	}
-
-	/* get the userid for a non root user */
-	ltp_uid = getuserid(ltp_user);
+	struct passwd *ltpuser = SAFE_GETPWNAM("nobody");
+	ltp_uid = ltpuser->pw_uid;
 }
 
-/*
- * cleanup() - performs all the ONE TIME cleanup for this test at completion
- * 	       or premature exit.
- */
-void cleanup(void)
+static void cleanup(void)
 {
-
+	if (sem_id != -1)
+		SAFE_SEMCTL(sem_id, 0, IPC_RMID);
 }
+
+static struct tst_test test = {
+	.setup = setup,
+	.cleanup = cleanup,
+	.forks_child = 1,
+	.needs_root = 1,
+	.test_all = verify_semctl,
+};
-- 
1.8.3.1




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

* [LTP] [PATCH 4/5] syscalls/ipc: semctl05: Convert to new API and cleanup
  2021-01-06  7:27 [LTP] [PATCH 1/5] syscalls/ipc: semctl02: Convert to new API and cleanup Feiyu Zhu
  2021-01-06  7:27 ` [LTP] [PATCH 2/5] syscalls/ipc: semctl03: " Feiyu Zhu
  2021-01-06  7:27 ` [LTP] [PATCH 3/5] syscalls/ipc: semctl04: " Feiyu Zhu
@ 2021-01-06  7:27 ` Feiyu Zhu
  2021-01-26 16:18   ` Cyril Hrubis
  2021-01-06  7:27 ` [LTP] [PATCH 5/5] syscalls/ipc: semctl07: " Feiyu Zhu
  2021-01-26 13:11 ` [LTP] [PATCH 1/5] syscalls/ipc: semctl02: " Cyril Hrubis
  4 siblings, 1 reply; 11+ messages in thread
From: Feiyu Zhu @ 2021-01-06  7:27 UTC (permalink / raw)
  To: ltp

Also make use of TST_EXP_FAIL

Signed-off-by: Feiyu Zhu <zhufy.jy@cn.fujitsu.com>
---
 testcases/kernel/syscalls/ipc/semctl/Makefile   |   4 +-
 testcases/kernel/syscalls/ipc/semctl/semctl05.c | 169 +++++-------------------
 2 files changed, 34 insertions(+), 139 deletions(-)

diff --git a/testcases/kernel/syscalls/ipc/semctl/Makefile b/testcases/kernel/syscalls/ipc/semctl/Makefile
index 2a379d9..4923010 100644
--- a/testcases/kernel/syscalls/ipc/semctl/Makefile
+++ b/testcases/kernel/syscalls/ipc/semctl/Makefile
@@ -7,7 +7,7 @@ LTPLIBS = ltpipc ltpnewipc
 
 include $(top_srcdir)/include/mk/testcases.mk
 
-semctl01 semctl05 semctl06 semctl07: LTPLDLIBS = -lltpipc
-semctl02 semctl03 semctl04 semctl08 semctl09: LTPLDLIBS = -lltpnewipc
+semctl01 semctl06 semctl07: LTPLDLIBS = -lltpipc
+semctl02 semctl03 semctl04 semctl05 semctl08 semctl09: LTPLDLIBS = -lltpnewipc
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/syscalls/ipc/semctl/semctl05.c b/testcases/kernel/syscalls/ipc/semctl/semctl05.c
index 84dace4..86297e2 100644
--- a/testcases/kernel/syscalls/ipc/semctl/semctl05.c
+++ b/testcases/kernel/syscalls/ipc/semctl/semctl05.c
@@ -1,59 +1,19 @@
+// 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) International Business Machines  Corp., 2001
  */
-
 /*
- * NAME
- *	semctl05.c
- *
  * DESCRIPTION
  *	semctl05 - test for ERANGE error
  *
- * ALGORITHM
- *	create a semaphore set with read and alter permissions
- *	loop if that option was specified
- *	call semctl() with three different invalid cases
- *	check the errno value
- *	  issue a PASS message if we get ERANGE
- *	otherwise, the tests fails
- *	  issue a FAIL message
- *	call cleanup
- *
- * USAGE:  <for command-line>
- *  semctl05 [-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
  *	03/2001 - Written by Wayne Boyer
- *
- * RESTRICTIONS
- *	none
  */
 
-#include "ipcsem.h"
-
-char *TCID = "semctl05";
-int TST_TOTAL = 3;
+#include "tst_safe_sysv_ipc.h"
+#include "tst_test.h"
+#include "lapi/sem.h"
+#include "libnewipc.h"
 
 #ifdef _XLC_COMPILER
 #define SEMUN_CAST
@@ -61,118 +21,53 @@ int TST_TOTAL = 3;
 #define SEMUN_CAST (union semun)
 #endif
 
-int sem_id_1 = -1;
+static int sem_id = -1;
 
 #define BIGV	65535		/* a number ((2^16)-1) that should be larger */
 				/* than the maximum for a semaphore value    */
 
-#ifdef _XLC_COMPILER
-#define SEMUN_CAST
-#else
-#define SEMUN_CAST (union semun)
-#endif
-
 unsigned short big_arr[] = { BIGV, BIGV, BIGV, BIGV, BIGV, BIGV, BIGV, BIGV,
 	BIGV, BIGV
 };
 
-struct test_case_t {
+static struct tcases {
 	int count;
 	int cmd;
 	union semun t_arg;
-} TC[] = {
-	/* ERANGE - the value to set is less than zero - SETVAL */
-	{
-	5, SETVAL, SEMUN_CAST - 1},
-	    /* ERANGE - the values to set are too large, > semaphore max value */
-	{
-	0, SETALL, SEMUN_CAST big_arr},
-	    /* ERANGE - the value to set is too large, > semaphore max value */
-	{
-	5, SETVAL, SEMUN_CAST BIGV}
+	char *message;
+} tests[] = {
+	{5, SETVAL, SEMUN_CAST - 1, "the value to set is less than zero"},
+	{0, SETALL, SEMUN_CAST big_arr, "the value to set are too large"},
+	{5, SETVAL, SEMUN_CAST BIGV, "the value to set is too large"}
 };
 
-int main(int ac, char **av)
+static void verify_semctl(unsigned int n)
 {
-	int lc;
-	int i;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();		/* global setup */
+	struct tcases *tc = &tests[n];
 
-	/* 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 (i = 0; i < TST_TOTAL; i++) {
-
-			TEST(semctl(sem_id_1, TC[i].count,
-				    TC[i].cmd, TC[i].t_arg));
-
-			if (TEST_RETURN != -1) {
-				tst_resm(TFAIL, "call succeeded unexpectedly");
-				continue;
-			}
-
-			switch (TEST_ERRNO) {
-			case ERANGE:
-				tst_resm(TPASS, "expected failure - errno = "
-					 "%d : %s", TEST_ERRNO,
-					 strerror(TEST_ERRNO));
-				break;
-			default:
-				tst_resm(TFAIL, "unexpected error "
-					 "- %d : %s", TEST_ERRNO,
-					 strerror(TEST_ERRNO));
-				break;
-			}
-		}
-	}
-
-	cleanup();
-
-	tst_exit();
+	TST_EXP_FAIL(semctl(sem_id, tc->count, tc->cmd, tc->t_arg), ERANGE,
+		     "semctl() with %s", tc->message);
 }
 
-/*
- * setup() - performs all the ONE TIME setup for this test.
- */
-void setup(void)
+static void setup(void)
 {
+	static key_t semkey;
 
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
+	semkey = GETIPCKEY();
 
-	TEST_PAUSE;
-
-	/*
-	 * Create a temporary directory and cd into it.
-	 * This helps to ensure that a unique msgkey is created.
-	 * See libs/libltpipc/libipc.c for more information.
-	 */
-	tst_tmpdir();
-
-	/* get an IPC resource key */
-	semkey = getipckey();
-
-	/* create a semaphore set with read and alter permissions */
-	if ((sem_id_1 =
-	     semget(semkey, PSEMS, IPC_CREAT | IPC_EXCL | SEM_RA)) == -1) {
-		tst_brkm(TBROK, cleanup, "couldn't create semaphore in setup");
-	}
+	sem_id = SAFE_SEMGET(semkey, PSEMS, IPC_CREAT | IPC_EXCL | SEM_RA);
 }
 
-/*
- * cleanup() - performs all the ONE TIME cleanup for this test at completion
- * 	       or premature exit.
- */
-void cleanup(void)
+static void cleanup(void)
 {
-	/* if it exists, remove the semaphore resouce */
-	rm_sema(sem_id_1);
-
-	tst_rmdir();
-
+	if (sem_id != -1)
+		SAFE_SEMCTL(sem_id, 0, IPC_RMID);
 }
+
+static struct tst_test test = {
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_root = 1,
+	.test = verify_semctl,
+	.tcnt = ARRAY_SIZE(tests),
+};
-- 
1.8.3.1




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

* [LTP] [PATCH 5/5] syscalls/ipc: semctl07: Convert to new API and cleanup
  2021-01-06  7:27 [LTP] [PATCH 1/5] syscalls/ipc: semctl02: Convert to new API and cleanup Feiyu Zhu
                   ` (2 preceding siblings ...)
  2021-01-06  7:27 ` [LTP] [PATCH 4/5] syscalls/ipc: semctl05: " Feiyu Zhu
@ 2021-01-06  7:27 ` Feiyu Zhu
  2021-01-27 12:25   ` Cyril Hrubis
  2021-01-26 13:11 ` [LTP] [PATCH 1/5] syscalls/ipc: semctl02: " Cyril Hrubis
  4 siblings, 1 reply; 11+ messages in thread
From: Feiyu Zhu @ 2021-01-06  7:27 UTC (permalink / raw)
  To: ltp

Signed-off-by: Feiyu Zhu <zhufy.jy@cn.fujitsu.com>
---
 testcases/kernel/syscalls/ipc/semctl/Makefile   |   4 +-
 testcases/kernel/syscalls/ipc/semctl/semctl07.c | 179 ++++++++----------------
 2 files changed, 62 insertions(+), 121 deletions(-)

diff --git a/testcases/kernel/syscalls/ipc/semctl/Makefile b/testcases/kernel/syscalls/ipc/semctl/Makefile
index 4923010..7b7a11d 100644
--- a/testcases/kernel/syscalls/ipc/semctl/Makefile
+++ b/testcases/kernel/syscalls/ipc/semctl/Makefile
@@ -7,7 +7,7 @@ LTPLIBS = ltpipc ltpnewipc
 
 include $(top_srcdir)/include/mk/testcases.mk
 
-semctl01 semctl06 semctl07: LTPLDLIBS = -lltpipc
-semctl02 semctl03 semctl04 semctl05 semctl08 semctl09: LTPLDLIBS = -lltpnewipc
+semctl01 semctl06: LTPLDLIBS = -lltpipc
+semctl02 semctl03 semctl04 semctl05 semctl07 semctl08 semctl09: LTPLDLIBS = -lltpnewipc
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/syscalls/ipc/semctl/semctl07.c b/testcases/kernel/syscalls/ipc/semctl/semctl07.c
index 5d7fad3..df92482 100644
--- a/testcases/kernel/syscalls/ipc/semctl/semctl07.c
+++ b/testcases/kernel/syscalls/ipc/semctl/semctl07.c
@@ -1,176 +1,117 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
- *   Copyright (c) International Business Machines  Corp., 2002
- *
- *   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) International Business Machines  Corp., 2002
  */
-
-/* 06/30/2001	Port to Linux	nsharoff@us.ibm.com */
-/* 10/30/2002	Port to LTP	dbarrera@us.ibm.com */
-
 /*
- * NAME
- *	semctl07
- *
- * CALLS
- *	semctl(2) semget(2)
- *
- * ALGORITHM
+ * DESCRIPTION
  *	Get and manipulate a set of semaphores.
  *
- * RESTRICTIONS
- *
  * HISTORY
- *      10/03/2008 Renaud Lottiaux (Renaud.Lottiaux@kerlabs.com)
- *      - Fix concurrency issue. A statically defined key was used. Leading
- *        to conflict with other instances of the same test.
+ *	06/30/2001   Port to Linux   nsharoff@us.ibm.com
+ *	10/30/2002   Port to LTP     dbarrera@us.ibm.com
+ *	10/03/2008 Renaud Lottiaux (Renaud.Lottiaux@kerlabs.com)
+ *	- Fix concurrency issue. A statically defined key was used. Leading
+ *	  to conflict with other instances of the same test.
  */
 
-#include <sys/types.h>
-#include <sys/ipc.h>
 #include <sys/sem.h>
-#include <signal.h>
 #include <errno.h>
 #include <stdio.h>
 #include <sys/wait.h>
-#include "ipcsem.h"
-#include "test.h"
-
-void setup(void);
-void cleanup(void);
-
-char *TCID = "semctl07";
-int TST_TOTAL = 1;
+#include "tst_test.h"
+#include "tst_safe_sysv_ipc.h"
+#include "libnewipc.h"
+#include "lapi/sem.h"
 
-key_t key;
-int semid = -1, nsems;
+static int semid = -1;
+static unsigned long nsems;
 
-int main(int argc, char *argv[])
+static void verify_semctl(void)
 {
 	int status;
 	struct semid_ds buf_ds;
 	union semun arg;
 
-	tst_parse_opts(argc, argv, NULL, NULL);
-
-	setup();
-
 	arg.buf = &buf_ds;
-	if ((status = semctl(semid, 0, IPC_STAT, arg)) == -1) {
-		tst_resm(TFAIL, "semctl() failed errno = %d", errno);
-		semctl(semid, 1, IPC_RMID, arg);
-
-	}
-
-	/*
-	 * Check contents of semid_ds structure.
-	 */
+	status = SAFE_SEMCTL(semid, 0, IPC_STAT, arg);
 
 	if (arg.buf->sem_nsems != nsems) {
-		tst_resm(TFAIL, "error: unexpected number of sems %lu",
+		tst_res(TFAIL, "error: unexpected number of sems %lu",
 			 arg.buf->sem_nsems);
-
 	}
+
 	if (arg.buf->sem_perm.uid != getuid()) {
-		tst_resm(TFAIL, "error: unexpected uid %d",
+		tst_res(TFAIL, "error: unexpected uid %d",
 			 arg.buf->sem_perm.uid);
-
 	}
+
 	if (arg.buf->sem_perm.gid != getgid()) {
-		tst_resm(TFAIL, "error: unexpected gid %d",
+		tst_res(TFAIL, "error: unexpected gid %d",
 			 arg.buf->sem_perm.gid);
-
 	}
+
 	if (arg.buf->sem_perm.cuid != getuid()) {
-		tst_resm(TFAIL, "error: unexpected cuid %d",
+		tst_res(TFAIL, "error: unexpected cuid %d",
 			 arg.buf->sem_perm.cuid);
-
 	}
+
 	if (arg.buf->sem_perm.cgid != getgid()) {
-		tst_resm(TFAIL, "error: unexpected cgid %d",
+		tst_res(TFAIL, "error: unexpected cgid %d",
 			 arg.buf->sem_perm.cgid);
-
 	}
-	if ((status = semctl(semid, 0, GETVAL, arg)) == -1) {
-		tst_resm(TFAIL, "semctl(GETVAL) failed errno = %d", errno);
 
-	}
+	if ((status = semctl(semid, 0, GETVAL, arg)) == -1)
+		tst_res(TFAIL, "semctl(GETVAL) failed errno = %d", errno);
+
 	arg.val = 1;
-	if ((status = semctl(semid, 0, SETVAL, arg)) == -1) {
-		tst_resm(TFAIL, "SEMCTL(SETVAL) failed errno = %d", errno);
+	if ((status = semctl(semid, 0, SETVAL, arg)) == -1)
+		tst_res(TFAIL, "SEMCTL(SETVAL) failed errno = %d", errno);
 
-	}
-	if ((status = semctl(semid, 0, GETVAL, arg)) == -1) {
-		tst_resm(TFAIL, "semctl(GETVAL) failed errno = %d", errno);
+	if ((status = semctl(semid, 0, GETVAL, arg)) == -1)
+		tst_res(TFAIL, "semctl(GETVAL) failed errno = %d", errno);
 
-	}
-	if (status != arg.val) {
-		tst_resm(TFAIL, "error: unexpected value %d", status);
+	if (status != arg.val)
+		tst_res(TFAIL, "error: unexpected value %d", status);
 
-	}
-	if ((status = semctl(semid, 0, GETPID, arg)) == -1) {
-		tst_resm(TFAIL, "semctl(GETPID) failed errno = %d", errno);
+	if ((status = semctl(semid, 0, GETPID, arg)) == -1)
+		tst_res(TFAIL, "semctl(GETPID) failed errno = %d", errno);
 
-	}
 	status = getpid();
-	if (status == 0) {
-		tst_resm(TFAIL, "error: unexpected pid %d", status);
+	if (status == 0)
+		tst_res(TFAIL, "error: unexpected pid %d", status);
 
-	}
-	if ((status = semctl(semid, 0, GETNCNT, arg)) == -1) {
-		tst_resm(TFAIL, "semctl(GETNCNT) failed errno = %d", errno);
+	if ((status = semctl(semid, 0, GETNCNT, arg)) == -1)
+		tst_res(TFAIL, "semctl(GETNCNT) failed errno = %d", errno);
 
-	}
-	if (status != 0) {
-		tst_resm(TFAIL, "error: unexpected semncnt %d", status);
+	if (status != 0)
+		tst_res(TFAIL, "error: unexpected semncnt %d", status);
 
-	}
-	if ((status = semctl(semid, 0, GETZCNT, arg)) == -1) {
-		tst_resm(TFAIL, "semctl(GETZCNT) failed errno = %d", errno);
-
-	}
-	if (status != 0) {
-		tst_resm(TFAIL, "error: unexpected semzcnt %d", status);
-
-	}
+	if ((status = semctl(semid, 0, GETZCNT, arg)) == -1)
+		tst_res(TFAIL, "semctl(GETZCNT) failed errno = %d", errno);
 
-	tst_resm(TPASS, "semctl07 ran successfully!");
+	if (status != 0)
+		tst_res(TFAIL, "error: unexpected semzcnt %d", status);
 
-	cleanup();
-	tst_exit();
+	tst_res(TPASS, "semctl07 ran successfully!");
 }
 
-void setup(void)
+static void setup(void)
 {
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	/* get an IPC resource key */
-	key = getipckey();
+	key_t key = GETIPCKEY();
 	nsems = 1;
 
-	if ((semid = semget(key, nsems, SEM_RA | IPC_CREAT)) == -1) {
-		tst_brkm(TFAIL, NULL, "semget() failed errno = %d", errno);
-	}
+	semid = SAFE_SEMGET(key, nsems, SEM_RA | IPC_CREAT);
 }
 
-void cleanup(void)
+static void cleanup(void)
 {
-	rm_sema(semid);
-	tst_rmdir();
+	if (semid != -1)
+		SAFE_SEMCTL(semid, 0, IPC_RMID);
 }
+
+static struct tst_test test = {
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_root = 1,
+	.test_all = verify_semctl,
+};
-- 
1.8.3.1




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

* [LTP] [PATCH 1/5] syscalls/ipc: semctl02: Convert to new API and cleanup
  2021-01-06  7:27 [LTP] [PATCH 1/5] syscalls/ipc: semctl02: Convert to new API and cleanup Feiyu Zhu
                   ` (3 preceding siblings ...)
  2021-01-06  7:27 ` [LTP] [PATCH 5/5] syscalls/ipc: semctl07: " Feiyu Zhu
@ 2021-01-26 13:11 ` Cyril Hrubis
  4 siblings, 0 replies; 11+ messages in thread
From: Cyril Hrubis @ 2021-01-26 13:11 UTC (permalink / raw)
  To: ltp

Hi!
>   *
>   * DESCRIPTION
>   *	semctl02 - test for EACCES error

I've reformatted this comment so that it's picked up by the
documentation parser and pushed, thanks.

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH 2/5] syscalls/ipc: semctl03: Convert to new API and cleanup
  2021-01-06  7:27 ` [LTP] [PATCH 2/5] syscalls/ipc: semctl03: " Feiyu Zhu
@ 2021-01-26 14:17   ` Cyril Hrubis
  0 siblings, 0 replies; 11+ messages in thread
From: Cyril Hrubis @ 2021-01-26 14:17 UTC (permalink / raw)
  To: ltp

Hi!
Pushed with a few changes, thanks.

* Reformatted the description comment for docparser

* Got rid of the IBM XLC compiler hack

* Return value from tst_get_bad_addr() is used for EFAULT instead of -1

* Removed needs_root = 1 as the test does not need root at all

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH 3/5] syscalls/ipc: semctl04: Convert to new API and cleanup
  2021-01-06  7:27 ` [LTP] [PATCH 3/5] syscalls/ipc: semctl04: " Feiyu Zhu
@ 2021-01-26 15:43   ` Cyril Hrubis
  0 siblings, 0 replies; 11+ messages in thread
From: Cyril Hrubis @ 2021-01-26 15:43 UTC (permalink / raw)
  To: ltp

Hi!
Pushed with a minor change, thanks.

I've changed the description comment so that it's picked up by the
docparser here as well.

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH 4/5] syscalls/ipc: semctl05: Convert to new API and cleanup
  2021-01-06  7:27 ` [LTP] [PATCH 4/5] syscalls/ipc: semctl05: " Feiyu Zhu
@ 2021-01-26 16:18   ` Cyril Hrubis
  0 siblings, 0 replies; 11+ messages in thread
From: Cyril Hrubis @ 2021-01-26 16:18 UTC (permalink / raw)
  To: ltp

Hi!
Pushed with a minor changes, thanks.

- Reformated the test description for docparser

- Got rid of the XLC compiler workaround

- Removed .needs_root

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH 5/5] syscalls/ipc: semctl07: Convert to new API and cleanup
  2021-01-06  7:27 ` [LTP] [PATCH 5/5] syscalls/ipc: semctl07: " Feiyu Zhu
@ 2021-01-27 12:25   ` Cyril Hrubis
  2021-01-28  9:52     ` Zhu Feiyu
  0 siblings, 1 reply; 11+ messages in thread
From: Cyril Hrubis @ 2021-01-27 12:25 UTC (permalink / raw)
  To: ltp

Hi!
> - * ALGORITHM
> + * DESCRIPTION
>   *	Get and manipulate a set of semaphores.
>   *
> - * RESTRICTIONS
> - *
>   * HISTORY
> - *      10/03/2008 Renaud Lottiaux (Renaud.Lottiaux@kerlabs.com)
> - *      - Fix concurrency issue. A statically defined key was used. Leading
> - *        to conflict with other instances of the same test.
> + *	06/30/2001   Port to Linux   nsharoff@us.ibm.com
> + *	10/30/2002   Port to LTP     dbarrera@us.ibm.com
> + *	10/03/2008 Renaud Lottiaux (Renaud.Lottiaux@kerlabs.com)
> + *	- Fix concurrency issue. A statically defined key was used. Leading
> + *	  to conflict with other instances of the same test.
>   */

The description should be changed into the docparser format and also bit
more verbose something as:

/*\
 * [DESCRIPTION]
 *
 * Basic tests for semctl().
 *
 * - semctl() with IPC_STAT where we check the semid_ds buf content
 * - semctl() with SETVAL and GETVAL
 * - semctl() with GETPID
 * - semctl() with GETNCNT and GETZCNT
\*/


> -#include <sys/types.h>
> -#include <sys/ipc.h>
>  #include <sys/sem.h>
> -#include <signal.h>
>  #include <errno.h>
>  #include <stdio.h>
>  #include <sys/wait.h>
> -#include "ipcsem.h"
> -#include "test.h"
> -
> -void setup(void);
> -void cleanup(void);
> -
> -char *TCID = "semctl07";
> -int TST_TOTAL = 1;
> +#include "tst_test.h"
> +#include "tst_safe_sysv_ipc.h"
> +#include "libnewipc.h"
> +#include "lapi/sem.h"
>  
> -key_t key;
> -int semid = -1, nsems;
> +static int semid = -1;
> +static unsigned long nsems;
>  
> -int main(int argc, char *argv[])
> +static void verify_semctl(void)
>  {
>  	int status;
>  	struct semid_ds buf_ds;
>  	union semun arg;
>  
> -	tst_parse_opts(argc, argv, NULL, NULL);
> -
> -	setup();
> -
>  	arg.buf = &buf_ds;
> -	if ((status = semctl(semid, 0, IPC_STAT, arg)) == -1) {
> -		tst_resm(TFAIL, "semctl() failed errno = %d", errno);
> -		semctl(semid, 1, IPC_RMID, arg);
> -
> -	}
> -
> -	/*
> -	 * Check contents of semid_ds structure.
> -	 */
> +	status = SAFE_SEMCTL(semid, 0, IPC_STAT, arg);
>  
>  	if (arg.buf->sem_nsems != nsems) {
> -		tst_resm(TFAIL, "error: unexpected number of sems %lu",
> +		tst_res(TFAIL, "error: unexpected number of sems %lu",
>  			 arg.buf->sem_nsems);
> -
>  	}
> +
>  	if (arg.buf->sem_perm.uid != getuid()) {
> -		tst_resm(TFAIL, "error: unexpected uid %d",
> +		tst_res(TFAIL, "error: unexpected uid %d",
>  			 arg.buf->sem_perm.uid);
> -
>  	}
> +
>  	if (arg.buf->sem_perm.gid != getgid()) {
> -		tst_resm(TFAIL, "error: unexpected gid %d",
> +		tst_res(TFAIL, "error: unexpected gid %d",
>  			 arg.buf->sem_perm.gid);
> -
>  	}
> +
>  	if (arg.buf->sem_perm.cuid != getuid()) {
> -		tst_resm(TFAIL, "error: unexpected cuid %d",
> +		tst_res(TFAIL, "error: unexpected cuid %d",
>  			 arg.buf->sem_perm.cuid);
> -
>  	}
> +
>  	if (arg.buf->sem_perm.cgid != getgid()) {
> -		tst_resm(TFAIL, "error: unexpected cgid %d",
> +		tst_res(TFAIL, "error: unexpected cgid %d",
>  			 arg.buf->sem_perm.cgid);
> -
>  	}
> -	if ((status = semctl(semid, 0, GETVAL, arg)) == -1) {
> -		tst_resm(TFAIL, "semctl(GETVAL) failed errno = %d", errno);
>  
> -	}
> +	if ((status = semctl(semid, 0, GETVAL, arg)) == -1)
> +		tst_res(TFAIL, "semctl(GETVAL) failed errno = %d", errno);
> +
>  	arg.val = 1;
> -	if ((status = semctl(semid, 0, SETVAL, arg)) == -1) {
> -		tst_resm(TFAIL, "SEMCTL(SETVAL) failed errno = %d", errno);
> +	if ((status = semctl(semid, 0, SETVAL, arg)) == -1)
> +		tst_res(TFAIL, "SEMCTL(SETVAL) failed errno = %d", errno);
>  
> -	}
> -	if ((status = semctl(semid, 0, GETVAL, arg)) == -1) {
> -		tst_resm(TFAIL, "semctl(GETVAL) failed errno = %d", errno);
> +	if ((status = semctl(semid, 0, GETVAL, arg)) == -1)
> +		tst_res(TFAIL, "semctl(GETVAL) failed errno = %d", errno);
>  
> -	}
> -	if (status != arg.val) {
> -		tst_resm(TFAIL, "error: unexpected value %d", status);
> +	if (status != arg.val)
> +		tst_res(TFAIL, "error: unexpected value %d", status);
>  
> -	}
> -	if ((status = semctl(semid, 0, GETPID, arg)) == -1) {
> -		tst_resm(TFAIL, "semctl(GETPID) failed errno = %d", errno);
> +	if ((status = semctl(semid, 0, GETPID, arg)) == -1)
> +		tst_res(TFAIL, "semctl(GETPID) failed errno = %d", errno);
>  
> -	}
>  	status = getpid();
> -	if (status == 0) {
> -		tst_resm(TFAIL, "error: unexpected pid %d", status);
> +	if (status == 0)
> +		tst_res(TFAIL, "error: unexpected pid %d", status);

This seems to be completely bogus, we should actually check here that
the value of status is equal to getpid().

Also this and a few other operations do not need arg to be passed as
last argument. Basically all the GET operations that return the value
directly in the return value does not need arg to be passed.

> -	}
> -	if ((status = semctl(semid, 0, GETNCNT, arg)) == -1) {
> -		tst_resm(TFAIL, "semctl(GETNCNT) failed errno = %d", errno);
> +	if ((status = semctl(semid, 0, GETNCNT, arg)) == -1)
> +		tst_res(TFAIL, "semctl(GETNCNT) failed errno = %d", errno);
>  
> -	}
> -	if (status != 0) {
> -		tst_resm(TFAIL, "error: unexpected semncnt %d", status);
> +	if (status != 0)
> +		tst_res(TFAIL, "error: unexpected semncnt %d", status);
>  
> -	}
> -	if ((status = semctl(semid, 0, GETZCNT, arg)) == -1) {
> -		tst_resm(TFAIL, "semctl(GETZCNT) failed errno = %d", errno);
> -
> -	}
> -	if (status != 0) {
> -		tst_resm(TFAIL, "error: unexpected semzcnt %d", status);
> -
> -	}
> +	if ((status = semctl(semid, 0, GETZCNT, arg)) == -1)
> +		tst_res(TFAIL, "semctl(GETZCNT) failed errno = %d", errno);
>  
> -	tst_resm(TPASS, "semctl07 ran successfully!");
> +	if (status != 0)
> +		tst_res(TFAIL, "error: unexpected semzcnt %d", status);
>  
> -	cleanup();
> -	tst_exit();
> +	tst_res(TPASS, "semctl07 ran successfully!");

This part is broken. We do issue the TPASS here even if one of the above
statement issued TFAIL.

So we either change the code to produce TPASS/TFAIL pair on each check
e.g.

	if (status != arg.val) {
		tst_res(TFAIL, "semctl(GETVAL) returned %d expected %d",
		        arg.val, status);
	} else {
		tst_res(TPASS, "semctl(GETVAL) returned %d", arg.val);
	}

Or we have to maintain flag that is set to non-zero on any failure and
then we can, at the end of the test do:

	if (!flag)
		tst_res(TPASS, "everything is fine");

>  }
>  
> -void setup(void)
> +static void setup(void)
>  {
> -	tst_sig(NOFORK, DEF_HANDLER, cleanup);
> -
> -	TEST_PAUSE;
> -
> -	tst_tmpdir();
> -
> -	/* get an IPC resource key */
> -	key = getipckey();
> +	key_t key = GETIPCKEY();
>  	nsems = 1;
>  
> -	if ((semid = semget(key, nsems, SEM_RA | IPC_CREAT)) == -1) {
> -		tst_brkm(TFAIL, NULL, "semget() failed errno = %d", errno);
> -	}
> +	semid = SAFE_SEMGET(key, nsems, SEM_RA | IPC_CREAT);
>  }
>  
> -void cleanup(void)
> +static void cleanup(void)
>  {
> -	rm_sema(semid);
> -	tst_rmdir();
> +	if (semid != -1)
> +		SAFE_SEMCTL(semid, 0, IPC_RMID);
>  }
> +
> +static struct tst_test test = {
> +	.setup = setup,
> +	.cleanup = cleanup,
> +	.needs_root = 1,
> +	.test_all = verify_semctl,
> +};
> -- 
> 1.8.3.1
> 
> 
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH 5/5] syscalls/ipc: semctl07: Convert to new API and cleanup
  2021-01-27 12:25   ` Cyril Hrubis
@ 2021-01-28  9:52     ` Zhu Feiyu
  0 siblings, 0 replies; 11+ messages in thread
From: Zhu Feiyu @ 2021-01-28  9:52 UTC (permalink / raw)
  To: ltp

Hi Cyril,

>
> This part is broken. We do issue the TPASS here even if one of the above
> statement issued TFAIL.
>
> So we either change the code to produce TPASS/TFAIL pair on each check
> e.g.
>
> 	if (status != arg.val) {
> 		tst_res(TFAIL, "semctl(GETVAL) returned %d expected %d",
> 		        arg.val, status);
> 	} else {
> 		tst_res(TPASS, "semctl(GETVAL) returned %d", arg.val);
> 	}
>
> Or we have to maintain flag that is set to non-zero on any failure and
> then we can, at the end of the test do:
>
> 	if (!flag)
> 		tst_res(TPASS, "everything is fine");
>

Thanks for your review, I have sent v2.

Best Regards
Feiyu Zhu



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

end of thread, other threads:[~2021-01-28  9:52 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-06  7:27 [LTP] [PATCH 1/5] syscalls/ipc: semctl02: Convert to new API and cleanup Feiyu Zhu
2021-01-06  7:27 ` [LTP] [PATCH 2/5] syscalls/ipc: semctl03: " Feiyu Zhu
2021-01-26 14:17   ` Cyril Hrubis
2021-01-06  7:27 ` [LTP] [PATCH 3/5] syscalls/ipc: semctl04: " Feiyu Zhu
2021-01-26 15:43   ` Cyril Hrubis
2021-01-06  7:27 ` [LTP] [PATCH 4/5] syscalls/ipc: semctl05: " Feiyu Zhu
2021-01-26 16:18   ` Cyril Hrubis
2021-01-06  7:27 ` [LTP] [PATCH 5/5] syscalls/ipc: semctl07: " Feiyu Zhu
2021-01-27 12:25   ` Cyril Hrubis
2021-01-28  9:52     ` Zhu Feiyu
2021-01-26 13:11 ` [LTP] [PATCH 1/5] syscalls/ipc: semctl02: " 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.