diff --git a/test/zdtm.py b/test/zdtm.py index ef67438dc..7aabbdcdf 100755 --- a/test/zdtm.py +++ b/test/zdtm.py @@ -477,7 +477,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 8f48f3ec9..592d934d2 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) + $( +#include +#include + +#include "zdtmtst.h" + +const char *test_doc = "Group starter"; +const char *test_author = "Pavel Emelianov "; + +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 000000000..c44b3f263 --- /dev/null +++ b/test/zdtm/lib/groups.desc @@ -0,0 +1 @@ +{'flags': 'noauto', 'deps': [ '/bin/sh', '/bin/kill', '/bin/cat' ]}