From 908e5dd95ddb4fb81be750e4c6dff6fbb444de29 Mon Sep 17 00:00:00 2001 From: Adrian Reber Date: Mon, 6 Dec 2021 16:51:21 +0000 Subject: [PATCH] lib: added tests for feature check in libcriu Signed-off-by: Adrian Reber --- test/others/libcriu/.gitignore | 1 + test/others/libcriu/Makefile | 1 + test/others/libcriu/run.sh | 10 ++++ test/others/libcriu/test_feature_check.c | 65 ++++++++++++++++++++++++ 4 files changed, 77 insertions(+) create mode 100644 test/others/libcriu/test_feature_check.c diff --git a/test/others/libcriu/.gitignore b/test/others/libcriu/.gitignore index 15abf07ac..0f6e52bb4 100644 --- a/test/others/libcriu/.gitignore +++ b/test/others/libcriu/.gitignore @@ -5,5 +5,6 @@ test_self test_sub test_join_ns test_pre_dump +test_feature_check output/ libcriu.so.* diff --git a/test/others/libcriu/Makefile b/test/others/libcriu/Makefile index 581574da0..ae7330533 100644 --- a/test/others/libcriu/Makefile +++ b/test/others/libcriu/Makefile @@ -7,6 +7,7 @@ TESTS += test_iters TESTS += test_errno TESTS += test_join_ns TESTS += test_pre_dump +TESTS += test_feature_check all: $(TESTS) .PHONY: all diff --git a/test/others/libcriu/run.sh b/test/others/libcriu/run.sh index 1b6c73448..77bdfb87e 100755 --- a/test/others/libcriu/run.sh +++ b/test/others/libcriu/run.sh @@ -62,6 +62,16 @@ if [ "$(uname -m)" = "x86_64" ]; then fi run_test test_errno run_test test_join_ns +if criu check --feature mem_dirty_track > /dev/null; then + export CRIU_FEATURE_MEM_TRACK=1 +fi +if criu check --feature uffd-noncoop > /dev/null; then + export CRIU_FEATURE_LAZY_PAGES=1 +fi +if criu check --feature pidfd_store > /dev/null; then + export CRIU_FEATURE_PIDFD_STORE=1 +fi +run_test test_feature_check echo "== Tests done" make libcriu_clean diff --git a/test/others/libcriu/test_feature_check.c b/test/others/libcriu/test_feature_check.c new file mode 100644 index 000000000..d88e0de23 --- /dev/null +++ b/test/others/libcriu/test_feature_check.c @@ -0,0 +1,65 @@ +#include "criu.h" +#include +#include +#include +#include +#include +#include +#include +#include + +#include "lib.h" + +int main(int argc, char **argv) +{ + int ret; + char *env; + bool mem_track = 0; + bool lazy_pages = 0; + bool pidfd_store = 0; + struct criu_feature_check features = { + .mem_track = true, + .lazy_pages = true, + .pidfd_store = true, + }; + + printf("--- Start feature check ---\n"); + criu_init_opts(); + criu_set_service_binary(argv[1]); + + env = getenv("CRIU_FEATURE_MEM_TRACK"); + if (env) { + mem_track = true; + } + env = getenv("CRIU_FEATURE_LAZY_PAGES"); + if (env) { + lazy_pages = true; + } + env = getenv("CRIU_FEATURE_PIDFD_STORE"); + if (env) { + pidfd_store = true; + } + + ret = criu_feature_check(&features, sizeof(features) + 1); + printf(" `- passing too large structure to libcriu should return -1: %d\n", ret); + if (ret != -1) + return -1; + + ret = criu_feature_check(&features, sizeof(features)); + if (ret < 0) { + what_err_ret_mean(ret); + return ret; + } + + printf(" `- mem_track : %d - expected : %d\n", features.mem_track, mem_track); + if (features.mem_track != mem_track) + return -1; + printf(" `- lazy_pages : %d - expected : %d\n", features.lazy_pages, lazy_pages); + if (features.lazy_pages != lazy_pages) + return -1; + printf(" `- pidfd_store: %d - expected : %d\n", features.pidfd_store, pidfd_store); + if (features.pidfd_store != pidfd_store) + return -1; + + return 0; +}