qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] [PATCH 5/6] blockdev-test: Factor out some common code into


From: Markus Armbruster
Subject: [Qemu-devel] [PATCH 5/6] blockdev-test: Factor out some common code into helpers
Date: Thu, 2 Oct 2014 16:51:35 +0200

Signed-off-by: Markus Armbruster <address@hidden>
---
 tests/drive_del-test.c | 60 +++++++++++++++++++++++++-------------------------
 1 file changed, 30 insertions(+), 30 deletions(-)

diff --git a/tests/drive_del-test.c b/tests/drive_del-test.c
index 2baf0b7..463479d 100644
--- a/tests/drive_del-test.c
+++ b/tests/drive_del-test.c
@@ -14,32 +14,44 @@
 #include <string.h>
 #include "libqtest.h"
 
+static void drive_add(void)
+{
+    QDict *response;
+
+    response = qmp("{'execute': 'human-monitor-command',"
+                   " 'arguments': {"
+                   "   'command-line': 'drive_add 0 if=none,id=drive0'"
+                   "}}");
+    g_assert(response);
+    g_assert_cmpstr(qdict_get_try_str(response, "return"), ==, "OK\r\n");
+    QDECREF(response);
+}
+
+static void drive_del(void)
+{
+    QDict *response;
+
+    response = qmp("{'execute': 'human-monitor-command',"
+                   " 'arguments': {"
+                   "   'command-line': 'drive_del drive0'"
+                   "}}");
+    g_assert(response);
+    g_assert_cmpstr(qdict_get_try_str(response, "return"), ==, "");
+    QDECREF(response);
+}
+
 static void test_drive_without_dev(void)
 {
-    QDict *response;
-
     /* Start with an empty drive */
     qtest_start("-drive if=none,id=drive0");
 
     /* Delete the drive */
-    response = qmp("{'execute': 'human-monitor-command',"
-                   " 'arguments': {"
-                   "   'command-line': 'drive_del drive0'"
-                   "}}");
-    g_assert(response);
-    g_assert_cmpstr(qdict_get_try_str(response, "return"), ==, "");
-    QDECREF(response);
+    drive_del();
 
     /* Ensure re-adding the drive works - there should be no duplicate ID error
      * because the old drive must be gone.
      */
-    response = qmp("{'execute': 'human-monitor-command',"
-                   " 'arguments': {"
-                   "   'command-line': 'drive_add 0 if=none,id=drive0'"
-                   "}}");
-    g_assert(response);
-    g_assert_cmpstr(qdict_get_try_str(response, "return"), ==, "OK\r\n");
-    QDECREF(response);
+    drive_add();
 
     qtest_end();
 }
@@ -65,24 +77,12 @@ static void test_after_failed_device_add(void)
     QDECREF(response);
 
     /* Delete the drive */
-    response = qmp("{'execute': 'human-monitor-command',"
-                   " 'arguments': {"
-                   "   'command-line': 'drive_del drive0'"
-                   "}}");
-    g_assert(response);
-    g_assert_cmpstr(qdict_get_try_str(response, "return"), ==, "");
-    QDECREF(response);
+    drive_del();
 
     /* Try to re-add the drive.  This fails with duplicate IDs if a leaked
      * virtio-blk-pci exists that holds a reference to the old drive0.
      */
-    response = qmp("{'execute': 'human-monitor-command',"
-                   " 'arguments': {"
-                   "   'command-line': 'drive_add 0 if=none,id=drive0'"
-                   "}}");
-    g_assert(response);
-    g_assert_cmpstr(qdict_get_try_str(response, "return"), ==, "OK\r\n");
-    QDECREF(response);
+    drive_add();
 
     qtest_end();
 }
-- 
1.9.3




reply via email to

[Prev in Thread] Current Thread [Next in Thread]