]> xenbits.xensource.com Git - libvirt.git/commitdiff
tests: Introduce viracpitest
authorMichal Privoznik <mprivozn@redhat.com>
Tue, 4 Apr 2023 15:07:21 +0000 (17:07 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 6 Apr 2023 10:48:22 +0000 (12:48 +0200)
Introduce a test that checks newly introduced virAcpi module.
There are three IORT tables from a real HW (IORT_ampere,
IORT_gigabyte and IORT_qualcomm), then there's one from a VM
(IORT_virt_aarch64) and one that I handcrafted to be empty
(IORT_empty).

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
build-aux/syntax-check.mk
tests/meson.build
tests/viracpidata/IORT_ampere [new file with mode: 0644]
tests/viracpidata/IORT_empty [new file with mode: 0644]
tests/viracpidata/IORT_gigabyte [new file with mode: 0644]
tests/viracpidata/IORT_qualcomm [new file with mode: 0644]
tests/viracpidata/IORT_virt_aarch64 [new file with mode: 0644]
tests/viracpitest.c [new file with mode: 0644]

index 5829dc9011141e6d14d6cfcc3e4fb19ada7df39c..64c1e2773ea77bb19021b17e0bf9072ba3ac26b6 100644 (file)
@@ -1370,7 +1370,7 @@ exclude_file_name_regexp--sc_prohibit_close = \
   (\.p[yl]$$|\.spec\.in$$|^docs/|^(src/util/vir(file|event)\.c|src/libvirt-stream\.c|tests/(vir.+mock\.c|commandhelper\.c|qemusecuritymock\.c)|tools/nss/libvirt_nss_(leases|macs)\.c)|tools/virt-qemu-qmp-proxy$$)
 
 exclude_file_name_regexp--sc_prohibit_empty_lines_at_EOF = \
-  (^tests/(nodedevmdevctl|virhostcpu|virpcitest|virstoragetest)data/|docs/js/.*\.js|docs/fonts/.*\.woff|\.diff|tests/virconfdata/no-newline\.conf$$)
+  (^tests/(nodedevmdevctl|viracpi|virhostcpu|virpcitest|virstoragetest)data/|docs/js/.*\.js|docs/fonts/.*\.woff|\.diff|tests/virconfdata/no-newline\.conf$$)
 
 exclude_file_name_regexp--sc_prohibit_fork_wrappers = \
   (^(src/(util/(vircommand|virdaemon)|lxc/lxc_controller)|tests/testutils)\.c$$)
index 24d08e4f978e4bf274c2b4b9acf58d2c880fcb56..35adbc2d5628816fc0873472d5d8e356d08dcf59 100644 (file)
@@ -269,6 +269,7 @@ tests += [
   { 'name': 'storagevolxml2xmltest' },
   { 'name': 'sysinfotest' },
   { 'name': 'utiltest' },
+  { 'name': 'viracpitest' },
   { 'name': 'viralloctest' },
   { 'name': 'virauthconfigtest' },
   { 'name': 'virbitmaptest' },
diff --git a/tests/viracpidata/IORT_ampere b/tests/viracpidata/IORT_ampere
new file mode 100644 (file)
index 0000000..02e7fd9
Binary files /dev/null and b/tests/viracpidata/IORT_ampere differ
diff --git a/tests/viracpidata/IORT_empty b/tests/viracpidata/IORT_empty
new file mode 100644 (file)
index 0000000..58b696f
Binary files /dev/null and b/tests/viracpidata/IORT_empty differ
diff --git a/tests/viracpidata/IORT_gigabyte b/tests/viracpidata/IORT_gigabyte
new file mode 100644 (file)
index 0000000..b18b445
Binary files /dev/null and b/tests/viracpidata/IORT_gigabyte differ
diff --git a/tests/viracpidata/IORT_qualcomm b/tests/viracpidata/IORT_qualcomm
new file mode 100644 (file)
index 0000000..5364a99
Binary files /dev/null and b/tests/viracpidata/IORT_qualcomm differ
diff --git a/tests/viracpidata/IORT_virt_aarch64 b/tests/viracpidata/IORT_virt_aarch64
new file mode 100644 (file)
index 0000000..7efd0ce
Binary files /dev/null and b/tests/viracpidata/IORT_virt_aarch64 differ
diff --git a/tests/viracpitest.c b/tests/viracpitest.c
new file mode 100644 (file)
index 0000000..f5dd542
--- /dev/null
@@ -0,0 +1,135 @@
+/*
+ * viracpitest.c: Test ACPI table parsing
+ *
+ * Copyright (C) 2023 Red Hat, Inc.
+ *
+ * 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/>.
+ *
+ */
+
+#include <config.h>
+
+#define LIBVIRT_VIRACPIPRIV_H_ALLOW
+#include "testutils.h"
+#include "viracpi.h"
+#include "viracpipriv.h"
+
+#define VIR_FROM_THIS VIR_FROM_NONE
+
+typedef struct testAarch64SMMUData testAarch64SMMUData;
+struct testAarch64SMMUData {
+    const char *filename;
+    ssize_t nnodes;
+    const virIORTNodeType *node_types;
+};
+
+static void
+printBitmap(virBitmap *types)
+{
+    size_t i;
+
+    for (i = 0; i < VIR_IORT_NODE_TYPE_LAST; i++) {
+        if (virBitmapIsBitSet(types, i)) {
+            fprintf(stderr, "%s\n", virIORTNodeTypeTypeToString(i));
+        }
+    }
+}
+
+static int
+testAarch64SMMU(const void *opaque)
+{
+    const testAarch64SMMUData *data = opaque;
+    g_autofree char *path = NULL;
+    g_autofree virIORTNodeHeader *nodes = NULL;
+    ssize_t nnodes = 0;
+
+    path = g_strdup_printf("%s/viracpidata/%s",
+                           abs_srcdir, data->filename);
+
+    nnodes = virAcpiParseIORT(&nodes, path);
+
+    if (nnodes != data->nnodes) {
+        fprintf(stderr,
+                "virAcpiParseIORT() returned wrong number of nodes: %zd, expected %zd\n",
+                nnodes, data->nnodes);
+        return -1;
+    }
+
+    if (nnodes > 0) {
+        g_autoptr(virBitmap) typesSeen = virBitmapNew(VIR_IORT_NODE_TYPE_LAST);
+        g_autoptr(virBitmap) typesExp = virBitmapNew(VIR_IORT_NODE_TYPE_LAST);
+        size_t i = 0;
+
+        for (i = 0; data->node_types[i] != VIR_IORT_NODE_TYPE_LAST; i++) {
+            size_t type = data->node_types[i];
+
+            ignore_value(virBitmapSetBit(typesExp, type));
+        }
+
+        for (i = 0; i < nnodes; i++) {
+            virIORTNodeHeader *h = &nodes[i];
+
+            ignore_value(virBitmapSetBit(typesSeen, h->type));
+        }
+
+        if (!virBitmapEqual(typesSeen, typesExp)) {
+            fprintf(stderr, "node types mismatch.\n\nExpected:\n");
+            printBitmap(typesExp);
+            fprintf(stderr, "\nActual:\n");
+            printBitmap(typesSeen);
+            return -1;
+        }
+    }
+
+    return 0;
+}
+
+
+static int
+mymain(void)
+{
+    int ret = 0;
+
+#define DO_TEST(filename, nnodes, ...) \
+    do { \
+        const virIORTNodeType node_types[] = { __VA_ARGS__, VIR_IORT_NODE_TYPE_LAST }; \
+        const testAarch64SMMUData data = {filename, nnodes, node_types }; \
+        if (virTestRun("aarch64 SMMU " filename, testAarch64SMMU, &data) < 0) \
+            ret = -1; \
+    } while (0)
+
+    DO_TEST("IORT_empty", 0, VIR_IORT_NODE_TYPE_LAST);
+    DO_TEST("IORT_virt_aarch64", 2,
+            VIR_IORT_NODE_TYPE_ITS_GROUP,
+            VIR_IORT_NODE_TYPE_ROOT_COMPLEX);
+    DO_TEST("IORT_ampere", 36,
+            VIR_IORT_NODE_TYPE_ITS_GROUP,
+            VIR_IORT_NODE_TYPE_ROOT_COMPLEX,
+            VIR_IORT_NODE_TYPE_SMMUV3);
+    DO_TEST("IORT_gigabyte", 30,
+            VIR_IORT_NODE_TYPE_ITS_GROUP,
+            VIR_IORT_NODE_TYPE_ROOT_COMPLEX,
+            VIR_IORT_NODE_TYPE_SMMUV1_OR_SMMUV2);
+    DO_TEST("IORT_qualcomm", 69,
+            VIR_IORT_NODE_TYPE_ITS_GROUP,
+            VIR_IORT_NODE_TYPE_NAMED_COMPONENT,
+            VIR_IORT_NODE_TYPE_ROOT_COMPLEX,
+            VIR_IORT_NODE_TYPE_SMMUV3,
+            VIR_IORT_NODE_TYPE_PMCG);
+
+    return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
+}
+
+VIR_TEST_MAIN(mymain)