[CRIU] [PATCH 5/5] test: rpc: add test for restore request

Ruslan Kuprieiev kupruser at gmail.com
Mon Sep 30 04:06:43 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..1055cff 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 &> ololo &
+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
diff --git a/test/rpc/test.c b/test/rpc/test.c
index e52bdde..1225636 100644
--- a/test/rpc/test.c
+++ b/test/rpc/test.c
@@ -5,6 +5,7 @@
 #include <sys/fcntl.h>
 #include <stdio.h>
 #include <dirent.h>
+#include <stdlib.h>
 
 #define MAX_MSG_SIZE 1024
 
@@ -83,24 +84,24 @@ int main()
 	 * Allocate CriuDumpReq.
 	 */
 	req.type			= CRIU_REQ_TYPE__DUMP;
-	req.dump			= malloc(sizeof(CriuDumpReq));
-	if (!req.dump) {
-			perror("Can't allocate memory for dump request");
+	req.opts			= malloc(sizeof(CriuOpts));
+	if (!req.opts) {
+			perror("Can't allocate memory for opts");
 			return -1;
 	}
 
-	criu_dump_req__init(req.dump);
+	criu_opts__init(req.opts);
 
 	/*
 	 * Set dump options.
 	 * Checkout more in protobuf/rpc.proto.
 	 */
-	req.dump->has_leave_running	= true;
-	req.dump->leave_running		= true;
-	req.dump->images_dir_fd		= dir_fd;
-	req.dump->has_shell_job		= true;
-	req.dump->shell_job		= true;
-	req.dump->log_level		= 4;
+	req.opts->has_leave_running	= true;
+	req.opts->leave_running		= true;
+	req.opts->images_dir_fd		= dir_fd;
+	req.opts->has_shell_job		= true;
+	req.opts->shell_job		= true;
+	req.opts->log_level		= 4;
 
 	/*
 	 * Connect to service socket
diff --git a/test/rpc/test.py b/test/rpc/test.py
index 46c6834..dcae3d1 100755
--- a/test/rpc/test.py
+++ b/test/rpc/test.py
@@ -14,13 +14,13 @@ 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.dump.leave_running	= True
-req.dump.shell_job	= True
+req.opts.leave_running	= True
+req.opts.shell_job	= True
 
 if not os.path.exists('imgs_py'):
 	os.makedirs('imgs_py')
 
-req.dump.images_dir_fd	= os.open('imgs_py', os.O_DIRECTORY)
+req.opts.images_dir_fd	= os.open('imgs_py', os.O_DIRECTORY)
 
 # Send request
 s.send(req.SerializeToString())


More information about the CRIU mailing list