From 6f09b4962b183ddd3eb90f6c2bcf12b2adaa9b2d Mon Sep 17 00:00:00 2001 From: Andrei Vagin Date: Fri, 16 Aug 2024 07:49:32 -0700 Subject: [PATCH] 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 --- test/cuda-checkpoint/.gitignore | 1 + test/cuda-checkpoint/Makefile | 17 +++++++++ test/cuda-checkpoint/cuda-checkpoint.c | 53 ++++++++++++++++++++++++++ test/zdtm.py | 16 +++++++- 4 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 test/cuda-checkpoint/.gitignore create mode 100644 test/cuda-checkpoint/Makefile create mode 100644 test/cuda-checkpoint/cuda-checkpoint.c diff --git a/test/cuda-checkpoint/.gitignore b/test/cuda-checkpoint/.gitignore new file mode 100644 index 000000000..717fb7028 --- /dev/null +++ b/test/cuda-checkpoint/.gitignore @@ -0,0 +1 @@ +cuda-checkpoint diff --git a/test/cuda-checkpoint/Makefile b/test/cuda-checkpoint/Makefile new file mode 100644 index 000000000..c59dadddc --- /dev/null +++ b/test/cuda-checkpoint/Makefile @@ -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 diff --git a/test/cuda-checkpoint/cuda-checkpoint.c b/test/cuda-checkpoint/cuda-checkpoint.c new file mode 100644 index 000000000..f35a4b41d --- /dev/null +++ b/test/cuda-checkpoint/cuda-checkpoint.c @@ -0,0 +1,53 @@ +/* The mocked version of cuda-checkpoint. */ +#include +#include +#include + +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; +} diff --git a/test/zdtm.py b/test/zdtm.py index 87914f740..6b2132cc3 100755 --- a/test/zdtm.py +++ b/test/zdtm.py @@ -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)