This test has 2 different uses:
1) DO_TEST_FREE initializes capabilities from vircaps2xmldata (since it exists
there already) and then requests list of free bitmaps (all unallocated
space) from virresctrl.c
2) DO_TEST_ALLOC takes capabilities from vircaps2xmldata, and uses resctrl info
to request an allocation from virresctrl.c for a VM from
genericxml2xmlindata.
Desirable outputs are saved in virresctrldata.
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
---
tests/Makefile.am | 8 +-
.../resctrl--cachetune/vcpus-0-1.alloc | 1 +
.../resctrl--cachetune/vcpus-3.alloc | 1 +
.../resctrl-cdp--cachetune-cdp/vcpus-0-1.alloc | 2 +
.../resctrl-cdp--cachetune-cdp/vcpus-2.alloc | 1 +
.../resctrl-cdp--cachetune-cdp/vcpus-3.alloc | 1 +
tests/virresctrldata/resctrl-cdp.schemata | 2 +
.../virresctrldata/resctrl-skx-twocaches.schemata | 1 +
tests/virresctrldata/resctrl-skx.schemata | 1 +
tests/virresctrldata/resctrl.schemata | 1 +
tests/virresctrltest.c | 277 +++++++++++++++++++++
11 files changed, 295 insertions(+), 1 deletion(-)
create mode 100644 tests/virresctrldata/resctrl--cachetune/vcpus-0-1.alloc
create mode 100644 tests/virresctrldata/resctrl--cachetune/vcpus-3.alloc
create mode 100644 tests/virresctrldata/resctrl-cdp--cachetune-cdp/vcpus-0-1.alloc
create mode 100644 tests/virresctrldata/resctrl-cdp--cachetune-cdp/vcpus-2.alloc
create mode 100644 tests/virresctrldata/resctrl-cdp--cachetune-cdp/vcpus-3.alloc
create mode 100644 tests/virresctrldata/resctrl-cdp.schemata
create mode 100644 tests/virresctrldata/resctrl-skx-twocaches.schemata
create mode 100644 tests/virresctrldata/resctrl-skx.schemata
create mode 100644 tests/virresctrldata/resctrl.schemata
create mode 100644 tests/virresctrltest.c
diff --git a/tests/Makefile.am b/tests/Makefile.am
index effa259e3a45..04695c0ad250 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -231,6 +231,7 @@ if WITH_LINUX
test_programs += fchosttest
test_programs += scsihosttest
test_programs += vircaps2xmltest
+test_programs += virresctrltest
test_libraries += virusbmock.la \
virnetdevbandwidthmock.la \
virnumamock.la \
@@ -1172,8 +1173,13 @@ virnumamock_la_CFLAGS = $(AM_CFLAGS)
virnumamock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS)
virnumamock_la_LIBADD = $(MOCKLIBS_LIBS)
+virresctrltest_SOURCES = \
+ virresctrltest.c testutils.h testutils.c virfilewrapper.h virfilewrapper.c
+virresctrltest_LDADD = $(LDADDS)
+
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
if WITH_NSS
diff --git a/tests/virresctrldata/resctrl--cachetune/vcpus-0-1.alloc b/tests/virresctrldata/resctrl--cachetune/vcpus-0-1.alloc
new file mode 100644
index 000000000000..6f48dd99d5a1
--- /dev/null
+++ b/tests/virresctrldata/resctrl--cachetune/vcpus-0-1.alloc
@@ -0,0 +1 @@
+L3:0=0000f;1=000f0
diff --git a/tests/virresctrldata/resctrl--cachetune/vcpus-3.alloc b/tests/virresctrldata/resctrl--cachetune/vcpus-3.alloc
new file mode 100644
index 000000000000..b47a36fecc8a
--- /dev/null
+++ b/tests/virresctrldata/resctrl--cachetune/vcpus-3.alloc
@@ -0,0 +1 @@
+L3:0=000f0
diff --git a/tests/virresctrldata/resctrl-cdp--cachetune-cdp/vcpus-0-1.alloc b/tests/virresctrldata/resctrl-cdp--cachetune-cdp/vcpus-0-1.alloc
new file mode 100644
index 000000000000..44886a2cfe38
--- /dev/null
+++ b/tests/virresctrldata/resctrl-cdp--cachetune-cdp/vcpus-0-1.alloc
@@ -0,0 +1,2 @@
+L3CODE:0=00ffc
+L3DATA:1=0001f
diff --git a/tests/virresctrldata/resctrl-cdp--cachetune-cdp/vcpus-2.alloc b/tests/virresctrldata/resctrl-cdp--cachetune-cdp/vcpus-2.alloc
new file mode 100644
index 000000000000..4225b0a36167
--- /dev/null
+++ b/tests/virresctrldata/resctrl-cdp--cachetune-cdp/vcpus-2.alloc
@@ -0,0 +1 @@
+L3CODE:1=0ff00
diff --git a/tests/virresctrldata/resctrl-cdp--cachetune-cdp/vcpus-3.alloc b/tests/virresctrldata/resctrl-cdp--cachetune-cdp/vcpus-3.alloc
new file mode 100644
index 000000000000..10be6844bd38
--- /dev/null
+++ b/tests/virresctrldata/resctrl-cdp--cachetune-cdp/vcpus-3.alloc
@@ -0,0 +1 @@
+L3DATA:1=03fe0
diff --git a/tests/virresctrldata/resctrl-cdp.schemata b/tests/virresctrldata/resctrl-cdp.schemata
new file mode 100644
index 000000000000..2897e2afa603
--- /dev/null
+++ b/tests/virresctrldata/resctrl-cdp.schemata
@@ -0,0 +1,2 @@
+L3CODE:0=00ffc;1=0ff00
+L3DATA:0=00000;1=03fff
diff --git a/tests/virresctrldata/resctrl-skx-twocaches.schemata b/tests/virresctrldata/resctrl-skx-twocaches.schemata
new file mode 100644
index 000000000000..86b3801a04c2
--- /dev/null
+++ b/tests/virresctrldata/resctrl-skx-twocaches.schemata
@@ -0,0 +1 @@
+L3:0=001;1=400
diff --git a/tests/virresctrldata/resctrl-skx.schemata b/tests/virresctrldata/resctrl-skx.schemata
new file mode 100644
index 000000000000..5e8b0d636277
--- /dev/null
+++ b/tests/virresctrldata/resctrl-skx.schemata
@@ -0,0 +1 @@
+L3:0=70f
diff --git a/tests/virresctrldata/resctrl.schemata b/tests/virresctrldata/resctrl.schemata
new file mode 100644
index 000000000000..fa980e58c9dd
--- /dev/null
+++ b/tests/virresctrldata/resctrl.schemata
@@ -0,0 +1 @@
+L3:0=000ff;1=000f0
diff --git a/tests/virresctrltest.c b/tests/virresctrltest.c
new file mode 100644
index 000000000000..e84d9ff94299
--- /dev/null
+++ b/tests/virresctrltest.c
@@ -0,0 +1,277 @@
+#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;
+ const char *test_name;
+};
+
+
+static int
+test_virResctrlGetFree(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 = virResctrlAllocGetFree(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
+test_virResctrlGetAlloc(const void *opaque)
+{
+ struct virResctrlData *data = (struct virResctrlData *) opaque;
+ char *system_dir = NULL;
+ char *resctrl_dir = NULL;
+ int ret = -1;
+ int rv = 0;
+ virResctrlAllocPtr alloc = NULL;
+ char *schemata_str = NULL;
+ char *schemata_file = NULL;
+ char *domain_file = NULL;
+ char *vcpus = NULL;
+ virCapsPtr caps = NULL;
+ virDomainDefPtr def = NULL;
+ size_t i = 0;
+ virDomainXMLOptionPtr xmlopt = NULL;
+ void *save_ptr = 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(&domain_file, "%s/genericxml2xmlindata/generic-%s.xml",
+ abs_srcdir, data->test_name) < 0)
+ goto cleanup;
+
+ virFileWrapperAddPrefix("/sys/devices/system", system_dir);
+ virFileWrapperAddPrefix("/sys/fs/resctrl", resctrl_dir);
+
+ caps = virTestGenericCapsInit();
+ if (!caps || virCapabilitiesInitCaches(caps) < 0) {
+ fprintf(stderr, "Could not initialize capabilities");
+ goto cleanup;
+ }
+
+ xmlopt = virTestGenericDomainXMLConfInit();
+ if (!xmlopt)
+ goto cleanup;
+
+ def = virDomainDefParseFile(domain_file, caps, xmlopt, NULL,
+ VIR_DOMAIN_DEF_PARSE_INACTIVE);
+ if (!def)
+ goto cleanup;
+
+ for (i = 0; i < def->ncachetunes; i++) {
+ if (virResctrlAllocMasksAssign(caps->host.resctrl,
+ def->cachetunes[i]->alloc,
+ &save_ptr) < 0) {
+ rv = -1;
+ break;
+ }
+ }
+
+ virFileWrapperClearPrefixes();
+
+ if (rv < 0) {
+ if (data->fail)
+ ret = 0;
+ goto cleanup;
+ } else if (data->fail) {
+ VIR_TEST_DEBUG("Error expected but there wasn't any.\n");
+ goto cleanup;
+ }
+
+ for (i = 0; i < def->ncachetunes; i++) {
+ VIR_FREE(vcpus);
+ vcpus = virBitmapFormat(def->cachetunes[i]->vcpus);
+
+ if (!vcpus)
+ goto cleanup;
+
+ VIR_FREE(schemata_file);
+ VIR_FREE(schemata_str);
+
+ if (virAsprintf(&schemata_file, "%s/virresctrldata/%s--%s/vcpus-%s.alloc",
+ abs_srcdir, data->filename, data->test_name, vcpus) < 0)
+ goto cleanup;
+
+ schemata_str = virResctrlAllocFormat(def->cachetunes[i]->alloc);
+ if (!schemata_str)
+ goto cleanup;
+
+ if (virTestCompareToFile(schemata_str, schemata_file) < 0)
+ rv = -1;
+ }
+
+ ret = rv;
+ cleanup:
+ virObjectUnref(save_ptr);
+ virObjectUnref(caps);
+ virObjectUnref(alloc);
+ virObjectUnref(xmlopt);
+ VIR_FREE(system_dir);
+ VIR_FREE(resctrl_dir);
+ VIR_FREE(schemata_str);
+ VIR_FREE(schemata_file);
+ VIR_FREE(domain_file);
+ VIR_FREE(vcpus);
+ virDomainDefFree(def);
+ return ret;
+}
+
+static int
+mymain(void)
+{
+ struct virResctrlData data = {0};
+ int ret = 0;
+
+#define DO_TEST_FREE(_filename) \
+ do { \
+ data = (struct virResctrlData) { .filename = _filename }; \
+ if (virTestRun("Free: " _filename, test_virResctrlGetFree, &data) < 0) \
+ ret = -1; \
+ } while (0)
+
+#define DO_TEST_ALLOC_FULL(_filename, _test_name, _fail) \
+ do { \
+ data = (struct virResctrlData) { .filename = _filename, \
+ .test_name = _test_name, \
+ .fail = _fail }; \
+ if (virTestRun("Alloc: " _filename "+" _test_name, \
+ test_virResctrlGetAlloc, &data) < 0) \
+ ret = -1; \
+ } while (0)
+
+#define DO_TEST_ALLOC(_filename, _test_name) \
+ DO_TEST_ALLOC_FULL(_filename, _test_name, false)
+
+#define DO_TEST_ALLOC_FAIL(_filename, _test_name) \
+ DO_TEST_ALLOC_FULL(_filename, _test_name, true)
+
+ DO_TEST_FREE("resctrl");
+ DO_TEST_FREE("resctrl-cdp");
+ DO_TEST_FREE("resctrl-skx");
+ DO_TEST_FREE("resctrl-skx-twocaches");
+
+
+ /*************
+ * Tests with generic-cachetune.xml (decently sized allocations for 2 caches)
+ ***/
+
+ /* Simplest one, this one should fail because there is not resctrl support
+ * on the host */
+ DO_TEST_ALLOC_FAIL("caches", "cachetune");
+
+ DO_TEST_ALLOC("resctrl", "cachetune");
+
+ /* This one should fail because there are allocations for two caches
+ * requested, but only one exists */
+ DO_TEST_ALLOC_FAIL("resctrl-skx", "cachetune");
+
+ /* This one should fail because there is not enough room available */
+ DO_TEST_ALLOC_FAIL("resctrl-skx-twocaches", "cachetune");
+
+ /* This one should fail because non-CDP allocation is requested on
+ * CDP-enabled system, support for this can be added in the future */
+ DO_TEST_ALLOC_FAIL("resctrl-cdp", "cachetune");
+
+ /*************
+ * Tests with generic-cachetune-small.xml (small allocation for 1 cache)
+ ***/
+
+ /* This one should fail because the allocation size is smaller than minimum
+ * (although with the right granularity) */
+ DO_TEST_ALLOC_FAIL("resctrl", "cachetune-small");
+
+ /* These two should fail because the allocations size is smaller than
+ * granularity */
+ DO_TEST_ALLOC_FAIL("resctrl-skx", "cachetune-small");
+ DO_TEST_ALLOC_FAIL("resctrl-skx-twocaches", "cachetune-small");
+
+ /* This one should fail because non-CDP allocation is requested on
+ * CDP-enabled system, support for this can be added in the future */
+ DO_TEST_ALLOC_FAIL("resctrl-cdp", "cachetune-small");
+
+ /*************
+ * Tests with generic-cachetune-cdp.xml (decently sized allocations,
+ * separate for code and data)
+ ***/
+
+ /* These should fail because CDP allocation is requested on non-CDP
+ * system */
+ DO_TEST_ALLOC_FAIL("resctrl", "cachetune-cdp");
+ DO_TEST_ALLOC_FAIL("resctrl-skx", "cachetune-cdp");
+ DO_TEST_ALLOC_FAIL("resctrl-skx-twocaches", "cachetune-cdp");
+
+ DO_TEST_ALLOC("resctrl-cdp", "cachetune-cdp");
+
+ return ret;
+}
+
+VIR_TEST_MAIN(mymain)
--
2.15.0
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
On 11/13/2017 03:50 AM, Martin Kletzander wrote: > This test has 2 different uses: > > 1) DO_TEST_FREE initializes capabilities from vircaps2xmldata (since it exists > there already) and then requests list of free bitmaps (all unallocated > space) from virresctrl.c > > 2) DO_TEST_ALLOC takes capabilities from vircaps2xmldata, and uses resctrl info > to request an allocation from virresctrl.c for a VM from > genericxml2xmlindata. > > Desirable outputs are saved in virresctrldata. > > Signed-off-by: Martin Kletzander <mkletzan@redhat.com> > --- > tests/Makefile.am | 8 +- > .../resctrl--cachetune/vcpus-0-1.alloc | 1 + > .../resctrl--cachetune/vcpus-3.alloc | 1 + > .../resctrl-cdp--cachetune-cdp/vcpus-0-1.alloc | 2 + > .../resctrl-cdp--cachetune-cdp/vcpus-2.alloc | 1 + > .../resctrl-cdp--cachetune-cdp/vcpus-3.alloc | 1 + > tests/virresctrldata/resctrl-cdp.schemata | 2 + > .../virresctrldata/resctrl-skx-twocaches.schemata | 1 + > tests/virresctrldata/resctrl-skx.schemata | 1 + > tests/virresctrldata/resctrl.schemata | 1 + > tests/virresctrltest.c | 277 +++++++++++++++++++++ > 11 files changed, 295 insertions(+), 1 deletion(-) > create mode 100644 tests/virresctrldata/resctrl--cachetune/vcpus-0-1.alloc > create mode 100644 tests/virresctrldata/resctrl--cachetune/vcpus-3.alloc > create mode 100644 tests/virresctrldata/resctrl-cdp--cachetune-cdp/vcpus-0-1.alloc > create mode 100644 tests/virresctrldata/resctrl-cdp--cachetune-cdp/vcpus-2.alloc > create mode 100644 tests/virresctrldata/resctrl-cdp--cachetune-cdp/vcpus-3.alloc > create mode 100644 tests/virresctrldata/resctrl-cdp.schemata > create mode 100644 tests/virresctrldata/resctrl-skx-twocaches.schemata > create mode 100644 tests/virresctrldata/resctrl-skx.schemata > create mode 100644 tests/virresctrldata/resctrl.schemata > create mode 100644 tests/virresctrltest.c > I'm not sure any mor amount of looking at this will help me figure out how this all works. I mean I understand how the test works, but how the CAT works - I'm lost. I honestly didn't follow the previous conversation on all this and trying to figure out how those schemata impact the XML or vice versa - thoroughly and completely lost. I can understand the need/desire for the technology but wonder if someone over engineered the simple rope swing the customer was looking to create (not the libvirt patches per se). There's so much detail in each cache line that one really needs to "know" a lot more than I (currently) have the desire to read up on. I can only imagine (as you noted a few patches earlier) how much thinking about CAT(s ;-)) has dominated your life lately. >From the aspect of it looks like a test, it works, then yeap - good to go. I'll be intrigued to see how qe tests/breaks this ;-)! Reviewed-by: John Ferlan <jferlan@redhat.com>, but not really fully understaood, John -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
On Wed, Nov 15, 2017 at 05:00:34PM -0500, John Ferlan wrote: > > > On 11/13/2017 03:50 AM, Martin Kletzander wrote: > > This test has 2 different uses: > > > > 1) DO_TEST_FREE initializes capabilities from vircaps2xmldata (since it exists > > there already) and then requests list of free bitmaps (all unallocated > > space) from virresctrl.c > > > > 2) DO_TEST_ALLOC takes capabilities from vircaps2xmldata, and uses resctrl info > > to request an allocation from virresctrl.c for a VM from > > genericxml2xmlindata. > > > > Desirable outputs are saved in virresctrldata. > > > > Signed-off-by: Martin Kletzander <mkletzan@redhat.com> > > --- > > tests/Makefile.am | 8 +- > > .../resctrl--cachetune/vcpus-0-1.alloc | 1 + > > .../resctrl--cachetune/vcpus-3.alloc | 1 + > > .../resctrl-cdp--cachetune-cdp/vcpus-0-1.alloc | 2 + > > .../resctrl-cdp--cachetune-cdp/vcpus-2.alloc | 1 + > > .../resctrl-cdp--cachetune-cdp/vcpus-3.alloc | 1 + > > tests/virresctrldata/resctrl-cdp.schemata | 2 + > > .../virresctrldata/resctrl-skx-twocaches.schemata | 1 + > > tests/virresctrldata/resctrl-skx.schemata | 1 + > > tests/virresctrldata/resctrl.schemata | 1 + > > tests/virresctrltest.c | 277 +++++++++++++++++++++ > > 11 files changed, 295 insertions(+), 1 deletion(-) > > create mode 100644 tests/virresctrldata/resctrl--cachetune/vcpus-0-1.alloc > > create mode 100644 tests/virresctrldata/resctrl--cachetune/vcpus-3.alloc > > create mode 100644 tests/virresctrldata/resctrl-cdp--cachetune-cdp/vcpus-0-1.alloc > > create mode 100644 tests/virresctrldata/resctrl-cdp--cachetune-cdp/vcpus-2.alloc > > create mode 100644 tests/virresctrldata/resctrl-cdp--cachetune-cdp/vcpus-3.alloc > > create mode 100644 tests/virresctrldata/resctrl-cdp.schemata > > create mode 100644 tests/virresctrldata/resctrl-skx-twocaches.schemata > > create mode 100644 tests/virresctrldata/resctrl-skx.schemata > > create mode 100644 tests/virresctrldata/resctrl.schemata > > create mode 100644 tests/virresctrltest.c > > > > I'm not sure any mor amount of looking at this will help me figure out > how this all works. I mean I understand how the test works, but how the > CAT works - I'm lost. I honestly didn't follow the previous conversation > on all this and trying to figure out how those schemata impact the XML > or vice versa - thoroughly and completely lost. I can understand the > need/desire for the technology but wonder if someone over engineered the > simple rope swing the customer was looking to create (not the libvirt > patches per se). There's so much detail in each cache line that one > really needs to "know" a lot more than I (currently) have the desire to > read up on. I can only imagine (as you noted a few patches earlier) how > much thinking about CAT(s ;-)) has dominated your life lately. > > >From the aspect of it looks like a test, it works, then yeap - good to > go. I'll be intrigued to see how qe tests/breaks this ;-)! > > Reviewed-by: John Ferlan <jferlan@redhat.com>, but not really fully > understaood, I've checked the data and it looks correct so Reviewed-by: Pavel Hrdina <phrdina@redhat.com> -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
© 2016 - 2025 Red Hat, Inc.