-
Notifications
You must be signed in to change notification settings - Fork 605
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
criu-ns: Add tests for criu-ns script (WIP)
These changes add test implementations for criu-ns script. Fixes: #1909 Signed-off-by: Dhanuka Warusadura <csx@tuta.io>
- Loading branch information
1 parent
ded46f6
commit 77a33f2
Showing
3 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
run: | ||
../../zdtm_ct run.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#!/usr/bin/env python | ||
|
||
import os | ||
import pty | ||
import shutil | ||
import subprocess | ||
import sys | ||
|
||
CR_NS = "../../../scripts/criu-ns" | ||
|
||
os.chdir(os.getcwd()) | ||
|
||
|
||
def check_dumpdir(): | ||
if os.path.isdir("dumpdir"): | ||
shutil.rmtree("dumpdir") | ||
os.mkdir("dumpdir", 0o755) | ||
|
||
|
||
def create_pty(): | ||
fd_m, fd_s = pty.openpty() | ||
return (os.fdopen(fd_m, "wb"), os.fdopen(fd_s, "wb")) | ||
|
||
|
||
def test_dump_and_restore_with_shell_job(): | ||
check_dumpdir() | ||
|
||
fd_m = fd_s = create_pty() | ||
pid = os.fork() | ||
if pid == 0: | ||
cmd = ["sleep", "inf"] | ||
print("Run: %s" % " ".join(cmd)) | ||
subprocess.Popen(cmd).wait() | ||
|
||
cmd = [CR_NS, "dump", "-D", "dumpdir", "-v4", "-o", "dump.log", | ||
"--shell-job", "-t", str(pid)] | ||
ret = subprocess.Popen(cmd).wait() | ||
if ret != 0: | ||
sys.exit(ret) | ||
|
||
fd_m, fd_s = create_pty() | ||
pid = os.fork() | ||
if pid == 0: | ||
cmd = [CR_NS, "restore", "-D", "dumpdir", "-v4", "-o", | ||
"restore.log", "--shell-job"] | ||
ret = subprocess.Popen(cmd).wait() | ||
if ret != 0: | ||
sys.exit(ret) | ||
|
||
os.waitpid(pid, 0) | ||
|
||
|
||
def test_dump_and_restore_without_shell_job(): | ||
check_dumpdir() | ||
|
||
fd_m, fd_s = create_pty() | ||
pid = os.fork() | ||
if pid == 0: | ||
os.setsid() | ||
cmd = ["sleep", "inf"] | ||
print("Run: %s" % " ".join(cmd)) | ||
subprocess.Popen(cmd, stdin=fd_s, stdout=fd_s, | ||
stderr=fd_s).wait() | ||
|
||
cmd = [CR_NS, "dump", "-D", "dumpdir", "-v4", "-o", "dump.log", | ||
"-t", str(pid)] | ||
ret = subprocess.Popen(cmd).wait() | ||
if ret != 0: | ||
sys.exit(ret) | ||
|
||
fd_m = fd_s = create_pty() | ||
pid = os.fork() | ||
if pid == 0: | ||
os.setsid() | ||
cmd = [CR_NS, "restore", "-D", "dumpdir", "-v4", "-o", "restore.log"] | ||
ret = subprocess.Popen(cmd).wait() | ||
if ret != 0: | ||
sys.exit(ret) | ||
|
||
os.waitpid(pid, 0) | ||
|
||
|
||
def test_dump_and_restore_with_restore_detached(): | ||
pass | ||
|
||
if __name__ == "__main__": | ||
test_dump_and_restore_with_shell_job() | ||
test_dump_and_restore_without_shell_job() | ||
test_dump_and_restore_with_restore_detached() | ||
sys.exit(0) |