All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH v2 0/6] testcases/kernel/containers cleanup
@ 2014-08-13 15:44 Artem Savkov
  2014-08-13 15:44 ` [LTP] [PATCH v2 1/6] mqns tests: runmqnsstest.sh -> runtest/containers Artem Savkov
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Artem Savkov @ 2014-08-13 15:44 UTC (permalink / raw)
  To: ltp-list; +Cc: Artem Savkov

Container tests are currently clumped together in a single script, this
patchset separates them so that they are listed one by on in runtest/containers

v2 set contains a bunch of changes for better compliance with LTP codestyle and
an additional patch doing the same for old code in netns testcases.

Artem Savkov (6):
  mqns tests: runmqnsstest.sh -> runtest/containers
  netns tests: runnetnstest.sh -> runtest/containers
  ipcns tests: runipcnstest.sh -> runtest/containers
  uts tests: runutstest.sh -> runtest/containers
  check_for_unshare test removed from containers tests
  kernel/containers/netns cleanup

 runtest/containers                                 |  42 ++++++-
 testcases/kernel/containers/check_for_unshare.c    |  57 ---------
 testcases/kernel/containers/container_test.sh      |  64 ----------
 .../kernel/containers/mqns/check_mqns_enabled.c    |  57 ---------
 testcases/kernel/containers/mqns/mqns_01.c         |  11 ++
 testcases/kernel/containers/mqns/mqns_02.c         |  11 ++
 testcases/kernel/containers/mqns/mqns_03.c         |  11 ++
 testcases/kernel/containers/mqns/mqns_04.c         |  11 ++
 testcases/kernel/containers/mqns/mqns_helper.h     |  55 +++++++++
 testcases/kernel/containers/mqns/runmqnstest.sh    |  40 -------
 testcases/kernel/containers/netns/Makefile         |   4 +-
 .../kernel/containers/netns/check_netns_enabled.c  |  56 ---------
 testcases/kernel/containers/netns/childns.sh       |   2 +
 testcases/kernel/containers/netns/common.c         |  49 ++------
 testcases/kernel/containers/netns/crtchild.c       |  16 ++-
 .../kernel/containers/netns/crtchild_delchild.c    |  15 ++-
 testcases/kernel/containers/netns/initialize.sh    |   7 +-
 testcases/kernel/containers/netns/netns_helper.h   |  72 +++++++++++
 testcases/kernel/containers/netns/par_chld_ftp.c   |  17 ++-
 testcases/kernel/containers/netns/par_chld_ftp.sh  |  54 +++++++++
 testcases/kernel/containers/netns/par_chld_ipv6.c  |  52 ++++----
 testcases/kernel/containers/netns/runnetnstest.sh  | 133 ---------------------
 .../kernel/containers/netns/two_children_ns.c      |  56 ++++-----
 .../containers/sysvipc/check_ipcns_enabled.c       |  42 -------
 testcases/kernel/containers/sysvipc/ipcns_helper.h |  41 +++++++
 testcases/kernel/containers/sysvipc/mesgq_nstest.c |  13 +-
 .../kernel/containers/sysvipc/runipcnstest.sh      |  62 ----------
 testcases/kernel/containers/sysvipc/sem_nstest.c   |  11 ++
 testcases/kernel/containers/sysvipc/semtest_2ns.c  |  13 ++
 .../kernel/containers/sysvipc/shmem_2nstest.c      |  15 +++
 testcases/kernel/containers/sysvipc/shmnstest.c    |  11 ++
 testcases/kernel/containers/utsname/README         |  53 --------
 .../containers/utsname/check_utsns_enabled.c       |  50 --------
 testcases/kernel/containers/utsname/runutstest.sh  |  33 -----
 testcases/kernel/containers/utsname/utstest.c      |  51 ++++++--
 35 files changed, 522 insertions(+), 765 deletions(-)
 delete mode 100644 testcases/kernel/containers/check_for_unshare.c
 delete mode 100755 testcases/kernel/containers/container_test.sh
 delete mode 100644 testcases/kernel/containers/mqns/check_mqns_enabled.c
 create mode 100644 testcases/kernel/containers/mqns/mqns_helper.h
 delete mode 100755 testcases/kernel/containers/mqns/runmqnstest.sh
 delete mode 100644 testcases/kernel/containers/netns/check_netns_enabled.c
 create mode 100644 testcases/kernel/containers/netns/netns_helper.h
 create mode 100755 testcases/kernel/containers/netns/par_chld_ftp.sh
 delete mode 100755 testcases/kernel/containers/netns/runnetnstest.sh
 delete mode 100644 testcases/kernel/containers/sysvipc/check_ipcns_enabled.c
 create mode 100644 testcases/kernel/containers/sysvipc/ipcns_helper.h
 delete mode 100644 testcases/kernel/containers/sysvipc/runipcnstest.sh
 delete mode 100644 testcases/kernel/containers/utsname/README
 delete mode 100644 testcases/kernel/containers/utsname/check_utsns_enabled.c
 delete mode 100755 testcases/kernel/containers/utsname/runutstest.sh

-- 
1.9.3


------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* [LTP] [PATCH v2 1/6] mqns tests: runmqnsstest.sh -> runtest/containers
  2014-08-13 15:44 [LTP] [PATCH v2 0/6] testcases/kernel/containers cleanup Artem Savkov
@ 2014-08-13 15:44 ` Artem Savkov
  2014-08-13 15:44 ` [LTP] [PATCH v2 2/6] netns tests: runnetnstest.sh " Artem Savkov
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Artem Savkov @ 2014-08-13 15:44 UTC (permalink / raw)
  To: ltp-list; +Cc: Artem Savkov

Extracted mqns tests from runmqnstest.sh and container_test.sh and added them
one by one to runtest/containers.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
---
 runtest/containers                                 |  9 ++++
 testcases/kernel/containers/container_test.sh      |  9 ----
 .../kernel/containers/mqns/check_mqns_enabled.c    | 57 ----------------------
 testcases/kernel/containers/mqns/mqns_01.c         | 11 +++++
 testcases/kernel/containers/mqns/mqns_02.c         | 11 +++++
 testcases/kernel/containers/mqns/mqns_03.c         | 11 +++++
 testcases/kernel/containers/mqns/mqns_04.c         | 11 +++++
 testcases/kernel/containers/mqns/mqns_helper.h     | 55 +++++++++++++++++++++
 testcases/kernel/containers/mqns/runmqnstest.sh    | 40 ---------------
 9 files changed, 108 insertions(+), 106 deletions(-)
 delete mode 100644 testcases/kernel/containers/mqns/check_mqns_enabled.c
 create mode 100644 testcases/kernel/containers/mqns/mqns_helper.h
 delete mode 100755 testcases/kernel/containers/mqns/runmqnstest.sh

diff --git a/runtest/containers b/runtest/containers
index 5f5eeab..f14817c 100644
--- a/runtest/containers
+++ b/runtest/containers
@@ -14,4 +14,13 @@ pidns20 pidns20
 pidns30 pidns30
 pidns31 pidns31
 
+mqns_01 mqns_01
+mqns_01_clone mqns_01 -clone
+mqns_02 mqns_02
+mqns_02_clone mqns_02 -clone
+mqns_03 mqns_03
+mqns_03_clone mqns_03 -clone
+mqns_04 mqns_04
+mqns_04_clone mqns_04 -clone
+
 Containers	container_test.sh
diff --git a/testcases/kernel/containers/container_test.sh b/testcases/kernel/containers/container_test.sh
index cc570f0..73d2527 100755
--- a/testcases/kernel/containers/container_test.sh
+++ b/testcases/kernel/containers/container_test.sh
@@ -46,15 +46,6 @@ else
 	echo "ipc namespaces not enabled in kernel.  Not running ipcns tests."
 fi
 
-check_mqns_enabled
-if [ $? -eq 0 ]; then
-    echo "Running POSIX message queue tests."
-    runmqnstest.sh
-else
-    echo "Posix message queues or ipc namespaces not enabled in kernel."
-    echo "Not running mqns tests."
-fi
-
 check_netns_enabled
 if [ $? -eq 0 ]; then
 	echo "Running netns tests."
diff --git a/testcases/kernel/containers/mqns/check_mqns_enabled.c b/testcases/kernel/containers/mqns/check_mqns_enabled.c
deleted file mode 100644
index b263604..0000000
--- a/testcases/kernel/containers/mqns/check_mqns_enabled.c
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright (c) International Business Machines Corp., 2009
- * Copyright (c) Nadia Derbey, 2009
- * 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
- *
- * Author: Serge Hallyn <serue@us.ibm.com>
- ***************************************************************************/
-#include <sys/mount.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <stdio.h>
-#include "../libclone/libclone.h"
-#include "test.h"
-#include "mqns.h"
-
-const char *TCID = "check_mqns_enabled";
-
-int dummy(void *v)
-{
-	return 0;
-}
-
-int main(void)
-{
-	int pid;
-	mqd_t mqd;
-
-	if (tst_kvercmp(2, 6, 30) < 0)
-		return 1;
-
-	mq_unlink("/checkmqnsenabled");
-	mqd =
-	    mq_open("/checkmqnsenabled", O_RDWR | O_CREAT | O_EXCL, 0777, NULL);
-	if (mqd == -1) {
-		perror("mq_open");
-		return 3;
-	}
-	mq_close(mqd);
-	mq_unlink("/checkmqnsenabled");
-
-	pid = ltp_clone_quick(CLONE_NEWIPC, dummy, NULL);
-	if (pid == -1)
-		return 5;
-
-	return 0;
-}
diff --git a/testcases/kernel/containers/mqns/mqns_01.c b/testcases/kernel/containers/mqns/mqns_01.c
index a8d2748..a8e481d 100644
--- a/testcases/kernel/containers/mqns/mqns_01.c
+++ b/testcases/kernel/containers/mqns/mqns_01.c
@@ -37,6 +37,7 @@
 #include <string.h>
 #include <unistd.h>
 #include "mqns.h"
+#include "mqns_helper.h"
 
 char *TCID = "posixmq_namespace_01";
 int TST_TOTAL = 1;
@@ -49,6 +50,8 @@ int check_mqueue(void *vtest)
 	char buf[30];
 	mqd_t mqd;
 
+	(void) vtest;
+
 	close(p1[1]);
 	close(p2[0]);
 
@@ -75,6 +78,12 @@ int check_mqueue(void *vtest)
 	exit(0);
 }
 
+static void setup(void)
+{
+	tst_require_root(NULL);
+	check_mqns();
+}
+
 int main(int argc, char *argv[])
 {
 	int r;
@@ -82,6 +91,8 @@ int main(int argc, char *argv[])
 	char buf[30];
 	int use_clone = T_UNSHARE;
 
+	setup();
+
 	if (argc == 2 && strcmp(argv[1], "-clone") == 0) {
 		tst_resm(TINFO,
 			 "Testing posix mq namespaces through clone(2).");
diff --git a/testcases/kernel/containers/mqns/mqns_02.c b/testcases/kernel/containers/mqns/mqns_02.c
index 8fab439..b7f6e32 100644
--- a/testcases/kernel/containers/mqns/mqns_02.c
+++ b/testcases/kernel/containers/mqns/mqns_02.c
@@ -40,6 +40,7 @@
 #include <string.h>
 #include <unistd.h>
 #include "mqns.h"
+#include "mqns_helper.h"
 
 char *TCID = "posixmq_namespace_02";
 int TST_TOTAL = 1;
@@ -52,6 +53,8 @@ int check_mqueue(void *vtest)
 	char buf[30];
 	mqd_t mqd;
 
+	(void) vtest;
+
 	close(p1[1]);
 	close(p2[0]);
 
@@ -108,6 +111,12 @@ int check_mqueue(void *vtest)
 
 }
 
+static void setup(void)
+{
+	tst_require_root(NULL);
+	check_mqns();
+}
+
 int main(int argc, char *argv[])
 {
 	int r;
@@ -115,6 +124,8 @@ int main(int argc, char *argv[])
 	char buf[30];
 	int use_clone = T_UNSHARE;
 
+	setup();
+
 	if (argc == 2 && strcmp(argv[1], "-clone") == 0) {
 		tst_resm(TINFO,
 			 "Testing posix mq namespaces through clone(2).");
diff --git a/testcases/kernel/containers/mqns/mqns_03.c b/testcases/kernel/containers/mqns/mqns_03.c
index f9b3cd4..0fa90bb 100644
--- a/testcases/kernel/containers/mqns/mqns_03.c
+++ b/testcases/kernel/containers/mqns/mqns_03.c
@@ -43,6 +43,7 @@
 #include <string.h>
 #include <errno.h>
 #include "mqns.h"
+#include "mqns_helper.h"
 
 char *TCID = "posixmq_namespace_03";
 int TST_TOTAL = 1;
@@ -60,6 +61,8 @@ int check_mqueue(void *vtest)
 	int rc;
 	struct stat statbuf;
 
+	(void) vtest;
+
 	close(p1[1]);
 	close(p2[0]);
 
@@ -126,12 +129,20 @@ int check_mqueue(void *vtest)
 	exit(0);
 }
 
+static void setup(void)
+{
+	tst_require_root(NULL);
+	check_mqns();
+}
+
 int main(int argc, char *argv[])
 {
 	int r;
 	char buf[30];
 	int use_clone = T_UNSHARE;
 
+	setup();
+
 	if (argc == 2 && strcmp(argv[1], "-clone") == 0) {
 		tst_resm(TINFO, "Testing posix mq namespaces through clone(2)");
 		use_clone = T_CLONE;
diff --git a/testcases/kernel/containers/mqns/mqns_04.c b/testcases/kernel/containers/mqns/mqns_04.c
index 80d25a6..7cd7c9d 100644
--- a/testcases/kernel/containers/mqns/mqns_04.c
+++ b/testcases/kernel/containers/mqns/mqns_04.c
@@ -40,6 +40,7 @@
 #include <string.h>
 #include <errno.h>
 #include "mqns.h"
+#include "mqns_helper.h"
 
 char *TCID = "posixmq_namespace_04";
 int TST_TOTAL = 1;
@@ -56,6 +57,8 @@ int check_mqueue(void *vtest)
 	mqd_t mqd;
 	int rc;
 
+	(void) vtest;
+
 	close(p1[1]);
 	close(p2[0]);
 
@@ -83,6 +86,12 @@ int check_mqueue(void *vtest)
 	tst_exit();
 }
 
+static void setup(void)
+{
+	tst_require_root(NULL);
+	check_mqns();
+}
+
 int main(int argc, char *argv[])
 {
 	int rc;
@@ -91,6 +100,8 @@ int main(int argc, char *argv[])
 	struct stat statbuf;
 	int use_clone = T_UNSHARE;
 
+	setup();
+
 	if (argc == 2 && strcmp(argv[1], "-clone") == 0) {
 		tst_resm(TINFO,
 			 "Testing posix mq namespaces through clone(2).");
diff --git a/testcases/kernel/containers/mqns/mqns_helper.h b/testcases/kernel/containers/mqns/mqns_helper.h
new file mode 100644
index 0000000..8b57e32
--- /dev/null
+++ b/testcases/kernel/containers/mqns/mqns_helper.h
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) International Business Machines Corp., 2009
+ * Copyright (c) Nadia Derbey, 2009
+ * 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
+ *
+ * Author: Serge Hallyn <serue@us.ibm.com>
+ ***************************************************************************/
+#include <sys/mount.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include "../libclone/libclone.h"
+#include "test.h"
+#include "mqns.h"
+#include "safe_macros.h"
+
+static int dummy_child(void *v)
+{
+	(void) v;
+	return 0;
+}
+
+static void check_mqns(void)
+{
+	int pid, status;
+	mqd_t mqd;
+
+	if (tst_kvercmp(2, 6, 30) < 0)
+		tst_brkm(TCONF, NULL, "Kernel version is lower than expected");
+
+	mq_unlink("/checkmqnsenabled");
+	mqd =
+	    mq_open("/checkmqnsenabled", O_RDWR | O_CREAT | O_EXCL, 0777, NULL);
+	if (mqd == -1)
+		tst_brkm(TCONF, NULL, "mq_open check failed");
+
+	mq_close(mqd);
+	mq_unlink("/checkmqnsenabled");
+
+	pid = do_clone_unshare_test(T_CLONE, CLONE_NEWIPC, dummy_child, NULL);
+	if (pid == -1)
+		tst_brkm(TCONF | TERRNO, NULL, "CLONE_NEWIPC not supported");
+
+	SAFE_WAIT(NULL, &status);
+}
diff --git a/testcases/kernel/containers/mqns/runmqnstest.sh b/testcases/kernel/containers/mqns/runmqnstest.sh
deleted file mode 100755
index 625976e..0000000
--- a/testcases/kernel/containers/mqns/runmqnstest.sh
+++ /dev/null
@@ -1,40 +0,0 @@
-#!/bin/sh
-################################################################################
-##                                                                            ##
-## Copyright (c) International Business Machines  Corp., 2009                 ##
-## Copyright (c) Nadia Derbey, 2009                                           ##
-##                                                                            ##
-## 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    ##
-##                                                                            ##
-################################################################################
-
-exit_code=0
-tests_list='mqns_01 mqns_02 mqns_03 mqns_04'
-
-for t in $tests_list
-do
-	$t
-	if [ $? -ne 0 ]; then
-		exit_code="$?"
-		exit $exit_code
-	fi
-	$t -clone
-	if [ $? -ne 0 ]; then
-		exit_code="$?"
-		exit $exit_code
-	fi
-done
-
-exit $exit_code
-- 
1.9.3


------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* [LTP] [PATCH v2 2/6] netns tests: runnetnstest.sh -> runtest/containers
  2014-08-13 15:44 [LTP] [PATCH v2 0/6] testcases/kernel/containers cleanup Artem Savkov
  2014-08-13 15:44 ` [LTP] [PATCH v2 1/6] mqns tests: runmqnsstest.sh -> runtest/containers Artem Savkov
