[PATCH v3 12/12] tests: Test detach-device and detach-device-alias for test driver

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

 



Signed-off-by: Luke Yue <lukedyue@xxxxxxxxx>
---
 tests/virshtest.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 96 insertions(+)

diff --git a/tests/virshtest.c b/tests/virshtest.c
index af2a70f5fb..8e5b397420 100644
--- a/tests/virshtest.c
+++ b/tests/virshtest.c
@@ -160,6 +160,8 @@ static char *custom_uri;
     "--connect", \
     custom_uri
 
+# define TEST_XML_PATH abs_top_builddir "/../examples/xml/test"
+
 static int testCompareListDefault(const void *data G_GNUC_UNUSED)
 {
     const char *const argv[] = { VIRSH_DEFAULT, "list", NULL };
@@ -437,6 +439,88 @@ static int testIOThreadPin(const void *data G_GNUC_UNUSED)
     return testCompareOutputLit(exp, "", NULL, argv);
 }
 
+static int testCompareDetachDevice(const void *data G_GNUC_UNUSED)
+{
+    const char *const argv[] = { VIRSH_CUSTOM, "detach-device fc5\
+                                 " TEST_XML_PATH "/testdevif.xml;\
+                                 detach-device fc5\
+                                 " TEST_XML_PATH "/testdevdiskcdrom.xml;\
+                                 detach-device fc5\
+                                 " TEST_XML_PATH "/testdevsound.xml;\
+                                 detach-device fc5\
+                                 " TEST_XML_PATH "/testdevhostdev.xml;\
+                                 detach-device fc5\
+                                 " TEST_XML_PATH "/testdevlease.xml;\
+                                 detach-device fc5\
+                                 " TEST_XML_PATH "/testdevcontroller.xml;\
+                                 detach-device fc5\
+                                 " TEST_XML_PATH "/testdevfs.xml;\
+                                 detach-device fc5\
+                                 " TEST_XML_PATH "/testdevrng.xml;\
+                                 detach-device fc5\
+                                 " TEST_XML_PATH "/testdevmem.xml;\
+                                 detach-device fc5\
+                                 " TEST_XML_PATH "/testdevshmem.xml;\
+                                 detach-device fc5\
+                                 " TEST_XML_PATH "/testdevwatchdog.xml;\
+                                 detach-device fc5\
+                                 " TEST_XML_PATH "/testdevinput.xml;\
+                                 detach-device fc5\
+                                 " TEST_XML_PATH "/testdevvsock.xml;\
+                                 detach-device fc5\
+                                 " TEST_XML_PATH "/testdevtpm.xml",
+                                 NULL };
+    const char *exp =
+"Device detached successfully\n\n\
+Device detached successfully\n\n\
+Device detached successfully\n\n\
+Device detached successfully\n\n\
+Device detached successfully\n\n\
+Device detached successfully\n\n\
+Device detached successfully\n\n\
+Device detached successfully\n\n\
+Device detached successfully\n\n\
+Device detached successfully\n\n\
+Device detached successfully\n\n\
+Device detached successfully\n\n\
+Device detached successfully\n\n\
+Device detached successfully\n\n";
+    return testCompareOutputLit(exp, "", NULL, argv);
+}
+
+static int testCompareDetachDeviceError(const void *data G_GNUC_UNUSED)
+{
+    const char *const argv[] = { VIRSH_CUSTOM, "detach-device fc5\
+                                 " TEST_XML_PATH "/testdevtpm.xml;\
+                                 detach-device fc5\
+                                 " TEST_XML_PATH "/testdevtpm.xml;\
+                                 detach-device fc5 --live\
+                                 " TEST_XML_PATH "/testdevmemballoon.xml",
+                                 NULL };
+    const char *exp =
+"Device detached successfully\n\n\n\n";
+    const char *error_msg =
+"error: Failed to detach device from " TEST_XML_PATH "/testdevtpm.xml\n\
+error: device not found: matching tpm device not found\n\
+error: Failed to detach device from " TEST_XML_PATH "/testdevmemballoon.xml\n\
+error: Operation not supported: detach of device 'memballoon' on running domain is not supported\n";
+    return testCompareOutputLit(exp, error_msg, NULL, argv);
+}
+
+static int testCompareDetachDeviceAlias(const void *data G_GNUC_UNUSED)
+{
+    const char *const argv[] = { VIRSH_CUSTOM,
+                                 "detach-device-alias fc5 ua-testCD;\
+                                 detach-device fc5\
+                                 " TEST_XML_PATH "/testdevdiskcdrom.xml",
+                                 NULL };
+    const char *exp = "Device detach request sent successfully\n\n\n";
+    const char *error_msg =
+"error: Failed to detach device from " TEST_XML_PATH "/testdevdiskcdrom.xml\n\
+error: device not found: no target device hdb\n";
+    return testCompareOutputLit(exp, error_msg, NULL, argv);
+}
+
 struct testInfo {
     const char *const *argv;
     const char *result;
@@ -553,6 +637,18 @@ mymain(void)
                    testIOThreadPin, NULL) != 0)
         ret = -1;
 
+    if (virTestRun("virsh detach-device",
+                   testCompareDetachDevice, NULL) != 0)
+        ret = -1;
+
+    if (virTestRun("virsh detach-device (with failure)",
+                   testCompareDetachDeviceError, NULL) != 0)
+        ret = -1;
+
+    if (virTestRun("virsh detach-device-alias",
+                   testCompareDetachDeviceAlias, NULL) != 0)
+        ret = -1;
+
     /* It's a bit awkward listing result before argument, but that's a
      * limitation of C99 vararg macros.  */
 # define DO_TEST(i, result, ...) \
-- 
2.33.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