[CRIU] [PATCH 4/4] test: rpc: add multireq test

Ruslan Kuprieiev kupruser at gmail.com
Sun Feb 2 02:55:58 PST 2014


This example shows what we've get instead of deleted pre_dump_loop().

Signed-off-by: Ruslan Kuprieiev <kupruser at gmail.com>
---
 test/rpc/multireq-pre-dump.py | 67 +++++++++++++++++++++++++++++++++++++++++++
 test/rpc/run.sh               |  3 ++
 test/rpc/test.py              |  7 ++++-
 3 files changed, 76 insertions(+), 1 deletion(-)
 create mode 100755 test/rpc/multireq-pre-dump.py

diff --git a/test/rpc/multireq-pre-dump.py b/test/rpc/multireq-pre-dump.py
new file mode 100755
index 0000000..a70905d
--- /dev/null
+++ b/test/rpc/multireq-pre-dump.py
@@ -0,0 +1,67 @@
+#!/usr/bin/python
+
+import socket, os, imp, sys, subprocess, time
+
+p = os.getcwd()
+sys.path.append(p)
+import rpc_pb2 as rpc
+
+# Connect to service socket
+s = socket.socket(socket.AF_UNIX, socket.SOCK_SEQPACKET)
+s.connect('criu_service.socket')
+
+# Tell criu, we want to use multireq mode
+req			= rpc.criu_req()
+req.type		= rpc.MULTIREQ
+req.opts.images_dir_fd	= os.open('.', os.O_DIRECTORY)
+req.opts.log_file	= "multireq.log"
+req.opts.log_level	= 4
+
+s.send(req.SerializeToString())
+
+resp		= rpc.criu_resp()
+MAX_MSG_SIZE	= 1024
+resp.ParseFromString(s.recv(MAX_MSG_SIZE))
+
+if resp.success:
+	print 'Success, multireq mode enabled'
+else:
+	print "Fail, can't enable multireq mode"
+	sys.exit(-1)
+
+# run loop.sh and form dump requests
+p = subprocess.Popen("../loop.sh")
+
+# form pre-dump request
+req			= rpc.criu_req()
+req.opts.pid		= p.pid
+req.type		= rpc.PRE_DUMP
+#req.opts.leave_running	= True
+req.opts.shell_job	= True
+req.opts.log_level	= 4
+if not os.path.exists('loop_pre'):
+	os.makedirs('loop_pre')
+req.opts.images_dir_fd	= os.open('loop_pre', os.O_DIRECTORY)
+
+# pre-dump 3 times with 2 sec interval
+resp = rpc.criu_resp()
+for i in range(0, 3):
+	req.id = i
+	time.sleep(2)
+	s.send(req.SerializeToString())
+	resp.ParseFromString(s.recv(MAX_MSG_SIZE))
+	print "pre-dump #"+repr(resp.id)+": "
+	if resp.success:
+		print "success"
+	else:
+		print "fail"
+
+# dump
+req.type = rpc.DUMP
+s.send(req.SerializeToString())
+resp.ParseFromString(s.recv(MAX_MSG_SIZE))
+print "dump: "
+if resp.success:
+	print "success"
+else:
+	print "fail"
diff --git a/test/rpc/run.sh b/test/rpc/run.sh
index 7cc8c52..88cf8a8 100755
--- a/test/rpc/run.sh
+++ b/test/rpc/run.sh
@@ -64,4 +64,7 @@ title_print "Run restore-loop"
 ../restore-loop.py || _exit $?
 kill -SIGTERM ${P}
 
+title_print "Run multireq test (pre-dump and dump loop.sh)"
+../multireq-pre-dump.py || _exit $?
+
 _exit 0
diff --git a/test/rpc/test.py b/test/rpc/test.py
index 5c30ef2..ed516dc 100755
--- a/test/rpc/test.py
+++ b/test/rpc/test.py
@@ -1,6 +1,6 @@
 #!/usr/bin/python
 
-import socket, os, imp, sys
+import socket, os, imp, sys, random
 
 p = os.getcwd()
 sys.path.append(p)
@@ -14,6 +14,7 @@ s.connect('criu_service.socket')
 # and set dump options. Checkout more options in protobuf/rpc.proto
 req			= rpc.criu_req()
 req.type		= rpc.DUMP
+req.id			= random.randint(0,100)
 req.opts.leave_running	= True
 req.opts.shell_job	= True
 req.opts.log_level	= 4
@@ -31,6 +32,10 @@ resp		= rpc.criu_resp()
 MAX_MSG_SIZE	= 1024
 resp.ParseFromString(s.recv(MAX_MSG_SIZE))
 
+print "resp.id = %d, req.id = %d\n" %(resp.id,req.id)
+if resp.id != req.id:
+	print "id mismatch(it's ok if 'Restored')"
+
 if resp.type != rpc.DUMP:
 	print 'Unexpected msg type'
 	sys.exit(-1)
-- 
1.8.3.2



More information about the CRIU mailing list