提交 ae885bb5 编写于 作者: M Martin Kletzander

tests: Add virresctrltest

This test initializes capabilities from vircaps2xmldata (since it exists there
already) and then requests list of free bitmaps (all unallocated space) from
virresctrl.c

Desirable outputs are saved in virresctrldata.
Signed-off-by: NMartin Kletzander <mkletzan@redhat.com>
上级 7387e3fe
...@@ -165,6 +165,7 @@ EXTRA_DIST = \ ...@@ -165,6 +165,7 @@ EXTRA_DIST = \
xml2vmxdata \ xml2vmxdata \
virstorageutildata \ virstorageutildata \
virfilecachedata \ virfilecachedata \
virresctrldata \
$(NULL) $(NULL)
test_helpers = commandhelper ssh test_helpers = commandhelper ssh
...@@ -232,6 +233,7 @@ if WITH_LINUX ...@@ -232,6 +233,7 @@ if WITH_LINUX
test_programs += fchosttest test_programs += fchosttest
test_programs += scsihosttest test_programs += scsihosttest
test_programs += vircaps2xmltest test_programs += vircaps2xmltest
test_programs += virresctrltest
test_libraries += virusbmock.la \ test_libraries += virusbmock.la \
virnetdevbandwidthmock.la \ virnetdevbandwidthmock.la \
virnumamock.la \ virnumamock.la \
...@@ -1165,8 +1167,13 @@ virnumamock_la_SOURCES = \ ...@@ -1165,8 +1167,13 @@ virnumamock_la_SOURCES = \
virnumamock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS) virnumamock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS)
virnumamock_la_LIBADD = $(MOCKLIBS_LIBS) virnumamock_la_LIBADD = $(MOCKLIBS_LIBS)
virresctrltest_SOURCES = \
virresctrltest.c testutils.h testutils.c virfilewrapper.h virfilewrapper.c
virresctrltest_LDADD = $(LDADDS)
else ! WITH_LINUX else ! WITH_LINUX
EXTRA_DIST += vircaps2xmltest.c virnumamock.c virfilewrapper.c virfilewrapper.h EXTRA_DIST += vircaps2xmltest.c virnumamock.c virfilewrapper.c \
virfilewrapper.h virresctrltest.c
endif ! WITH_LINUX endif ! WITH_LINUX
if WITH_NSS if WITH_NSS
......
L3CODE:0=00ffc;1=0ff00
L3DATA:0=00000;1=03fff
#include <config.h>
#include <stdlib.h>
#include "testutils.h"
#include "virfilewrapper.h"
#include "virresctrlpriv.h"
#define VIR_FROM_THIS VIR_FROM_NONE
struct virResctrlData {
const char *filename;
bool fail;
};
static int
test_virResctrlGetUnused(const void *opaque)
{
struct virResctrlData *data = (struct virResctrlData *) opaque;
char *system_dir = NULL;
char *resctrl_dir = NULL;
int ret = -1;
virResctrlAllocPtr alloc = NULL;
char *schemata_str = NULL;
char *schemata_file;
virCapsPtr caps = NULL;
if (virAsprintf(&system_dir, "%s/vircaps2xmldata/linux-%s/system",
abs_srcdir, data->filename) < 0)
goto cleanup;
if (virAsprintf(&resctrl_dir, "%s/vircaps2xmldata/linux-%s/resctrl",
abs_srcdir, data->filename) < 0)
goto cleanup;
if (virAsprintf(&schemata_file, "%s/virresctrldata/%s.schemata",
abs_srcdir, data->filename) < 0)
goto cleanup;
virFileWrapperAddPrefix("/sys/devices/system", system_dir);
virFileWrapperAddPrefix("/sys/fs/resctrl", resctrl_dir);
caps = virCapabilitiesNew(VIR_ARCH_X86_64, false, false);
if (!caps || virCapabilitiesInitCaches(caps) < 0) {
fprintf(stderr, "Could not initialize capabilities");
goto cleanup;
}
alloc = virResctrlAllocGetUnused(caps->host.resctrl);
virFileWrapperClearPrefixes();
if (!alloc) {
if (data->fail)
ret = 0;
goto cleanup;
} else if (data->fail) {
VIR_TEST_DEBUG("Error expected but there wasn't any.\n");
ret = -1;
goto cleanup;
}
schemata_str = virResctrlAllocFormat(alloc);
if (virTestCompareToFile(schemata_str, schemata_file) < 0)
goto cleanup;
ret = 0;
cleanup:
virObjectUnref(caps);
virObjectUnref(alloc);
VIR_FREE(system_dir);
VIR_FREE(resctrl_dir);
VIR_FREE(schemata_str);
VIR_FREE(schemata_file);
return ret;
}
static int
mymain(void)
{
struct virResctrlData data = {0};
int ret = 0;
#define DO_TEST_UNUSED(_filename) \
do { \
data = (struct virResctrlData) { .filename = _filename }; \
if (virTestRun("Free: " _filename, test_virResctrlGetUnused, &data) < 0) \
ret = -1; \
} while (0)
DO_TEST_UNUSED("resctrl");
DO_TEST_UNUSED("resctrl-cdp");
DO_TEST_UNUSED("resctrl-skx");
DO_TEST_UNUSED("resctrl-skx-twocaches");
return ret;
}
VIR_TEST_MAIN(mymain)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册