[CRIU] [PATCH 5/5] test: add a new test to check external terminals

Andrey Vagin avagin at openvz.org
Fri Dec 25 06:49:37 PST 2015


From: Andrew Vagin <avagin at virtuozzo.com>

It's an example how it can be used

Signed-off-by: Andrew Vagin <avagin at virtuozzo.com>
---
 test/ext-tty/run.py | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
 create mode 100755 test/ext-tty/run.py

diff --git a/test/ext-tty/run.py b/test/ext-tty/run.py
new file mode 100755
index 0000000..e37c260
--- /dev/null
+++ b/test/ext-tty/run.py
@@ -0,0 +1,36 @@
+import subprocess
+import pty
+import os, sys, time
+
+master, slave = pty.openpty()
+
+p = subprocess.Popen(["setsid", "--ctty", "sleep", "10000"],
+			stdin = slave, stdout = slave, stderr = slave, close_fds = True)
+st = os.stat("/proc/self/fd/%d" % slave)
+ttyid = "tty[%x:%x]" % (st.st_rdev, st.st_dev)
+os.close(slave)
+time.sleep(1)
+
+ret = subprocess.Popen(["../../criu", "dump", "-t", str(p.pid), "-v4", "--external", ttyid]).wait()
+if ret:
+	sys.exit(ret)
+p.wait()
+
+new_master, slave = pty.openpty() # get another pty pair
+os.close(master)
+
+ttyid = "fd[%d]:tty[%x:%x]" % (slave, st.st_rdev, st.st_dev)
+
+ret = subprocess.Popen(["../../criu", "restore", "-v4", "--inherit-fd", ttyid, "--restore-sibling", "--restore-detach"]).wait()
+if ret:
+	sys.exit(ret)
+os.close(slave)
+os.waitpid(-1, os.WNOHANG) # is the process alive
+
+os.close(new_master)
+_, status = os.wait()
+if not os.WIFSIGNALED(status) or not os.WTERMSIG(status):
+	print status
+	sys.exit(1)
+
+print "PASS"
-- 
2.4.3



More information about the CRIU mailing list