[libvirt PATCH 3/7] nodedev: Add tests for mdevctl autostart command

Jonathon Jongsma jjongsma at redhat.com
Thu Jun 3 20:11:52 UTC 2021


Signed-off-by: Jonathon Jongsma <jjongsma at redhat.com>
---
 .../nodedevmdevctldata/mdevctl-autostart.argv |  8 +++
 tests/nodedevmdevctltest.c                    | 54 +++++++++++++++++++
 2 files changed, 62 insertions(+)
 create mode 100644 tests/nodedevmdevctldata/mdevctl-autostart.argv

diff --git a/tests/nodedevmdevctldata/mdevctl-autostart.argv b/tests/nodedevmdevctldata/mdevctl-autostart.argv
new file mode 100644
index 0000000000..9b441e9466
--- /dev/null
+++ b/tests/nodedevmdevctldata/mdevctl-autostart.argv
@@ -0,0 +1,8 @@
+mdevctl \
+modify \
+--uuid d069d019-36ea-4111-8f0a-8c9a70e21366 \
+--auto
+mdevctl \
+modify \
+--uuid d069d019-36ea-4111-8f0a-8c9a70e21366 \
+--manual
diff --git a/tests/nodedevmdevctltest.c b/tests/nodedevmdevctltest.c
index 8ba1d2da70..3f9d4c84b9 100644
--- a/tests/nodedevmdevctltest.c
+++ b/tests/nodedevmdevctltest.c
@@ -118,6 +118,55 @@ testMdevctlHelper(const void *data)
 }
 
 
+static int
+testMdevctlAutostart(const void *data G_GNUC_UNUSED)
+{
+    g_autoptr(virNodeDeviceDef) def = NULL;
+    virBuffer buf = VIR_BUFFER_INITIALIZER;
+    const char *actualCmdline = NULL;
+    int ret = -1;
+    g_autoptr(virCommand) enablecmd = NULL;
+    g_autoptr(virCommand) disablecmd = NULL;
+    g_autofree char *errmsg = NULL;
+    /* just concatenate both calls into the same output file */
+    g_autofree char *cmdlinefile =
+        g_strdup_printf("%s/nodedevmdevctldata/mdevctl-autostart.argv",
+                        abs_srcdir);
+    g_autofree char *mdevxml =
+        g_strdup_printf("%s/nodedevschemadata/mdev_d069d019_36ea_4111_8f0a_8c9a70e21366.xml",
+                        abs_srcdir);
+    g_autoptr(virCommandDryRunToken) dryRunToken = virCommandDryRunTokenNew();
+
+    if (!(def = virNodeDeviceDefParseFile(mdevxml, CREATE_DEVICE, VIRT_TYPE)))
+        return -1;
+
+    virCommandSetDryRun(dryRunToken, &buf, true, true, NULL, NULL);
+
+    if (!(enablecmd = nodeDeviceGetMdevctlSetAutostartCommand(def, true, &errmsg)))
+        goto cleanup;
+
+    if (virCommandRun(enablecmd, NULL) < 0)
+        goto cleanup;
+
+    if (!(disablecmd = nodeDeviceGetMdevctlSetAutostartCommand(def, false, &errmsg)))
+        goto cleanup;
+
+    if (virCommandRun(disablecmd, NULL) < 0)
+        goto cleanup;
+
+    if (!(actualCmdline = virBufferCurrentContent(&buf)))
+        goto cleanup;
+
+    if (virTestCompareToFileFull(actualCmdline, cmdlinefile, false) < 0)
+        goto cleanup;
+
+    ret = 0;
+
+ cleanup:
+    virBufferFreeAndReset(&buf);
+    return ret;
+}
+
 static int
 testMdevctlListDefined(const void *data G_GNUC_UNUSED)
 {
@@ -348,6 +397,9 @@ mymain(void)
 #define DO_TEST_LIST_DEFINED() \
     DO_TEST_FULL("list defined mdevs", testMdevctlListDefined, NULL)
 
+#define DO_TEST_AUTOSTART() \
+    DO_TEST_FULL("autostart mdevs", testMdevctlAutostart, NULL)
+
 #define DO_TEST_PARSE_JSON(filename) \
     DO_TEST_FULL("parse mdevctl json " filename, testMdevctlParse, filename)
 
@@ -370,6 +422,8 @@ mymain(void)
 
     DO_TEST_START("mdev_d069d019_36ea_4111_8f0a_8c9a70e21366");
 
+    DO_TEST_AUTOSTART();
+
  done:
     nodedevTestDriverFree(driver);
 
-- 
2.31.1




More information about the libvir-list mailing list