@ 2014-08-13 15:44 ` Artem Savkov
  2014-08-13 15:44 ` [LTP] [PATCH v2 3/6] ipcns tests: runipcnstest.sh " Artem Savkov
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Artem Savkov @ 2014-08-13 15:44 UTC (permalink / raw)
  To: ltp-list; +Cc: Artem Savkov

Extracted netns tests from runnetnstest.sh and container_test.sh and added them
one by one to runtest/containers.
vsftpd start/stop is moved to par_child_ftp.sh
iproute2 check is moved to check_iproute() function in netn_helper.h

Signed-off-by: Artem Savkov <asavkov@redhat.com>
---
 runtest/containers                                 |   6 +
 testcases/kernel/containers/container_test.sh      |   8 --
 testcases/kernel/containers/netns/Makefile         |   4 +-
 .../kernel/containers/netns/check_netns_enabled.c  |  56 ---------
 testcases/kernel/containers/netns/childns.sh       |   2 +
 testcases/kernel/containers/netns/crtchild.c       |  16 ++-
 .../kernel/containers/netns/crtchild_delchild.c    |  15 ++-
 testcases/kernel/containers/netns/initialize.sh    |   7 +-
 testcases/kernel/containers/netns/netns_helper.h   |  72 +++++++++++
 testcases/kernel/containers/netns/par_chld_ftp.c   |  17 ++-
 testcases/kernel/containers/netns/par_chld_ftp.sh  |  54 +++++++++
 testcases/kernel/containers/netns/par_chld_ipv6.c  |  11 ++
 testcases/kernel/containers/netns/runnetnstest.sh  | 133 ---------------------
 .../kernel/containers/netns/two_children_ns.c      |  14 ++-
 14 files changed, 207 insertions(+), 208 deletions(-)
 delete mode 100644 testcases/kernel/containers/netns/check_netns_enabled.c
 create mode 100644 testcases/kernel/containers/netns/netns_helper.h
 create mode 100755 testcases/kernel/containers/netns/par_chld_ftp.sh
 delete mode 100755 testcases/kernel/containers/netns/runnetnstest.sh

diff --git a/runtest/containers b/runtest/containers
index f14817c..5c4fc89 100644
--- a/runtest/containers
+++ b/runtest/containers
@@ -23,4 +23,10 @@ mqns_03_clone mqns_03 -clone
 mqns_04 mqns_04
 mqns_04_clone mqns_04 -clone
 
+crtchild crtchild
+two_children_ns two_children_ns
+crtchild_delchild crtchild_delchild
+par_chld_ipv6 par_chld_ipv6
+par_chld_ftp par_chld_ftp.sh
+
 Containers	container_test.sh
