backup: Wire up qemu full pull backup commands over QMP
[libvirt/ericb.git] / tests / virresctrltest.c
blob5abbb11e9ac7322227355c6e73cac00d1345a82e
1 #include <config.h>
3 #include "testutils.h"
4 #include "virfilewrapper.h"
5 #define LIBVIRT_VIRRESCTRLPRIV_H_ALLOW
6 #include "virresctrlpriv.h"
9 #define VIR_FROM_THIS VIR_FROM_NONE
11 struct virResctrlData {
12 const char *filename;
13 bool fail;
17 static int
18 test_virResctrlGetUnused(const void *opaque)
20 struct virResctrlData *data = (struct virResctrlData *) opaque;
21 char *system_dir = NULL;
22 char *resctrl_dir = NULL;
23 int ret = -1;
24 virResctrlAllocPtr alloc = NULL;
25 char *schemata_str = NULL;
26 char *schemata_file;
27 virCapsPtr caps = NULL;
29 if (virAsprintf(&system_dir, "%s/vircaps2xmldata/linux-%s/system",
30 abs_srcdir, data->filename) < 0)
31 goto cleanup;
33 if (virAsprintf(&resctrl_dir, "%s/vircaps2xmldata/linux-%s/resctrl",
34 abs_srcdir, data->filename) < 0)
35 goto cleanup;
37 if (virAsprintf(&schemata_file, "%s/virresctrldata/%s.schemata",
38 abs_srcdir, data->filename) < 0)
39 goto cleanup;
41 virFileWrapperAddPrefix("/sys/devices/system", system_dir);
42 virFileWrapperAddPrefix("/sys/fs/resctrl", resctrl_dir);
44 caps = virCapabilitiesNew(VIR_ARCH_X86_64, false, false);
45 if (!caps || virCapabilitiesInitCaches(caps) < 0) {
46 fprintf(stderr, "Could not initialize capabilities");
47 goto cleanup;
50 alloc = virResctrlAllocGetUnused(caps->host.resctrl);
52 virFileWrapperClearPrefixes();
54 if (!alloc) {
55 if (data->fail)
56 ret = 0;
57 goto cleanup;
58 } else if (data->fail) {
59 VIR_TEST_DEBUG("Error expected but there wasn't any.\n");
60 ret = -1;
61 goto cleanup;
64 schemata_str = virResctrlAllocFormat(alloc);
66 if (virTestCompareToFile(schemata_str, schemata_file) < 0)
67 goto cleanup;
69 ret = 0;
70 cleanup:
71 virObjectUnref(caps);
72 virObjectUnref(alloc);
73 VIR_FREE(system_dir);
74 VIR_FREE(resctrl_dir);
75 VIR_FREE(schemata_str);
76 VIR_FREE(schemata_file);
77 return ret;
81 static int
82 mymain(void)
84 struct virResctrlData data = {0};
85 int ret = 0;
87 #define DO_TEST_UNUSED(_filename) \
88 do { \
89 data = (struct virResctrlData) { .filename = _filename }; \
90 if (virTestRun("Free: " _filename, test_virResctrlGetUnused, &data) < 0) \
91 ret = -1; \
92 } while (0)
94 DO_TEST_UNUSED("resctrl");
95 DO_TEST_UNUSED("resctrl-cdp");
96 DO_TEST_UNUSED("resctrl-skx");
97 DO_TEST_UNUSED("resctrl-skx-twocaches");
99 return ret;
102 VIR_TEST_MAIN(mymain)