[PATCH v2 1/2] vircaps2xmltest: Introduce basic testing

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



For now only one test is introduced. It's purpose in life
is to check we don't break NUMA host distances XML format.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 tests/Makefile.am                              |   6 +
 tests/vircaps2xmldata/vircaps-basic-4-4-2G.xml |  74 +++++++++++
 tests/vircaps2xmltest.c                        | 164 +++++++++++++++++++++++++
 3 files changed, 244 insertions(+)
 create mode 100644 tests/vircaps2xmldata/vircaps-basic-4-4-2G.xml
 create mode 100644 tests/vircaps2xmltest.c

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 1fdfd3b..9f4dff3 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -124,6 +124,7 @@ EXTRA_DIST =		\
 	storagevolxml2xmlout \
 	sysinfodata \
 	test-lib.sh	\
+	vircaps2xmldata \
 	virsh-uriprecedence \
 	virfiledata \
 	virpcitestdata \
@@ -167,6 +168,7 @@ test_programs = virshtest sockettest \
 	vircapstest \
 	domainconftest \
 	virhostdevtest \
+	vircaps2xmltest \
 	$(NULL)
 
 if WITH_REMOTE
@@ -803,6 +805,10 @@ vircapstest_SOURCES = \
 	vircapstest.c testutils.h testutils.c
 vircapstest_LDADD = $(LDADDS)
 
+vircaps2xmltest_SOURCES = \
+	vircaps2xmltest.c testutils.h testutils.c
+vircaps2xmltest_LDADD = $(LDADDS)
+
 if WITH_LIBVIRTD
 libvirtdconftest_SOURCES = \
 	libvirtdconftest.c testutils.h testutils.c \
