lib: added tests for feature check in libcriu

Signed-off-by: Adrian Reber <areber@redhat.com>
This commit is contained in:
Adrian Reber 2021-12-06 16:51:21 +00:00 committed by Andrei Vagin
parent b00b61f0e6
commit 908e5dd95d
4 changed files with 77 additions and 0 deletions

View file

@ -5,5 +5,6 @@ test_self
test_sub
test_join_ns
test_pre_dump
test_feature_check
output/
libcriu.so.*

View file

@ -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

View file

@ -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

View file

@ -0,0 +1,65 @@
#include "criu.h"
#include <fcntl.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#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;
}