Improve drive_del test coverage
PATCH 4/6 blockdev-test: Simplify by using g_assert_cmpstr()
In reply to Markus Armbruster--- tests/drive_del-test.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
tests/drive_del-test.c +2 -7
@@ -17,7 +17,6 @@static void test_drive_without_dev (void ) {QDict *response; -const char *response_return;/* Start with an empty drive */ qtest_start ("-drive if=none,id=drive0" );
@@ -28,9 +27,7 @@ static void test_drive_without_dev(void)" 'command-line': 'drive_del drive0'" "}}");g_assert (response); - response_return =qdict_get_try_str (response,"return" ); -g_assert (response_return); -g_assert (strcmp (response_return,"" ) ==0 ); + g_assert_cmpstr(qdict_get_try_str(response, "return"), ==, "");QDECREF (response);/* Ensure re-adding the drive works - there should be no duplicate ID error
@@ -41,9 +38,7 @@ static void test_drive_without_dev(void)" 'command-line': 'drive_add 0 if=none,id=drive0'" "}}");g_assert (response); - response_return =qdict_get_try_str (response,"return" ); -g_assert (response_return); -g_assert (strcmp (response_return,"OK\r\n" ) ==0 ); + g_assert_cmpstr(qdict_get_try_str(response, "return"), ==, "OK\r\n");QDECREF (response);qtest_end ();
Signature · 1 line
1.9.3
cover Improve drive_del test coverage
The meat is in the last patch, the others are just cleanup.
Markus Armbruster (6):
drive_del-test: Merge of qdev-monitor-test, blockdev-test
blockdev-test: Use single rather than double quotes in QMP
blockdev-test: Clean up bogus drive_add argument
blockdev-test: Simplify by using g_assert_cmpstr()
blockdev-test: Factor out some common code into helpers
blockdev-test: Test device_del after drive_del
tests/Makefile | 5 +- tests/blockdev-test.c | 59 -------------------- tests/drive_del-test.c | 137 ++++++++++++++++++++++++++++++++++++++++++++++ tests/qdev-monitor-test.c | 77 -------------------------- 4 files changed, 139 insertions(+), 139 deletions(-) delete mode 100644 tests/blockdev-test.c create mode 100644 tests/drive_del-test.c delete mode 100644 tests/qdev-monitor-test.c
Signature · 1 line
1.9.3
PATCH 2/6 blockdev-test: Use single rather than double quotes in QMP
QMP accepts both single and double quotes. This is the only test using double quotes. They need to be quoted in C strings. Replace them by single quotes.
--- tests/drive_del-test.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-)
tests/drive_del-test.c +16 -16
@@ -23,9 +23,9 @@ static void test_drive_without_dev(void)qtest_start ("-drive if=none,id=drive0" );/* Delete the drive */ - response =qmp ("{\"execute\": \"human-monitor-command\"," -" \"arguments\": {" -" \"command-line\": \"drive_del drive0\"" + response =qmp ("{'execute': 'human-monitor-command'," +" 'arguments': {" +" 'command-line': 'drive_del drive0'" "}}" );g_assert (response); response_return =qdict_get_try_str (response,"return" );
@@ -36,9 +36,9 @@ static void test_drive_without_dev(void)/* 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\"" + response =qmp ("{'execute': 'human-monitor-command'," +" 'arguments': {" +" 'command-line': 'drive_add 0 if=none,id=drive0'" "}}" );g_assert (response); response_return =qdict_get_try_str (response,"return" );
@@ -59,10 +59,10 @@ static void test_after_failed_device_add(void)/* Make device_add fail. If this leaks the virtio-blk-pci device then a * reference to drive0 will also be held (via qdev properties). */ - response =qmp ("{\"execute\": \"device_add\"," -" \"arguments\": {" -" \"driver\": \"virtio-blk-pci\"," -" \"drive\": \"drive0\"" + response =qmp ("{'execute': 'device_add'," +" 'arguments': {" +" 'driver': 'virtio-blk-pci'," +" 'drive': 'drive0'" "}}" );g_assert (response); error =qdict_get_qdict (response,"error" );
@@ -70,9 +70,9 @@ 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\"" + response =qmp ("{'execute': 'human-monitor-command'," +" 'arguments': {" +" 'command-line': 'drive_del drive0'" "}}" );g_assert (response); g_assert_cmpstr(qdict_get_try_str(response, "return"), ==, "");
@@ -81,9 +81,9 @@ static void test_after_failed_device_add(void)/* 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 pci-addr=auto if=none,id=drive0\"" + response =qmp ("{'execute': 'human-monitor-command'," +" 'arguments': {" +" 'command-line': 'drive_add pci-addr=auto if=none,id=drive0'" "}}" );g_assert (response); g_assert_cmpstr(qdict_get_try_str(response, "return"), ==, "OK\r\n");
Signature · 1 line
1.9.3
PATCH 5/6 blockdev-test: Factor out some common code into helpers
In reply to Markus Armbruster--- tests/drive_del-test.c | 60 +++++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 30 deletions(-)
tests/drive_del-test.c +30 -30
@@ -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 (); }
Signature · 1 line
1.9.3
PATCH 6/6 blockdev-test: Test device_del after drive_del
In reply to Markus ArmbrusterExecuted in this order, drive_del and device_del's automatic drive deletion take notoriously tricky special paths.
--- tests/drive_del-test.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)
tests/drive_del-test.c +32 -0
@@ -40,6 +40,19 @@ static void drive_del(void)QDECREF (response); } +static void device_del (void ) +{ +QDict *response; + +/* Complication: ignore DEVICE_DELETED event */ +qmp_discard_response ("{'execute': 'device_del'," +" 'arguments': { 'id': 'dev0' } }" ); + response =qmp_receive (); +g_assert (response); +g_assert (qdict_haskey (response,"return" )); +QDECREF (response); +} +static void test_drive_without_dev (void ) {/* Start with an empty drive */
@@ -87,6 +100,23 @@ static void test_after_failed_device_add(void)qtest_end (); } +static void test_drive_del_device_del (void ) +{ +/* Start with a drive used by an device that unplugs instantaneously */ +qtest_start ("-drive if=none,id=drive0,file=/dev/null" +" -device virtio-scsi-pci" +" -device scsi-hd,drive=drive0,id=dev0" ); + +/* +* Delete the drive, and then the device +* Doing it in this order takes notoriously tricky special paths +*/ +drive_del (); +device_del (); + +qtest_end (); +} +int main (int argc,char **argv) {const char *arch =qtest_get_arch ();
@@ -99,6 +129,8 @@ int main(int argc, char **argv)if (!strcmp (arch,"i386" ) || !strcmp (arch,"x86_64" )) {qtest_add_func ("/drive_del/after_failed_device_add" , test_after_failed_device_add); +qtest_add_func ("/blockdev/drive_del_device_del" , + test_drive_del_device_del); }return g_test_run ();
Signature · 1 line
1.9.3
PATCH 1/6 drive_del-test: Merge of qdev-monitor-test, blockdev-test
In reply to Markus ArmbrusterEach of qdev-monitor-test and blockdev-test has just one test case, and both are about drive_del.
---
tests/Makefile | 5 +--
tests/blockdev-test.c | 59 -------------------------
tests/{qdev-monitor-test.c => drive_del-test.c} | 57 +++++++++++++++++++-----
3 files changed, 47 insertions(+), 74 deletions(-)
delete mode 100644 tests/blockdev-test.c
rename tests/{qdev-monitor-test.c => drive_del-test.c} (56%)tests/Makefile +2 -3
@@ -140,8 +140,7 @@ check-qtest-i386-y += tests/bios-tables-test$(EXESUF) check-qtest-i386-y += tests/rtc-test$(EXESUF) check-qtest-i386-y += tests/i440fx-test$(EXESUF) check-qtest-i386-y += tests/fw_cfg-test$(EXESUF) -check-qtest-i386-y += tests/blockdev-test$(EXESUF) -check-qtest-i386-y += tests/qdev-monitor-test$(EXESUF) +check-qtest-i386-y += tests/drive_del-test$(EXESUF) check-qtest-i386-y += tests/wdt_ib700-test$(EXESUF) gcov-files-i386-y += hw/watchdog/watchdog.c hw/watchdog/wdt_ib700.c check-qtest-i386-y += $(check-qtest-pci-y)
@@ -335,7 +334,7 @@ tests/tpci200-test$(EXESUF): tests/tpci200-test.o tests/display-vga-test$(EXESUF): tests/display-vga-test.o tests/ipoctal232-test$(EXESUF): tests/ipoctal232-test.o tests/qom-test$(EXESUF): tests/qom-test.o -tests/blockdev-test$(EXESUF): tests/blockdev-test.o $(libqos-pc-obj-y) +tests/drive_del-test$(EXESUF): tests/drive_del-test.o $(libqos-pc-obj-y) tests/qdev-monitor-test$(EXESUF): tests/qdev-monitor-test.o $(libqos-pc-obj-y) tests/nvme-test$(EXESUF): tests/nvme-test.o tests/pvpanic-test$(EXESUF): tests/pvpanic-test.o
tests/blockdev-test.c deleted +0 -59
59 lines not on this page · raw message
tests/drive_del-test.c renamed from tests/qdev-monitor-test.c +45 -12
78 lines not on this page · raw message
Signature · 1 line
1.9.3
PATCH 3/6 blockdev-test: Clean up bogus drive_add argument
In reply to Markus ArmbrusterThe first argument should be a PCI address, which pci-addr=auto isn't. Doesn't really matter, as drive_add ignores its first argument when its second argument has if=none. Clean it up anyway.
--- tests/drive_del-test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tests/drive_del-test.c +1 -1
@@ -83,7 +83,7 @@ static void test_after_failed_device_add(void)*/ response =qmp ("{'execute': 'human-monitor-command'," " 'arguments': {" -" 'command-line': 'drive_add pci-addr=auto if=none,id=drive0'" +" 'command-line': 'drive_add 0 if=none,id=drive0'" "}}" );g_assert (response); g_assert_cmpstr(qdict_get_try_str(response, "return"), ==, "OK\r\n");
Signature · 1 line
1.9.3
Re: [Qemu-devel] [PATCH 2/6] blockdev-test: Use single rather than double quotes in QMP
In reply to Markus ArmbrusterQuoted 3 lines · Markus Armbruster
QMP accepts both single and double quotes. This is the only test using double quotes. They need to be quoted in C strings. Replace them by single quotes.
Ooh, the use of single quotes on input is undocumented, and a violation of JSON. We always output double quotes, and I've been relying on .json/.hx files using single quotes for QAPI vs. double quotes for QMP examples. What would break if we tightened up our input parser to forbid non-JSON inputs and mandate that QMP use double quotes, bringing us into compliance with our docs (docs/qmp/README)?
Quoted 5 lines
Signed-off-by Markus Armbruster <[email protected]>--- tests/drive_del-test.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-)
If we WANT to keep undocumented support for single quotes (and/or document our extension to JSON), then this is fine; otherwise, I'd prefer that we use double quotes in QMP.
But if we decide single quotes are tolerable,
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 3/6] blockdev-test: Clean up bogus drive_add argument
In reply to Markus ArmbrusterQuoted 8 lines · Markus Armbruster
The first argument should be a PCI address, which pci-addr=auto isn't. Doesn't really matter, as
drive_addignores its first argument when its second argument has if=none. Clean it up anyway.Signed-off-by Markus Armbruster <[email protected]>--- tests/drive_del-test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 1/6] drive_del-test: Merge of qdev-monitor-test, blockdev-test
In reply to Markus ArmbrusterQuoted 11 lines · Markus Armbruster
Each of qdev-monitor-test and blockdev-test has just one test case, and both are about
drive_del.Signed-off-by Markus Armbruster <[email protected]>--- tests/Makefile | 5 +-- tests/blockdev-test.c | 59 ------------------------- tests/{qdev-monitor-test.c => drive_del-test.c} | 57 +++++++++++++++++++----- 3 files changed, 47 insertions(+), 74 deletions(-) delete mode 100644 tests/blockdev-test.c rename tests/{qdev-monitor-test.c => drive_del-test.c} (56%)
tests/drive_del-test.c line 4
Quoted 8 lines
tests/drive_del-test.c renamed from tests/qdev-monitor-test.c +1
-1@@ -1,5 +1,5 @@/* -* qdev-monitor.c test cases +* blockdev.c test cases * * Copyright (C) 2013 Red Hat Inc.
Worth bumping this to include 2014 while at it?
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 4/6] blockdev-test: Simplify by using g_assert_cmpstr()
In reply to Markus ArmbrusterQuoted 4 lines · Markus Armbruster
Signed-off-by Markus Armbruster <[email protected]>--- tests/drive_del-test.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 5/6] blockdev-test: Factor out some common code into helpers
In reply to Markus ArmbrusterQuoted 11 lines · Markus Armbruster
Signed-off-by Markus Armbruster <[email protected]>--- tests/drive_del-test.c | 60 +++++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 30 deletions(-)tests/drive_del-test.c +0
-0@@ -14,32 +14,44 @@#include <string.h>
tests/drive_del-test.c line 24
Quoted 10 lines
tests/drive_del-test.c +8
-0#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'" +"}}" );
I'm still not necessarily a fan of '' in QMP, but this follows existing practice.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 6/6] blockdev-test: Test device_del after drive_del
In reply to Markus Armbrustertests/drive_del-test.c static void drive_del(void) · line 48
Quoted 12 lines · Markus Armbruster
Executed in this order,
drive_deland device_del's automatic drive deletion take notoriously tricky special paths.Signed-off-by Markus Armbruster <[email protected]>--- tests/drive_del-test.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)tests/drive_del-test.c +2
-0+/* Complication: ignore DEVICE_DELETED event */ + qmp_discard_response("{'execute': 'device_del',"
Still not a fan of single quotes in QMP, but it's existing style.
tests/drive_del-test.c static void test_after_failed_device_add(void) · line 105
Quoted 3 lines
tests/drive_del-test.c +3
-0+static void test_drive_del_device_del (void ) +{ +/* Start with a drive used by an device that unplugs instantaneously */
s/an device/a device/
New tests are always good; with the typo fix:
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 1/6] drive_del-test: Merge of qdev-monitor-test, blockdev-test
In reply to Eric BlakeQuoted 16 lines · Eric Blake
Quoted 11 lines · Markus Armbruster
Each of qdev-monitor-test and blockdev-test has just one test case, and both are about
drive_del.Signed-off-by Markus Armbruster <[email protected]>--- tests/Makefile | 5 +-- tests/blockdev-test.c | 59 ------------------------- tests/{qdev-monitor-test.c => drive_del-test.c} | 57 +++++++++++++++++++----- 3 files changed, 47 insertions(+), 74 deletions(-) delete mode 100644 tests/blockdev-test.c rename tests/{qdev-monitor-test.c => drive_del-test.c} (56%)Reviewed-by Eric Blake <[email protected]>
Quoted 10 lines
tests/drive_del-test.c line 4
Quoted 8 lines
tests/drive_del-test.c renamed from tests/qdev-monitor-test.c +1
-1@@ -1,5 +1,5 @@/* -* qdev-monitor.c test cases +* blockdev.c test cases * * Copyright (C) 2013 Red Hat Inc. Worth bumping this to include 2014 while at it?
Sure, if I have to respin anyway.
Thanks!
Re: [Qemu-devel] [PATCH 2/6] blockdev-test: Use single rather than double quotes in QMP
In reply to Eric BlakeQuoted 11 lines · Eric Blake
Quoted 3 lines · Markus Armbruster
QMP accepts both single and double quotes. This is the only test using double quotes. They need to be quoted in C strings. Replace them by single quotes.
Ooh, the use of single quotes on input is undocumented, and a violation of JSON. We always output double quotes, and I've been relying on .json/.hx files using single quotes for QAPI vs. double quotes for QMP examples. What would break if we tightened up our input parser to forbid non-JSON inputs and mandate that QMP use double quotes, bringing us into compliance with our docs (docs/qmp/README)?
A whole bunch of tests. Easily fixable.
No telling what out-of-tree stuff breaks. Maybe even nothing.
Perhaps Anthony (cc'ed) can advise.
Quoted 5 lines
Quoted 4 lines
Signed-off-by Markus Armbruster <[email protected]>--- tests/drive_del-test.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-)
Quoted 7 lines
If we WANT to keep undocumented support for single quotes (and/or document our extension to JSON), then this is fine; otherwise, I'd prefer that we use double quotes in QMP.
But if we decide single quotes are tolerable,
Reviewed-by Eric Blake <[email protected]>
Thanks!
Re: [Qemu-devel] [PATCH 6/6] blockdev-test: Test device_del after drive_del
In reply to Eric BlakeQuoted 17 lines · Eric Blake
tests/drive_del-test.c static void drive_del(void) · line 48
Quoted 12 lines · Markus Armbruster
Executed in this order,
drive_deland device_del's automatic drive deletion take notoriously tricky special paths.Signed-off-by Markus Armbruster <[email protected]>--- tests/drive_del-test.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)tests/drive_del-test.c +2
-0+/* Complication: ignore DEVICE_DELETED event */ + qmp_discard_response("{'execute': 'device_del',"Still not a fan of single quotes in QMP, but it's existing style.
Quoted 8 lines
tests/drive_del-test.c static void test_after_failed_device_add(void) · line 105
Quoted 3 lines
tests/drive_del-test.c +3
-0+static void test_drive_del_device_del (void ) +{ +/* Start with a drive used by an device that unplugs instantaneously */ s/an device/a device/
New tests are always good; with the typo fix:
Reviewed-by Eric Blake <[email protected]>
I'll get that fixed, either on commit, or via respin. Thanks!
Stefan Hajnoczi
AppliedQuoted 10 lines · Markus Armbruster
The meat is in the last patch, the others are just cleanup.
Markus Armbruster (6):
drive_del-test: Merge of qdev-monitor-test, blockdev-test
blockdev-test: Use single rather than double quotes in QMP
blockdev-test: Clean up bogusdrive_addargument
blockdev-test: Simplify by usingg_assert_cmpstr()
blockdev-test: Factor out some common code into helpers
blockdev-test: Testdevice_delafterdrive_del
Quoted 8 lines
tests/Makefile | 5 +- tests/blockdev-test.c | 59 -------------------- tests/drive_del-test.c | 137 ++++++++++++++++++++++++++++++++++++++++++++++ tests/qdev-monitor-test.c | 77 -------------------------- 4 files changed, 139 insertions(+), 139 deletions(-) delete mode 100644 tests/blockdev-test.c create mode 100644 tests/drive_del-test.c delete mode 100644 tests/qdev-monitor-test.c
I made the copyright year and typo fixups when applying the patches.
Thanks, applied to my block tree:
https://github.com/stefanha/qemu/commits/block
Stefan