mirror of
https://github.com/checkpoint-restore/criu.git
synced 2026-01-23 02:14:37 +00:00
zdtm: Add test to check global properties of cgroup-v2 are preserved
Check that CRIU can checkpoint/restore global properties in cgroup-v2 properly. Signed-off-by: Bui Quang Minh <minhquangbui99@gmail.com>
This commit is contained in:
parent
d7e8746598
commit
ad3936e81e
5 changed files with 115 additions and 0 deletions
|
|
@ -386,6 +386,7 @@ TST_DIR = \
|
|||
cgroup02 \
|
||||
cgroup03 \
|
||||
cgroup04 \
|
||||
cgroupv2_00 \
|
||||
cgroup_ifpriomap \
|
||||
cgroup_ignore \
|
||||
cgroup_stray \
|
||||
|
|
|
|||
86
test/zdtm/static/cgroupv2_00.c
Normal file
86
test/zdtm/static/cgroupv2_00.c
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
#include <sys/mount.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "zdtmtst.h"
|
||||
|
||||
const char *test_doc = "Check that some cgroup-v2 properties in kernel controllers are preserved";
|
||||
const char *test_author = "Bui Quang Minh <minhquangbui99@gmail.com>";
|
||||
|
||||
char *dirname;
|
||||
TEST_OPTION(dirname, string, "cgroup-v2 directory name", 1);
|
||||
const char *cgname = "subcg00";
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
char path[1024], aux[1024];
|
||||
int ret = -1;
|
||||
|
||||
test_init(argc, argv);
|
||||
|
||||
if (mkdir(dirname, 0700) < 0 && errno != EEXIST) {
|
||||
pr_perror("Can't make dir");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (mount("cgroup2", dirname, "cgroup2", 0, NULL)) {
|
||||
pr_perror("Can't mount cgroup-v2");
|
||||
return -1;
|
||||
}
|
||||
|
||||
sprintf(path, "%s/%s", dirname, cgname);
|
||||
if (mkdir(path, 0700) < 0 && errno != EEXIST) {
|
||||
pr_perror("Can't make dir");
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* Make cpuset controllers available in children directory */
|
||||
sprintf(path, "%s/%s", dirname, "cgroup.subtree_control");
|
||||
sprintf(aux, "%s", "+cpuset");
|
||||
if (write_value(path, aux))
|
||||
goto out;
|
||||
|
||||
sprintf(path, "%s/%s/%s", dirname, cgname, "cgroup.subtree_control");
|
||||
sprintf(aux, "%s", "+cpuset");
|
||||
if (write_value(path, aux))
|
||||
goto out;
|
||||
|
||||
sprintf(path, "%s/%s/%s", dirname, cgname, "cgroup.type");
|
||||
sprintf(aux, "%s", "threaded");
|
||||
if (write_value(path, aux))
|
||||
goto out;
|
||||
|
||||
sprintf(path, "%s/%s/%s", dirname, cgname, "cgroup.procs");
|
||||
sprintf(aux, "%d", getpid());
|
||||
if (write_value(path, aux))
|
||||
goto out;
|
||||
|
||||
test_daemon();
|
||||
test_waitsig();
|
||||
|
||||
sprintf(path, "%s/%s/%s", dirname, cgname, "cgroup.subtree_control");
|
||||
if (read_value(path, aux, sizeof(aux)))
|
||||
goto out;
|
||||
|
||||
if (strcmp(aux, "cpuset\n")) {
|
||||
fail("cgroup.subtree_control mismatches");
|
||||
goto out;
|
||||
}
|
||||
|
||||
sprintf(path, "%s/%s/%s", dirname, cgname, "cgroup.type");
|
||||
if (read_value(path, aux, sizeof(aux)))
|
||||
goto out;
|
||||
|
||||
if (strcmp(aux, "threaded\n")) {
|
||||
fail("cgroup.type mismatches");
|
||||
goto out;
|
||||
}
|
||||
|
||||
pass();
|
||||
|
||||
ret = 0;
|
||||
|
||||
out:
|
||||
sprintf(path, "%s", dirname);
|
||||
umount(path);
|
||||
return ret;
|
||||
}
|
||||
11
test/zdtm/static/cgroupv2_00.checkskip
Executable file
11
test/zdtm/static/cgroupv2_00.checkskip
Executable file
|
|
@ -0,0 +1,11 @@
|
|||
#!/bin/bash
|
||||
|
||||
if [ -f /sys/fs/cgroup/cgroup.controllers ]; then
|
||||
grep -q "cpuset" /sys/fs/cgroup/cgroup.controllers && exit 0
|
||||
fi
|
||||
|
||||
if [ -d /sys/fs/cgroup/unified ]; then
|
||||
grep -q "cpuset" /sys/fs/cgroup/unified/cgroup.controllers && exit 0
|
||||
fi
|
||||
|
||||
exit 1
|
||||
1
test/zdtm/static/cgroupv2_00.desc
Normal file
1
test/zdtm/static/cgroupv2_00.desc
Normal file
|
|
@ -0,0 +1 @@
|
|||
{'flavor': 'h ns', 'flags': 'suid', 'opts': '--manage-cgroups=full'}
|
||||
16
test/zdtm/static/cgroupv2_00.hook
Executable file
16
test/zdtm/static/cgroupv2_00.hook
Executable file
|
|
@ -0,0 +1,16 @@
|
|||
#!/bin/bash
|
||||
|
||||
[ "$1" == "--clean" -o "$1" == "--pre-restore" ] || exit 0
|
||||
|
||||
set -e
|
||||
cgname="subcg00"
|
||||
tname=$(mktemp -d cgclean.XXXXXX)
|
||||
mount -t cgroup2 cgroup2 $tname
|
||||
|
||||
echo "Cleaning $tname"
|
||||
echo "-cpuset" > "$tname/$cgname/cgroup.subtree_control"
|
||||
|
||||
set +e
|
||||
rmdir "$tname/$cgname"
|
||||
umount "$tname"
|
||||
rmdir "$tname"
|
||||
Loading…
Add table
Add a link
Reference in a new issue