diff --git a/testcases/kernel/containers/container_test.sh b/testcases/kernel/containers/container_test.sh
index 73d2527..98e4851 100755
--- a/testcases/kernel/containers/container_test.sh
+++ b/testcases/kernel/containers/container_test.sh
@@ -45,11 +45,3 @@ if [ $? -eq 0 ]; then
 else
 	echo "ipc namespaces not enabled in kernel.  Not running ipcns tests."
 fi
-
-check_netns_enabled
-if [ $? -eq 0 ]; then
-	echo "Running netns tests."
-	runnetnstest.sh
-else
-	echo "Network namespaces not enabled in kernel.  Not running netns tests."
-fi
diff --git a/testcases/kernel/containers/netns/Makefile b/testcases/kernel/containers/netns/Makefile
index 68cca80..189272e 100644
--- a/testcases/kernel/containers/netns/Makefile
+++ b/testcases/kernel/containers/netns/Makefile
@@ -26,11 +26,11 @@ include $(abs_srcdir)/../Makefile.inc
 
 INSTALL_TARGETS		:= *.sh container_ftp.pl
 
+LDLIBS			+= -lclone
+
 MAKE_TARGETS		:= create_container crtchild crtchild_delchild \
 			   par_chld_ftp par_chld_ipv6 sysfsview two_children_ns
 
 $(MAKE_TARGETS): %: common.o %.o
 
-MAKE_TARGETS		+= check_netns_enabled
-
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/containers/netns/check_netns_enabled.c b/testcases/kernel/containers/netns/check_netns_enabled.c
deleted file mode 100644
index 9c1d84a..0000000
--- a/testcases/kernel/containers/netns/check_netns_enabled.c
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
-* Copyright (c) International Business Machines Corp., 2008
-* 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
-*
-* Author: Veerendra C <vechandr@in.ibm.com>
-*
-* Net namespaces were introduced around 2.6.25.  Kernels before that,
-* assume they are not enabled.  Kernels after that, check for -EINVAL
-* when trying to use CLONE_NEWNET and CLONE_NEWNS.
-***************************************************************************/
-
-#define _GNU_SOURCE
-
-#include <stdio.h>
-#include <sched.h>
-#include "config.h"
-#include "libclone.h"
-#include "linux_syscall_numbers.h"
-#include "test.h"
-
-char *TCID = "check_netns_enabled";
-int TST_COUNT = 1;
-int TST_TOTAL = 1;
-
-#ifndef CLONE_NEWNET
-#define CLONE_NEWNET -1
-#endif
-
-#ifndef CLONE_NEWNS
-#define CLONE_NEWNS -1
-#endif
-
-int main(void)
-{
-	/* Checking if the kernel supports unshare with netns capabilities. */
-	if (CLONE_NEWNET == -1 || CLONE_NEWNS == -1)
-		tst_resm(TBROK | TERRNO,
-			 "CLONE_NEWNET (%d) or CLONE_NEWNS (%d) not supported",
-			 CLONE_NEWNET, CLONE_NEWNS);
-	else if (ltp_syscall(__NR_unshare, CLONE_NEWNET | CLONE_NEWNS) == -1)
-		tst_resm(TFAIL | TERRNO, "unshare syscall smoke test failed");
-	else
-		tst_resm(TPASS, "unshare syscall smoke test passed");
-	tst_exit();
-}
diff --git a/testcases/kernel/containers/netns/childns.sh b/testcases/kernel/containers/netns/childns.sh
index 23be6cd..5f5f6a9 100755
--- a/testcases/kernel/containers/netns/childns.sh
+++ b/testcases/kernel/containers/netns/childns.sh
@@ -33,6 +33,8 @@
 # The test case ID, the test case count and the total number of test case
 
 export TCID=${TCID:-childns.sh}
+export TST_COUNT=1
+export TST_TOTAL=1
 . cmdlib.sh
 exists awk grep ip ping sshd
 . initialize.sh
diff --git a/testcases/kernel/containers/netns/crtchild.c b/testcases/kernel/containers/netns/crtchild.c
index d2769c7..6f60500 100644
--- a/testcases/kernel/containers/netns/crtchild.c
+++ b/testcases/kernel/containers/netns/crtchild.c
@@ -27,12 +27,26 @@
 * =============================================================================*/
 
 #include "common.h"
+#include "netns_helper.h"
 
 const char *TCID = "crtchild";
 
+static void setup(void)
+{
+	tst_require_root(NULL);
+	check_iproute();
+	check_netns();
+}
+
 int main(void)
 {
 	int status;
+
+	setup();
 	status = create_net_namespace("parent.sh", "child.sh");
-	return status;
+	if (status == 0)
+		tst_resm(TPASS, "create_net_namespace");
+	else
+		tst_resm(TFAIL, "create_net_namespace");
+	tst_exit();
 }
diff --git a/testcases/kernel/containers/netns/crtchild_delchild.c b/testcases/kernel/containers/netns/crtchild_delchild.c
index 6b82997..0e85883 100644
--- a/testcases/kernel/containers/netns/crtchild_delchild.c
+++ b/testcases/kernel/containers/netns/crtchild_delchild.c
@@ -30,12 +30,25 @@
 * =========================================================================*/
 
 #include "common.h"
+#include "netns_helper.h"
 
 const char *TCID = "crtchild_delchild";
 
+static void setup(void)
+{
+	tst_require_root(NULL);
+	check_iproute();
+	check_netns();
+}
+
 int main(void)
 {
 	int status;
+	setup();
 	status = create_net_namespace("delchild.sh", "rename_net.sh");
-	return status;
+	if (status == 0)
+		tst_resm(TPASS, "create_net_namespace");
+	else
+		tst_resm(TFAIL, "create_net_namespace");
+	tst_exit();
 }
diff --git a/testcases/kernel/containers/netns/initialize.sh b/testcases/kernel/containers/netns/initialize.sh
index 5333e7b..a7d8a21 100755
--- a/testcases/kernel/containers/netns/initialize.sh
+++ b/testcases/kernel/containers/netns/initialize.sh
@@ -29,6 +29,8 @@ export TCID=${TCID:-initialize}
 export TST_TOTAL=1
 export TST_COUNT=1
 
+. test.sh
+
 TEST_SUBNET=${TEST_SUBNET:=192.168.0}
 i=1
 while [ $i -le 4 ] ; do
@@ -52,11 +54,6 @@ else
     exit 1
 fi
 
-IPver=`ip -V | awk  -F"-" ' { print $2 } '` ;
-if ! printf "%s\n%s\n" "ss080417" "$IPver" | sort -c ; then
-    tst_resm  TINFO "ip version should be atleast ss080417"
-    exit 1
-fi
 i=1
 while [ $i -le 6 ] ; do
     mkfifo /tmp/FIFO$i 2> /dev/null
diff --git a/testcases/kernel/containers/netns/netns_helper.h b/testcases/kernel/containers/netns/netns_helper.h
new file mode 100644
index 0000000..7f301ce
--- /dev/null
+++ b/testcases/kernel/containers/netns/netns_helper.h
@@ -0,0 +1,72 @@
+/*
+* Copyright (c) International Business Machines Corp., 2008
+* 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
+*
+* Author: Veerendra C <vechandr@in.ibm.com>
+*
+* Net namespaces were introduced around 2.6.25.  Kernels before that,
+* assume they are not enabled.  Kernels after that, check for -EINVAL
+* when trying to use CLONE_NEWNET and CLONE_NEWNS.
+***************************************************************************/
+
+#define _GNU_SOURCE
+
+#include <sched.h>
+#include "config.h"
+#include "libclone.h"
+#include "linux_syscall_numbers.h"
+#include "test.h"
+#include "safe_macros.h"
+
+#ifndef CLONE_NEWNS
+#define CLONE_NEWNS -1
+#endif
+
+#define IPROUTE_MIN_VER 80725
+
+static void check_iproute(void)
+{
+	FILE *ipf;
+	int n;
+	unsigned int ipver = 0;
+
+	ipf = popen("ip -V", "r");
+	if (ipf == NULL)
+		tst_brkm(TCONF, NULL,
+				"Failed while opening pipe for iproute check");
+
+	n = fscanf(ipf, "ip utility, iproute2-ss%u", &ipver);
+	if (n < 1 || ipver < IPROUTE_MIN_VER)
+		tst_brkm(TCONF, NULL,
+			"iproute tools do not support setting network namespaces");
+
+	pclose(ipf);
+}
+
+static void check_netns(void)
+{
+	int pid, status;
+	/* Checking if the kernel supports unshare with netns capabilities. */
+	if (CLONE_NEWNS == -1)
+		tst_brkm(TCONF | TERRNO, NULL, "CLONE_NEWNS (%d) not supported",
+			 CLONE_NEWNS);
+
+	pid = do_clone_unshare_test(T_UNSHARE, CLONE_NEWNET | CLONE_NEWNS, NULL,
+			NULL);
+	if (pid == -1)
+		tst_brkm(TCONF | TERRNO, NULL,
+				"unshare syscall smoke test failed");
+
+	SAFE_WAIT(NULL, &status);
+}
diff --git a/testcases/kernel/containers/netns/par_chld_ftp.c b/testcases/kernel/containers/netns/par_chld_ftp.c
index 605be19..acee21f 100644
--- a/testcases/kernel/containers/netns/par_chld_ftp.c
+++ b/testcases/kernel/containers/netns/par_chld_ftp.c
@@ -27,12 +27,27 @@
 * =============================================================================*/
 
 #include "common.h"
+#include "netns_helper.h"
 
 const char *TCID = "par_chld_ftp";
 
+static void setup(void)
+{
+	tst_require_root(NULL);
+	check_iproute();
+	check_netns();
+}
+
 int main(void)
 {
 	int status;
+
+	setup();
+
 	status = create_net_namespace("par_ftp.sh", "ch_ftp.sh");
-	return status;
+	if (status == 0)
+		tst_resm(TPASS, "create_net_namespace");
+	else
+		tst_resm(TFAIL, "create_net_namespace");
+	tst_exit();
 }
