2017-11-11 08:13:08 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "testutils.h"
|
|
|
|
#include "virfilewrapper.h"
|
2018-12-13 14:53:50 +00:00
|
|
|
#define LIBVIRT_VIRRESCTRLPRIV_H_ALLOW
|
2017-11-11 08:13:08 +00:00
|
|
|
#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;
|
2021-09-04 20:37:31 +00:00
|
|
|
g_autofree char *system_dir = NULL;
|
|
|
|
g_autofree char *resctrl_dir = NULL;
|
2021-08-20 13:53:53 +00:00
|
|
|
g_autoptr(virResctrlAlloc) alloc = NULL;
|
2021-09-04 20:37:31 +00:00
|
|
|
g_autofree char *schemata_str = NULL;
|
|
|
|
g_autofree char *schemata_file = NULL;
|
2021-08-20 13:53:53 +00:00
|
|
|
g_autoptr(virCaps) caps = NULL;
|
2017-11-11 08:13:08 +00:00
|
|
|
|
2019-10-22 13:26:14 +00:00
|
|
|
system_dir = g_strdup_printf("%s/vircaps2xmldata/linux-%s/system", abs_srcdir,
|
|
|
|
data->filename);
|
2017-11-11 08:13:08 +00:00
|
|
|
|
2019-10-22 13:26:14 +00:00
|
|
|
resctrl_dir = g_strdup_printf("%s/vircaps2xmldata/linux-%s/resctrl",
|
|
|
|
abs_srcdir, data->filename);
|
2017-11-11 08:13:08 +00:00
|
|
|
|
2019-10-22 13:26:14 +00:00
|
|
|
schemata_file = g_strdup_printf("%s/virresctrldata/%s.schemata", abs_srcdir,
|
|
|
|
data->filename);
|
2017-11-11 08:13:08 +00:00
|
|
|
|
|
|
|
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");
|
2021-09-04 20:41:36 +00:00
|
|
|
return -1;
|
2017-11-11 08:13:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
alloc = virResctrlAllocGetUnused(caps->host.resctrl);
|
|
|
|
|
|
|
|
virFileWrapperClearPrefixes();
|
|
|
|
|
|
|
|
if (!alloc) {
|
|
|
|
if (data->fail)
|
2021-09-04 20:41:36 +00:00
|
|
|
return 0;
|
|
|
|
return -1;
|
2017-11-11 08:13:08 +00:00
|
|
|
} else if (data->fail) {
|
2019-05-03 08:31:02 +00:00
|
|
|
VIR_TEST_DEBUG("Error expected but there wasn't any.");
|
2021-09-04 20:41:36 +00:00
|
|
|
return -1;
|
2017-11-11 08:13:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
schemata_str = virResctrlAllocFormat(alloc);
|
|
|
|
|
|
|
|
if (virTestCompareToFile(schemata_str, schemata_file) < 0)
|
2021-09-04 20:41:36 +00:00
|
|
|
return -1;
|
2017-11-11 08:13:08 +00:00
|
|
|
|
2021-09-04 20:41:36 +00:00
|
|
|
return 0;
|
2017-11-11 08:13:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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");
|
|
|
|
|
2024-09-12 12:02:57 +00:00
|
|
|
DO_TEST_UNUSED("resctrl-amd");
|
|
|
|
DO_TEST_UNUSED("resctrl-mba_MBps");
|
|
|
|
|
2021-05-16 16:14:53 +00:00
|
|
|
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
2017-11-11 08:13:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VIR_TEST_MAIN(mymain)
|