mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-01 17:35:17 +00:00
tests: Augment vcgrouptest to add virCgroupGetMemoryStat
Add a test to fetch the GetMemoryStat output. This only gets data for v1 only right now since the v2 data from commit 61ff6021 is rather useless returning all 0's. The v1 data was originally added in commit d1452470. Signed-off-by: John Ferlan <jferlan@redhat.com> Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
This commit is contained in:
parent
b8176d6eaa
commit
99b8ef7a98
@ -802,6 +802,67 @@ static int testCgroupGetMemoryUsage(const void *args ATTRIBUTE_UNUSED)
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
testCgroupGetMemoryStat(const void *args ATTRIBUTE_UNUSED)
|
||||
{
|
||||
virCgroupPtr cgroup = NULL;
|
||||
int rv;
|
||||
int ret = -1;
|
||||
size_t i;
|
||||
|
||||
const unsigned long long expected_values[] = {
|
||||
1336619008ULL,
|
||||
67100672ULL,
|
||||
145887232ULL,
|
||||
661872640ULL,
|
||||
627400704UL,
|
||||
3690496ULL
|
||||
};
|
||||
const char* names[] = {
|
||||
"cache",
|
||||
"active_anon",
|
||||
"inactive_anon",
|
||||
"active_file",
|
||||
"inactive_file",
|
||||
"unevictable"
|
||||
};
|
||||
unsigned long long values[ARRAY_CARDINALITY(expected_values)];
|
||||
|
||||
if ((rv = virCgroupNewPartition("/virtualmachines", true,
|
||||
(1 << VIR_CGROUP_CONTROLLER_MEMORY),
|
||||
&cgroup)) < 0) {
|
||||
fprintf(stderr, "Could not create /virtualmachines cgroup: %d\n", -rv);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if ((rv = virCgroupGetMemoryStat(cgroup, &values[0],
|
||||
&values[1], &values[2],
|
||||
&values[3], &values[4],
|
||||
&values[5])) < 0) {
|
||||
fprintf(stderr, "Could not retrieve GetMemoryStat for /virtualmachines cgroup: %d\n", -rv);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
for (i = 0; i < ARRAY_CARDINALITY(expected_values); i++) {
|
||||
/* NB: virCgroupGetMemoryStat returns a KiB scaled value */
|
||||
if ((expected_values[i] >> 10) != values[i]) {
|
||||
fprintf(stderr,
|
||||
"Wrong value (%llu) for %s from virCgroupGetMemoryStat "
|
||||
"(expected %llu)\n",
|
||||
values[i], names[i], (expected_values[i] >> 10));
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
cleanup:
|
||||
virCgroupFree(&cgroup);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static int testCgroupGetBlkioIoServiced(const void *args ATTRIBUTE_UNUSED)
|
||||
{
|
||||
virCgroupPtr cgroup = NULL;
|
||||
@ -1035,6 +1096,9 @@ mymain(void)
|
||||
if (virTestRun("virCgroupGetMemoryUsage works", testCgroupGetMemoryUsage, NULL) < 0)
|
||||
ret = -1;
|
||||
|
||||
if (virTestRun("virCgroupGetMemoryStat works", testCgroupGetMemoryStat, NULL) < 0)
|
||||
ret = -1;
|
||||
|
||||
if (virTestRun("virCgroupGetPercpuStats works", testCgroupGetPercpuStats, NULL) < 0)
|
||||
ret = -1;
|
||||
cleanupFakeFS(fakerootdir);
|
||||
|
Loading…
x
Reference in New Issue
Block a user