diff --git a/testcases/kernel/containers/netns/par_chld_ftp.sh b/testcases/kernel/containers/netns/par_chld_ftp.sh
new file mode 100755
index 0000000..5d461dc
--- /dev/null
+++ b/testcases/kernel/containers/netns/par_chld_ftp.sh
@@ -0,0 +1,54 @@
+#!/bin/bash
+
+################################################################################
+##                                                                            ##
+## Copyright (c) International Business Machines  Corp., 2008                 ##
+##                                                                            ##
+## 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    ##
+##                                                                            ##
+## Author:      Veerendra <veeren@linux.vnet.ibm.com>                         ##
+################################################################################
+
+export TCID=${TCID:-par_chld_ftp.sh}
+export TST_COUNT=1
+export TST_TOTAL=1
+
+. test.sh
+. daemonlib.sh
+
+flag=0
+
+status_daemon vsftpd
+if [ $? -ne 0 ]; then
+	start_daemon vsftpd
+	if [ $? -ne 0 ]; then
+		TST_CLEANUP=""
+		tst_brkm TCONF "Can't start vsftp"
+	fi
+	flag=1
+fi
+
+par_chld_ftp
+if [ $? -eq 0 ]; then
+	tst_resm TPASS "par_child_ftp"
+else
+	tst_resm TFAIL "par_child_ftp"
+fi
+
+if [ $flag -eq 1 ]; then
+	stop_daemon vsftpd
+fi
+
+tst_exit
diff --git a/testcases/kernel/containers/netns/par_chld_ipv6.c b/testcases/kernel/containers/netns/par_chld_ipv6.c
index f45ce5a..c9f7ad2 100644
--- a/testcases/kernel/containers/netns/par_chld_ipv6.c
+++ b/testcases/kernel/containers/netns/par_chld_ipv6.c
@@ -45,16 +45,26 @@
 #include "test.h"
 #include "config.h"
 #include "common.h"
+#include "netns_helper.h"
 
 char *TCID = "netns_ipv6";
 int TST_TOTAL = 1;
 
+static void setup(void)
+{
+	tst_require_root(NULL);
+	check_iproute();
+	check_netns();
+}
+
 int main(void)
 {
 	int pid, status = 0, ret;
 	long int flags = 0;
 	char *ltproot, *par, *child;
 
+	setup();
+
 	flags |= CLONE_NEWNS;
 	flags |= CLONE_NEWNET;
 
@@ -116,6 +126,7 @@ parent & child NS");
 				 errno);
 			status = errno;
 		}
+		tst_resm(TPASS, "par child ipv6");
 		return status;
 	}
 }
diff --git a/testcases/kernel/containers/netns/runnetnstest.sh b/testcases/kernel/containers/netns/runnetnstest.sh
deleted file mode 100755
index 15ee006..0000000
--- a/testcases/kernel/containers/netns/runnetnstest.sh
+++ /dev/null
@@ -1,133 +0,0 @@
-#!/bin/bash
-
-################################################################################
-##                                                                            ##
-## Copyright (c) International Business Machines  Corp., 2008                 ##
-##                                                                            ##
-## 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    ##
-##                                                                            ##
-## Author:      Veerendra <veeren@linux.vnet.ibm.com>                         ##
-################################################################################
-
-
-rc=0
-exit_code=0
-
-# Check the iproute2 version (aka "SnapShot")
-IPROUTEV=`ip -V | cut -d ',' -f 2 | cut -d '-' -f 2 | sed -e 's/^ss//'`
-
-# We need to strip leading 0s else bash thinks we're giving it octal numbers.
-IPROUTEY=$(echo ${IPROUTEV:0:2} | sed -e 's/^0\+//') # Year
-IPROUTEM=$(echo ${IPROUTEV:2:2} | sed -e 's/^0\+//') # Month
-IPROUTED=$(echo ${IPROUTEV:4:2} | sed -e 's/^0\+//') # Day
-
-V=$((${IPROUTEY}*12*32 + ${IPROUTEM}*32 + ${IPROUTED}))
-
-#
-# iproute-ss080725 and later support setting the network namespace of an
-# interface.
-#
-NETNSV=$((8*12*32 + 7*32 + 25))
-if [ ${V} -lt ${NETNSV} ]; then
-	echo "INFO: iproute tools do not support setting network namespaces. Skipping network namespace tests."
-	exit $exit_code
-fi
-
-crtchild
-rc=$?
-if [ $rc -ne 0 ]; then
-    exit_code=$rc
-    errmesg="crtchild: return code is $exit_code ; "
-    echo $errmesg
-else
-   echo "crtchild: PASS"
-fi
-echo
-
-two_children_ns
-rc=$?
-if [ $rc -ne 0 ]; then
-    exit_code=$rc
-    errmesg="$errmesg two_children_ns: return code is $exit_code ; "
-    echo $errmesg
-else
-   echo "two_children_ns: PASS"
-fi
-echo
-
-crtchild_delchild
-rc=$?
-if [ $rc -ne 0 ]; then
-    exit_code=$rc
-    errmesg="$errmesg crtchild_delchild: return code is $exit_code ; "
-    echo $errmesg
-else
-   echo "crtchild_delchild: PASS"
-fi
-echo
-
-
-par_chld_ipv6
-rc=$?
-if [ $rc -ne 0 ]; then
-    exit_code=$rc
-    errmesg="$errmesg par_chld_ipv6: return code is $exit_code ; "
-    echo $errmesg
-else
-   echo "par_chld_ipv6: PASS"
-fi
-echo
-
-# sysfs tagging does not exist, so this test can't pass.  In
-# fact at the moment it fails when mount -t sysfs none /sys is
-# refused, fails in a bad state, leaving the system hard to
-# reboot.  Revisit enabling this test when per-container sysfs
-# views are supported.
-#sysfsview
-#rc=$?
-#if [ $rc -ne 0 ]; then
-#    exit_code=$rc
-#    errmesg="$errmesg sysfsview: return code is $exit_code ; "
-#    echo $errmesg
-#else
-#   echo "sysfsview: PASS"
-#fi
-#echo
-
-. cmdlib.sh
-flag=0
-
-status_daemon vsftpd
-if [ $? -ne 0 ]; then
-	start_daemon vsftpd
-	flag=1
-fi
-
-par_chld_ftp
-rc=$?
-if [ $rc -ne 0 ]; then
-    exit_code=$rc
-    errmesg="$errmesg par_chld_ftp: FAIL $exit_code ; "
-    echo $errmesg
-else
-   echo "par_chld_ftp: PASS"
-fi
-
-if [ $flag -eq 1 ]; then
-	stop_daemon vsftpd
-fi
-
-echo
-exit $exit_code
diff --git a/testcases/kernel/containers/netns/two_children_ns.c b/testcases/kernel/containers/netns/two_children_ns.c
index 13ae1e6..8cc0e5d 100644
--- a/testcases/kernel/containers/netns/two_children_ns.c
+++ b/testcases/kernel/containers/netns/two_children_ns.c
@@ -47,10 +47,18 @@
 #include "libclone.h"
 #include "config.h"
 #include "common.h"
+#include "netns_helper.h"
 
 char *TCID = "netns_2children";
 int TST_TOTAL = 1;
 
+static void setup(void)
+{
+	tst_require_root(NULL);
+	check_iproute();
+	check_netns();
+}
+
 int main(void)
 {
 	int ret, pid[2], status, i;
@@ -58,6 +66,8 @@ int main(void)
 	char *child[2], *par[2];
 	char *ltproot;
 
+	setup();
+
 	flags |= CLONE_NEWNS;
 	flags |= CLONE_NEWNET;
 
@@ -133,5 +143,7 @@ int main(void)
 			exit(status);
 		}
 	}
-	exit(0);
+
+	tst_resm(TPASS, "two children ns");
+	tst_exit();
 }
-- 
1.9.3


------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* [LTP] [PATCH v2 3/6] ipcns tests: runipcnstest.sh -> runtest/containers
  2014-08-13 15:44 [LTP] [PATCH v2 0/6] testcases/kernel/containers cleanup Artem Savkov
  2014-08-13 15:44 ` [LTP] [PATCH v2 1/6] mqns tests: runmqnsstest.sh -> runtest/containers Artem Savkov
  2014-08-13 15:44 ` [LTP] [PATCH v2 2/6] netns tests: runnetnstest.sh " Artem Savkov
@ 2014-08-13 15:44 ` Artem Savkov
  2014-08-13 15:44 ` [LTP] [PATCH v2 4/6] uts tests: runutstest.sh " Artem Savkov
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Artem Savkov @ 2014-08-13 15:44 UTC (permalink / raw)
  To: ltp-list; +Cc: Artem Savkov

Extracted sysvipc tests from runipcnstest.sh and container_test.sh and added
them one by one to runtest/containers.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
---
 runtest/containers                                 | 16 ++++++
 testcases/kernel/containers/container_test.sh      |  8 ---
 .../containers/sysvipc/check_ipcns_enabled.c       | 42 ---------------
 testcases/kernel/containers/sysvipc/ipcns_helper.h | 41 ++++++++++++++
 testcases/kernel/containers/sysvipc/mesgq_nstest.c | 13 ++++-
 .../kernel/containers/sysvipc/runipcnstest.sh      | 62 ----------------------
 testcases/kernel/containers/sysvipc/sem_nstest.c   | 11 ++++
 testcases/kernel/containers/sysvipc/semtest_2ns.c  | 13 +++++
 .../kernel/containers/sysvipc/shmem_2nstest.c      | 15 ++++++
 testcases/kernel/containers/sysvipc/shmnstest.c    | 11 ++++
 10 files changed, 119 insertions(+), 113 deletions(-)
 delete mode 100644 testcases/kernel/containers/sysvipc/check_ipcns_enabled.c
 create mode 100644 testcases/kernel/containers/sysvipc/ipcns_helper.h
 delete mode 100644 testcases/kernel/containers/sysvipc/runipcnstest.sh

diff --git a/runtest/containers b/runtest/containers
index 5c4fc89..0f40716 100644
--- a/runtest/containers
+++ b/runtest/containers
@@ -29,4 +29,20 @@ crtchild_delchild crtchild_delchild
 par_chld_ipv6 par_chld_ipv6
 par_chld_ftp par_chld_ftp.sh
 
