c1c534
From 15e49265411702cd518af91e04a78ef911559d06 Mon Sep 17 00:00:00 2001
c1c534
Message-Id: <15e49265411702cd518af91e04a78ef911559d06@dist-git>
c1c534
From: Martin Kletzander <mkletzan@redhat.com>
c1c534
Date: Wed, 31 Jan 2018 16:32:31 +0100
c1c534
Subject: [PATCH] tests: Add virresctrltest
c1c534
c1c534
This test initializes capabilities from vircaps2xmldata (since it exists there
c1c534
already) and then requests list of free bitmaps (all unallocated space) from
c1c534
virresctrl.c
c1c534
c1c534
Desirable outputs are saved in virresctrldata.
c1c534
c1c534
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
c1c534
(cherry picked from commit ae885bb52089b1d367e7ac1ed5d8d683e0bfefbd)
c1c534
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
c1c534
c1c534
https://bugzilla.redhat.com/show_bug.cgi?id=1289368
c1c534
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
c1c534
---
c1c534
 tests/Makefile.am                                  |   9 +-
c1c534
 tests/virresctrldata/resctrl-cdp.schemata          |   2 +
c1c534
 .../virresctrldata/resctrl-skx-twocaches.schemata  |   1 +
c1c534
 tests/virresctrldata/resctrl-skx.schemata          |   1 +
c1c534
 tests/virresctrldata/resctrl.schemata              |   1 +
c1c534
 tests/virresctrltest.c                             | 102 +++++++++++++++++++++
c1c534
 6 files changed, 115 insertions(+), 1 deletion(-)
c1c534
 create mode 100644 tests/virresctrldata/resctrl-cdp.schemata
c1c534
 create mode 100644 tests/virresctrldata/resctrl-skx-twocaches.schemata
c1c534
 create mode 100644 tests/virresctrldata/resctrl-skx.schemata
c1c534
 create mode 100644 tests/virresctrldata/resctrl.schemata
c1c534
 create mode 100644 tests/virresctrltest.c
c1c534
c1c534
diff --git a/tests/Makefile.am b/tests/Makefile.am
c1c534
index 0b2305d70b..f845b44102 100644
c1c534
--- a/tests/Makefile.am
c1c534
+++ b/tests/Makefile.am
c1c534
@@ -164,6 +164,7 @@ EXTRA_DIST =		\
c1c534
 	xml2vmxdata \
c1c534
 	virstorageutildata \
c1c534
 	virfilecachedata \
c1c534
+	virresctrldata \
c1c534
 	$(NULL)
c1c534
 
c1c534
 test_helpers = commandhelper ssh
c1c534
@@ -231,6 +232,7 @@ if WITH_LINUX
c1c534
 test_programs += fchosttest
c1c534
 test_programs += scsihosttest
c1c534
 test_programs += vircaps2xmltest
c1c534
+test_programs += virresctrltest
c1c534
 test_libraries += virusbmock.la \
c1c534
 	virnetdevbandwidthmock.la \
c1c534
 	virnumamock.la \
c1c534
@@ -1172,8 +1174,13 @@ virnumamock_la_CFLAGS = $(AM_CFLAGS)
c1c534
 virnumamock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS)
c1c534
 virnumamock_la_LIBADD = $(MOCKLIBS_LIBS)
c1c534
 
c1c534
+virresctrltest_SOURCES = \
c1c534
+	virresctrltest.c testutils.h testutils.c virfilewrapper.h virfilewrapper.c
c1c534
+virresctrltest_LDADD = $(LDADDS)
c1c534
+
c1c534
 else ! WITH_LINUX
c1c534
-EXTRA_DIST += vircaps2xmltest.c virnumamock.c virfilewrapper.c virfilewrapper.h
c1c534
+EXTRA_DIST += vircaps2xmltest.c virnumamock.c virfilewrapper.c \
c1c534
+			  virfilewrapper.h virresctrltest.c
c1c534
 endif ! WITH_LINUX
c1c534
 
c1c534
 if WITH_NSS
