test/zdtm: allow to run tests with the mocked cuda-checkpoint tool

Here is an example how to run one test:
$ python test/zdtm.py run -t zdtm/static/env00 --ignore-taint --mocked-cuda-checkpoint

Signed-off-by: Andrei Vagin <avagin@google.com>
This commit is contained in:
Andrei Vagin 2024-08-16 07:49:32 -07:00 committed by Andrei Vagin
parent 67fe44e981
commit dea6305914
4 changed files with 85 additions and 2 deletions

1
test/cuda-checkpoint/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
cuda-checkpoint

View file

@ -0,0 +1,17 @@
CFLAGS += $(USERCFLAGS) $(ARCHCFLAGS)
BIN := cuda-checkpoint
SRC := cuda-checkpoint.c
DEP := $(SRC:%.c=%.d)
OBJ := $(SRC:%.c=%.o)
TARGETS := $(BIN)
include ../zdtm/Makefile.inc
all: $(TARGETS)
.PHONY: all
clean-more:
$(RM) $(TARGETS)
.PHONY: clean-more
clean: clean-more

View file

@ -0,0 +1,53 @@
/* The mocked version of cuda-checkpoint. */
#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
int c;
while (1) {
int option_index = 0;
static struct option long_options[] = {
{ "pid", required_argument, 0, 'p' },
{ "get-restore-tid", no_argument, 0, 'g' },
{ "action", required_argument, 0, 'a' },
{ "timeout", required_argument, 0, 't' },
{ "help", no_argument, 0, 'h' },
{ 0, 0, 0, 0 }
};
c = getopt_long(argc, argv, "p:ga:ht:",
long_options, &option_index);
if (c == -1)
break;
switch (c) {
case 'p':
printf("%s\n", optarg);
break;
case 'g':
case 'a':
case 't':
break;
case 'h':
printf("--action - execute an action");
break;
default:
fprintf(stderr, "getopt returned character code 0%o ??\n", c);
return 1;
}
}
if (optind < argc) {
fprintf(stderr, "non-option ARGV-elements: ");
while (optind < argc)
fprintf(stderr, "%s ", argv[optind++]);
fprintf(stderr, "\n");
return 1;
}
return 0;
}

View file

@ -684,6 +684,8 @@ class zdtm_test:
for name in opts['criu_plugin']:
subprocess.check_call(["make", '--no-print-directory', "-C", "plugins/", f"{name}_plugin.so"])
if 'mocked_cuda_checkpoint' in opts and opts['mocked_cuda_checkpoint']:
subprocess.check_call(["make", "-C", "cuda-checkpoint/"])
if 'rootless' in opts and opts['rootless']:
return
subprocess.check_call(
@ -1141,6 +1143,7 @@ class criu:
self.__pre_dump_mode = opts['pre_dump_mode']
self.__preload_libfault = bool(opts['preload_libfault'])
self.__mntns_compat_mode = bool(opts['mntns_compat_mode'])
self.__cuda_checkpoint = bool(opts['mocked_cuda_checkpoint'])
if opts['rpc']:
self.__criu = criu_rpc
@ -1223,6 +1226,9 @@ class criu:
s_args = ["--log-file", log, "--images-dir", self.__ddir(),
"--verbosity=4"] + opts
if self.__cuda_checkpoint:
s_args += [ "--libdir" , os.path.join(os.getcwd(), "..", "plugins", "cuda") ]
with open(os.path.join(self.__ddir(), action + '.cropt'), 'w') as f:
f.write(' '.join(s_args) + '\n')
@ -2160,7 +2166,7 @@ class Launcher:
'dedup', 'sbs', 'freezecg', 'user', 'dry_run', 'noauto_dedup',
'remote_lazy_pages', 'show_stats', 'lazy_migrate', 'stream',
'tls', 'criu_bin', 'crit_bin', 'pre_dump_mode', 'mntns_compat_mode',
'rootless', 'preload_libfault')
'rootless', 'preload_libfault', 'mocked_cuda_checkpoint')
arg = repr((name, desc, flavor, {d: self.__opts[d] for d in nd}))
if self.__use_log:
@ -2173,8 +2179,11 @@ class Launcher:
if opts['rootless'] and os.getuid() == 0:
os.setgid(NON_ROOT_UID)
os.setuid(NON_ROOT_UID)
env = dict(os.environ, CR_CT_TEST_INFO=arg)
if opts['mocked_cuda_checkpoint']:
env['PATH'] = os.path.join(os.getcwd(), "cuda-checkpoint") + ":" + env["PATH"]
sub = subprocess.Popen(["./zdtm_ct", "zdtm.py"],
env=dict(os.environ, CR_CT_TEST_INFO=arg),
env=env,
stdout=log,
stderr=subprocess.STDOUT,
close_fds=True)
@ -2871,6 +2880,9 @@ def get_cli_args():
choices=['amdgpu', 'cuda'],
nargs='+',
default=None)
rp.add_argument("--mocked-cuda-checkpoint",
action="store_true",
help="Run criu with the cuda plugin and the mocked cuda-checkpoint tool")
lp = sp.add_parser("list", help="List tests")
lp.set_defaults(action=list_tests)