mirror of
https://github.com/checkpoint-restore/criu
synced 2025-08-30 22:05:36 +00:00
zdtm.py: The groups_test class for running groups
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@parallels.com>
This commit is contained in:
50
test/zdtm.py
50
test/zdtm.py
@@ -477,7 +477,55 @@ class inhfd_test:
|
|||||||
pass
|
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
|
# CRIU when launched using CLI
|
||||||
|
@@ -5,6 +5,7 @@ CFLAGS += $(USERCFLAGS)
|
|||||||
|
|
||||||
LIBDIR = .
|
LIBDIR = .
|
||||||
LIB = libzdtmtst.a
|
LIB = libzdtmtst.a
|
||||||
|
GRPS = groups
|
||||||
|
|
||||||
LIBSRC = datagen.c msg.c parseargs.c test.c streamutil.c lock.c ns.c tcp.c fs.c
|
LIBSRC = datagen.c msg.c parseargs.c test.c streamutil.c lock.c ns.c tcp.c fs.c
|
||||||
LIBOBJ = $(LIBSRC:%.c=%.o)
|
LIBOBJ = $(LIBSRC:%.c=%.o)
|
||||||
@@ -31,6 +32,17 @@ cleandep:
|
|||||||
cleanout:
|
cleanout:
|
||||||
@true
|
@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
|
realclean: clean cleandep
|
||||||
|
|
||||||
.PHONY: clean cleandep cleanout realclean
|
.PHONY: clean cleandep cleanout realclean
|
||||||
|
46
test/zdtm/lib/groups.c
Normal file
46
test/zdtm/lib/groups.c
Normal file
@@ -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@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;
|
||||||
|
}
|
1
test/zdtm/lib/groups.desc
Normal file
1
test/zdtm/lib/groups.desc
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{'flags': 'noauto', 'deps': [ '/bin/sh', '/bin/kill', '/bin/cat' ]}
|
Reference in New Issue
Block a user