+shmnstest_none shmnstest none
+shmnstest_clone shmnstest clone
+shmnstest_unshare shmnstest unshare
+shmem_2nstest_none shmem_2nstest none
+shmem_2nstest_clone shmem_2nstest clone
+shmem_2nstest_unshare shmem_2nstest unshare
+mesgq_nstest_none mesgq_nstest none
+mesgq_nstest_clone mesgq_nstest clone
+mesgq_nstest_unshare mesgq_nstest unshare
+sem_nstest_none sem_nstest none
+sem_nstest_clone sem_nstest clone
+sem_nstest_unshare sem_nstest unshare
+semtest_2ns_none semtest_2ns none
+semtest_2ns_clone semtest_2ns clone
+semtest_2ns_unshare semtest_2ns unshare
+
 Containers	container_test.sh
diff --git a/testcases/kernel/containers/container_test.sh b/testcases/kernel/containers/container_test.sh
index 98e4851..ca67bb2 100755
--- a/testcases/kernel/containers/container_test.sh
+++ b/testcases/kernel/containers/container_test.sh
@@ -37,11 +37,3 @@ fi
 #else
 	#echo "User namespaces not enabled in kernel.  Not running userns tests."
 #fi
-
-check_ipcns_enabled
-if [ $? -eq 0 ]; then
-	echo "Running ipcns tests."
-	runipcnstest.sh
-else
-	echo "ipc namespaces not enabled in kernel.  Not running ipcns tests."
-fi
diff --git a/testcases/kernel/containers/sysvipc/check_ipcns_enabled.c b/testcases/kernel/containers/sysvipc/check_ipcns_enabled.c
deleted file mode 100644
index 45cbbd1..0000000
--- a/testcases/kernel/containers/sysvipc/check_ipcns_enabled.c
+++ /dev/null
@@ -1,42 +0,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
-*
-* Author: Rishikesh K Rajak <risrajak@in.ibm.com>
-***************************************************************************/
-#include <sched.h>
-#include <stdio.h>
-#include "../libclone/libclone.h"
-#include "test.h"
-
-const char *TCID = "check_ipcns_enabled";
-
-int dummy(void *v)
-{
-	return 0;
-}
-
-int main(void)
-{
-	int pid;
-
-	if (tst_kvercmp(2, 6, 19) < 0)
-		return 1;
-
-	pid = ltp_clone_quick(CLONE_NEWIPC, dummy, NULL);
-
-	if (pid == -1)
-		return 3;
-	return 0;
-}
diff --git a/testcases/kernel/containers/sysvipc/ipcns_helper.h b/testcases/kernel/containers/sysvipc/ipcns_helper.h
new file mode 100644
index 0000000..01ad0ff
--- /dev/null
+++ b/testcases/kernel/containers/sysvipc/ipcns_helper.h
@@ -0,0 +1,41 @@
+/*
+* 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
+*
+* Author: Rishikesh K Rajak <risrajak@in.ibm.com>
+***************************************************************************/
+#include <sched.h>
+#include "../libclone/libclone.h"
+#include "test.h"
+#include "safe_macros.h"
+
+static int dummy_child(void *v)
+{
+	(void) v;
+	return 0;
+}
+
+static void check_newipc(void)
+{
+	int pid, status;
+
+	if (tst_kvercmp(2, 6, 19) < 0)
+		tst_brkm(TCONF, NULL, "CLONE_NEWIPC not supported");
+
+	pid = do_clone_unshare_test(T_CLONE, CLONE_NEWIPC, dummy_child, NULL);
+	if (pid == -1)
+		tst_brkm(TCONF | TERRNO, NULL, "CLONE_NEWIPC not supported");
+
+	SAFE_WAIT(NULL, &status);
+}
diff --git a/testcases/kernel/containers/sysvipc/mesgq_nstest.c b/testcases/kernel/containers/sysvipc/mesgq_nstest.c
index 5e5a74f..70ea636 100644
--- a/testcases/kernel/containers/sysvipc/mesgq_nstest.c
+++ b/testcases/kernel/containers/sysvipc/mesgq_nstest.c
@@ -32,6 +32,7 @@
 #include <sys/msg.h>
 #include <libclone.h>
 #include "test.h"
+#include "ipcns_helper.h"
 
 #define KEY_VAL		154326L
 #define UNSHARESTR	"unshare"
@@ -47,7 +48,7 @@ struct msg_buf {
 	char mtext[80];		/* text of the message */
 } msg;
 
-void mesgq_read(id)
+void mesgq_read(int id)
 {
 	int READMAX = 80;
 	int n;
@@ -66,6 +67,8 @@ int check_mesgq(void *vtest)
 	char buf[3];
 	int id;
 
+	(void) vtest;
+
 	close(p1[1]);
 	close(p2[0]);
 
@@ -82,12 +85,20 @@ int check_mesgq(void *vtest)
 	return 0;
 }
 
