[CRIU] [PATCH 4/4] test: rpc: test page-server

Ruslan Kuprieiev kupruser at gmail.com
Wed Sep 17 00:25:20 PDT 2014


Signed-off-by: Ruslan Kuprieiev <kupruser at gmail.com>
---
 test/rpc/ps_test.py | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 test/rpc/run.sh     |  3 +++
 2 files changed, 68 insertions(+)
 create mode 100755 test/rpc/ps_test.py

diff --git a/test/rpc/ps_test.py b/test/rpc/ps_test.py
new file mode 100755
index 0000000..2c02e2d
--- /dev/null
+++ b/test/rpc/ps_test.py
@@ -0,0 +1,65 @@
+#!/usr/bin/python
+
+import socket, os, imp, sys
+
+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')
+
+# Start page-server
+print 'Starting page-server'
+req			= rpc.criu_req()
+req.type		= rpc.PAGE_SERVER
+req.opts.log_file	= 'page-server.log'
+req.opts.log_level	= 4
+
+if not os.path.exists('ps_test'):
+	os.makedirs('ps_test')
+
+req.opts.images_dir_fd	= os.open('ps_test', os.O_DIRECTORY)
+
+s.send(req.SerializeToString())
+
+resp	= rpc.criu_resp()
+MAX_MSG_SIZE = 1024
+resp.ParseFromString(s.recv(MAX_MSG_SIZE))
+
+if resp.type != rpc.PAGE_SERVER:
+	print 'Unexpected msg type'
+	sys.exit(1)
+else:
+	if resp.success:
+		print 'Success, page-server started on port %u' %(resp.ps.port)
+	else:
+		print 'Failed to start page-server'
+		sys.exit(1)
+
+
+# Perform self-dump
+print 'Dumping myself using page-server'
+req.type		= rpc.DUMP
+req.opts.ps.port	= resp.ps.port
+req.opts.log_file	= 'dump.log'
+req.opts.shell_job	= True
+req.opts.leave_running	= True
+
+s.close()
+s = socket.socket(socket.AF_UNIX, socket.SOCK_SEQPACKET)
+s.connect('criu_service.socket')
+s.send(req.SerializeToString())
+
+resp.ParseFromString(s.recv(MAX_MSG_SIZE))
+
+if resp.type != rpc.DUMP:
+	print 'Unexpected msg type'
+	sys.exit(1)
+else:
+	if resp.success:
+		print 'Success'
+	else:
+		print 'Fail'
+		sys.exit(1)
diff --git a/test/rpc/run.sh b/test/rpc/run.sh
index 7cc8c52..896d472 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 ps_test"
+../ps_test.py || _exit $?
+
 _exit 0
-- 
1.9.3



More information about the CRIU mailing list