forked from checkpoint-restore/criu
-
Notifications
You must be signed in to change notification settings - Fork 0
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
These changes add test implementations for criu-ns script. Fixes: checkpoint-restore#1909 Signed-off-by: Dhanuka Warusadura <csx@tuta.io>
- Loading branch information
1 parent
a807c42
commit a62bac7
Showing
4 changed files
with
125 additions
and
2 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
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,108 @@ | ||
#!/usr/bin/env python | ||
|
||
import os | ||
import pty | ||
import shutil | ||
import subprocess | ||
import sys | ||
import time | ||
|
||
|
||
CRIU_BIN = "../../../criu/criu" | ||
CRIU_NS = "../../../scripts/criu-ns" | ||
|
||
|
||
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() | ||
|
||
open("running", "w").close() | ||
fd_m, fd_s = create_pty() | ||
pid = os.fork() | ||
if pid == 0: | ||
os.setsid() | ||
while True: | ||
if not os.access("running", os.F_OK): | ||
sys.exit(0) | ||
time.sleep(1) | ||
sys.exit(1) | ||
|
||
cmd = [CRIU_NS, "dump", "-D", "dumpdir", "-v", "--shell-job", | ||
"-t", str(pid), "--criu-binary", CRIU_BIN] | ||
ret = subprocess.Popen(cmd).wait() | ||
if ret != 0: | ||
sys.exit(ret) | ||
|
||
os.unlink("running") | ||
fd_m, fd_s = create_pty() | ||
pid = os.fork() | ||
if pid == 0: | ||
cmd = [CRIU_NS, "restore", "-D", "dumpdir", "-v", | ||
"--shell-job", "--criu-binary", CRIU_BIN] | ||
ret = subprocess.Popen(cmd).wait() | ||
if ret != 0: | ||
sys.exit(ret) | ||
os._exit(0) | ||
|
||
os.waitpid(pid, 0) | ||
|
||
|
||
def test_dump_and_restore_without_shell_job(restore_detached=False): | ||
check_dumpdir() | ||
|
||
open("running", "w").close() | ||
fd_m, fd_s = create_pty() | ||
pid = os.fork() | ||
if pid == 0: | ||
os.setsid() | ||
os.dup2(fd_s.fileno(), 0) | ||
os.dup2(fd_s.fileno(), 1) | ||
os.dup2(fd_s.fileno(), 2) | ||
while True: | ||
if not os.access("running", os.F_OK): | ||
sys.exit(0) | ||
time.sleep(1) | ||
sys.exit(1) | ||
|
||
cmd = [CRIU_NS, "dump", "-D", "dumpdir", "-v", "-t", str(pid), | ||
"--criu-binary", CRIU_BIN] | ||
ret = subprocess.Popen(cmd).wait() | ||
if ret != 0: | ||
sys.exit(ret) | ||
|
||
os.unlink("running") | ||
fd_m, fd_s = create_pty() | ||
pid = os.fork() | ||
if pid == 0: | ||
os.setsid() | ||
|
||
if restore_detached: | ||
cmd = [CRIU_NS, "restore", "-D", "dumpdir", "-v", | ||
"--restore-detached", "--criu-binary", | ||
CRIU_BIN] | ||
else: | ||
cmd = [CRIU_NS, "restore", "-D", "dumpdir", "-v", | ||
"--criu-binary", CRIU_BIN] | ||
|
||
ret = subprocess.Popen(cmd).wait() | ||
if ret != 0: | ||
sys.exit(ret) | ||
os._exit(0) | ||
|
||
os.waitpid(pid, 0) | ||
|
||
|
||
if __name__ == "__main__": | ||
test_dump_and_restore_with_shell_job() | ||
test_dump_and_restore_without_shell_job() | ||
test_dump_and_restore_without_shell_job(restore_detached=True) |