From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: Thomas Huth <thuth@redhat.com>, Fabiano Rosas <farosas@suse.de>,
qemu-devel@nongnu.org
Cc: Laurent Vivier <lvivier@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Pierrick Bouvier <pierrick.bouvier@linaro.org>
Subject: Re: [PATCH v2] tests/qtest/libqos: Avoid double swapping when using modern virtio
Date: Wed, 30 Apr 2025 15:50:30 +0200 [thread overview]
Message-ID: <d315f4dc-11a6-41a9-9a19-fe96a12b07b8@linaro.org> (raw)
In-Reply-To: <20250430132817.610903-1-thuth@redhat.com>
On 30/4/25 15:28, Thomas Huth wrote:
> From: Thomas Huth <thuth@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 <thuth@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é <philmd@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);
| ^
next prev parent reply other threads:[~2025-04-30 13:51 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-30 13:28 [PATCH v2] tests/qtest/libqos: Avoid double swapping when using modern virtio Thomas Huth
2025-04-30 13:50 ` Philippe Mathieu-Daudé [this message]
2025-04-30 14:31 ` Thomas Huth
2025-04-30 14:54 ` Alex Bennée
2025-05-05 14:55 ` Fabiano Rosas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d315f4dc-11a6-41a9-9a19-fe96a12b07b8@linaro.org \
--to=philmd@linaro.org \
--cc=farosas@suse.de \
--cc=lvivier@redhat.com \
--cc=pbonzini@redhat.com \
--cc=pierrick.bouvier@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=thuth@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).