Signed-off-by: Luke Yue <lukedyue(a)gmail.com>
---
tests/virshtest.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 78 insertions(+)
diff --git a/tests/virshtest.c b/tests/virshtest.c
index 0d2ffd960a..c37d24e900 100644
--- a/tests/virshtest.c
+++ b/tests/virshtest.c
@@ -159,6 +159,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 };
@@ -343,6 +345,74 @@ static int testCompareSetBlkioParameters(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;\
+ 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\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";
+ 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;
@@ -443,6 +513,14 @@ mymain(void)
testCompareSetBlkioParameters, NULL) != 0)
ret = -1;
+ if (virTestRun("virsh detach-device",
+ testCompareDetachDevice, 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.0