All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH v1 1/2] Refactor pidns01 test using new LTP API
@ 2022-08-04  8:48 Andrea Cervesato via ltp
  2022-08-04  8:48 ` [LTP] [PATCH v1 2/2] Refactor pidns02 " Andrea Cervesato via ltp
  2022-08-05 13:01 ` [LTP] [PATCH v1 1/2] Refactor pidns01 " Cyril Hrubis
  0 siblings, 2 replies; 4+ messages in thread
From: Andrea Cervesato via ltp @ 2022-08-04  8:48 UTC (permalink / raw)
  To: ltp

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
 testcases/kernel/containers/pidns/pidns01.c | 131 +++++---------------
 1 file changed, 29 insertions(+), 102 deletions(-)

diff --git a/testcases/kernel/containers/pidns/pidns01.c b/testcases/kernel/containers/pidns/pidns01.c
index ac702dd14..0633bb07d 100644
--- a/testcases/kernel/containers/pidns/pidns01.c
+++ b/testcases/kernel/containers/pidns/pidns01.c
@@ -1,118 +1,45 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
-* Copyright (c) International Business Machines Corp., 2007
-* 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
-*
-***************************************************************************
-
-* File: pidns01.c
-*
-* Description:
-*  The pidns01.c testcase builds into the ltp framework to verify
-*  the basic functionality of PID Namespace.
-*
-* Verify that:
-* 1. When parent clone a process with flag CLONE_NEWPID, the process ID of
-* child should be always one.
-*
-* 2. When parent clone a process with flag CLONE_NEWPID, the parent process ID of
-* should be always zero.
-*
-* Total Tests:
-*
-* Test Name: pidns01
-*
-* Test Assertion & Strategy:
-*
-* From main() clone a new child process with passing the clone_flag as CLONE_NEWPID,
-* Inside the cloned pid check for the getpid() and getppid()
-* Verify with global macro defined value for parent pid & child pid.
-*
-* Usage: <for command-line>
-* pidns01
-*
-* History:
-*
-* FLAG DATE		NAME			DESCRIPTION
-* 27/12/07  RISHIKESH K RAJAK <risrajak@in.ibm.com> Created this test
-*
-*******************************************************************************************/
-#define _GNU_SOURCE
-#include <sys/wait.h>
-#include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <errno.h>
-#include "pidns_helper.h"
-#include "test.h"
+ * Copyright (c) International Business Machines Corp., 2007
+ *               27/12/07  Rishikesh K Rajak <risrajak@in.ibm.com>
+ * Copyright (C) 2022 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
 
-char *TCID = "pidns01";
-int TST_TOTAL = 1;
+/*\
+ * [Description]
+ *
+ * Clone a process with CLONE_NEWPID flag and check:
+ *
+ * - child process ID must be 1
+ * - parent process ID must be 0
+ */
 
-#define CHILD_PID       1
-#define PARENT_PID      0
+#include "tst_test.h"
+#include "lapi/namespaces_constants.h"
 
-/*
- * child_fn1() - Inside container
- */
-int child_fn1(void *ttype LTP_ATTRIBUTE_UNUSED)
+static int child_func(LTP_ATTRIBUTE_UNUSED void *arg)
 {
-	int exit_val;
 	pid_t cpid, ppid;
+
 	cpid = getpid();
 	ppid = getppid();
 
-	tst_resm(TINFO, "PIDNS test is running inside container");
-	if (cpid == CHILD_PID && ppid == PARENT_PID) {
-		printf("Got expected cpid and ppid\n");
-		exit_val = 0;
-	} else {
-		printf("Got unexpected result of cpid=%d ppid=%d\n",
-		       cpid, ppid);
-		exit_val = 1;
-	}
+	TST_EXP_PASS(cpid == 1);
+	TST_EXP_PASS(ppid == 0);
 
-	return exit_val;
+	return 0;
 }
 
