[CRIU] [PATCH 3/3] zdtm.py: The groups_test class for running groups
Pavel Emelyanov
xemul at parallels.com
Thu Dec 3 05:09:04 PST 2015
So here's the new test class that handles the test from
groups set. The class is inherited from zdtm_test one as
what it does is -- starts the pseudo-init in ns/uns flavors
and asks one to spawn() the sub-tests from the list.
All groups tests can only be run inside ns flavor, so if
the host flavor is asked, just the pseudo-init is spawned.
This is because using ns flavor is the easiest way to spawn
all the sub tests under this init (however, h flavor can be
supported by marking the pseudo-init as sub-reaper).
On stop this pseudo-init is signalled to stop, it in turn
stops all the sub-tests and then exits. When the pid
namespace destruction is complete, the sub-tests .out-s are
checked.
Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
---
test/zdtm.py | 50 ++++++++++++++++++++++++++++++++++++++++++++++-
test/zdtm/lib/Makefile | 12 ++++++++++++
test/zdtm/lib/groups.c | 46 +++++++++++++++++++++++++++++++++++++++++++
test/zdtm/lib/groups.desc | 1 +
4 files changed, 108 insertions(+), 1 deletion(-)
create mode 100644 test/zdtm/lib/groups.c
create mode 100644 test/zdtm/lib/groups.desc
diff --git a/test/zdtm.py b/test/zdtm.py
index e99d312..fa8b752 100755
--- a/test/zdtm.py
+++ b/test/zdtm.py
@@ -478,7 +478,55 @@ class inhfd_test:
pass
-test_classes = { 'zdtm': zdtm_test, 'inhfd': inhfd_test }
+class groups_test(zdtm_test):
+ def __init__(self, name, desc, flavor):
+ zdtm_test.__init__(self, 'zdtm/lib/groups', desc, flavor)
+ if flavor.ns:
+ self.__real_name = name
+ self.__subs = map(lambda x: x.strip(), open(name).readlines())
+ print "Subs:\n%s" % '\n'.join(self.__subs)
+ else:
+ self.__real_name = ''
+ self.__subs = []
+
+ self._bins += self.__subs
+ self._env = { 'ZDTM_TESTS': self.__real_name }
+
+ def __get_start_cmd(self, name):
+ tdir = os.path.dirname(name)
+ tname = os.path.basename(name)
+
+ s_args = ['make', '--no-print-directory', '-C', tdir]
+ subprocess.check_call(s_args + [ tname + '.cleanout' ])
+ s = subprocess.Popen(s_args + [ '--dry-run', tname + '.pid' ], stdout = subprocess.PIPE)
+ cmd = s.stdout.readlines().pop().strip()
+ s.wait()
+
+ return 'cd /' + tdir + ' && ' + cmd
+
+ def start(self):
+ if (self.__subs):
+ with open(self.__real_name + '.start', 'w') as f:
+ for test in self.__subs:
+ cmd = self.__get_start_cmd(test)
+ f.write(cmd + '\n')
+
+ with open(self.__real_name + '.stop', 'w') as f:
+ for test in self.__subs:
+ f.write('kill -TERM `cat /%s.pid`\n' % test)
+
+ zdtm_test.start(self)
+
+ def stop(self):
+ zdtm_test.stop(self)
+
+ for test in self.__subs:
+ res = tail(test + '.out')
+ if not 'PASS' in res.split():
+ raise test_fail_exc("sub %s result check" % test)
+
+
+test_classes = { 'zdtm': zdtm_test, 'inhfd': inhfd_test, 'groups': groups_test }
#
# CRIU when launched using CLI
diff --git a/test/zdtm/lib/Makefile b/test/zdtm/lib/Makefile
index 8f48f3e..592d934 100644
--- a/test/zdtm/lib/Makefile
+++ b/test/zdtm/lib/Makefile
@@ -5,6 +5,7 @@ CFLAGS += $(USERCFLAGS)
LIBDIR = .
LIB = libzdtmtst.a
+GRPS = groups
LIBSRC = datagen.c msg.c parseargs.c test.c streamutil.c lock.c ns.c tcp.c fs.c
LIBOBJ = $(LIBSRC:%.c=%.o)
@@ -31,6 +32,17 @@ cleandep:
cleanout:
@true
+$(GRPS): $(LIB)
+
+$(GRPS:%=%.pid): $(GRPS)
+ $(<D)/$(<F) --pidfile=$@ --outfile=$<.out
+
+$(GRPS:%=%.out): $(GRPS:%=%.pid)
+ -kill -TERM `cat $<`
+
+$(GRPS:%=%.cleanout): $(GRPS)
+ $(Q) $(RM) -f -r $<.pid $<.out* *$<.test* $<.*.test $<.state $<.init.pid
+
realclean: clean cleandep
.PHONY: clean cleandep cleanout realclean
diff --git a/test/zdtm/lib/groups.c b/test/zdtm/lib/groups.c
new file mode 100644
index 0000000..4160cd1
--- /dev/null
+++ b/test/zdtm/lib/groups.c
@@ -0,0 +1,46 @@
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "zdtmtst.h"
+
+const char *test_doc = "Group starter";
+const char *test_author = "Pavel Emelianov <xemul at parallels.com>";
+
+int main(int argc, char **argv)
+{
+ int sret = 0;
+ char *env;
+ char sh[1024];
+
+ test_init(argc, argv);
+
+ env = getenv("ZDTM_TESTS");
+ if (env[0] != '\0') {
+ unsetenv("ZDTM_NEWNS");
+ unsetenv("ZDTM_GROUPS");
+ unsetenv("ZDTM_UID");
+ unsetenv("ZDTM_GID");
+ unsetenv("ZDTM_ROOT");
+ unsetenv("ZDTM_PIDFILE");
+
+ test_msg("List: [%s]\n", env);
+ sprintf(sh, "sh /%s.start", env);
+ system(sh);
+ }
+
+ test_daemon();
+ test_waitsig();
+
+ if (env[0] != '\0') {
+ sprintf(sh, "sh /%s.stop", env);
+ sret = system(sh);
+ }
+
+ if (sret == 0)
+ pass();
+ else
+ fail("Some subs failed");
+
+ return 0;
+}
diff --git a/test/zdtm/lib/groups.desc b/test/zdtm/lib/groups.desc
new file mode 100644
index 0000000..c44b3f2
--- /dev/null
+++ b/test/zdtm/lib/groups.desc
@@ -0,0 +1 @@
+{'flags': 'noauto', 'deps': [ '/bin/sh', '/bin/kill', '/bin/cat' ]}
--
1.9.3
More information about the CRIU
mailing list