[PATCH 1/2] vircapstest: 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/vircapsdata/vircaps-basic.xml | 66 +++++++++++++++++++++++++++++++
 tests/vircapstest.c                 | 77 ++++++++++++++++++++++++++++++++++++-
 2 files changed, 141 insertions(+), 2 deletions(-)
 create mode 100644 tests/vircapsdata/vircaps-basic.xml

diff --git a/tests/vircapsdata/vircaps-basic.xml b/tests/vircapsdata/vircaps-basic.xml
new file mode 100644
index 0000000..c438c0d
--- /dev/null
+++ b/tests/vircapsdata/vircaps-basic.xml
@@ -0,0 +1,66 @@
+<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='2'>
+            <cpu id='0' socket_id='0' core_id='0' siblings='0'/>
+            <cpu id='1' socket_id='0' core_id='1' 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='2'>
+            <cpu id='1' socket_id='1' core_id='1' siblings='1'/>
+            <cpu id='2' socket_id='1' core_id='2' 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='2'>
+            <cpu id='2' socket_id='2' core_id='2' siblings=''/>
+            <cpu id='3' socket_id='2' core_id='3' siblings=''/>
+          </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='2'>
+            <cpu id='3' socket_id='3' core_id='3' siblings=''/>
+            <cpu id='4' socket_id='3' core_id='4' siblings=''/>
+          </cpus>
+        </cell>
+      </cells>
+    </topology>
+  </host>
+
+</capabilities>
diff --git a/tests/vircapstest.c b/tests/vircapstest.c
index 3edebba..64a9980 100644
--- a/tests/vircapstest.c
+++ b/tests/vircapstest.c
@@ -41,8 +41,10 @@ buildNUMATopology(int seq)
 {
     virCapsPtr caps;
     virCapsHostNUMACellCPUPtr cell_cpus = NULL;
-    int core_id, cell_id;
+    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;
@@ -63,13 +65,25 @@ buildNUMATopology(int seq)
         }
         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 + seq,
                                            MAX_MEM_IN_CELL,
                                            MAX_CPUS_IN_CELL, cell_cpus,
-                                           0, NULL) < 0)
+                                           nsiblings, siblings) < 0)
            goto error;
 
         cell_cpus = NULL;
+        siblings = NULL;
     }
 
     return caps;
@@ -77,6 +91,7 @@ buildNUMATopology(int seq)
  error:
     virCapabilitiesClearHostNUMACellCPUTopology(cell_cpus, MAX_CPUS_IN_CELL);
     VIR_FREE(cell_cpus);
+    VIR_FREE(siblings);
     virObjectUnref(caps);
     return NULL;
 
@@ -117,6 +132,55 @@ test_virCapabilitiesGetCpusForNodemask(const void *data ATTRIBUTE_UNUSED)
 }
 
 
+struct virCapabilitiesFormatData {
+    const char *filename;
+    int seq;
+};
+
+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;
+
+    /*
+     * Build a NUMA topology with cell_id (NUMA node id
+     * being 3(0 + 3),4(1 + 3), 5 and 6
+     */
+    if (!(caps = buildNUMATopology(0)))
+        goto cleanup;
+
+    if (!(capsXML = virCapabilitiesFormatXML(caps))) {
+        fprintf(stderr, "Unable to format capabilities XML");
+        goto cleanup;
+    }
+
+    if (virAsprintf(&path, "%s/vircapsdata/vircaps-%s.xml",
+                    abs_srcdir, data->filename) < 0)
+        goto cleanup;
+
+    if (virFileReadAll(path, 8192, &capsFromFile) < 0)
+        goto cleanup;
+
+    if (STRNEQ(capsXML, capsFromFile)) {
+        virtTestDifference(stderr, capsXML, capsFromFile);
+        goto cleanup;
+    }
+
+    ret = 0;
+
+ cleanup:
+    VIR_FREE(path);
+    VIR_FREE(capsFromFile);
+    VIR_FREE(capsXML);
+    virObjectUnref(caps);
+    return ret;
+}
+
 static int
 mymain(void)
 {
@@ -126,6 +190,15 @@ mymain(void)
                     test_virCapabilitiesGetCpusForNodemask, NULL) < 0)
         ret = -1;
 
+#define DO_TEST(filename, seq)                                              \
+    do {                                                                    \
+        struct virCapabilitiesFormatData data = {filename, seq};            \
+        if (virtTestRun(filename, test_virCapabilitiesFormat, &data) < 0)   \
+        ret = -1;                                                           \
+    } while (0)
+
+    DO_TEST("basic", 0);
+
     return ret;
 }
 
-- 
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]