diff --git a/tests/vircaps2xmldata/vircaps-basic-4-4-2G.xml b/tests/vircaps2xmldata/vircaps-basic-4-4-2G.xml
new file mode 100644
index 0000000..8694f87
--- /dev/null
+++ b/tests/vircaps2xmldata/vircaps-basic-4-4-2G.xml
@@ -0,0 +1,74 @@
+<capabilities>
+
+  <host>
+    <cpu>
+      <arch>x86_64</arch>
+    </cpu>
+    <power_management/>
+    <topology>
+      <cells num='4'>
+        <cell id='0'>
+          <memory unit='KiB'>2097152</memory>
+          <distances>
+            <sibling id='0' value='10'/>
+            <sibling id='1' value='20'/>
+            <sibling id='2' value='20'/>
+            <sibling id='3' value='20'/>
+          </distances>
+          <cpus num='4'>
+            <cpu id='0' socket_id='0' core_id='0' siblings='0'/>
+            <cpu id='0' socket_id='0' core_id='1' siblings='0'/>
+            <cpu id='0' socket_id='0' core_id='2' siblings='0'/>
+            <cpu id='0' socket_id='0' core_id='3' siblings='0'/>
+          </cpus>
+        </cell>
+        <cell id='1'>
+          <memory unit='KiB'>2097152</memory>
+          <distances>
+            <sibling id='0' value='20'/>
+            <sibling id='1' value='10'/>
+            <sibling id='2' value='20'/>
+            <sibling id='3' value='20'/>
+          </distances>
+          <cpus num='4'>
+            <cpu id='1' socket_id='1' core_id='1' siblings='1'/>
+            <cpu id='1' socket_id='1' core_id='2' siblings='1'/>
+            <cpu id='1' socket_id='1' core_id='3' siblings='1'/>
+            <cpu id='1' socket_id='1' core_id='4' siblings='1'/>
+          </cpus>
+        </cell>
+        <cell id='2'>
+          <memory unit='KiB'>2097152</memory>
+          <distances>
+            <sibling id='0' value='20'/>
+            <sibling id='1' value='20'/>
+            <sibling id='2' value='10'/>
+            <sibling id='3' value='20'/>
+          </distances>
+          <cpus num='4'>
+            <cpu id='2' socket_id='2' core_id='2' siblings='2'/>
+            <cpu id='2' socket_id='2' core_id='3' siblings='2'/>
+            <cpu id='2' socket_id='2' core_id='4' siblings='2'/>
+            <cpu id='2' socket_id='2' core_id='5' siblings='2'/>
+          </cpus>
+        </cell>
+        <cell id='3'>
+          <memory unit='KiB'>2097152</memory>
+          <distances>
+            <sibling id='0' value='20'/>
+            <sibling id='1' value='20'/>
+            <sibling id='2' value='20'/>
+            <sibling id='3' value='10'/>
+          </distances>
+          <cpus num='4'>
+            <cpu id='3' socket_id='3' core_id='3' siblings='3'/>
+            <cpu id='3' socket_id='3' core_id='4' siblings='3'/>
+            <cpu id='3' socket_id='3' core_id='5' siblings='3'/>
+            <cpu id='3' socket_id='3' core_id='6' siblings='3'/>
+          </cpus>
+        </cell>
+      </cells>
+    </topology>
+  </host>
+
+</capabilities>
diff --git a/tests/vircaps2xmltest.c b/tests/vircaps2xmltest.c
new file mode 100644
index 0000000..fa02534
--- /dev/null
+++ b/tests/vircaps2xmltest.c
@@ -0,0 +1,164 @@
+/*
+ * Copyright (C) Red Hat, Inc. 2014
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ *      Michal Privoznik <mprivozn@xxxxxxxxxx>
+ */
+
+#include <config.h>
+#include <stdlib.h>
+
+#include "testutils.h"
+#include "capabilities.h"
+#include "virbitmap.h"
+
+
+#define VIR_FROM_THIS VIR_FROM_NONE
+
+static virCapsPtr
+buildVirCapabilities(int max_cells,
+                     int max_cpus_in_cell,
+                     int max_mem_in_cell)
+{
+    virCapsPtr caps;
+    virCapsHostNUMACellCPUPtr cell_cpus = NULL;
+    virCapsHostNUMACellSiblingInfoPtr siblings = NULL;
+    int core_id, cell_id, nsiblings;
+    int id;
+    size_t i;
+
+    if ((caps = virCapabilitiesNew(VIR_ARCH_X86_64, 0, 0)) == NULL)
+        goto error;
+
+    id = 0;
+    for (cell_id = 0; cell_id < max_cells; cell_id++) {
+        if (VIR_ALLOC_N(cell_cpus, max_cpus_in_cell) < 0)
+            goto error;
+
+        for (core_id = 0; core_id < max_cpus_in_cell; core_id++) {
+            cell_cpus[core_id].id = id;
+            cell_cpus[core_id].socket_id = cell_id;
+            cell_cpus[core_id].core_id = id + core_id;
+            if (!(cell_cpus[core_id].siblings =
+                  virBitmapNew(max_cpus_in_cell)))
+                goto error;
+            ignore_value(virBitmapSetBit(cell_cpus[core_id].siblings, id));
+        }
+        id++;
+
+        if (VIR_ALLOC_N(siblings, max_cells) < 0)
+            goto error;
+        nsiblings = max_cells;
+
+        for (i = 0; i < nsiblings; i++) {
+            siblings[i].node = i;
+            /* Some magical constants, see virNumaGetDistances()
+             * for their description. */
+            siblings[i].distance = cell_id == i ? 10 : 20;
+        }
+
+        if (virCapabilitiesAddHostNUMACell(caps, cell_id,
+                                           max_mem_in_cell,
+                                           max_cpus_in_cell, cell_cpus,
+                                           nsiblings, siblings) < 0)
+           goto error;
+
+        cell_cpus = NULL;
+        siblings = NULL;
+    }
+
+    return caps;
+
+ error:
+    virCapabilitiesClearHostNUMACellCPUTopology(cell_cpus, max_cpus_in_cell);
+    VIR_FREE(cell_cpus);
+    VIR_FREE(siblings);
+    virObjectUnref(caps);
+    return NULL;
+}
+
+
+struct virCapabilitiesFormatData {
+    const char *filename;
+    int max_cells;
+    int max_cpus_in_cell;
+    int max_mem_in_cell;
+};
+
+static int
+test_virCapabilitiesFormat(const void *opaque)
+{
+    struct virCapabilitiesFormatData *data = (struct virCapabilitiesFormatData *) opaque;
+    virCapsPtr caps = NULL;
+    char *capsXML = NULL;
+    char *capsFromFile = NULL;
+    char *path = NULL;
+    int ret = -1;
+
+    if (!(caps = buildVirCapabilities(data->max_cells, data->max_cpus_in_cell,
+                                      data->max_mem_in_cell)))
+        goto cleanup;
+
+    if (!(capsXML = virCapabilitiesFormatXML(caps))) {
+        fprintf(stderr, "Unable to format capabilities XML");
+        goto cleanup;
+    }
+
+    if (virAsprintf(&path, "%s/vircaps2xmldata/vircaps-%s.xml",
+                    abs_srcdir, data->filename) < 0)
+        goto cleanup;
+
+    if (virFileReadAll(path, 8192, &capsFromFile) < 0)
+        goto cleanup;
+
+
+    if (STRNEQ(capsXML, capsFromFile)) {
+        virtTestDifference(stderr, capsFromFile, capsXML);
+        goto cleanup;
+    }
+
+    ret = 0;
+
+ cleanup:
+    VIR_FREE(path);
+    VIR_FREE(capsFromFile);
+    VIR_FREE(capsXML);
+    virObjectUnref(caps);
+    return ret;
+}
+
+static int
+mymain(void)
+{
+    int ret = 0;
+
+#define DO_TEST(filename, max_cells,                                        \
+                max_cpus_in_cell, max_mem_in_cell)                          \
+    do {                                                                    \
+        struct virCapabilitiesFormatData data = {filename, max_cells,       \
+                                                 max_cpus_in_cell,          \
+                                                 max_mem_in_cell};          \
+        if (virtTestRun(filename, test_virCapabilitiesFormat, &data) < 0)   \
+        ret = -1;                                                           \
+    } while (0)
+
+    DO_TEST("basic-4-4-2G", 4, 4, 2*1024*1024);
+
+    return ret;
+}
+
+VIRT_TEST_MAIN(mymain)
-- 
2.0.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]