On 30/4/25 15:28, Thomas Huth wrote:
From: Thomas Huth <th...@redhat.com>

The logic in the qvirtio_read/write function is rather a headache,
involving byte-swapping when the target is big endian, just to
maybe involve another byte-swapping  in the qtest_read/write
function immediately afterwards (on the QEMU side). Let's do it in
a more obvious way here: For virtio 1.0, we know that the values have
to be little endian, so let's read/write the bytes in that well known
order here.

Signed-off-by: Thomas Huth <th...@redhat.com>
---
  This also decreases our usage of qtest_big_endian() which might (or
  might not) get helpful for the universal binary one day...

  v2: Use leXX_to_cpu() / cpu_to_leXX() instead of doing it manually

  tests/qtest/libqos/virtio.c | 44 ++++++++++++++++++++++++-------------
  1 file changed, 29 insertions(+), 15 deletions(-)

Thanks!

Reviewed-by: Philippe Mathieu-Daudé <phi...@linaro.org>

I tried this on top:

-- >8 --
diff --git a/tests/qtest/libqtest.h b/tests/qtest/libqtest.h
index 930a91dcb7d..5e01c1effc7 100644
--- a/tests/qtest/libqtest.h
+++ b/tests/qtest/libqtest.h
@@ -731,8 +730,0 @@ int64_t qtest_clock_set(QTestState *s, int64_t val);
-/**
- * qtest_big_endian:
- * @s: QTestState instance to operate on.
- *
- * Returns: True if the architecture under test has a big endian configuration.
- */
-bool qtest_big_endian(QTestState *s);
-
diff --git a/tests/qtest/libqos/virtio-pci.c b/tests/qtest/libqos/virtio-pci.c
index 002bf8b8c2d..98b35ceb9e3 100644
--- a/tests/qtest/libqos/virtio-pci.c
+++ b/tests/qtest/libqos/virtio-pci.c
@@ -389,0 +390,20 @@ void qvirtio_pci_start_hw(QOSGraphObject *obj)
+/**
+ * qvirtio_pci_query_legacy_endianness:
+ * @s: QTestState instance to operate on.
+ *
+ * Returns: True if the architecture under test has a big endian configuration.
+ */
+static int qvirtio_pci_query_legacy_endianness(QTestState *s)
+{
+    gchar **args;
+    int big_endian;
+
+    qtest_sendf(s, "endianness\n");
+    args = qtest_rsp_args(s, 1);
+ g_assert(strcmp(args[1], "big") == 0 || strcmp(args[1], "little") == 0);
+    big_endian = strcmp(args[1], "big") == 0;
+    g_strfreev(args);
+
+    return big_endian;
+}
+
@@ -391,0 +412,2 @@ static void qvirtio_pci_init_legacy(QVirtioPCIDevice *dev) + bool big_endian = qvirtio_pci_query_legacy_endianness(dev->pdev->bus->qts);
+
@@ -396 +418 @@ static void qvirtio_pci_init_legacy(QVirtioPCIDevice *dev)
-    dev->vdev.big_endian = qtest_big_endian(dev->pdev->bus->qts);
+    dev->vdev.big_endian = big_endian;
diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
index 358580361d3..4a29a8fd750 100644
--- a/tests/qtest/libqtest.c
+++ b/tests/qtest/libqtest.c
@@ -87 +86,0 @@ struct QTestState
-    bool big_endian;
@@ -552,2 +550,0 @@ void qtest_connect(QTestState *s)
-    /* ask endianness of the target */
-    s->big_endian = qtest_query_target_endianness(s);
@@ -779,14 +775,0 @@ static void qtest_rsp(QTestState *s)
-static int qtest_query_target_endianness(QTestState *s)
-{
-    gchar **args;
-    int big_endian;
-
-    qtest_sendf(s, "endianness\n");
-    args = qtest_rsp_args(s, 1);
- g_assert(strcmp(args[1], "big") == 0 || strcmp(args[1], "little") == 0);
-    big_endian = strcmp(args[1], "big") == 0;
-    g_strfreev(args);
-
-    return big_endian;
-}
-
@@ -1561,5 +1543,0 @@ void qtest_qmp_fds_assert_success(QTestState *qts, int *fds, size_t nfds,
-bool qtest_big_endian(QTestState *s)
-{
-    return s->big_endian;
-}
-
@@ -2000,2 +1977,0 @@ QTestState *qtest_inproc_init(QTestState **s, bool log, const char* arch,
-    qts->big_endian = qtest_query_target_endianness(qts);
-
---

But it doesn't work due to qtest_sendf() and qtest_rsp_args() being
local to tests/qtest/libqtest.c:

../../tests/qtest/libqos/virtio-pci.c:401:5: error: call to undeclared function 'qtest_sendf'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
  401 |     qtest_sendf(s, "endianness\n");
      |     ^
../../tests/qtest/libqos/virtio-pci.c:402:12: error: call to undeclared function 'qtest_rsp_args'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
  402 |     args = qtest_rsp_args(s, 1);
      |            ^


Reply via email to