c1c534
diff --git a/tests/virresctrldata/resctrl-cdp.schemata b/tests/virresctrldata/resctrl-cdp.schemata
c1c534
new file mode 100644
c1c534
index 0000000000..2897e2afa6
c1c534
--- /dev/null
c1c534
+++ b/tests/virresctrldata/resctrl-cdp.schemata
c1c534
@@ -0,0 +1,2 @@
c1c534
+L3CODE:0=00ffc;1=0ff00
c1c534
+L3DATA:0=00000;1=03fff
c1c534
diff --git a/tests/virresctrldata/resctrl-skx-twocaches.schemata b/tests/virresctrldata/resctrl-skx-twocaches.schemata
c1c534
new file mode 100644
c1c534
index 0000000000..86b3801a04
c1c534
--- /dev/null
c1c534
+++ b/tests/virresctrldata/resctrl-skx-twocaches.schemata
c1c534
@@ -0,0 +1 @@
c1c534
+L3:0=001;1=400
c1c534
diff --git a/tests/virresctrldata/resctrl-skx.schemata b/tests/virresctrldata/resctrl-skx.schemata
c1c534
new file mode 100644
c1c534
index 0000000000..5e8b0d6362
c1c534
--- /dev/null
c1c534
+++ b/tests/virresctrldata/resctrl-skx.schemata
c1c534
@@ -0,0 +1 @@
c1c534
+L3:0=70f
c1c534
diff --git a/tests/virresctrldata/resctrl.schemata b/tests/virresctrldata/resctrl.schemata
c1c534
new file mode 100644
c1c534
index 0000000000..fa980e58c9
c1c534
--- /dev/null
c1c534
+++ b/tests/virresctrldata/resctrl.schemata
c1c534
@@ -0,0 +1 @@
c1c534
+L3:0=000ff;1=000f0
c1c534
diff --git a/tests/virresctrltest.c b/tests/virresctrltest.c
c1c534
new file mode 100644
c1c534
index 0000000000..99e20d5dec
c1c534
--- /dev/null
c1c534
+++ b/tests/virresctrltest.c
c1c534
@@ -0,0 +1,102 @@
c1c534
+#include <config.h>
c1c534
+#include <stdlib.h>
c1c534
+
c1c534
+#include "testutils.h"
c1c534
+#include "virfilewrapper.h"
c1c534
+#include "virresctrlpriv.h"
c1c534
+
c1c534
+
c1c534
+#define VIR_FROM_THIS VIR_FROM_NONE
c1c534
+
c1c534
+struct virResctrlData {
c1c534
+    const char *filename;
c1c534
+    bool fail;
c1c534
+};
c1c534
+
c1c534
+
c1c534
+static int
c1c534
+test_virResctrlGetUnused(const void *opaque)
c1c534
+{
c1c534
+    struct virResctrlData *data = (struct virResctrlData *) opaque;
c1c534
+    char *system_dir = NULL;
c1c534
+    char *resctrl_dir = NULL;
c1c534
+    int ret = -1;
c1c534
+    virResctrlAllocPtr alloc = NULL;
c1c534
+    char *schemata_str = NULL;
c1c534
+    char *schemata_file;
c1c534
+    virCapsPtr caps = NULL;
c1c534
+
c1c534
+    if (virAsprintf(&system_dir, "%s/vircaps2xmldata/linux-%s/system",
c1c534
+                    abs_srcdir, data->filename) < 0)
c1c534
+        goto cleanup;
c1c534
+
c1c534
+    if (virAsprintf(&resctrl_dir, "%s/vircaps2xmldata/linux-%s/resctrl",
c1c534
+                    abs_srcdir, data->filename) < 0)
c1c534
+        goto cleanup;
c1c534
+
c1c534
+    if (virAsprintf(&schemata_file, "%s/virresctrldata/%s.schemata",
c1c534
+                    abs_srcdir, data->filename) < 0)
c1c534
+        goto cleanup;
c1c534
+
c1c534
+    virFileWrapperAddPrefix("/sys/devices/system", system_dir);
c1c534
+    virFileWrapperAddPrefix("/sys/fs/resctrl", resctrl_dir);
c1c534
+
c1c534
+    caps = virCapabilitiesNew(VIR_ARCH_X86_64, false, false);
c1c534
+    if (!caps || virCapabilitiesInitCaches(caps) < 0) {
c1c534
+        fprintf(stderr, "Could not initialize capabilities");
c1c534
+        goto cleanup;
c1c534
+    }
c1c534
+
c1c534
+    alloc = virResctrlAllocGetUnused(caps->host.resctrl);
c1c534
+
c1c534
+    virFileWrapperClearPrefixes();
c1c534
+
c1c534
+    if (!alloc) {
c1c534
+        if (data->fail)
c1c534
+            ret = 0;
c1c534
+        goto cleanup;
c1c534
+    } else if (data->fail) {
c1c534
+        VIR_TEST_DEBUG("Error expected but there wasn't any.\n");
c1c534
+        ret = -1;
c1c534
+        goto cleanup;
c1c534
+    }
c1c534
+
c1c534
+    schemata_str = virResctrlAllocFormat(alloc);
c1c534
+
c1c534
+    if (virTestCompareToFile(schemata_str, schemata_file) < 0)
c1c534
+        goto cleanup;
c1c534
+
c1c534
+    ret = 0;
c1c534
+ cleanup:
c1c534
+    virObjectUnref(caps);
c1c534
+    virObjectUnref(alloc);
c1c534
+    VIR_FREE(system_dir);
c1c534
+    VIR_FREE(resctrl_dir);
c1c534
+    VIR_FREE(schemata_str);
c1c534
+    VIR_FREE(schemata_file);
c1c534
+    return ret;
c1c534
+}
c1c534
+
c1c534
+
c1c534
+static int
c1c534
+mymain(void)
c1c534
+{
c1c534
+    struct virResctrlData data = {0};
c1c534
+    int ret = 0;
c1c534
+
c1c534
+#define DO_TEST_UNUSED(_filename) \
c1c534
+    do { \
c1c534
+        data = (struct virResctrlData) { .filename = _filename }; \
c1c534
+        if (virTestRun("Free: " _filename, test_virResctrlGetUnused, &data) < 0) \
c1c534
+            ret = -1; \
c1c534
+    } while (0)
c1c534
+
c1c534
+    DO_TEST_UNUSED("resctrl");
c1c534
+    DO_TEST_UNUSED("resctrl-cdp");
c1c534
+    DO_TEST_UNUSED("resctrl-skx");
c1c534
+    DO_TEST_UNUSED("resctrl-skx-twocaches");
c1c534
+
c1c534
+    return ret;
c1c534
+}
c1c534
+
c1c534
+VIR_TEST_MAIN(mymain)
c1c534
-- 
c1c534
2.16.1
c1c534