ahci: rerror/werror=stop resume tests
cover ahci: rerror/werror=stop resume tests
This series requires, in order:
ahci-preliminary-refactor (stefanha/block)
ahci-dma-test (stefanha/block)
[PATCH v4 00/17] ide: rerror/werror migration fixes for IDE/ISA and AHCI [PATCH 0/8] ahci: add more IO tests
This patchset brings us up to feature parity with the ide-test that was checked in for the rerror/werror migration fixes series.
With the expanded functionality of libqos, we test error injection and error recovery for the AHCI device.
John Snow (6):
qtest/ahci: Add simple flush test qtest/ahci: Allow override of default CLI options
libqtest: add qmp_eventwait
libqtest: add qmp_async
libqos: add blkdebug_prepare_script qtest/ahci: add flush retry test
tests/ahci-test.c | 143 ++++++++++++++++++++++++++++++++++++++++------- tests/ide-test.c | 34 +---------- tests/libqos/libqos-pc.c | 5 ++ tests/libqos/libqos-pc.h | 1 + tests/libqos/libqos.c | 22 ++++++++ tests/libqos/libqos.h | 1 + tests/libqtest.c | 46 ++++++++++++++- tests/libqtest.h | 47 ++++++++++++++++ 8 files changed, 245 insertions(+), 54 deletions(-)
Signature · 1 line
1.9.3
PATCH 1/6 qtest/ahci: Add simple flush test
--- tests/ahci-test.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+)
tests/ahci-test.c +34 -0
@@ -774,6 +774,29 @@ static void ahci_test_io_rw_simple(AHCIQState *ahci, unsigned bufsize,g_free (rx); } +static void ahci_test_nondata (AHCIQState *ahci,uint8_t ide_cmd) +{ +uint8_t px; +AHCICommand *cmd; + +/* Sanitize */ + px =ahci_port_select (ahci); +ahci_port_clear (ahci, px); + +/* Issue Command */ + cmd =ahci_command_create (ide_cmd); +ahci_command_commit (ahci, cmd, px); +ahci_command_issue (ahci, cmd); +ahci_command_verify (ahci, cmd); +ahci_command_free (cmd); +} + +static void ahci_test_flush (AHCIQState *ahci) +{ +ahci_test_nondata (ahci,CMD_FLUSH_CACHE ); +} + +/******************************************************************************/ /* Test Interfaces */ /******************************************************************************/
@@ -911,6 +934,15 @@ static void test_dma_fragmented(void)g_free (tx); } +static void test_flush (void ) +{ +AHCIQState *ahci; + + ahci =ahci_boot_and_enable (); +ahci_test_flush (ahci); +ahci_shutdown (ahci); +} +/******************************************************************************/ /* AHCI I/O Test Matrix Definitions */
@@ -1150,6 +1182,8 @@ int main(int argc, char **argv)qtest_add_func ("/ahci/io/dma/lba28/fragmented" , test_dma_fragmented); +qtest_add_func ("/ahci/flush/simple" , test_flush); + ret =g_test_run ();/* Cleanup */
Signature · 1 line
1.9.3
PATCH 2/6 qtest/ahci: Allow override of default CLI options
In reply to John Snow--- tests/ahci-test.c | 67 ++++++++++++++++++++++++++++++++---------------- tests/libqos/libqos-pc.c | 5 ++++ tests/libqos/libqos-pc.h | 1 + 3 files changed, 51 insertions(+), 22 deletions(-)
tests/ahci-test.c +45 -22
@@ -75,19 +75,12 @@ static void string_bswap16(uint16_t *s, size_t bytes)/** * Start a Q35 machine and bookmark a handle to the AHCI device. */ -static AHCIQState *ahci_boot (void ) +static AHCIQState *ahci_vboot (const char *cli,va_list ap) {AHCIQState *s; -const char *cli; s =g_malloc0 (sizeof (AHCIQState)); - - cli ="-drive if=none,id=drive0,file=%s,cache=writeback,serial=%s" -",format=qcow2" -" -M q35 " -"-device ide-hd,drive=drive0 " -"-global ide-hd.ver=%s" ; - s->parent =qtest_pc_boot (cli, tmp_path,"testdisk" ,"version" ); + s->parent =qtest_pc_vboot (cli, ap);alloc_set_flags (s->parent->alloc,ALLOC_LEAK_ASSERT );/* Verify that we have an AHCI device present. */
@@ -97,12 +90,35 @@ static AHCIQState *ahci_boot(void) }/** +* Start a Q35 machine and bookmark a handle to the AHCI device. +*/ +static AHCIQState *ahci_boot (const char *cli, ...) +{ +AHCIQState *s; +va_list ap; + +if (cli) { +va_start (ap, cli); + s =ahci_vboot (cli, ap); +va_end (ap); + }else { + cli ="-drive if=none,id=drive0,file=%s,cache=writeback,serial=%s" +",format=qcow2" +" -M q35 " +"-device ide-hd,drive=drive0 " +"-global ide-hd.ver=%s" ; + s =ahci_boot (cli, tmp_path,"testdisk" ,"version" ); + } + +return s; +} + +/** * Clean up the PCI device, then terminate the QEMU instance. */ static void ahci_shutdown (AHCIQState *ahci) {QOSState *qs = ahci->parent; -ahci_clean_mem (ahci);free_ahci_device (ahci->dev);g_free (ahci);
@@ -113,10 +129,18 @@ static void ahci_shutdown(AHCIQState *ahci)* Boot and fully enable the HBA device. * @see ahci_boot, ahci_pci_enable and ahci_hba_enable. */ -static AHCIQState *ahci_boot_and_enable (void ) +static AHCIQState *ahci_boot_and_enable (const char *cli, ...) {AHCIQState *ahci; - ahci =ahci_boot (); +va_list ap; + +if (cli) { +va_start (ap, cli); + ahci =ahci_vboot (cli, ap); +va_end (ap); + }else { + ahci =ahci_boot (NULL ); + }ahci_pci_enable (ahci);ahci_hba_enable (ahci);
@@ -807,7 +831,7 @@ static void ahci_test_flush(AHCIQState *ahci)static void test_sanity (void ) {AHCIQState *ahci; - ahci =ahci_boot (); + ahci =ahci_boot (NULL );ahci_shutdown (ahci); }
@@ -818,7 +842,7 @@ static void test_sanity(void)static void test_pci_spec (void ) {AHCIQState *ahci; - ahci =ahci_boot (); + ahci =ahci_boot (NULL );ahci_test_pci_spec (ahci);ahci_shutdown (ahci); }
@@ -830,8 +854,7 @@ static void test_pci_spec(void)static void test_pci_enable (void ) {AHCIQState *ahci; - - ahci =ahci_boot (); + ahci =ahci_boot (NULL );ahci_pci_enable (ahci);ahci_shutdown (ahci); }
@@ -844,7 +867,7 @@ static void test_hba_spec(void) {AHCIQState *ahci; - ahci =ahci_boot (); + ahci =ahci_boot (NULL );ahci_pci_enable (ahci);ahci_test_hba_spec (ahci);ahci_shutdown (ahci);
@@ -858,7 +881,7 @@ static void test_hba_enable(void) {AHCIQState *ahci; - ahci =ahci_boot (); + ahci =ahci_boot (NULL );ahci_pci_enable (ahci);ahci_hba_enable (ahci);ahci_shutdown (ahci);
@@ -872,7 +895,7 @@ static void test_identify(void) {AHCIQState *ahci; - ahci =ahci_boot_and_enable (); + ahci =ahci_boot_and_enable (NULL );ahci_test_identify (ahci);ahci_shutdown (ahci); }
@@ -894,7 +917,7 @@ static void test_dma_fragmented(void)unsigned i;uint64_t ptr; - ahci =ahci_boot_and_enable (); + ahci =ahci_boot_and_enable (NULL ); px =ahci_port_select (ahci);ahci_port_clear (ahci, px);
@@ -938,7 +961,7 @@ static void test_flush(void) {AHCIQState *ahci; - ahci =ahci_boot_and_enable (); + ahci =ahci_boot_and_enable (NULL );ahci_test_flush (ahci);ahci_shutdown (ahci); }
@@ -1053,7 +1076,7 @@ static void test_io_rw_interface(enum AddrMode lba48, enum IOMode dma, {AHCIQState *ahci; - ahci =ahci_boot_and_enable (); + ahci =ahci_boot_and_enable (NULL );ahci_test_io_rw_simple (ahci, bufsize, sector, io_cmds[dma][lba48][IO_READ ], io_cmds[dma][lba48][IO_WRITE ]);
tests/libqos/libqos-pc.c +5 -0
@@ -6,6 +6,11 @@ static QOSOps qos_ops = { .uninit_allocator = pc_alloc_uninit }; +QOSState *qtest_pc_vboot (const char *cmdline_fmt,va_list ap) +{ +return qtest_vboot (&qos_ops, cmdline_fmt, ap); +} +QOSState *qtest_pc_boot (const char *cmdline_fmt, ...) {QOSState *qs;
tests/libqos/libqos-pc.h +1 -0
@@ -3,6 +3,7 @@#include "libqos/libqos.h" +QOSState *qtest_pc_vboot (const char *cmdline_fmt,va_list ap);QOSState *qtest_pc_boot (const char *cmdline_fmt, ...);void qtest_pc_shutdown (QOSState *qs);
Signature · 1 line
1.9.3
PATCH 3/6 libqtest: add qmp_eventwait
In reply to John SnowAllow the user to poll until a desired interrupt occurs.
--- tests/ide-test.c | 11 +---------- tests/libqtest.c | 16 ++++++++++++++++ tests/libqtest.h | 20 ++++++++++++++++++++ 3 files changed, 37 insertions(+), 10 deletions(-)
tests/ide-test.c +1 -10
@@ -520,7 +520,6 @@ static void test_retry_flush(const char *machine) {uint8_t data;const char *s; -QDict *response;prepare_blkdebug_script (debug_path,"flush_to_disk" );
@@ -539,15 +538,7 @@ static void test_retry_flush(const char *machine)assert_bit_set (data,BSY |DRDY );assert_bit_clear (data,DF |ERR |DRQ ); -for (;; response =NULL ) { - response =qmp_receive (); -if ((qdict_haskey (response,"event" )) && - (strcmp (qdict_get_str (response,"event" ),"STOP" ) ==0 )) { -QDECREF (response); -break ; - } -QDECREF (response); - } +qmp_eventwait ("STOP" );/* Complete the command */ s ="{'execute':'cont' }" ;
tests/libqtest.c +16 -0
@@ -450,6 +450,22 @@ void qtest_qmp_discard_response(QTestState *s, const char *fmt, ...)QDECREF (response); } +void qtest_qmp_eventwait (QTestState *s,const char *event) +{ +QDict *response; + +for (;;) { + response =qtest_qmp_receive (s); +if ((qdict_haskey (response,"event" )) && + (strcmp (qdict_get_str (response,"event" ), event) ==0 )) { +QDECREF (response); +break ; + } +QDECREF (response); + } +} + +const char *qtest_get_arch (void ) {const char *qemu =getenv ("QTEST_QEMU_BINARY" );
tests/libqtest.h +20 -0
@@ -92,6 +92,15 @@ QDict *qtest_qmpv(QTestState *s, const char *fmt, va_list ap);QDict *qtest_qmp_receive (QTestState *s);/** +* qtest_qmp_eventwait: +* @s: #QTestState instance to operate on. +* @s: #event event to wait for. +* +* Continuosly polls for QMP responses until it receives the desired event. +*/ +void qtest_qmp_eventwait (QTestState *s,const char *event); + +/** * qtest_get_irq: * @s: #QTestState instance to operate on. * @num: Interrupt to observe.
@@ -397,6 +406,17 @@ static inline QDict *qmp_receive(void) }/** +* qmp_eventwait: +* @s: #event event to wait for. +* +* Continuosly polls for QMP responses until it receives the desired event. +*/ +static inline void qmp_eventwait (const char *event) +{ +return qtest_qmp_eventwait (global_qtest, event); +} + +/** * get_irq: * @num: Interrupt to observe. *
Signature · 1 line
1.9.3
PATCH 4/6 libqtest: add qmp_async
In reply to John SnowAdd qmp_async, which lets us send QMP commands asynchronously. This is useful when we want to send commands that will trigger event responses, but we don't know in what order to expect them.
Sometimes the event responses may arrive even before the command confirmation will show up, so it is convenient to leave the responses in the stream.
--- tests/libqtest.c | 30 +++++++++++++++++++++++++++++- tests/libqtest.h | 27 +++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-)
tests/libqtest.c +29 -1
@@ -388,7 +388,12 @@ QDict *qtest_qmp_receive(QTestState *s)return qmp.response; } -QDict *qtest_qmpv (QTestState *s,const char *fmt,va_list ap) +/** +* Allow users to send a message without waiting for the reply, +* in the case that they choose to discard all replies up until +* a particular EVENT is received. +*/ +void qtest_async_qmpv (QTestState *s,const char *fmt,va_list ap) {va_list ap_copy;QObject *qobj;
@@ -417,6 +422,11 @@ QDict *qtest_qmpv(QTestState *s, const char *fmt, va_list ap)QDECREF (qstr);qobject_decref (qobj); } +} + +QDict *qtest_qmpv (QTestState *s,const char *fmt,va_list ap) +{ +qtest_async_qmpv (s, fmt, ap);/* Receive reply */ return qtest_qmp_receive (s);
@@ -433,6 +443,15 @@ QDict *qtest_qmp(QTestState *s, const char *fmt, ...)return response; } +void qtest_async_qmp (QTestState *s,const char *fmt, ...) +{ +va_list ap; + +va_start (ap, fmt); +qtest_async_qmpv (s, fmt, ap); +va_end (ap); +} +void qtest_qmpv_discard_response (QTestState *s,const char *fmt,va_list ap) {QDict *response =qtest_qmpv (s, fmt, ap);
@@ -704,6 +723,15 @@ QDict *qmp(const char *fmt, ...)return response; } +void qmp_async (const char *fmt, ...) +{ +va_list ap; + +va_start (ap, fmt); +qtest_async_qmpv (global_qtest, fmt, ap); +va_end (ap); +} +void qmp_discard_response (const char *fmt, ...) {va_list ap;
tests/libqtest.h +27 -0
@@ -64,6 +64,15 @@ void qtest_qmp_discard_response(QTestState *s, const char *fmt, ...);QDict *qtest_qmp (QTestState *s,const char *fmt, ...);/** +* qtest_async_qmp: +* @s: #QTestState instance to operate on. +* @fmt...: QMP message to send to qemu +* +* Sends a QMP message to QEMU and leaves the response in the stream. +*/ +void qtest_async_qmp (QTestState *s,const char *fmt, ...); + +/** * qtest_qmpv_discard_response: * @s: #QTestState instance to operate on. * @fmt: QMP message to send to QEMU
@@ -84,6 +93,16 @@ void qtest_qmpv_discard_response(QTestState *s, const char *fmt, va_list ap);QDict *qtest_qmpv (QTestState *s,const char *fmt,va_list ap);/** +* qtest_async_qmpv: +* @s: #QTestState instance to operate on. +* @fmt: QMP message to send to QEMU +* @ap: QMP message arguments +* +* Sends a QMP message to QEMU and leaves the response in the stream. +*/ +void qtest_async_qmpv (QTestState *s,const char *fmt,va_list ap); + +/** * qtest_receive: * @s: #QTestState instance to operate on. *
@@ -388,6 +407,14 @@ static inline void qtest_end(void)QDict *qmp (const char *fmt, ...);/** +* qmp_async: +* @fmt...: QMP message to send to qemu +* +* Sends a QMP message to QEMU and leaves the response in the stream. +*/ +void qmp_async (const char *fmt, ...); + +/** * qmp_discard_response: * @fmt...: QMP message to send to qemu *
Signature · 1 line
1.9.3
PATCH 5/6 libqos: add blkdebug_prepare_script
In reply to John SnowPull this helper out of ide-test and into libqos,
to be shared with ahci-test.
--- tests/ide-test.c | 23 +---------------------- tests/libqos/libqos.c | 22 ++++++++++++++++++++++ tests/libqos/libqos.h | 1 + 3 files changed, 24 insertions(+), 22 deletions(-)
tests/ide-test.c +1 -22
@@ -29,6 +29,7 @@#include <glib.h> #include "libqtest.h" +#include "libqos/libqos.h" #include "libqos/pci-pc.h" #include "libqos/malloc-pc.h"
@@ -494,28 +495,6 @@ static void test_flush(void)ide_test_quit (); } -static void prepare_blkdebug_script (const char *debug_fn,const char *event) -{ -FILE *debug_file =fopen (debug_fn,"w" ); -int ret; - -fprintf (debug_file,"[inject-error]\n" ); -fprintf (debug_file,"event = \"%s\"\n" , event); -fprintf (debug_file,"errno = \"5\"\n" ); -fprintf (debug_file,"state = \"1\"\n" ); -fprintf (debug_file,"immediately = \"off\"\n" ); -fprintf (debug_file,"once = \"on\"\n" ); - -fprintf (debug_file,"[set-state]\n" ); -fprintf (debug_file,"event = \"%s\"\n" , event); -fprintf (debug_file,"new_state = \"2\"\n" ); -fflush (debug_file); -g_assert (!ferror (debug_file)); - - ret =fclose (debug_file); -g_assert (ret ==0 ); -} -static void test_retry_flush (const char *machine) {uint8_t data;
tests/libqos/libqos.c +22 -0
@@ -91,3 +91,25 @@ int mkqcow2(const char *file, unsigned size_mb)g_assert_not_reached (); } + +void prepare_blkdebug_script (const char *debug_fn,const char *event) +{ +FILE *debug_file =fopen (debug_fn,"w" ); +int ret; + +fprintf (debug_file,"[inject-error]\n" ); +fprintf (debug_file,"event = \"%s\"\n" , event); +fprintf (debug_file,"errno = \"5\"\n" ); +fprintf (debug_file,"state = \"1\"\n" ); +fprintf (debug_file,"immediately = \"off\"\n" ); +fprintf (debug_file,"once = \"on\"\n" ); + +fprintf (debug_file,"[set-state]\n" ); +fprintf (debug_file,"event = \"%s\"\n" , event); +fprintf (debug_file,"new_state = \"2\"\n" ); +fflush (debug_file); +g_assert (!ferror (debug_file)); + + ret =fclose (debug_file); +g_assert (ret ==0 ); +}
tests/libqos/libqos.h +1 -0
@@ -20,6 +20,7 @@ QOSState *qtest_vboot(QOSOps *ops, const char *cmdline_fmt, va_list ap);QOSState *qtest_boot (QOSOps *ops,const char *cmdline_fmt, ...);void qtest_shutdown (QOSState *qs);int mkqcow2 (const char *file,unsigned size_mb); +void prepare_blkdebug_script (const char *debug_fn,const char *event);static inline uint64_t qmalloc (QOSState *q,size_t bytes) {
Signature · 1 line
1.9.3
PATCH 6/6 qtest/ahci: add flush retry test
In reply to John Snow--- tests/ahci-test.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+)
tests/ahci-test.c +44 -0
@@ -46,6 +46,7 @@/*** Globals ***/ static char tmp_path[] ="/tmp/qtest.XXXXXX" ; +static char debug_path[] ="/tmp/qtest-blkdebug.XXXXXX" ;static bool ahci_pedantic;/*** Function Declarations ***/
@@ -966,6 +967,41 @@ static void test_flush(void)ahci_shutdown (ahci); } +static void test_flush_retry (void ) +{ +AHCIQState *ahci; +AHCICommand *cmd; +uint8_t port; +const char *s; + +prepare_blkdebug_script (debug_path,"flush_to_disk" ); + ahci =ahci_boot_and_enable ("-drive file=blkdebug:%s:%s,if=none,id=drive0," +"format=qcow2,cache=writeback," +"rerror=stop,werror=stop " +"-M q35 " +"-device ide-hd,drive=drive0 " , + debug_path, + tmp_path); + +/* Issue Flush Command */ + port =ahci_port_select (ahci); +ahci_port_clear (ahci, port); + cmd =ahci_command_create (CMD_FLUSH_CACHE ); +ahci_command_commit (ahci, cmd, port); +ahci_command_issue_async (ahci, cmd); +qmp_eventwait ("STOP" ); + +/* Complete the command */ + s ="{'execute':'cont' }" ; +qmp_async (s); +qmp_eventwait ("RESUME" ); +ahci_command_wait (ahci, cmd); +ahci_command_verify (ahci, cmd); + +ahci_command_free (cmd); +ahci_shutdown (ahci); +} +/******************************************************************************/ /* AHCI I/O Test Matrix Definitions */
@@ -1147,6 +1183,7 @@ int main(int argc, char **argv) {const char *arch;int ret; +int fd;int c;int i, j, k, m;
@@ -1185,6 +1222,11 @@ int main(int argc, char **argv)/* Create a temporary qcow2 image */ mkqcow2 (tmp_path,TEST_IMAGE_SIZE_MB ); +/* Create temporary blkdebug instructions */ + fd =mkstemp (debug_path); +g_assert (fd >=0 ); +close (fd); +/* Run the tests */ qtest_add_func ("/ahci/sanity" , test_sanity);qtest_add_func ("/ahci/pci_spec" , test_pci_spec);
@@ -1206,11 +1248,13 @@ int main(int argc, char **argv)qtest_add_func ("/ahci/io/dma/lba28/fragmented" , test_dma_fragmented);qtest_add_func ("/ahci/flush/simple" , test_flush); +qtest_add_func ("/ahci/flush/retry" , test_flush_retry); ret =g_test_run ();/* Cleanup */ unlink (tmp_path); +unlink (debug_path);return ret; }
Signature · 1 line
1.9.3
Quoted 4 lines · John Snow
This series requires, in order:
ahci-preliminary-refactor (stefanha/block)
ahci-dma-test (stefanha/block)
Update 2015-02-24: You can base off of master; but you still need the patches below:
Quoted 27 lines
[PATCH v4 00/17] ide: rerror/werror migration fixes for IDE/ISA and AHCI [PATCH 0/8] ahci: add more IO tests
This patchset brings us up to feature parity with the ide-test that was checked in for the rerror/werror migration fixes series.
With the expanded functionality of libqos, we test error injection and error recovery for the AHCI device.
John Snow (6):
qtest/ahci: Add simple flush test qtest/ahci: Allow override of default CLI options
libqtest: addqmp_eventwait
libqtest: addqmp_async
libqos: addblkdebug_prepare_scriptqtest/ahci: add flush retry testtests/ahci-test.c | 143 ++++++++++++++++++++++++++++++++++++++++------- tests/ide-test.c | 34 +---------- tests/libqos/libqos-pc.c | 5 ++ tests/libqos/libqos-pc.h | 1 + tests/libqos/libqos.c | 22 ++++++++ tests/libqos/libqos.h | 1 + tests/libqtest.c | 46 ++++++++++++++- tests/libqtest.h | 47 ++++++++++++++++ 8 files changed, 245 insertions(+), 54 deletions(-)
Signature · 1 line
—js
Stefan Hajnoczi
AppliedQuoted 21 lines · John Snow
This series requires, in order:
ahci-preliminary-refactor (stefanha/block)
ahci-dma-test (stefanha/block)
[PATCH v4 00/17] ide: rerror/werror migration fixes for IDE/ISA and AHCI [PATCH 0/8] ahci: add more IO testsThis patchset brings us up to feature parity with the ide-test that was checked in for the rerror/werror migration fixes series.
With the expanded functionality of libqos, we test error injection and error recovery for the AHCI device.
John Snow (6):
qtest/ahci: Add simple flush test qtest/ahci: Allow override of default CLI options
libqtest: addqmp_eventwait
libqtest: addqmp_async
libqos: addblkdebug_prepare_scriptqtest/ahci: add flush retry test
Quoted 9 lines
tests/ahci-test.c | 143 ++++++++++++++++++++++++++++++++++++++++------- tests/ide-test.c | 34 +---------- tests/libqos/libqos-pc.c | 5 ++ tests/libqos/libqos-pc.h | 1 + tests/libqos/libqos.c | 22 ++++++++ tests/libqos/libqos.h | 1 + tests/libqtest.c | 46 ++++++++++++++- tests/libqtest.h | 47 ++++++++++++++++ 8 files changed, 245 insertions(+), 54 deletions(-)
Thanks, applied to my block tree:
https://github.com/stefanha/qemu/commits/block
Stefan