Received: from eggs.gnu.org ([2001:4830:134:3::10]:50970) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XaVth-0006Pz-IC for qemu-devel@nongnu.org; Sat, 04 Oct 2014 16:25:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XaVtb-0004mr-9p for qemu-devel@nongnu.org; Sat, 04 Oct 2014 16:25:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:7007) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XaVtb-0004mk-2z for qemu-devel@nongnu.org; Sat, 04 Oct 2014 16:25:39 -0400 From: Stefan Hajnoczi Date: Sat, 4 Oct 2014 21:24:48 +0100 Message-Id: <1412454289-1789-23-git-send-email-stefanha@redhat.com> In-Reply-To: <1412454289-1789-1-git-send-email-stefanha@redhat.com> References: <1412454289-1789-1-git-send-email-stefanha@redhat.com> Subject: [Qemu-devel] [PULL 22/23] blockdev-test: Factor out some common code into helpers List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Maydell From: Markus Armbruster Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Message-id: 1412261496-24455-6-git-send-email-armbru@redhat.com Signed-off-by: Stefan Hajnoczi --- tests/drive_del-test.c | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/tests/drive_del-test.c b/tests/drive_del-test.c index 80917ad..38f8229 100644 --- a/tests/drive_del-test.c +++ b/tests/drive_del-test.c @@ -14,14 +14,23 @@ #include #include "libqtest.h" -static void test_drive_without_dev(void) +static void drive_add(void) { QDict *response; - /* Start with an empty drive */ - qtest_start("-drive if=none,id=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); +} + +static void drive_del(void) +{ + QDict *response; - /* Delete the drive */ response = qmp("{'execute': 'human-monitor-command'," " 'arguments': {" " 'command-line': 'drive_del drive0'" @@ -29,17 +38,20 @@ static void test_drive_without_dev(void) g_assert(response); g_assert_cmpstr(qdict_get_try_str(response, "return"), ==, ""); QDECREF(response); +} + +static void test_drive_without_dev(void) +{ + /* Start with an empty drive */ + qtest_start("-drive if=none,id=drive0"); + + /* Delete the drive */ + 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