[CRIU] [PATCHv2 4/4] test: rpc: restore

Ruslan Kuprieiev kupruser at gmail.com
Wed Oct 2 12:45:35 PDT 2013


Signed-off-by: Ruslan Kuprieiev <kupruser at gmail.com>

-------------- next part --------------
---
diff --git a/test/rpc/loop.sh b/test/rpc/loop.sh
new file mode 100755
index 0000000..0ab34ce
--- /dev/null
+++ b/test/rpc/loop.sh
@@ -0,0 +1,4 @@
+#!/bin/bash
+while :; do
+	sleep 1
+done
diff --git a/test/rpc/restore-loop.py b/test/rpc/restore-loop.py
new file mode 100755
index 0000000..bf91cb5
--- /dev/null
+++ b/test/rpc/restore-loop.py
@@ -0,0 +1,37 @@
+#!/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')
+
+# Create criu msg, set it's type to dump request
+# and set dump options. Checkout more options in protobuf/rpc.proto
+req			= rpc.criu_req()
+req.type		= rpc.RESTORE
+
+req.opts.images_dir_fd	= os.open('imgs_loop', os.O_DIRECTORY)
+
+# Send request
+s.send(req.SerializeToString())
+
+# Recv response
+resp		= rpc.criu_resp()
+MAX_MSG_SIZE	= 1024
+resp.ParseFromString(s.recv(MAX_MSG_SIZE))
+
+if resp.type != rpc.RESTORE:
+	print 'Unexpected msg type'
+	sys.exit(-1)
+else:
+	if resp.success:
+		print 'Restore success'
+	else:
+		print 'Restore fail'
+		sys.exit(-1)
+	print "PID of the restored program is %d\n" %(resp.restore.pid)
diff --git a/test/rpc/run.sh b/test/rpc/run.sh
index 4d8260c..f13b040 100755
--- a/test/rpc/run.sh
+++ b/test/rpc/run.sh
@@ -24,6 +24,12 @@ function _exit {
 	exit $1
 }
 
+function check_and_term {
+	title_print "Check and term $1"
+	ps -C $1
+	pkill $1
+}
+
 title_print "Build programs"
 make clean
 mkdir build
@@ -45,4 +51,17 @@ ${CRIU} restore -v4 -o restore-c.log -D imgs_c --shell-job || _exit $?
 title_print "Restore test-py"
 ${CRIU} restore -v4 -o restore-py.log -D imgs_py --shell-job || _exit $?
 
+title_print "Run loop.sh"
+setsid ../loop.sh < /dev/null &> loop.log &
+P=${!}
+echo "pid ${P}"
+
+title_print "Dump loop.sh"
+mkdir imgs_loop
+${CRIU} dump -v4 -o dump-loop.log -D imgs_loop -t ${P} || _exit $?
+
+title_print "Run restore-loop"
+../restore-loop.py || _exit $?
+kill -SIGTERM ${P}
+
 _exit 0


More information about the CRIU mailing list