-static void setup(void)
+static void run(void)
 {
-	tst_require_root();
-	check_newpid();
-}
-
-int main(int argc, char *argv[])
-{
-	int status;
-	tst_parse_opts(argc, argv, NULL, NULL);
-	setup();
-
-	TEST(do_clone_unshare_test(T_CLONE, CLONE_NEWPID, child_fn1, NULL));
-
-	if (TEST_RETURN == -1) {
-		tst_brkm(TFAIL | TTERRNO, NULL, "clone failed");
-	} else if ((wait(&status)) == -1) {
-		tst_brkm(TWARN | TERRNO, NULL, "wait failed");
-	}
-
-	if (WIFEXITED(status) && WEXITSTATUS(status) != 0)
-		tst_resm(TFAIL, "child exited abnormally");
-	else if (WIFSIGNALED(status)) {
-		tst_resm(TFAIL, "child was killed with signal = %d",
-			 WTERMSIG(status));
-	}
+	int ret;
 
-	tst_exit();
+	ret = ltp_clone_quick(CLONE_NEWNS | SIGCHLD, child_func, NULL);
+	if (ret < 0)
+		tst_brk(TBROK | TERRNO, "clone failed");
 }
 
+static struct tst_test test = {
+	.test_all = run,
+	.needs_root = 1,
+};
-- 
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

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

* [LTP] [PATCH v1 2/2] Refactor pidns02 test using new LTP API
  2022-08-04  8:48 [LTP] [PATCH v1 1/2] Refactor pidns01 test using new LTP API Andrea Cervesato via ltp
@ 2022-08-04  8:48 ` Andrea Cervesato via ltp
  2022-08-05 13:01   ` Cyril Hrubis
  2022-08-05 13:01 ` [LTP] [PATCH v1 1/2] Refactor pidns01 " Cyril Hrubis
  1 sibling, 1 reply; 4+ messages in thread
From: Andrea Cervesato via ltp @ 2022-08-04  8:48 UTC (permalink / raw)
  To: ltp

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
 testcases/kernel/containers/pidns/pidns02.c | 130 +++++---------------
 1 file changed, 30 insertions(+), 100 deletions(-)

diff --git a/testcases/kernel/containers/pidns/pidns02.c b/testcases/kernel/containers/pidns/pidns02.c
index 2bc9035d8..a106ed8b7 100644
--- a/testcases/kernel/containers/pidns/pidns02.c
+++ b/testcases/kernel/containers/pidns/pidns02.c
@@ -1,114 +1,44 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
-* Copyright (c) International Business Machines Corp., 2007
-* 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
-*
-***************************************************************************
-
-* File: pidns02.c
-*
-* Description:
-*	The pidns02.c testcase builds into the ltp framework to verify
-*	the basic functionality of PID Namespace.
-*
-* Verify that:
-* 1. When parent clone a process with flag CLONE_NEWPID, the session ID of
-* child should be always one.
-*
-* 2. When parent clone a process with flag CLONE_NEWPID, the parent process group ID
-* should be always one.
-*
-* Total Tests
-*
-* Test Name: pidns02
-*
-* Test Assertion & Strategy:
-*
-* From main() clone a new child process with passing the clone_flag as CLONE_NEWPID,
-* Call the setid() inside container.
-* Inside the cloned pid check for the getsid(0) and getpgid(0)
-* Verify with global macro defined value for parent pid & child pid.
-*
-* Usage: <for command-line>
-* pidns02
-*/
-
-#define _GNU_SOURCE
-#include <sys/wait.h>
-#include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <errno.h>
-#include "pidns_helper.h"
-#include "test.h"
+ * Copyright (c) International Business Machines Corp., 2007
+ * Copyright (C) 2022 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
 
-char *TCID = "pidns02";
-int TST_TOTAL = 1;
+/*\
+ * [Description]
+ *
+ * Clone a process with CLONE_NEWPID flag and check:
+ *
+ * - child session ID must be 1
+ * - parent process group ID must be 1
+ */
 
-#define PGID	1
-#define SID	1
+#include "tst_test.h"
+#include "lapi/namespaces_constants.h"
 
-/*
- * child_fn1() - Inside container
- */
-int child_fn1(void *vtest)
+static int child_func(LTP_ATTRIBUTE_UNUSED void *arg)
 {
-	pid_t pgid, sid;
+	pid_t sid, pgid;
 
-	setsid();
-
-	pgid = getpgid(0);
 	sid = getsid(0);
+	pgid = getpgid(0);
 
-	printf("Checking session id & group id inside container\n");
-	if (pgid == PGID && sid == SID) {
-		printf("Success: Got Group ID = %d & Session ID = %d\n",
-		       pgid, sid);
-		exit(0);
-	} else {
-		printf("Got unexpected result of Group ID = %d & Session ID = "
-		       "%d\n", pgid, sid);
-		exit(1);
-	}
-}
+	TST_EXP_PASS(sid == 1);
+	TST_EXP_PASS(pgid == 1);
 
-static void setup(void)
-{
-	tst_require_root();
-	check_newpid();
+	return 0;
 }
 
-int main(void)
+static void run(void)
 {
-	int status;
-
-	setup();
-
-	TEST(do_clone_unshare_test(T_CLONE, CLONE_NEWPID, child_fn1, NULL));
-	if (TEST_RETURN == -1) {
-		tst_brkm(TFAIL | TTERRNO, NULL, "clone failed");
-	} else if ((wait(&status)) == -1) {
-		tst_brkm(TFAIL | TERRNO, NULL, "wait failed");
-	}
-
-	if (WIFEXITED(status) && WEXITSTATUS(status) != 0) {
-		tst_resm(TFAIL | TERRNO, "child exited abnormally");
-	} else if (WIFSIGNALED(status)) {
-		tst_resm(TFAIL | TERRNO, "child exited with signal %d",
-			 WTERMSIG(status));
-	}
-
-	tst_exit();
+	int ret;
 
+	ret = ltp_clone_quick(CLONE_NEWNS | SIGCHLD, child_func, NULL);
+	if (ret < 0)
+		tst_brk(TBROK | TERRNO, "clone failed");
 }
+
+static struct tst_test test = {
+	.test_all = run,
+	.needs_root = 1,
+};
-- 
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

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

* Re: [LTP] [PATCH v1 1/2] Refactor pidns01 test using new LTP API
  2022-08-04  8:48 [LTP] [PATCH v1 1/2] Refactor pidns01 test using new LTP API Andrea Cervesato via ltp
  2022-08-04  8:48 ` [LTP] [PATCH v1 2/2] Refactor pidns02 " Andrea Cervesato via ltp
