public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Artem Savkov <asavkov@redhat.com>
To: ltp-list@lists.sourceforge.net
Cc: Artem Savkov <asavkov@redhat.com>
Subject: [LTP] [PATCH v2 6/6] kernel/containers/netns cleanup
Date: Wed, 13 Aug 2014 17:44:26 +0200	[thread overview]
Message-ID: <1407944666-32659-7-git-send-email-asavkov@redhat.com> (raw)
In-Reply-To: <1407944666-32659-1-git-send-email-asavkov@redhat.com>

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

  parent reply	other threads:[~2014-08-13 15:44 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` Artem Savkov [this message]
2014-08-18 15:53 ` [LTP] [PATCH v2 0/6] testcases/kernel/containers cleanup chrubis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1407944666-32659-7-git-send-email-asavkov@redhat.com \
    --to=asavkov@redhat.com \
    --cc=ltp-list@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox