All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tests/qtest/fdc-test: check block accounting of non-DMA reads
@ 2026-10-11  8:14 Christian Quante
  2026-10-12 10:52 ` Kevin Wolf
  0 siblings, 1 reply; 2+ messages in thread
From: Christian Quante @ 2026-10-11  8:14 UTC (permalink / raw)
  To: Kevin Wolf
  Cc: John Snow, Fabiano Rosas, Laurent Vivier, Paolo Bonzini,
	qemu-block, qemu-devel

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 <kwolf@redhat.com>
Signed-off-by: Christian Quante <christian@quante.one>
---
 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 33d1b83aeb..a10951f204 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.53.0



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] tests/qtest/fdc-test: check block accounting of non-DMA reads
  2026-10-11  8:14 [PATCH] tests/qtest/fdc-test: check block accounting of non-DMA reads Christian Quante
@ 2026-10-12 10:52 ` Kevin Wolf
  0 siblings, 0 replies; 2+ messages in thread
From: Kevin Wolf @ 2026-10-12 10:52 UTC (permalink / raw)
  To: Christian Quante
  Cc: John Snow, Fabiano Rosas, Laurent Vivier, Paolo Bonzini,
	qemu-block, qemu-devel

Am 11.10.2026 um 10:14 hat Christian Quante geschrieben:
> 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 <kwolf@redhat.com>
> Signed-off-by: Christian Quante <christian@quante.one>

Thanks, applied to the block branch.

Kevin



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-10-12 10:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-11  8:14 [PATCH] tests/qtest/fdc-test: check block accounting of non-DMA reads Christian Quante
2026-10-12 10:52 ` Kevin Wolf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.