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

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

 



Signed-off-by: Jonathon Jongsma <jjongsma@xxxxxxxxxx>
Reviewed-by: Daniel P. Berrangé <berrange@xxxxxxxxxx>
---
 .../nodedevmdevctldata/mdevctl-autostart.argv |  8 +++
 tests/nodedevmdevctltest.c                    | 55 +++++++++++++++++++
 2 files changed, 63 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 3d1a7e4b6c..92d3c75766 100644
--- a/tests/nodedevmdevctltest.c
+++ b/tests/nodedevmdevctltest.c
@@ -124,6 +124,56 @@ 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,
+                                          &parser_callbacks, NULL)))
+        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)
 {
@@ -378,6 +428,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)
 
@@ -401,6 +454,8 @@ mymain(void)
 
     DO_TEST_START("mdev_d069d019_36ea_4111_8f0a_8c9a70e21366");
 
+    DO_TEST_AUTOSTART();
+
  done:
     nodedevTestDriverFree(driver);
 
-- 
2.31.1




[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]

  Powered by Linux