mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 13:45:38 +00:00
tests: add cgroup nested tests
Signed-off-by: Pavel Hrdina <phrdina@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
184245f53b
commit
85099c3393
12
tests/vircgroupdata/systemd-legacy.cgroups
Normal file
12
tests/vircgroupdata/systemd-legacy.cgroups
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#subsys_name hierarchy num_cgroups enabled
|
||||||
|
blkio 1 1 1
|
||||||
|
cpu 2 1 1
|
||||||
|
cpuacct 3 1 1
|
||||||
|
cpuset 4 1 1
|
||||||
|
devices 5 1 1
|
||||||
|
freezer 6 1 1
|
||||||
|
hugetlb 7 1 1
|
||||||
|
memory 8 1 1
|
||||||
|
net_cls 9 1 1
|
||||||
|
perf_event 10 1 1
|
||||||
|
pids 11 1 1
|
11
tests/vircgroupdata/systemd-legacy.mounts
Normal file
11
tests/vircgroupdata/systemd-legacy.mounts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
cgroup /not/really/sys/fs/cgroup/blkio cgroup rw,seclabel,nosuid,nodev,noexec,relatime,blkio 0 0
|
||||||
|
cgroup /not/really/sys/fs/cgroup/cpu cgroup rw,seclabel,nosuid,nodev,noexec,relatime,cpu 0 0
|
||||||
|
cgroup /not/really/sys/fs/cgroup/cpuacct cgroup rw,seclabel,nosuid,nodev,noexec,relatime,cpuacct 0 0
|
||||||
|
cgroup /not/really/sys/fs/cgroup/cpuset cgroup rw,seclabel,nosuid,nodev,noexec,relatime,cpuset 0 0
|
||||||
|
cgroup /not/really/sys/fs/cgroup/devices cgroup rw,seclabel,nosuid,nodev,noexec,relatime,devices 0 0
|
||||||
|
cgroup /not/really/sys/fs/cgroup/freezer cgroup rw,seclabel,nosuid,nodev,noexec,relatime,freezer 0 0
|
||||||
|
cgroup /not/really/sys/fs/cgroup/hugetlb cgroup rw,seclabel,nosuid,nodev,noexec,relatime,hugetlb 0 0
|
||||||
|
cgroup /not/really/sys/fs/cgroup/memory cgroup rw,seclabel,nosuid,nodev,noexec,relatime,memory 0 0
|
||||||
|
cgroup /not/really/sys/fs/cgroup/net_cls cgroup rw,seclabel,nosuid,nodev,noexec,relatime,net_cls 0 0
|
||||||
|
cgroup /not/really/sys/fs/cgroup/perf_event cgroup rw,seclabel,nosuid,nodev,noexec,relatime,perf_event 0 0
|
||||||
|
cgroup /not/really/sys/fs/cgroup/pids cgroup rw,seclabel,nosuid,nodev,noexec,relatime,pids 0 0
|
11
tests/vircgroupdata/systemd-legacy.self.cgroup
Normal file
11
tests/vircgroupdata/systemd-legacy.self.cgroup
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
1:blkio:/libvirt
|
||||||
|
2:cpu:/libvirt/emulator
|
||||||
|
3:cpuacct:/libvirt/emulator
|
||||||
|
4:cpuset:/libvirt/emulator
|
||||||
|
5:devices:/libvirt
|
||||||
|
6:freezer:/libvirt
|
||||||
|
7:hugetlb:/
|
||||||
|
8:memory:/libvirt
|
||||||
|
9:net_cls:/libvirt
|
||||||
|
10:perf_event:/libvirt
|
||||||
|
11:pids:/
|
13
tests/vircgroupdata/systemd-unified.cgroups
Normal file
13
tests/vircgroupdata/systemd-unified.cgroups
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#subsys_name hierarchy num_cgroups enabled
|
||||||
|
cpuset 0 1 1
|
||||||
|
cpu 0 1 1
|
||||||
|
cpuacct 0 1 1
|
||||||
|
blkio 0 1 1
|
||||||
|
memory 0 1 1
|
||||||
|
devices 0 1 1
|
||||||
|
freezer 0 1 1
|
||||||
|
net_cls 0 1 1
|
||||||
|
perf_event 0 1 1
|
||||||
|
net_prio 0 1 1
|
||||||
|
hugetlb 0 1 1
|
||||||
|
pids 0 1 1
|
1
tests/vircgroupdata/systemd-unified.mounts
Normal file
1
tests/vircgroupdata/systemd-unified.mounts
Normal file
@ -0,0 +1 @@
|
|||||||
|
cgroup2 /not/really/sys/fs/cgroup cgroup2 rw,seclabel,nosuid,nodev,noexec,relatime,nsdelegate 0 0
|
1
tests/vircgroupdata/systemd-unified.self.cgroup
Normal file
1
tests/vircgroupdata/systemd-unified.self.cgroup
Normal file
@ -0,0 +1 @@
|
|||||||
|
0::/libvirt/emulator
|
@ -576,6 +576,64 @@ static int testCgroupNewForSelfHybrid(const void *args G_GNUC_UNUSED)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int testCgroupNewForSelfSystemdLegacy(const void *args G_GNUC_UNUSED)
|
||||||
|
{
|
||||||
|
g_autoptr(virCgroup) cgroup = NULL;
|
||||||
|
const char *empty[VIR_CGROUP_CONTROLLER_LAST] = { 0 };
|
||||||
|
const char *mounts[VIR_CGROUP_CONTROLLER_LAST] = {
|
||||||
|
[VIR_CGROUP_CONTROLLER_BLKIO] = "/not/really/sys/fs/cgroup/blkio",
|
||||||
|
[VIR_CGROUP_CONTROLLER_CPU] = "/not/really/sys/fs/cgroup/cpu",
|
||||||
|
[VIR_CGROUP_CONTROLLER_CPUACCT] = "/not/really/sys/fs/cgroup/cpuacct",
|
||||||
|
[VIR_CGROUP_CONTROLLER_CPUSET] = "/not/really/sys/fs/cgroup/cpuset",
|
||||||
|
[VIR_CGROUP_CONTROLLER_DEVICES] = "/not/really/sys/fs/cgroup/devices",
|
||||||
|
[VIR_CGROUP_CONTROLLER_FREEZER] = "/not/really/sys/fs/cgroup/freezer",
|
||||||
|
[VIR_CGROUP_CONTROLLER_MEMORY] = "/not/really/sys/fs/cgroup/memory",
|
||||||
|
[VIR_CGROUP_CONTROLLER_NET_CLS] = "/not/really/sys/fs/cgroup/net_cls",
|
||||||
|
[VIR_CGROUP_CONTROLLER_PERF_EVENT] = "/not/really/sys/fs/cgroup/perf_event",
|
||||||
|
};
|
||||||
|
const char *placement[VIR_CGROUP_CONTROLLER_LAST] = {
|
||||||
|
[VIR_CGROUP_CONTROLLER_BLKIO] = "",
|
||||||
|
[VIR_CGROUP_CONTROLLER_CPU] = "",
|
||||||
|
[VIR_CGROUP_CONTROLLER_CPUACCT] = "",
|
||||||
|
[VIR_CGROUP_CONTROLLER_CPUSET] = "",
|
||||||
|
[VIR_CGROUP_CONTROLLER_DEVICES] = "",
|
||||||
|
[VIR_CGROUP_CONTROLLER_FREEZER] = "",
|
||||||
|
[VIR_CGROUP_CONTROLLER_MEMORY] = "",
|
||||||
|
[VIR_CGROUP_CONTROLLER_NET_CLS] = "",
|
||||||
|
[VIR_CGROUP_CONTROLLER_PERF_EVENT] = "",
|
||||||
|
};
|
||||||
|
|
||||||
|
if (virCgroupNewSelf(&cgroup) < 0) {
|
||||||
|
fprintf(stderr, "Cannot create cgroup for self\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return validateCgroup(cgroup, mounts, empty, placement, NULL, NULL, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int testCgroupNewForSelfSystemdUnified(const void *args G_GNUC_UNUSED)
|
||||||
|
{
|
||||||
|
g_autoptr(virCgroup) cgroup = NULL;
|
||||||
|
const char *empty[VIR_CGROUP_CONTROLLER_LAST] = { 0 };
|
||||||
|
unsigned int controllers =
|
||||||
|
(1 << VIR_CGROUP_CONTROLLER_CPU) |
|
||||||
|
(1 << VIR_CGROUP_CONTROLLER_CPUACCT) |
|
||||||
|
(1 << VIR_CGROUP_CONTROLLER_MEMORY) |
|
||||||
|
(1 << VIR_CGROUP_CONTROLLER_DEVICES) |
|
||||||
|
(1 << VIR_CGROUP_CONTROLLER_BLKIO);
|
||||||
|
|
||||||
|
if (virCgroupNewSelf(&cgroup) < 0) {
|
||||||
|
fprintf(stderr, "Cannot create cgroup for self\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return validateCgroup(cgroup, empty, empty, empty,
|
||||||
|
"/not/really/sys/fs/cgroup", "",
|
||||||
|
controllers);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static int testCgroupAvailable(const void *args)
|
static int testCgroupAvailable(const void *args)
|
||||||
{
|
{
|
||||||
bool got = virCgroupAvailable();
|
bool got = virCgroupAvailable();
|
||||||
@ -1046,6 +1104,20 @@ mymain(void)
|
|||||||
ret = -1;
|
ret = -1;
|
||||||
cleanupFakeFS(fakerootdir);
|
cleanupFakeFS(fakerootdir);
|
||||||
|
|
||||||
|
fakerootdir = initFakeFS("legacy", "systemd-legacy");
|
||||||
|
if (virTestRun("New cgroup for self (systemd-legacy)",
|
||||||
|
testCgroupNewForSelfSystemdLegacy, NULL) < 0) {
|
||||||
|
ret = -1;
|
||||||
|
}
|
||||||
|
cleanupFakeFS(fakerootdir);
|
||||||
|
|
||||||
|
fakerootdir = initFakeFS("unified", "systemd-unified");
|
||||||
|
if (virTestRun("New cgroup for self (systemd-unified)",
|
||||||
|
testCgroupNewForSelfSystemdUnified, NULL) < 0) {
|
||||||
|
ret = -1;
|
||||||
|
}
|
||||||
|
cleanupFakeFS(fakerootdir);
|
||||||
|
|
||||||
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user