[CRIU] [PATCH 2/4] Convert to python3 style print() syntax
Radostin Stoyanov
rstoyanov1 at gmail.com
Sun Sep 23 17:31:52 MSK 2018
Use __future__ imports to keep this working for python2
Signed-off-by: Radostin Stoyanov <rstoyanov1 at gmail.com>
---
soccr/test/run.py | 8 ++--
soccr/test/tcp-test.py | 7 ++--
test/check_actions.py | 4 +-
test/exhaustive/pipe.py | 26 ++++++-------
test/exhaustive/unix.py | 67 ++++++++++++++++-----------------
test/inhfd/fifo.py | 2 +-
test/others/ext-tty/run.py | 4 +-
test/others/mounts/mounts.py | 4 +-
test/others/rpc/errno.py | 16 ++++----
test/others/rpc/ps_test.py | 20 +++++-----
test/others/rpc/restore-loop.py | 8 ++--
test/others/rpc/test.py | 10 ++---
test/others/rpc/version.py | 2 +-
13 files changed, 89 insertions(+), 89 deletions(-)
diff --git a/soccr/test/run.py b/soccr/test/run.py
index c4d81fbd..a25c2926 100644
--- a/soccr/test/run.py
+++ b/soccr/test/run.py
@@ -12,7 +12,7 @@ dst = os.getenv("TCP_DST", "127.0.0.1")
sport = os.getenv("TCP_SPORT", "12345")
dport = os.getenv("TCP_DPORT", "54321")
-print sys.argv[1]
+print(sys.argv[1])
args = [sys.argv[1],
"--addr", src, "--port", sport, "--seq", "555",
"--next",
@@ -41,7 +41,7 @@ m.update(str2)
str2 = m.hexdigest()
if str2 != eval(s):
- print "FAIL", repr(str2), repr(s)
+ print("FAIL", repr(str2), repr(s))
sys.exit(5);
s = p1.stdout.read()
@@ -51,7 +51,7 @@ str1 = m.hexdigest()
s = p2.stdout.read()
if str1 != eval(s):
- print "FAIL", repr(str1), s
+ print("FAIL", repr(str1), s)
sys.exit(5);
if p1.wait():
@@ -59,4 +59,4 @@ if p1.wait():
if p2.wait():
sys.exit(1)
-print "PASS"
+print("PASS")
diff --git a/soccr/test/tcp-test.py b/soccr/test/tcp-test.py
index f401fc06..ff3fe29d 100755
--- a/soccr/test/tcp-test.py
+++ b/soccr/test/tcp-test.py
@@ -1,5 +1,6 @@
#!/usr/bin/env python2
+from __future__ import print_function
import sys, socket
import hashlib
@@ -7,13 +8,13 @@ sk = socket.fromfd(3, socket.AF_INET, socket.SOCK_STREAM)
s = sys.stdin.read()
ret = sk.send(s)
-print >> sys.stderr, "%s: send() -> %d" % (sys.argv[1], ret)
+print("%s: send() -> %d" % (sys.argv[1], ret), file=sys.stderr)
sk.shutdown(socket.SHUT_WR)
m = hashlib.md5()
while True:
s = sk.recv((1 << 20) * 10)
if not s:
break
- print >> sys.stderr, "%s: recv() -> %d" % (sys.argv[1], len(s))
+ print("%s: recv() -> %d" % (sys.argv[1], len(s)), file=sys.stderr)
m.update(s)
-print repr(m.hexdigest())
+print(repr(m.hexdigest()))
diff --git a/test/check_actions.py b/test/check_actions.py
index 96c07a75..0e3daf17 100755
--- a/test/check_actions.py
+++ b/test/check_actions.py
@@ -34,7 +34,7 @@ if actions:
if errors:
for x in errors:
- print x
+ print(x)
sys.exit(1)
-print 'PASS'
+print('PASS')
diff --git a/test/exhaustive/pipe.py b/test/exhaustive/pipe.py
index 47c052ef..b4453129 100755
--- a/test/exhaustive/pipe.py
+++ b/test/exhaustive/pipe.py
@@ -34,7 +34,7 @@ def mix(nr_tasks, nr_pipes):
# Called by a test sub-process. It just closes the not needed ends
# of pipes and sleeps waiting for death.
def make_pipes(task_nr, nr_pipes, pipes, comb, status_pipe):
- print '\t\tMake pipes for %d' % task_nr
+ print('\t\tMake pipes for %d' % task_nr)
# We need to make sure that pipes have their
# ends according to comb for task_nr
@@ -134,7 +134,7 @@ def check_pipes(kids, pipes, comb):
# and waits for a signal (unix socket message) to start checking
# the kids' FD tables.
def make_comb(comb, opts, status_pipe):
- print '\tMake pipes'
+ print('\tMake pipes')
# 1st -- make needed pipes
pipes = []
for p in xrange(0, opts.pipes):
@@ -168,7 +168,7 @@ def make_comb(comb, opts, status_pipe):
ex_code = 1
if k_res == '0' * opts.tasks:
- print '\tWait for C/R'
+ print('\tWait for C/R')
cmd_sk = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM, 0)
cmd_sk.bind('\0CRIUPCSK')
@@ -178,12 +178,12 @@ def make_comb(comb, opts, status_pipe):
os.close(status_pipe)
v = cmd_sk.recv(16)
if v == '0':
- print '\tCheck pipes'
+ print('\tCheck pipes')
res = check_pipes(kids, pipes, comb)
if res == None:
ex_code = 0
else:
- print '\tFAIL %s' % res
+ print('\tFAIL %s' % res)
# Just kill kids, all checks are done by us, we don't need'em any more
for t in kids:
@@ -194,27 +194,27 @@ def make_comb(comb, opts, status_pipe):
def cr_test(pid):
- print 'C/R test'
+ print('C/R test')
img_dir = 'pimg_%d' % pid
try:
os.mkdir(img_dir)
subprocess.check_call([criu_bin, 'dump', '-t', '%d' % pid, '-D', img_dir, '-o', 'dump.log', '-v4', '-j'])
except:
- print '`- dump fail'
+ print('`- dump fail')
return False
try:
os.waitpid(pid, 0)
subprocess.check_call([criu_bin, 'restore', '-D', img_dir, '-o', 'rst.log', '-v4', '-j', '-d', '-S'])
except:
- print '`- restore fail'
+ print('`- restore fail')
return False
return True
def run(comb, opts):
- print 'Checking %r' % comb
+ print('Checking %r' % comb)
cpipe = os.pipe()
pid = os.fork()
if pid == 0:
@@ -230,7 +230,7 @@ def run(comb, opts):
if res == '0':
res = cr_test(pid)
- print 'Wake up test'
+ print('Wake up test')
s = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM, 0)
if res:
res = '0'
@@ -249,7 +249,7 @@ def run(comb, opts):
if os.WIFEXITED(st):
st = os.WEXITSTATUS(st)
- print 'Done (%d, pid == %d)' % (st, pid)
+ print('Done (%d, pid == %d)' % (st, pid))
return st == 0
@@ -264,7 +264,7 @@ pipe_combs = mix(opts.tasks, opts.pipes)
for comb in pipe_combs:
if not run(comb, opts):
- print 'FAIL'
+ print('FAIL')
break
else:
- print 'PASS'
+ print('PASS')
diff --git a/test/exhaustive/unix.py b/test/exhaustive/unix.py
index 24d245d8..6b1ed85d 100755
--- a/test/exhaustive/unix.py
+++ b/test/exhaustive/unix.py
@@ -471,10 +471,10 @@ def chk_real_state(st):
try:
s_st = os.fstat(rsk.fileno())
except:
- print 'FAIL: Socket %d lost' % sk.sk_id
+ print('FAIL: Socket %d lost' % sk.sk_id)
return CHK_FAIL_SOCKET
if not stat.S_ISSOCK(s_st.st_mode):
- print 'FAIL: Not a socket %d at %d' % (sk.sk_id, rsk.fileno())
+ print('FAIL: Not a socket %d at %d' % (sk.sk_id, rsk.fileno()))
return CHK_FAIL_STAT
# First -- check the listen states and names
@@ -485,16 +485,16 @@ def chk_real_state(st):
rsk = st.real_sockets[sk.sk_id]
r_listen = rsk.getsockopt(socket.SOL_SOCKET, socket.SO_ACCEPTCONN)
if (sk.listen and r_listen == 0) or (not sk.listen and r_listen == 1):
- print "FAIL: Socket %d listen %d, expected %d" % \
- (sk.sk_id, r_listen, sk.listen and 1 or 0)
+ print("FAIL: Socket %d listen %d, expected %d"
+ % (sk.sk_id, r_listen, sk.listen and 1 or 0))
return CHK_FAIL_LISTEN
if sk.name:
r_name = rsk.getsockname()
w_name = sock.real_name_for(sk.name)
if r_name != w_name:
- print 'FAIL: Socket %d name mismatch [%s], want [%s]' % \
- (sk.sk_id, r_name, w_name)
+ print('FAIL: Socket %d name mismatch [%s], want [%s]'
+ % (sk.sk_id, r_name, w_name))
return CHK_FAIL_NAME
# Second -- check (accept) pending connections
@@ -513,10 +513,10 @@ def chk_real_state(st):
try:
acc.do(st)
except:
- print 'FAIL: Cannot accept pending connection for %d' % sk.sk_id
+ print('FAIL: Cannot accept pending connection for %d' % sk.sk_id)
return CHK_FAIL_ACCEPT
- print ' `- did %s' % acc.show()
+ print(' `- did %s' % acc.show())
# Third -- check inqueues
for sk in st.sockets:
@@ -531,18 +531,18 @@ def chk_real_state(st):
try:
r_msg, m_from = rsk.recvfrom(128)
except:
- print 'FAIL: No message in queue for %d' % sk.sk_id
+ print('FAIL: No message in queue for %d' % sk.sk_id)
return CHK_FAIL_RECV_0
w_msg = act_sendmsg.msgval(msg[1])
if r_msg != w_msg:
- print 'FAIL: Message misorder: %s want %s (from %d)' % \
- (r_msg, w_msg, msg[0])
+ print('FAIL: Message misorder: %s want %s (from %d)'
+ %(r_msg, w_msg, msg[0]))
return CHK_FAIL_RECV_MIX
# TODO -- check sender
- print ' `- recvd %d.%d msg %s -> %d' % \
- (msg[0], msg[1], m_from, sk.sk_id)
+ print(' `- recvd %d.%d msg %s -> %d'
+ % (msg[0], msg[1], m_from, sk.sk_id))
# Finally, after all sockets are visible and all inqueues are
# drained -- check the sockets connectivity
@@ -563,8 +563,7 @@ def chk_real_state(st):
rsk.send(msgv)
rmsg = psk.recv(128)
except:
- print 'FAIL: Connectivity %d -> %d lost' % \
- (sk.sk_id, sk.peer)
+ print('FAIL: Connectivity %d -> %d lost' % (sk.sk_id, sk.peer))
return CHK_FAIL_CONNECT
# If sockets are not connected the recv above
@@ -573,17 +572,17 @@ def chk_real_state(st):
# the hard way -- also check for the message being
# delivered for real
if rmsg != msgv:
- print 'FAIL: Connectivity %d -> %d not verified' % \
- (sk.sk_id, sk.peer)
+ print('FAIL: Connectivity %d -> %d not verified'
+ % (sk.sk_id, sk.peer))
return CHK_FAIL_CONNECT2
- print ' `- checked %d -> %d with %s' % (sk.sk_id, sk.peer, msgv)
+ print(' `- checked %d -> %d with %s' % (sk.sk_id, sk.peer, msgv))
return CHK_PASS
def chk_state(st, opts):
- print "Will check state"
+ print("Will check state")
sigsk_name = "\0" + "CRSIGSKC"
signal_sk = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM, 0)
@@ -606,25 +605,25 @@ def chk_state(st, opts):
for rsk in st.real_sockets.values():
rsk.close()
- print "`- dump"
+ print("`- dump")
img_path = "sti_" + st.describe()
try:
os.mkdir(img_path)
subprocess.check_call([criu_bin, "dump", "-t", "%d" % pid, "-D", img_path, "-v4", "-o", "dump.log", "-j"])
except:
- print "Dump failed"
+ print("Dump failed")
os.kill(pid, signal.SIGKILL)
return CHK_FAIL_DUMP
- print "`- restore"
+ print("`- restore")
try:
os.waitpid(pid, 0)
subprocess.check_call([criu_bin, "restore", "-D", img_path, "-v4", "-o", "rst.log", "-j", "-d", "-S"])
except:
- print "Restore failed"
+ print("Restore failed")
return CHK_FAIL_RESTORE
- print "`- check"
+ print("`- check")
signal_sk = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM, 0)
try:
signal_sk.sendto('check', sigsk_name)
@@ -636,11 +635,11 @@ def chk_state(st, opts):
if os.WIFEXITED(status):
status = os.WEXITSTATUS(status)
if status != CHK_PASS:
- print "`- exited with %d" % status
+ print("`- exited with %d" % status)
return status
elif os.WIFSIGNALED(status):
status = os.WTERMSIG(status)
- print "`- killed with %d" % status
+ print("`- killed with %d" % status)
return CHK_FAIL_KILLED
else:
return CHK_FAIL_UNKNOWN
@@ -649,7 +648,7 @@ def chk_state(st, opts):
def run_state(st, opts):
- print "Will run state"
+ print("Will run state")
pid = os.fork()
if pid != 0:
wpid, status = os.wait()
@@ -685,9 +684,9 @@ def proceed(st, seen, failed, opts, depth = 0):
# using less steps and it's better to proceed as we have
# depth to move forward and generate more states.
seen[desc] = len(st.steps)
- print '%s' % desc
+ print('%s' % desc)
for s in st.steps:
- print '\t%s' % s.show()
+ print('\t%s' % s.show())
if not opts.gen:
ret = run_state(st, opts)
@@ -731,7 +730,7 @@ opts.depth = int(opts.depth)
# XXX: does it make any sense to mix two types in one go?
if opts.stream and opts.dgram:
- print 'Choose only one type'
+ print('Choose only one type')
sys.exit(1)
if opts.stream:
@@ -739,7 +738,7 @@ if opts.stream:
elif opts.dgram:
sk_type = socket.SOCK_DGRAM
else:
- print 'Choose some type'
+ print('Choose some type')
sys.exit(1)
st = state(int(opts.sockets), sk_type)
@@ -748,8 +747,8 @@ failed = set()
proceed(st, seen, failed, opts)
if len(failed) == 0:
- print 'PASS (%d states)' % len(seen)
+ print('PASS (%d states)' % len(seen))
else:
- print 'FAIL %d/%d' % (len(failed), len(seen))
+ print('FAIL %d/%d' % (len(failed), len(seen)))
for f in failed:
- print "\t%-50s: %s" % (f[0], fail_desc.get(f[1], 'unknown reason %d' % f[1]))
+ print("\t%-50s: %s" % (f[0], fail_desc.get(f[1], 'unknown reason %d' % f[1])))
diff --git a/test/inhfd/fifo.py b/test/inhfd/fifo.py
index 11703e1c..40af371a 100755
--- a/test/inhfd/fifo.py
+++ b/test/inhfd/fifo.py
@@ -13,7 +13,7 @@ def create_fds():
os.system("umount -l %s" % tdir)
os.rmdir(tdir)
- mnt_id = -1;
+ mnt_id = -1
with open("/proc/self/fdinfo/%d" % fd1.fileno()) as f:
for l in f:
l = l.split()
diff --git a/test/others/ext-tty/run.py b/test/others/ext-tty/run.py
index 052f9c1a..f44b1d94 100755
--- a/test/others/ext-tty/run.py
+++ b/test/others/ext-tty/run.py
@@ -30,7 +30,7 @@ os.waitpid(-1, os.WNOHANG) # is the process alive
os.close(new_master)
_, status = os.wait()
if not os.WIFSIGNALED(status) or os.WTERMSIG(status) != signal.SIGHUP:
- print status
+ print(status)
sys.exit(1)
-print "PASS"
+print("PASS")
diff --git a/test/others/mounts/mounts.py b/test/others/mounts/mounts.py
index 7f11d7dc..474feed4 100755
--- a/test/others/mounts/mounts.py
+++ b/test/others/mounts/mounts.py
@@ -14,10 +14,10 @@ def mount(src, dst, shared, private, slave):
else:
cmd += " -t tmpfs none '%s'" % (dst)
- print cmd
+ print(cmd)
ret = os.system(cmd)
if ret:
- print "failed"
+ print("failed")
root = tempfile.mkdtemp(prefix = "root.mount", dir = "/tmp")
mount(None, root, 1, 0, 0)
diff --git a/test/others/rpc/errno.py b/test/others/rpc/errno.py
index 20937a0b..ee9e90d8 100755
--- a/test/others/rpc/errno.py
+++ b/test/others/rpc/errno.py
@@ -48,7 +48,7 @@ class test:
raise Exception('Unexpected cr_errno ' + str(resp.cr_errno))
def no_process(self):
- print 'Try to dump unexisting process'
+ print('Try to dump unexisting process')
# Get pid of non-existing process.
# Suppose max_pid is not taken by any process.
with open("/proc/sys/kernel/pid_max", "r") as f:
@@ -70,10 +70,10 @@ class test:
self.check_resp(resp, rpc.DUMP, errno.ESRCH)
- print 'Success'
+ print('Success')
def process_exists(self):
- print 'Try to restore process which pid is already taken by other process'
+ print('Try to restore process which pid is already taken by other process')
# Perform self-dump
req = self.get_base_req()
@@ -95,10 +95,10 @@ class test:
self.check_resp(resp, rpc.RESTORE, errno.EEXIST)
- print 'Success'
+ print('Success')
def bad_options(self):
- print 'Try to send criu invalid opts'
+ print('Try to send criu invalid opts')
# Subdirs are not allowed in log_file
req = self.get_base_req()
@@ -110,10 +110,10 @@ class test:
self.check_resp(resp, rpc.DUMP, errno.EBADRQC)
- print 'Success'
+ print('Success')
def bad_request(self):
- print 'Try to send criu invalid request type'
+ print('Try to send criu invalid request type')
req = self.get_base_req()
req.type = rpc.NOTIFY
@@ -123,7 +123,7 @@ class test:
self.check_resp(resp, rpc.EMPTY, None)
- print 'Success'
+ print('Success')
def run(self):
self.no_process()
diff --git a/test/others/rpc/ps_test.py b/test/others/rpc/ps_test.py
index d40dbf09..1872120f 100755
--- a/test/others/rpc/ps_test.py
+++ b/test/others/rpc/ps_test.py
@@ -15,7 +15,7 @@ s = socket.socket(socket.AF_UNIX, socket.SOCK_SEQPACKET)
s.connect(args['socket'])
# Start page-server
-print 'Starting page-server'
+print('Starting page-server')
req = rpc.criu_req()
req.type = rpc.PAGE_SERVER
req.opts.log_file = 'page-server.log'
@@ -29,7 +29,7 @@ MAX_MSG_SIZE = 1024
resp.ParseFromString(s.recv(MAX_MSG_SIZE))
if resp.type != rpc.PAGE_SERVER:
- print 'Unexpected msg type'
+ print('Unexpected msg type')
sys.exit(1)
else:
if resp.success:
@@ -38,18 +38,18 @@ else:
os.kill(resp.ps.pid, 0)
except OSError as err:
if err.errno == errno.ESRCH:
- print 'No process with page-server pid %d' %(resp.ps.pid)
+ print('No process with page-server pid %d' %(resp.ps.pid))
else:
- print 'Can\'t check that process %d exists' %(resp.ps.pid)
+ print('Can\'t check that process %d exists' %(resp.ps.pid))
sys.exit(1)
- print 'Success, page-server pid %d started on port %u' %(resp.ps.pid, resp.ps.port)
+ print('Success, page-server pid %d started on port %u' %(resp.ps.pid, resp.ps.port))
else:
- print 'Failed to start page-server'
+ print('Failed to start page-server')
sys.exit(1)
# Perform self-dump
-print 'Dumping myself using page-server'
+print('Dumping myself using page-server')
req.type = rpc.DUMP
req.opts.ps.port = resp.ps.port
req.opts.ps.address = "127.0.0.1"
@@ -64,11 +64,11 @@ s.send(req.SerializeToString())
resp.ParseFromString(s.recv(MAX_MSG_SIZE))
if resp.type != rpc.DUMP:
- print 'Unexpected msg type'
+ print('Unexpected msg type')
sys.exit(1)
else:
if resp.success:
- print 'Success'
+ print('Success')
else:
- print 'Fail'
+ print('Fail')
sys.exit(1)
diff --git a/test/others/rpc/restore-loop.py b/test/others/rpc/restore-loop.py
index 2577a994..ce5786a5 100755
--- a/test/others/rpc/restore-loop.py
+++ b/test/others/rpc/restore-loop.py
@@ -34,12 +34,12 @@ MAX_MSG_SIZE = 1024
resp.ParseFromString(s.recv(MAX_MSG_SIZE))
if resp.type != rpc.RESTORE:
- print 'Unexpected msg type'
+ print('Unexpected msg type')
sys.exit(-1)
else:
if resp.success:
- print 'Restore success'
+ print('Restore success')
else:
- print 'Restore fail'
+ print('Restore fail')
sys.exit(-1)
- print "PID of the restored program is %d\n" %(resp.restore.pid)
+ print("PID of the restored program is %d\n" %(resp.restore.pid))
diff --git a/test/others/rpc/test.py b/test/others/rpc/test.py
index 56f03b03..fe67103b 100755
--- a/test/others/rpc/test.py
+++ b/test/others/rpc/test.py
@@ -31,17 +31,17 @@ MAX_MSG_SIZE = 1024
resp.ParseFromString(s.recv(MAX_MSG_SIZE))
if resp.type != rpc.DUMP:
- print 'Unexpected msg type'
+ print('Unexpected msg type')
sys.exit(-1)
else:
if resp.success:
- print 'Success'
+ print('Success')
else:
- print 'Fail'
+ print('Fail')
sys.exit(-1)
if resp.dump.restored:
- print 'Restored'
+ print('Restored')
# Connect to service socket
s = socket.socket(socket.AF_UNIX, socket.SOCK_SEQPACKET)
@@ -77,5 +77,5 @@ else:
if resp.version.HasField('name'):
print('CRIU name %s' % resp.version.name)
else:
- print 'Fail'
+ print('Fail')
sys.exit(-1)
diff --git a/test/others/rpc/version.py b/test/others/rpc/version.py
index 7c2cc2cd..5cca4e24 100755
--- a/test/others/rpc/version.py
+++ b/test/others/rpc/version.py
@@ -43,5 +43,5 @@ else:
if resp.version.HasField('name'):
print('CRIU name %s' % resp.version.name)
else:
- print 'Fail'
+ print('Fail')
sys.exit(-1)
--
2.17.1
More information about the CRIU
mailing list