[CRIU] [PATCH 5/5 v5] Modify and add test for configuration file functionality

vkabatov at redhat.com vkabatov at redhat.com
Tue Jun 20 16:14:12 MSK 2017


From: Veronika Kabatova <vkabatov at redhat.com>

Creating a test for verifying configuration parsing feature. The
test is created by reusing already present inotify_irmap test.

Because of addition of default configuration files, --no-default-config
option is added to zdtm.py to not break the test suite on systems with
these files present.

Signed-off-by: Veronika Kabatova <vkabatov at redhat.com>
---
 test/Makefile                              |  2 +-
 test/zdtm.py                               |  7 ++-
 test/zdtm/static/Makefile                  |  1 +
 test/zdtm/static/config_inotify_irmap.c    | 91 ++++++++++++++++++++++++++++++
 test/zdtm/static/config_inotify_irmap.desc |  3 +
 5 files changed, 100 insertions(+), 4 deletions(-)
 create mode 100644 test/zdtm/static/config_inotify_irmap.c
 create mode 100644 test/zdtm/static/config_inotify_irmap.desc

diff --git a/test/Makefile b/test/Makefile
index 6d75571..0778d3a 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -51,7 +51,7 @@ clean_root:
 .PHONY: clean_root
 
 clean: clean_root
-	$(RM) zdtm_ct zdtm-tst-list umount2
+	$(RM) zdtm_ct zdtm-tst-list umount2 zdtm_test_config.conf
 	$(Q) $(RM) *.log
 	$(Q) $(RM) -r ./dump/
 	$(Q) $(MAKE) -C zdtm cleandep clean cleanout
diff --git a/test/zdtm.py b/test/zdtm.py
index da22974..d277b89 100755
--- a/test/zdtm.py
+++ b/test/zdtm.py
@@ -688,8 +688,8 @@ class criu_cli:
 		if fault:
 			print "Forcing %s fault" % fault
 			env['CRIU_FAULT'] = fault
-
-		cr = subprocess.Popen(strace + [criu_bin, action] + args, env = env, preexec_fn = preexec)
+		cr = subprocess.Popen(strace + [criu_bin, action, "--no-default-config"] + args,
+				env = env, preexec_fn = preexec)
 		if nowait:
 			return cr
 		return cr.wait()
@@ -1065,7 +1065,8 @@ class criu:
 
 	@staticmethod
 	def check(feature):
-		return criu_cli.run("check", ["-v0", "--feature", feature]) == 0
+		return criu_cli.run("check", ["--no-default-config", "-v0",
+				"--feature", feature]) == 0
 
 	@staticmethod
 	def available():
diff --git a/test/zdtm/static/Makefile b/test/zdtm/static/Makefile
index de9188a..55c3ef1 100644
--- a/test/zdtm/static/Makefile
+++ b/test/zdtm/static/Makefile
@@ -184,6 +184,7 @@ TST_NOFILE	:=				\
 		pidns01				\
 		pidns02				\
 		pidns03				\
+		config_inotify_irmap		\
 #		jobctl00			\
 
 ifneq ($(SRCARCH),arm)
diff --git a/test/zdtm/static/config_inotify_irmap.c b/test/zdtm/static/config_inotify_irmap.c
new file mode 100644
index 0000000..831dc19
--- /dev/null
+++ b/test/zdtm/static/config_inotify_irmap.c
@@ -0,0 +1,91 @@
+#include <unistd.h>
+#include <limits.h>
+
+#include <sys/types.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <string.h>
+#include <stdio.h>
+#include <errno.h>
+#include <sys/inotify.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+#include "zdtmtst.h"
+
+/*
+ * This test reuses inotify_irmap test for testing configuration files
+ * functionality. For parts not related to configuration files, please
+ * refer to the original test case and it's author.
+ */
+
+const char *test_doc	= "Default configuration files usage";
+const char *test_author	= "Veronika Kabatova <vkabatov at redhat.com>";
+
+#define TDIR		"/etc"
+char test_files[2][128] = {TDIR"/zdtm-test", TDIR"/zdtm-test1",};
+#define CONFIG_PATH	"../../zdtm_test_config.conf"
+
+#define BUFF_SIZE ((sizeof(struct inotify_event) + PATH_MAX))
+
+int main (int argc, char *argv[])
+{
+	char buf[BUFF_SIZE];
+	int fd, wd, i;
+
+	test_init(argc, argv);
+
+	for (i = 0; i < 2; i++) {
+		unlink(test_files[i]);
+		if (creat(test_files[i], 0600) < 0) {
+			pr_perror("Can't make test file");
+			exit(1);
+		}
+	}
+	fd = inotify_init1(IN_NONBLOCK);
+	if (fd < 0) {
+		pr_perror("inotify_init failed");
+		goto err;
+	}
+	for (i = 0; i < 2; i++) {
+		wd = inotify_add_watch(fd, test_files[i], IN_OPEN);
+		if (wd < 0) {
+			pr_perror("inotify_add_watch failed");
+			goto err;
+		}
+	}
+
+	FILE *configfile = fopen(CONFIG_PATH, "w");
+	if (configfile == NULL) {
+		pr_perror("Unable to create configuration file %s", CONFIG_PATH);
+		goto err;
+	}
+	fprintf(configfile, "force-irmap\t\nirmap-scan-path /zdtm/static\n");
+	fclose(configfile);
+
+	test_daemon();
+	test_waitsig();
+
+	for (i = 0; i < 2; i++) {
+		memset(buf, 0, sizeof(buf));
+		wd = open(test_files[i], O_RDONLY);
+		if (read(fd, buf, sizeof(buf)) <= 0) {
+			fail("No events in queue");
+			unlink(CONFIG_PATH);
+			goto err;
+		}
+	}
+
+	close(wd);
+	close(fd);
+	for (i = 0; i < 2; i++)
+		unlink(test_files[i]);
+	unlink(CONFIG_PATH);
+	pass();
+	return 0;
+err:
+	for (i = 0; i < 2; i++)
+		unlink(test_files[i]);
+	return 1;
+}
diff --git a/test/zdtm/static/config_inotify_irmap.desc b/test/zdtm/static/config_inotify_irmap.desc
new file mode 100644
index 0000000..591ae71
--- /dev/null
+++ b/test/zdtm/static/config_inotify_irmap.desc
@@ -0,0 +1,3 @@
+(lambda confpath:
+{'flags': 'suid', 'opts': '--config %s' % (confpath)
+}) (os.path.abspath('./zdtm_test_config.conf'))
-- 
2.7.4



More information about the CRIU mailing list