]> xenbits.xensource.com Git - libvirt.git/commitdiff
nodedev: Add testing for 'mdevctl stop'
authorJonathon Jongsma <jjongsma@redhat.com>
Thu, 18 Jun 2020 21:06:03 +0000 (16:06 -0500)
committerErik Skultety <eskultet@redhat.com>
Fri, 19 Jun 2020 08:39:55 +0000 (10:39 +0200)
Test that we run 'mdevctl' with the proper arguments when we destroy
mediated devices with virNodeDeviceDestroy()

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
tests/nodedevmdevctldata/mdevctl-stop.argv [new file with mode: 0644]
tests/nodedevmdevctltest.c

diff --git a/tests/nodedevmdevctldata/mdevctl-stop.argv b/tests/nodedevmdevctldata/mdevctl-stop.argv
new file mode 100644 (file)
index 0000000..3dbaab6
--- /dev/null
@@ -0,0 +1 @@
+$MDEVCTL_BINARY$ stop -u e2451f73-c95b-4124-b900-e008af37c576
index 4b029c72866b6dcee13de4a7025dd14575f452d2..f5bcf5227d7b54f237e92c1152d8423ba1b1bbb9 100644 (file)
@@ -110,6 +110,41 @@ testMdevctlStartHelper(const void *data)
                             jsonfile);
 }
 
+static int
+testMdevctlStop(const void *data)
+{
+    const char *uuid = data;
+    virBuffer buf = VIR_BUFFER_INITIALIZER;
+    const char *actualCmdline = NULL;
+    int ret = -1;
+    g_autoptr(virCommand) cmd = NULL;
+    g_autofree char *cmdlinefile =
+        g_strdup_printf("%s/nodedevmdevctldata/mdevctl-stop.argv",
+                        abs_srcdir);
+
+    cmd = nodeDeviceGetMdevctlStopCommand(uuid);
+
+    if (!cmd)
+        goto cleanup;
+
+    virCommandSetDryRun(&buf, NULL, NULL);
+    if (virCommandRun(cmd, NULL) < 0)
+        goto cleanup;
+
+    if (!(actualCmdline = virBufferCurrentContent(&buf)))
+        goto cleanup;
+
+    if (nodedevCompareToFile(actualCmdline, cmdlinefile) < 0)
+        goto cleanup;
+
+    ret = 0;
+
+ cleanup:
+    virBufferFreeAndReset(&buf);
+    virCommandSetDryRun(NULL, NULL, NULL);
+    return ret;
+}
+
 static void
 nodedevTestDriverFree(virNodeDeviceDriverStatePtr drv)
 {
@@ -248,11 +283,17 @@ mymain(void)
 #define DO_TEST_START(filename) \
     DO_TEST_START_FULL("QEMU", CREATE_DEVICE, filename)
 
+#define DO_TEST_STOP(uuid) \
+    DO_TEST_FULL("mdevctl stop " uuid, testMdevctlStop, uuid)
+
     /* Test mdevctl start commands */
     DO_TEST_START("mdev_d069d019_36ea_4111_8f0a_8c9a70e21366");
     DO_TEST_START("mdev_fedc4916_1ca8_49ac_b176_871d16c13076");
     DO_TEST_START("mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9");
 
+    /* Test mdevctl stop command, pass an arbitrary uuid */
+    DO_TEST_STOP("e2451f73-c95b-4124-b900-e008af37c576");
+
  done:
     nodedevTestDriverFree(driver);