mirror of
https://github.com/checkpoint-restore/criu
synced 2025-09-04 08:15:37 +00:00
zdtm: use flake8 to verify zdtm.py
and fix various warnings. For example, we mix tab and space indentations. v2: add flake8.cfg Cc: Tycho Andersen <tycho.andersen@canonical.com> Signed-off-by: Andrew Vagin <avagin@virtuozzo.com> Acked-by: Tycho Andersen <tycho.andersen@canonical.com> Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
This commit is contained in:
committed by
Pavel Emelyanov
parent
93991e6678
commit
66299a0065
3
Makefile
3
Makefile
@@ -321,6 +321,9 @@ help:
|
|||||||
@echo ' gcov - Make code coverage report'
|
@echo ' gcov - Make code coverage report'
|
||||||
.PHONY: help
|
.PHONY: help
|
||||||
|
|
||||||
|
lint:
|
||||||
|
flake8 --config=scripts/flake8.cfg test/zdtm.py
|
||||||
|
|
||||||
include Makefile.install
|
include Makefile.install
|
||||||
|
|
||||||
.DEFAULT_GOAL := all
|
.DEFAULT_GOAL := all
|
||||||
|
8
scripts/flake8.cfg
Normal file
8
scripts/flake8.cfg
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[flake8]
|
||||||
|
# W191 indentation contains tabs
|
||||||
|
# E128 continuation line under-indented for visual indent
|
||||||
|
# E501 line too long
|
||||||
|
# E251 unexpected spaces around keyword / parameter equals
|
||||||
|
# E101 indentation contains mixed spaces and tabs
|
||||||
|
# E126 continuation line over-indented for hanging indent
|
||||||
|
ignore = W191,E128,E501,E251,E101,E126
|
@@ -9,3 +9,6 @@ chmod a+x $HOME
|
|||||||
make
|
make
|
||||||
make -C test/zdtm
|
make -C test/zdtm
|
||||||
python test/zdtm.py run -a -f h,ns -x 'cgroup*'
|
python test/zdtm.py run -a -f h,ns -x 'cgroup*'
|
||||||
|
|
||||||
|
pip install flake8
|
||||||
|
make lint
|
||||||
|
177
test/zdtm.py
177
test/zdtm.py
@@ -15,7 +15,6 @@ import linecache
|
|||||||
import random
|
import random
|
||||||
import string
|
import string
|
||||||
import imp
|
import imp
|
||||||
import socket
|
|
||||||
import fcntl
|
import fcntl
|
||||||
import errno
|
import errno
|
||||||
import datetime
|
import datetime
|
||||||
@@ -24,6 +23,8 @@ import yaml
|
|||||||
os.chdir(os.path.dirname(os.path.abspath(__file__)))
|
os.chdir(os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
|
||||||
prev_line = None
|
prev_line = None
|
||||||
|
|
||||||
|
|
||||||
def traceit(f, e, a):
|
def traceit(f, e, a):
|
||||||
if e == "line":
|
if e == "line":
|
||||||
lineno = f.f_lineno
|
lineno = f.f_lineno
|
||||||
@@ -44,11 +45,13 @@ def traceit(f, e, a):
|
|||||||
# sit in the same dir
|
# sit in the same dir
|
||||||
tests_root = None
|
tests_root = None
|
||||||
|
|
||||||
|
|
||||||
def clean_tests_root():
|
def clean_tests_root():
|
||||||
global tests_root
|
global tests_root
|
||||||
if tests_root:
|
if tests_root:
|
||||||
os.rmdir(tests_root)
|
os.rmdir(tests_root)
|
||||||
|
|
||||||
|
|
||||||
def make_tests_root():
|
def make_tests_root():
|
||||||
global tests_root
|
global tests_root
|
||||||
if not tests_root:
|
if not tests_root:
|
||||||
@@ -60,12 +63,14 @@ def make_tests_root():
|
|||||||
|
|
||||||
report_dir = None
|
report_dir = None
|
||||||
|
|
||||||
|
|
||||||
def init_report(path):
|
def init_report(path):
|
||||||
global report_dir
|
global report_dir
|
||||||
report_dir = path
|
report_dir = path
|
||||||
if not os.access(report_dir, os.F_OK):
|
if not os.access(report_dir, os.F_OK):
|
||||||
os.makedirs(report_dir)
|
os.makedirs(report_dir)
|
||||||
|
|
||||||
|
|
||||||
def add_to_report(path, tgt_name):
|
def add_to_report(path, tgt_name):
|
||||||
global report_dir
|
global report_dir
|
||||||
if report_dir:
|
if report_dir:
|
||||||
@@ -82,6 +87,7 @@ def add_to_report(path, tgt_name):
|
|||||||
os.mkdir(os.path.dirname(tgt_path))
|
os.mkdir(os.path.dirname(tgt_path))
|
||||||
shutil.copy2(path, tgt_path)
|
shutil.copy2(path, tgt_path)
|
||||||
|
|
||||||
|
|
||||||
def add_to_output(path):
|
def add_to_output(path):
|
||||||
global report_dir
|
global report_dir
|
||||||
if not report_dir:
|
if not report_dir:
|
||||||
@@ -90,7 +96,7 @@ def add_to_output(path):
|
|||||||
fdi = open(path, "r")
|
fdi = open(path, "r")
|
||||||
fdo = open(os.path.join(report_dir, "output"), "a")
|
fdo = open(os.path.join(report_dir, "output"), "a")
|
||||||
while True:
|
while True:
|
||||||
buf = fdi.read(1<<20)
|
buf = fdi.read(1 << 20)
|
||||||
if not buf:
|
if not buf:
|
||||||
break
|
break
|
||||||
fdo.write(buf)
|
fdo.write(buf)
|
||||||
@@ -106,6 +112,7 @@ arch = os.uname()[4]
|
|||||||
# uns -- user namespace, the same as above plus user namespace
|
# uns -- user namespace, the same as above plus user namespace
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
||||||
class host_flavor:
|
class host_flavor:
|
||||||
def __init__(self, opts):
|
def __init__(self, opts):
|
||||||
self.name = "host"
|
self.name = "host"
|
||||||
@@ -122,6 +129,7 @@ class host_flavor:
|
|||||||
def clean():
|
def clean():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class ns_flavor:
|
class ns_flavor:
|
||||||
__root_dirs = ["/bin", "/sbin", "/etc", "/lib", "/lib64", "/dev", "/dev/pts", "/dev/net", "/tmp", "/usr", "/proc"]
|
__root_dirs = ["/bin", "/sbin", "/etc", "/lib", "/lib64", "/dev", "/dev/pts", "/dev/net", "/tmp", "/usr", "/proc"]
|
||||||
|
|
||||||
@@ -151,10 +159,10 @@ class ns_flavor:
|
|||||||
|
|
||||||
# This Mayakovsky-style code gets list of libraries a binary
|
# This Mayakovsky-style code gets list of libraries a binary
|
||||||
# needs minus vdso and gate .so-s
|
# needs minus vdso and gate .so-s
|
||||||
libs = map(lambda x: x[1] == '=>' and x[2] or x[0], \
|
libs = map(lambda x: x[1] == '=>' and x[2] or x[0],
|
||||||
map(lambda x: x.split(), \
|
map(lambda x: x.split(),
|
||||||
filter(lambda x: not xl.match(x), \
|
filter(lambda x: not xl.match(x),
|
||||||
map(lambda x: x.strip(), \
|
map(lambda x: x.strip(),
|
||||||
filter(lambda x: x.startswith('\t'), ldd.stdout.readlines())))))
|
filter(lambda x: x.startswith('\t'), ldd.stdout.readlines())))))
|
||||||
ldd.wait()
|
ldd.wait()
|
||||||
|
|
||||||
@@ -181,7 +189,7 @@ class ns_flavor:
|
|||||||
os.mkdir(self.root + dir)
|
os.mkdir(self.root + dir)
|
||||||
os.chmod(self.root + dir, 0777)
|
os.chmod(self.root + dir, 0777)
|
||||||
|
|
||||||
for ldir in [ "/bin", "/sbin", "/lib", "/lib64" ]:
|
for ldir in ["/bin", "/sbin", "/lib", "/lib64"]:
|
||||||
os.symlink(".." + ldir, self.root + "/usr" + ldir)
|
os.symlink(".." + ldir, self.root + "/usr" + ldir)
|
||||||
|
|
||||||
self.__mknod("tty", os.makedev(5, 0))
|
self.__mknod("tty", os.makedev(5, 0))
|
||||||
@@ -189,7 +197,7 @@ class ns_flavor:
|
|||||||
self.__mknod("net/tun")
|
self.__mknod("net/tun")
|
||||||
self.__mknod("rtc")
|
self.__mknod("rtc")
|
||||||
|
|
||||||
def __copy_deps(self, deps):
|
def __copy_deps(self, deps):
|
||||||
for d in deps.split('|'):
|
for d in deps.split('|'):
|
||||||
if os.access(d, os.F_OK):
|
if os.access(d, os.F_OK):
|
||||||
self.__copy_one(d)
|
self.__copy_one(d)
|
||||||
@@ -248,35 +256,40 @@ class userns_flavor(ns_flavor):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
flavors = { 'h': host_flavor, 'ns': ns_flavor, 'uns': userns_flavor }
|
flavors = {'h': host_flavor, 'ns': ns_flavor, 'uns': userns_flavor}
|
||||||
|
|
||||||
#
|
#
|
||||||
# Helpers
|
# Helpers
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
||||||
def encode_flav(f):
|
def encode_flav(f):
|
||||||
return (flavors.keys().index(f) + 128)
|
return (flavors.keys().index(f) + 128)
|
||||||
|
|
||||||
|
|
||||||
def decode_flav(i):
|
def decode_flav(i):
|
||||||
i = i - 128
|
i = i - 128
|
||||||
if flavors.has_key(i):
|
if i in flavors:
|
||||||
return flavors.keys()[i - 128]
|
return flavors.keys()[i - 128]
|
||||||
return "unknown"
|
return "unknown"
|
||||||
|
|
||||||
|
|
||||||
def tail(path):
|
def tail(path):
|
||||||
p = subprocess.Popen(['tail', '-n1', path],
|
p = subprocess.Popen(['tail', '-n1', path],
|
||||||
stdout = subprocess.PIPE)
|
stdout = subprocess.PIPE)
|
||||||
return p.stdout.readline()
|
return p.stdout.readline()
|
||||||
|
|
||||||
|
|
||||||
def rpidfile(path):
|
def rpidfile(path):
|
||||||
return open(path).readline().strip()
|
return open(path).readline().strip()
|
||||||
|
|
||||||
|
|
||||||
def wait_pid_die(pid, who, tmo = 30):
|
def wait_pid_die(pid, who, tmo = 30):
|
||||||
stime = 0.1
|
stime = 0.1
|
||||||
while stime < tmo:
|
while stime < tmo:
|
||||||
try:
|
try:
|
||||||
os.kill(int(pid), 0)
|
os.kill(int(pid), 0)
|
||||||
except: # Died
|
except: # Died
|
||||||
break
|
break
|
||||||
|
|
||||||
print "Wait for %s to die for %f" % (who, stime)
|
print "Wait for %s to die for %f" % (who, stime)
|
||||||
@@ -285,6 +298,7 @@ def wait_pid_die(pid, who, tmo = 30):
|
|||||||
else:
|
else:
|
||||||
raise test_fail_exc("%s die" % who)
|
raise test_fail_exc("%s die" % who)
|
||||||
|
|
||||||
|
|
||||||
def test_flag(tdesc, flag):
|
def test_flag(tdesc, flag):
|
||||||
return flag in tdesc.get('flags', '').split()
|
return flag in tdesc.get('flags', '').split()
|
||||||
|
|
||||||
@@ -294,10 +308,12 @@ def test_flag(tdesc, flag):
|
|||||||
# test checks fail
|
# test checks fail
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
||||||
class test_fail_exc:
|
class test_fail_exc:
|
||||||
def __init__(self, step):
|
def __init__(self, step):
|
||||||
self.step = step
|
self.step = step
|
||||||
|
|
||||||
|
|
||||||
class test_fail_expected_exc:
|
class test_fail_expected_exc:
|
||||||
def __init__(self, cr_action):
|
def __init__(self, cr_action):
|
||||||
self.cr_action = cr_action
|
self.cr_action = cr_action
|
||||||
@@ -306,6 +322,7 @@ class test_fail_expected_exc:
|
|||||||
# A test from zdtm/ directory.
|
# A test from zdtm/ directory.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
||||||
class zdtm_test:
|
class zdtm_test:
|
||||||
def __init__(self, name, desc, flavor, freezer):
|
def __init__(self, name, desc, flavor, freezer):
|
||||||
self.__name = name
|
self.__name = name
|
||||||
@@ -315,16 +332,16 @@ class zdtm_test:
|
|||||||
self.__pid = 0
|
self.__pid = 0
|
||||||
self.__flavor = flavor
|
self.__flavor = flavor
|
||||||
self.__freezer = freezer
|
self.__freezer = freezer
|
||||||
self._bins = [ name ]
|
self._bins = [name]
|
||||||
self._env = {}
|
self._env = {}
|
||||||
self._deps = desc.get('deps', [])
|
self._deps = desc.get('deps', [])
|
||||||
self.auto_reap = True
|
self.auto_reap = True
|
||||||
|
|
||||||
def __make_action(self, act, env = None, root = None):
|
def __make_action(self, act, env = None, root = None):
|
||||||
sys.stdout.flush() # Not to let make's messages appear before ours
|
sys.stdout.flush() # Not to let make's messages appear before ours
|
||||||
tpath = self.__name + '.' + act
|
tpath = self.__name + '.' + act
|
||||||
s_args = ['make', '--no-print-directory', \
|
s_args = ['make', '--no-print-directory',
|
||||||
'-C', os.path.dirname(tpath), \
|
'-C', os.path.dirname(tpath),
|
||||||
os.path.basename(tpath)]
|
os.path.basename(tpath)]
|
||||||
|
|
||||||
if env:
|
if env:
|
||||||
@@ -379,7 +396,7 @@ class zdtm_test:
|
|||||||
criu_dir = os.path.dirname(os.getcwd())
|
criu_dir = os.path.dirname(os.getcwd())
|
||||||
criu_dir_r = "%s%s" % (self.__flavor.root, criu_dir)
|
criu_dir_r = "%s%s" % (self.__flavor.root, criu_dir)
|
||||||
|
|
||||||
env['ZDTM_CRIU'] = os.path.dirname(os.getcwd());
|
env['ZDTM_CRIU'] = os.path.dirname(os.getcwd())
|
||||||
subprocess.check_call(["mkdir", "-p", criu_dir_r])
|
subprocess.check_call(["mkdir", "-p", criu_dir_r])
|
||||||
|
|
||||||
self.__make_action('pid', env, self.__flavor.root)
|
self.__make_action('pid', env, self.__flavor.root)
|
||||||
@@ -404,11 +421,11 @@ class zdtm_test:
|
|||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
self.__freezer.thaw()
|
self.__freezer.thaw()
|
||||||
self.getpid() # Read the pid from pidfile back
|
self.getpid() # Read the pid from pidfile back
|
||||||
self.kill(signal.SIGTERM)
|
self.kill(signal.SIGTERM)
|
||||||
|
|
||||||
res = tail(self.__name + '.out')
|
res = tail(self.__name + '.out')
|
||||||
if not 'PASS' in res.split():
|
if 'PASS' not in res.split():
|
||||||
raise test_fail_exc("result check")
|
raise test_fail_exc("result check")
|
||||||
|
|
||||||
def getpid(self):
|
def getpid(self):
|
||||||
@@ -495,7 +512,7 @@ class inhfd_test:
|
|||||||
if self.__peer_pid == 0:
|
if self.__peer_pid == 0:
|
||||||
os.setsid()
|
os.setsid()
|
||||||
|
|
||||||
getattr(self.__fdtyp, "child_prep", lambda fd : None)(peer_file)
|
getattr(self.__fdtyp, "child_prep", lambda fd: None)(peer_file)
|
||||||
|
|
||||||
os.close(0)
|
os.close(0)
|
||||||
os.close(1)
|
os.close(1)
|
||||||
@@ -574,15 +591,15 @@ class groups_test(zdtm_test):
|
|||||||
|
|
||||||
self._bins += self.__subs
|
self._bins += self.__subs
|
||||||
self._deps += get_test_desc('zdtm/lib/groups')['deps']
|
self._deps += get_test_desc('zdtm/lib/groups')['deps']
|
||||||
self._env = { 'ZDTM_TESTS': self.__real_name }
|
self._env = {'ZDTM_TESTS': self.__real_name}
|
||||||
|
|
||||||
def __get_start_cmd(self, name):
|
def __get_start_cmd(self, name):
|
||||||
tdir = os.path.dirname(name)
|
tdir = os.path.dirname(name)
|
||||||
tname = os.path.basename(name)
|
tname = os.path.basename(name)
|
||||||
|
|
||||||
s_args = ['make', '--no-print-directory', '-C', tdir]
|
s_args = ['make', '--no-print-directory', '-C', tdir]
|
||||||
subprocess.check_call(s_args + [ tname + '.cleanout' ])
|
subprocess.check_call(s_args + [tname + '.cleanout'])
|
||||||
s = subprocess.Popen(s_args + [ '--dry-run', tname + '.pid' ], stdout = subprocess.PIPE)
|
s = subprocess.Popen(s_args + ['--dry-run', tname + '.pid'], stdout = subprocess.PIPE)
|
||||||
cmd = s.stdout.readlines().pop().strip()
|
cmd = s.stdout.readlines().pop().strip()
|
||||||
s.wait()
|
s.wait()
|
||||||
|
|
||||||
@@ -606,11 +623,11 @@ class groups_test(zdtm_test):
|
|||||||
|
|
||||||
for test in self.__subs:
|
for test in self.__subs:
|
||||||
res = tail(test + '.out')
|
res = tail(test + '.out')
|
||||||
if not 'PASS' in res.split():
|
if 'PASS' not in res.split():
|
||||||
raise test_fail_exc("sub %s result check" % test)
|
raise test_fail_exc("sub %s result check" % test)
|
||||||
|
|
||||||
|
|
||||||
test_classes = { 'zdtm': zdtm_test, 'inhfd': inhfd_test, 'groups': groups_test }
|
test_classes = {'zdtm': zdtm_test, 'inhfd': inhfd_test, 'groups': groups_test}
|
||||||
|
|
||||||
#
|
#
|
||||||
# CRIU when launched using CLI
|
# CRIU when launched using CLI
|
||||||
@@ -618,6 +635,8 @@ test_classes = { 'zdtm': zdtm_test, 'inhfd': inhfd_test, 'groups': groups_test }
|
|||||||
|
|
||||||
criu_bin = "../criu/criu"
|
criu_bin = "../criu/criu"
|
||||||
join_ns_file = '/run/netns/zdtm_netns'
|
join_ns_file = '/run/netns/zdtm_netns'
|
||||||
|
|
||||||
|
|
||||||
class criu_cli:
|
class criu_cli:
|
||||||
def __init__(self, opts):
|
def __init__(self, opts):
|
||||||
self.__test = None
|
self.__test = None
|
||||||
@@ -688,8 +707,8 @@ class criu_cli:
|
|||||||
print_fname(fname, 'strace')
|
print_fname(fname, 'strace')
|
||||||
strace = ["strace", "-o", fname, '-T']
|
strace = ["strace", "-o", fname, '-T']
|
||||||
if action == 'restore':
|
if action == 'restore':
|
||||||
strace += [ '-f' ]
|
strace += ['-f']
|
||||||
s_args += [ '--action-script', os.getcwd() + '/../scripts/fake-restore.sh' ]
|
s_args += ['--action-script', os.getcwd() + '/../scripts/fake-restore.sh']
|
||||||
|
|
||||||
if self.__script:
|
if self.__script:
|
||||||
s_args += ['--action-script', self.__script]
|
s_args += ['--action-script', self.__script]
|
||||||
@@ -712,9 +731,9 @@ class criu_cli:
|
|||||||
# on restore we move only a log file, because we need images
|
# on restore we move only a log file, because we need images
|
||||||
os.rename(os.path.join(__ddir, log), os.path.join(__ddir, log + ".fail"))
|
os.rename(os.path.join(__ddir, log), os.path.join(__ddir, log + ".fail"))
|
||||||
# try again without faults
|
# try again without faults
|
||||||
print "Run criu " + action
|
print "Run criu " + action
|
||||||
ret = self.__criu(action, s_args, False, strace, preexec)
|
ret = self.__criu(action, s_args, False, strace, preexec)
|
||||||
grep_errors(os.path.join(__ddir, log))
|
grep_errors(os.path.join(__ddir, log))
|
||||||
if ret == 0:
|
if ret == 0:
|
||||||
return
|
return
|
||||||
if self.__test.blocking() or (self.__sat and action == 'restore'):
|
if self.__test.blocking() or (self.__sat and action == 'restore'):
|
||||||
@@ -735,9 +754,9 @@ class criu_cli:
|
|||||||
if self.__page_server:
|
if self.__page_server:
|
||||||
print "Adding page server"
|
print "Adding page server"
|
||||||
|
|
||||||
ps_opts = [ "--port", "12345", "--daemon", "--pidfile", "ps.pid" ]
|
ps_opts = ["--port", "12345", "--daemon", "--pidfile", "ps.pid"]
|
||||||
if self.__dedup:
|
if self.__dedup:
|
||||||
ps_opts += [ "--auto-dedup" ]
|
ps_opts += ["--auto-dedup"]
|
||||||
|
|
||||||
self.__criu_act("page-server", opts = ps_opts)
|
self.__criu_act("page-server", opts = ps_opts)
|
||||||
a_opts += ["--page-server", "--address", "127.0.0.1", "--port", "12345"]
|
a_opts += ["--page-server", "--address", "127.0.0.1", "--port", "12345"]
|
||||||
@@ -745,9 +764,9 @@ class criu_cli:
|
|||||||
a_opts += self.__test.getdopts()
|
a_opts += self.__test.getdopts()
|
||||||
|
|
||||||
if self.__dedup:
|
if self.__dedup:
|
||||||
a_opts += [ "--auto-dedup" ]
|
a_opts += ["--auto-dedup"]
|
||||||
|
|
||||||
a_opts += [ "--timeout", "10" ]
|
a_opts += ["--timeout", "10"]
|
||||||
|
|
||||||
criu_dir = os.path.dirname(os.getcwd())
|
criu_dir = os.path.dirname(os.getcwd())
|
||||||
if os.getenv("GCOV"):
|
if os.getenv("GCOV"):
|
||||||
@@ -801,6 +820,7 @@ def try_run_hook(test, args):
|
|||||||
|
|
||||||
do_sbs = False
|
do_sbs = False
|
||||||
|
|
||||||
|
|
||||||
def init_sbs():
|
def init_sbs():
|
||||||
if sys.stdout.isatty():
|
if sys.stdout.isatty():
|
||||||
global do_sbs
|
global do_sbs
|
||||||
@@ -808,18 +828,20 @@ def init_sbs():
|
|||||||
else:
|
else:
|
||||||
print "Can't do step-by-step in this runtime"
|
print "Can't do step-by-step in this runtime"
|
||||||
|
|
||||||
|
|
||||||
def sbs(what):
|
def sbs(what):
|
||||||
if do_sbs:
|
if do_sbs:
|
||||||
raw_input("Pause at %s. Press any key to continue." % what)
|
raw_input("Pause at %s. Press any key to continue." % what)
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Main testing entity -- dump (probably with pre-dumps) and restore
|
# Main testing entity -- dump (probably with pre-dumps) and restore
|
||||||
#
|
#
|
||||||
|
|
||||||
def iter_parm(opt, dflt):
|
def iter_parm(opt, dflt):
|
||||||
x = ((opt or str(dflt)) + ":0").split(':')
|
x = ((opt or str(dflt)) + ":0").split(':')
|
||||||
return (xrange(0, int(x[0])), float(x[1]))
|
return (xrange(0, int(x[0])), float(x[1]))
|
||||||
|
|
||||||
|
|
||||||
def cr(cr_api, test, opts):
|
def cr(cr_api, test, opts):
|
||||||
if opts['nocr']:
|
if opts['nocr']:
|
||||||
return
|
return
|
||||||
@@ -855,12 +877,12 @@ def cr(cr_api, test, opts):
|
|||||||
# Additional checks that can be done outside of test process
|
# Additional checks that can be done outside of test process
|
||||||
|
|
||||||
def get_visible_state(test):
|
def get_visible_state(test):
|
||||||
maps = {}
|
maps = {}
|
||||||
files = {}
|
files = {}
|
||||||
mounts = {}
|
mounts = {}
|
||||||
|
|
||||||
if not getattr(test, "static", lambda : False)() or \
|
if not getattr(test, "static", lambda: False)() or \
|
||||||
not getattr(test, "ns", lambda : False)():
|
not getattr(test, "ns", lambda: False)():
|
||||||
return ({}, {}, {})
|
return ({}, {}, {})
|
||||||
|
|
||||||
r = re.compile('^[0-9]+$')
|
r = re.compile('^[0-9]+$')
|
||||||
@@ -890,6 +912,7 @@ def get_visible_state(test):
|
|||||||
mounts[pid] = cmounts
|
mounts[pid] = cmounts
|
||||||
return files, maps, mounts
|
return files, maps, mounts
|
||||||
|
|
||||||
|
|
||||||
def check_visible_state(test, state, opts):
|
def check_visible_state(test, state, opts):
|
||||||
new = get_visible_state(test)
|
new = get_visible_state(test)
|
||||||
|
|
||||||
@@ -906,7 +929,7 @@ def check_visible_state(test, state, opts):
|
|||||||
if old_maps != new_maps:
|
if old_maps != new_maps:
|
||||||
print "%s: Old maps lost: %s" % (pid, old_maps - new_maps)
|
print "%s: Old maps lost: %s" % (pid, old_maps - new_maps)
|
||||||
print "%s: New maps appeared: %s" % (pid, new_maps - old_maps)
|
print "%s: New maps appeared: %s" % (pid, new_maps - old_maps)
|
||||||
if not opts['fault']: # skip parasite blob
|
if not opts['fault']: # skip parasite blob
|
||||||
raise test_fail_exc("maps compare")
|
raise test_fail_exc("maps compare")
|
||||||
|
|
||||||
old_mounts = state[2][pid]
|
old_mounts = state[2][pid]
|
||||||
@@ -968,10 +991,10 @@ class cg_freezer:
|
|||||||
self.__set_state('THAWED')
|
self.__set_state('THAWED')
|
||||||
|
|
||||||
def getdopts(self):
|
def getdopts(self):
|
||||||
return [ '--freeze-cgroup', self.__path, '--manage-cgroups' ]
|
return ['--freeze-cgroup', self.__path, '--manage-cgroups']
|
||||||
|
|
||||||
def getropts(self):
|
def getropts(self):
|
||||||
return [ '--manage-cgroups' ]
|
return ['--manage-cgroups']
|
||||||
|
|
||||||
|
|
||||||
def get_freezer(desc):
|
def get_freezer(desc):
|
||||||
@@ -982,6 +1005,7 @@ def get_freezer(desc):
|
|||||||
fr = cg_freezer(path = fd[0], state = fd[1])
|
fr = cg_freezer(path = fd[0], state = fd[1])
|
||||||
return fr
|
return fr
|
||||||
|
|
||||||
|
|
||||||
def cmp_ns(ns1, match, ns2, msg):
|
def cmp_ns(ns1, match, ns2, msg):
|
||||||
ns1_ino = os.stat(ns1).st_ino
|
ns1_ino = os.stat(ns1).st_ino
|
||||||
ns2_ino = os.stat(ns2).st_ino
|
ns2_ino = os.stat(ns2).st_ino
|
||||||
@@ -1048,6 +1072,7 @@ def do_run_test(tname, tdesc, flavs, opts):
|
|||||||
cr_api.cleanup()
|
cr_api.cleanup()
|
||||||
print_sep("Test %s PASS" % tname)
|
print_sep("Test %s PASS" % tname)
|
||||||
|
|
||||||
|
|
||||||
class launcher:
|
class launcher:
|
||||||
def __init__(self, opts, nr_tests):
|
def __init__(self, opts, nr_tests):
|
||||||
self.__opts = opts
|
self.__opts = opts
|
||||||
@@ -1103,10 +1128,10 @@ class launcher:
|
|||||||
self.__nr += 1
|
self.__nr += 1
|
||||||
self.__show_progress()
|
self.__show_progress()
|
||||||
|
|
||||||
nd = ('nocr', 'norst', 'pre', 'iters', 'page_server', 'sibling', \
|
nd = ('nocr', 'norst', 'pre', 'iters', 'page_server', 'sibling',
|
||||||
'fault', 'keep_img', 'report', 'snaps', 'sat', 'script', \
|
'fault', 'keep_img', 'report', 'snaps', 'sat', 'script',
|
||||||
'join_ns', 'dedup', 'sbs', 'freezecg', 'user', 'dry_run')
|
'join_ns', 'dedup', 'sbs', 'freezecg', 'user', 'dry_run')
|
||||||
arg = repr((name, desc, flavor, { d: self.__opts[d] for d in nd }))
|
arg = repr((name, desc, flavor, {d: self.__opts[d] for d in nd}))
|
||||||
|
|
||||||
if self.__use_log:
|
if self.__use_log:
|
||||||
logf = name.replace('/', '_') + ".log"
|
logf = name.replace('/', '_') + ".log"
|
||||||
@@ -1115,10 +1140,10 @@ class launcher:
|
|||||||
logf = None
|
logf = None
|
||||||
log = None
|
log = None
|
||||||
|
|
||||||
sub = subprocess.Popen(["./zdtm_ct", "zdtm.py"], \
|
sub = subprocess.Popen(["./zdtm_ct", "zdtm.py"],
|
||||||
env = dict(os.environ, CR_CT_TEST_INFO = arg ), \
|
env = dict(os.environ, CR_CT_TEST_INFO = arg),
|
||||||
stdout = log, stderr = subprocess.STDOUT, close_fds = True)
|
stdout = log, stderr = subprocess.STDOUT, close_fds = True)
|
||||||
self.__subs[sub.pid] = { 'sub': sub, 'log': logf, 'name': name }
|
self.__subs[sub.pid] = {'sub': sub, 'log': logf, 'name': name}
|
||||||
|
|
||||||
if test_flag(desc, 'excl'):
|
if test_flag(desc, 'excl'):
|
||||||
self.wait()
|
self.wait()
|
||||||
@@ -1133,7 +1158,7 @@ class launcher:
|
|||||||
failed_flavor = decode_flav(os.WEXITSTATUS(status))
|
failed_flavor = decode_flav(os.WEXITSTATUS(status))
|
||||||
if self.__file_report:
|
if self.__file_report:
|
||||||
testline = "not ok %d - %s # flavor %s" % (self.__runtest, sub['name'], failed_flavor)
|
testline = "not ok %d - %s # flavor %s" % (self.__runtest, sub['name'], failed_flavor)
|
||||||
details = { 'output': open(sub['log']).read() }
|
details = {'output': open(sub['log']).read()}
|
||||||
print >> self.__file_report, testline
|
print >> self.__file_report, testline
|
||||||
print >> self.__file_report, yaml.dump(details, explicit_start=True, explicit_end=True, default_style='|')
|
print >> self.__file_report, yaml.dump(details, explicit_start=True, explicit_end=True, default_style='|')
|
||||||
if sub['log']:
|
if sub['log']:
|
||||||
@@ -1176,23 +1201,24 @@ class launcher:
|
|||||||
print_sep("FAIL", "#")
|
print_sep("FAIL", "#")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
def all_tests(opts):
|
def all_tests(opts):
|
||||||
desc = eval(open(opts['set'] + '.desc').read())
|
desc = eval(open(opts['set'] + '.desc').read())
|
||||||
lst = subprocess.Popen(['find', desc['dir'], '-type', 'f', '-executable' ], \
|
lst = subprocess.Popen(['find', desc['dir'], '-type', 'f', '-executable'],
|
||||||
stdout = subprocess.PIPE)
|
stdout = subprocess.PIPE)
|
||||||
excl = map(lambda x: os.path.join(desc['dir'], x), desc['exclude'])
|
excl = map(lambda x: os.path.join(desc['dir'], x), desc['exclude'])
|
||||||
tlist = filter(lambda x: \
|
tlist = filter(lambda x:
|
||||||
not x.endswith('.checkskip') and \
|
not x.endswith('.checkskip') and
|
||||||
not x.endswith('.hook') and \
|
not x.endswith('.hook') and
|
||||||
not x in excl, \
|
x not in excl,
|
||||||
map(lambda x: x.strip(), lst.stdout.readlines()) \
|
map(lambda x: x.strip(), lst.stdout.readlines())
|
||||||
)
|
)
|
||||||
lst.wait()
|
lst.wait()
|
||||||
return tlist
|
return tlist
|
||||||
|
|
||||||
|
|
||||||
# Descriptor for abstract test not in list
|
# Descriptor for abstract test not in list
|
||||||
default_test={ }
|
default_test = {}
|
||||||
|
|
||||||
|
|
||||||
def get_test_desc(tname):
|
def get_test_desc(tname):
|
||||||
@@ -1204,13 +1230,14 @@ def get_test_desc(tname):
|
|||||||
|
|
||||||
|
|
||||||
def self_checkskip(tname):
|
def self_checkskip(tname):
|
||||||
chs = tname + '.checkskip'
|
chs = tname + '.checkskip'
|
||||||
if os.access(chs, os.X_OK):
|
if os.access(chs, os.X_OK):
|
||||||
ch = subprocess.Popen([chs])
|
ch = subprocess.Popen([chs])
|
||||||
return not ch.wait() == 0
|
return not ch.wait() == 0
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def print_fname(fname, typ):
|
def print_fname(fname, typ):
|
||||||
print "=[%s]=> %s" % (typ, fname)
|
print "=[%s]=> %s" % (typ, fname)
|
||||||
|
|
||||||
@@ -1218,6 +1245,7 @@ def print_fname(fname, typ):
|
|||||||
def print_sep(title, sep = "=", width = 80):
|
def print_sep(title, sep = "=", width = 80):
|
||||||
print (" " + title + " ").center(width, sep)
|
print (" " + title + " ").center(width, sep)
|
||||||
|
|
||||||
|
|
||||||
def grep_errors(fname):
|
def grep_errors(fname):
|
||||||
first = True
|
first = True
|
||||||
for l in open(fname):
|
for l in open(fname):
|
||||||
@@ -1230,6 +1258,7 @@ def grep_errors(fname):
|
|||||||
if not first:
|
if not first:
|
||||||
print_sep("ERROR OVER", "-", 60)
|
print_sep("ERROR OVER", "-", 60)
|
||||||
|
|
||||||
|
|
||||||
def run_tests(opts):
|
def run_tests(opts):
|
||||||
excl = None
|
excl = None
|
||||||
features = {}
|
features = {}
|
||||||
@@ -1237,7 +1266,7 @@ def run_tests(opts):
|
|||||||
if opts['pre'] or opts['snaps']:
|
if opts['pre'] or opts['snaps']:
|
||||||
if not criu_cli.check("mem_dirty_track"):
|
if not criu_cli.check("mem_dirty_track"):
|
||||||
print "Tracking memory is not available"
|
print "Tracking memory is not available"
|
||||||
return;
|
return
|
||||||
|
|
||||||
if opts['keep_going'] and (not opts['all']):
|
if opts['keep_going'] and (not opts['all']):
|
||||||
print "[WARNING] Option --keep-going is more useful with option --all."
|
print "[WARNING] Option --keep-going is more useful with option --all."
|
||||||
@@ -1279,9 +1308,9 @@ def run_tests(opts):
|
|||||||
|
|
||||||
if opts['join_ns']:
|
if opts['join_ns']:
|
||||||
if subprocess.Popen(["ip", "netns", "add", "zdtm_netns"]).wait():
|
if subprocess.Popen(["ip", "netns", "add", "zdtm_netns"]).wait():
|
||||||
raise Exception("Unable to create a network namespace")
|
raise Exception("Unable to create a network namespace")
|
||||||
if subprocess.Popen(["ip", "netns", "exec", "zdtm_netns", "ip", "link", "set", "up", "dev", "lo"]).wait():
|
if subprocess.Popen(["ip", "netns", "exec", "zdtm_netns", "ip", "link", "set", "up", "dev", "lo"]).wait():
|
||||||
raise Exception("ip link set up dev lo")
|
raise Exception("ip link set up dev lo")
|
||||||
|
|
||||||
l = launcher(opts, len(torun))
|
l = launcher(opts, len(torun))
|
||||||
try:
|
try:
|
||||||
@@ -1303,7 +1332,7 @@ def run_tests(opts):
|
|||||||
|
|
||||||
feat = tdesc.get('feature', None)
|
feat = tdesc.get('feature', None)
|
||||||
if feat:
|
if feat:
|
||||||
if not features.has_key(feat):
|
if feat not in features:
|
||||||
print "Checking feature %s" % feat
|
print "Checking feature %s" % feat
|
||||||
features[feat] = criu_cli.check(feat)
|
features[feat] = criu_cli.check(feat)
|
||||||
|
|
||||||
@@ -1340,7 +1369,7 @@ def run_tests(opts):
|
|||||||
# FIXME -- probably uns will make sense
|
# FIXME -- probably uns will make sense
|
||||||
run_flavs -= set(['ns', 'uns'])
|
run_flavs -= set(['ns', 'uns'])
|
||||||
|
|
||||||
#remove ns and uns flavor in join_ns
|
# remove ns and uns flavor in join_ns
|
||||||
if opts['join_ns']:
|
if opts['join_ns']:
|
||||||
run_flavs -= set(['ns', 'uns'])
|
run_flavs -= set(['ns', 'uns'])
|
||||||
|
|
||||||
@@ -1355,6 +1384,7 @@ def run_tests(opts):
|
|||||||
|
|
||||||
sti_fmt = "%-40s%-10s%s"
|
sti_fmt = "%-40s%-10s%s"
|
||||||
|
|
||||||
|
|
||||||
def show_test_info(t):
|
def show_test_info(t):
|
||||||
tdesc = get_test_desc(t)
|
tdesc = get_test_desc(t)
|
||||||
flavs = tdesc.get('flavor', '')
|
flavs = tdesc.get('flavor', '')
|
||||||
@@ -1371,7 +1401,7 @@ def list_tests(opts):
|
|||||||
|
|
||||||
class group:
|
class group:
|
||||||
def __init__(self, tname, tdesc):
|
def __init__(self, tname, tdesc):
|
||||||
self.__tests = [ tname ]
|
self.__tests = [tname]
|
||||||
self.__desc = tdesc
|
self.__desc = tdesc
|
||||||
self.__deps = set()
|
self.__deps = set()
|
||||||
|
|
||||||
@@ -1404,8 +1434,8 @@ class group:
|
|||||||
# which will call all tests' scripts in turn
|
# which will call all tests' scripts in turn
|
||||||
def __dump_meta(self, fname, ext):
|
def __dump_meta(self, fname, ext):
|
||||||
scripts = filter(lambda names: os.access(names[1], os.X_OK),
|
scripts = filter(lambda names: os.access(names[1], os.X_OK),
|
||||||
map(lambda test: (test, test + ext),
|
map(lambda test: (test, test + ext),
|
||||||
self.__tests))
|
self.__tests))
|
||||||
if scripts:
|
if scripts:
|
||||||
f = open(fname + ext, "w")
|
f = open(fname + ext, "w")
|
||||||
f.write("#!/bin/sh -e\n")
|
f.write("#!/bin/sh -e\n")
|
||||||
@@ -1436,6 +1466,7 @@ class group:
|
|||||||
self.__dump_meta(fname, '.checkskip')
|
self.__dump_meta(fname, '.checkskip')
|
||||||
self.__dump_meta(fname, '.hook')
|
self.__dump_meta(fname, '.hook')
|
||||||
|
|
||||||
|
|
||||||
def group_tests(opts):
|
def group_tests(opts):
|
||||||
excl = None
|
excl = None
|
||||||
groups = []
|
groups = []
|
||||||
@@ -1473,7 +1504,7 @@ def group_tests(opts):
|
|||||||
suf = opts['name'] or 'group'
|
suf = opts['name'] or 'group'
|
||||||
|
|
||||||
for g in groups:
|
for g in groups:
|
||||||
if maxs > 1 and g.size() == 1: # Not much point in group test for this
|
if maxs > 1 and g.size() == 1: # Not much point in group test for this
|
||||||
continue
|
continue
|
||||||
|
|
||||||
fn = os.path.join("groups", "%s.%d" % (suf, nr))
|
fn = os.path.join("groups", "%s.%d" % (suf, nr))
|
||||||
@@ -1495,7 +1526,7 @@ def clean_stuff(opts):
|
|||||||
# main() starts here
|
# main() starts here
|
||||||
#
|
#
|
||||||
|
|
||||||
if os.environ.has_key('CR_CT_TEST_INFO'):
|
if 'CR_CT_TEST_INFO' in os.environ:
|
||||||
# Fork here, since we're new pidns init and are supposed to
|
# Fork here, since we're new pidns init and are supposed to
|
||||||
# collect this namespace's zombies
|
# collect this namespace's zombies
|
||||||
status = 0
|
status = 0
|
||||||
@@ -1511,7 +1542,7 @@ if os.environ.has_key('CR_CT_TEST_INFO'):
|
|||||||
status = os.WEXITSTATUS(status)
|
status = os.WEXITSTATUS(status)
|
||||||
else:
|
else:
|
||||||
status = 1
|
status = 1
|
||||||
break;
|
break
|
||||||
|
|
||||||
sys.exit(status)
|
sys.exit(status)
|
||||||
|
|
||||||
@@ -1549,7 +1580,7 @@ rp.add_argument("-p", "--parallel", help = "Run test in parallel")
|
|||||||
rp.add_argument("--dry-run", help="Don't run tests, just pretend to", action='store_true')
|
rp.add_argument("--dry-run", help="Don't run tests, just pretend to", action='store_true')
|
||||||
rp.add_argument("--script", help="Add script to get notified by criu")
|
rp.add_argument("--script", help="Add script to get notified by criu")
|
||||||
rp.add_argument("-k", "--keep-img", help = "Whether or not to keep images after test",
|
rp.add_argument("-k", "--keep-img", help = "Whether or not to keep images after test",
|
||||||
choices = [ 'always', 'never', 'failed' ], default = 'failed')
|
choices = ['always', 'never', 'failed'], default = 'failed')
|
||||||
rp.add_argument("--report", help = "Generate summary report in directory")
|
rp.add_argument("--report", help = "Generate summary report in directory")
|
||||||
rp.add_argument("--keep-going", help = "Keep running tests in spite of failures", action = 'store_true')
|
rp.add_argument("--keep-going", help = "Keep running tests in spite of failures", action = 'store_true')
|
||||||
|
|
||||||
@@ -1565,7 +1596,7 @@ gp.add_argument("-x", "--exclude", help = "Exclude tests from --all run", action
|
|||||||
|
|
||||||
cp = sp.add_parser("clean", help = "Clean something")
|
cp = sp.add_parser("clean", help = "Clean something")
|
||||||
cp.set_defaults(action = clean_stuff)
|
cp.set_defaults(action = clean_stuff)
|
||||||
cp.add_argument("what", choices = [ 'nsroot' ])
|
cp.add_argument("what", choices = ['nsroot'])
|
||||||
|
|
||||||
opts = vars(p.parse_args())
|
opts = vars(p.parse_args())
|
||||||
if opts.get('sat', False):
|
if opts.get('sat', False):
|
||||||
|
Reference in New Issue
Block a user