From: Christian Quante <[email protected]> Since commit 9c4c09d2a663 ("hw/block/fdc: account for read and write requests"), the floppy reports its reads and writes in query-blockstats. Check this for the existing non-DMA reads: send_read_no_dma_command() now compares rd_operations and rd_bytes before and after the command, one 512-byte request for every sector the test reads through the FIFO.
Without the accounting, read_no_dma_1, read_no_dma_18 and read_no_dma_19 fail with rd_operations at 0 instead of 2, 36 and 38. Suggested-by: Kevin Wolf <[email protected]> Signed-off-by: Christian Quante <[email protected]> Message-ID: <[email protected]> Reviewed-by: Kevin Wolf <[email protected]> Tested-by: Kevin Wolf <[email protected]> Signed-off-by: Kevin Wolf <[email protected]> --- tests/qtest/fdc-test.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/tests/qtest/fdc-test.c b/tests/qtest/fdc-test.c index 33d1b83aebc..a10951f204d 100644 --- a/tests/qtest/fdc-test.c +++ b/tests/qtest/fdc-test.c @@ -27,6 +27,7 @@ #include "libqtest-single.h" #include "qobject/qdict.h" +#include "qobject/qlist.h" #define DRIVE_FLOPPY_BLANK \ "-drive if=floppy,file=null-co://,file.read-zeroes=on,format=raw,size=1440k" @@ -177,6 +178,34 @@ static uint8_t send_read_command(uint8_t cmd) return ret; } +/* Returns a counter that query-blockstats reports for floppy0 */ +static int64_t floppy_blockstat(const char *counter) +{ + QDict *response; + QList *list; + QListEntry *entry; + QDict *stats = NULL; + int64_t value; + + response = qtest_qmp(global_qtest, "{'execute': 'query-blockstats'}"); + g_assert(response && qdict_haskey(response, "return")); + list = qdict_get_qlist(response, "return"); + + QLIST_FOREACH_ENTRY(list, entry) { + QDict *entry_dict = qobject_to(QDict, entry->value); + + if (!g_strcmp0(qdict_get_try_str(entry_dict, "qdev"), "floppy0")) { + stats = qdict_get_qdict(entry_dict, "stats"); + break; + } + } + + g_assert(stats); + value = qdict_get_int(stats, counter); + qobject_unref(response); + return value; +} + static uint8_t send_read_no_dma_command(int nb_sect, uint8_t expected_st0) { uint8_t drive = 0; @@ -193,6 +222,9 @@ static uint8_t send_read_no_dma_command(int nb_sect, uint8_t expected_st0) uint8_t ret = 0; + int64_t rd_ops_before = floppy_blockstat("rd_operations"); + int64_t rd_bytes_before = floppy_blockstat("rd_bytes"); + floppy_send(CMD_READ); floppy_send(head << 2 | drive); g_assert(!get_irq(FLOPPY_IRQ)); @@ -248,6 +280,16 @@ static uint8_t send_read_no_dma_command(int nb_sect, uint8_t expected_st0) assert_bit_set(msr, RQM); g_assert(!get_irq(FLOPPY_IRQ)); + /* + * The non-DMA loop above has read 2 * nb_sect sectors through the FIFO, + * and the controller fetches each of them from the image with a request + * of its own. + */ + g_assert_cmpint(floppy_blockstat("rd_operations") - rd_ops_before, ==, + 2 * nb_sect); + g_assert_cmpint(floppy_blockstat("rd_bytes") - rd_bytes_before, ==, + 512 * 2 * nb_sect); + return ret; } -- 2.56.0