+static void setup(void)
+{
+	tst_require_root(NULL);
+	check_newipc();
+}
+
 int main(int argc, char *argv[])
 {
 	int ret, use_clone = T_NONE, id, n;
 	char *tsttype = NONESTR;
 	char buf[7];
 
+	setup();
+
 	if (argc != 2) {
 		tst_resm(TFAIL, "Usage: %s <clone|unshare|none>", argv[0]);
 		tst_resm(TFAIL, " where clone, unshare, or fork specifies"
diff --git a/testcases/kernel/containers/sysvipc/runipcnstest.sh b/testcases/kernel/containers/sysvipc/runipcnstest.sh
deleted file mode 100644
index 46863a3..0000000
--- a/testcases/kernel/containers/sysvipc/runipcnstest.sh
+++ /dev/null
@@ -1,62 +0,0 @@
-#!/bin/sh
-################################################################################
-##                                                                            ##
-## 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    ##
-##                                                                            ##
-################################################################################
-
-exit_code=0
-ret=0
-echo "****************** sysvipc tests ******************"
-for type in none clone unshare; do
-      echo "sysvipc: SharedMemory $type"
-      shmnstest $type
-      ret=$?
-      if [ $ret -ne 0 ]; then
-              exit_code=$ret
-      fi
-      shmem_2nstest $type
-      ret=$?
-      if [ $ret -ne 0 ]; then
-              exit_code=$ret
-      fi
-done
-echo
-for type in none clone unshare; do
-      echo "sysvipc: MesgQ $type"
-      mesgq_nstest $type
-	  ret=$?
-      if [ $exit_code -ne 0 ]; then
-              exit_code=$ret
-      fi
-done
-echo
-for type in none clone unshare; do
-      echo "sysvipc: Semaphore $type"
-      sem_nstest $type
-	  ret=$?
-      if [ $exit_code -ne 0 ]; then
-              exit_code=$ret
-      fi
-      semtest_2ns $type
-      ret=$?
-      if [ $ret -ne 0 ]; then
-              exit_code=$ret
-      fi
-done
-echo
-exit $exit_code
diff --git a/testcases/kernel/containers/sysvipc/sem_nstest.c b/testcases/kernel/containers/sysvipc/sem_nstest.c
index 2405b24..ae49477 100644
--- a/testcases/kernel/containers/sysvipc/sem_nstest.c
+++ b/testcases/kernel/containers/sysvipc/sem_nstest.c
@@ -32,6 +32,7 @@
 #include <sys/sem.h>
 #include <libclone.h>
 #include "test.h"
+#include "ipcns_helper.h"
 
 #define MY_KEY     154326L
 #define UNSHARESTR "unshare"
@@ -48,6 +49,8 @@ int check_semaphore(void *vtest)
 	char buf[3];
 	int id;
 
+	(void) vtest;
+
 	close(p1[1]);
 	close(p2[0]);
 
@@ -65,12 +68,20 @@ int check_semaphore(void *vtest)
 	return 0;
 }
 
+static void setup(void)
+{
+	tst_require_root(NULL);
+	check_newipc();
+}
+
 int main(int argc, char *argv[])
 {
 	int ret, use_clone = T_NONE, id;
 	char *tsttype = NONESTR;
 	char buf[7];
 
+	setup();
+
 	if (argc != 2) {
 		tst_resm(TFAIL, "Usage: %s <clone| unshare| none>", argv[0]);
 		tst_resm(TFAIL, " where clone, unshare, or fork specifies"
diff --git a/testcases/kernel/containers/sysvipc/semtest_2ns.c b/testcases/kernel/containers/sysvipc/semtest_2ns.c
index d9afc25..3d97bd4 100644
--- a/testcases/kernel/containers/sysvipc/semtest_2ns.c
+++ b/testcases/kernel/containers/sysvipc/semtest_2ns.c
@@ -45,6 +45,7 @@
 #include <sys/sem.h>
 #include <libclone.h>
 #include "test.h"
+#include "ipcns_helper.h"
 
 #define MY_KEY     124326L
 #define UNSHARESTR "unshare"
@@ -93,6 +94,8 @@ int check_sem1(void *vtest)
 {
 	int id1;
 
+	(void) vtest;
+
 	close(p1[0]);
 	/* 1. Create (or fetch if existing) the binary semaphore */
 	id1 = semget(MY_KEY, 1, IPC_CREAT | IPC_EXCL | 0666);
@@ -126,6 +129,8 @@ int check_sem2(void *vtest)
 	char buf[3];
 	int id2;
 
+	(void) vtest;
+
 	close(p1[1]);
 	close(p2[0]);
 	read(p1[0], buf, 3);
@@ -154,12 +159,20 @@ int check_sem2(void *vtest)
 	return 0;
 }
 
+static void setup(void)
+{
+	tst_require_root(NULL);
+	check_newipc();
+}
+
 int main(int argc, char *argv[])
 {
 	int ret, id, use_clone = T_NONE;
 	char *tsttype = NONESTR;
 	char buf[7];
 
+	setup();
+
 	if (argc != 2) {
 		tst_resm(TINFO, "Usage: %s <clone| unshare| none>", argv[0]);
 		tst_resm(TINFO, " where clone, unshare, or fork specifies"
diff --git a/testcases/kernel/containers/sysvipc/shmem_2nstest.c b/testcases/kernel/containers/sysvipc/shmem_2nstest.c
index 3833261..8c0d2f9 100644
--- a/testcases/kernel/containers/sysvipc/shmem_2nstest.c
+++ b/testcases/kernel/containers/sysvipc/shmem_2nstest.c
@@ -45,6 +45,7 @@
 #include <sys/shm.h>
 #include <libclone.h>
 #include "test.h"
+#include "ipcns_helper.h"
 
 #define TESTKEY    124426L
 #define UNSHARESTR "unshare"
@@ -62,6 +63,9 @@ int p1[2];
 int check_shmem1(void *vtest)
 {
 	int id1;
+
+	(void) vtest;
+
 	close(p1[0]);
 
 	/* first create the key */
@@ -81,6 +85,9 @@ int check_shmem2(void *vtest)
 {
 	char buf[3];
 	int id2;
+
+	(void) vtest;
+
 	close(p1[1]);
 	close(p2[0]);
 
@@ -102,6 +109,12 @@ int check_shmem2(void *vtest)
 	tst_exit();
 }
 
+static void setup(void)
+{
+	tst_require_root(NULL);
+	check_newipc();
+}
+
 int main(int argc, char *argv[])
 {
 	int ret, use_clone = T_NONE;
@@ -109,6 +122,8 @@ int main(int argc, char *argv[])
 	char buf[7];
 	int id;
 
+	setup();
+
 	if (argc != 2) {
 		tst_resm(TINFO, "Usage: %s <clone| unshare| none>", argv[0]);
 		tst_resm(TINFO, " where clone, unshare, or fork specifies"
diff --git a/testcases/kernel/containers/sysvipc/shmnstest.c b/testcases/kernel/containers/sysvipc/shmnstest.c
index 2188183..deccc04 100644
--- a/testcases/kernel/containers/sysvipc/shmnstest.c
+++ b/testcases/kernel/containers/sysvipc/shmnstest.c
@@ -33,6 +33,7 @@
 #include <sys/shm.h>
 #include "test.h"
 #include <libclone.h>
+#include "ipcns_helper.h"
 
 char *TCID = "sysvipc_namespace";
 int TST_TOTAL = 1;
@@ -46,6 +47,8 @@ int check_shmid(void *vtest)
 	char buf[3];
 	int id;
 
+	(void) vtest;
+
 	close(p1[1]);
 	close(p2[0]);
 
@@ -61,6 +64,12 @@ int check_shmid(void *vtest)
 	tst_exit();
 }
 
+static void setup(void)
+{
+	tst_require_root(NULL);
+	check_newipc();
+}
+
 #define UNSHARESTR "unshare"
 #define CLONESTR "clone"
 #define NONESTR "none"
@@ -71,6 +80,8 @@ int main(int argc, char *argv[])
 	char *tsttype = NONESTR;
 	char buf[7];
 
+	setup();
+
 	if (argc != 2) {
 		tst_resm(TFAIL, "Usage: %s <clone|unshare|none>", argv[0]);
 		tst_resm(TFAIL,
-- 
1.9.3


------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* [LTP] [PATCH v2 4/6] uts tests: runutstest.sh -> runtest/containers
  2014-08-13 15:44 [LTP] [PATCH v2 0/6] testcases/kernel/containers cleanup Artem Savkov
                   ` (2 preceding siblings ...)
  2014-08-13 15:44 ` [LTP] [PATCH v2 3/6] ipcns tests: runipcnstest.sh " Artem Savkov
@ 2014-08-13 15:44 ` Artem Savkov
  2014-08-13 15:44 ` [LTP] [PATCH v2 5/6] check_for_unshare test removed from containers tests Artem Savkov
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Artem Savkov @ 2014-08-13 15:44 UTC (permalink / raw)
  To: ltp-list; +Cc: Artem Savkov

Extracted utsname tests from runutstest.sh and container_test.sh and added
them one by one to runtest/containers.
hostname recovery moved to utstest.c. tst_exits removed from P2 so that
hostname is actually recovered.
README is removed as it was mostly duplicating utstest.c's header.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
---
 runtest/containers                                 | 11 +++++
 testcases/kernel/containers/container_test.sh      |  7 ---
 testcases/kernel/containers/utsname/README         | 53 ----------------------
 .../containers/utsname/check_utsns_enabled.c       | 50 --------------------
 testcases/kernel/containers/utsname/runutstest.sh  | 33 --------------
 testcases/kernel/containers/utsname/utstest.c      | 51 +++++++++++++++++----
 6 files changed, 53 insertions(+), 152 deletions(-)
 delete mode 100644 testcases/kernel/containers/utsname/README
 delete mode 100644 testcases/kernel/containers/utsname/check_utsns_enabled.c
 delete mode 100755 testcases/kernel/containers/utsname/runutstest.sh

diff --git a/runtest/containers b/runtest/containers
index 0f40716..827a5d7 100644
--- a/runtest/containers
+++ b/runtest/containers
@@ -45,4 +45,15 @@ semtest_2ns_none semtest_2ns none
 semtest_2ns_clone semtest_2ns clone
 semtest_2ns_unshare semtest_2ns unshare
 
+utstest_unshare_1 utstest unshare 1
+utstest_unshare_2 utstest unshare 2
+utstest_unshare_3 utstest unshare 3
+utstest_unshare_4 utstest unshare 4
+utstest_unshare_5 utstest unshare 5
+utstest_clone_1 utstest clone 1
+utstest_clone_2 utstest clone 2
+utstest_clone_3 utstest clone 3
+utstest_clone_4 utstest clone 4
+utstest_clone_5 utstest clone 5
+
 Containers	container_test.sh
diff --git a/testcases/kernel/containers/container_test.sh b/testcases/kernel/containers/container_test.sh
index ca67bb2..9e515e4 100755
--- a/testcases/kernel/containers/container_test.sh
+++ b/testcases/kernel/containers/container_test.sh
@@ -15,13 +15,6 @@ if [ $? -eq 1 ]; then
 	echo "Unshare not supported.  Not running container tests"
 	exit 0
 fi
-check_utsns_enabled
-if [ $? -eq 0 ]; then
-	echo "Running utsns tests."
-	runutstest.sh
-else
-	echo "Uts namespaces not enabled in kernel.  Not running utsns tests."
-fi
 
 #check_userns_enabled
 #if [ $? -eq 0 ]; then
diff --git a/testcases/kernel/containers/utsname/README b/testcases/kernel/containers/utsname/README
deleted file mode 100644
index 5734f88..0000000
--- a/testcases/kernel/containers/utsname/README
+++ /dev/null
@@ -1,53 +0,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    ##
-##                                                                            ##
-################################################################################
-
-This contains five tests for the uts namespace unsharing functionality.
-
-To enable this functionality, you currently must use a -mm kernel (see
-kernel.org). Then to run these tests, just type
-
-	sh runutstest.sh
-
-The tests are intended to do the following:
-
-test 1: check that after fork, two children see the same utsname
-	P1: A=gethostname
-	P2: B=gethostname
-	Ensure(A==B)
-test 2: check that after fork, two children are in the same utsname namespace.
-	P1: sethostname(newname); A=gethostname
-	P2: (wait); B=gethostname
-	Ensure (A==B)
-
-test 3: check that after unshare, processes are in different utsname namespaces.
-	P1: A=gethostname; unshare(utsname); sethostname(newname); C=gethostname
-	P2: B=gethostname; (wait); (wait); D=gethostname
-	Ensure (A==B && A==D && C!=D)
-
-test 4: similar to test 3, but other child changes hostname.
-	P1: A=gethostname; unshare(utsname); (wait); C=gethostname
-	P2: B=gethostname; (wait); sethostname(newname); D=gethostname
-	Ensure (A==B && A==C && C!=D)
-
-test 5: check that unsharing utsname without required permissions (CAP_SYS_AUDIT)
-	fails.
-	P1: A=gethostname; unshare(utsname) without suff. perms; (wait); C=gethostname
-	P2: B=gethostname; (wait); sethostname(newname); D=gethostname
-	Ensure (A==B==C==D) and state is ok.
diff --git a/testcases/kernel/containers/utsname/check_utsns_enabled.c b/testcases/kernel/containers/utsname/check_utsns_enabled.c
deleted file mode 100644
index 8834052..0000000
--- a/testcases/kernel/containers/utsname/check_utsns_enabled.c
+++ /dev/null
@@ -1,50 +0,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
-*
-* Author: Serge Hallyn <serue@us.ibm.com>
-*
-* uts namespaces were introduced around 2.6.19.  Kernels before that,
-* assume they are not enabled.  Kernels after that, check for -EINVAL
-* when trying to use CLONE_NEWUTS.
-***************************************************************************/
-
-#include <sys/utsname.h>
-#include <sched.h>
-#include <stdio.h>
-#include "../libclone/libclone.h"
-#include "test.h"
-
-const char *TCID = "check_utsns_enabled";
-
-int dummy(void *v)
-{
-	return 0;
-}
-
-int main(void)
-{
-	int pid;
-
-	if (tst_kvercmp(2, 6, 19) < 0)
-		return 1;
-
-	pid = ltp_clone_quick(CLONE_NEWUTS, dummy, NULL);
-
-	if (pid == -1) {
-		perror("ltp_clone_quick");
-		return 3;
-	}
-	return 0;
-}
diff --git a/testcases/kernel/containers/utsname/runutstest.sh b/testcases/kernel/containers/utsname/runutstest.sh
deleted file mode 100755
index d3a8021..0000000
--- a/testcases/kernel/containers/utsname/runutstest.sh
+++ /dev/null
@@ -1,33 +0,0 @@
-#!/bin/sh
-################################################################################
-##                                                                            ##
-## 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    ##
-##                                                                            ##
-################################################################################
-
-oldhostname=`hostname`
-echo "unshare tests"
-for i in `seq 1 5`; do
-	echo "test $i (unshare)"
-	utstest unshare $i
-done
-echo "clone tests"
-for i in `seq 1 5`; do
-	echo "test $i (clone)"
-	utstest clone $i
-done
-hostname "$oldhostname"
diff --git a/testcases/kernel/containers/utsname/utstest.c b/testcases/kernel/containers/utsname/utstest.c
index a399605..c70f90b 100644
--- a/testcases/kernel/containers/utsname/utstest.c
+++ b/testcases/kernel/containers/utsname/utstest.c
@@ -54,11 +54,32 @@
 #include <errno.h>
 #include "test.h"
 #include <libclone.h>
+#include "safe_macros.h"
 
 char *TCID = "uts_namespace";
 int TST_TOTAL = 1;
 
-int drop_root()
+static int dummy_child(void *v)
+{
+	(void) v;
+	return 0;
+}
+
+static void check_newuts(void)
+{
+	int pid, status;
+
+	if (tst_kvercmp(2, 6, 19) < 0)
+		tst_brkm(TCONF, NULL, "CLONE_NEWUTS not supported");
+
+	pid = do_clone_unshare_test(T_CLONE, CLONE_NEWUTS, dummy_child, NULL);
+	if (pid == -1)
+		tst_brkm(TCONF | TERRNO, NULL, "CLONE_NEWUTS not supported");
+
+	SAFE_WAIT(NULL, &status);
+}
+
+int drop_root(void)
 {
 	int ret;
 	ret = setresuid(1000, 1000, 1000);
@@ -69,13 +90,14 @@ int drop_root()
 	return 1;
 }
 
-int p1fd[2], p2fd[2];
-pid_t cpid;
-
 #define HLEN 100
 #define NAME1 "serge1"
 #define NAME2 "serge2"
 
+int p1fd[2], p2fd[2];
+static char oldhost[HLEN];
+pid_t cpid;
+
 void picknewhostname(char *orig, char *new)
 {
 	memset(new, 0, HLEN);
@@ -198,7 +220,7 @@ int P1(void *vtest)
 	default:
 		break;
 	}
-	return -1;
+	tst_exit();
 }
 
 int P2(void *vtest)
@@ -234,8 +256,7 @@ int P2(void *vtest)
 		}
 		if (hostname[0] == '0') {
 			tst_resm(TPASS, "P2: P1 claims error");
-			tst_exit();
-			exit(0);
+			return 0;
 		}
 		gethostname(hostname, HLEN);
 		picknewhostname(hostname, newhostname);
@@ -246,10 +267,21 @@ int P2(void *vtest)
 		tst_resm(TFAIL, "undefined test: %d", testnum);
 		break;
 	}
-	tst_exit();
 	return 0;
 }
 
+static void setup(void)
+{
+	gethostname(oldhost, HLEN);
+	tst_require_root(NULL);
+	check_newuts();
+}
+
+static void cleanup(void)
+{
+	sethostname(oldhost, strlen(oldhost));
+}
+
 #define UNSHARESTR "unshare"
 #define CLONESTR "clone"
 int main(int argc, char *argv[])
@@ -258,6 +290,7 @@ int main(int argc, char *argv[])
 	int testnum;
 	void *vtest;
 
+	setup();
 	if (argc != 3) {
 		tst_resm(TFAIL, "Usage: %s <clone|unshare> <testnum>",
 			 argv[0]);
@@ -304,7 +337,6 @@ int main(int argc, char *argv[])
 			if (!drop_root()) {
 				tst_resm(TFAIL, "failed to drop root.");
 				tst_exit();
-				exit(1);
 			}
 			r = do_clone_unshare_test(use_clone, CLONE_NEWUTS,
 						  P1, vtest);
@@ -320,5 +352,6 @@ int main(int argc, char *argv[])
 		break;
 	}
 
+	cleanup();
 	tst_exit();
 }
-- 
1.9.3


------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* [LTP] [PATCH v2 5/6] check_for_unshare test removed from containers tests
  2014-08-13 15:44 [LTP] [PATCH v2 0/6] testcases/kernel/containers cleanup Artem Savkov
                   ` (3 preceding siblings ...)
  2014-08-13 15:44 ` [LTP] [PATCH v2 4/6] uts tests: runutstest.sh " Artem Savkov
@ 2014-08-13 15:44 ` Artem Savkov
  2014-08-13 15:44 ` [LTP] [PATCH v2 6/6] kernel/containers/netns cleanup Artem Savkov
  2014-08-18 15:53 ` [LTP] [PATCH v2 0/6] testcases/kernel/containers cleanup chrubis
  6 siblings, 0 replies; 8+ messages in thread
From: Artem Savkov @ 2014-08-13 15:44 UTC (permalink / raw)
  To: ltp-list; +Cc: Artem Savkov

Removed this test as it doesn't seem to be needed any more, it just checks
availability of unshare(2) call and all the code that actually uses it has it
wrapped with appropriate #if HAVE_UNSARE clauses.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
---
 runtest/containers                              |  2 -
 testcases/kernel/containers/check_for_unshare.c | 57 -------------------------
 testcases/kernel/containers/container_test.sh   | 32 --------------
 3 files changed, 91 deletions(-)
 delete mode 100644 testcases/kernel/containers/check_for_unshare.c
 delete mode 100755 testcases/kernel/containers/container_test.sh

diff --git a/runtest/containers b/runtest/containers
index 827a5d7..a15bd50 100644
--- a/runtest/containers
+++ b/runtest/containers
@@ -55,5 +55,3 @@ utstest_clone_2 utstest clone 2
 utstest_clone_3 utstest clone 3
 utstest_clone_4 utstest clone 4
 utstest_clone_5 utstest clone 5
-
-Containers	container_test.sh
diff --git a/testcases/kernel/containers/check_for_unshare.c b/testcases/kernel/containers/check_for_unshare.c
deleted file mode 100644
index fbb8d11..0000000
--- a/testcases/kernel/containers/check_for_unshare.c
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
-* Copyright (c) International Business Machines Corp., 2008
-* 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
-*
-**************************************************************************/
-/*
-* Description:
-* This program verifies the kernel version to be no later than 2.6.16
-* And checks if the unshare() system call is defined using dlsym(),
-* in the Dynamically Linked Libraries.
-*
-* Date : 26-11-2008
-* Author : Veerendra C <vechandr@in.ibm.com>
-*/
-
-#include <dlfcn.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include "test.h"
-
-const char *TCID = "check_for_unshare";
-
-int main(int argc, char **argv)
-{
-	void *handle;
-	void *ret;
-	char *error;
-	if (tst_kvercmp(2, 6, 16) < 0)
-		return 1;
-
-	handle = dlopen(NULL, RTLD_LAZY);
-	if (!handle) {
-		fprintf(stderr, "%s\n", dlerror());
-		exit(1);
-	}
-
-	dlerror();		/* Clear any existing error */
-	ret = dlsym(handle, "unshare");
-	if ((error = dlerror()) != NULL) {
-		fprintf(stderr, "Error: %s\n", error);
-		exit(1);
-	}
-
-	dlclose(handle);
-	return 0;
-}
diff --git a/testcases/kernel/containers/container_test.sh b/testcases/kernel/containers/container_test.sh
deleted file mode 100755
index 9e515e4..0000000
--- a/testcases/kernel/containers/container_test.sh
+++ /dev/null
@@ -1,32 +0,0 @@
-#!/bin/bash
-#
-# This test performs capability tests for file operations.
-#
-# Copyright 2007 IBM
-#
-# 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.
-
-#check_utsns_enabled
-check_for_unshare
-if [ $? -eq 1 ]; then
-	echo "Unshare not supported.  Not running container tests"
-	exit 0
-fi
-
-#check_userns_enabled
-#if [ $? -eq 0 ]; then
-	#echo "Running userns tests."
-#	userns_mounts unshare
-#	userns_mounts clone
-#	userns_sigio none
-#	userns_sigio unshare
-#	userns_sigio clone
-#	for i in `seq 1 4`; do
-#		userns_sigpending $i
-#	done
-#else
-	#echo "User namespaces not enabled in kernel.  Not running userns tests."
-#fi
-- 
1.9.3


------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* [LTP] [PATCH v2 6/6] kernel/containers/netns cleanup
  2014-08-13 15:44 [LTP] [PATCH v2 0/6] testcases/kernel/containers cleanup Artem Savkov
                   ` (4 preceding siblings ...)
  2014-08-13 15:44 ` [LTP] [PATCH v2 5/6] check_for_unshare test removed from containers tests Artem Savkov
@ 2014-08-13 15:44 ` Artem Savkov
  2014-08-18 15:53 ` [LTP] [PATCH v2 0/6] testcases/kernel/containers cleanup chrubis
  6 siblings, 0 replies; 8+ messages in thread
From: Artem Savkov @ 2014-08-13 15:44 UTC (permalink / raw)
  To: ltp-list; +Cc: Artem Savkov

Updated netns testcases to use tst_resm/tst_exit interfaces instead of plain
exits and call subexecutables using just their name instead of full path as
it is guaranteed that they are within $PATH.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
---
 testcases/kernel/containers/netns/common.c         | 49 ++++------------------
 testcases/kernel/containers/netns/par_chld_ipv6.c  | 41 +++++++-----------
 .../kernel/containers/netns/two_children_ns.c      | 42 ++++++-------------
 3 files changed, 36 insertions(+), 96 deletions(-)

diff --git a/testcases/kernel/containers/netns/common.c b/testcases/kernel/containers/netns/common.c
index 6862700..2a54be5 100644
--- a/testcases/kernel/containers/netns/common.c
+++ b/testcases/kernel/containers/netns/common.c
@@ -45,6 +45,9 @@
 #include "config.h"
 #include "common.h"
 
+#define PARENTNS_SCRIPT "parentns.sh"
+#define CHILDNS_SCRIPT "childns.sh"
+
 static int child_fn(void *c1);
 
 int crtchild(char *s1, char *s2)
@@ -58,11 +61,11 @@ int crtchild(char *s1, char *s2)
 int create_net_namespace(char *p1, char *c1)
 {
 	int pid, status = 0, ret;
-	char *ltproot, *par;
+	char par[FILENAME_MAX];
 	long int clone_flags = 0;
 
 	if (tst_kvercmp(2, 6, 19) < 0)
-		return 1;
+		tst_brkm(TCONF, NULL, "CLONE_NEWPID not supported");
 
 	clone_flags |= CLONE_NEWNS;
 /* Enable other namespaces too optionally */
@@ -77,32 +80,15 @@ int create_net_namespace(char *p1, char *c1)
 		return -1;
 	}
 
-	/* This code will be executed in parent */
-	ltproot = getenv("LTPROOT");
-
-	if (!ltproot) {
-		printf("LTPROOT env variable is not set\n");
-		printf("Please set LTPROOT and re-run the test.. Thankyou\n");
-		return -1;
-	}
-
-	par = malloc(FILENAME_MAX);
-
-	if (par == NULL) {
-		printf("FAIL: error while allocating memory");
-		exit(1);
-	}
-
 	/* We need to pass the child pid to the parentns.sh script */
-	sprintf(par, "%s/testcases/bin/parentns.sh %s %" PRId32, ltproot, p1,
-		pid);
+	sprintf(par, "%s %s %" PRId32, PARENTNS_SCRIPT, p1, pid);
 
 	ret = system(par);
 	status = WEXITSTATUS(ret);
 	if (ret == -1 || status != 0) {
-		printf("Error while running the script\n");
+		tst_resm(TFAIL, "Error while running the script\n");
 		fflush(stdout);
-		exit(1);
+		tst_exit();
 	}
 	fflush(stdout);
 
@@ -118,7 +104,6 @@ int create_net_namespace(char *p1, char *c1)
 /* The function to be executed in the child namespace */
 int child_fn(void *c1)
 {
-	char *ltproot, *child;
 	unsigned long flags = 0;
 #if HAVE_UNSHARE
 	int ret;
@@ -130,22 +115,6 @@ int child_fn(void *c1)
 	flags |= CLONE_NEWUTS;
 	flags |= CLONE_FS;
 
-	ltproot = getenv("LTPROOT");
-
-	if (!ltproot) {
-		printf("LTPROOT env variable is not set\n");
-		printf("Please set LTPROOT and re-run the test..\n");
-		return -1;
-	}
-
-	child = malloc(FILENAME_MAX);
-	if (child == NULL) {
-		printf("FAIL: error while allocating memory");
-		exit(1);
-	}
-
-	sprintf(child, "%s/testcases/bin/childns.sh", ltproot);
-
 	/* Unshare the network namespace in the child */
 #if HAVE_UNSHARE
 	ret = unshare(flags);
@@ -153,7 +122,7 @@ int child_fn(void *c1)
 		perror("Failed to unshare for netns...");
 		return 1;
 	}
-	return crtchild(child, c1);
+	return crtchild(CHILDNS_SCRIPT, c1);
 #else
 	printf("System doesn't support unshare.\n");
 	return -1;
diff --git a/testcases/kernel/containers/netns/par_chld_ipv6.c b/testcases/kernel/containers/netns/par_chld_ipv6.c
index c9f7ad2..bb1e2fc 100644
--- a/testcases/kernel/containers/netns/par_chld_ipv6.c
+++ b/testcases/kernel/containers/netns/par_chld_ipv6.c
@@ -50,6 +50,9 @@
 char *TCID = "netns_ipv6";
 int TST_TOTAL = 1;
 
+#define PARENT_SCRIPT "paripv6.sh"
+#define CHILD_SCRIPT "childipv6.sh"
+
 static void setup(void)
 {
 	tst_require_root(NULL);
@@ -61,7 +64,6 @@ int main(void)
 {
 	int pid, status = 0, ret;
 	long int flags = 0;
-	char *ltproot, *par, *child;
 
 	setup();
 
@@ -69,26 +71,7 @@ int main(void)
 	flags |= CLONE_NEWNET;
 
 	if (tst_kvercmp(2, 6, 19) < 0)
-		return 1;
-
-	ltproot = getenv("LTPROOT");
-
-	if (!ltproot) {
-		tst_resm(TINFO, "LTPROOT env variable is not set");
-		tst_resm(TINFO,
-			 "Please set LTPROOT and re-run the test.. Thankyou");
-		return -1;
-	}
-
-	par = malloc(FILENAME_MAX);
-	child = malloc(FILENAME_MAX);
-
-	if (par == NULL || child == NULL) {
-		tst_resm(TFAIL, "error while allocating mem");
-		exit(1);
-	}
-	sprintf(par, "%s/testcases/bin/paripv6.sh", ltproot);
-	sprintf(child, "%s/testcases/bin/childipv6.sh", ltproot);
+		tst_brkm(TCONF, NULL, "CLONE_NEWPID not supported");
 
 	if ((pid = fork()) == 0) {
 
@@ -99,23 +82,26 @@ int main(void)
 			perror("unshare");
 			tst_resm(TFAIL,
 				 "Error:Unshare syscall failed for network namespace");
-			return 1;
+			tst_exit();
 		}
 #else
 		tst_resm(TCONF, "System doesn't have unshare support");
 #endif
-		return crtchild(child, NULL);
+		if (crtchild(CHILD_SCRIPT, NULL) != 0) {
+			tst_resm(TFAIL, "Failed running child script");
+			tst_exit();
+		}
 	} else {
 
 		//parent
-		ret = system(par);
+		ret = system(PARENT_SCRIPT);
 		status = WEXITSTATUS(ret);
 		if (ret == -1 || status != 0) {
 			tst_resm(TFAIL,
 				 "Error: While running the IPv6 tests between \
 parent & child NS");
 			fflush(stdout);
-			exit(1);
+			tst_exit();
 		}
 		fflush(stdout);
 
@@ -124,9 +110,10 @@ parent & child NS");
 		if (status != 0 || ret == -1) {
 			tst_resm(TFAIL, "waitpid() returns %d, errno %d", ret,
 				 errno);
-			status = errno;
+			tst_exit();
 		}
 		tst_resm(TPASS, "par child ipv6");
-		return status;
+		tst_exit();
 	}
+	tst_exit();
 }
diff --git a/testcases/kernel/containers/netns/two_children_ns.c b/testcases/kernel/containers/netns/two_children_ns.c
index 8cc0e5d..9bc291c 100644
--- a/testcases/kernel/containers/netns/two_children_ns.c
+++ b/testcases/kernel/containers/netns/two_children_ns.c
@@ -63,8 +63,7 @@ int main(void)
 {
 	int ret, pid[2], status, i;
 	long long flags = 0;
-	char *child[2], *par[2];
-	char *ltproot;
+	char child[2][FILENAME_MAX], par[2][FILENAME_MAX];
 
 	setup();
 
@@ -78,30 +77,12 @@ int main(void)
 
 	/* Checking for Kernel Version */
 	if (tst_kvercmp(2, 6, 19) < 0)
-		return 1;
-
-	ltproot = getenv("LTPROOT");
-	if (!ltproot) {
-		tst_resm(TINFO, "LTPROOT env variable is not set");
-		tst_resm(TINFO,
-			 "Please set LTPROOT and re-run the test.. Thankyou");
-		return -1;
-	}
-
-	child[0] = malloc(FILENAME_MAX);
-	child[1] = malloc(FILENAME_MAX);
-	par[0] = malloc(FILENAME_MAX);
-	par[1] = malloc(FILENAME_MAX);
-	if (child[0] == NULL || child[1] == NULL ||
-	    par[0] == NULL || par[1] == NULL) {
-		tst_resm(TFAIL, "error while allocating mem");
-		exit(1);
-	}
+		tst_brkm(TCONF, NULL, "CLONE_NEWPID not supported");
 
-	sprintf(child[0], "%s/testcases/bin/child_1.sh", ltproot);
-	sprintf(child[1], "%s/testcases/bin/child_2.sh", ltproot);
-	sprintf(par[0], "%s/testcases/bin/parent_1.sh", ltproot);
-	sprintf(par[1], "%s/testcases/bin/parent_2.sh", ltproot);
+	strcpy(child[0], "child_1.sh");
+	strcpy(child[1], "child_2.sh");
+	strcpy(par[0], "parent_1.sh");
+	strcpy(par[1], "parent_2.sh");
 
 	/* Loop for creating two child Network Namespaces */
 	for (i = 0; i < 2; i++) {
@@ -115,10 +96,13 @@ int main(void)
 				perror("Unshare");
 				tst_resm(TFAIL,
 					 "Error:Unshare syscall failed for network namespace");
-				return ret;
+				tst_exit();
 			}
 #endif
-			return crtchild(child[i], NULL);
+			if (crtchild(child[i], NULL) != 0) {
+				tst_resm(TFAIL, "Failed running child script");
+				tst_exit();
+			}
 		} else {
 			//Parent
 
@@ -127,7 +111,7 @@ int main(void)
 			if (ret == -1 || status != 0) {
 				tst_resm(TFAIL,
 					 "Error while running the scripts");
-				exit(status);
+				tst_exit();
 			}
 		}
 	}			//End of FOR Loop
@@ -140,7 +124,7 @@ int main(void)
 			tst_resm(TFAIL, "waitpid() returns %d, errno %d", ret,
 				 status);
 			fflush(stdout);
-			exit(status);
+			tst_exit();
 		}
 	}
 
-- 
1.9.3


------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* Re: [LTP] [PATCH v2 0/6] testcases/kernel/containers cleanup
  2014-08-13 15:44 [LTP] [PATCH v2 0/6] testcases/kernel/containers cleanup Artem Savkov
                   ` (5 preceding siblings ...)
  2014-08-13 15:44 ` [LTP] [PATCH v2 6/6] kernel/containers/netns cleanup Artem Savkov
@ 2014-08-18 15:53 ` chrubis
  6 siblings, 0 replies; 8+ messages in thread
From: chrubis @ 2014-08-18 15:53 UTC (permalink / raw)
  To: Artem Savkov; +Cc: ltp-list

Hi!
> Container tests are currently clumped together in a single script, this
> patchset separates them so that they are listed one by on in runtest/containers
> 
> v2 set contains a bunch of changes for better compliance with LTP codestyle and
> an additional patch doing the same for old code in netns testcases.

All pushed, thanks.

For me the par_chld_ftp test fails (after vsftpd was installed), I will
have a look into that tomorrow.

I will also rename a few of the scripts in order to avoid installation
collisions (rename initialize.sh to netns_initialize.sh etc.)

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

end of thread, other threads:[~2014-08-18 15:54 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-13 15:44 [LTP] [PATCH v2 0/6] testcases/kernel/containers cleanup Artem Savkov
2014-08-13 15:44 ` [LTP] [PATCH v2 1/6] mqns tests: runmqnsstest.sh -> runtest/containers Artem Savkov
2014-08-13 15:44 ` [LTP] [PATCH v2 2/6] netns tests: runnetnstest.sh " Artem Savkov
2014-08-13 15:44 ` [LTP] [PATCH v2 3/6] ipcns tests: runipcnstest.sh " Artem Savkov
2014-08-13 15:44 ` [LTP] [PATCH v2 4/6] uts tests: runutstest.sh " Artem Savkov
2014-08-13 15:44 ` [LTP] [PATCH v2 5/6] check_for_unshare test removed from containers tests Artem Savkov
2014-08-13 15:44 ` [LTP] [PATCH v2 6/6] kernel/containers/netns cleanup Artem Savkov
2014-08-18 15:53 ` [LTP] [PATCH v2 0/6] testcases/kernel/containers cleanup chrubis

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.