2
0
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:
Andrew Vagin
2016-06-03 05:33:00 +03:00
committed by Pavel Emelyanov
parent 93991e6678
commit 66299a0065
4 changed files with 118 additions and 73 deletions

View File

@@ -321,6 +321,9 @@ help:
@echo ' gcov - Make code coverage report'
.PHONY: help
lint:
flake8 --config=scripts/flake8.cfg test/zdtm.py
include Makefile.install
.DEFAULT_GOAL := all

8
scripts/flake8.cfg Normal file
View 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

View File

@@ -9,3 +9,6 @@ chmod a+x $HOME
make
make -C test/zdtm
python test/zdtm.py run -a -f h,ns -x 'cgroup*'
pip install flake8
make lint

View File

@@ -15,7 +15,6 @@ import linecache
import random
import string
import imp
import socket
import fcntl
import errno
import datetime
@@ -24,6 +23,8 @@ import yaml
os.chdir(os.path.dirname(os.path.abspath(__file__)))
prev_line = None
def traceit(f, e, a):
if e == "line":
lineno = f.f_lineno
@@ -44,11 +45,13 @@ def traceit(f, e, a):
# sit in the same dir
tests_root = None
def clean_tests_root():
global tests_root
if tests_root:
os.rmdir(tests_root)
def make_tests_root():
global tests_root
if not tests_root:
@@ -60,12 +63,14 @@ def make_tests_root():
report_dir = None
def init_report(path):
global report_dir
report_dir = path
if not os.access(report_dir, os.F_OK):
os.makedirs(report_dir)
def add_to_report(path, tgt_name):
global report_dir
if report_dir:
@@ -82,6 +87,7 @@ def add_to_report(path, tgt_name):
os.mkdir(os.path.dirname(tgt_path))
shutil.copy2(path, tgt_path)
def add_to_output(path):
global report_dir
if not report_dir:
@@ -106,6 +112,7 @@ arch = os.uname()[4]
# uns -- user namespace, the same as above plus user namespace
#
class host_flavor:
def __init__(self, opts):
self.name = "host"
@@ -122,6 +129,7 @@ class host_flavor:
def clean():
pass
class ns_flavor:
__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
# needs minus vdso and gate .so-s
libs = map(lambda x: x[1] == '=>' and x[2] or x[0], \
map(lambda x: x.split(), \
filter(lambda x: not xl.match(x), \
map(lambda x: x.strip(), \
libs = map(lambda x: x[1] == '=>' and x[2] or x[0],
map(lambda x: x.split(),
filter(lambda x: not xl.match(x),
map(lambda x: x.strip(),
filter(lambda x: x.startswith('\t'), ldd.stdout.readlines())))))
ldd.wait()
@@ -254,23 +262,28 @@ flavors = { 'h': host_flavor, 'ns': ns_flavor, 'uns': userns_flavor }
# Helpers
#
def encode_flav(f):
return (flavors.keys().index(f) + 128)
def decode_flav(i):
i = i - 128
if flavors.has_key(i):
if i in flavors:
return flavors.keys()[i - 128]
return "unknown"
def tail(path):
p = subprocess.Popen(['tail', '-n1', path],
stdout = subprocess.PIPE)
return p.stdout.readline()
def rpidfile(path):
return open(path).readline().strip()
def wait_pid_die(pid, who, tmo = 30):
stime = 0.1
while stime < tmo:
@@ -285,6 +298,7 @@ def wait_pid_die(pid, who, tmo = 30):
else:
raise test_fail_exc("%s die" % who)
def test_flag(tdesc, flag):
return flag in tdesc.get('flags', '').split()
@@ -294,10 +308,12 @@ def test_flag(tdesc, flag):
# test checks fail
#
class test_fail_exc:
def __init__(self, step):
self.step = step
class test_fail_expected_exc:
def __init__(self, cr_action):
self.cr_action = cr_action
@@ -306,6 +322,7 @@ class test_fail_expected_exc:
# A test from zdtm/ directory.
#
class zdtm_test:
def __init__(self, name, desc, flavor, freezer):
self.__name = name
@@ -323,8 +340,8 @@ class zdtm_test:
def __make_action(self, act, env = None, root = None):
sys.stdout.flush() # Not to let make's messages appear before ours
tpath = self.__name + '.' + act
s_args = ['make', '--no-print-directory', \
'-C', os.path.dirname(tpath), \
s_args = ['make', '--no-print-directory',
'-C', os.path.dirname(tpath),
os.path.basename(tpath)]
if env:
@@ -379,7 +396,7 @@ class zdtm_test:
criu_dir = os.path.dirname(os.getcwd())
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])
self.__make_action('pid', env, self.__flavor.root)
@@ -408,7 +425,7 @@ class zdtm_test:
self.kill(signal.SIGTERM)
res = tail(self.__name + '.out')
if not 'PASS' in res.split():
if 'PASS' not in res.split():
raise test_fail_exc("result check")
def getpid(self):
@@ -606,7 +623,7 @@ class groups_test(zdtm_test):
for test in self.__subs:
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)
@@ -618,6 +635,8 @@ test_classes = { 'zdtm': zdtm_test, 'inhfd': inhfd_test, 'groups': groups_test }
criu_bin = "../criu/criu"
join_ns_file = '/run/netns/zdtm_netns'
class criu_cli:
def __init__(self, opts):
self.__test = None
@@ -801,6 +820,7 @@ def try_run_hook(test, args):
do_sbs = False
def init_sbs():
if sys.stdout.isatty():
global do_sbs
@@ -808,18 +828,20 @@ def init_sbs():
else:
print "Can't do step-by-step in this runtime"
def sbs(what):
if do_sbs:
raw_input("Pause at %s. Press any key to continue." % what)
#
# Main testing entity -- dump (probably with pre-dumps) and restore
#
def iter_parm(opt, dflt):
x = ((opt or str(dflt)) + ":0").split(':')
return (xrange(0, int(x[0])), float(x[1]))
def cr(cr_api, test, opts):
if opts['nocr']:
return
@@ -890,6 +912,7 @@ def get_visible_state(test):
mounts[pid] = cmounts
return files, maps, mounts
def check_visible_state(test, state, opts):
new = get_visible_state(test)
@@ -982,6 +1005,7 @@ def get_freezer(desc):
fr = cg_freezer(path = fd[0], state = fd[1])
return fr
def cmp_ns(ns1, match, ns2, msg):
ns1_ino = os.stat(ns1).st_ino
ns2_ino = os.stat(ns2).st_ino
@@ -1048,6 +1072,7 @@ def do_run_test(tname, tdesc, flavs, opts):
cr_api.cleanup()
print_sep("Test %s PASS" % tname)
class launcher:
def __init__(self, opts, nr_tests):
self.__opts = opts
@@ -1103,8 +1128,8 @@ class launcher:
self.__nr += 1
self.__show_progress()
nd = ('nocr', 'norst', 'pre', 'iters', 'page_server', 'sibling', \
'fault', 'keep_img', 'report', 'snaps', 'sat', 'script', \
nd = ('nocr', 'norst', 'pre', 'iters', 'page_server', 'sibling',
'fault', 'keep_img', 'report', 'snaps', 'sat', 'script',
'join_ns', 'dedup', 'sbs', 'freezecg', 'user', 'dry_run')
arg = repr((name, desc, flavor, {d: self.__opts[d] for d in nd}))
@@ -1115,8 +1140,8 @@ class launcher:
logf = None
log = None
sub = subprocess.Popen(["./zdtm_ct", "zdtm.py"], \
env = dict(os.environ, CR_CT_TEST_INFO = arg ), \
sub = subprocess.Popen(["./zdtm_ct", "zdtm.py"],
env = dict(os.environ, CR_CT_TEST_INFO = arg),
stdout = log, stderr = subprocess.STDOUT, close_fds = True)
self.__subs[sub.pid] = {'sub': sub, 'log': logf, 'name': name}
@@ -1176,16 +1201,17 @@ class launcher:
print_sep("FAIL", "#")
sys.exit(1)
def all_tests(opts):
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)
excl = map(lambda x: os.path.join(desc['dir'], x), desc['exclude'])
tlist = filter(lambda x: \
not x.endswith('.checkskip') and \
not x.endswith('.hook') and \
not x in excl, \
map(lambda x: x.strip(), lst.stdout.readlines()) \
tlist = filter(lambda x:
not x.endswith('.checkskip') and
not x.endswith('.hook') and
x not in excl,
map(lambda x: x.strip(), lst.stdout.readlines())
)
lst.wait()
return tlist
@@ -1211,6 +1237,7 @@ def self_checkskip(tname):
return False
def print_fname(fname, typ):
print "=[%s]=> %s" % (typ, fname)
@@ -1218,6 +1245,7 @@ def print_fname(fname, typ):
def print_sep(title, sep = "=", width = 80):
print (" " + title + " ").center(width, sep)
def grep_errors(fname):
first = True
for l in open(fname):
@@ -1230,6 +1258,7 @@ def grep_errors(fname):
if not first:
print_sep("ERROR OVER", "-", 60)
def run_tests(opts):
excl = None
features = {}
@@ -1237,7 +1266,7 @@ def run_tests(opts):
if opts['pre'] or opts['snaps']:
if not criu_cli.check("mem_dirty_track"):
print "Tracking memory is not available"
return;
return
if opts['keep_going'] and (not opts['all']):
print "[WARNING] Option --keep-going is more useful with option --all."
@@ -1303,7 +1332,7 @@ def run_tests(opts):
feat = tdesc.get('feature', None)
if feat:
if not features.has_key(feat):
if feat not in features:
print "Checking feature %s" % feat
features[feat] = criu_cli.check(feat)
@@ -1355,6 +1384,7 @@ def run_tests(opts):
sti_fmt = "%-40s%-10s%s"
def show_test_info(t):
tdesc = get_test_desc(t)
flavs = tdesc.get('flavor', '')
@@ -1436,6 +1466,7 @@ class group:
self.__dump_meta(fname, '.checkskip')
self.__dump_meta(fname, '.hook')
def group_tests(opts):
excl = None
groups = []
@@ -1495,7 +1526,7 @@ def clean_stuff(opts):
# 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
# collect this namespace's zombies
status = 0
@@ -1511,7 +1542,7 @@ if os.environ.has_key('CR_CT_TEST_INFO'):
status = os.WEXITSTATUS(status)
else:
status = 1
break;
break
sys.exit(status)