[PATCH 44/51] tests/qtest: microbit-test: Fix socket access for win32

Bin Meng posted 51 patches 3 years, 5 months ago
Maintainers: "Alex Bennée" <alex.bennee@linaro.org>, "Philippe Mathieu-Daudé" <f4bug@amsat.org>, Thomas Huth <thuth@redhat.com>, Wainer dos Santos Moschetta <wainersm@redhat.com>, Beraldo Leal <bleal@redhat.com>, Laurent Vivier <lvivier@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, Stefan Berger <stefanb@linux.vnet.ibm.com>, Kevin Wolf <kwolf@redhat.com>, Hanna Reitz <hreitz@redhat.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, Greg Kurz <groug@kaod.org>, Christian Schoenebeck <qemu_oss@crudebyte.com>, "Cédric Le Goater" <clg@kaod.org>, Daniel Henrique Barboza <danielhb413@gmail.com>, David Gibson <david@gibson.dropbear.id.au>, Gerd Hoffmann <kraxel@redhat.com>, Eduardo Habkost <eduardo@habkost.net>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, Yanan Wang <wangyanan55@huawei.com>, "Daniel P. Berrangé" <berrange@redhat.com>, Michael Roth <michael.roth@amd.com>, Konstantin Kostiuk <kkostiuk@redhat.com>, Richard Henderson <richard.henderson@linaro.org>, Juan Quintela <quintela@redhat.com>, "Dr. David Alan Gilbert" <dgilbert@redhat.com>, John Snow <jsnow@redhat.com>, Peter Maydell <peter.maydell@linaro.org>, Andrew Jeffery <andrew@aj.id.au>, Joel Stanley <joel@jms.id.au>, "Michael S. Tsirkin" <mst@redhat.com>, Igor Mammedov <imammedo@redhat.com>, Ani Sinha <ani@anisinha.ca>, Alexander Bulekov <alxndr@bu.edu>, Bandan Das <bsd@redhat.com>, Stefan Hajnoczi <stefanha@redhat.com>, Darren Kenny <darren.kenny@oracle.com>, Qiuhao Li <Qiuhao.Li@outlook.com>, Havard Skinnemoen <hskinnemoen@google.com>, Tyrone Ting <kfting@nuvoton.com>, Markus Armbruster <armbru@redhat.com>, Coiby Xu <Coiby.Xu@gmail.com>, Jason Wang <jasowang@redhat.com>, Fam Zheng <fam@euphon.net>
There is a newer version of this series
[PATCH 44/51] tests/qtest: microbit-test: Fix socket access for win32
Posted by Bin Meng 3 years, 5 months ago
From: Bin Meng <bin.meng@windriver.com>

Sockets on Windows do not use *nix-style file descriptors, so
write()/read()/close() do not work on Windows.

Switch over to use send()/recv()/closesocket() which work with
sockets on all platforms.

Signed-off-by: Bin Meng <bin.meng@windriver.com>
---

 tests/qtest/microbit-test.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/tests/qtest/microbit-test.c b/tests/qtest/microbit-test.c
index b71daae9a9..4bc267020b 100644
--- a/tests/qtest/microbit-test.c
+++ b/tests/qtest/microbit-test.c
@@ -51,7 +51,7 @@ static void uart_rw_to_rxd(QTestState *qts, int sock_fd, const char *in,
 {
     int i, in_len = strlen(in);
 
-    g_assert_true(write(sock_fd, in, in_len) == in_len);
+    g_assert_true(send(sock_fd, in, in_len, 0) == in_len);
     for (i = 0; i < in_len; i++) {
         g_assert_true(uart_wait_for_event(qts, NRF51_UART_BASE +
                                                A_UART_RXDRDY));
@@ -77,7 +77,7 @@ static void test_nrf51_uart(void)
     char s[10];
     QTestState *qts = qtest_init_with_serial("-M microbit", &sock_fd);
 
-    g_assert_true(write(sock_fd, "c", 1) == 1);
+    g_assert_true(send(sock_fd, "c", 1, 0) == 1);
     g_assert_cmphex(qtest_readl(qts, NRF51_UART_BASE + A_UART_RXD), ==, 0x00);
 
     qtest_writel(qts, NRF51_UART_BASE + A_UART_ENABLE, 0x04);
@@ -97,17 +97,17 @@ static void test_nrf51_uart(void)
 
     qtest_writel(qts, NRF51_UART_BASE + A_UART_STARTTX, 0x01);
     uart_w_to_txd(qts, "d");
-    g_assert_true(read(sock_fd, s, 10) == 1);
+    g_assert_true(recv(sock_fd, s, 10, 0) == 1);
     g_assert_cmphex(s[0], ==, 'd');
 
     qtest_writel(qts, NRF51_UART_BASE + A_UART_SUSPEND, 0x01);
     qtest_writel(qts, NRF51_UART_BASE + A_UART_TXD, 'h');
     qtest_writel(qts, NRF51_UART_BASE + A_UART_STARTTX, 0x01);
     uart_w_to_txd(qts, "world");
-    g_assert_true(read(sock_fd, s, 10) == 5);
+    g_assert_true(recv(sock_fd, s, 10, 0) == 5);
     g_assert_true(memcmp(s, "world", 5) == 0);
 
-    close(sock_fd);
+    closesocket(sock_fd);
 
     qtest_quit(qts);
 }
-- 
2.34.1
Re: [PATCH 44/51] tests/qtest: microbit-test: Fix socket access for win32
Posted by Marc-André Lureau 3 years, 5 months ago
On Wed, Aug 24, 2022 at 3:27 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Bin Meng <bin.meng@windriver.com>
>
> Sockets on Windows do not use *nix-style file descriptors, so
> write()/read()/close() do not work on Windows.
>
> Switch over to use send()/recv()/closesocket() which work with
> sockets on all platforms.
>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
>

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>


> ---
>
>  tests/qtest/microbit-test.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/tests/qtest/microbit-test.c b/tests/qtest/microbit-test.c
> index b71daae9a9..4bc267020b 100644
> --- a/tests/qtest/microbit-test.c
> +++ b/tests/qtest/microbit-test.c
> @@ -51,7 +51,7 @@ static void uart_rw_to_rxd(QTestState *qts, int sock_fd,
> const char *in,
>  {
>      int i, in_len = strlen(in);
>
> -    g_assert_true(write(sock_fd, in, in_len) == in_len);
> +    g_assert_true(send(sock_fd, in, in_len, 0) == in_len);
>      for (i = 0; i < in_len; i++) {
>          g_assert_true(uart_wait_for_event(qts, NRF51_UART_BASE +
>                                                 A_UART_RXDRDY));
> @@ -77,7 +77,7 @@ static void test_nrf51_uart(void)
>      char s[10];
>      QTestState *qts = qtest_init_with_serial("-M microbit", &sock_fd);
>
> -    g_assert_true(write(sock_fd, "c", 1) == 1);
> +    g_assert_true(send(sock_fd, "c", 1, 0) == 1);
>      g_assert_cmphex(qtest_readl(qts, NRF51_UART_BASE + A_UART_RXD), ==,
> 0x00);
>
>      qtest_writel(qts, NRF51_UART_BASE + A_UART_ENABLE, 0x04);
> @@ -97,17 +97,17 @@ static void test_nrf51_uart(void)
>
>      qtest_writel(qts, NRF51_UART_BASE + A_UART_STARTTX, 0x01);
>      uart_w_to_txd(qts, "d");
> -    g_assert_true(read(sock_fd, s, 10) == 1);
> +    g_assert_true(recv(sock_fd, s, 10, 0) == 1);
>      g_assert_cmphex(s[0], ==, 'd');
>
>      qtest_writel(qts, NRF51_UART_BASE + A_UART_SUSPEND, 0x01);
>      qtest_writel(qts, NRF51_UART_BASE + A_UART_TXD, 'h');
>      qtest_writel(qts, NRF51_UART_BASE + A_UART_STARTTX, 0x01);
>      uart_w_to_txd(qts, "world");
> -    g_assert_true(read(sock_fd, s, 10) == 5);
> +    g_assert_true(recv(sock_fd, s, 10, 0) == 5);
>      g_assert_true(memcmp(s, "world", 5) == 0);
>
> -    close(sock_fd);
> +    closesocket(sock_fd);
>
>      qtest_quit(qts);
>  }
> --
> 2.34.1
>
>
>

-- 
Marc-André Lureau