@ 2022-08-05 13:01 ` Cyril Hrubis
  1 sibling, 0 replies; 4+ messages in thread
From: Cyril Hrubis @ 2022-08-05 13:01 UTC (permalink / raw)
  To: Andrea Cervesato; +Cc: ltp

Hi!
> +// SPDX-License-Identifier: GPL-2.0
>  /*
> -* Copyright (c) International Business Machines Corp., 2007
> -* 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.

The original license was -or-later so I fixed it here and pushed,
thanks.

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

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

* Re: [LTP] [PATCH v1 2/2] Refactor pidns02 test using new LTP API
  2022-08-04  8:48 ` [LTP] [PATCH v1 2/2] Refactor pidns02 " Andrea Cervesato via ltp
@ 2022-08-05 13:01   ` Cyril Hrubis
  0 siblings, 0 replies; 4+ messages in thread
From: Cyril Hrubis @ 2022-08-05 13:01 UTC (permalink / raw)
  To: Andrea Cervesato; +Cc: ltp

Hi!
Here as well, added -or-later and pushed, thanks.

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

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

end of thread, other threads:[~2022-08-05 13:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-04  8:48 [LTP] [PATCH v1 1/2] Refactor pidns01 test using new LTP API Andrea Cervesato via ltp
2022-08-04  8:48 ` [LTP] [PATCH v1 2/2] Refactor pidns02 " Andrea Cervesato via ltp
2022-08-05 13:01   ` Cyril Hrubis
2022-08-05 13:01 ` [LTP] [PATCH v1 1/2] Refactor pidns01 " 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.