[PATCH] test: Introduce chxml2xmltest

Michal Privoznik posted 1 patch 1 year, 1 month ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/34519d6f2c35d2e324931583ad527e09f38808d0.1676043002.git.mprivozn@redhat.com
tests/chxml2xmlin/basic.xml  | 30 ++++++++++++++
tests/chxml2xmlout/basic.xml |  1 +
tests/chxml2xmltest.c        | 77 ++++++++++++++++++++++++++++++++++++
tests/meson.build            |  6 +++
4 files changed, 114 insertions(+)
create mode 100644 tests/chxml2xmlin/basic.xml
create mode 120000 tests/chxml2xmlout/basic.xml
create mode 100644 tests/chxml2xmltest.c
[PATCH] test: Introduce chxml2xmltest
Posted by Michal Privoznik 1 year, 1 month ago
Whilst reviewing a patch upstream (that ended up as
v9.0.0-200-g092176e5ec), I realized we don't have a single
xml2xml test for CH driver. Well, introduce the test with one
simple test case for now.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---

We could also benefit from xml2arg test, but I'll leave that for future
ourselves.

 tests/chxml2xmlin/basic.xml  | 30 ++++++++++++++
 tests/chxml2xmlout/basic.xml |  1 +
 tests/chxml2xmltest.c        | 77 ++++++++++++++++++++++++++++++++++++
 tests/meson.build            |  6 +++
 4 files changed, 114 insertions(+)
 create mode 100644 tests/chxml2xmlin/basic.xml
 create mode 120000 tests/chxml2xmlout/basic.xml
 create mode 100644 tests/chxml2xmltest.c

diff --git a/tests/chxml2xmlin/basic.xml b/tests/chxml2xmlin/basic.xml
new file mode 100644
index 0000000000..911aa7c621
--- /dev/null
+++ b/tests/chxml2xmlin/basic.xml
@@ -0,0 +1,30 @@
+<domain type='kvm'>
+  <name>cloudhypervisor</name>
+  <uuid>4dea22b3-1d52-d8f3-2516-782e98ab3fa0</uuid>
+  <memory unit='KiB'>2097152</memory>
+  <currentMemory unit='KiB'>2097152</currentMemory>
+  <vcpu placement='static'>2</vcpu>
+  <os>
+    <type arch='x86_64'>hvm</type>
+    <kernel>hypervisor-fw</kernel>
+    <boot dev='hd'/>
+  </os>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <emulator>/usr/local/bin/cloud-hypervisor</emulator>
+    <disk type='file' device='disk'>
+      <source file='disk.raw'/>
+      <target dev='vda' bus='virtio'/>
+    </disk>
+    <interface type='ethernet'>
+      <mac address='52:54:00:5c:e4:84'/>
+      <model type='virtio'/>
+    </interface>
+    <console type='pty'>
+      <target type='serial' port='0'/>
+    </console>
+  </devices>
+</domain>
diff --git a/tests/chxml2xmlout/basic.xml b/tests/chxml2xmlout/basic.xml
new file mode 120000
index 0000000000..eb8df546aa
--- /dev/null
+++ b/tests/chxml2xmlout/basic.xml
@@ -0,0 +1 @@
+../chxml2xmlin/basic.xml
\ No newline at end of file
diff --git a/tests/chxml2xmltest.c b/tests/chxml2xmltest.c
new file mode 100644
index 0000000000..97b485dc4a
--- /dev/null
+++ b/tests/chxml2xmltest.c
@@ -0,0 +1,77 @@
+#include <config.h>
+
+#include <testutils.h>
+
+#include "ch/ch_conf.h"
+
+struct testInfo {
+    const char *name;
+    virCHDriver *driver;
+    testCompareDomXML2XMLResult expectResult;
+};
+
+typedef enum {
+    FLAG_IS_DIFFERENT =   1 << 0,
+    FLAG_EXPECT_FAILURE = 1 << 1,
+} virBhyveXMLToXMLTestFlags;
+
+static int
+testCompareXMLToXMLHelper(const void *data)
+{
+    const struct testInfo *info = data;
+    g_autofree char *xml_in = NULL;
+    g_autofree char *xml_out = NULL;
+
+    xml_in = g_strdup_printf("%s/chxml2xmlin/%s.xml",
+                             abs_srcdir, info->name);
+    xml_out = g_strdup_printf("%s/chxml2xmlout/%s.xml",
+                              abs_srcdir, info->name);
+
+    return testCompareDomXML2XMLFiles(NULL, info->driver->xmlopt,
+                                      xml_in, xml_out, false, 0,
+                                      info->expectResult);
+}
+
+static int
+mymain(void)
+{
+    int ret = 0;
+    virCHDriver *driver = NULL;
+
+    driver = g_new0(virCHDriver, 1);
+
+    if (!(driver->caps = virCHDriverCapsInit())) {
+        fprintf(stderr, "unable to initialize driver capabilities\n");
+        goto cleanup;
+    }
+
+    if (!(driver->xmlopt = chDomainXMLConfInit(driver))) {
+        fprintf(stderr, "unable to initialize driver XMLOPT\n");
+        goto cleanup;
+    }
+
+#define DO_TEST_FULL(name, expectResult) \
+    do { \
+        const struct testInfo info = {name, driver, expectResult}; \
+        if (virTestRun("CH XML-2-XML " name, \
+                       testCompareXMLToXMLHelper, &info) < 0) \
+        ret = -1; \
+    } while (0)
+
+#define DO_TEST(name) \
+    DO_TEST_FULL(name, TEST_COMPARE_DOM_XML2XML_RESULT_SUCCESS)
+
+#define DO_TEST_FAIL_PARSE(name) \
+    DO_TEST_FULL(name, TEST_COMPARE_DOM_XML2XML_RESULT_FAIL_PARSE)
+
+    DO_TEST("basic");
+
+ cleanup:
+    virObjectUnref(driver->xmlopt);
+    virObjectUnref(driver->caps);
+    g_free(driver);
+
+    return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
+}
+
+VIR_TEST_MAIN(mymain)
diff --git a/tests/meson.build b/tests/meson.build
index 3365dce307..15b049c6ac 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -347,6 +347,12 @@ if conf.has('WITH_BHYVE')
   ]
 endif
 
+if conf.has('WITH_CH')
+  tests += [
+    { 'name': 'chxml2xmltest', 'link_with': [ ch_driver_impl ] },
+  ]
+endif
+
 if conf.has('WITH_ESX')
   tests += [
     { 'name': 'esxutilstest', 'deps': [ esx_dep ] },
-- 
2.39.1
Re: [PATCH] test: Introduce chxml2xmltest
Posted by Ján Tomko 1 year, 1 month ago
On a Friday in 2023, Michal Privoznik wrote:
>Whilst reviewing a patch upstream (that ended up as
>v9.0.0-200-g092176e5ec), I realized we don't have a single
>xml2xml test for CH driver. Well, introduce the test with one
>simple test case for now.
>
>Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
>---
>
>We could also benefit from xml2arg test, but I'll leave that for future
>ourselves.
>
> tests/chxml2xmlin/basic.xml  | 30 ++++++++++++++
> tests/chxml2xmlout/basic.xml |  1 +
> tests/chxml2xmltest.c        | 77 ++++++++++++++++++++++++++++++++++++
> tests/meson.build            |  6 +++
> 4 files changed, 114 insertions(+)
> create mode 100644 tests/chxml2xmlin/basic.xml
> create mode 120000 tests/chxml2xmlout/basic.xml
> create mode 100644 tests/chxml2xmltest.c
>

Reviewed-by: Ján Tomko <jtomko@redhat.com>

Jano