[CRIU] [PATCH v3] zdtm: netns check ipv4 device config preserve while c/r

Pavel Tikhomirov ptikhomirov at parallels.com
Mon Oct 6 07:58:29 PDT 2014


check for default/lo only disable_policy, disable_xfrm and tag,
so we wont have a chance to break other tests for openvz case

changes:
v2: make for all config options, avoid use of "system".
v3: err->fail, run in own set of namespaces, add random,
check not all options.

Signed-off-by: Pavel Tikhomirov <ptikhomirov at parallels.com>
---
 test/zdtm.sh                      |   2 +
 test/zdtm/live/static/Makefile    |   1 +
 test/zdtm/live/static/netns-dev.c | 151 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 154 insertions(+)
 create mode 100644 test/zdtm/live/static/netns-dev.c

diff --git a/test/zdtm.sh b/test/zdtm.sh
index da85c92..bd9c7fc 100755
--- a/test/zdtm.sh
+++ b/test/zdtm.sh
@@ -171,6 +171,7 @@ transition/ipc
 ns/static/tun
 static/netns-nf
 static/netns
+ns/static/netns-dev
 static/cgroup00
 static/cgroup01
 ns/static/clean_mntns
@@ -223,6 +224,7 @@ deleted_dev
 mntns_open
 mntns_link_remap
 mntns_link_ghost
+netns-dev
 "
 
 source $(readlink -f `dirname $0`/env.sh) || exit 1
diff --git a/test/zdtm/live/static/Makefile b/test/zdtm/live/static/Makefile
index 07d1114..a552e6c 100644
--- a/test/zdtm/live/static/Makefile
+++ b/test/zdtm/live/static/Makefile
@@ -93,6 +93,7 @@ TST_NOFILE	=				\
 		tty03				\
 		mountpoints			\
 		netns				\
+		netns-dev			\
 		session01			\
 		session02			\
 		session03			\
diff --git a/test/zdtm/live/static/netns-dev.c b/test/zdtm/live/static/netns-dev.c
new file mode 100644
index 0000000..308fea4
--- /dev/null
+++ b/test/zdtm/live/static/netns-dev.c
@@ -0,0 +1,151 @@
+#include <unistd.h>
+#include <stdlib.h>
+#include <dirent.h>
+
+#include "zdtmtst.h"
+
+#define LO_CONF_DIR_PATH "/proc/sys/net/ipv4/conf/lo"
+#define DEF_CONF_DIR_PATH "/proc/sys/net/ipv4/conf/default"
+
+char *devconfs[] = {
+	"disable_policy",
+	"disable_xfrm",
+	"tag",
+	NULL,
+};
+
+int rand_limit[] = {
+	2,	/* disable_policy */
+	2,	/* disable_xfrm */
+	0,	/* tag */
+};
+
+struct test_conf {
+	int ipv4_conf[3];
+	int ipv4_conf_rand[3];
+	char *dir;
+} lo, def;
+
+static int save_and_set(int opt, FILE *fp, struct test_conf *tc) {
+	int ret;
+	int val;
+
+	/*
+	 * Save
+	 */
+	ret = fscanf(fp, "%d", &tc->ipv4_conf[opt]);
+	if (ret < 0) {
+		err("fscanf");
+		return -1;
+	}
+
+	/*
+	 * Set random value
+	 */
+	val = (int)lrand48();
+
+	if (rand_limit[opt] != 0)
+		tc->ipv4_conf_rand[opt] = val % rand_limit[opt];
+	else
+		tc->ipv4_conf_rand[opt] = val;
+
+	ret = fprintf(fp, "%d", tc->ipv4_conf_rand[opt]);
+	if (ret < 0) {
+		err("fprintf");
+		return -1;
+	}
+
+	return 0;
+}
+
+static int check_and_restore(int opt, FILE *fp, struct test_conf *tc) {
+	int ret;
+	int val;
+
+	/*
+	 * Check opt
+	 */
+	ret = fscanf(fp, "%d", &val);
+	if (ret < 0) {
+		err("fscanf");
+		return -1;
+	}
+
+	if (val != tc->ipv4_conf_rand[opt]) {
+		fail("Option \"%s/%s\" changed from %d to %d",
+		     tc->dir, devconfs[opt], tc->ipv4_conf_rand[opt], val);
+		return -1;
+	}
+
+	/*
+	 * Restore opt
+	 */
+	ret = fprintf(fp, "%d", tc->ipv4_conf[opt]);
+	if (ret < 0) {
+		err("fprintf");
+		return -1;
+	}
+
+	return 0;
+}
+
+static int for_each_option_do(int (*f)(int opt, FILE *fp, struct test_conf *tc), struct test_conf *tc) {
+	int ret;
+	int i;
+
+	for (i = 0; devconfs[i]; i++) {
+		FILE *fp;
+		char path[PATH_MAX];
+
+		snprintf(path, sizeof(path), "%s/%s", tc->dir, devconfs[i]);
+		ret = access(path, W_OK);
+		if (ret < 0)
+			continue;
+
+		fp = fopen(path, "r+");
+		if (fp == NULL) {
+			err("fopen");
+			return -1;
+		}
+
+		ret = (*f)(i, fp, tc);
+		if (ret < 0)
+			return -1;
+
+		fclose(fp);
+	}
+
+	return 0;
+}
+
+int main(int argc, char **argv)
+{
+	int ret;
+
+	lo.dir = LO_CONF_DIR_PATH;
+	def.dir = DEF_CONF_DIR_PATH;
+
+	test_init(argc, argv);
+
+	ret = for_each_option_do(save_and_set, &lo);
+	if (ret < 0)
+		return -1;
+
+	ret = for_each_option_do(save_and_set, &def);
+	if (ret < 0)
+		return -1;
+
+	test_daemon();
+	test_waitsig();
+
+	ret = for_each_option_do(check_and_restore, &lo);
+	if (ret < 0)
+		return -1;
+
+	ret = for_each_option_do(check_and_restore, &def);
+	if (ret < 0)
+		return -1;
+
+	pass();
+	return 0;
+}
-- 
1.9.3



More information about the CRIU mailing list