[CRIU] [PATCH 8/8] test: rpc: cr_errno, v2

Ruslan Kuprieiev kupruser at gmail.com
Tue Dec 2 04:29:45 PST 2014


Lets simulate some errors and check what
error will be returned by service.

v2, fix tests accordingly to new errorlist

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

diff --git a/test/rpc/errno.py b/test/rpc/errno.py
new file mode 100755
index 0000000..d90293c
--- /dev/null
+++ b/test/rpc/errno.py
@@ -0,0 +1,133 @@
+#!/usr/bin/python
+# Test criu errno
+
+import socket, os, imp, sys, errno
+
+p = os.getcwd()
+sys.path.append(p)
+import rpc_pb2 as rpc
+
+
+# Prepare dir for images
+class test:
+	def __init__(self):
+		imgs_path = "imgs_errno"
+		if not os.path.exists(imgs_path):
+			os.makedirs(imgs_path)
+		self.imgs_fd = os.open(imgs_path, os.O_DIRECTORY)
+		self.s = -1
+		self._MAX_MSG_SIZE = 1024
+
+	def connect(self):
+		self.s = socket.socket(socket.AF_UNIX, socket.SOCK_SEQPACKET)
+		self.s.connect('criu_service.socket')
+
+	def get_base_req(self):
+		req			= rpc.criu_req()
+		req.opts.log_level	= 4
+		req.opts.images_dir_fd	= self.imgs_fd
+		return req
+
+	def send_req(self, req):
+		self.connect()
+		self.s.send(req.SerializeToString())
+
+	def recv_resp(self):
+		resp = rpc.criu_resp()
+		resp.ParseFromString(self.s.recv(self._MAX_MSG_SIZE))
+		return resp
+
+	def check_cr_errno(self, resp, err):
+		if resp.success:
+			raise Exception('Unexpected success = True')
+		else:
+			if resp.cr_errno != err:
+				raise Exception('Unexpected cr_errno ' + str(resp.cr_errno))
+
+	def no_process(self):
+		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:
+			pid = int(f.readline())
+			try:
+				os.kill(pid, 0)
+			except OSError:
+				pass
+			else:
+				raise Exception('max pid is taken')
+
+		# Ask criu to dump non-existing process.
+		req = self.get_base_req()
+		req.type = rpc.DUMP
+		req.opts.pid = pid
+
+		self.send_req(req)
+		resp = self.recv_resp()
+
+		self.check_cr_errno(resp, errno.ESRCH)
+
+		print 'Success'
+
+	def process_exists(self):
+		print 'Try to restore process which pid is already taken by other process'
+
+		# Perform self-dump
+		req = self.get_base_req()
+		req.type		= rpc.DUMP
+		req.opts.shell_job	= True
+		req.opts.leave_running	= True
+
+		self.send_req(req)
+		resp = self.recv_resp()
+
+		if resp.success != True:
+			raise Exception('Self-dump failed')
+
+		# Ask to restore process from images of ourselves
+		req = self.get_base_req()
+		req.type = rpc.RESTORE
+
+		self.send_req(req)
+		resp = self.recv_resp()
+
+		self.check_cr_errno(resp, errno.EEXIST)
+
+		print 'Success'
+
+	def bad_options(self):
+		print 'Try to send criu invalid opts'
+
+		# Subdirs are not allowed in log_file
+		req = self.get_base_req()
+		req.type = rpc.DUMP
+		req.opts.log_file = "../file.log"
+
+		self.send_req(req)
+		resp = self.recv_resp()
+
+		self.check_cr_errno(resp, errno.EBADRQC)
+
+		print 'Success'
+
+	def bad_request(self):
+		print 'Try to send criu invalid request type'
+
+		req = self.get_base_req()
+		req.type = rpc.NOTIFY
+
+		self.send_req(req)
+		resp = self.recv_resp()
+
+		self.check_cr_errno(resp, errno.ENOTSUP)
+
+		print 'Success'
+
+	def run(self):
+		self.no_process()
+		self.process_exists()
+		self.bad_options()
+		self.bad_request()
+
+t = test()
+t.run()
diff --git a/test/rpc/run.sh b/test/rpc/run.sh
index 896d472..b9455f6 100755
--- a/test/rpc/run.sh
+++ b/test/rpc/run.sh
@@ -67,4 +67,7 @@ kill -SIGTERM ${P}
 title_print "Run ps_test"
 ../ps_test.py || _exit $?
 
+title_print "Run cr_errno test"
+../errno.py || _exit $?
+
 _exit 0
-- 
1.9.3



More information about the CRIU mailing list