Hi Tao,

On 15/7/26 18:07, Tao Ding wrote:
Add a standalone qtest for the SDHCI controller on the
xilinx-zynq-a9 machine.

The test covers the SDMA boundary continuation case for a
multi-block read. After the controller stops at a boundary,
software updates SYSAD to continue the transfer. This verifies
the generic SDHCI behavior that previously failed when the
continuation SYSAD write was ignored and the transfer stalled.

Reviewed-by: Bin Meng <[email protected]>
Signed-off-by: Tao Ding <[email protected]>
---
Build:
   mkdir build
   cd build
   ../configure --target-list="arm-softmmu"  --disable-slirp --enable-debug 
--disable-werror
   make -j4

Run:
   QTEST_QEMU_BINARY=./qemu-system-arm \
   tests/qtest/xilinx-zynq-sdhci-test

Before the fix, the test fails with a BLKCNT assertion:
   ERROR:../tests/qtest/xilinx-zynq-sdhci-test.c:90:wait_for_block_count:
   assertion failed (qtest_readw(qts, XILINX_ZYNQ_MMC_BA + SDHC_BLKCNT) == 
expected): (1 == 0)

After applying the fix, the test passes:
   ok 1 /arm/xilinx-zynq-sdhci/sdma/read-boundary-continue

  tests/qtest/meson.build              |   1 +
  tests/qtest/xilinx-zynq-sdhci-test.c | 178 +++++++++++++++++++++++++++
  2 files changed, 179 insertions(+)
  create mode 100644 tests/qtest/xilinx-zynq-sdhci-test.c


+static void write_pattern_to_image(size_t offset, size_t len)
+{
+    int fd;
+    int ret;
+    uint8_t *buf = g_malloc(len);
+
+    for (size_t i = 0; i < len; i++) {
+        buf[i] = (i * 13 + 7) & 0xff;
+    }
+
+    fd = open(sd_path, O_WRONLY);
+    g_assert_cmpint(fd, >=, 0);
+    ret = pwrite(fd, buf, len, offset);
+    close(fd);
+    g_assert_cmpint(ret, ==, len);
+
+    g_free(buf);
+}

pwrite() is POSIX and is not supported on Windows:

../tests/qtest/xilinx-zynq-sdhci-test.c:71:11: error: call to undeclared function 'pwrite'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
   71 |     ret = pwrite(fd, buf, len, offset);
      |           ^

I converted this method to GLib which is much cross-OS:

-- >8 --
diff --git a/tests/qtest/xilinx-zynq-sdhci-test.c b/tests/qtest/xilinx-zynq-sdhci-test.c
index 601b9140834..7957358cf5d 100644
--- a/tests/qtest/xilinx-zynq-sdhci-test.c
+++ b/tests/qtest/xilinx-zynq-sdhci-test.c
@@ -58,19 +58,26 @@ static QTestState *setup_sd_card(void)

 static void write_pattern_to_image(size_t offset, size_t len)
 {
-    int fd;
-    int ret;
-    uint8_t *buf = g_malloc(len);
+    gchar *buf = g_malloc(len);
+    GError *err = NULL;
+    gsize bytes_written;
+    GIOChannel *chan;

     for (size_t i = 0; i < len; i++) {
         buf[i] = (i * 13 + 7) & 0xff;
     }

-    fd = open(sd_path, O_WRONLY);
-    g_assert_cmpint(fd, >=, 0);
-    ret = pwrite(fd, buf, len, offset);
-    close(fd);
-    g_assert_cmpint(ret, ==, len);
+    chan = g_io_channel_new_file(sd_path, "w", &err);
+    g_assert_no_error(err);
+    g_io_channel_set_encoding(chan, NULL, &err);
+    g_assert_no_error(err);
+    g_io_channel_seek_position(chan, offset, G_SEEK_SET, &err);
+    g_assert_no_error(err);
+    g_io_channel_write_chars(chan, buf, len, &bytes_written, &err);
+    g_assert_no_error(err);
+    g_assert_cmpint(bytes_written, ==, len);
+    g_io_channel_shutdown(chan, TRUE, &err);
+    g_assert_no_error(err);

     g_free(buf);
 }
---

Regards,

Phil.

Reply via email to