All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/51] tests/qtest: Enable running qtest on Windows
@ 2022-08-24  9:39 Bin Meng
  2022-08-24  9:39 ` [PATCH 01/51] tests/qtest: Use g_setenv() Bin Meng
                   ` (50 more replies)
  0 siblings, 51 replies; 174+ messages in thread
From: Bin Meng @ 2022-08-24  9:39 UTC (permalink / raw)
  To: qemu-devel
  Cc: Alex Bennée, Alexander Bulekov, Andrew Jeffery, Ani Sinha,
	Bandan Das, Beraldo Leal, Christian Schoenebeck, Coiby Xu,
	Cédric Le Goater, Daniel Henrique Barboza,
	Daniel P. Berrangé,
	Darren Kenny, David Gibson, Dr. David Alan Gilbert,
	Eduardo Habkost, Emanuele Giuseppe Esposito, Fam Zheng,
	Gerd Hoffmann, Greg Kurz, Hanna Reitz, Havard Skinnemoen,
	Igor Mammedov, Jason Wang, Joel Stanley, John Snow,
	Juan Quintela, Kevin Wolf, Konstantin Kostiuk, Laurent Vivier,
	Marc-André Lureau, Marcel Apfelbaum, Markus Armbruster,
	Michael Roth, Michael S. Tsirkin, Paolo Bonzini, Peter Maydell,
	Philippe Mathieu-Daudé,
	Qiuhao Li, Richard Henderson, Stefan Berger, Stefan Hajnoczi,
	Thomas Huth, Tyrone Ting, Vladimir Sementsov-Ogievskiy,
	Wainer dos Santos Moschetta, Willian Rampazzo, Yanan Wang,
	qemu-arm, qemu-block, qemu-ppc

In prepartion to adding virtio-9p support on Windows, this series
enables running qtest on Windows, so that we can run the virtio-9p
tests on Windows to make sure it does not break accidently.

Patch 1-22 updates various components (mostly test cases) so that
they can build on Windows with the same functionality.

Patch 23 supports the qtest accelerator for Windows.

Patch 31 updates the libqtest core for Windows.

Patch 32-47 are the fixes of qtest errors exposed when running on Windows.

Patch 49 fixes the instability of running qtests on Windows.

Patch 50 updates the CI to run qtests on Windows.

Patch 51 documents best practices of writing portable test cases as
we learned during the enablement of running qtest on Windows.

Based-on: <20220802075200.907360-1-bmeng.cn@gmail.com>


Bin Meng (41):
  tests/qtest: Use g_setenv()
  tests/qtest: Use g_mkdtemp()
  block: Unify the get_tmp_filename() implementation
  semihosting/arm-compat-semi: Avoid using hardcoded /tmp
  tcg: Avoid using hardcoded /tmp
  util/qemu-sockets: Use g_get_tmp_dir() to get the directory for
    temporary files
  tests: Avoid using hardcoded /tmp in test cases
  block/vvfat: Unify the mkdir() call
  fsdev/virtfs-proxy-helper: Use g_mkdir_with_parents()
  hw/usb: dev-mtp: Use g_mkdir_with_parents()
  qga/commands-posix-ssh: Use g_mkdir_with_parents()
  tests: Use g_mkdir_with_parents()
  tests/qtest: migration-test: Handle link() for win32
  backends/tpm: Exclude headers and macros that don't exist on win32
  tests/qtest: Adapt {m48t59,rtc}-test cases for win32
  tests/qtest: Build e1000e-test for posix only
  tests/qtest: Build virtio-net-test for posix only
  tests/qtest: Build cases that use memory-backend-file for posix only
  tests/qtest: Build test-filter-{mirror,redirector} cases for posix
    only
  tests/qtest: i440fx-test: Skip running request_{bios,pflash} for win32
  tests/qtest: migration-test: Skip running test_migrate_fd_proto on
    win32
  tests/qtest: qmp-test: Skip running test_qmp_oob for win32
  tests/qtest: libqtest: Exclude the *_fds APIs for win32
  tests/qtest: libqtest: Install signal handler via signal()
  tests: Skip iotests and qtest when '--without-default-devices'
  tests/qtest: Support libqtest to build and run on Windows
  tests/qtest: Fix ERROR_SHARING_VIOLATION for win32
  tests/qtest: {ahci,ide}-test: Use relative path for temporary files
  tests/qtest: bios-tables-test: Adapt the case for win32
  tests/qtest: device-plug-test: Reverse the usage of double/single
    quotes
  tests/qtest: machine-none-test: Use double quotes to pass the cpu
    option
  tests/qtest: migration-test: Disable IO redirection for win32
  tests/qtest: npcm7xx_emc-test: Skip running test_{tx,rx} on win32
  tests/qtest: microbit-test: Fix socket access for win32
  tests/qtest: prom-env-test: Use double quotes to pass the prom-env
    option
  tests/qtest: libqtest: Replace the call to close a socket with
    closesocket()
  tests/qtest: libqtest: Correct the timeout unit of blocking receive
    calls for win32
  io/channel-watch: Drop a superfluous '#ifdef WIN32'
  io/channel-watch: Fix socket watch on Windows
  .gitlab-ci.d/windows.yml: Increase the timeout to the runner limit
  docs/devel: testing: Document writing portable test cases

Xuzhou Cheng (10):
  accel/qtest: Support qtest accelerator for Windows
  tests/qtest: libqos: Drop inclusion of <sys/wait.h>
  tests/qtest: libqos: Rename malloc.h to libqos-malloc.h
  tests/qtest: libqtest: Move global_qtest definition back to libqtest.c
  tests/qtest: Use send/recv for socket communication
  tests/qtest: {ahci,ide}-test: Open file in binary mode
  tests/qtest: virtio-net-failover: Disable migration tests for win32
  chardev/char-file: Add FILE_SHARE_WRITE when openning the file for
    win32
  tests/qtest: migration-test: Kill "to" after migration is canceled
  hw/ppc: spapr: Use qemu_vfree() to free spapr->htab

 docs/devel/testing.rst                        |  30 ++++
 backends/tpm/tpm_ioctl.h                      |   4 +
 include/hw/core/cpu.h                         |   1 +
 tests/qtest/fuzz/generic_fuzz_configs.h       |   8 +-
 tests/qtest/libqos/generic-pcihost.h          |   2 +-
 .../libqos/{malloc.h => libqos-malloc.h}      |   0
 tests/qtest/libqos/libqos.h                   |   2 +-
 tests/qtest/libqos/malloc-pc.h                |   2 +-
 tests/qtest/libqos/malloc-spapr.h             |   2 +-
 tests/qtest/libqos/pci-pc.h                   |   2 +-
 tests/qtest/libqos/pci-spapr.h                |   2 +-
 tests/qtest/libqos/qgraph.h                   |   2 +-
 tests/qtest/libqos/qos_external.h             |   2 +-
 tests/qtest/libqos/rtas.h                     |   2 +-
 tests/qtest/libqos/virtio.h                   |   2 +-
 tests/qtest/libqtest-single.h                 |   2 +-
 tests/qtest/libqtest.h                        |   8 +
 tests/qtest/migration-helpers.h               |   2 +
 accel/dummy-cpus.c                            |  14 +-
 block.c                                       |  16 +-
 block/vvfat.c                                 |   8 +-
 chardev/char-file.c                           |   4 +-
 fsdev/virtfs-proxy-helper.c                   |   2 +-
 hw/ppc/spapr.c                                |   2 +-
 hw/usb/dev-mtp.c                              |   2 +-
 io/channel-watch.c                            |   6 -
 qga/commands-posix-ssh.c                      |   2 +-
 semihosting/arm-compat-semi.c                 |   3 +-
 softmmu/cpus.c                                |   9 +-
 tcg/tcg.c                                     |   4 +-
 tests/migration/stress.c                      |   2 +-
 tests/qtest/ahci-test.c                       |  44 ++++-
 tests/qtest/aspeed_smc-test.c                 |   4 +-
 tests/qtest/bios-tables-test.c                |  22 ++-
 tests/qtest/boot-serial-test.c                |  21 ++-
 tests/qtest/cdrom-test.c                      |   2 +-
 tests/qtest/cxl-test.c                        |  19 +-
 tests/qtest/device-plug-test.c                |   2 +-
 tests/qtest/e1000e-test.c                     |   2 +-
 tests/qtest/fdc-test.c                        |   4 +-
 tests/qtest/fuzz/generic_fuzz.c               |   8 +-
 tests/qtest/fuzz/qos_fuzz.c                   |   2 +-
 tests/qtest/fuzz/virtio_blk_fuzz.c            |   2 +-
 tests/qtest/hd-geo-test.c                     |   8 +-
 tests/qtest/i440fx-test.c                     |   6 +
 tests/qtest/ide-test.c                        |  26 ++-
 tests/qtest/ivshmem-test.c                    |   4 +-
 tests/qtest/libqmp.c                          |   4 +-
 .../libqos/aarch64-xlnx-zcu102-machine.c      |   2 +-
 tests/qtest/libqos/arm-imx25-pdk-machine.c    |   2 +-
 tests/qtest/libqos/arm-n800-machine.c         |   2 +-
 tests/qtest/libqos/arm-raspi2-machine.c       |   2 +-
 tests/qtest/libqos/arm-sabrelite-machine.c    |   2 +-
 tests/qtest/libqos/arm-smdkc210-machine.c     |   2 +-
 tests/qtest/libqos/arm-virt-machine.c         |   2 +-
 .../qtest/libqos/arm-xilinx-zynq-a9-machine.c |   2 +-
 tests/qtest/libqos/e1000e.c                   |   2 +-
 .../libqos/{malloc.c => libqos-malloc.c}      |   2 +-
 tests/qtest/libqos/libqos.c                   |   2 -
 tests/qtest/libqos/qos_external.c             |   2 +-
 tests/qtest/libqos/virtio-9p.c                |   4 +-
 tests/qtest/libqos/virtio-mmio.c              |   2 +-
 tests/qtest/libqos/virtio-pci.c               |   2 +-
 tests/qtest/libqtest.c                        | 164 +++++++++++++++---
 tests/qtest/m48t59-test.c                     |   2 +-
 tests/qtest/machine-none-test.c               |   2 +-
 tests/qtest/microbit-test.c                   |  10 +-
 tests/qtest/migration-helpers.c               |   2 +
 tests/qtest/migration-test.c                  |  69 +++++---
 tests/qtest/npcm7xx_emc-test.c                |   8 +
 tests/qtest/pflash-cfi02-test.c               |   7 +-
 tests/qtest/prom-env-test.c                   |   4 +-
 tests/qtest/qmp-test.c                        |  14 +-
 tests/qtest/qos-test.c                        |   2 +-
 tests/qtest/rtc-test.c                        |   2 +-
 tests/qtest/vhost-user-blk-test.c             |   3 +-
 tests/qtest/vhost-user-test.c                 |   7 +-
 tests/qtest/virtio-blk-test.c                 |   2 +-
 tests/qtest/virtio-net-failover.c             |   9 +-
 tests/qtest/virtio-net-test.c                 |   6 -
 tests/qtest/virtio-scsi-test.c                |   3 +-
 tests/unit/test-crypto-tlscredsx509.c         |   4 +-
 tests/unit/test-crypto-tlssession.c           |   6 +-
 tests/unit/test-image-locking.c               |   6 +-
 tests/unit/test-io-channel-tls.c              |   6 +-
 tests/unit/test-qga.c                         |   4 +-
 tests/vhost-user-bridge.c                     |   3 +-
 util/qemu-sockets.c                           |   5 +-
 .gitlab-ci.d/windows.yml                      |   4 +-
 accel/meson.build                             |   1 +
 accel/qtest/meson.build                       |   1 +
 tests/qemu-iotests/meson.build                |   5 +
 tests/qtest/libqos/meson.build                |   2 +-
 tests/qtest/meson.build                       |  46 +++--
 94 files changed, 549 insertions(+), 221 deletions(-)
 rename tests/qtest/libqos/{malloc.h => libqos-malloc.h} (100%)
 rename tests/qtest/libqos/{malloc.c => libqos-malloc.c} (99%)

-- 
2.34.1



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

* [PATCH 01/51] tests/qtest: Use g_setenv()
  2022-08-24  9:39 [PATCH 00/51] tests/qtest: Enable running qtest on Windows Bin Meng
@ 2022-08-24  9:39 ` Bin Meng
  2022-08-24 11:45   ` Thomas Huth
  2022-09-04 14:10   ` Philippe Mathieu-Daudé via
  2022-08-24  9:39 ` [PATCH 02/51] tests/qtest: Use g_mkdtemp() Bin Meng
                   ` (49 subsequent siblings)
  50 siblings, 2 replies; 174+ messages in thread
From: Bin Meng @ 2022-08-24  9:39 UTC (permalink / raw)
  To: qemu-devel
  Cc: Bin Meng, Alexander Bulekov, Bandan Das, Darren Kenny,
	Laurent Vivier, Paolo Bonzini, Qiuhao Li, Stefan Hajnoczi,
	Thomas Huth

From: Bin Meng <bin.meng@windriver.com>

Windows does not provide a setenv() API, but glib does.
Replace setenv() call with the glib version.

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

 tests/qtest/fuzz/generic_fuzz.c | 8 ++++----
 tests/qtest/libqtest.c          | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/tests/qtest/fuzz/generic_fuzz.c b/tests/qtest/fuzz/generic_fuzz.c
index 447ffe8178..afc1d20355 100644
--- a/tests/qtest/fuzz/generic_fuzz.c
+++ b/tests/qtest/fuzz/generic_fuzz.c
@@ -994,16 +994,16 @@ static GString *generic_fuzz_predefined_config_cmdline(FuzzTarget *t)
     g_assert(t->opaque);
 
     config = t->opaque;
-    setenv("QEMU_AVOID_DOUBLE_FETCH", "1", 1);
+    g_setenv("QEMU_AVOID_DOUBLE_FETCH", "1", 1);
     if (config->argfunc) {
         args = config->argfunc();
-        setenv("QEMU_FUZZ_ARGS", args, 1);
+        g_setenv("QEMU_FUZZ_ARGS", args, 1);
         g_free(args);
     } else {
         g_assert_nonnull(config->args);
-        setenv("QEMU_FUZZ_ARGS", config->args, 1);
+        g_setenv("QEMU_FUZZ_ARGS", config->args, 1);
     }
-    setenv("QEMU_FUZZ_OBJECTS", config->objects, 1);
+    g_setenv("QEMU_FUZZ_OBJECTS", config->objects, 1);
     return generic_fuzz_cmdline(t);
 }
 
diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
index 8c159eacf5..ad6860d774 100644
--- a/tests/qtest/libqtest.c
+++ b/tests/qtest/libqtest.c
@@ -1424,7 +1424,7 @@ QTestState *qtest_inproc_init(QTestState **s, bool log, const char* arch,
      * way, qtest_get_arch works for inproc qtest.
      */
     gchar *bin_path = g_strconcat("/qemu-system-", arch, NULL);
-    setenv("QTEST_QEMU_BINARY", bin_path, 0);
+    g_setenv("QTEST_QEMU_BINARY", bin_path, 0);
     g_free(bin_path);
 
     return qts;
-- 
2.34.1



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

* [PATCH 02/51] tests/qtest: Use g_mkdtemp()
  2022-08-24  9:39 [PATCH 00/51] tests/qtest: Enable running qtest on Windows Bin Meng
  2022-08-24  9:39 ` [PATCH 01/51] tests/qtest: Use g_setenv() Bin Meng
@ 2022-08-24  9:39 ` Bin Meng
  2022-08-24 14:42   ` Thomas Huth
  2022-08-24  9:39 ` [PATCH 03/51] block: Unify the get_tmp_filename() implementation Bin Meng
                   ` (48 subsequent siblings)
  50 siblings, 1 reply; 174+ messages in thread
From: Bin Meng @ 2022-08-24  9:39 UTC (permalink / raw)
  To: qemu-devel
  Cc: Bin Meng, Alexander Bulekov, Bandan Das, Darren Kenny,
	Dr. David Alan Gilbert, John Snow, Juan Quintela,
	Konstantin Kostiuk, Laurent Vivier, Markus Armbruster,
	Michael Roth, Paolo Bonzini, Qiuhao Li, Stefan Hajnoczi,
	Thomas Huth, qemu-block

From: Bin Meng <bin.meng@windriver.com>

Windows does not provide a mkdtemp() API, but glib does.
Replace mkdtemp() call with the glib version.

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

 tests/qtest/fuzz/generic_fuzz_configs.h | 2 +-
 tests/qtest/cdrom-test.c                | 2 +-
 tests/qtest/cxl-test.c                  | 6 +++---
 tests/qtest/ivshmem-test.c              | 4 ++--
 tests/qtest/libqos/virtio-9p.c          | 4 ++--
 tests/qtest/libqtest.c                  | 2 +-
 tests/qtest/migration-test.c            | 4 ++--
 tests/qtest/qmp-test.c                  | 4 ++--
 tests/qtest/vhost-user-test.c           | 4 ++--
 tests/unit/test-qga.c                   | 2 +-
 10 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/tests/qtest/fuzz/generic_fuzz_configs.h b/tests/qtest/fuzz/generic_fuzz_configs.h
index 004c701915..0775e6702b 100644
--- a/tests/qtest/fuzz/generic_fuzz_configs.h
+++ b/tests/qtest/fuzz/generic_fuzz_configs.h
@@ -21,7 +21,7 @@ typedef struct generic_fuzz_config {
 
 static inline gchar *generic_fuzzer_virtio_9p_args(void){
     char tmpdir[] = "/tmp/qemu-fuzz.XXXXXX";
-    g_assert_nonnull(mkdtemp(tmpdir));
+    g_assert_nonnull(g_mkdtemp(tmpdir));
 
     return g_strdup_printf("-machine q35 -nodefaults "
     "-device virtio-9p,fsdev=hshare,mount_tag=hshare "
diff --git a/tests/qtest/cdrom-test.c b/tests/qtest/cdrom-test.c
index a7766a9e65..26a2400181 100644
--- a/tests/qtest/cdrom-test.c
+++ b/tests/qtest/cdrom-test.c
@@ -52,7 +52,7 @@ static int prepare_image(const char *arch, char *isoimage)
         perror("Error creating temporary iso image file");
         return -1;
     }
-    if (!mkdtemp(srcdir)) {
+    if (!g_mkdtemp(srcdir)) {
         perror("Error creating temporary directory");
         goto cleanup;
     }
diff --git a/tests/qtest/cxl-test.c b/tests/qtest/cxl-test.c
index 2133e973f4..4e6d285061 100644
--- a/tests/qtest/cxl-test.c
+++ b/tests/qtest/cxl-test.c
@@ -95,7 +95,7 @@ static void cxl_t3d(void)
     char template[] = "/tmp/cxl-test-XXXXXX";
     const char *tmpfs;
 
-    tmpfs = mkdtemp(template);
+    tmpfs = g_mkdtemp(template);
 
     g_string_printf(cmdline, QEMU_PXB_CMD QEMU_RP QEMU_T3D, tmpfs, tmpfs);
 
@@ -109,7 +109,7 @@ static void cxl_1pxb_2rp_2t3d(void)
     char template[] = "/tmp/cxl-test-XXXXXX";
     const char *tmpfs;
 
-    tmpfs = mkdtemp(template);
+    tmpfs = g_mkdtemp(template);
 
     g_string_printf(cmdline, QEMU_PXB_CMD QEMU_2RP QEMU_2T3D,
                     tmpfs, tmpfs, tmpfs, tmpfs);
@@ -124,7 +124,7 @@ static void cxl_2pxb_4rp_4t3d(void)
     char template[] = "/tmp/cxl-test-XXXXXX";
     const char *tmpfs;
 
-    tmpfs = mkdtemp(template);
+    tmpfs = g_mkdtemp(template);
 
     g_string_printf(cmdline, QEMU_2PXB_CMD QEMU_4RP QEMU_4T3D,
                     tmpfs, tmpfs, tmpfs, tmpfs, tmpfs, tmpfs,
diff --git a/tests/qtest/ivshmem-test.c b/tests/qtest/ivshmem-test.c
index e23a97fa8e..9611d05eb5 100644
--- a/tests/qtest/ivshmem-test.c
+++ b/tests/qtest/ivshmem-test.c
@@ -481,8 +481,8 @@ int main(int argc, char **argv)
     tmpshmem = mmap(0, TMPSHMSIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
     g_assert(tmpshmem != MAP_FAILED);
     /* server */
-    if (mkdtemp(dir) == NULL) {
-        g_error("mkdtemp: %s", g_strerror(errno));
+    if (g_mkdtemp(dir) == NULL) {
+        g_error("g_mkdtemp: %s", g_strerror(errno));
     }
     tmpdir = dir;
     tmpserver = g_strconcat(tmpdir, "/server", NULL);
diff --git a/tests/qtest/libqos/virtio-9p.c b/tests/qtest/libqos/virtio-9p.c
index 70aea8bf62..ae9b0a20e2 100644
--- a/tests/qtest/libqos/virtio-9p.c
+++ b/tests/qtest/libqos/virtio-9p.c
@@ -48,9 +48,9 @@ void virtio_9p_create_local_test_dir(void)
      */
     char *template = concat_path(pwd, "qtest-9p-local-XXXXXX");
 
-    local_test_path = mkdtemp(template);
+    local_test_path = g_mkdtemp(template);
     if (!local_test_path) {
-        g_test_message("mkdtemp('%s') failed: %s", template, strerror(errno));
+        g_test_message("g_mkdtemp('%s') failed: %s", template, strerror(errno));
     }
 
     g_assert(local_test_path != NULL);
diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
index ad6860d774..7c9fc07de4 100644
--- a/tests/qtest/libqtest.c
+++ b/tests/qtest/libqtest.c
@@ -393,7 +393,7 @@ QTestState *qtest_init_with_serial(const char *extra_args, int *sock_fd)
     char *sock_path, sock_dir[] = "/tmp/qtest-serial-XXXXXX";
     QTestState *qts;
 
-    g_assert_true(mkdtemp(sock_dir) != NULL);
+    g_assert_true(g_mkdtemp(sock_dir) != NULL);
     sock_path = g_strdup_printf("%s/sock", sock_dir);
 
     sock_fd_init = init_socket(sock_path);
diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index 520a5f917c..52988b86eb 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -2450,9 +2450,9 @@ int main(int argc, char **argv)
         return g_test_run();
     }
 
-    tmpfs = mkdtemp(template);
+    tmpfs = g_mkdtemp(template);
     if (!tmpfs) {
-        g_test_message("mkdtemp on path (%s): %s", template, strerror(errno));
+        g_test_message("g_mkdtemp on path (%s): %s", template, strerror(errno));
     }
     g_assert(tmpfs);
 
diff --git a/tests/qtest/qmp-test.c b/tests/qtest/qmp-test.c
index 9a42480cef..bf7304c7dc 100644
--- a/tests/qtest/qmp-test.c
+++ b/tests/qtest/qmp-test.c
@@ -166,8 +166,8 @@ char *fifo_name;
 
 static void setup_blocking_cmd(void)
 {
-    if (!mkdtemp(tmpdir)) {
-        g_error("mkdtemp: %s", strerror(errno));
+    if (!g_mkdtemp(tmpdir)) {
+        g_error("g_mkdtemp: %s", strerror(errno));
     }
     fifo_name = g_strdup_printf("%s/fifo", tmpdir);
     if (mkfifo(fifo_name, 0666)) {
diff --git a/tests/qtest/vhost-user-test.c b/tests/qtest/vhost-user-test.c
index 8bf390be20..d7d6cfc9bd 100644
--- a/tests/qtest/vhost-user-test.c
+++ b/tests/qtest/vhost-user-test.c
@@ -491,9 +491,9 @@ static TestServer *test_server_new(const gchar *name,
     /* run the main loop thread so the chardev may operate */
     server->thread = g_thread_new(NULL, thread_function, server->loop);
 
-    tmpfs = mkdtemp(template);
+    tmpfs = g_mkdtemp(template);
     if (!tmpfs) {
-        g_test_message("mkdtemp on path (%s): %s", template, strerror(errno));
+        g_test_message("g_mkdtemp on path (%s): %s", template, strerror(errno));
     }
     g_assert(tmpfs);
 
diff --git a/tests/unit/test-qga.c b/tests/unit/test-qga.c
index b27c77a695..a05a4628ed 100644
--- a/tests/unit/test-qga.c
+++ b/tests/unit/test-qga.c
@@ -60,7 +60,7 @@ fixture_setup(TestFixture *fixture, gconstpointer data, gchar **envp)
     fixture->loop = g_main_loop_new(NULL, FALSE);
 
     fixture->test_dir = g_strdup("/tmp/qgatest.XXXXXX");
-    g_assert_nonnull(mkdtemp(fixture->test_dir));
+    g_assert_nonnull(g_mkdtemp(fixture->test_dir));
 
     path = g_build_filename(fixture->test_dir, "sock", NULL);
     cwd = g_get_current_dir();
-- 
2.34.1



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

* [PATCH 03/51] block: Unify the get_tmp_filename() implementation
  2022-08-24  9:39 [PATCH 00/51] tests/qtest: Enable running qtest on Windows Bin Meng
  2022-08-24  9:39 ` [PATCH 01/51] tests/qtest: Use g_setenv() Bin Meng
  2022-08-24  9:39 ` [PATCH 02/51] tests/qtest: Use g_mkdtemp() Bin Meng
@ 2022-08-24  9:39 ` Bin Meng
  2022-08-31 12:54   ` Marc-André Lureau
  2022-08-24  9:39 ` [PATCH 04/51] semihosting/arm-compat-semi: Avoid using hardcoded /tmp Bin Meng
                   ` (47 subsequent siblings)
  50 siblings, 1 reply; 174+ messages in thread
From: Bin Meng @ 2022-08-24  9:39 UTC (permalink / raw)
  To: qemu-devel; +Cc: Bin Meng, Hanna Reitz, Kevin Wolf, qemu-block

From: Bin Meng <bin.meng@windriver.com>

At present get_tmp_filename() has platform specific implementations
to get the directory to use for temporary files. Switch over to use
g_get_tmp_dir() which works on all supported platforms.

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

 block.c | 16 ++--------------
 1 file changed, 2 insertions(+), 14 deletions(-)

diff --git a/block.c b/block.c
index bc85f46eed..d06df47f72 100644
--- a/block.c
+++ b/block.c
@@ -864,21 +864,10 @@ int bdrv_probe_geometry(BlockDriverState *bs, HDGeometry *geo)
  */
 int get_tmp_filename(char *filename, int size)
 {
-#ifdef _WIN32
-    char temp_dir[MAX_PATH];
-    /* GetTempFileName requires that its output buffer (4th param)
-       have length MAX_PATH or greater.  */
-    assert(size >= MAX_PATH);
-    return (GetTempPath(MAX_PATH, temp_dir)
-            && GetTempFileName(temp_dir, "qem", 0, filename)
-            ? 0 : -GetLastError());
-#else
     int fd;
     const char *tmpdir;
-    tmpdir = getenv("TMPDIR");
-    if (!tmpdir) {
-        tmpdir = "/var/tmp";
-    }
+    tmpdir = g_get_tmp_dir();
+
     if (snprintf(filename, size, "%s/vl.XXXXXX", tmpdir) >= size) {
         return -EOVERFLOW;
     }
@@ -891,7 +880,6 @@ int get_tmp_filename(char *filename, int size)
         return -errno;
     }
     return 0;
-#endif
 }
 
 /*
-- 
2.34.1



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

* [PATCH 04/51] semihosting/arm-compat-semi: Avoid using hardcoded /tmp
  2022-08-24  9:39 [PATCH 00/51] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (2 preceding siblings ...)
  2022-08-24  9:39 ` [PATCH 03/51] block: Unify the get_tmp_filename() implementation Bin Meng
@ 2022-08-24  9:39 ` Bin Meng
  2022-08-31 12:59   ` Marc-André Lureau
  2022-08-24  9:39 ` [PATCH 05/51] tcg: " Bin Meng
                   ` (46 subsequent siblings)
  50 siblings, 1 reply; 174+ messages in thread
From: Bin Meng @ 2022-08-24  9:39 UTC (permalink / raw)
  To: qemu-devel; +Cc: Bin Meng, Alex Bennée

From: Bin Meng <bin.meng@windriver.com>

Use g_get_tmp_dir() to get the directory to use for temporary files.

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

 semihosting/arm-compat-semi.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c
index e741674238..d5e66cc298 100644
--- a/semihosting/arm-compat-semi.c
+++ b/semihosting/arm-compat-semi.c
@@ -503,7 +503,8 @@ void do_common_semihosting(CPUState *cs)
         GET_ARG(0);
         GET_ARG(1);
         GET_ARG(2);
-        len = asprintf(&s, "/tmp/qemu-%x%02x", getpid(), (int)arg1 & 0xff);
+        len = asprintf(&s, "%s/qemu-%x%02x", g_get_tmp_dir(),
+                       getpid(), (int)arg1 & 0xff);
         if (len < 0) {
             common_semi_set_ret(cs, -1);
             break;
-- 
2.34.1



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

* [PATCH 05/51] tcg: Avoid using hardcoded /tmp
  2022-08-24  9:39 [PATCH 00/51] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (3 preceding siblings ...)
  2022-08-24  9:39 ` [PATCH 04/51] semihosting/arm-compat-semi: Avoid using hardcoded /tmp Bin Meng
@ 2022-08-24  9:39 ` Bin Meng
  2022-08-31 13:02   ` Marc-André Lureau
  2022-08-24  9:39 ` [PATCH 06/51] util/qemu-sockets: Use g_get_tmp_dir() to get the directory for temporary files Bin Meng
                   ` (45 subsequent siblings)
  50 siblings, 1 reply; 174+ messages in thread
From: Bin Meng @ 2022-08-24  9:39 UTC (permalink / raw)
  To: qemu-devel; +Cc: Bin Meng, Richard Henderson

From: Bin Meng <bin.meng@windriver.com>

Use g_get_tmp_dir() to get the directory to use for temporary files.

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

 tcg/tcg.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tcg/tcg.c b/tcg/tcg.c
index 0f9cfe96f2..932156a352 100644
--- a/tcg/tcg.c
+++ b/tcg/tcg.c
@@ -4729,13 +4729,15 @@ static void tcg_register_jit_int(const void *buf_ptr, size_t buf_size,
     /* Enable this block to be able to debug the ELF image file creation.
        One can use readelf, objdump, or other inspection utilities.  */
     {
-        FILE *f = fopen("/tmp/qemu.jit", "w+b");
+        char *jit = g_strdup_printf("%s/qemu.jit", g_get_tmp_dir());
+        FILE *f = fopen(jit, "w+b");
         if (f) {
             if (fwrite(img, img_size, 1, f) != img_size) {
                 /* Avoid stupid unused return value warning for fwrite.  */
             }
             fclose(f);
         }
+        g_free(jit);
     }
 #endif
 
-- 
2.34.1



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

* [PATCH 06/51] util/qemu-sockets: Use g_get_tmp_dir() to get the directory for temporary files
  2022-08-24  9:39 [PATCH 00/51] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (4 preceding siblings ...)
  2022-08-24  9:39 ` [PATCH 05/51] tcg: " Bin Meng
@ 2022-08-24  9:39 ` Bin Meng
  2022-08-31 13:05   ` Marc-André Lureau
  2022-08-24  9:39 ` [PATCH 07/51] tests: Avoid using hardcoded /tmp in test cases Bin Meng
                   ` (44 subsequent siblings)
  50 siblings, 1 reply; 174+ messages in thread
From: Bin Meng @ 2022-08-24  9:39 UTC (permalink / raw)
  To: qemu-devel; +Cc: Bin Meng, Daniel P. Berrangé

From: Bin Meng <bin.meng@windriver.com>

Replace the existing logic to get the directory for temporary files
with g_get_tmp_dir(), which works for win32 too.

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

 util/qemu-sockets.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c
index 83f4bd6fd2..0c41ca9e42 100644
--- a/util/qemu-sockets.c
+++ b/util/qemu-sockets.c
@@ -919,9 +919,8 @@ static int unix_listen_saddr(UnixSocketAddress *saddr,
     if (saddr->path[0] || abstract) {
         path = saddr->path;
     } else {
-        const char *tmpdir = getenv("TMPDIR");
-        tmpdir = tmpdir ? tmpdir : "/tmp";
-        path = pathbuf = g_strdup_printf("%s/qemu-socket-XXXXXX", tmpdir);
+        path = pathbuf = g_strdup_printf("%s/qemu-socket-XXXXXX",
+                                         g_get_tmp_dir());
     }
 
     pathlen = strlen(path);
-- 
2.34.1



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

* [PATCH 07/51] tests: Avoid using hardcoded /tmp in test cases
  2022-08-24  9:39 [PATCH 00/51] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (5 preceding siblings ...)
  2022-08-24  9:39 ` [PATCH 06/51] util/qemu-sockets: Use g_get_tmp_dir() to get the directory for temporary files Bin Meng
@ 2022-08-24  9:39 ` Bin Meng
  2022-08-24 17:51   ` Dr. David Alan Gilbert
  2022-08-25  8:41   ` Thomas Huth
  2022-08-24  9:39 ` [PATCH 08/51] block/vvfat: Unify the mkdir() call Bin Meng
                   ` (43 subsequent siblings)
  50 siblings, 2 replies; 174+ messages in thread
From: Bin Meng @ 2022-08-24  9:39 UTC (permalink / raw)
  To: qemu-devel
  Cc: Bin Meng, Alexander Bulekov, Andrew Jeffery, Bandan Das,
	Coiby Xu, Cédric Le Goater, Darren Kenny,
	Dr. David Alan Gilbert, Fam Zheng, Joel Stanley, John Snow,
	Juan Quintela, Konstantin Kostiuk, Laurent Vivier,
	Markus Armbruster, Michael Roth, Paolo Bonzini, Peter Maydell,
	Qiuhao Li, Stefan Hajnoczi, Thomas Huth, qemu-arm, qemu-block

From: Bin Meng <bin.meng@windriver.com>

Use g_get_tmp_dir() to get the directory to use for temporary files.

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

 tests/qtest/fuzz/generic_fuzz_configs.h |  6 ++++--
 tests/qtest/ahci-test.c                 | 15 +++++++++++----
 tests/qtest/aspeed_smc-test.c           |  4 +++-
 tests/qtest/boot-serial-test.c          |  8 ++++++--
 tests/qtest/cxl-test.c                  |  9 ++++++---
 tests/qtest/fdc-test.c                  |  4 +++-
 tests/qtest/fuzz/virtio_blk_fuzz.c      |  2 +-
 tests/qtest/hd-geo-test.c               |  8 ++++----
 tests/qtest/ide-test.c                  |  8 ++++++--
 tests/qtest/libqtest.c                  | 10 +++++++---
 tests/qtest/migration-test.c            |  4 +++-
 tests/qtest/pflash-cfi02-test.c         |  7 +++++--
 tests/qtest/qmp-test.c                  |  4 +++-
 tests/qtest/vhost-user-blk-test.c       |  3 ++-
 tests/qtest/vhost-user-test.c           |  3 ++-
 tests/qtest/virtio-blk-test.c           |  2 +-
 tests/qtest/virtio-scsi-test.c          |  3 ++-
 tests/unit/test-image-locking.c         |  6 ++++--
 tests/unit/test-qga.c                   |  2 +-
 tests/vhost-user-bridge.c               |  3 ++-
 20 files changed, 76 insertions(+), 35 deletions(-)

diff --git a/tests/qtest/fuzz/generic_fuzz_configs.h b/tests/qtest/fuzz/generic_fuzz_configs.h
index 0775e6702b..d0f9961187 100644
--- a/tests/qtest/fuzz/generic_fuzz_configs.h
+++ b/tests/qtest/fuzz/generic_fuzz_configs.h
@@ -20,13 +20,15 @@ typedef struct generic_fuzz_config {
 } generic_fuzz_config;
 
 static inline gchar *generic_fuzzer_virtio_9p_args(void){
-    char tmpdir[] = "/tmp/qemu-fuzz.XXXXXX";
+    char *tmpdir = g_strdup_printf("%s/qemu-fuzz.XXXXXX", g_get_tmp_dir());
     g_assert_nonnull(g_mkdtemp(tmpdir));
 
-    return g_strdup_printf("-machine q35 -nodefaults "
+    gchar *args = g_strdup_printf("-machine q35 -nodefaults "
     "-device virtio-9p,fsdev=hshare,mount_tag=hshare "
     "-fsdev local,id=hshare,path=%s,security_model=mapped-xattr,"
     "writeout=immediate,fmode=0600,dmode=0700", tmpdir);
+    g_free(tmpdir);
+    return args;
 }
 
 const generic_fuzz_config predefined_configs[] = {
diff --git a/tests/qtest/ahci-test.c b/tests/qtest/ahci-test.c
index f1e510b0ac..f26cd6f86f 100644
--- a/tests/qtest/ahci-test.c
+++ b/tests/qtest/ahci-test.c
@@ -44,9 +44,9 @@
 #define TEST_IMAGE_SIZE_MB_SMALL 64
 
 /*** Globals ***/
-static char tmp_path[] = "/tmp/qtest.XXXXXX";
-static char debug_path[] = "/tmp/qtest-blkdebug.XXXXXX";
-static char mig_socket[] = "/tmp/qtest-migration.XXXXXX";
+static char *tmp_path;
+static char *debug_path;
+static char *mig_socket;
 static bool ahci_pedantic;
 static const char *imgfmt;
 static unsigned test_image_size_mb;
@@ -1437,7 +1437,7 @@ static void test_ncq_simple(void)
 
 static int prepare_iso(size_t size, unsigned char **buf, char **name)
 {
-    char cdrom_path[] = "/tmp/qtest.iso.XXXXXX";
+    char *cdrom_path = g_strdup_printf("%s/qtest.iso.XXXXXX", g_get_tmp_dir());
     unsigned char *patt;
     ssize_t ret;
     int fd = mkstemp(cdrom_path);
@@ -1454,6 +1454,7 @@ static int prepare_iso(size_t size, unsigned char **buf, char **name)
 
     *name = g_strdup(cdrom_path);
     *buf = patt;
+    g_free(cdrom_path);
     return fd;
 }
 
@@ -1872,6 +1873,7 @@ int main(int argc, char **argv)
     }
 
     /* Create a temporary image */
+    tmp_path = g_strdup_printf("%s/qtest.XXXXXX", g_get_tmp_dir());
     fd = mkstemp(tmp_path);
     g_assert(fd >= 0);
     if (have_qemu_img()) {
@@ -1889,11 +1891,13 @@ int main(int argc, char **argv)
     close(fd);
 
     /* Create temporary blkdebug instructions */
+    debug_path = g_strdup_printf("%s/qtest-blkdebug.XXXXXX", g_get_tmp_dir());
     fd = mkstemp(debug_path);
     g_assert(fd >= 0);
     close(fd);
 
     /* Reserve a hollow file to use as a socket for migration tests */
+    mig_socket = g_strdup_printf("%s/qtest-migration.XXXXXX", g_get_tmp_dir());
     fd = mkstemp(mig_socket);
     g_assert(fd >= 0);
     close(fd);
@@ -1947,8 +1951,11 @@ int main(int argc, char **argv)
 
     /* Cleanup */
     unlink(tmp_path);
+    g_free(tmp_path);
     unlink(debug_path);
+    g_free(debug_path);
     unlink(mig_socket);
+    g_free(mig_socket);
 
     return ret;
 }
diff --git a/tests/qtest/aspeed_smc-test.c b/tests/qtest/aspeed_smc-test.c
index 05ce941566..cab769459c 100644
--- a/tests/qtest/aspeed_smc-test.c
+++ b/tests/qtest/aspeed_smc-test.c
@@ -608,7 +608,7 @@ static void test_write_block_protect_bottom_bit(void)
     flash_reset();
 }
 
-static char tmp_path[] = "/tmp/qtest.m25p80.XXXXXX";
+static char *tmp_path;
 
 int main(int argc, char **argv)
 {
@@ -617,6 +617,7 @@ int main(int argc, char **argv)
 
     g_test_init(&argc, &argv, NULL);
 
+    tmp_path = g_strdup_printf("%s/qtest.m25p80.XXXXXX", g_get_tmp_dir());
     fd = mkstemp(tmp_path);
     g_assert(fd >= 0);
     ret = ftruncate(fd, FLASH_SIZE);
@@ -646,5 +647,6 @@ int main(int argc, char **argv)
 
     qtest_quit(global_qtest);
     unlink(tmp_path);
+    g_free(tmp_path);
     return ret;
 }
diff --git a/tests/qtest/boot-serial-test.c b/tests/qtest/boot-serial-test.c
index 2f99d71cab..404adcfa20 100644
--- a/tests/qtest/boot-serial-test.c
+++ b/tests/qtest/boot-serial-test.c
@@ -224,8 +224,10 @@ static bool check_guest_output(QTestState *qts, const testdef_t *test, int fd)
 static void test_machine(const void *data)
 {
     const testdef_t *test = data;
-    char serialtmp[] = "/tmp/qtest-boot-serial-sXXXXXX";
-    char codetmp[] = "/tmp/qtest-boot-serial-cXXXXXX";
+    char *serialtmp = g_strdup_printf("%s/qtest-boot-serial-sXXXXXX",
+                                      g_get_tmp_dir());
+    char *codetmp = g_strdup_printf("%s/qtest-boot-serial-cXXXXXX",
+                                    g_get_tmp_dir());
     const char *codeparam = "";
     const uint8_t *code = NULL;
     QTestState *qts;
@@ -264,6 +266,7 @@ static void test_machine(const void *data)
                       serialtmp, test->extra);
     if (code) {
         unlink(codetmp);
+        g_free(codetmp);
     }
 
     if (!check_guest_output(qts, test, ser_fd)) {
@@ -271,6 +274,7 @@ static void test_machine(const void *data)
                 serialtmp);
     }
     unlink(serialtmp);
+    g_free(serialtmp);
 
     qtest_quit(qts);
 
diff --git a/tests/qtest/cxl-test.c b/tests/qtest/cxl-test.c
index 4e6d285061..b3733cdb5f 100644
--- a/tests/qtest/cxl-test.c
+++ b/tests/qtest/cxl-test.c
@@ -92,12 +92,13 @@ static void cxl_2root_port(void)
 static void cxl_t3d(void)
 {
     g_autoptr(GString) cmdline = g_string_new(NULL);
-    char template[] = "/tmp/cxl-test-XXXXXX";
+    char *template = g_strdup_printf("%s/cxl-test-XXXXXX", g_get_tmp_dir());
     const char *tmpfs;
 
     tmpfs = g_mkdtemp(template);
 
     g_string_printf(cmdline, QEMU_PXB_CMD QEMU_RP QEMU_T3D, tmpfs, tmpfs);
+    g_free(template);
 
     qtest_start(cmdline->str);
     qtest_end();
@@ -106,13 +107,14 @@ static void cxl_t3d(void)
 static void cxl_1pxb_2rp_2t3d(void)
 {
     g_autoptr(GString) cmdline = g_string_new(NULL);
-    char template[] = "/tmp/cxl-test-XXXXXX";
+    char *template = g_strdup_printf("%s/cxl-test-XXXXXX", g_get_tmp_dir());
     const char *tmpfs;
 
     tmpfs = g_mkdtemp(template);
 
     g_string_printf(cmdline, QEMU_PXB_CMD QEMU_2RP QEMU_2T3D,
                     tmpfs, tmpfs, tmpfs, tmpfs);
+    g_free(template);
 
     qtest_start(cmdline->str);
     qtest_end();
@@ -121,7 +123,7 @@ static void cxl_1pxb_2rp_2t3d(void)
 static void cxl_2pxb_4rp_4t3d(void)
 {
     g_autoptr(GString) cmdline = g_string_new(NULL);
-    char template[] = "/tmp/cxl-test-XXXXXX";
+    char *template = g_strdup_printf("%s/cxl-test-XXXXXX", g_get_tmp_dir());
     const char *tmpfs;
 
     tmpfs = g_mkdtemp(template);
@@ -129,6 +131,7 @@ static void cxl_2pxb_4rp_4t3d(void)
     g_string_printf(cmdline, QEMU_2PXB_CMD QEMU_4RP QEMU_4T3D,
                     tmpfs, tmpfs, tmpfs, tmpfs, tmpfs, tmpfs,
                     tmpfs, tmpfs);
+    g_free(template);
 
     qtest_start(cmdline->str);
     qtest_end();
diff --git a/tests/qtest/fdc-test.c b/tests/qtest/fdc-test.c
index 52ade90a7d..8651100b05 100644
--- a/tests/qtest/fdc-test.c
+++ b/tests/qtest/fdc-test.c
@@ -68,7 +68,7 @@ enum {
     DSKCHG  = 0x80,
 };
 
-static char test_image[] = "/tmp/qtest.XXXXXX";
+static char *test_image;
 
 #define assert_bit_set(data, mask) g_assert_cmphex((data) & (mask), ==, (mask))
 #define assert_bit_clear(data, mask) g_assert_cmphex((data) & (mask), ==, 0)
@@ -608,6 +608,7 @@ int main(int argc, char **argv)
     int ret;
 
     /* Create a temporary raw image */
+    test_image = g_strdup_printf("%s/qtest.XXXXXX", g_get_tmp_dir());
     fd = mkstemp(test_image);
     g_assert(fd >= 0);
     ret = ftruncate(fd, TEST_IMAGE_SIZE);
@@ -640,6 +641,7 @@ int main(int argc, char **argv)
     /* Cleanup */
     qtest_end();
     unlink(test_image);
+    g_free(test_image);
 
     return ret;
 }
diff --git a/tests/qtest/fuzz/virtio_blk_fuzz.c b/tests/qtest/fuzz/virtio_blk_fuzz.c
index 236d078cc8..3e9541a38a 100644
--- a/tests/qtest/fuzz/virtio_blk_fuzz.c
+++ b/tests/qtest/fuzz/virtio_blk_fuzz.c
@@ -181,7 +181,7 @@ static void drive_destroy(void *path)
 static char *drive_create(void)
 {
     int fd, ret;
-    char *t_path = g_strdup("/tmp/qtest.XXXXXX");
+    char *t_path = g_strdup_printf("%s/qtest.XXXXXX", g_get_tmp_dir());
 
     /* Create a temporary raw image */
     fd = mkstemp(t_path);
diff --git a/tests/qtest/hd-geo-test.c b/tests/qtest/hd-geo-test.c
index 413cf964c0..dc5d8422ea 100644
--- a/tests/qtest/hd-geo-test.c
+++ b/tests/qtest/hd-geo-test.c
@@ -27,7 +27,7 @@
 
 static char *create_test_img(int secs)
 {
-    char *template = strdup("/tmp/qtest.XXXXXX");
+    char *template = g_strdup_printf("%s/qtest.XXXXXX", g_get_tmp_dir());
     int fd, ret;
 
     fd = mkstemp(template);
@@ -36,7 +36,7 @@ static char *create_test_img(int secs)
     close(fd);
 
     if (ret) {
-        free(template);
+        g_free(template);
         template = NULL;
     }
 
@@ -422,7 +422,7 @@ static MBRpartitions empty_mbr = { {false, 0, 0, 0, 0, 0, 0, 0, 0},
 
 static char *create_qcow2_with_mbr(MBRpartitions mbr, uint64_t sectors)
 {
-    const char *template = "/tmp/qtest.XXXXXX";
+    const char *template = g_strdup_printf("%s/qtest.XXXXXX", g_get_tmp_dir());
     char *raw_path = strdup(template);
     char *qcow2_path = strdup(template);
     char cmd[100 + 2 * PATH_MAX];
@@ -987,7 +987,7 @@ test_add_done:
     for (i = 0; i < backend_last; i++) {
         if (img_file_name[i]) {
             unlink(img_file_name[i]);
-            free(img_file_name[i]);
+            g_free(img_file_name[i]);
         }
     }
 
diff --git a/tests/qtest/ide-test.c b/tests/qtest/ide-test.c
index 5bcb75a7e5..ebbf8e0126 100644
--- a/tests/qtest/ide-test.c
+++ b/tests/qtest/ide-test.c
@@ -121,8 +121,8 @@ enum {
 static QPCIBus *pcibus = NULL;
 static QGuestAllocator guest_malloc;
 
-static char tmp_path[] = "/tmp/qtest.XXXXXX";
-static char debug_path[] = "/tmp/qtest-blkdebug.XXXXXX";
+static char *tmp_path;
+static char *debug_path;
 
 static QTestState *ide_test_start(const char *cmdline_fmt, ...)
 {
@@ -1015,11 +1015,13 @@ int main(int argc, char **argv)
     int ret;
 
     /* Create temporary blkdebug instructions */
+    debug_path = g_strdup_printf("%s/qtest-blkdebug.XXXXXX", g_get_tmp_dir());
     fd = mkstemp(debug_path);
     g_assert(fd >= 0);
     close(fd);
 
     /* Create a temporary raw image */
+    tmp_path = g_strdup_printf("%s/qtest.XXXXXX", g_get_tmp_dir());
     fd = mkstemp(tmp_path);
     g_assert(fd >= 0);
     ret = ftruncate(fd, TEST_IMAGE_SIZE);
@@ -1049,7 +1051,9 @@ int main(int argc, char **argv)
 
     /* Cleanup */
     unlink(tmp_path);
+    g_free(tmp_path);
     unlink(debug_path);
+    g_free(debug_path);
 
     return ret;
 }
diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
index 7c9fc07de4..34744ace7c 100644
--- a/tests/qtest/libqtest.c
+++ b/tests/qtest/libqtest.c
@@ -265,8 +265,10 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args)
 
     s = g_new(QTestState, 1);
 
-    socket_path = g_strdup_printf("/tmp/qtest-%d.sock", getpid());
-    qmp_socket_path = g_strdup_printf("/tmp/qtest-%d.qmp", getpid());
+    socket_path = g_strdup_printf("%s/qtest-%d.sock",
+                                  g_get_tmp_dir(), getpid());
+    qmp_socket_path = g_strdup_printf("%s/qtest-%d.qmp",
+                                      g_get_tmp_dir(), getpid());
 
     /* It's possible that if an earlier test run crashed it might
      * have left a stale unix socket lying around. Delete any
@@ -390,9 +392,10 @@ QTestState *qtest_initf(const char *fmt, ...)
 QTestState *qtest_init_with_serial(const char *extra_args, int *sock_fd)
 {
     int sock_fd_init;
-    char *sock_path, sock_dir[] = "/tmp/qtest-serial-XXXXXX";
+    char *sock_path, *sock_dir;
     QTestState *qts;
 
+    sock_dir = g_strdup_printf("%s/qtest-serial-XXXXXX", g_get_tmp_dir());
     g_assert_true(g_mkdtemp(sock_dir) != NULL);
     sock_path = g_strdup_printf("%s/sock", sock_dir);
 
@@ -406,6 +409,7 @@ QTestState *qtest_init_with_serial(const char *extra_args, int *sock_fd)
     unlink(sock_path);
     g_free(sock_path);
     rmdir(sock_dir);
+    g_free(sock_dir);
 
     g_assert_true(*sock_fd >= 0);
 
diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index 52988b86eb..5fa4ffeff0 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -2422,7 +2422,8 @@ static bool kvm_dirty_ring_supported(void)
 
 int main(int argc, char **argv)
 {
-    char template[] = "/tmp/migration-test-XXXXXX";
+    char *template = g_strdup_printf("%s/migration-test-XXXXXX",
+                                     g_get_tmp_dir());
     const bool has_kvm = qtest_has_accel("kvm");
     const bool has_uffd = ufd_version_check();
     const char *arch = qtest_get_arch();
@@ -2576,6 +2577,7 @@ int main(int argc, char **argv)
         g_test_message("unable to rmdir: path (%s): %s",
                        tmpfs, strerror(errno));
     }
+    g_free(template);
 
     return ret;
 }
diff --git a/tests/qtest/pflash-cfi02-test.c b/tests/qtest/pflash-cfi02-test.c
index 7fce614b64..6de83717dd 100644
--- a/tests/qtest/pflash-cfi02-test.c
+++ b/tests/qtest/pflash-cfi02-test.c
@@ -56,7 +56,7 @@ typedef struct {
     QTestState *qtest;
 } FlashConfig;
 
-static char image_path[] = "/tmp/qtest.XXXXXX";
+static char *image_path;
 
 /*
  * The pflash implementation allows some parameters to be unspecified. We want
@@ -608,6 +608,7 @@ static void test_cfi_in_autoselect(const void *opaque)
 static void cleanup(void *opaque)
 {
     unlink(image_path);
+    g_free(image_path);
 }
 
 /*
@@ -635,16 +636,18 @@ static const FlashConfig configuration[] = {
 
 int main(int argc, char **argv)
 {
+    image_path = g_strdup_printf("%s/qtest.XXXXXX", g_get_tmp_dir());
     int fd = mkstemp(image_path);
     if (fd == -1) {
         g_printerr("Failed to create temporary file %s: %s\n", image_path,
                    strerror(errno));
+        g_free(image_path);
         exit(EXIT_FAILURE);
     }
     if (ftruncate(fd, UNIFORM_FLASH_SIZE) < 0) {
         int error_code = errno;
         close(fd);
-        unlink(image_path);
+        cleanup(NULL);
         g_printerr("Failed to truncate file %s to %u MB: %s\n", image_path,
                    UNIFORM_FLASH_SIZE, strerror(error_code));
         exit(EXIT_FAILURE);
diff --git a/tests/qtest/qmp-test.c b/tests/qtest/qmp-test.c
index bf7304c7dc..b950dbafaf 100644
--- a/tests/qtest/qmp-test.c
+++ b/tests/qtest/qmp-test.c
@@ -161,11 +161,12 @@ static void test_qmp_protocol(void)
 
 /* Out-of-band tests */
 
-char tmpdir[] = "/tmp/qmp-test-XXXXXX";
+char *tmpdir;
 char *fifo_name;
 
 static void setup_blocking_cmd(void)
 {
+    tmpdir = g_strdup_printf("%s/qmp-test-XXXXXX", g_get_tmp_dir());
     if (!g_mkdtemp(tmpdir)) {
         g_error("g_mkdtemp: %s", strerror(errno));
     }
@@ -179,6 +180,7 @@ static void cleanup_blocking_cmd(void)
 {
     unlink(fifo_name);
     rmdir(tmpdir);
+    g_free(tmpdir);
 }
 
 static void send_cmd_that_blocks(QTestState *s, const char *id)
diff --git a/tests/qtest/vhost-user-blk-test.c b/tests/qtest/vhost-user-blk-test.c
index a81c2a2715..07a4c2d500 100644
--- a/tests/qtest/vhost-user-blk-test.c
+++ b/tests/qtest/vhost-user-blk-test.c
@@ -841,7 +841,8 @@ static char *create_listen_socket(int *fd)
     char *path;
 
     /* No race because our pid makes the path unique */
-    path = g_strdup_printf("/tmp/qtest-%d-sock.XXXXXX", getpid());
+    path = g_strdup_printf("%s/qtest-%d-sock.XXXXXX",
+                           g_get_tmp_dir(), getpid());
     tmp_fd = mkstemp(path);
     g_assert_cmpint(tmp_fd, >=, 0);
     close(tmp_fd);
diff --git a/tests/qtest/vhost-user-test.c b/tests/qtest/vhost-user-test.c
index d7d6cfc9bd..a41168de25 100644
--- a/tests/qtest/vhost-user-test.c
+++ b/tests/qtest/vhost-user-test.c
@@ -482,7 +482,7 @@ static TestServer *test_server_new(const gchar *name,
         struct vhost_user_ops *ops)
 {
     TestServer *server = g_new0(TestServer, 1);
-    char template[] = "/tmp/vhost-test-XXXXXX";
+    char *template = g_strdup_printf("%s/vhost-test-XXXXXX", g_get_tmp_dir());
     const char *tmpfs;
 
     server->context = g_main_context_new();
@@ -501,6 +501,7 @@ static TestServer *test_server_new(const gchar *name,
     server->socket_path = g_strdup_printf("%s/%s.sock", tmpfs, name);
     server->mig_path = g_strdup_printf("%s/%s.mig", tmpfs, name);
     server->chr_name = g_strdup_printf("chr-%s", name);
+    g_free(template);
 
     g_mutex_init(&server->data_mutex);
     g_cond_init(&server->data_cond);
diff --git a/tests/qtest/virtio-blk-test.c b/tests/qtest/virtio-blk-test.c
index dc5eed31c8..8920ce7c46 100644
--- a/tests/qtest/virtio-blk-test.c
+++ b/tests/qtest/virtio-blk-test.c
@@ -49,7 +49,7 @@ static void drive_destroy(void *path)
 static char *drive_create(void)
 {
     int fd, ret;
-    char *t_path = g_strdup("/tmp/qtest.XXXXXX");
+    char *t_path = g_strdup_printf("%s/qtest.XXXXXX", g_get_tmp_dir());
 
     /* Create a temporary raw image */
     fd = mkstemp(t_path);
diff --git a/tests/qtest/virtio-scsi-test.c b/tests/qtest/virtio-scsi-test.c
index 8ceb12aacd..33ab6ec685 100644
--- a/tests/qtest/virtio-scsi-test.c
+++ b/tests/qtest/virtio-scsi-test.c
@@ -268,7 +268,7 @@ static void test_iothread_attach_node(void *obj, void *data,
     QVirtioSCSIPCI *scsi_pci = obj;
     QVirtioSCSI *scsi = &scsi_pci->scsi;
     QVirtioSCSIQueues *vs;
-    char tmp_path[] = "/tmp/qtest.XXXXXX";
+    char *tmp_path = g_strdup_printf("%s/qtest.XXXXXX", g_get_tmp_dir());
     int fd;
     int ret;
 
@@ -309,6 +309,7 @@ static void test_iothread_attach_node(void *obj, void *data,
 fail:
     qvirtio_scsi_pci_free(vs);
     unlink(tmp_path);
+    g_free(tmp_path);
 }
 
 static void *virtio_scsi_hotplug_setup(GString *cmd_line, void *arg)
diff --git a/tests/unit/test-image-locking.c b/tests/unit/test-image-locking.c
index ba057bd66c..795c602ff6 100644
--- a/tests/unit/test-image-locking.c
+++ b/tests/unit/test-image-locking.c
@@ -76,7 +76,7 @@ static void check_locked_bytes(int fd, uint64_t perm_locks,
 static void test_image_locking_basic(void)
 {
     BlockBackend *blk1, *blk2, *blk3;
-    char img_path[] = "/tmp/qtest.XXXXXX";
+    char *img_path = g_strdup_printf("%s/qtest.XXXXXX", g_get_tmp_dir());
     uint64_t perm, shared_perm;
 
     int fd = mkstemp(img_path);
@@ -112,12 +112,13 @@ static void test_image_locking_basic(void)
     blk_unref(blk3);
     close(fd);
     unlink(img_path);
+    g_free(img_path);
 }
 
 static void test_set_perm_abort(void)
 {
     BlockBackend *blk1, *blk2;
-    char img_path[] = "/tmp/qtest.XXXXXX";
+    char *img_path = g_strdup_printf("%s/qtest.XXXXXX", g_get_tmp_dir());
     uint64_t perm, shared_perm;
     int r;
     int fd = mkstemp(img_path);
@@ -140,6 +141,7 @@ static void test_set_perm_abort(void)
     check_locked_bytes(fd, perm, ~shared_perm);
     blk_unref(blk1);
     blk_unref(blk2);
+    g_free(img_path);
 }
 
 int main(int argc, char **argv)
diff --git a/tests/unit/test-qga.c b/tests/unit/test-qga.c
index a05a4628ed..b73d231cd5 100644
--- a/tests/unit/test-qga.c
+++ b/tests/unit/test-qga.c
@@ -59,7 +59,7 @@ fixture_setup(TestFixture *fixture, gconstpointer data, gchar **envp)
 
     fixture->loop = g_main_loop_new(NULL, FALSE);
 
-    fixture->test_dir = g_strdup("/tmp/qgatest.XXXXXX");
+    fixture->test_dir = g_strdup_printf("%s/qgatest.XXXXXX", g_get_tmp_dir());
     g_assert_nonnull(g_mkdtemp(fixture->test_dir));
 
     path = g_build_filename(fixture->test_dir, "sock", NULL);
diff --git a/tests/vhost-user-bridge.c b/tests/vhost-user-bridge.c
index 9b1dab2f28..0da6a6157f 100644
--- a/tests/vhost-user-bridge.c
+++ b/tests/vhost-user-bridge.c
@@ -631,7 +631,7 @@ static void *notifier_thread(void *arg)
 static void
 vubr_host_notifier_setup(VubrDev *dev)
 {
-    char template[] = "/tmp/vubr-XXXXXX";
+    char *template = g_strdup_printf("%s/vubr-XXXXXX", g_get_tmp_dir());
     pthread_t thread;
     size_t length;
     void *addr;
@@ -640,6 +640,7 @@ vubr_host_notifier_setup(VubrDev *dev)
     length = qemu_real_host_page_size() * VHOST_USER_BRIDGE_MAX_QUEUES;
 
     fd = mkstemp(template);
+    g_free(template);
     if (fd < 0) {
         vubr_die("mkstemp()");
     }
-- 
2.34.1



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

* [PATCH 08/51] block/vvfat: Unify the mkdir() call
  2022-08-24  9:39 [PATCH 00/51] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (6 preceding siblings ...)
  2022-08-24  9:39 ` [PATCH 07/51] tests: Avoid using hardcoded /tmp in test cases Bin Meng
@ 2022-08-24  9:39 ` Bin Meng
  2022-08-31 13:08   ` Marc-André Lureau
  2022-08-24  9:39 ` [PATCH 09/51] fsdev/virtfs-proxy-helper: Use g_mkdir_with_parents() Bin Meng
                   ` (42 subsequent siblings)
  50 siblings, 1 reply; 174+ messages in thread
From: Bin Meng @ 2022-08-24  9:39 UTC (permalink / raw)
  To: qemu-devel; +Cc: Bin Meng, Hanna Reitz, Kevin Wolf, qemu-block

From: Bin Meng <bin.meng@windriver.com>

There is a difference in the mkdir() call for win32 and non-win32
platforms, and currently is handled in the codes with #ifdefs.

glib provides a portable g_mkdir_with_parents() API and we can use
it to unify the codes without #ifdefs.

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

 block/vvfat.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/block/vvfat.c b/block/vvfat.c
index d6dd919683..9c389ce5ea 100644
--- a/block/vvfat.c
+++ b/block/vvfat.c
@@ -2726,13 +2726,9 @@ static int handle_renames_and_mkdirs(BDRVVVFATState* s)
             mapping_t* mapping;
             int j, parent_path_len;
 
-#ifdef __MINGW32__
-            if (mkdir(commit->path))
+            if (g_mkdir_with_parents(commit->path, 0755)) {
                 return -5;
-#else
-            if (mkdir(commit->path, 0755))
-                return -5;
-#endif
+            }
 
             mapping = insert_mapping(s, commit->param.mkdir.cluster,
                     commit->param.mkdir.cluster + 1);
-- 
2.34.1



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

* [PATCH 09/51] fsdev/virtfs-proxy-helper: Use g_mkdir_with_parents()
  2022-08-24  9:39 [PATCH 00/51] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (7 preceding siblings ...)
  2022-08-24  9:39 ` [PATCH 08/51] block/vvfat: Unify the mkdir() call Bin Meng
@ 2022-08-24  9:39 ` Bin Meng
  2022-08-26 10:09   ` Christian Schoenebeck
  2022-08-24  9:39 ` [PATCH 10/51] hw/usb: dev-mtp: " Bin Meng
                   ` (41 subsequent siblings)
  50 siblings, 1 reply; 174+ messages in thread
From: Bin Meng @ 2022-08-24  9:39 UTC (permalink / raw)
  To: qemu-devel; +Cc: Bin Meng, Christian Schoenebeck, Greg Kurz

From: Bin Meng <bin.meng@windriver.com>

Use the same g_mkdir_with_parents() call to create a directory on
all platforms.

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

 fsdev/virtfs-proxy-helper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fsdev/virtfs-proxy-helper.c b/fsdev/virtfs-proxy-helper.c
index 2dde27922f..d0cf76d6d1 100644
--- a/fsdev/virtfs-proxy-helper.c
+++ b/fsdev/virtfs-proxy-helper.c
@@ -639,7 +639,7 @@ static int do_create_others(int type, struct iovec *iovec)
         if (retval < 0) {
             goto err_out;
         }
-        retval = mkdir(path.data, mode);
+        retval = g_mkdir_with_parents(path.data, mode);
         break;
     case T_SYMLINK:
         retval = proxy_unmarshal(iovec, offset, "ss", &oldpath, &path);
-- 
2.34.1



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

* [PATCH 10/51] hw/usb: dev-mtp: Use g_mkdir_with_parents()
  2022-08-24  9:39 [PATCH 00/51] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (8 preceding siblings ...)
  2022-08-24  9:39 ` [PATCH 09/51] fsdev/virtfs-proxy-helper: Use g_mkdir_with_parents() Bin Meng
@ 2022-08-24  9:39 ` Bin Meng
  2022-08-31 13:09   ` Marc-André Lureau
  2022-08-24  9:39 ` [PATCH 11/51] qga/commands-posix-ssh: " Bin Meng
                   ` (40 subsequent siblings)
  50 siblings, 1 reply; 174+ messages in thread
From: Bin Meng @ 2022-08-24  9:39 UTC (permalink / raw)
  To: qemu-devel; +Cc: Bin Meng, Gerd Hoffmann

From: Bin Meng <bin.meng@windriver.com>

Use the same g_mkdir_with_parents() call to create a directory on
all platforms.

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

 hw/usb/dev-mtp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/usb/dev-mtp.c b/hw/usb/dev-mtp.c
index 5831395cef..97c894f231 100644
--- a/hw/usb/dev-mtp.c
+++ b/hw/usb/dev-mtp.c
@@ -1622,7 +1622,7 @@ static void usb_mtp_write_data(MTPState *s, uint32_t handle)
         if (s->dataset.filename) {
             path = g_strdup_printf("%s/%s", parent->path, s->dataset.filename);
             if (s->dataset.format == FMT_ASSOCIATION) {
-                ret = mkdir(path, mask);
+                ret = g_mkdir_with_parents(path, mask);
                 if (!ret) {
                     usb_mtp_queue_result(s, RES_OK, d->trans, 3,
                                          QEMU_STORAGE_ID,
-- 
2.34.1



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

* [PATCH 11/51] qga/commands-posix-ssh: Use g_mkdir_with_parents()
  2022-08-24  9:39 [PATCH 00/51] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (9 preceding siblings ...)
  2022-08-24  9:39 ` [PATCH 10/51] hw/usb: dev-mtp: " Bin Meng
@ 2022-08-24  9:39 ` Bin Meng
  2022-08-24 14:41   ` Konstantin Kostiuk
  2022-08-24  9:39 ` [PATCH 12/51] tests: " Bin Meng
                   ` (39 subsequent siblings)
  50 siblings, 1 reply; 174+ messages in thread
From: Bin Meng @ 2022-08-24  9:39 UTC (permalink / raw)
  To: qemu-devel; +Cc: Bin Meng, Konstantin Kostiuk, Michael Roth

From: Bin Meng <bin.meng@windriver.com>

g_mkdir() is a deprecated API and newer codes should use
g_mkdir_with_parents().

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

 qga/commands-posix-ssh.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/qga/commands-posix-ssh.c b/qga/commands-posix-ssh.c
index f3a580b8cc..2460112a38 100644
--- a/qga/commands-posix-ssh.c
+++ b/qga/commands-posix-ssh.c
@@ -59,7 +59,7 @@ static bool
 mkdir_for_user(const char *path, const struct passwd *p,
                mode_t mode, Error **errp)
 {
-    if (g_mkdir(path, mode) == -1) {
+    if (g_mkdir_with_parents(path, mode) == -1) {
         error_setg(errp, "failed to create directory '%s': %s",
                    path, g_strerror(errno));
         return false;
-- 
2.34.1



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

* [PATCH 12/51] tests: Use g_mkdir_with_parents()
  2022-08-24  9:39 [PATCH 00/51] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (10 preceding siblings ...)
  2022-08-24  9:39 ` [PATCH 11/51] qga/commands-posix-ssh: " Bin Meng
@ 2022-08-24  9:39 ` Bin Meng
  2022-08-24 17:58   ` Dr. David Alan Gilbert
  2022-08-24  9:39 ` [PATCH 13/51] tests/qtest: migration-test: Handle link() for win32 Bin Meng
                   ` (38 subsequent siblings)
  50 siblings, 1 reply; 174+ messages in thread
From: Bin Meng @ 2022-08-24  9:39 UTC (permalink / raw)
  To: qemu-devel
  Cc: Bin Meng, Daniel P. Berrangé,
	Dr. David Alan Gilbert, Juan Quintela, Laurent Vivier,
	Paolo Bonzini, Thomas Huth

From: Bin Meng <bin.meng@windriver.com>

Use the same g_mkdir_with_parents() call to create a directory on
all platforms.

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

 tests/migration/stress.c              | 2 +-
 tests/qtest/migration-test.c          | 6 +++---
 tests/unit/test-crypto-tlscredsx509.c | 4 ++--
 tests/unit/test-crypto-tlssession.c   | 6 +++---
 tests/unit/test-io-channel-tls.c      | 6 +++---
 5 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/tests/migration/stress.c b/tests/migration/stress.c
index b7240a15c8..88acf8dc25 100644
--- a/tests/migration/stress.c
+++ b/tests/migration/stress.c
@@ -232,7 +232,7 @@ static void stress(unsigned long long ramsizeGB, int ncpus)
 
 static int mount_misc(const char *fstype, const char *dir)
 {
-    if (mkdir(dir, 0755) < 0 && errno != EEXIST) {
+    if (g_mkdir_with_parents(dir, 0755) < 0 && errno != EEXIST) {
         fprintf(stderr, "%s (%05d): ERROR: cannot create %s: %s\n",
                 argv0, gettid(), dir, strerror(errno));
         return -1;
diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index 5fa4ffeff0..38356d4aba 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -761,14 +761,14 @@ test_migrate_tls_psk_start_common(QTestState *from,
     data->workdir = g_strdup_printf("%s/tlscredspsk0", tmpfs);
     data->pskfile = g_strdup_printf("%s/%s", data->workdir,
                                     QCRYPTO_TLS_CREDS_PSKFILE);
-    mkdir(data->workdir, 0700);
+    g_mkdir_with_parents(data->workdir, 0700);
     test_tls_psk_init(data->pskfile);
 
     if (mismatch) {
         data->workdiralt = g_strdup_printf("%s/tlscredspskalt0", tmpfs);
         data->pskfilealt = g_strdup_printf("%s/%s", data->workdiralt,
                                            QCRYPTO_TLS_CREDS_PSKFILE);
-        mkdir(data->workdiralt, 0700);
+        g_mkdir_with_parents(data->workdiralt, 0700);
         test_tls_psk_init_alt(data->pskfilealt);
     }
 
@@ -873,7 +873,7 @@ test_migrate_tls_x509_start_common(QTestState *from,
         data->clientcert = g_strdup_printf("%s/client-cert.pem", data->workdir);
     }
 
-    mkdir(data->workdir, 0700);
+    g_mkdir_with_parents(data->workdir, 0700);
 
     test_tls_init(data->keyfile);
     g_assert(link(data->keyfile, data->serverkey) == 0);
diff --git a/tests/unit/test-crypto-tlscredsx509.c b/tests/unit/test-crypto-tlscredsx509.c
index aab4149b56..3c25d75ca1 100644
--- a/tests/unit/test-crypto-tlscredsx509.c
+++ b/tests/unit/test-crypto-tlscredsx509.c
@@ -75,7 +75,7 @@ static void test_tls_creds(const void *opaque)
     QCryptoTLSCreds *creds;
 
 #define CERT_DIR "tests/test-crypto-tlscredsx509-certs/"
-    mkdir(CERT_DIR, 0700);
+    g_mkdir_with_parents(CERT_DIR, 0700);
 
     unlink(CERT_DIR QCRYPTO_TLS_CREDS_X509_CA_CERT);
     if (data->isServer) {
@@ -141,7 +141,7 @@ int main(int argc, char **argv)
     g_test_init(&argc, &argv, NULL);
     g_setenv("GNUTLS_FORCE_FIPS_MODE", "2", 1);
 
-    mkdir(WORKDIR, 0700);
+    g_mkdir_with_parents(WORKDIR, 0700);
 
     test_tls_init(KEYFILE);
 
diff --git a/tests/unit/test-crypto-tlssession.c b/tests/unit/test-crypto-tlssession.c
index f222959d36..615a1344b4 100644
--- a/tests/unit/test-crypto-tlssession.c
+++ b/tests/unit/test-crypto-tlssession.c
@@ -249,8 +249,8 @@ static void test_crypto_tls_session_x509(const void *opaque)
 
 #define CLIENT_CERT_DIR "tests/test-crypto-tlssession-client/"
 #define SERVER_CERT_DIR "tests/test-crypto-tlssession-server/"
-    mkdir(CLIENT_CERT_DIR, 0700);
-    mkdir(SERVER_CERT_DIR, 0700);
+    g_mkdir_with_parents(CLIENT_CERT_DIR, 0700);
+    g_mkdir_with_parents(SERVER_CERT_DIR, 0700);
 
     unlink(SERVER_CERT_DIR QCRYPTO_TLS_CREDS_X509_CA_CERT);
     unlink(SERVER_CERT_DIR QCRYPTO_TLS_CREDS_X509_SERVER_CERT);
@@ -398,7 +398,7 @@ int main(int argc, char **argv)
     g_test_init(&argc, &argv, NULL);
     g_setenv("GNUTLS_FORCE_FIPS_MODE", "2", 1);
 
-    mkdir(WORKDIR, 0700);
+    g_mkdir_with_parents(WORKDIR, 0700);
 
     test_tls_init(KEYFILE);
     test_tls_psk_init(PSKFILE);
diff --git a/tests/unit/test-io-channel-tls.c b/tests/unit/test-io-channel-tls.c
index f6fb988c01..cc39247556 100644
--- a/tests/unit/test-io-channel-tls.c
+++ b/tests/unit/test-io-channel-tls.c
@@ -125,8 +125,8 @@ static void test_io_channel_tls(const void *opaque)
 
 #define CLIENT_CERT_DIR "tests/test-io-channel-tls-client/"
 #define SERVER_CERT_DIR "tests/test-io-channel-tls-server/"
-    mkdir(CLIENT_CERT_DIR, 0700);
-    mkdir(SERVER_CERT_DIR, 0700);
+    g_mkdir_with_parents(CLIENT_CERT_DIR, 0700);
+    g_mkdir_with_parents(SERVER_CERT_DIR, 0700);
 
     unlink(SERVER_CERT_DIR QCRYPTO_TLS_CREDS_X509_CA_CERT);
     unlink(SERVER_CERT_DIR QCRYPTO_TLS_CREDS_X509_SERVER_CERT);
@@ -273,7 +273,7 @@ int main(int argc, char **argv)
     g_test_init(&argc, &argv, NULL);
     g_setenv("GNUTLS_FORCE_FIPS_MODE", "2", 1);
 
-    mkdir(WORKDIR, 0700);
+    g_mkdir_with_parents(WORKDIR, 0700);
 
     test_tls_init(KEYFILE);
 
-- 
2.34.1



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

* [PATCH 13/51] tests/qtest: migration-test: Handle link() for win32
  2022-08-24  9:39 [PATCH 00/51] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (11 preceding siblings ...)
  2022-08-24  9:39 ` [PATCH 12/51] tests: " Bin Meng
@ 2022-08-24  9:39 ` Bin Meng
  2022-08-24 18:41   ` Dr. David Alan Gilbert
  2022-08-24  9:39 ` [PATCH 14/51] backends/tpm: Exclude headers and macros that don't exist on win32 Bin Meng
                   ` (37 subsequent siblings)
  50 siblings, 1 reply; 174+ messages in thread
From: Bin Meng @ 2022-08-24  9:39 UTC (permalink / raw)
  To: qemu-devel
  Cc: Bin Meng, Dr. David Alan Gilbert, Juan Quintela, Laurent Vivier,
	Paolo Bonzini, Thomas Huth

From: Bin Meng <bin.meng@windriver.com>

Windows does not provide a link() API like POSIX. Instead it provides
a similar API CreateHardLink() that does the same thing, but with
different argument order and return value.

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

 tests/qtest/migration-test.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index 38356d4aba..af9250750b 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -876,9 +876,17 @@ test_migrate_tls_x509_start_common(QTestState *from,
     g_mkdir_with_parents(data->workdir, 0700);
 
     test_tls_init(data->keyfile);
+#ifndef _WIN32
     g_assert(link(data->keyfile, data->serverkey) == 0);
+#else
+    g_assert(CreateHardLink(data->serverkey, data->keyfile, NULL) != 0);
+#endif
     if (args->clientcert) {
+#ifndef _WIN32
         g_assert(link(data->keyfile, data->clientkey) == 0);
+#else
+        g_assert(CreateHardLink(data->clientkey, data->keyfile, NULL) != 0);
+#endif
     }
 
     TLS_ROOT_REQ_SIMPLE(cacertreq, data->cacert);
-- 
2.34.1



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

* [PATCH 14/51] backends/tpm: Exclude headers and macros that don't exist on win32
  2022-08-24  9:39 [PATCH 00/51] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (12 preceding siblings ...)
  2022-08-24  9:39 ` [PATCH 13/51] tests/qtest: migration-test: Handle link() for win32 Bin Meng
@ 2022-08-24  9:39 ` Bin Meng
  2022-08-24 12:35   ` Stefan Berger
  2022-08-24  9:39 ` [PATCH 15/51] tests/qtest: Adapt {m48t59,rtc}-test cases for win32 Bin Meng
                   ` (36 subsequent siblings)
  50 siblings, 1 reply; 174+ messages in thread
From: Bin Meng @ 2022-08-24  9:39 UTC (permalink / raw)
  To: qemu-devel; +Cc: Bin Meng, Stefan Berger

From: Bin Meng <bin.meng@windriver.com>

These headers and macros do not exist on Windows. Exclude them.

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

 backends/tpm/tpm_ioctl.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/backends/tpm/tpm_ioctl.h b/backends/tpm/tpm_ioctl.h
index bd6c12cb86..d67bf0283b 100644
--- a/backends/tpm/tpm_ioctl.h
+++ b/backends/tpm/tpm_ioctl.h
@@ -9,8 +9,10 @@
 #ifndef TPM_IOCTL_H
 #define TPM_IOCTL_H
 
+#ifndef _WIN32
 #include <sys/uio.h>
 #include <sys/ioctl.h>
+#endif
 
 #ifdef HAVE_SYS_IOCCOM_H
 #include <sys/ioccom.h>
@@ -222,6 +224,7 @@ typedef struct ptm_setbuffersize ptm_setbuffersize;
 #define PTM_CAP_SET_DATAFD         (1 << 12)
 #define PTM_CAP_SET_BUFFERSIZE     (1 << 13)
 
+#ifndef _WIN32
 enum {
     PTM_GET_CAPABILITY     = _IOR('P', 0, ptm_cap),
     PTM_INIT               = _IOWR('P', 1, ptm_init),
@@ -241,6 +244,7 @@ enum {
     PTM_SET_DATAFD         = _IOR('P', 15, ptm_res),
     PTM_SET_BUFFERSIZE     = _IOWR('P', 16, ptm_setbuffersize),
 };
+#endif
 
 /*
  * Commands used by the non-CUSE TPMs
-- 
2.34.1



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

* [PATCH 15/51] tests/qtest: Adapt {m48t59,rtc}-test cases for win32
  2022-08-24  9:39 [PATCH 00/51] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (13 preceding siblings ...)
  2022-08-24  9:39 ` [PATCH 14/51] backends/tpm: Exclude headers and macros that don't exist on win32 Bin Meng
@ 2022-08-24  9:39 ` Bin Meng
  2022-08-25  8:20   ` Thomas Huth
  2022-08-24  9:39 ` [PATCH 16/51] tests/qtest: Build e1000e-test for posix only Bin Meng
                   ` (35 subsequent siblings)
  50 siblings, 1 reply; 174+ messages in thread
From: Bin Meng @ 2022-08-24  9:39 UTC (permalink / raw)
  To: qemu-devel; +Cc: Bin Meng, Laurent Vivier, Paolo Bonzini, Thomas Huth

From: Bin Meng <bin.meng@windriver.com>

There is no tm_gmtoff member in 'struct tm' on Windows.
Update rtc-test.c and m48t59-test.c accordingly.

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

 tests/qtest/m48t59-test.c | 2 +-
 tests/qtest/rtc-test.c    | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/tests/qtest/m48t59-test.c b/tests/qtest/m48t59-test.c
index b94a1230f7..843d2ced8e 100644
--- a/tests/qtest/m48t59-test.c
+++ b/tests/qtest/m48t59-test.c
@@ -137,7 +137,7 @@ static void cmos_get_date_time(QTestState *s, struct tm *date)
     date->tm_mday = mday;
     date->tm_mon = mon - 1;
     date->tm_year = base_year + year - 1900;
-#ifndef __sun__
+#if !defined(__sun__) && !defined(_WIN32)
     date->tm_gmtoff = 0;
 #endif
 
diff --git a/tests/qtest/rtc-test.c b/tests/qtest/rtc-test.c
index 8126ab1bdb..02ed4e1238 100644
--- a/tests/qtest/rtc-test.c
+++ b/tests/qtest/rtc-test.c
@@ -111,7 +111,7 @@ static void cmos_get_date_time(struct tm *date)
     date->tm_mday = mday;
     date->tm_mon = mon - 1;
     date->tm_year = base_year + year - 1900;
-#ifndef __sun__
+#if !defined(__sun__) && !defined(_WIN32)
     date->tm_gmtoff = 0;
 #endif
 
-- 
2.34.1



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

* [PATCH 16/51] tests/qtest: Build e1000e-test for posix only
  2022-08-24  9:39 [PATCH 00/51] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (14 preceding siblings ...)
  2022-08-24  9:39 ` [PATCH 15/51] tests/qtest: Adapt {m48t59,rtc}-test cases for win32 Bin Meng
@ 2022-08-24  9:39 ` Bin Meng
  2022-08-25 10:59   ` Thomas Huth
  2022-08-24  9:39 ` [PATCH 17/51] tests/qtest: Build virtio-net-test " Bin Meng
                   ` (34 subsequent siblings)
  50 siblings, 1 reply; 174+ messages in thread
From: Bin Meng @ 2022-08-24  9:39 UTC (permalink / raw)
  To: qemu-devel; +Cc: Bin Meng, Laurent Vivier, Paolo Bonzini, Thomas Huth

From: Bin Meng <bin.meng@windriver.com>

The whole e1000e-test test case relies on socketpair() which does
not exist on win32.

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

 tests/qtest/meson.build | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
index be4b30dea2..9d0f82bf1c 100644
--- a/tests/qtest/meson.build
+++ b/tests/qtest/meson.build
@@ -239,7 +239,6 @@ qos_test_ss.add(
   'adm1272-test.c',
   'ds1338-test.c',
   'e1000-test.c',
-  'e1000e-test.c',
   'eepro100-test.c',
   'es1370-test.c',
   'ipoctal232-test.c',
@@ -267,6 +266,9 @@ qos_test_ss.add(
   'virtio-iommu-test.c',
   'vmxnet3-test.c',
 )
+if config_host.has_key('CONFIG_POSIX')
+  qos_test_ss.add(files('e1000e-test.c'))
+endif
 if have_virtfs
   qos_test_ss.add(files('virtio-9p-test.c'))
 endif
-- 
2.34.1



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

* [PATCH 17/51] tests/qtest: Build virtio-net-test for posix only
  2022-08-24  9:39 [PATCH 00/51] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (15 preceding siblings ...)
  2022-08-24  9:39 ` [PATCH 16/51] tests/qtest: Build e1000e-test for posix only Bin Meng
@ 2022-08-24  9:39 ` Bin Meng
  2022-08-25 11:27   ` Thomas Huth
  2022-08-31 13:25   ` Marc-André Lureau
  2022-08-24  9:39 ` [PATCH 18/51] tests/qtest: Build cases that use memory-backend-file " Bin Meng
                   ` (33 subsequent siblings)
  50 siblings, 2 replies; 174+ messages in thread
From: Bin Meng @ 2022-08-24  9:39 UTC (permalink / raw)
  To: qemu-devel
  Cc: Bin Meng, Jason Wang, Laurent Vivier, Paolo Bonzini, Thomas Huth

From: Bin Meng <bin.meng@windriver.com>

All of the virtio-net-test test cases require socketpair() to do the
test setup.

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

 tests/qtest/virtio-net-test.c | 6 ------
 tests/qtest/meson.build       | 3 +--
 2 files changed, 1 insertion(+), 8 deletions(-)

diff --git a/tests/qtest/virtio-net-test.c b/tests/qtest/virtio-net-test.c
index 6ded252901..d44c3d9666 100644
--- a/tests/qtest/virtio-net-test.c
+++ b/tests/qtest/virtio-net-test.c
@@ -26,8 +26,6 @@
 #define QVIRTIO_NET_TIMEOUT_US (30 * 1000 * 1000)
 #define VNET_HDR_SIZE sizeof(struct virtio_net_hdr_mrg_rxbuf)
 
-#ifndef _WIN32
-
 static void rx_test(QVirtioDevice *dev,
                     QGuestAllocator *alloc, QVirtQueue *vq,
                     int socket)
@@ -165,8 +163,6 @@ static void stop_cont_test(void *obj, void *data, QGuestAllocator *t_alloc)
     rx_stop_cont_test(dev, t_alloc, rx, sv[0]);
 }
 
-#endif
-
 static void hotplug(void *obj, void *data, QGuestAllocator *t_alloc)
 {
     QVirtioPCIDevice *dev = obj;
@@ -324,10 +320,8 @@ static void register_virtio_net_test(void)
     };
 
     qos_add_test("hotplug", "virtio-net-pci", hotplug, &opts);
-#ifndef _WIN32
     qos_add_test("basic", "virtio-net", send_recv_test, &opts);
     qos_add_test("rx_stop_cont", "virtio-net", stop_cont_test, &opts);
-#endif
     qos_add_test("announce-self", "virtio-net", announce_self, &opts);
 
     /* These tests do not need a loopback backend.  */
diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
index 9d0f82bf1c..72bb9e21f3 100644
--- a/tests/qtest/meson.build
+++ b/tests/qtest/meson.build
@@ -259,7 +259,6 @@ qos_test_ss.add(
   'usb-hcd-ohci-test.c',
   'virtio-test.c',
   'virtio-blk-test.c',
-  'virtio-net-test.c',
   'virtio-rng-test.c',
   'virtio-scsi-test.c',
   'virtio-serial-test.c',
@@ -267,7 +266,7 @@ qos_test_ss.add(
   'vmxnet3-test.c',
 )
 if config_host.has_key('CONFIG_POSIX')
-  qos_test_ss.add(files('e1000e-test.c'))
+  qos_test_ss.add(files('e1000e-test.c', 'virtio-net-test.c'))
 endif
 if have_virtfs
   qos_test_ss.add(files('virtio-9p-test.c'))
-- 
2.34.1



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

* [PATCH 18/51] tests/qtest: Build cases that use memory-backend-file for posix only
  2022-08-24  9:39 [PATCH 00/51] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (16 preceding siblings ...)
  2022-08-24  9:39 ` [PATCH 17/51] tests/qtest: Build virtio-net-test " Bin Meng
@ 2022-08-24  9:39 ` Bin Meng
  2022-08-25 12:39   ` Thomas Huth
  2022-08-24  9:39 ` [PATCH 19/51] tests/qtest: Build test-filter-{mirror, redirector} cases " Bin Meng
                   ` (32 subsequent siblings)
  50 siblings, 1 reply; 174+ messages in thread
From: Bin Meng @ 2022-08-24  9:39 UTC (permalink / raw)
  To: qemu-devel
  Cc: Bin Meng, Ani Sinha, Igor Mammedov, Laurent Vivier,
	Michael S. Tsirkin, Paolo Bonzini, Thomas Huth

From: Bin Meng <bin.meng@windriver.com>

As backends/meson.build tells us, hostmem-file.c is only supported on
POSIX platforms, hence any test case that utilizes the memory backend
file should be guarded by CONFIG_POSIX too.

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

 tests/qtest/bios-tables-test.c | 10 ++++++++++
 tests/qtest/cxl-test.c         |  4 ++++
 tests/qtest/meson.build        |  3 ++-
 3 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/tests/qtest/bios-tables-test.c b/tests/qtest/bios-tables-test.c
index 7c5f736b51..36783966b0 100644
--- a/tests/qtest/bios-tables-test.c
+++ b/tests/qtest/bios-tables-test.c
@@ -1461,6 +1461,7 @@ static void test_acpi_piix4_tcg_acpi_hmat(void)
     test_acpi_tcg_acpi_hmat(MACHINE_PC);
 }
 
+#ifdef CONFIG_POSIX
 static void test_acpi_erst(const char *machine)
 {
     gchar *tmp_path = g_dir_make_tmp("qemu-test-erst.XXXXXX", NULL);
@@ -1511,6 +1512,7 @@ static void test_acpi_microvm_acpi_erst(void)
     g_free(tmp_path);
     free_test_data(&data);
 }
+#endif /* CONFIG_POSIX */
 
 static void test_acpi_virt_tcg(void)
 {
@@ -1551,6 +1553,7 @@ static void test_acpi_q35_viot(void)
     free_test_data(&data);
 }
 
+#ifdef CONFIG_POSIX
 static void test_acpi_q35_cxl(void)
 {
     gchar *tmp_path = g_dir_make_tmp("qemu-test-cxl.XXXXXX", NULL);
@@ -1593,6 +1596,7 @@ static void test_acpi_q35_cxl(void)
     g_free(tmp_path);
     free_test_data(&data);
 }
+#endif /* CONFIG_POSIX */
 
 static void test_acpi_virt_viot(void)
 {
@@ -1805,8 +1809,10 @@ int main(int argc, char *argv[])
         qtest_add_func("acpi/q35/dimmpxm", test_acpi_q35_tcg_dimm_pxm);
         qtest_add_func("acpi/piix4/acpihmat", test_acpi_piix4_tcg_acpi_hmat);
         qtest_add_func("acpi/q35/acpihmat", test_acpi_q35_tcg_acpi_hmat);
+#ifdef CONFIG_POSIX
         qtest_add_func("acpi/piix4/acpierst", test_acpi_piix4_acpi_erst);
         qtest_add_func("acpi/q35/acpierst", test_acpi_q35_acpi_erst);
+#endif
         qtest_add_func("acpi/q35/applesmc", test_acpi_q35_applesmc);
         qtest_add_func("acpi/q35/pvpanic-isa", test_acpi_q35_pvpanic_isa);
         qtest_add_func("acpi/microvm", test_acpi_microvm_tcg);
@@ -1818,7 +1824,9 @@ int main(int argc, char *argv[])
             qtest_add_func("acpi/q35/ivrs", test_acpi_q35_tcg_ivrs);
             if (strcmp(arch, "x86_64") == 0) {
                 qtest_add_func("acpi/microvm/pcie", test_acpi_microvm_pcie_tcg);
+#ifdef CONFIG_POSIX
                 qtest_add_func("acpi/microvm/acpierst", test_acpi_microvm_acpi_erst);
+#endif
             }
         }
         if (has_kvm) {
@@ -1826,7 +1834,9 @@ int main(int argc, char *argv[])
             qtest_add_func("acpi/q35/kvm/dmar", test_acpi_q35_kvm_dmar);
         }
         qtest_add_func("acpi/q35/viot", test_acpi_q35_viot);
+#ifdef CONFIG_POSIX
         qtest_add_func("acpi/q35/cxl", test_acpi_q35_cxl);
+#endif
         qtest_add_func("acpi/q35/slic", test_acpi_q35_slic);
     } else if (strcmp(arch, "aarch64") == 0) {
         if (has_tcg) {
diff --git a/tests/qtest/cxl-test.c b/tests/qtest/cxl-test.c
index b3733cdb5f..4b4e7e5088 100644
--- a/tests/qtest/cxl-test.c
+++ b/tests/qtest/cxl-test.c
@@ -89,6 +89,7 @@ static void cxl_2root_port(void)
     qtest_end();
 }
 
+#ifdef CONFIG_POSIX
 static void cxl_t3d(void)
 {
     g_autoptr(GString) cmdline = g_string_new(NULL);
@@ -136,6 +137,7 @@ static void cxl_2pxb_4rp_4t3d(void)
     qtest_start(cmdline->str);
     qtest_end();
 }
+#endif /* CONFIG_POSIX */
 
 int main(int argc, char **argv)
 {
@@ -147,8 +149,10 @@ int main(int argc, char **argv)
     qtest_add_func("/pci/cxl/pxb_x2_with_window", cxl_2pxb_with_window);
     qtest_add_func("/pci/cxl/rp", cxl_root_port);
     qtest_add_func("/pci/cxl/rp_x2", cxl_2root_port);
+#ifdef CONFIG_POSIX
     qtest_add_func("/pci/cxl/type3_device", cxl_t3d);
     qtest_add_func("/pci/cxl/rp_x2_type3_x2", cxl_1pxb_2rp_2t3d);
     qtest_add_func("/pci/cxl/pxb_x2_root_port_x4_type3_x4", cxl_2pxb_4rp_4t3d);
+#endif
     return g_test_run();
 }
diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
index 72bb9e21f3..9e484e60ba 100644
--- a/tests/qtest/meson.build
+++ b/tests/qtest/meson.build
@@ -71,7 +71,8 @@ qtests_i386 = \
   (config_all_devices.has_key('CONFIG_SB16') ? ['fuzz-sb16-test'] : []) +                   \
   (config_all_devices.has_key('CONFIG_SDHCI_PCI') ? ['fuzz-sdcard-test'] : []) +            \
   (config_all_devices.has_key('CONFIG_ESP_PCI') ? ['am53c974-test'] : []) +                 \
-  (config_all_devices.has_key('CONFIG_ACPI_ERST') ? ['erst-test'] : []) +                        \
+  (config_host.has_key('CONFIG_POSIX') and                                                  \
+   config_all_devices.has_key('CONFIG_ACPI_ERST') ? ['erst-test'] : []) +                   \
   (config_all_devices.has_key('CONFIG_VIRTIO_NET') and                                      \
    config_all_devices.has_key('CONFIG_Q35') and                                             \
    config_all_devices.has_key('CONFIG_VIRTIO_PCI') and                                      \
-- 
2.34.1



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

* [PATCH 19/51] tests/qtest: Build test-filter-{mirror, redirector} cases for posix only
  2022-08-24  9:39 [PATCH 00/51] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (17 preceding siblings ...)
  2022-08-24  9:39 ` [PATCH 18/51] tests/qtest: Build cases that use memory-backend-file " Bin Meng
@ 2022-08-24  9:39 ` Bin Meng
  2022-08-25 11:37   ` Thomas Huth
  2022-08-31 13:27   ` Marc-André Lureau
  2022-08-24  9:39 ` [PATCH 20/51] tests/qtest: i440fx-test: Skip running request_{bios, pflash} for win32 Bin Meng
                   ` (31 subsequent siblings)
  50 siblings, 2 replies; 174+ messages in thread
From: Bin Meng @ 2022-08-24  9:39 UTC (permalink / raw)
  To: qemu-devel; +Cc: Bin Meng, Laurent Vivier, Paolo Bonzini, Thomas Huth

From: Bin Meng <bin.meng@windriver.com>

The test-filter-{mirror,redirector} cases use socketpair() API that
is only available on POSIX and should only be built for POSIX.

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

 tests/qtest/meson.build | 28 ++++++++++++++++++----------
 1 file changed, 18 insertions(+), 10 deletions(-)

diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
index 9e484e60ba..c97da5a062 100644
--- a/tests/qtest/meson.build
+++ b/tests/qtest/meson.build
@@ -42,6 +42,7 @@ qtests_cxl = \
 qtests_i386 = \
   (slirp.found() ? ['pxe-test', 'test-netfilter'] : []) +             \
   (config_host.has_key('CONFIG_POSIX') ? ['test-filter-mirror'] : []) +                     \
+  (config_host.has_key('CONFIG_POSIX') ? ['test-filter-redirector'] : []) +                 \
   (have_tools ? ['ahci-test'] : []) +                                                       \
   (config_all_devices.has_key('CONFIG_ISA_TESTDEV') ? ['endianness-test'] : []) +           \
   (config_all_devices.has_key('CONFIG_SGA') ? ['boot-serial-test'] : []) +                  \
@@ -95,8 +96,7 @@ qtests_i386 = \
    'vmgenid-test',
    'migration-test',
    'test-x86-cpuid-compat',
-   'numa-test',
-   'test-filter-redirector'
+   'numa-test'
   ]
 
 if dbus_display
@@ -120,29 +120,34 @@ endif
 qtests_x86_64 = qtests_i386
 
 qtests_alpha = ['boot-serial-test'] + \
-  ['test-filter-mirror', 'test-filter-redirector'] + \
+  (config_host.has_key('CONFIG_POSIX') ? ['test-filter-mirror'] : []) +     \
+  (config_host.has_key('CONFIG_POSIX') ? ['test-filter-redirector'] : []) + \
   (slirp.found() ? ['test-netfilter'] : []) + \
   (config_all_devices.has_key('CONFIG_VGA') ? ['display-vga-test'] : [])
 
 qtests_avr = [ 'boot-serial-test' ]
 
 qtests_hppa = ['boot-serial-test'] + \
-  ['test-filter-mirror', 'test-filter-redirector'] + \
+  (config_host.has_key('CONFIG_POSIX') ? ['test-filter-mirror'] : []) +     \
+  (config_host.has_key('CONFIG_POSIX') ? ['test-filter-redirector'] : []) + \
   (slirp.found() ? ['test-netfilter'] : []) + \
   (config_all_devices.has_key('CONFIG_VGA') ? ['display-vga-test'] : [])
 
 qtests_m68k = ['boot-serial-test'] + \
-  ['test-filter-mirror', 'test-filter-redirector'] + \
+  (config_host.has_key('CONFIG_POSIX') ? ['test-filter-mirror'] : []) +     \
+  (config_host.has_key('CONFIG_POSIX') ? ['test-filter-redirector'] : []) + \
   (slirp.found() ? ['test-netfilter'] : [])
 
 qtests_microblaze = ['boot-serial-test'] + \
-  ['test-filter-mirror', 'test-filter-redirector'] + \
+  (config_host.has_key('CONFIG_POSIX') ? ['test-filter-mirror'] : []) +     \
+  (config_host.has_key('CONFIG_POSIX') ? ['test-filter-redirector'] : []) + \
   (slirp.found() ? ['test-netfilter'] : [])
 
 qtests_microblazeel = qtests_microblaze
 
 qtests_mips = \
-  ['test-filter-mirror', 'test-filter-redirector'] + \
+  (config_host.has_key('CONFIG_POSIX') ? ['test-filter-mirror'] : []) +     \
+  (config_host.has_key('CONFIG_POSIX') ? ['test-filter-redirector'] : []) + \
   (slirp.found() ? ['test-netfilter'] : []) + \
   (config_all_devices.has_key('CONFIG_ISA_TESTDEV') ? ['endianness-test'] : []) +            \
   (config_all_devices.has_key('CONFIG_VGA') ? ['display-vga-test'] : [])
@@ -152,7 +157,8 @@ qtests_mips64 = qtests_mips
 qtests_mips64el = qtests_mips
 
 qtests_ppc = \
-  ['test-filter-mirror', 'test-filter-redirector'] + \
+  (config_host.has_key('CONFIG_POSIX') ? ['test-filter-mirror'] : []) +     \
+  (config_host.has_key('CONFIG_POSIX') ? ['test-filter-redirector'] : []) + \
   (slirp.found() ? ['test-netfilter'] : []) + \
   (config_all_devices.has_key('CONFIG_ISA_TESTDEV') ? ['endianness-test'] : []) +            \
   (config_all_devices.has_key('CONFIG_M48T59') ? ['m48t59-test'] : []) +                     \
@@ -174,13 +180,15 @@ qtests_sh4 = (config_all_devices.has_key('CONFIG_ISA_TESTDEV') ? ['endianness-te
 qtests_sh4eb = (config_all_devices.has_key('CONFIG_ISA_TESTDEV') ? ['endianness-test'] : [])
 
 qtests_sparc = ['prom-env-test', 'm48t59-test', 'boot-serial-test'] + \
-  ['test-filter-mirror', 'test-filter-redirector'] + \
+  (config_host.has_key('CONFIG_POSIX') ? ['test-filter-mirror'] : []) +     \
+  (config_host.has_key('CONFIG_POSIX') ? ['test-filter-redirector'] : []) + \
   (slirp.found() ? ['test-netfilter'] : [])
 
 qtests_sparc64 = \
   (config_all_devices.has_key('CONFIG_ISA_TESTDEV') ? ['endianness-test'] : []) +            \
   (slirp.found() ? ['test-netfilter'] : []) + \
-  ['test-filter-mirror', 'test-filter-redirector'] + \
+  (config_host.has_key('CONFIG_POSIX') ? ['test-filter-mirror'] : []) +     \
+  (config_host.has_key('CONFIG_POSIX') ? ['test-filter-redirector'] : []) + \
   ['prom-env-test', 'boot-serial-test']
 
 qtests_npcm7xx = \
-- 
2.34.1



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

* [PATCH 20/51] tests/qtest: i440fx-test: Skip running request_{bios, pflash} for win32
  2022-08-24  9:39 [PATCH 00/51] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (18 preceding siblings ...)
  2022-08-24  9:39 ` [PATCH 19/51] tests/qtest: Build test-filter-{mirror, redirector} cases " Bin Meng
@ 2022-08-24  9:39 ` Bin Meng
  2022-08-25 11:40   ` [PATCH 20/51] tests/qtest: i440fx-test: Skip running request_{bios,pflash} " Thomas Huth
  2022-08-31 13:40   ` [PATCH 20/51] tests/qtest: i440fx-test: Skip running request_{bios, pflash} " Marc-André Lureau
  2022-08-24  9:39 ` [PATCH 21/51] tests/qtest: migration-test: Skip running test_migrate_fd_proto on win32 Bin Meng
                   ` (30 subsequent siblings)
  50 siblings, 2 replies; 174+ messages in thread
From: Bin Meng @ 2022-08-24  9:39 UTC (permalink / raw)
  To: qemu-devel; +Cc: Bin Meng, Laurent Vivier, Paolo Bonzini, Thomas Huth

From: Bin Meng <bin.meng@windriver.com>

The request_{bios,pflash} test cases call mmap() which does not
exist on win32. Exclude them.

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

 tests/qtest/i440fx-test.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/tests/qtest/i440fx-test.c b/tests/qtest/i440fx-test.c
index 6d7d4d8d8f..3890f1237c 100644
--- a/tests/qtest/i440fx-test.c
+++ b/tests/qtest/i440fx-test.c
@@ -278,6 +278,8 @@ static void test_i440fx_pam(gconstpointer opaque)
     qtest_end();
 }
 
+#ifndef _WIN32
+
 #define BLOB_SIZE ((size_t)65536)
 #define ISA_BIOS_MAXSZ ((size_t)(128 * 1024))
 
@@ -396,6 +398,8 @@ static void request_pflash(FirmwareTestFixture *fixture,
     fixture->is_bios = false;
 }
 
+#endif /* _WIN32 */
+
 int main(int argc, char **argv)
 {
     TestData data;
@@ -406,8 +410,10 @@ int main(int argc, char **argv)
 
     qtest_add_data_func("i440fx/defaults", &data, test_i440fx_defaults);
     qtest_add_data_func("i440fx/pam", &data, test_i440fx_pam);
+#ifndef _WIN32
     add_firmware_test("i440fx/firmware/bios", request_bios);
     add_firmware_test("i440fx/firmware/pflash", request_pflash);
+#endif
 
     return g_test_run();
 }
-- 
2.34.1



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

* [PATCH 21/51] tests/qtest: migration-test: Skip running test_migrate_fd_proto on win32
  2022-08-24  9:39 [PATCH 00/51] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (19 preceding siblings ...)
  2022-08-24  9:39 ` [PATCH 20/51] tests/qtest: i440fx-test: Skip running request_{bios, pflash} for win32 Bin Meng
@ 2022-08-24  9:39 ` Bin Meng
  2022-08-24 18:49   ` Dr. David Alan Gilbert
  2022-09-04 14:15   ` Philippe Mathieu-Daudé via
  2022-08-24  9:40 ` [PATCH 22/51] tests/qtest: qmp-test: Skip running test_qmp_oob for win32 Bin Meng
                   ` (29 subsequent siblings)
  50 siblings, 2 replies; 174+ messages in thread
From: Bin Meng @ 2022-08-24  9:39 UTC (permalink / raw)
  To: qemu-devel
  Cc: Bin Meng, Dr. David Alan Gilbert, Juan Quintela, Laurent Vivier,
	Paolo Bonzini, Thomas Huth

From: Bin Meng <bin.meng@windriver.com>

The test case 'test_migrate_fd_proto' calls socketpair() which does
not exist on win32. Exclude it. The helper function wait_command_fd()
is not needed anymore, hence exclude it too.

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

 tests/qtest/migration-helpers.h | 2 ++
 tests/qtest/migration-helpers.c | 2 ++
 tests/qtest/migration-test.c    | 4 ++++
 3 files changed, 8 insertions(+)

diff --git a/tests/qtest/migration-helpers.h b/tests/qtest/migration-helpers.h
index 59561898d0..db0684de48 100644
--- a/tests/qtest/migration-helpers.h
+++ b/tests/qtest/migration-helpers.h
@@ -17,8 +17,10 @@
 
 extern bool got_stop;
 
+#ifndef _WIN32
 G_GNUC_PRINTF(3, 4)
 QDict *wait_command_fd(QTestState *who, int fd, const char *command, ...);
+#endif
 
 G_GNUC_PRINTF(2, 3)
 QDict *wait_command(QTestState *who, const char *command, ...);
diff --git a/tests/qtest/migration-helpers.c b/tests/qtest/migration-helpers.c
index c6fbeb3974..f6f3c6680f 100644
--- a/tests/qtest/migration-helpers.c
+++ b/tests/qtest/migration-helpers.c
@@ -34,6 +34,7 @@ static void check_stop_event(QTestState *who)
     }
 }
 
+#ifndef _WIN32
 /*
  * Events can get in the way of responses we are actually waiting for.
  */
@@ -58,6 +59,7 @@ QDict *wait_command_fd(QTestState *who, int fd, const char *command, ...)
 
     return ret;
 }
+#endif
 
 /*
  * Events can get in the way of responses we are actually waiting for.
diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index af9250750b..2ae7498d5d 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -1629,6 +1629,7 @@ static void test_precopy_tcp_tls_x509_reject_anon_client(void)
 #endif /* CONFIG_TASN1 */
 #endif /* CONFIG_GNUTLS */
 
+#ifndef _WIN32
 static void *test_migrate_fd_start_hook(QTestState *from,
                                         QTestState *to)
 {
@@ -1697,6 +1698,7 @@ static void test_migrate_fd_proto(void)
     };
     test_precopy_common(&args);
 }
+#endif /* _WIN32 */
 
 static void do_test_validate_uuid(MigrateStart *args, bool should_fail)
 {
@@ -2531,7 +2533,9 @@ int main(int argc, char **argv)
 #endif /* CONFIG_GNUTLS */
 
     /* qtest_add_func("/migration/ignore_shared", test_ignore_shared); */
+#ifndef _WIN32
     qtest_add_func("/migration/fd_proto", test_migrate_fd_proto);
+#endif
     qtest_add_func("/migration/validate_uuid", test_validate_uuid);
     qtest_add_func("/migration/validate_uuid_error", test_validate_uuid_error);
     qtest_add_func("/migration/validate_uuid_src_not_set",
-- 
2.34.1



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

* [PATCH 22/51] tests/qtest: qmp-test: Skip running test_qmp_oob for win32
  2022-08-24  9:39 [PATCH 00/51] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (20 preceding siblings ...)
  2022-08-24  9:39 ` [PATCH 21/51] tests/qtest: migration-test: Skip running test_migrate_fd_proto on win32 Bin Meng
@ 2022-08-24  9:40 ` Bin Meng
  2022-08-25 11:45   ` Thomas Huth
  2022-08-29 13:14   ` Markus Armbruster
  2022-08-24  9:40 ` [PATCH 23/51] accel/qtest: Support qtest accelerator for Windows Bin Meng
                   ` (28 subsequent siblings)
  50 siblings, 2 replies; 174+ messages in thread
From: Bin Meng @ 2022-08-24  9:40 UTC (permalink / raw)
  To: qemu-devel
  Cc: Bin Meng, Laurent Vivier, Markus Armbruster, Paolo Bonzini, Thomas Huth

From: Bin Meng <bin.meng@windriver.com>

The test_qmp_oob test case calls mkfifo() which does not exist on
win32. Exclude it.

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

 tests/qtest/qmp-test.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/tests/qtest/qmp-test.c b/tests/qtest/qmp-test.c
index b950dbafaf..4a165447f8 100644
--- a/tests/qtest/qmp-test.c
+++ b/tests/qtest/qmp-test.c
@@ -159,6 +159,8 @@ static void test_qmp_protocol(void)
     qtest_quit(qts);
 }
 
+#ifndef _WIN32
+
 /* Out-of-band tests */
 
 char *tmpdir;
@@ -279,6 +281,8 @@ static void test_qmp_oob(void)
     qtest_quit(qts);
 }
 
+#endif /* _WIN32 */
+
 /* Preconfig tests */
 
 static void test_qmp_preconfig(void)
@@ -338,7 +342,9 @@ int main(int argc, char *argv[])
     g_test_init(&argc, &argv, NULL);
 
     qtest_add_func("qmp/protocol", test_qmp_protocol);
+#ifndef _WIN32
     qtest_add_func("qmp/oob", test_qmp_oob);
+#endif
     qtest_add_func("qmp/preconfig", test_qmp_preconfig);
     qtest_add_func("qmp/missing-any-arg", test_qmp_missing_any_arg);
 
-- 
2.34.1



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

* [PATCH 23/51] accel/qtest: Support qtest accelerator for Windows
  2022-08-24  9:39 [PATCH 00/51] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (21 preceding siblings ...)
  2022-08-24  9:40 ` [PATCH 22/51] tests/qtest: qmp-test: Skip running test_qmp_oob for win32 Bin Meng
@ 2022-08-24  9:40 ` Bin Meng
  2022-08-31 13:49   ` Marc-André Lureau
  2022-08-24  9:40 ` [PATCH 24/51] tests/qtest: libqos: Drop inclusion of <sys/wait.h> Bin Meng
                   ` (27 subsequent siblings)
  50 siblings, 1 reply; 174+ messages in thread
From: Bin Meng @ 2022-08-24  9:40 UTC (permalink / raw)
  To: qemu-devel
  Cc: Xuzhou Cheng, Bin Meng, Eduardo Habkost, Laurent Vivier,
	Marcel Apfelbaum, Paolo Bonzini, Philippe Mathieu-Daudé,
	Richard Henderson, Thomas Huth, Yanan Wang

From: Xuzhou Cheng <xuzhou.cheng@windriver.com>

Currently signal SIGIPI [=SIGUSR1] is used to kick the dummy CPU
when qtest accelerator is used. However SIGUSR1 is unsupported on
Windows. To support Windows, we add a QemuSemaphore CPUState::sem
to kick the dummy CPU instead for Windows.

Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
Signed-off-by: Bin Meng <bin.meng@windriver.com>
---

 include/hw/core/cpu.h   |  1 +
 accel/dummy-cpus.c      | 14 ++++++++++++--
 softmmu/cpus.c          |  9 +++++----
 accel/meson.build       |  1 +
 accel/qtest/meson.build |  1 +
 5 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index 500503da13..c564108877 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -325,6 +325,7 @@ struct CPUState {
     struct QemuThread *thread;
 #ifdef _WIN32
     HANDLE hThread;
+    QemuSemaphore sem;
 #endif
     int thread_id;
     bool running, has_waiter;
diff --git a/accel/dummy-cpus.c b/accel/dummy-cpus.c
index 10429fdfb2..d6a1b8d0a2 100644
--- a/accel/dummy-cpus.c
+++ b/accel/dummy-cpus.c
@@ -21,8 +21,6 @@
 static void *dummy_cpu_thread_fn(void *arg)
 {
     CPUState *cpu = arg;
-    sigset_t waitset;
-    int r;
 
     rcu_register_thread();
 
@@ -32,8 +30,13 @@ static void *dummy_cpu_thread_fn(void *arg)
     cpu->can_do_io = 1;
     current_cpu = cpu;
 
+#ifndef _WIN32
+    sigset_t waitset;
+    int r;
+
     sigemptyset(&waitset);
     sigaddset(&waitset, SIG_IPI);
+#endif
 
     /* signal CPU creation */
     cpu_thread_signal_created(cpu);
@@ -41,6 +44,7 @@ static void *dummy_cpu_thread_fn(void *arg)
 
     do {
         qemu_mutex_unlock_iothread();
+#ifndef _WIN32
         do {
             int sig;
             r = sigwait(&waitset, &sig);
@@ -49,6 +53,9 @@ static void *dummy_cpu_thread_fn(void *arg)
             perror("sigwait");
             exit(1);
         }
+#else
+        qemu_sem_wait(&cpu->sem);
+#endif
         qemu_mutex_lock_iothread();
         qemu_wait_io_event(cpu);
     } while (!cpu->unplug);
@@ -69,4 +76,7 @@ void dummy_start_vcpu_thread(CPUState *cpu)
              cpu->cpu_index);
     qemu_thread_create(cpu->thread, thread_name, dummy_cpu_thread_fn, cpu,
                        QEMU_THREAD_JOINABLE);
+#ifdef _WIN32
+    qemu_sem_init(&cpu->sem, 0);
+#endif
 }
diff --git a/softmmu/cpus.c b/softmmu/cpus.c
index 23b30484b2..fd10db927a 100644
--- a/softmmu/cpus.c
+++ b/softmmu/cpus.c
@@ -437,18 +437,19 @@ void qemu_wait_io_event(CPUState *cpu)
 
 void cpus_kick_thread(CPUState *cpu)
 {
-#ifndef _WIN32
-    int err;
-
     if (cpu->thread_kicked) {
         return;
     }
     cpu->thread_kicked = true;
-    err = pthread_kill(cpu->thread->thread, SIG_IPI);
+
+#ifndef _WIN32
+    int err = pthread_kill(cpu->thread->thread, SIG_IPI);
     if (err && err != ESRCH) {
         fprintf(stderr, "qemu:%s: %s", __func__, strerror(err));
         exit(1);
     }
+#else
+    qemu_sem_post(&cpu->sem);
 #endif
 }
 
diff --git a/accel/meson.build b/accel/meson.build
index b9a963cf80..b21c85dc0a 100644
--- a/accel/meson.build
+++ b/accel/meson.build
@@ -17,4 +17,5 @@ dummy_ss.add(files(
 ))
 
 specific_ss.add_all(when: ['CONFIG_SOFTMMU', 'CONFIG_POSIX'], if_true: dummy_ss)
+specific_ss.add_all(when: ['CONFIG_WIN32'], if_true: dummy_ss)
 specific_ss.add_all(when: ['CONFIG_XEN'], if_true: dummy_ss)
diff --git a/accel/qtest/meson.build b/accel/qtest/meson.build
index 4c65600293..a4876fc0f2 100644
--- a/accel/qtest/meson.build
+++ b/accel/qtest/meson.build
@@ -1,2 +1,3 @@
 qtest_module_ss.add(when: ['CONFIG_SOFTMMU', 'CONFIG_POSIX'],
                     if_true: files('qtest.c'))
+qtest_module_ss.add(when: ['CONFIG_WIN32'], if_true: files('qtest.c'))
-- 
2.34.1



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

* [PATCH 24/51] tests/qtest: libqos: Drop inclusion of <sys/wait.h>
  2022-08-24  9:39 [PATCH 00/51] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (22 preceding siblings ...)
  2022-08-24  9:40 ` [PATCH 23/51] accel/qtest: Support qtest accelerator for Windows Bin Meng
@ 2022-08-24  9:40 ` Bin Meng
  2022-08-25 11:55   ` Thomas Huth
  2022-08-31 13:50   ` Marc-André Lureau
  2022-08-24  9:40 ` [PATCH 25/51] tests/qtest: libqos: Rename malloc.h to libqos-malloc.h Bin Meng
                   ` (26 subsequent siblings)
  50 siblings, 2 replies; 174+ messages in thread
From: Bin Meng @ 2022-08-24  9:40 UTC (permalink / raw)
  To: qemu-devel
  Cc: Xuzhou Cheng, Bin Meng, Laurent Vivier, Paolo Bonzini, Thomas Huth

From: Xuzhou Cheng <xuzhou.cheng@windriver.com>

There is no <sys/wait.h> in the Windows build environment. Actually
this is not needed in the non-win32 builds too. Drop it.

Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
Signed-off-by: Bin Meng <bin.meng@windriver.com>
---

 tests/qtest/libqos/libqos.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/tests/qtest/libqos/libqos.c b/tests/qtest/libqos/libqos.c
index 85c7641add..5ffda080ec 100644
--- a/tests/qtest/libqos/libqos.c
+++ b/tests/qtest/libqos/libqos.c
@@ -1,6 +1,4 @@
 #include "qemu/osdep.h"
-#include <sys/wait.h>
-
 #include "../libqtest.h"
 #include "libqos.h"
 #include "pci.h"
-- 
2.34.1



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

* [PATCH 25/51] tests/qtest: libqos: Rename malloc.h to libqos-malloc.h
  2022-08-24  9:39 [PATCH 00/51] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (23 preceding siblings ...)
  2022-08-24  9:40 ` [PATCH 24/51] tests/qtest: libqos: Drop inclusion of <sys/wait.h> Bin Meng
@ 2022-08-24  9:40 ` Bin Meng
  2022-08-25 11:51   ` Thomas Huth
  2022-08-31 13:51   ` Marc-André Lureau
  2022-08-24  9:40 ` [PATCH 26/51] tests/qtest: libqtest: Move global_qtest definition back to libqtest.c Bin Meng
                   ` (25 subsequent siblings)
  50 siblings, 2 replies; 174+ messages in thread
From: Bin Meng @ 2022-08-24  9:40 UTC (permalink / raw)
  To: qemu-devel
  Cc: Xuzhou Cheng, Bin Meng, Alexander Bulekov, Bandan Das,
	Cédric Le Goater, Daniel Henrique Barboza, Darren Kenny,
	David Gibson, Greg Kurz, Laurent Vivier, Paolo Bonzini,
	Qiuhao Li, Stefan Hajnoczi, Thomas Huth, qemu-ppc

From: Xuzhou Cheng <xuzhou.cheng@windriver.com>

The qtest/libqos directory is included via the "-I" option to search
for header files when building qtest. Unfortunately the malloc.h has
a name conflict with the standard libc header, leading to a build
failure on the Windows host, due to the MinGW libc stdlib.h header
file includes malloc.h and it now gets wrongly pointed to the one
in the qtest/libqos directory.

Rename "qtest/libqos/malloc.h" to "qtest/libqos/libqos-malloc.h" to
avoid the namespace pollution.

Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
Signed-off-by: Bin Meng <bin.meng@windriver.com>
---

 tests/qtest/libqos/generic-pcihost.h             | 2 +-
 tests/qtest/libqos/{malloc.h => libqos-malloc.h} | 0
 tests/qtest/libqos/libqos.h                      | 2 +-
 tests/qtest/libqos/malloc-pc.h                   | 2 +-
 tests/qtest/libqos/malloc-spapr.h                | 2 +-
 tests/qtest/libqos/pci-pc.h                      | 2 +-
 tests/qtest/libqos/pci-spapr.h                   | 2 +-
 tests/qtest/libqos/qgraph.h                      | 2 +-
 tests/qtest/libqos/qos_external.h                | 2 +-
 tests/qtest/libqos/rtas.h                        | 2 +-
 tests/qtest/libqos/virtio.h                      | 2 +-
 tests/qtest/e1000e-test.c                        | 2 +-
 tests/qtest/fuzz/qos_fuzz.c                      | 2 +-
 tests/qtest/libqos/aarch64-xlnx-zcu102-machine.c | 2 +-
 tests/qtest/libqos/arm-imx25-pdk-machine.c       | 2 +-
 tests/qtest/libqos/arm-n800-machine.c            | 2 +-
 tests/qtest/libqos/arm-raspi2-machine.c          | 2 +-
 tests/qtest/libqos/arm-sabrelite-machine.c       | 2 +-
 tests/qtest/libqos/arm-smdkc210-machine.c        | 2 +-
 tests/qtest/libqos/arm-virt-machine.c            | 2 +-
 tests/qtest/libqos/arm-xilinx-zynq-a9-machine.c  | 2 +-
 tests/qtest/libqos/e1000e.c                      | 2 +-
 tests/qtest/libqos/{malloc.c => libqos-malloc.c} | 2 +-
 tests/qtest/libqos/qos_external.c                | 2 +-
 tests/qtest/libqos/virtio-mmio.c                 | 2 +-
 tests/qtest/libqos/virtio-pci.c                  | 2 +-
 tests/qtest/qos-test.c                           | 2 +-
 tests/qtest/libqos/meson.build                   | 2 +-
 28 files changed, 27 insertions(+), 27 deletions(-)
 rename tests/qtest/libqos/{malloc.h => libqos-malloc.h} (100%)
 rename tests/qtest/libqos/{malloc.c => libqos-malloc.c} (99%)

diff --git a/tests/qtest/libqos/generic-pcihost.h b/tests/qtest/libqos/generic-pcihost.h
index c693c769df..6493a8712a 100644
--- a/tests/qtest/libqos/generic-pcihost.h
+++ b/tests/qtest/libqos/generic-pcihost.h
@@ -14,7 +14,7 @@
 #define LIBQOS_GENERIC_PCIHOST_H
 
 #include "pci.h"
-#include "malloc.h"
+#include "libqos-malloc.h"
 #include "qgraph.h"
 
 typedef struct QGenericPCIBus {
diff --git a/tests/qtest/libqos/malloc.h b/tests/qtest/libqos/libqos-malloc.h
similarity index 100%
rename from tests/qtest/libqos/malloc.h
rename to tests/qtest/libqos/libqos-malloc.h
diff --git a/tests/qtest/libqos/libqos.h b/tests/qtest/libqos/libqos.h
index ba7df448ca..9b4dd509f0 100644
--- a/tests/qtest/libqos/libqos.h
+++ b/tests/qtest/libqos/libqos.h
@@ -3,7 +3,7 @@
 
 #include "../libqtest.h"
 #include "pci.h"
-#include "malloc.h"
+#include "libqos-malloc.h"
 
 typedef struct QOSState QOSState;
 
diff --git a/tests/qtest/libqos/malloc-pc.h b/tests/qtest/libqos/malloc-pc.h
index d8d79853c8..e531473601 100644
--- a/tests/qtest/libqos/malloc-pc.h
+++ b/tests/qtest/libqos/malloc-pc.h
@@ -13,7 +13,7 @@
 #ifndef LIBQOS_MALLOC_PC_H
 #define LIBQOS_MALLOC_PC_H
 
-#include "malloc.h"
+#include "libqos-malloc.h"
 
 void pc_alloc_init(QGuestAllocator *s, QTestState *qts, QAllocOpts flags);
 
diff --git a/tests/qtest/libqos/malloc-spapr.h b/tests/qtest/libqos/malloc-spapr.h
index f99572fd71..f544c0d611 100644
--- a/tests/qtest/libqos/malloc-spapr.h
+++ b/tests/qtest/libqos/malloc-spapr.h
@@ -8,7 +8,7 @@
 #ifndef LIBQOS_MALLOC_SPAPR_H
 #define LIBQOS_MALLOC_SPAPR_H
 
-#include "malloc.h"
+#include "libqos-malloc.h"
 
 void spapr_alloc_init(QGuestAllocator *s, QTestState *qts, QAllocOpts flags);
 
diff --git a/tests/qtest/libqos/pci-pc.h b/tests/qtest/libqos/pci-pc.h
index 49ec9507f2..849bd493de 100644
--- a/tests/qtest/libqos/pci-pc.h
+++ b/tests/qtest/libqos/pci-pc.h
@@ -14,7 +14,7 @@
 #define LIBQOS_PCI_PC_H
 
 #include "pci.h"
-#include "malloc.h"
+#include "libqos-malloc.h"
 #include "qgraph.h"
 
 typedef struct QPCIBusPC {
diff --git a/tests/qtest/libqos/pci-spapr.h b/tests/qtest/libqos/pci-spapr.h
index 20a43718b7..3dbf1e58ae 100644
--- a/tests/qtest/libqos/pci-spapr.h
+++ b/tests/qtest/libqos/pci-spapr.h
@@ -8,7 +8,7 @@
 #ifndef LIBQOS_PCI_SPAPR_H
 #define LIBQOS_PCI_SPAPR_H
 
-#include "malloc.h"
+#include "libqos-malloc.h"
 #include "pci.h"
 #include "qgraph.h"
 
diff --git a/tests/qtest/libqos/qgraph.h b/tests/qtest/libqos/qgraph.h
index 871740c0dc..6e94824d09 100644
--- a/tests/qtest/libqos/qgraph.h
+++ b/tests/qtest/libqos/qgraph.h
@@ -21,7 +21,7 @@
 
 #include <gmodule.h>
 #include "qemu/module.h"
-#include "malloc.h"
+#include "libqos-malloc.h"
 
 /* maximum path length */
 #define QOS_PATH_MAX_ELEMENT_SIZE 50
diff --git a/tests/qtest/libqos/qos_external.h b/tests/qtest/libqos/qos_external.h
index 8446e3df0b..ea37364887 100644
--- a/tests/qtest/libqos/qos_external.h
+++ b/tests/qtest/libqos/qos_external.h
@@ -21,7 +21,7 @@
 
 #include "qgraph.h"
 
-#include "malloc.h"
+#include "libqos-malloc.h"
 #include "qapi/qapi-types-machine.h"
 #include "qapi/qapi-types-qom.h"
 
diff --git a/tests/qtest/libqos/rtas.h b/tests/qtest/libqos/rtas.h
index f38f99dfab..be8353d505 100644
--- a/tests/qtest/libqos/rtas.h
+++ b/tests/qtest/libqos/rtas.h
@@ -5,7 +5,7 @@
 
 #ifndef LIBQOS_RTAS_H
 #define LIBQOS_RTAS_H
-#include "malloc.h"
+#include "libqos-malloc.h"
 
 int qrtas_get_time_of_day(QTestState *qts, QGuestAllocator *alloc,
                           struct tm *tm, uint32_t *ns);
diff --git a/tests/qtest/libqos/virtio.h b/tests/qtest/libqos/virtio.h
index b8bd06e1b8..7adc7cbd10 100644
--- a/tests/qtest/libqos/virtio.h
+++ b/tests/qtest/libqos/virtio.h
@@ -10,7 +10,7 @@
 #ifndef LIBQOS_VIRTIO_H
 #define LIBQOS_VIRTIO_H
 
-#include "malloc.h"
+#include "libqos-malloc.h"
 #include "standard-headers/linux/virtio_ring.h"
 
 #define QVIRTIO_F_BAD_FEATURE           0x40000000ull
diff --git a/tests/qtest/e1000e-test.c b/tests/qtest/e1000e-test.c
index c98779c7c0..4cdd8238f2 100644
--- a/tests/qtest/e1000e-test.c
+++ b/tests/qtest/e1000e-test.c
@@ -31,7 +31,7 @@
 #include "qemu/iov.h"
 #include "qemu/module.h"
 #include "qemu/bitops.h"
-#include "libqos/malloc.h"
+#include "libqos/libqos-malloc.h"
 #include "libqos/e1000e.h"
 
 static void e1000e_send_verify(QE1000E *d, int *test_sockets, QGuestAllocator *alloc)
diff --git a/tests/qtest/fuzz/qos_fuzz.c b/tests/qtest/fuzz/qos_fuzz.c
index c856d3d500..3a3d9c16dd 100644
--- a/tests/qtest/fuzz/qos_fuzz.c
+++ b/tests/qtest/fuzz/qos_fuzz.c
@@ -23,7 +23,7 @@
 #include "qemu/main-loop.h"
 
 #include "tests/qtest/libqtest.h"
-#include "tests/qtest/libqos/malloc.h"
+#include "tests/qtest/libqos/libqos-malloc.h"
 #include "tests/qtest/libqos/qgraph.h"
 #include "tests/qtest/libqos/qgraph_internal.h"
 #include "tests/qtest/libqos/qos_external.h"
diff --git a/tests/qtest/libqos/aarch64-xlnx-zcu102-machine.c b/tests/qtest/libqos/aarch64-xlnx-zcu102-machine.c
index c8a3ea11eb..ab24add8eb 100644
--- a/tests/qtest/libqos/aarch64-xlnx-zcu102-machine.c
+++ b/tests/qtest/libqos/aarch64-xlnx-zcu102-machine.c
@@ -19,7 +19,7 @@
 #include "qemu/osdep.h"
 #include "../libqtest.h"
 #include "qemu/module.h"
-#include "malloc.h"
+#include "libqos-malloc.h"
 #include "qgraph.h"
 #include "sdhci.h"
 
diff --git a/tests/qtest/libqos/arm-imx25-pdk-machine.c b/tests/qtest/libqos/arm-imx25-pdk-machine.c
index 54d0c95330..8fe128fae8 100644
--- a/tests/qtest/libqos/arm-imx25-pdk-machine.c
+++ b/tests/qtest/libqos/arm-imx25-pdk-machine.c
@@ -20,7 +20,7 @@
 
 #include "qemu/osdep.h"
 #include "../libqtest.h"
-#include "malloc.h"
+#include "libqos-malloc.h"
 #include "qgraph.h"
 #include "i2c.h"
 
diff --git a/tests/qtest/libqos/arm-n800-machine.c b/tests/qtest/libqos/arm-n800-machine.c
index ecd46b1daf..4e5afe0164 100644
--- a/tests/qtest/libqos/arm-n800-machine.c
+++ b/tests/qtest/libqos/arm-n800-machine.c
@@ -20,7 +20,7 @@
 
 #include "qemu/osdep.h"
 #include "../libqtest.h"
-#include "malloc.h"
+#include "libqos-malloc.h"
 #include "qgraph.h"
 #include "i2c.h"
 
diff --git a/tests/qtest/libqos/arm-raspi2-machine.c b/tests/qtest/libqos/arm-raspi2-machine.c
index 0a2943440b..367c6c17a5 100644
--- a/tests/qtest/libqos/arm-raspi2-machine.c
+++ b/tests/qtest/libqos/arm-raspi2-machine.c
@@ -19,7 +19,7 @@
 #include "qemu/osdep.h"
 #include "../libqtest.h"
 #include "qemu/module.h"
-#include "malloc.h"
+#include "libqos-malloc.h"
 #include "qgraph.h"
 #include "sdhci.h"
 
diff --git a/tests/qtest/libqos/arm-sabrelite-machine.c b/tests/qtest/libqos/arm-sabrelite-machine.c
index ec19a01660..94f6a20fc7 100644
--- a/tests/qtest/libqos/arm-sabrelite-machine.c
+++ b/tests/qtest/libqos/arm-sabrelite-machine.c
@@ -19,7 +19,7 @@
 #include "qemu/osdep.h"
 #include "../libqtest.h"
 #include "qemu/module.h"
-#include "malloc.h"
+#include "libqos-malloc.h"
 #include "qgraph.h"
 #include "sdhci.h"
 
diff --git a/tests/qtest/libqos/arm-smdkc210-machine.c b/tests/qtest/libqos/arm-smdkc210-machine.c
index 4bff249ee8..9bbce924ea 100644
--- a/tests/qtest/libqos/arm-smdkc210-machine.c
+++ b/tests/qtest/libqos/arm-smdkc210-machine.c
@@ -19,7 +19,7 @@
 #include "qemu/osdep.h"
 #include "../libqtest.h"
 #include "qemu/module.h"
-#include "malloc.h"
+#include "libqos-malloc.h"
 #include "qgraph.h"
 #include "sdhci.h"
 
diff --git a/tests/qtest/libqos/arm-virt-machine.c b/tests/qtest/libqos/arm-virt-machine.c
index 139eaba142..4e87405b58 100644
--- a/tests/qtest/libqos/arm-virt-machine.c
+++ b/tests/qtest/libqos/arm-virt-machine.c
@@ -19,7 +19,7 @@
 #include "qemu/osdep.h"
 #include "../libqtest.h"
 #include "qemu/module.h"
-#include "malloc.h"
+#include "libqos-malloc.h"
 #include "qgraph.h"
 #include "virtio-mmio.h"
 #include "generic-pcihost.h"
diff --git a/tests/qtest/libqos/arm-xilinx-zynq-a9-machine.c b/tests/qtest/libqos/arm-xilinx-zynq-a9-machine.c
index 3be80020a6..daac762a06 100644
--- a/tests/qtest/libqos/arm-xilinx-zynq-a9-machine.c
+++ b/tests/qtest/libqos/arm-xilinx-zynq-a9-machine.c
@@ -19,7 +19,7 @@
 #include "qemu/osdep.h"
 #include "../libqtest.h"
 #include "qemu/module.h"
-#include "malloc.h"
+#include "libqos-malloc.h"
 #include "qgraph.h"
 #include "sdhci.h"
 
diff --git a/tests/qtest/libqos/e1000e.c b/tests/qtest/libqos/e1000e.c
index f87e0e84b2..fc14b07884 100644
--- a/tests/qtest/libqos/e1000e.c
+++ b/tests/qtest/libqos/e1000e.c
@@ -23,7 +23,7 @@
 #include "qemu/iov.h"
 #include "qemu/module.h"
 #include "qemu/bitops.h"
-#include "malloc.h"
+#include "libqos-malloc.h"
 #include "qgraph.h"
 #include "e1000e.h"
 
diff --git a/tests/qtest/libqos/malloc.c b/tests/qtest/libqos/libqos-malloc.c
similarity index 99%
rename from tests/qtest/libqos/malloc.c
rename to tests/qtest/libqos/libqos-malloc.c
index f0c8f950c8..d7566972c4 100644
--- a/tests/qtest/libqos/malloc.c
+++ b/tests/qtest/libqos/libqos-malloc.c
@@ -11,7 +11,7 @@
  */
 
 #include "qemu/osdep.h"
-#include "malloc.h"
+#include "libqos-malloc.h"
 #include "qemu/host-utils.h"
 
 typedef struct MemBlock {
diff --git a/tests/qtest/libqos/qos_external.c b/tests/qtest/libqos/qos_external.c
index b7a0b873a3..c6bb8bff09 100644
--- a/tests/qtest/libqos/qos_external.c
+++ b/tests/qtest/libqos/qos_external.c
@@ -24,7 +24,7 @@
 #include "qapi/qmp/qstring.h"
 #include "qemu/module.h"
 #include "qapi/qmp/qlist.h"
-#include "malloc.h"
+#include "libqos-malloc.h"
 #include "qgraph.h"
 #include "qgraph_internal.h"
 #include "qos_external.h"
diff --git a/tests/qtest/libqos/virtio-mmio.c b/tests/qtest/libqos/virtio-mmio.c
index a6cca8613b..bd0b1d890b 100644
--- a/tests/qtest/libqos/virtio-mmio.c
+++ b/tests/qtest/libqos/virtio-mmio.c
@@ -12,7 +12,7 @@
 #include "qemu/module.h"
 #include "virtio.h"
 #include "virtio-mmio.h"
-#include "malloc.h"
+#include "libqos-malloc.h"
 #include "qgraph.h"
 #include "standard-headers/linux/virtio_ring.h"
 
diff --git a/tests/qtest/libqos/virtio-pci.c b/tests/qtest/libqos/virtio-pci.c
index 67c2498c84..485b8f6b7e 100644
--- a/tests/qtest/libqos/virtio-pci.c
+++ b/tests/qtest/libqos/virtio-pci.c
@@ -13,7 +13,7 @@
 #include "virtio-pci.h"
 #include "pci.h"
 #include "pci-pc.h"
-#include "malloc.h"
+#include "libqos-malloc.h"
 #include "malloc-pc.h"
 #include "qgraph.h"
 #include "standard-headers/linux/virtio_ring.h"
diff --git a/tests/qtest/qos-test.c b/tests/qtest/qos-test.c
index f97d0a08fd..831db5cf2a 100644
--- a/tests/qtest/qos-test.c
+++ b/tests/qtest/qos-test.c
@@ -25,7 +25,7 @@
 #include "qapi/qobject-input-visitor.h"
 #include "qapi/qapi-visit-machine.h"
 #include "qapi/qapi-visit-qom.h"
-#include "libqos/malloc.h"
+#include "libqos/libqos-malloc.h"
 #include "libqos/qgraph.h"
 #include "libqos/qgraph_internal.h"
 #include "libqos/qos_external.h"
diff --git a/tests/qtest/libqos/meson.build b/tests/qtest/libqos/meson.build
index fd5d6e5ae1..cff83c86d9 100644
--- a/tests/qtest/libqos/meson.build
+++ b/tests/qtest/libqos/meson.build
@@ -6,7 +6,7 @@ libqos_srcs = files(
         'qos_external.c',
         'pci.c',
         'fw_cfg.c',
-        'malloc.c',
+        'libqos-malloc.c',
         'libqos.c',
         'sdhci-cmd.c',
 
-- 
2.34.1



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

* [PATCH 26/51] tests/qtest: libqtest: Move global_qtest definition back to libqtest.c
  2022-08-24  9:39 [PATCH 00/51] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (24 preceding siblings ...)
  2022-08-24  9:40 ` [PATCH 25/51] tests/qtest: libqos: Rename malloc.h to libqos-malloc.h Bin Meng
@ 2022-08-24  9:40 ` Bin Meng
  2022-08-25 11:59   ` Thomas Huth
  2022-08-24  9:40 ` [PATCH 27/51] tests/qtest: Use send/recv for socket communication Bin Meng
                   ` (24 subsequent siblings)
  50 siblings, 1 reply; 174+ messages in thread
From: Bin Meng @ 2022-08-24  9:40 UTC (permalink / raw)
  To: qemu-devel
  Cc: Xuzhou Cheng, Bin Meng, Laurent Vivier, Paolo Bonzini, Thomas Huth

From: Xuzhou Cheng <xuzhou.cheng@windriver.com>

Commit dd2107497275 ("tests/libqtest: Use libqtest-single.h in tests that require global_qtest")
moved global_qtest to libqtest-single.h, by declaring global_qtest
attribute to be common and weak.

This trick unfortunately does not work on Windows, and building
qtest test cases results in multiple definition errors of the weak
symbol global_qtest, as Windows PE does not have the concept of
the so-called weak symbol like ELF in the *nix world.

Let's move the definition of global_qtest back to libqtest.c.

Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
Signed-off-by: Bin Meng <bin.meng@windriver.com>
---

 tests/qtest/libqtest-single.h | 2 +-
 tests/qtest/libqtest.c        | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/tests/qtest/libqtest-single.h b/tests/qtest/libqtest-single.h
index 4e7d0ae1dc..3294985d7b 100644
--- a/tests/qtest/libqtest-single.h
+++ b/tests/qtest/libqtest-single.h
@@ -13,7 +13,7 @@
 
 #include "libqtest.h"
 
-QTestState *global_qtest __attribute__((common, weak));
+extern QTestState *global_qtest;
 
 /**
  * qtest_start:
diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
index 34744ace7c..909583dad3 100644
--- a/tests/qtest/libqtest.c
+++ b/tests/qtest/libqtest.c
@@ -65,6 +65,8 @@ struct QTestState
     GList *pending_events;
 };
 
+QTestState *global_qtest;
+
 static GHookList abrt_hooks;
 static struct sigaction sigact_old;
 
-- 
2.34.1



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

* [PATCH 27/51] tests/qtest: Use send/recv for socket communication
  2022-08-24  9:39 [PATCH 00/51] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (25 preceding siblings ...)
  2022-08-24  9:40 ` [PATCH 26/51] tests/qtest: libqtest: Move global_qtest definition back to libqtest.c Bin Meng
@ 2022-08-24  9:40 ` Bin Meng
  2022-08-25 13:04   ` Thomas Huth
  2022-08-24  9:40 ` [PATCH 28/51] tests/qtest: libqtest: Exclude the *_fds APIs for win32 Bin Meng
                   ` (23 subsequent siblings)
  50 siblings, 1 reply; 174+ messages in thread
From: Bin Meng @ 2022-08-24  9:40 UTC (permalink / raw)
  To: qemu-devel
  Cc: Xuzhou Cheng, Bin Meng, Laurent Vivier, Paolo Bonzini, Thomas Huth

From: Xuzhou Cheng <xuzhou.cheng@windriver.com>

Socket communication in the libqtest and libqmp codes uses read()
and write() which work on any file descriptor on *nix, and sockets
in *nix are an example of a file descriptor.

However sockets on Windows do not use *nix-style file descriptors,
so read() and write() cannot be used on sockets on Windows.
Switch over to use send() and recv() instead which work on both
Windows and *nix.

Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
Signed-off-by: Bin Meng <bin.meng@windriver.com>
---

 tests/qtest/libqmp.c   | 4 ++--
 tests/qtest/libqtest.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/tests/qtest/libqmp.c b/tests/qtest/libqmp.c
index ade26c15f0..995a39c1f8 100644
--- a/tests/qtest/libqmp.c
+++ b/tests/qtest/libqmp.c
@@ -36,7 +36,7 @@ typedef struct {
 
 static void socket_send(int fd, const char *buf, size_t size)
 {
-    size_t res = qemu_write_full(fd, buf, size);
+    ssize_t res = send(fd, buf, size, 0);
 
     assert(res == size);
 }
@@ -69,7 +69,7 @@ QDict *qmp_fd_receive(int fd)
         ssize_t len;
         char c;
 
-        len = read(fd, &c, 1);
+        len = recv(fd, &c, 1, 0);
         if (len == -1 && errno == EINTR) {
             continue;
         }
diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
index 909583dad3..b7b7c9c541 100644
--- a/tests/qtest/libqtest.c
+++ b/tests/qtest/libqtest.c
@@ -438,7 +438,7 @@ void qtest_quit(QTestState *s)
 
 static void socket_send(int fd, const char *buf, size_t size)
 {
-    size_t res = qemu_write_full(fd, buf, size);
+    ssize_t res = send(fd, buf, size, 0);
 
     assert(res == size);
 }
@@ -470,7 +470,7 @@ static GString *qtest_client_socket_recv_line(QTestState *s)
         ssize_t len;
         char buffer[1024];
 
-        len = read(s->fd, buffer, sizeof(buffer));
+        len = recv(s->fd, buffer, sizeof(buffer), 0);
         if (len == -1 && errno == EINTR) {
             continue;
         }
-- 
2.34.1



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

* [PATCH 28/51] tests/qtest: libqtest: Exclude the *_fds APIs for win32
  2022-08-24  9:39 [PATCH 00/51] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (26 preceding siblings ...)
  2022-08-24  9:40 ` [PATCH 27/51] tests/qtest: Use send/recv for socket communication Bin Meng
@ 2022-08-24  9:40 ` Bin Meng
  2022-08-31 14:10   ` Marc-André Lureau
  2022-08-24  9:40 ` [PATCH 29/51] tests/qtest: libqtest: Install signal handler via signal() Bin Meng
                   ` (22 subsequent siblings)
  50 siblings, 1 reply; 174+ messages in thread
From: Bin Meng @ 2022-08-24  9:40 UTC (permalink / raw)
  To: qemu-devel; +Cc: Bin Meng, Laurent Vivier, Paolo Bonzini, Thomas Huth

From: Bin Meng <bin.meng@windriver.com>

libqmp.c::qmp_fd_vsend_fds() is not available on Windows, hence any
APIs in libqtest that call libqmp.c::qmp_fd_vsend_fds() should be
excluded for win32 too. This includes the following:

  * qtest_qmp_vsend_fds()
  * qtest_vqmp_fds()
  * qtest_qmp_fds()
  * qtest_qmp_add_client()

Note qtest_qmp_vsend() was wrongly written to call qmp_fd_vsend_fds()
previously, but it should call the non fds version API qmp_fd_vsend().

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

 tests/qtest/libqtest.h |  8 ++++++++
 tests/qtest/libqtest.c | 10 +++++++++-
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/tests/qtest/libqtest.h b/tests/qtest/libqtest.h
index 94b187837d..3abc75964d 100644
--- a/tests/qtest/libqtest.h
+++ b/tests/qtest/libqtest.h
@@ -94,6 +94,7 @@ void qtest_kill_qemu(QTestState *s);
  */
 void qtest_quit(QTestState *s);
 
+#ifndef _WIN32
 /**
  * qtest_qmp_fds:
  * @s: #QTestState instance to operate on.
@@ -108,6 +109,7 @@ void qtest_quit(QTestState *s);
 QDict *qtest_qmp_fds(QTestState *s, int *fds, size_t fds_num,
                      const char *fmt, ...)
     G_GNUC_PRINTF(4, 5);
+#endif /* _WIN32 */
 
 /**
  * qtest_qmp:
@@ -152,6 +154,7 @@ void qtest_qmp_send_raw(QTestState *s, const char *fmt, ...)
  */
 int qtest_socket_server(const char *socket_path);
 
+#ifndef _WIN32
 /**
  * qtest_vqmp_fds:
  * @s: #QTestState instance to operate on.
@@ -167,6 +170,7 @@ int qtest_socket_server(const char *socket_path);
 QDict *qtest_vqmp_fds(QTestState *s, int *fds, size_t fds_num,
                       const char *fmt, va_list ap)
     G_GNUC_PRINTF(4, 0);
+#endif /* _WIN32 */
 
 /**
  * qtest_vqmp:
@@ -181,6 +185,7 @@ QDict *qtest_vqmp_fds(QTestState *s, int *fds, size_t fds_num,
 QDict *qtest_vqmp(QTestState *s, const char *fmt, va_list ap)
     G_GNUC_PRINTF(2, 0);
 
+#ifndef _WIN32
 /**
  * qtest_qmp_vsend_fds:
  * @s: #QTestState instance to operate on.
@@ -196,6 +201,7 @@ QDict *qtest_vqmp(QTestState *s, const char *fmt, va_list ap)
 void qtest_qmp_vsend_fds(QTestState *s, int *fds, size_t fds_num,
                          const char *fmt, va_list ap)
     G_GNUC_PRINTF(4, 0);
+#endif /* _WIN32 */
 
 /**
  * qtest_qmp_vsend:
@@ -743,6 +749,7 @@ void qtest_qmp_device_add_qdict(QTestState *qts, const char *drv,
 void qtest_qmp_device_add(QTestState *qts, const char *driver, const char *id,
                           const char *fmt, ...) G_GNUC_PRINTF(4, 5);
 
+#ifndef _WIN32
 /**
  * qtest_qmp_add_client:
  * @qts: QTestState instance to operate on
@@ -752,6 +759,7 @@ void qtest_qmp_device_add(QTestState *qts, const char *driver, const char *id,
  * Call QMP ``getfd`` followed by ``add_client`` with the given @fd.
  */
 void qtest_qmp_add_client(QTestState *qts, const char *protocol, int fd);
+#endif /* _WIN32 */
 
 /**
  * qtest_qmp_device_del:
diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
index b7b7c9c541..1b24a4f1f7 100644
--- a/tests/qtest/libqtest.c
+++ b/tests/qtest/libqtest.c
@@ -594,17 +594,20 @@ int qtest_socket_server(const char *socket_path)
     return sock;
 }
 
+#ifndef _WIN32
 void qtest_qmp_vsend_fds(QTestState *s, int *fds, size_t fds_num,
                          const char *fmt, va_list ap)
 {
     qmp_fd_vsend_fds(s->qmp_fd, fds, fds_num, fmt, ap);
 }
+#endif
 
 void qtest_qmp_vsend(QTestState *s, const char *fmt, va_list ap)
 {
-    qmp_fd_vsend_fds(s->qmp_fd, NULL, 0, fmt, ap);
+    qmp_fd_vsend(s->qmp_fd, fmt, ap);
 }
 
+#ifndef _WIN32
 QDict *qtest_vqmp_fds(QTestState *s, int *fds, size_t fds_num,
                       const char *fmt, va_list ap)
 {
@@ -613,6 +616,7 @@ QDict *qtest_vqmp_fds(QTestState *s, int *fds, size_t fds_num,
     /* Receive reply */
     return qtest_qmp_receive(s);
 }
+#endif
 
 QDict *qtest_vqmp(QTestState *s, const char *fmt, va_list ap)
 {
@@ -622,6 +626,7 @@ QDict *qtest_vqmp(QTestState *s, const char *fmt, va_list ap)
     return qtest_qmp_receive(s);
 }
 
+#ifndef _WIN32
 QDict *qtest_qmp_fds(QTestState *s, int *fds, size_t fds_num,
                      const char *fmt, ...)
 {
@@ -633,6 +638,7 @@ QDict *qtest_qmp_fds(QTestState *s, int *fds, size_t fds_num,
     va_end(ap);
     return response;
 }
+#endif
 
 QDict *qtest_qmp(QTestState *s, const char *fmt, ...)
 {
@@ -1329,6 +1335,7 @@ void qtest_qmp_device_add(QTestState *qts, const char *driver, const char *id,
     qobject_unref(args);
 }
 
+#ifndef _WIN32
 void qtest_qmp_add_client(QTestState *qts, const char *protocol, int fd)
 {
     QDict *resp;
@@ -1348,6 +1355,7 @@ void qtest_qmp_add_client(QTestState *qts, const char *protocol, int fd)
     g_assert(!qdict_haskey(resp, "error"));
     qobject_unref(resp);
 }
+#endif
 
 /*
  * Generic hot-unplugging test via the device_del QMP command.
-- 
2.34.1



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

* [PATCH 29/51] tests/qtest: libqtest: Install signal handler via signal()
  2022-08-24  9:39 [PATCH 00/51] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (27 preceding siblings ...)
  2022-08-24  9:40 ` [PATCH 28/51] tests/qtest: libqtest: Exclude the *_fds APIs for win32 Bin Meng
@ 2022-08-24  9:40 ` Bin Meng
  2022-08-31 14:16   ` Marc-André Lureau
  2022-08-24  9:40 ` [PATCH 30/51] tests: Skip iotests and qtest when '--without-default-devices' Bin Meng
                   ` (21 subsequent siblings)
  50 siblings, 1 reply; 174+ messages in thread
From: Bin Meng @ 2022-08-24  9:40 UTC (permalink / raw)
  To: qemu-devel; +Cc: Bin Meng, Laurent Vivier, Paolo Bonzini, Thomas Huth

From: Bin Meng <bin.meng@windriver.com>

At present the codes uses sigaction() to install signal handler with
a flag SA_RESETHAND. Such usage can be covered by the signal() API
that is a simplified interface to the general sigaction() facility.

Update to use signal() to install the signal handler, as it is
avaiable on Windows which we are going to support.

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

 tests/qtest/libqtest.c | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)

diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
index 1b24a4f1f7..70d7578740 100644
--- a/tests/qtest/libqtest.c
+++ b/tests/qtest/libqtest.c
@@ -68,7 +68,7 @@ struct QTestState
 QTestState *global_qtest;
 
 static GHookList abrt_hooks;
-static struct sigaction sigact_old;
+static sighandler_t sighandler_old;
 
 static int qtest_query_target_endianness(QTestState *s);
 
@@ -181,20 +181,12 @@ static void sigabrt_handler(int signo)
 
 static void setup_sigabrt_handler(void)
 {
-    struct sigaction sigact;
-
-    /* Catch SIGABRT to clean up on g_assert() failure */
-    sigact = (struct sigaction){
-        .sa_handler = sigabrt_handler,
-        .sa_flags = SA_RESETHAND,
-    };
-    sigemptyset(&sigact.sa_mask);
-    sigaction(SIGABRT, &sigact, &sigact_old);
+    sighandler_old = signal(SIGABRT, sigabrt_handler);
 }
 
 static void cleanup_sigabrt_handler(void)
 {
-    sigaction(SIGABRT, &sigact_old, NULL);
+    signal(SIGABRT, sighandler_old);
 }
 
 static bool hook_list_is_empty(GHookList *hook_list)
-- 
2.34.1



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

* [PATCH 30/51] tests: Skip iotests and qtest when '--without-default-devices'
  2022-08-24  9:39 [PATCH 00/51] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (28 preceding siblings ...)
  2022-08-24  9:40 ` [PATCH 29/51] tests/qtest: libqtest: Install signal handler via signal() Bin Meng
@ 2022-08-24  9:40 ` Bin Meng
  2022-08-25 12:03   ` Thomas Huth
  2022-08-24  9:40 ` [PATCH 31/51] tests/qtest: Support libqtest to build and run on Windows Bin Meng
                   ` (20 subsequent siblings)
  50 siblings, 1 reply; 174+ messages in thread
From: Bin Meng @ 2022-08-24  9:40 UTC (permalink / raw)
  To: qemu-devel
  Cc: Bin Meng, Hanna Reitz, Kevin Wolf, Laurent Vivier, Paolo Bonzini,
	Thomas Huth, qemu-block

From: Bin Meng <bin.meng@windriver.com>

When QEMU is configured with '--without-default-devices', we should
not build and run iotests and qtest because devices used by these
test cases are not built in.

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

 tests/qemu-iotests/meson.build | 5 +++++
 tests/qtest/meson.build        | 5 +++++
 2 files changed, 10 insertions(+)

diff --git a/tests/qemu-iotests/meson.build b/tests/qemu-iotests/meson.build
index 323a4acb6a..38d9a874d2 100644
--- a/tests/qemu-iotests/meson.build
+++ b/tests/qemu-iotests/meson.build
@@ -2,6 +2,11 @@ if not have_tools or targetos == 'windows' or get_option('gprof')
   subdir_done()
 endif
 
+# Skip iotests if configured without a default selection of devices
+if not get_option('default_devices')
+  subdir_done()
+endif
+
 foreach cflag: config_host['QEMU_CFLAGS'].split()
   if cflag.startswith('-fsanitize') and \
      not cflag.contains('safe-stack') and not cflag.contains('cfi-icall')
diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
index c97da5a062..0291b3966c 100644
--- a/tests/qtest/meson.build
+++ b/tests/qtest/meson.build
@@ -4,6 +4,11 @@ if not config_host.has_key('CONFIG_POSIX')
   subdir_done()
 endif
 
+# Skip QTests if configured without a default selection of devices
+if not get_option('default_devices')
+  subdir_done()
+endif
+
 slow_qtests = {
   'ahci-test' : 60,
   'bios-tables-test' : 120,
-- 
2.34.1



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

* [PATCH 31/51] tests/qtest: Support libqtest to build and run on Windows
  2022-08-24  9:39 [PATCH 00/51] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (29 preceding siblings ...)
  2022-08-24  9:40 ` [PATCH 30/51] tests: Skip iotests and qtest when '--without-default-devices' Bin Meng
@ 2022-08-24  9:40 ` Bin Meng
  2022-08-31 16:28   ` Marc-André Lureau
  2022-09-01 11:38   ` Marc-André Lureau
  2022-08-24  9:40 ` [PATCH 32/51] tests/qtest: Fix ERROR_SHARING_VIOLATION for win32 Bin Meng
                   ` (19 subsequent siblings)
  50 siblings, 2 replies; 174+ messages in thread
From: Bin Meng @ 2022-08-24  9:40 UTC (permalink / raw)
  To: qemu-devel
  Cc: Bin Meng, Xuzhou Cheng, Laurent Vivier, Paolo Bonzini, Thomas Huth

From: Bin Meng <bin.meng@windriver.com>

At present the libqtest codes were written to depend on several
POSIX APIs, including fork(), kill() and waitpid(). Unfortunately
these APIs are not available on Windows.

This commit implements the corresponding functionalities using
win32 native APIs. With this change, all qtest cases can build
successfully on a Windows host, and we can start qtest testing
on Windows now.

Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
Signed-off-by: Bin Meng <bin.meng@windriver.com>
---

 tests/qtest/libqtest.c  | 101 +++++++++++++++++++++++++++++++++++++++-
 tests/qtest/meson.build |   5 +-
 2 files changed, 101 insertions(+), 5 deletions(-)

diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
index 70d7578740..99e52ff571 100644
--- a/tests/qtest/libqtest.c
+++ b/tests/qtest/libqtest.c
@@ -16,9 +16,11 @@
 
 #include "qemu/osdep.h"
 
+#ifndef _WIN32
 #include <sys/socket.h>
 #include <sys/wait.h>
 #include <sys/un.h>
+#endif /* _WIN32 */
 #ifdef __linux__
 #include <sys/prctl.h>
 #endif /* __linux__ */
@@ -27,6 +29,7 @@
 #include "libqmp.h"
 #include "qemu/ctype.h"
 #include "qemu/cutils.h"
+#include "qemu/sockets.h"
 #include "qapi/qmp/qdict.h"
 #include "qapi/qmp/qjson.h"
 #include "qapi/qmp/qlist.h"
@@ -35,6 +38,16 @@
 #define MAX_IRQ 256
 #define SOCKET_TIMEOUT 50
 
+#ifndef _WIN32
+# define CMD_EXEC   "exec "
+# define DEV_STDERR "/dev/fd/2"
+# define DEV_NULL   "/dev/null"
+#else
+# define CMD_EXEC   ""
+# define DEV_STDERR "2"
+# define DEV_NULL   "nul"
+#endif
+
 typedef void (*QTestSendFn)(QTestState *s, const char *buf);
 typedef void (*ExternalSendFn)(void *s, const char *buf);
 typedef GString* (*QTestRecvFn)(QTestState *);
@@ -68,6 +81,9 @@ struct QTestState
 QTestState *global_qtest;
 
 static GHookList abrt_hooks;
+#ifdef _WIN32
+typedef void (*sighandler_t)(int);
+#endif
 static sighandler_t sighandler_old;
 
 static int qtest_query_target_endianness(QTestState *s);
@@ -120,10 +136,18 @@ bool qtest_probe_child(QTestState *s)
     pid_t pid = s->qemu_pid;
 
     if (pid != -1) {
+#ifndef _WIN32
         pid = waitpid(pid, &s->wstatus, WNOHANG);
         if (pid == 0) {
             return true;
         }
+#else
+        DWORD exit_code;
+        GetExitCodeProcess((HANDLE)pid, &exit_code);
+        if (exit_code == STILL_ACTIVE) {
+            return true;
+        }
+#endif
         s->qemu_pid = -1;
     }
     return false;
@@ -137,13 +161,23 @@ void qtest_set_expected_status(QTestState *s, int status)
 void qtest_kill_qemu(QTestState *s)
 {
     pid_t pid = s->qemu_pid;
+#ifndef _WIN32
     int wstatus;
+#else
+    DWORD ret, exit_code;
+#endif
 
     /* Skip wait if qtest_probe_child already reaped.  */
     if (pid != -1) {
+#ifndef _WIN32
         kill(pid, SIGTERM);
         TFR(pid = waitpid(s->qemu_pid, &s->wstatus, 0));
         assert(pid == s->qemu_pid);
+#else
+        TerminateProcess((HANDLE)pid, s->expected_status);
+        ret = WaitForSingleObject((HANDLE)pid, INFINITE);
+        assert(ret == WAIT_OBJECT_0);
+#endif
         s->qemu_pid = -1;
     }
 
@@ -151,6 +185,7 @@ void qtest_kill_qemu(QTestState *s)
      * Check whether qemu exited with expected exit status; anything else is
      * fishy and should be logged with as much detail as possible.
      */
+#ifndef _WIN32
     wstatus = s->wstatus;
     if (WIFEXITED(wstatus) && WEXITSTATUS(wstatus) != s->expected_status) {
         fprintf(stderr, "%s:%d: kill_qemu() tried to terminate QEMU "
@@ -167,6 +202,16 @@ void qtest_kill_qemu(QTestState *s)
                 __FILE__, __LINE__, sig, signame, dump);
         abort();
     }
+#else
+    GetExitCodeProcess((HANDLE)pid, &exit_code);
+    CloseHandle((HANDLE)pid);
+    if (exit_code != s->expected_status) {
+        fprintf(stderr, "%s:%d: kill_qemu() tried to terminate QEMU "
+                "process but encountered exit status %ld (expected %d)\n",
+                __FILE__, __LINE__, exit_code, s->expected_status);
+        abort();
+    }
+#endif
 }
 
 static void kill_qemu_hook_func(void *s)
@@ -245,6 +290,38 @@ static const char *qtest_qemu_binary(void)
     return qemu_bin;
 }
 
+#ifdef _WIN32
+static pid_t qtest_create_process(char *cmd)
+{
+    STARTUPINFO si;
+    PROCESS_INFORMATION pi;
+    BOOL ret;
+
+    ZeroMemory(&si, sizeof(si));
+    si.cb = sizeof(si);
+    ZeroMemory(&pi, sizeof(pi));
+
+    ret = CreateProcess(NULL,   /* module name */
+                        cmd,    /* command line */
+                        NULL,   /* process handle not inheritable */
+                        NULL,   /* thread handle not inheritable */
+                        FALSE,  /* set handle inheritance to FALSE */
+                        0,      /* No creation flags */
+                        NULL,   /* use parent's environment block */
+                        NULL,   /* use parent's starting directory */
+                        &si,    /* pointer to STARTUPINFO structure */
+                        &pi     /* pointer to PROCESS_INFORMATION structure */
+                        );
+    if (ret == 0) {
+        fprintf(stderr, "%s:%d: unable to create a new process (%s)\n",
+                __FILE__, __LINE__, strerror(GetLastError()));
+        abort();
+    }
+
+    return (pid_t)pi.hProcess;
+}
+#endif /* _WIN32 */
+
 QTestState *qtest_init_without_qmp_handshake(const char *extra_args)
 {
     QTestState *s;
@@ -272,6 +349,9 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args)
     unlink(socket_path);
     unlink(qmp_socket_path);
 
+#ifdef _WIN32
+    socket_init();
+#endif
     sock = init_socket(socket_path);
     qmpsock = init_socket(qmp_socket_path);
 
@@ -280,7 +360,7 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args)
 
     qtest_add_abrt_handler(kill_qemu_hook_func, s);
 
-    command = g_strdup_printf("exec %s %s"
+    command = g_strdup_printf(CMD_EXEC "%s %s"
                               "-qtest unix:%s "
                               "-qtest-log %s "
                               "-chardev socket,path=%s,id=char0 "
@@ -289,7 +369,7 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args)
                               "%s"
                               " -accel qtest",
                               qemu_binary, tracearg, socket_path,
-                              getenv("QTEST_LOG") ? "/dev/fd/2" : "/dev/null",
+                              getenv("QTEST_LOG") ? DEV_STDERR : DEV_NULL,
                               qmp_socket_path,
                               extra_args ?: "");
 
@@ -298,6 +378,7 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args)
     s->pending_events = NULL;
     s->wstatus = 0;
     s->expected_status = 0;
+#ifndef _WIN32
     s->qemu_pid = fork();
     if (s->qemu_pid == 0) {
 #ifdef __linux__
@@ -320,6 +401,9 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args)
         execlp("/bin/sh", "sh", "-c", command, NULL);
         exit(1);
     }
+#else
+    s->qemu_pid = qtest_create_process(command);
+#endif /* _WIN32 */
 
     g_free(command);
     s->fd = socket_accept(sock);
@@ -338,9 +422,19 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args)
         s->irq_level[i] = false;
     }
 
+    /*
+     * Stopping QEMU for debugging is not supported on Windows.
+     *
+     * Using DebugActiveProcess() API can suspend the QEMU process,
+     * but gdb cannot attach to the process. Using the undocumented
+     * NtSuspendProcess() can suspend the QEMU process and gdb can
+     * attach to the process, but gdb cannot resume it.
+     */
+#ifndef _WIN32
     if (getenv("QTEST_STOP")) {
         kill(s->qemu_pid, SIGSTOP);
     }
+#endif
 
     /* ask endianness of the target */
 
@@ -393,6 +487,9 @@ QTestState *qtest_init_with_serial(const char *extra_args, int *sock_fd)
     g_assert_true(g_mkdtemp(sock_dir) != NULL);
     sock_path = g_strdup_printf("%s/sock", sock_dir);
 
+#ifdef _WIN32
+    socket_init();
+#endif
     sock_fd_init = init_socket(sock_path);
 
     qts = qtest_initf("-chardev socket,id=s0,path=%s -serial chardev:s0 %s",
diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
index 0291b3966c..6d469a1822 100644
--- a/tests/qtest/meson.build
+++ b/tests/qtest/meson.build
@@ -1,6 +1,5 @@
-# All QTests for now are POSIX-only, but the dependencies are
-# really in libqtest, not in the testcases themselves.
-if not config_host.has_key('CONFIG_POSIX')
+# Build all QTests for POSIX and Windows
+if not config_host.has_key('CONFIG_POSIX') and not config_host.has_key('CONFIG_WIN32')
   subdir_done()
 endif
 
-- 
2.34.1



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

* [PATCH 32/51] tests/qtest: Fix ERROR_SHARING_VIOLATION for win32
  2022-08-24  9:39 [PATCH 00/51] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (30 preceding siblings ...)
  2022-08-24  9:40 ` [PATCH 31/51] tests/qtest: Support libqtest to build and run on Windows Bin Meng
@ 2022-08-24  9:40 ` Bin Meng
  2022-08-25 12:06   ` Thomas Huth
  2022-09-01  8:42   ` Marc-André Lureau
  2022-08-24  9:40 ` [PATCH 33/51] tests/qtest: {ahci, ide}-test: Use relative path for temporary files Bin Meng
                   ` (18 subsequent siblings)
  50 siblings, 2 replies; 174+ messages in thread
From: Bin Meng @ 2022-08-24  9:40 UTC (permalink / raw)
  To: qemu-devel
  Cc: Bin Meng, John Snow, Laurent Vivier, Paolo Bonzini, Thomas Huth,
	qemu-block

From: Bin Meng <bin.meng@windriver.com>

On Windows, the MinGW provided mkstemp() API opens the file with
exclusive access, denying other processes to read/write the file.
Such behavior prevents the QEMU executable from opening the file,
(e.g.: CreateFile returns ERROR_SHARING_VIOLATION).

This can be fixed by closing the file and reopening it.

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

 tests/qtest/ahci-test.c        | 14 ++++++++++++++
 tests/qtest/boot-serial-test.c | 13 +++++++++++++
 2 files changed, 27 insertions(+)

diff --git a/tests/qtest/ahci-test.c b/tests/qtest/ahci-test.c
index f26cd6f86f..0e88cd0eef 100644
--- a/tests/qtest/ahci-test.c
+++ b/tests/qtest/ahci-test.c
@@ -1443,6 +1443,20 @@ static int prepare_iso(size_t size, unsigned char **buf, char **name)
     int fd = mkstemp(cdrom_path);
 
     g_assert(fd != -1);
+#ifdef _WIN32
+    /*
+     * On Windows, the MinGW provided mkstemp() API opens the file with
+     * exclusive access, denying other processes to read/write the file.
+     * Such behavior prevents the QEMU executable from opening the file,
+     * (e.g.: CreateFile returns ERROR_SHARING_VIOLATION).
+     *
+     * Close the file and reopen it.
+     */
+    close(fd);
+    fd = open(cdrom_path, O_WRONLY);
+    g_assert(fd != -1);
+#endif
+
     g_assert(buf);
     g_assert(name);
     patt = g_malloc(size);
diff --git a/tests/qtest/boot-serial-test.c b/tests/qtest/boot-serial-test.c
index 404adcfa20..fb6c81bf35 100644
--- a/tests/qtest/boot-serial-test.c
+++ b/tests/qtest/boot-serial-test.c
@@ -235,6 +235,19 @@ static void test_machine(const void *data)
 
     ser_fd = mkstemp(serialtmp);
     g_assert(ser_fd != -1);
+#ifdef _WIN32
+    /*
+     * On Windows, the MinGW provided mkstemp() API opens the file with
+     * exclusive access, denying other processes to read/write the file.
+     * Such behavior prevents the QEMU executable from opening the file,
+     * (e.g.: CreateFile returns ERROR_SHARING_VIOLATION).
+     *
+     * Close the file and reopen it.
+     */
+    close(ser_fd);
+    ser_fd = open(serialtmp, O_RDONLY);
+    g_assert(ser_fd != -1);
+#endif
 
     if (test->kernel) {
         code = test->kernel;
-- 
2.34.1



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

* [PATCH 33/51] tests/qtest: {ahci, ide}-test: Use relative path for temporary files
  2022-08-24  9:39 [PATCH 00/51] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (31 preceding siblings ...)
  2022-08-24  9:40 ` [PATCH 32/51] tests/qtest: Fix ERROR_SHARING_VIOLATION for win32 Bin Meng
@ 2022-08-24  9:40 ` Bin Meng
  2022-09-01  8:58   ` Marc-André Lureau
  2022-08-24  9:40 ` [PATCH 34/51] tests/qtest: bios-tables-test: Adapt the case for win32 Bin Meng
                   ` (17 subsequent siblings)
  50 siblings, 1 reply; 174+ messages in thread
From: Bin Meng @ 2022-08-24  9:40 UTC (permalink / raw)
  To: qemu-devel
  Cc: Bin Meng, John Snow, Laurent Vivier, Paolo Bonzini, Thomas Huth,
	qemu-block

From: Bin Meng <bin.meng@windriver.com>

These test cases uses "blkdebug:path/to/config:path/to/image" for
testing. On Windows, absolute file paths contain the delimiter ':'
which causes the blkdebug filename parser fail to parse filenames.

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

 tests/qtest/ahci-test.c | 19 ++++++++++++++++---
 tests/qtest/ide-test.c  | 18 ++++++++++++++++--
 2 files changed, 32 insertions(+), 5 deletions(-)

diff --git a/tests/qtest/ahci-test.c b/tests/qtest/ahci-test.c
index 0e88cd0eef..bce9ff770c 100644
--- a/tests/qtest/ahci-test.c
+++ b/tests/qtest/ahci-test.c
@@ -1848,7 +1848,7 @@ static void create_ahci_io_test(enum IOMode type, enum AddrMode addr,
 
 int main(int argc, char **argv)
 {
-    const char *arch;
+    const char *arch, *base;
     int ret;
     int fd;
     int c;
@@ -1886,8 +1886,21 @@ int main(int argc, char **argv)
         return 0;
     }
 
+    /*
+     * "base" stores the starting point where we create temporary files.
+     *
+     * On Windows, this is set to the relative path of current working
+     * directory, because the absolute path causes the blkdebug filename
+     * parser fail to parse "blkdebug:path/to/config:path/to/image".
+     */
+#ifndef _WIN32
+    base = g_get_tmp_dir();
+#else
+    base = ".";
+#endif
+
     /* Create a temporary image */
-    tmp_path = g_strdup_printf("%s/qtest.XXXXXX", g_get_tmp_dir());
+    tmp_path = g_strdup_printf("%s/qtest.XXXXXX", base);
     fd = mkstemp(tmp_path);
     g_assert(fd >= 0);
     if (have_qemu_img()) {
@@ -1905,7 +1918,7 @@ int main(int argc, char **argv)
     close(fd);
 
     /* Create temporary blkdebug instructions */
-    debug_path = g_strdup_printf("%s/qtest-blkdebug.XXXXXX", g_get_tmp_dir());
+    debug_path = g_strdup_printf("%s/qtest-blkdebug.XXXXXX", base);
     fd = mkstemp(debug_path);
     g_assert(fd >= 0);
     close(fd);
diff --git a/tests/qtest/ide-test.c b/tests/qtest/ide-test.c
index ebbf8e0126..c5cad6c0be 100644
--- a/tests/qtest/ide-test.c
+++ b/tests/qtest/ide-test.c
@@ -1011,17 +1011,31 @@ static void test_cdrom_dma(void)
 
 int main(int argc, char **argv)
 {
+    const char *base;
     int fd;
     int ret;
 
+    /*
+     * "base" stores the starting point where we create temporary files.
+     *
+     * On Windows, this is set to the relative path of current working
+     * directory, because the absolute path causes the blkdebug filename
+     * parser fail to parse "blkdebug:path/to/config:path/to/image".
+     */
+#ifndef _WIN32
+    base = g_get_tmp_dir();
+#else
+    base = ".";
+#endif
+
     /* Create temporary blkdebug instructions */
-    debug_path = g_strdup_printf("%s/qtest-blkdebug.XXXXXX", g_get_tmp_dir());
+    debug_path = g_strdup_printf("%s/qtest-blkdebug.XXXXXX", base);
     fd = mkstemp(debug_path);
     g_assert(fd >= 0);
     close(fd);
 
     /* Create a temporary raw image */
-    tmp_path = g_strdup_printf("%s/qtest.XXXXXX", g_get_tmp_dir());
+    tmp_path = g_strdup_printf("%s/qtest.XXXXXX", base);
     fd = mkstemp(tmp_path);
     g_assert(fd >= 0);
     ret = ftruncate(fd, TEST_IMAGE_SIZE);
-- 
2.34.1



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

* [PATCH 34/51] tests/qtest: bios-tables-test: Adapt the case for win32
  2022-08-24  9:39 [PATCH 00/51] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (32 preceding siblings ...)
  2022-08-24  9:40 ` [PATCH 33/51] tests/qtest: {ahci, ide}-test: Use relative path for temporary files Bin Meng
@ 2022-08-24  9:40 ` Bin Meng
  2022-08-24 12:42   ` Ani Sinha
  2022-09-01  9:05   ` Marc-André Lureau
  2022-08-24  9:40 ` [PATCH 35/51] tests/qtest: device-plug-test: Reverse the usage of double/single quotes Bin Meng
                   ` (16 subsequent siblings)
  50 siblings, 2 replies; 174+ messages in thread
From: Bin Meng @ 2022-08-24  9:40 UTC (permalink / raw)
  To: qemu-devel; +Cc: Bin Meng, Ani Sinha, Igor Mammedov, Michael S. Tsirkin

From: Bin Meng <bin.meng@windriver.com>

Single quotes in the arguments (oem_id='CRASH ') are not removed in
the Windows environment before it is passed to the QEMU executable.
The space in the argument causes the "-acpitable" option parser to
think that all of its parameters are done, hence it complains:

  '-acpitable' requires one of 'data' or 'file'

Change to use double quotes which works fine on all platforms.

Also /dev/null does not work on win32, and nul should be used.

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

 tests/qtest/bios-tables-test.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/tests/qtest/bios-tables-test.c b/tests/qtest/bios-tables-test.c
index 36783966b0..0148ce388c 100644
--- a/tests/qtest/bios-tables-test.c
+++ b/tests/qtest/bios-tables-test.c
@@ -1615,6 +1615,12 @@ static void test_acpi_virt_viot(void)
     free_test_data(&data);
 }
 
+#ifndef _WIN32
+# define DEV_NULL "/dev/null"
+#else
+# define DEV_NULL "nul"
+#endif
+
 static void test_acpi_q35_slic(void)
 {
     test_data data = {
@@ -1622,9 +1628,9 @@ static void test_acpi_q35_slic(void)
         .variant = ".slic",
     };
 
-    test_acpi_one("-acpitable sig=SLIC,oem_id='CRASH ',oem_table_id='ME',"
-                  "oem_rev=00002210,asl_compiler_id='qemu',"
-                  "asl_compiler_rev=00000000,data=/dev/null",
+    test_acpi_one("-acpitable sig=SLIC,oem_id=\"CRASH \",oem_table_id=ME,"
+                  "oem_rev=00002210,asl_compiler_id=qemu,"
+                  "asl_compiler_rev=00000000,data=" DEV_NULL,
                   &data);
     free_test_data(&data);
 }
-- 
2.34.1



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

* [PATCH 35/51] tests/qtest: device-plug-test: Reverse the usage of double/single quotes
  2022-08-24  9:39 [PATCH 00/51] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (33 preceding siblings ...)
  2022-08-24  9:40 ` [PATCH 34/51] tests/qtest: bios-tables-test: Adapt the case for win32 Bin Meng
@ 2022-08-24  9:40 ` Bin Meng
  2022-08-25 12:20   ` Thomas Huth
  2022-08-24  9:40 ` [PATCH 36/51] tests/qtest: machine-none-test: Use double quotes to pass the cpu option Bin Meng
                   ` (15 subsequent siblings)
  50 siblings, 1 reply; 174+ messages in thread
From: Bin Meng @ 2022-08-24  9:40 UTC (permalink / raw)
  To: qemu-devel; +Cc: Bin Meng, Laurent Vivier, Paolo Bonzini, Thomas Huth

From: Bin Meng <bin.meng@windriver.com>

The usage of double/single quotes in test_pci_unplug_json_request()
should be reversed to work on both win32 and non-win32 platforms:

- The value of -device parameter needs to be surrounded by "" as
  Windows does not drop '' when passing it to QEMU which causes
  QEMU command line option parser failure.
- The JSON key/value pairs need to be surrounded by '' to make the
  JSON parser happy on Windows.

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

 tests/qtest/device-plug-test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/qtest/device-plug-test.c b/tests/qtest/device-plug-test.c
index 2e3137843e..a1fb99c8ff 100644
--- a/tests/qtest/device-plug-test.c
+++ b/tests/qtest/device-plug-test.c
@@ -95,7 +95,7 @@ static void test_pci_unplug_json_request(void)
     }
 
     QTestState *qtest = qtest_initf(
-        "%s -device '{\"driver\": \"virtio-mouse-pci\", \"id\": \"dev0\"}'",
+        "%s -device \"{'driver': 'virtio-mouse-pci', 'id': 'dev0'}\"",
         machine_addition);
 
     /*
-- 
2.34.1



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

* [PATCH 36/51] tests/qtest: machine-none-test: Use double quotes to pass the cpu option
  2022-08-24  9:39 [PATCH 00/51] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (34 preceding siblings ...)
  2022-08-24  9:40 ` [PATCH 35/51] tests/qtest: device-plug-test: Reverse the usage of double/single quotes Bin Meng
@ 2022-08-24  9:40 ` Bin Meng
  2022-08-25 12:22   ` Thomas Huth
  2022-08-24  9:40 ` [PATCH 37/51] tests/qtest: migration-test: Disable IO redirection for win32 Bin Meng
                   ` (14 subsequent siblings)
  50 siblings, 1 reply; 174+ messages in thread
From: Bin Meng @ 2022-08-24  9:40 UTC (permalink / raw)
  To: qemu-devel; +Cc: Bin Meng, Laurent Vivier, Paolo Bonzini, Thomas Huth

From: Bin Meng <bin.meng@windriver.com>

Single quotes in the arguments (e.g.: -cpu 'qemu64,apic-id=0') are
not removed in the Windows environment before it is passed to the
QEMU executable. Such argument causes a failure in the QEMU CPU
option parser codes.

Change to use double quotes which works fine on all platforms.

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

 tests/qtest/machine-none-test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/qtest/machine-none-test.c b/tests/qtest/machine-none-test.c
index f92fab479f..31cc0bfb01 100644
--- a/tests/qtest/machine-none-test.c
+++ b/tests/qtest/machine-none-test.c
@@ -81,7 +81,7 @@ static void test_machine_cpu_cli(void)
                 " add it to cpus_map\n", arch);
         return; /* TODO: die here to force all targets have a test */
     }
-    qts = qtest_initf("-machine none -cpu '%s'", cpu_model);
+    qts = qtest_initf("-machine none -cpu \"%s\"", cpu_model);
 
     response = qtest_qmp(qts, "{ 'execute': 'quit' }");
     g_assert(qdict_haskey(response, "return"));
-- 
2.34.1



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

* [PATCH 37/51] tests/qtest: migration-test: Disable IO redirection for win32
  2022-08-24  9:39 [PATCH 00/51] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (35 preceding siblings ...)
  2022-08-24  9:40 ` [PATCH 36/51] tests/qtest: machine-none-test: Use double quotes to pass the cpu option Bin Meng
@ 2022-08-24  9:40 ` Bin Meng
  2022-08-24 18:53   ` Dr. David Alan Gilbert
  2022-08-24  9:40 ` [PATCH 38/51] tests/qtest: {ahci,ide}-test: Open file in binary mode Bin Meng
                   ` (13 subsequent siblings)
  50 siblings, 1 reply; 174+ messages in thread
From: Bin Meng @ 2022-08-24  9:40 UTC (permalink / raw)
  To: qemu-devel
  Cc: Bin Meng, Dr. David Alan Gilbert, Juan Quintela, Laurent Vivier,
	Paolo Bonzini, Thomas Huth

From: Bin Meng <bin.meng@windriver.com>

On Windows the QEMU executable is created via CreateProcess() and IO
redirection does not work, so we need to set MigrateStart::hide_stderr
to false to disable adding IO redirection to the command line.

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

 tests/qtest/migration-test.c | 39 +++++++++++++++++++++++-------------
 1 file changed, 25 insertions(+), 14 deletions(-)

diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index 2ae7498d5d..125d48d855 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -53,6 +53,17 @@ static bool uffd_feature_thread_id;
  */
 #define DIRTYLIMIT_TOLERANCE_RANGE  25  /* MB/s */
 
+/*
+ * On Windows the QEMU executable is created via CreateProcess() and IO
+ * redirection does not work, so we need to set MigrateStart::hide_stderr
+ * to false to disable adding IO redirection to the command line.
+ */
+#ifndef _WIN32
+# define HIDE_STDERR true
+#else
+# define HIDE_STDERR false
+#endif
+
 #if defined(__linux__)
 #include <sys/syscall.h>
 #include <sys/vfs.h>
@@ -1186,7 +1197,7 @@ static void test_postcopy_recovery_common(MigrateCommon *args)
     g_autofree char *uri = NULL;
 
     /* Always hide errors for postcopy recover tests since they're expected */
-    args->start.hide_stderr = true;
+    args->start.hide_stderr = HIDE_STDERR;
 
     if (migrate_postcopy_prepare(&from, &to, args)) {
         return;
@@ -1287,7 +1298,7 @@ static void test_postcopy_preempt_all(void)
 static void test_baddest(void)
 {
     MigrateStart args = {
-        .hide_stderr = true
+        .hide_stderr = HIDE_STDERR
     };
     QTestState *from, *to;
 
@@ -1410,7 +1421,7 @@ static void test_precopy_unix_tls_x509_default_host(void)
     g_autofree char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
     MigrateCommon args = {
         .start = {
-            .hide_stderr = true,
+            .hide_stderr = HIDE_STDERR,
         },
         .connect_uri = uri,
         .listen_uri = uri,
@@ -1526,7 +1537,7 @@ static void test_precopy_tcp_tls_psk_mismatch(void)
 {
     MigrateCommon args = {
         .start = {
-            .hide_stderr = true,
+            .hide_stderr = HIDE_STDERR,
         },
         .listen_uri = "tcp:127.0.0.1:0",
         .start_hook = test_migrate_tls_psk_start_mismatch,
@@ -1564,7 +1575,7 @@ static void test_precopy_tcp_tls_x509_mismatch_host(void)
 {
     MigrateCommon args = {
         .start = {
-            .hide_stderr = true,
+            .hide_stderr = HIDE_STDERR,
         },
         .listen_uri = "tcp:127.0.0.1:0",
         .start_hook = test_migrate_tls_x509_start_mismatch_host,
@@ -1590,7 +1601,7 @@ static void test_precopy_tcp_tls_x509_hostile_client(void)
 {
     MigrateCommon args = {
         .start = {
-            .hide_stderr = true,
+            .hide_stderr = HIDE_STDERR,
         },
         .listen_uri = "tcp:127.0.0.1:0",
         .start_hook = test_migrate_tls_x509_start_hostile_client,
@@ -1616,7 +1627,7 @@ static void test_precopy_tcp_tls_x509_reject_anon_client(void)
 {
     MigrateCommon args = {
         .start = {
-            .hide_stderr = true,
+            .hide_stderr = HIDE_STDERR,
         },
         .listen_uri = "tcp:127.0.0.1:0",
         .start_hook = test_migrate_tls_x509_start_reject_anon_client,
@@ -1747,7 +1758,7 @@ static void test_validate_uuid_error(void)
     MigrateStart args = {
         .opts_source = "-uuid 11111111-1111-1111-1111-111111111111",
         .opts_target = "-uuid 22222222-2222-2222-2222-222222222222",
-        .hide_stderr = true,
+        .hide_stderr = HIDE_STDERR,
     };
 
     do_test_validate_uuid(&args, true);
@@ -1757,7 +1768,7 @@ static void test_validate_uuid_src_not_set(void)
 {
     MigrateStart args = {
         .opts_target = "-uuid 22222222-2222-2222-2222-222222222222",
-        .hide_stderr = true,
+        .hide_stderr = HIDE_STDERR,
     };
 
     do_test_validate_uuid(&args, false);
@@ -1767,7 +1778,7 @@ static void test_validate_uuid_dst_not_set(void)
 {
     MigrateStart args = {
         .opts_source = "-uuid 11111111-1111-1111-1111-111111111111",
-        .hide_stderr = true,
+        .hide_stderr = HIDE_STDERR,
     };
 
     do_test_validate_uuid(&args, false);
@@ -1990,7 +2001,7 @@ static void test_multifd_tcp_tls_psk_mismatch(void)
 {
     MigrateCommon args = {
         .start = {
-            .hide_stderr = true,
+            .hide_stderr = HIDE_STDERR,
         },
         .listen_uri = "defer",
         .start_hook = test_migrate_multifd_tcp_tls_psk_start_mismatch,
@@ -2038,7 +2049,7 @@ static void test_multifd_tcp_tls_x509_mismatch_host(void)
      */
     MigrateCommon args = {
         .start = {
-            .hide_stderr = true,
+            .hide_stderr = HIDE_STDERR,
         },
         .listen_uri = "defer",
         .start_hook = test_migrate_multifd_tls_x509_start_mismatch_host,
@@ -2062,7 +2073,7 @@ static void test_multifd_tcp_tls_x509_reject_anon_client(void)
 {
     MigrateCommon args = {
         .start = {
-            .hide_stderr = true,
+            .hide_stderr = HIDE_STDERR,
         },
         .listen_uri = "defer",
         .start_hook = test_migrate_multifd_tls_x509_start_reject_anon_client,
@@ -2088,7 +2099,7 @@ static void test_multifd_tcp_tls_x509_reject_anon_client(void)
 static void test_multifd_tcp_cancel(void)
 {
     MigrateStart args = {
-        .hide_stderr = true,
+        .hide_stderr = HIDE_STDERR,
     };
     QTestState *from, *to, *to2;
     QDict *rsp;
-- 
2.34.1



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

* [PATCH 38/51] tests/qtest: {ahci,ide}-test: Open file in binary mode
  2022-08-24  9:39 [PATCH 00/51] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (36 preceding siblings ...)
  2022-08-24  9:40 ` [PATCH 37/51] tests/qtest: migration-test: Disable IO redirection for win32 Bin Meng
@ 2022-08-24  9:40 ` Bin Meng
  2022-08-25 12:28   ` Thomas Huth
  2022-09-01  9:08   ` [PATCH 38/51] tests/qtest: {ahci, ide}-test: " Marc-André Lureau
  2022-08-24  9:40 ` [PATCH 39/51] tests/qtest: virtio-net-failover: Disable migration tests for win32 Bin Meng
                   ` (12 subsequent siblings)
  50 siblings, 2 replies; 174+ messages in thread
From: Bin Meng @ 2022-08-24  9:40 UTC (permalink / raw)
  To: qemu-devel
  Cc: Xuzhou Cheng, Bin Meng, John Snow, Laurent Vivier, Paolo Bonzini,
	Thomas Huth, qemu-block

From: Xuzhou Cheng <xuzhou.cheng@windriver.com>

By default Windows opens file in text mode, while a POSIX compliant
implementation treats text files and binary files the same.

The fopen() 'mode' string can include the letter 'b' to indicate
binary mode shall be used. POSIX spec says the character 'b' shall
have no effect, but is allowed for ISO C standard conformance.
Let's add the letter 'b' which works on both POSIX and Windows.

Similar situation applies to the open() 'flags' where O_BINARY is
used for binary mode.

Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
Signed-off-by: Bin Meng <bin.meng@windriver.com>
---

 tests/qtest/ahci-test.c | 2 +-
 tests/qtest/ide-test.c  | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/tests/qtest/ahci-test.c b/tests/qtest/ahci-test.c
index bce9ff770c..be11508c75 100644
--- a/tests/qtest/ahci-test.c
+++ b/tests/qtest/ahci-test.c
@@ -1453,7 +1453,7 @@ static int prepare_iso(size_t size, unsigned char **buf, char **name)
      * Close the file and reopen it.
      */
     close(fd);
-    fd = open(cdrom_path, O_WRONLY);
+    fd = open(cdrom_path, O_WRONLY | O_BINARY);
     g_assert(fd != -1);
 #endif
 
diff --git a/tests/qtest/ide-test.c b/tests/qtest/ide-test.c
index c5cad6c0be..ee03dea4fa 100644
--- a/tests/qtest/ide-test.c
+++ b/tests/qtest/ide-test.c
@@ -892,7 +892,7 @@ static void cdrom_pio_impl(int nblocks)
 
     /* Prepopulate the CDROM with an interesting pattern */
     generate_pattern(pattern, patt_len, ATAPI_BLOCK_SIZE);
-    fh = fopen(tmp_path, "w+");
+    fh = fopen(tmp_path, "wb+");
     ret = fwrite(pattern, ATAPI_BLOCK_SIZE, patt_blocks, fh);
     g_assert_cmpint(ret, ==, patt_blocks);
     fclose(fh);
@@ -993,7 +993,7 @@ static void test_cdrom_dma(void)
     prdt[0].size = cpu_to_le32(len | PRDT_EOT);
 
     generate_pattern(pattern, ATAPI_BLOCK_SIZE * 16, ATAPI_BLOCK_SIZE);
-    fh = fopen(tmp_path, "w+");
+    fh = fopen(tmp_path, "wb+");
     ret = fwrite(pattern, ATAPI_BLOCK_SIZE, 16, fh);
     g_assert_cmpint(ret, ==, 16);
     fclose(fh);
-- 
2.34.1



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

* [PATCH 39/51] tests/qtest: virtio-net-failover: Disable migration tests for win32
  2022-08-24  9:39 [PATCH 00/51] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (37 preceding siblings ...)
  2022-08-24  9:40 ` [PATCH 38/51] tests/qtest: {ahci,ide}-test: Open file in binary mode Bin Meng
@ 2022-08-24  9:40 ` Bin Meng
  2022-08-24  9:40 ` [PATCH 40/51] chardev/char-file: Add FILE_SHARE_WRITE when openning the file " Bin Meng
                   ` (11 subsequent siblings)
  50 siblings, 0 replies; 174+ messages in thread
From: Bin Meng @ 2022-08-24  9:40 UTC (permalink / raw)
  To: qemu-devel
  Cc: Xuzhou Cheng, Bin Meng, Laurent Vivier, Paolo Bonzini, Thomas Huth

From: Xuzhou Cheng <xuzhou.cheng@windriver.com>

These tests use the exec migration protocol, which is unsupported
on Windows as of today. Disable these tests for now.

Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
Signed-off-by: Bin Meng <bin.meng@windriver.com>
---

 tests/qtest/virtio-net-failover.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/tests/qtest/virtio-net-failover.c b/tests/qtest/virtio-net-failover.c
index 443ee56de9..4a809590bf 100644
--- a/tests/qtest/virtio-net-failover.c
+++ b/tests/qtest/virtio-net-failover.c
@@ -588,6 +588,7 @@ static void test_hotplug_2_reverse(void)
     machine_stop(qts);
 }
 
+#ifndef _WIN32
 static QDict *migrate_status(QTestState *qts)
 {
     QDict *resp, *ret;
@@ -1827,6 +1828,7 @@ static void test_multi_in(gconstpointer opaque)
 
     machine_stop(qts);
 }
+#endif /* _WIN32 */
 
 int main(int argc, char **argv)
 {
@@ -1857,7 +1859,11 @@ int main(int argc, char **argv)
     qtest_add_func("failover-virtio-net/hotplug/2_reverse",
                    test_hotplug_2_reverse);
 
-    /* migration tests */
+#ifndef _WIN32
+    /*
+     * These migration tests cases use the exec migration protocol,
+     * which is unsupported on Windows.
+     */
     qtest_add_data_func("failover-virtio-net/migrate/on/out", tmpfile,
                         test_migrate_out);
     qtest_add_data_func("failover-virtio-net/migrate/on/in", tmpfile,
@@ -1886,6 +1892,7 @@ int main(int argc, char **argv)
                         tmpfile, test_multi_out);
     qtest_add_data_func("failover-virtio-net/migrate/multi/in",
                    tmpfile, test_multi_in);
+#endif /* _WIN32 */
 
     ret = g_test_run();
 
-- 
2.34.1



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

* [PATCH 40/51] chardev/char-file: Add FILE_SHARE_WRITE when openning the file for win32
  2022-08-24  9:39 [PATCH 00/51] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (38 preceding siblings ...)
  2022-08-24  9:40 ` [PATCH 39/51] tests/qtest: virtio-net-failover: Disable migration tests for win32 Bin Meng
@ 2022-08-24  9:40 ` Bin Meng
  2022-08-25  7:58   ` Marc-André Lureau
  2022-08-24  9:40 ` [PATCH 41/51] tests/qtest: migration-test: Kill "to" after migration is canceled Bin Meng
                   ` (10 subsequent siblings)
  50 siblings, 1 reply; 174+ messages in thread
From: Bin Meng @ 2022-08-24  9:40 UTC (permalink / raw)
  To: qemu-devel; +Cc: Xuzhou Cheng, Bin Meng, Marc-André Lureau, Paolo Bonzini

From: Xuzhou Cheng <xuzhou.cheng@windriver.com>

The combination of GENERIC_WRITE and FILE_SHARE_READ options does
not allow the same file to be opened again by CreateFile() from
another QEMU process with the same options when the previous QEMU
process still holds the file handle openned.

As per [1] we should add FILE_SHARE_WRITE to the share mode to allow
such use case. This change makes the behavior be consisten with the
POSIX platforms.

[1] https://docs.microsoft.com/en-us/windows/win32/fileio/creating-and-opening-files

Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
Signed-off-by: Bin Meng <bin.meng@windriver.com>
---

 chardev/char-file.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/chardev/char-file.c b/chardev/char-file.c
index 2fd80707e5..66385211eb 100644
--- a/chardev/char-file.c
+++ b/chardev/char-file.c
@@ -60,8 +60,8 @@ static void qmp_chardev_open_file(Chardev *chr,
         flags = CREATE_ALWAYS;
     }
 
-    out = CreateFile(file->out, accessmode, FILE_SHARE_READ, NULL, flags,
-                     FILE_ATTRIBUTE_NORMAL, NULL);
+    out = CreateFile(file->out, accessmode, FILE_SHARE_READ | FILE_SHARE_WRITE,
+                     NULL, flags, FILE_ATTRIBUTE_NORMAL, NULL);
     if (out == INVALID_HANDLE_VALUE) {
         error_setg(errp, "open %s failed", file->out);
         return;
-- 
2.34.1



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

* [PATCH 41/51] tests/qtest: migration-test: Kill "to" after migration is canceled
  2022-08-24  9:39 [PATCH 00/51] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (39 preceding siblings ...)
  2022-08-24  9:40 ` [PATCH 40/51] chardev/char-file: Add FILE_SHARE_WRITE when openning the file " Bin Meng
@ 2022-08-24  9:40 ` Bin Meng
  2022-08-24 18:56   ` Dr. David Alan Gilbert
  2022-08-24  9:40 ` [PATCH 42/51] hw/ppc: spapr: Use qemu_vfree() to free spapr->htab Bin Meng
                   ` (9 subsequent siblings)
  50 siblings, 1 reply; 174+ messages in thread
From: Bin Meng @ 2022-08-24  9:40 UTC (permalink / raw)
  To: qemu-devel
  Cc: Xuzhou Cheng, Bin Meng, Dr. David Alan Gilbert, Juan Quintela,
	Laurent Vivier, Paolo Bonzini, Thomas Huth

From: Xuzhou Cheng <xuzhou.cheng@windriver.com>

Make sure QEMU process "to" is killed before launching another target
for migration in the test_multifd_tcp_cancel case.

Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
Signed-off-by: Bin Meng <bin.meng@windriver.com>
---

 tests/qtest/migration-test.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index 125d48d855..18ec079abf 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -2132,6 +2132,10 @@ static void test_multifd_tcp_cancel(void)
     wait_for_migration_pass(from);
 
     migrate_cancel(from);
+    /* Make sure QEMU process "to" is killed */
+    if (qtest_probe_child(to)) {
+        qtest_kill_qemu(to);
+    }
 
     args = (MigrateStart){
         .only_target = true,
-- 
2.34.1



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

* [PATCH 42/51] hw/ppc: spapr: Use qemu_vfree() to free spapr->htab
  2022-08-24  9:39 [PATCH 00/51] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (40 preceding siblings ...)
  2022-08-24  9:40 ` [PATCH 41/51] tests/qtest: migration-test: Kill "to" after migration is canceled Bin Meng
@ 2022-08-24  9:40 ` Bin Meng
  2022-08-24 17:32   ` Daniel Henrique Barboza
  2022-09-01 11:40   ` Marc-André Lureau
  2022-08-24  9:40 ` [PATCH 43/51] tests/qtest: npcm7xx_emc-test: Skip running test_{tx, rx} on win32 Bin Meng
                   ` (8 subsequent siblings)
  50 siblings, 2 replies; 174+ messages in thread
From: Bin Meng @ 2022-08-24  9:40 UTC (permalink / raw)
  To: qemu-devel
  Cc: Xuzhou Cheng, Bin Meng, Cédric Le Goater,
	Daniel Henrique Barboza, David Gibson, Greg Kurz, qemu-ppc

From: Xuzhou Cheng <xuzhou.cheng@windriver.com>

spapr->htab is allocated by qemu_memalign(), hence we should use
qemu_vfree() to free it.

Fixes: c5f54f3e31bf ("pseries: Move hash page table allocation to reset time")
Fixes: b4db54132ffe ("target/ppc: Implement H_REGISTER_PROCESS_TABLE H_CALL"")
Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
Signed-off-by: Bin Meng <bin.meng@windriver.com>
---

 hw/ppc/spapr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index bc9ba6e6dc..4034f4d130 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -1522,7 +1522,7 @@ int spapr_hpt_shift_for_ramsize(uint64_t ramsize)
 
 void spapr_free_hpt(SpaprMachineState *spapr)
 {
-    g_free(spapr->htab);
+    qemu_vfree(spapr->htab);
     spapr->htab = NULL;
     spapr->htab_shift = 0;
     close_htab_fd(spapr);
-- 
2.34.1



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

* [PATCH 43/51] tests/qtest: npcm7xx_emc-test: Skip running test_{tx, rx} on win32
  2022-08-24  9:39 [PATCH 00/51] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (41 preceding siblings ...)
  2022-08-24  9:40 ` [PATCH 42/51] hw/ppc: spapr: Use qemu_vfree() to free spapr->htab Bin Meng
@ 2022-08-24  9:40 ` Bin Meng
  2022-08-25 12:32   ` [PATCH 43/51] tests/qtest: npcm7xx_emc-test: Skip running test_{tx,rx} " Thomas Huth
  2022-08-25 16:40   ` [PATCH 43/51] tests/qtest: npcm7xx_emc-test: Skip running test_{tx, rx} " Hao Wu
  2022-08-24  9:40 ` [PATCH 44/51] tests/qtest: microbit-test: Fix socket access for win32 Bin Meng
                   ` (7 subsequent siblings)
  50 siblings, 2 replies; 174+ messages in thread
From: Bin Meng @ 2022-08-24  9:40 UTC (permalink / raw)
  To: qemu-devel
  Cc: Bin Meng, Havard Skinnemoen, Laurent Vivier, Paolo Bonzini,
	Thomas Huth, Tyrone Ting, qemu-arm

From: Bin Meng <bin.meng@windriver.com>

The test cases 'test_{tx,rx}' call socketpair() which does not exist
on win32. Exclude them.

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

 tests/qtest/npcm7xx_emc-test.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/tests/qtest/npcm7xx_emc-test.c b/tests/qtest/npcm7xx_emc-test.c
index a353fef0ca..c373d24e1e 100644
--- a/tests/qtest/npcm7xx_emc-test.c
+++ b/tests/qtest/npcm7xx_emc-test.c
@@ -209,6 +209,7 @@ static int emc_module_index(const EMCModule *mod)
     return diff;
 }
 
+#ifndef _WIN32
 static void packet_test_clear(void *sockets)
 {
     int *test_sockets = sockets;
@@ -243,6 +244,7 @@ static int *packet_test_init(int module_num, GString *cmd_line)
     g_test_queue_destroy(packet_test_clear, test_sockets);
     return test_sockets;
 }
+#endif /* _WIN32 */
 
 static uint32_t emc_read(QTestState *qts, const EMCModule *mod,
                          NPCM7xxPWMRegister regno)
@@ -250,6 +252,7 @@ static uint32_t emc_read(QTestState *qts, const EMCModule *mod,
     return qtest_readl(qts, mod->base_addr + regno * sizeof(uint32_t));
 }
 
+#ifndef _WIN32
 static void emc_write(QTestState *qts, const EMCModule *mod,
                       NPCM7xxPWMRegister regno, uint32_t value)
 {
@@ -339,6 +342,7 @@ static bool emc_soft_reset(QTestState *qts, const EMCModule *mod)
     g_message("%s: Timeout expired", __func__);
     return false;
 }
+#endif /* _WIN32 */
 
 /* Check emc registers are reset to default value. */
 static void test_init(gconstpointer test_data)
@@ -387,6 +391,7 @@ static void test_init(gconstpointer test_data)
     qtest_quit(qts);
 }
 
+#ifndef _WIN32
 static bool emc_wait_irq(QTestState *qts, const EMCModule *mod, int step,
                          bool is_tx)
 {
@@ -843,6 +848,7 @@ static void test_rx(gconstpointer test_data)
 
     qtest_quit(qts);
 }
+#endif /* _WIN32 */
 
 static void emc_add_test(const char *name, const TestData* td,
                          GTestDataFunc fn)
@@ -865,8 +871,10 @@ int main(int argc, char **argv)
         td->module = &emc_module_list[i];
 
         add_test(init, td);
+#ifndef _WIN32
         add_test(tx, td);
         add_test(rx, td);
+#endif
     }
 
     return g_test_run();
-- 
2.34.1



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

* [PATCH 44/51] tests/qtest: microbit-test: Fix socket access for win32
  2022-08-24  9:39 [PATCH 00/51] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (42 preceding siblings ...)
  2022-08-24  9:40 ` [PATCH 43/51] tests/qtest: npcm7xx_emc-test: Skip running test_{tx, rx} on win32 Bin Meng
@ 2022-08-24  9:40 ` Bin Meng
  2022-09-01 11:44   ` Marc-André Lureau
  2022-08-24  9:40 ` [PATCH 45/51] tests/qtest: prom-env-test: Use double quotes to pass the prom-env option Bin Meng
                   ` (6 subsequent siblings)
  50 siblings, 1 reply; 174+ messages in thread
From: Bin Meng @ 2022-08-24  9:40 UTC (permalink / raw)
  To: qemu-devel
  Cc: Bin Meng, Joel Stanley, Laurent Vivier, Paolo Bonzini,
	Peter Maydell, Thomas Huth, qemu-arm

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



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

* [PATCH 45/51] tests/qtest: prom-env-test: Use double quotes to pass the prom-env option
  2022-08-24  9:39 [PATCH 00/51] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (43 preceding siblings ...)
  2022-08-24  9:40 ` [PATCH 44/51] tests/qtest: microbit-test: Fix socket access for win32 Bin Meng
@ 2022-08-24  9:40 ` Bin Meng
  2022-08-25 12:33   ` Thomas Huth
  2022-08-24  9:40 ` [PATCH 46/51] tests/qtest: libqtest: Replace the call to close a socket with closesocket() Bin Meng
                   ` (5 subsequent siblings)
  50 siblings, 1 reply; 174+ messages in thread
From: Bin Meng @ 2022-08-24  9:40 UTC (permalink / raw)
  To: qemu-devel; +Cc: Bin Meng, Laurent Vivier, Paolo Bonzini, Thomas Huth

From: Bin Meng <bin.meng@windriver.com>

Single quotes like -prom-env 'nvramrc=cafec0de 4000 l!' in the arguments
are not removed in the Windows environment before it is passed to the
QEMU executable. Such argument causes a failure in the QEMU prom-env
option parser codes.

Change to use double quotes which works fine on all platforms.

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

 tests/qtest/prom-env-test.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tests/qtest/prom-env-test.c b/tests/qtest/prom-env-test.c
index c2b0448e55..39ccb59797 100644
--- a/tests/qtest/prom-env-test.c
+++ b/tests/qtest/prom-env-test.c
@@ -58,8 +58,8 @@ static void test_machine(const void *machine)
             " -machine " PSERIES_DEFAULT_CAPABILITIES;
     }
 
-    qts = qtest_initf("-M %s -accel tcg %s -prom-env 'use-nvramrc?=true' "
-                      "-prom-env 'nvramrc=%x %x l!' ", (const char *)machine,
+    qts = qtest_initf("-M %s -accel tcg %s -prom-env \"use-nvramrc?=true\" "
+                      "-prom-env \"nvramrc=%x %x l!\" ", (const char *)machine,
                       extra_args, MAGIC, ADDRESS);
     check_guest_memory(qts);
     qtest_quit(qts);
-- 
2.34.1



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

* [PATCH 46/51] tests/qtest: libqtest: Replace the call to close a socket with closesocket()
  2022-08-24  9:39 [PATCH 00/51] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (44 preceding siblings ...)
  2022-08-24  9:40 ` [PATCH 45/51] tests/qtest: prom-env-test: Use double quotes to pass the prom-env option Bin Meng
@ 2022-08-24  9:40 ` Bin Meng
  2022-09-01 11:46   ` Marc-André Lureau
  2022-08-24  9:40 ` [PATCH 47/51] tests/qtest: libqtest: Correct the timeout unit of blocking receive calls for win32 Bin Meng
                   ` (4 subsequent siblings)
  50 siblings, 1 reply; 174+ messages in thread
From: Bin Meng @ 2022-08-24  9:40 UTC (permalink / raw)
  To: qemu-devel; +Cc: Bin Meng, Laurent Vivier, Paolo Bonzini, Thomas Huth

From: Bin Meng <bin.meng@windriver.com>

close() is a *nix function. It works on any file descriptor, and
sockets in *nix are an example of a file descriptor.

closesocket() is a Windows-specific function, which works only
specifically with sockets. Sockets on Windows do not use *nix-style
file descriptors, and socket() returns a handle to a kernel object
instead, so it must be closed with closesocket().

In QEMU there is already a logic to handle such platform difference
in os-posix.h and os-win32.h, that:

  * closesocket maps to close on POSIX
  * closesocket maps to a wrapper that calls the real closesocket()
    on Windows

Replace the call to close a socket with closesocket() instead.

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

 tests/qtest/libqtest.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
index 99e52ff571..918f4657ed 100644
--- a/tests/qtest/libqtest.c
+++ b/tests/qtest/libqtest.c
@@ -115,7 +115,7 @@ static int socket_accept(int sock)
                    (void *)&timeout, sizeof(timeout))) {
         fprintf(stderr, "%s failed to set SO_RCVTIMEO: %s\n",
                 __func__, strerror(errno));
-        close(sock);
+        closesocket(sock);
         return -1;
     }
 
@@ -126,7 +126,7 @@ static int socket_accept(int sock)
     if (ret == -1) {
         fprintf(stderr, "%s failed: %s\n", __func__, strerror(errno));
     }
-    close(sock);
+    closesocket(sock);
 
     return ret;
 }
@@ -512,8 +512,8 @@ void qtest_quit(QTestState *s)
     qtest_remove_abrt_handler(s);
 
     qtest_kill_qemu(s);
-    close(s->fd);
-    close(s->qmp_fd);
+    closesocket(s->fd);
+    closesocket(s->qmp_fd);
     g_string_free(s->rx, true);
 
     for (GList *it = s->pending_events; it != NULL; it = it->next) {
-- 
2.34.1



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

* [PATCH 47/51] tests/qtest: libqtest: Correct the timeout unit of blocking receive calls for win32
  2022-08-24  9:39 [PATCH 00/51] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (45 preceding siblings ...)
  2022-08-24  9:40 ` [PATCH 46/51] tests/qtest: libqtest: Replace the call to close a socket with closesocket() Bin Meng
@ 2022-08-24  9:40 ` Bin Meng
  2022-09-01 11:57   ` Marc-André Lureau
  2022-08-24  9:40 ` [PATCH 48/51] io/channel-watch: Drop a superfluous '#ifdef WIN32' Bin Meng
                   ` (3 subsequent siblings)
  50 siblings, 1 reply; 174+ messages in thread
From: Bin Meng @ 2022-08-24  9:40 UTC (permalink / raw)
  To: qemu-devel; +Cc: Bin Meng, Laurent Vivier, Paolo Bonzini, Thomas Huth

From: Bin Meng <bin.meng@windriver.com>

Some qtest cases don't get response from the the QEMU executable
under test in time on Windows. It turns out that the socket receive
call got timeout before it receive the complete response.

The timeout value is supposed to be set to 50 seconds via the
setsockopt() call, but there is a difference among platforms.
The timeout unit of blocking receive calls is measured in
seconds on non-Windows platforms but milliseconds on Windows.

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

 tests/qtest/libqtest.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
index 918f4657ed..7b41971347 100644
--- a/tests/qtest/libqtest.c
+++ b/tests/qtest/libqtest.c
@@ -36,13 +36,14 @@
 #include "qapi/qmp/qstring.h"
 
 #define MAX_IRQ 256
-#define SOCKET_TIMEOUT 50
 
 #ifndef _WIN32
+# define SOCKET_TIMEOUT 50
 # define CMD_EXEC   "exec "
 # define DEV_STDERR "/dev/fd/2"
 # define DEV_NULL   "/dev/null"
 #else
+# define SOCKET_TIMEOUT 50000
 # define CMD_EXEC   ""
 # define DEV_STDERR "2"
 # define DEV_NULL   "nul"
@@ -108,8 +109,16 @@ static int socket_accept(int sock)
     struct sockaddr_un addr;
     socklen_t addrlen;
     int ret;
+    /*
+     * timeout unit of blocking receive calls is different among platfoms.
+     * It's in seconds on non-Windows platforms but milliseconds on Windows.
+     */
+#ifndef _WIN32
     struct timeval timeout = { .tv_sec = SOCKET_TIMEOUT,
                                .tv_usec = 0 };
+#else
+    DWORD timeout = SOCKET_TIMEOUT;
+#endif
 
     if (setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO,
                    (void *)&timeout, sizeof(timeout))) {
-- 
2.34.1



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

* [PATCH 48/51] io/channel-watch: Drop a superfluous '#ifdef WIN32'
  2022-08-24  9:39 [PATCH 00/51] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (46 preceding siblings ...)
  2022-08-24  9:40 ` [PATCH 47/51] tests/qtest: libqtest: Correct the timeout unit of blocking receive calls for win32 Bin Meng
@ 2022-08-24  9:40 ` Bin Meng
  2022-09-01 12:24   ` Marc-André Lureau
  2022-10-17 12:34   ` Daniel P. Berrangé
  2022-08-24  9:40 ` [PATCH 49/51] io/channel-watch: Fix socket watch on Windows Bin Meng
                   ` (2 subsequent siblings)
  50 siblings, 2 replies; 174+ messages in thread
From: Bin Meng @ 2022-08-24  9:40 UTC (permalink / raw)
  To: qemu-devel; +Cc: Bin Meng, Daniel P. Berrangé

From: Bin Meng <bin.meng@windriver.com>

In the win32 version qio_channel_create_socket_watch() body there is
no need to do a '#ifdef WIN32'.

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

 io/channel-watch.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/io/channel-watch.c b/io/channel-watch.c
index 0289b3647c..89f3c8a88a 100644
--- a/io/channel-watch.c
+++ b/io/channel-watch.c
@@ -285,11 +285,9 @@ GSource *qio_channel_create_socket_watch(QIOChannel *ioc,
     GSource *source;
     QIOChannelSocketSource *ssource;
 
-#ifdef WIN32
     WSAEventSelect(socket, ioc->event,
                    FD_READ | FD_ACCEPT | FD_CLOSE |
                    FD_CONNECT | FD_WRITE | FD_OOB);
-#endif
 
     source = g_source_new(&qio_channel_socket_source_funcs,
                           sizeof(QIOChannelSocketSource));
-- 
2.34.1



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

* [PATCH 49/51] io/channel-watch: Fix socket watch on Windows
  2022-08-24  9:39 [PATCH 00/51] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (47 preceding siblings ...)
  2022-08-24  9:40 ` [PATCH 48/51] io/channel-watch: Drop a superfluous '#ifdef WIN32' Bin Meng
@ 2022-08-24  9:40 ` Bin Meng
  2022-09-01 12:58   ` Marc-André Lureau
  2022-10-17 12:35   ` Daniel P. Berrangé
  2022-08-24  9:40 ` [PATCH 50/51] .gitlab-ci.d/windows.yml: Increase the timeout to the runner limit Bin Meng
  2022-08-24  9:40 ` [PATCH 51/51] docs/devel: testing: Document writing portable test cases Bin Meng
  50 siblings, 2 replies; 174+ messages in thread
From: Bin Meng @ 2022-08-24  9:40 UTC (permalink / raw)
  To: qemu-devel; +Cc: Bin Meng, Daniel P. Berrangé

From: Bin Meng <bin.meng@windriver.com>

Random failure was observed when running qtests on Windows due to
"Broken pipe" detected by qmp_fd_receive(). What happened is that
the qtest executable sends testing data over a socket to the QEMU
under test but no response is received. The errno of the recv()
call from the qtest executable indicates ETIMEOUT, due to the qmp
chardev's tcp_chr_read() is never called to receive testing data
hence no response is sent to the other side.

tcp_chr_read() is registered as the callback of the socket watch
GSource. The reason of the callback not being called by glib, is
that the source check fails to indicate the source is ready. There
are two socket watch sources created to monitor the same socket
event object from the char-socket backend in update_ioc_handlers().
During the source check phase, qio_channel_socket_source_check()
calls WSAEnumNetworkEvents() to discovers occurrences of network
events for the indicated socket, clear internal network event records,
and reset the event object. Testing shows that if we don't reset the
event object by not passing the event handle to WSAEnumNetworkEvents()
the symptom goes away and qtest runs very stably.

It looks we don't need to call WSAEnumNetworkEvents() at all, as we
don't parse the result of WSANETWORKEVENTS returned from this API.
We use select() to poll the socket status. Fix this instability by
dropping the WSAEnumNetworkEvents() call.

Signed-off-by: Bin Meng <bin.meng@windriver.com>
---
During the testing, I removed the following codes in update_ioc_handlers():

    remove_hup_source(s);
    s->hup_source = qio_channel_create_watch(s->ioc, G_IO_HUP);
    g_source_set_callback(s->hup_source, (GSourceFunc)tcp_chr_hup,
                          chr, NULL);
    g_source_attach(s->hup_source, chr->gcontext);

and such change also makes the symptom go away.

And if I moved the above codes to the beginning, before the call to
io_add_watch_poll(), the symptom also goes away.

It seems two sources watching on the same socket event object is
the key that leads to the instability. The order of adding a source
watch seems to also play a role but I can't explain why.
Hopefully a Windows and glib expert could explain this behavior.

 io/channel-watch.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/io/channel-watch.c b/io/channel-watch.c
index 89f3c8a88a..e34d86e810 100644
--- a/io/channel-watch.c
+++ b/io/channel-watch.c
@@ -115,17 +115,13 @@ static gboolean
 qio_channel_socket_source_check(GSource *source)
 {
     static struct timeval tv0;
-
     QIOChannelSocketSource *ssource = (QIOChannelSocketSource *)source;
-    WSANETWORKEVENTS ev;
     fd_set rfds, wfds, xfds;
 
     if (!ssource->condition) {
         return 0;
     }
 
-    WSAEnumNetworkEvents(ssource->socket, ssource->ioc->event, &ev);
-
     FD_ZERO(&rfds);
     FD_ZERO(&wfds);
     FD_ZERO(&xfds);
-- 
2.34.1



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

* [PATCH 50/51] .gitlab-ci.d/windows.yml: Increase the timeout to the runner limit
  2022-08-24  9:39 [PATCH 00/51] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (48 preceding siblings ...)
  2022-08-24  9:40 ` [PATCH 49/51] io/channel-watch: Fix socket watch on Windows Bin Meng
@ 2022-08-24  9:40 ` Bin Meng
  2022-08-25  8:18   ` Thomas Huth
  2022-08-24  9:40 ` [PATCH 51/51] docs/devel: testing: Document writing portable test cases Bin Meng
  50 siblings, 1 reply; 174+ messages in thread
From: Bin Meng @ 2022-08-24  9:40 UTC (permalink / raw)
  To: qemu-devel
  Cc: Bin Meng, Alex Bennée, Beraldo Leal,
	Philippe Mathieu-Daudé,
	Thomas Huth, Wainer dos Santos Moschetta

From: Bin Meng <bin.meng@windriver.com>

commit 9f8e6cad65a6 ("gitlab-ci: Speed up the msys2-64bit job by using --without-default-devices"
changed to compile QEMU with the --without-default-devices switch for
the msys2-64bit job, due to the build could not complete within the
project timeout (1h), and also mentioned that a bigger timeout was
getting ignored on the shared Gitlab-CI Windows runners.

However as of today it seems the shared Gitlab-CI Windows runners does
honor the job timeout, and the runner has the timeout limit of 2h, so
let's increase the timeout to the runner limit and drop the configure
switch "--without-default-devices" to get a larger build coverage.

As a result of this, the check-qtest starts running on Windows in CI.

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

 .gitlab-ci.d/windows.yml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/.gitlab-ci.d/windows.yml b/.gitlab-ci.d/windows.yml
index c4bde758be..d4fd821b5f 100644
--- a/.gitlab-ci.d/windows.yml
+++ b/.gitlab-ci.d/windows.yml
@@ -10,7 +10,7 @@
       - ${CI_PROJECT_DIR}/msys64/var/cache
   needs: []
   stage: build
-  timeout: 70m
+  timeout: 2h
   before_script:
   - If ( !(Test-Path -Path msys64\var\cache ) ) {
       mkdir msys64\var\cache
@@ -59,7 +59,7 @@ msys2-64bit:
   - $env:MSYSTEM = 'MINGW64'     # Start a 64 bit Mingw environment
   - $env:MSYS = 'winsymlinks:native' # Enable native Windows symlink
   - .\msys64\usr\bin\bash -lc './configure --target-list=x86_64-softmmu
-      --enable-capstone --without-default-devices'
+      --enable-capstone'
   - .\msys64\usr\bin\bash -lc "sed -i '/^ROMS=/d' build/config-host.mak"
   - .\msys64\usr\bin\bash -lc 'make -j2'
   - .\msys64\usr\bin\bash -lc 'make check'
-- 
2.34.1



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

* [PATCH 51/51] docs/devel: testing: Document writing portable test cases
  2022-08-24  9:39 [PATCH 00/51] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (49 preceding siblings ...)
  2022-08-24  9:40 ` [PATCH 50/51] .gitlab-ci.d/windows.yml: Increase the timeout to the runner limit Bin Meng
@ 2022-08-24  9:40 ` Bin Meng
  2022-09-01 13:02   ` Marc-André Lureau
  50 siblings, 1 reply; 174+ messages in thread
From: Bin Meng @ 2022-08-24  9:40 UTC (permalink / raw)
  To: qemu-devel
  Cc: Bin Meng, Emanuele Giuseppe Esposito, Hanna Reitz,
	Philippe Mathieu-Daudé,
	Vladimir Sementsov-Ogievskiy, Willian Rampazzo

From: Bin Meng <bin.meng@windriver.com>

Update the best practices of how to write portable test cases that
can be built and run successfully on both Linux and Windows hosts.

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

 docs/devel/testing.rst | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/docs/devel/testing.rst b/docs/devel/testing.rst
index 3f6ebd5073..8fcabda30f 100644
--- a/docs/devel/testing.rst
+++ b/docs/devel/testing.rst
@@ -115,6 +115,36 @@ check-block
 are in the "auto" group).
 See the "QEMU iotests" section below for more information.
 
+Writing portable test cases
+~~~~~~~~~~~~~~~~~~~~~~~~~~~
+Both unit tests and qtests can run on a Linux host as well as a Windows host.
+Care must be taken when writing portable test cases that can be built and run
+successfully on both hosts. The following are some best practices:
+
+* Use portable APIs from glib whenever necessary, e.g.: g_setenv(),
+  g_mkdtemp(), g_mkdir_with_parents().
+* Avoid using hardcoded /tmp for temporary file directory.
+  Use g_get_tmp_dir() instead.
+* Bear in mind that Windows has different special string representation for
+  stdin/stdout/stderr and null devices. For example if your test case uses
+  "/dev/fd/2" and "/dev/null" on Linux, remember to use "2" and "nul" on
+  Windows instead. Also IO redirection does not work on Windows, so avoid
+  using "2>nul" whenever necessary.
+* If your test cases uses the blkdebug feature, use relative path to pass
+  the config and image file paths in the command line as Windows absolute
+  path contains the delimeter ":" which will confuse the blkdebug parser.
+* Use double quotes in your extra QEMU commmand line in your test cases
+  instead of single quotes, as Windows does not drop single quotes when
+  passing the command line to QEMU.
+* Windows opens a file in text mode by default, while a POSIX compliant
+  implementation treats text files and binary files the same. So if your
+  test cases opens a file to write some data and later wants to compare the
+  written data with the original one, be sure to pass the letter 'b' as
+  part of the mode string to fopen(), or O_BINARY flag for the open() call.
+* If a certain test case can only run on POSIX or Linux hosts, use a proper
+  #ifdef in the codes. If the whole test suite cannot run on Windows, disable
+  the build in the meson.build file.
+
 QEMU iotests
 ------------
 
-- 
2.34.1



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

* Re: [PATCH 01/51] tests/qtest: Use g_setenv()
  2022-08-24  9:39 ` [PATCH 01/51] tests/qtest: Use g_setenv() Bin Meng
@ 2022-08-24 11:45   ` Thomas Huth
  2022-09-04 14:10   ` Philippe Mathieu-Daudé via
  1 sibling, 0 replies; 174+ messages in thread
From: Thomas Huth @ 2022-08-24 11:45 UTC (permalink / raw)
  To: Bin Meng, qemu-devel
  Cc: Bin Meng, Alexander Bulekov, Bandan Das, Darren Kenny,
	Laurent Vivier, Paolo Bonzini, Qiuhao Li, Stefan Hajnoczi

On 24/08/2022 11.39, Bin Meng wrote:
> From: Bin Meng <bin.meng@windriver.com>
> 
> Windows does not provide a setenv() API, but glib does.
> Replace setenv() call with the glib version.
> 
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
> 
>   tests/qtest/fuzz/generic_fuzz.c | 8 ++++----
>   tests/qtest/libqtest.c          | 2 +-
>   2 files changed, 5 insertions(+), 5 deletions(-)

Reviewed-by: Thomas Huth <thuth@redhat.com>



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

* Re: [PATCH 14/51] backends/tpm: Exclude headers and macros that don't exist on win32
  2022-08-24  9:39 ` [PATCH 14/51] backends/tpm: Exclude headers and macros that don't exist on win32 Bin Meng
@ 2022-08-24 12:35   ` Stefan Berger
  2022-08-31 13:20     ` Marc-André Lureau
  0 siblings, 1 reply; 174+ messages in thread
From: Stefan Berger @ 2022-08-24 12:35 UTC (permalink / raw)
  To: Bin Meng, qemu-devel; +Cc: Bin Meng, Stefan Berger



On 8/24/22 05:39, Bin Meng wrote:
> From: Bin Meng <bin.meng@windriver.com>
> 
> These headers and macros do not exist on Windows. Exclude them.
> 
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
> 
>   backends/tpm/tpm_ioctl.h | 4 ++++
>   1 file changed, 4 insertions(+)
> 
> diff --git a/backends/tpm/tpm_ioctl.h b/backends/tpm/tpm_ioctl.h
> index bd6c12cb86..d67bf0283b 100644
> --- a/backends/tpm/tpm_ioctl.h
> +++ b/backends/tpm/tpm_ioctl.h
> @@ -9,8 +9,10 @@
>   #ifndef TPM_IOCTL_H
>   #define TPM_IOCTL_H
> 
> +#ifndef _WIN32
>   #include <sys/uio.h>
>   #include <sys/ioctl.h>
> +#endif
> 
>   #ifdef HAVE_SYS_IOCCOM_H
>   #include <sys/ioccom.h>
> @@ -222,6 +224,7 @@ typedef struct ptm_setbuffersize ptm_setbuffersize;
>   #define PTM_CAP_SET_DATAFD         (1 << 12)
>   #define PTM_CAP_SET_BUFFERSIZE     (1 << 13)
> 
> +#ifndef _WIN32
>   enum {
>       PTM_GET_CAPABILITY     = _IOR('P', 0, ptm_cap),
>       PTM_INIT               = _IOWR('P', 1, ptm_init),
> @@ -241,6 +244,7 @@ enum {
>       PTM_SET_DATAFD         = _IOR('P', 15, ptm_res),
>       PTM_SET_BUFFERSIZE     = _IOWR('P', 16, ptm_setbuffersize),
>   };
> +#endif
> 
>   /*
>    * Commands used by the non-CUSE TPMs

Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>


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

* Re: [PATCH 34/51] tests/qtest: bios-tables-test: Adapt the case for win32
  2022-08-24  9:40 ` [PATCH 34/51] tests/qtest: bios-tables-test: Adapt the case for win32 Bin Meng
@ 2022-08-24 12:42   ` Ani Sinha
  2022-08-26 10:38     ` Bin Meng
  2022-09-01  9:05   ` Marc-André Lureau
  1 sibling, 1 reply; 174+ messages in thread
From: Ani Sinha @ 2022-08-24 12:42 UTC (permalink / raw)
  To: Bin Meng
  Cc: qemu-devel, Bin Meng, Ani Sinha, Igor Mammedov, Michael S. Tsirkin



On Wed, 24 Aug 2022, Bin Meng wrote:

> From: Bin Meng <bin.meng@windriver.com>
>
> Single quotes in the arguments (oem_id='CRASH ') are not removed in
> the Windows environment before it is passed to the QEMU executable.
> The space in the argument causes the "-acpitable" option parser to
> think that all of its parameters are done, hence it complains:
>
>   '-acpitable' requires one of 'data' or 'file'
>
> Change to use double quotes which works fine on all platforms.
>
> Also /dev/null does not work on win32, and nul should be used.
>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
>
>  tests/qtest/bios-tables-test.c | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/tests/qtest/bios-tables-test.c b/tests/qtest/bios-tables-test.c
> index 36783966b0..0148ce388c 100644
> --- a/tests/qtest/bios-tables-test.c
> +++ b/tests/qtest/bios-tables-test.c
> @@ -1615,6 +1615,12 @@ static void test_acpi_virt_viot(void)
>      free_test_data(&data);
>  }
>
> +#ifndef _WIN32
> +# define DEV_NULL "/dev/null"
> +#else
> +# define DEV_NULL "nul"
> +#endif
> +
>  static void test_acpi_q35_slic(void)
>  {
>      test_data data = {
> @@ -1622,9 +1628,9 @@ static void test_acpi_q35_slic(void)
>          .variant = ".slic",
>      };
>
> -    test_acpi_one("-acpitable sig=SLIC,oem_id='CRASH ',oem_table_id='ME',"
> -                  "oem_rev=00002210,asl_compiler_id='qemu',"
> -                  "asl_compiler_rev=00000000,data=/dev/null",
> +    test_acpi_one("-acpitable sig=SLIC,oem_id=\"CRASH \",oem_table_id=ME,"
> +                  "oem_rev=00002210,asl_compiler_id=qemu,"

ME and qemu should be surrounded by quotes. They are string arguments.
https://www.qemu.org/docs/master/interop/qemu-qmp-ref.html?highlight=oem_table_id




> +                  "asl_compiler_rev=00000000,data=" DEV_NULL,
>                    &data);
>      free_test_data(&data);
>  }
> --
> 2.34.1
>
>


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

* Re: [PATCH 11/51] qga/commands-posix-ssh: Use g_mkdir_with_parents()
  2022-08-24  9:39 ` [PATCH 11/51] qga/commands-posix-ssh: " Bin Meng
@ 2022-08-24 14:41   ` Konstantin Kostiuk
  2022-08-26 14:46     ` Bin Meng
  0 siblings, 1 reply; 174+ messages in thread
From: Konstantin Kostiuk @ 2022-08-24 14:41 UTC (permalink / raw)
  To: Bin Meng; +Cc: qemu-devel, Bin Meng, Michael Roth

[-- Attachment #1: Type: text/plain, Size: 966 bytes --]

Reviewed-by: Konstantin Kostiuk <kkostiuk@redhat.com>

On Wed, Aug 24, 2022 at 12:42 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Bin Meng <bin.meng@windriver.com>
>
> g_mkdir() is a deprecated API and newer codes should use
> g_mkdir_with_parents().
>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
>
>  qga/commands-posix-ssh.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/qga/commands-posix-ssh.c b/qga/commands-posix-ssh.c
> index f3a580b8cc..2460112a38 100644
> --- a/qga/commands-posix-ssh.c
> +++ b/qga/commands-posix-ssh.c
> @@ -59,7 +59,7 @@ static bool
>  mkdir_for_user(const char *path, const struct passwd *p,
>                 mode_t mode, Error **errp)
>  {
> -    if (g_mkdir(path, mode) == -1) {
> +    if (g_mkdir_with_parents(path, mode) == -1) {
>          error_setg(errp, "failed to create directory '%s': %s",
>                     path, g_strerror(errno));
>          return false;
> --
> 2.34.1
>
>

[-- Attachment #2: Type: text/html, Size: 1578 bytes --]

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

* Re: [PATCH 02/51] tests/qtest: Use g_mkdtemp()
  2022-08-24  9:39 ` [PATCH 02/51] tests/qtest: Use g_mkdtemp() Bin Meng
@ 2022-08-24 14:42   ` Thomas Huth
  0 siblings, 0 replies; 174+ messages in thread
From: Thomas Huth @ 2022-08-24 14:42 UTC (permalink / raw)
  To: Bin Meng, qemu-devel
  Cc: Bin Meng, Alexander Bulekov, Bandan Das, Darren Kenny,
	Dr. David Alan Gilbert, John Snow, Juan Quintela,
	Konstantin Kostiuk, Laurent Vivier, Markus Armbruster,
	Michael Roth, Paolo Bonzini, Qiuhao Li, Stefan Hajnoczi,
	qemu-block

On 24/08/2022 11.39, Bin Meng wrote:
> From: Bin Meng <bin.meng@windriver.com>
> 
> Windows does not provide a mkdtemp() API, but glib does.
> Replace mkdtemp() call with the glib version.
> 
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
> 
>   tests/qtest/fuzz/generic_fuzz_configs.h | 2 +-
>   tests/qtest/cdrom-test.c                | 2 +-
>   tests/qtest/cxl-test.c                  | 6 +++---
>   tests/qtest/ivshmem-test.c              | 4 ++--
>   tests/qtest/libqos/virtio-9p.c          | 4 ++--
>   tests/qtest/libqtest.c                  | 2 +-
>   tests/qtest/migration-test.c            | 4 ++--
>   tests/qtest/qmp-test.c                  | 4 ++--
>   tests/qtest/vhost-user-test.c           | 4 ++--
>   tests/unit/test-qga.c                   | 2 +-
>   10 files changed, 17 insertions(+), 17 deletions(-)

Reviewed-by: Thomas Huth <thuth@redhat.com>



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

* Re: [PATCH 42/51] hw/ppc: spapr: Use qemu_vfree() to free spapr->htab
  2022-08-24  9:40 ` [PATCH 42/51] hw/ppc: spapr: Use qemu_vfree() to free spapr->htab Bin Meng
@ 2022-08-24 17:32   ` Daniel Henrique Barboza
  2022-09-01 11:40   ` Marc-André Lureau
  1 sibling, 0 replies; 174+ messages in thread
From: Daniel Henrique Barboza @ 2022-08-24 17:32 UTC (permalink / raw)
  To: Bin Meng, qemu-devel
  Cc: Xuzhou Cheng, Bin Meng, Cédric Le Goater, David Gibson,
	Greg Kurz, qemu-ppc



On 8/24/22 06:40, Bin Meng wrote:
> From: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> 
> spapr->htab is allocated by qemu_memalign(), hence we should use
> qemu_vfree() to free it.
> 
> Fixes: c5f54f3e31bf ("pseries: Move hash page table allocation to reset time")
> Fixes: b4db54132ffe ("target/ppc: Implement H_REGISTER_PROCESS_TABLE H_CALL"")
> Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---

Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>

> 
>   hw/ppc/spapr.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
> index bc9ba6e6dc..4034f4d130 100644
> --- a/hw/ppc/spapr.c
> +++ b/hw/ppc/spapr.c
> @@ -1522,7 +1522,7 @@ int spapr_hpt_shift_for_ramsize(uint64_t ramsize)
>   
>   void spapr_free_hpt(SpaprMachineState *spapr)
>   {
> -    g_free(spapr->htab);
> +    qemu_vfree(spapr->htab);
>       spapr->htab = NULL;
>       spapr->htab_shift = 0;
>       close_htab_fd(spapr);


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

* Re: [PATCH 07/51] tests: Avoid using hardcoded /tmp in test cases
  2022-08-24  9:39 ` [PATCH 07/51] tests: Avoid using hardcoded /tmp in test cases Bin Meng
@ 2022-08-24 17:51   ` Dr. David Alan Gilbert
  2022-08-25  8:41   ` Thomas Huth
  1 sibling, 0 replies; 174+ messages in thread
From: Dr. David Alan Gilbert @ 2022-08-24 17:51 UTC (permalink / raw)
  To: Bin Meng
  Cc: qemu-devel, Bin Meng, Alexander Bulekov, Andrew Jeffery,
	Bandan Das, Coiby Xu, Cédric Le Goater, Darren Kenny,
	Fam Zheng, Joel Stanley, John Snow, Juan Quintela,
	Konstantin Kostiuk, Laurent Vivier, Markus Armbruster,
	Michael Roth, Paolo Bonzini, Peter Maydell, Qiuhao Li,
	Stefan Hajnoczi, Thomas Huth, qemu-arm, qemu-block

* Bin Meng (bmeng.cn@gmail.com) wrote:
> From: Bin Meng <bin.meng@windriver.com>
> 
> Use g_get_tmp_dir() to get the directory to use for temporary files.
> 
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
> 
>  tests/qtest/fuzz/generic_fuzz_configs.h |  6 ++++--
>  tests/qtest/ahci-test.c                 | 15 +++++++++++----
>  tests/qtest/aspeed_smc-test.c           |  4 +++-
>  tests/qtest/boot-serial-test.c          |  8 ++++++--
>  tests/qtest/cxl-test.c                  |  9 ++++++---
>  tests/qtest/fdc-test.c                  |  4 +++-
>  tests/qtest/fuzz/virtio_blk_fuzz.c      |  2 +-
>  tests/qtest/hd-geo-test.c               |  8 ++++----
>  tests/qtest/ide-test.c                  |  8 ++++++--
>  tests/qtest/libqtest.c                  | 10 +++++++---
>  tests/qtest/migration-test.c            |  4 +++-
>  tests/qtest/pflash-cfi02-test.c         |  7 +++++--
>  tests/qtest/qmp-test.c                  |  4 +++-
>  tests/qtest/vhost-user-blk-test.c       |  3 ++-
>  tests/qtest/vhost-user-test.c           |  3 ++-
>  tests/qtest/virtio-blk-test.c           |  2 +-
>  tests/qtest/virtio-scsi-test.c          |  3 ++-
>  tests/unit/test-image-locking.c         |  6 ++++--
>  tests/unit/test-qga.c                   |  2 +-
>  tests/vhost-user-bridge.c               |  3 ++-
>  20 files changed, 76 insertions(+), 35 deletions(-)
> 
> diff --git a/tests/qtest/fuzz/generic_fuzz_configs.h b/tests/qtest/fuzz/generic_fuzz_configs.h
> index 0775e6702b..d0f9961187 100644
> --- a/tests/qtest/fuzz/generic_fuzz_configs.h
> +++ b/tests/qtest/fuzz/generic_fuzz_configs.h
> @@ -20,13 +20,15 @@ typedef struct generic_fuzz_config {
>  } generic_fuzz_config;
>  
>  static inline gchar *generic_fuzzer_virtio_9p_args(void){
> -    char tmpdir[] = "/tmp/qemu-fuzz.XXXXXX";
> +    char *tmpdir = g_strdup_printf("%s/qemu-fuzz.XXXXXX", g_get_tmp_dir());

You might find it easier to use g_autofree in a lot of these, and then
you don't need to bother with the g_free at the end.

Dave

>      g_assert_nonnull(g_mkdtemp(tmpdir));
>  
> -    return g_strdup_printf("-machine q35 -nodefaults "
> +    gchar *args = g_strdup_printf("-machine q35 -nodefaults "
>      "-device virtio-9p,fsdev=hshare,mount_tag=hshare "
>      "-fsdev local,id=hshare,path=%s,security_model=mapped-xattr,"
>      "writeout=immediate,fmode=0600,dmode=0700", tmpdir);
> +    g_free(tmpdir);
> +    return args;
>  }
>  
>  const generic_fuzz_config predefined_configs[] = {
> diff --git a/tests/qtest/ahci-test.c b/tests/qtest/ahci-test.c
> index f1e510b0ac..f26cd6f86f 100644
> --- a/tests/qtest/ahci-test.c
> +++ b/tests/qtest/ahci-test.c
> @@ -44,9 +44,9 @@
>  #define TEST_IMAGE_SIZE_MB_SMALL 64
>  
>  /*** Globals ***/
> -static char tmp_path[] = "/tmp/qtest.XXXXXX";
> -static char debug_path[] = "/tmp/qtest-blkdebug.XXXXXX";
> -static char mig_socket[] = "/tmp/qtest-migration.XXXXXX";
> +static char *tmp_path;
> +static char *debug_path;
> +static char *mig_socket;
>  static bool ahci_pedantic;
>  static const char *imgfmt;
>  static unsigned test_image_size_mb;
> @@ -1437,7 +1437,7 @@ static void test_ncq_simple(void)
>  
>  static int prepare_iso(size_t size, unsigned char **buf, char **name)
>  {
> -    char cdrom_path[] = "/tmp/qtest.iso.XXXXXX";
> +    char *cdrom_path = g_strdup_printf("%s/qtest.iso.XXXXXX", g_get_tmp_dir());
>      unsigned char *patt;
>      ssize_t ret;
>      int fd = mkstemp(cdrom_path);
> @@ -1454,6 +1454,7 @@ static int prepare_iso(size_t size, unsigned char **buf, char **name)
>  
>      *name = g_strdup(cdrom_path);
>      *buf = patt;
> +    g_free(cdrom_path);
>      return fd;
>  }
>  
> @@ -1872,6 +1873,7 @@ int main(int argc, char **argv)
>      }
>  
>      /* Create a temporary image */
> +    tmp_path = g_strdup_printf("%s/qtest.XXXXXX", g_get_tmp_dir());
>      fd = mkstemp(tmp_path);
>      g_assert(fd >= 0);
>      if (have_qemu_img()) {
> @@ -1889,11 +1891,13 @@ int main(int argc, char **argv)
>      close(fd);
>  
>      /* Create temporary blkdebug instructions */
> +    debug_path = g_strdup_printf("%s/qtest-blkdebug.XXXXXX", g_get_tmp_dir());
>      fd = mkstemp(debug_path);
>      g_assert(fd >= 0);
>      close(fd);
>  
>      /* Reserve a hollow file to use as a socket for migration tests */
> +    mig_socket = g_strdup_printf("%s/qtest-migration.XXXXXX", g_get_tmp_dir());
>      fd = mkstemp(mig_socket);
>      g_assert(fd >= 0);
>      close(fd);
> @@ -1947,8 +1951,11 @@ int main(int argc, char **argv)
>  
>      /* Cleanup */
>      unlink(tmp_path);
> +    g_free(tmp_path);
>      unlink(debug_path);
> +    g_free(debug_path);
>      unlink(mig_socket);
> +    g_free(mig_socket);
>  
>      return ret;
>  }
> diff --git a/tests/qtest/aspeed_smc-test.c b/tests/qtest/aspeed_smc-test.c
> index 05ce941566..cab769459c 100644
> --- a/tests/qtest/aspeed_smc-test.c
> +++ b/tests/qtest/aspeed_smc-test.c
> @@ -608,7 +608,7 @@ static void test_write_block_protect_bottom_bit(void)
>      flash_reset();
>  }
>  
> -static char tmp_path[] = "/tmp/qtest.m25p80.XXXXXX";
> +static char *tmp_path;
>  
>  int main(int argc, char **argv)
>  {
> @@ -617,6 +617,7 @@ int main(int argc, char **argv)
>  
>      g_test_init(&argc, &argv, NULL);
>  
> +    tmp_path = g_strdup_printf("%s/qtest.m25p80.XXXXXX", g_get_tmp_dir());
>      fd = mkstemp(tmp_path);
>      g_assert(fd >= 0);
>      ret = ftruncate(fd, FLASH_SIZE);
> @@ -646,5 +647,6 @@ int main(int argc, char **argv)
>  
>      qtest_quit(global_qtest);
>      unlink(tmp_path);
> +    g_free(tmp_path);
>      return ret;
>  }
> diff --git a/tests/qtest/boot-serial-test.c b/tests/qtest/boot-serial-test.c
> index 2f99d71cab..404adcfa20 100644
> --- a/tests/qtest/boot-serial-test.c
> +++ b/tests/qtest/boot-serial-test.c
> @@ -224,8 +224,10 @@ static bool check_guest_output(QTestState *qts, const testdef_t *test, int fd)
>  static void test_machine(const void *data)
>  {
>      const testdef_t *test = data;
> -    char serialtmp[] = "/tmp/qtest-boot-serial-sXXXXXX";
> -    char codetmp[] = "/tmp/qtest-boot-serial-cXXXXXX";
> +    char *serialtmp = g_strdup_printf("%s/qtest-boot-serial-sXXXXXX",
> +                                      g_get_tmp_dir());
> +    char *codetmp = g_strdup_printf("%s/qtest-boot-serial-cXXXXXX",
> +                                    g_get_tmp_dir());
>      const char *codeparam = "";
>      const uint8_t *code = NULL;
>      QTestState *qts;
> @@ -264,6 +266,7 @@ static void test_machine(const void *data)
>                        serialtmp, test->extra);
>      if (code) {
>          unlink(codetmp);
> +        g_free(codetmp);
>      }
>  
>      if (!check_guest_output(qts, test, ser_fd)) {
> @@ -271,6 +274,7 @@ static void test_machine(const void *data)
>                  serialtmp);
>      }
>      unlink(serialtmp);
> +    g_free(serialtmp);
>  
>      qtest_quit(qts);
>  
> diff --git a/tests/qtest/cxl-test.c b/tests/qtest/cxl-test.c
> index 4e6d285061..b3733cdb5f 100644
> --- a/tests/qtest/cxl-test.c
> +++ b/tests/qtest/cxl-test.c
> @@ -92,12 +92,13 @@ static void cxl_2root_port(void)
>  static void cxl_t3d(void)
>  {
>      g_autoptr(GString) cmdline = g_string_new(NULL);
> -    char template[] = "/tmp/cxl-test-XXXXXX";
> +    char *template = g_strdup_printf("%s/cxl-test-XXXXXX", g_get_tmp_dir());
>      const char *tmpfs;
>  
>      tmpfs = g_mkdtemp(template);
>  
>      g_string_printf(cmdline, QEMU_PXB_CMD QEMU_RP QEMU_T3D, tmpfs, tmpfs);
> +    g_free(template);
>  
>      qtest_start(cmdline->str);
>      qtest_end();
> @@ -106,13 +107,14 @@ static void cxl_t3d(void)
>  static void cxl_1pxb_2rp_2t3d(void)
>  {
>      g_autoptr(GString) cmdline = g_string_new(NULL);
> -    char template[] = "/tmp/cxl-test-XXXXXX";
> +    char *template = g_strdup_printf("%s/cxl-test-XXXXXX", g_get_tmp_dir());
>      const char *tmpfs;
>  
>      tmpfs = g_mkdtemp(template);
>  
>      g_string_printf(cmdline, QEMU_PXB_CMD QEMU_2RP QEMU_2T3D,
>                      tmpfs, tmpfs, tmpfs, tmpfs);
> +    g_free(template);
>  
>      qtest_start(cmdline->str);
>      qtest_end();
> @@ -121,7 +123,7 @@ static void cxl_1pxb_2rp_2t3d(void)
>  static void cxl_2pxb_4rp_4t3d(void)
>  {
>      g_autoptr(GString) cmdline = g_string_new(NULL);
> -    char template[] = "/tmp/cxl-test-XXXXXX";
> +    char *template = g_strdup_printf("%s/cxl-test-XXXXXX", g_get_tmp_dir());
>      const char *tmpfs;
>  
>      tmpfs = g_mkdtemp(template);
> @@ -129,6 +131,7 @@ static void cxl_2pxb_4rp_4t3d(void)
>      g_string_printf(cmdline, QEMU_2PXB_CMD QEMU_4RP QEMU_4T3D,
>                      tmpfs, tmpfs, tmpfs, tmpfs, tmpfs, tmpfs,
>                      tmpfs, tmpfs);
> +    g_free(template);
>  
>      qtest_start(cmdline->str);
>      qtest_end();
> diff --git a/tests/qtest/fdc-test.c b/tests/qtest/fdc-test.c
> index 52ade90a7d..8651100b05 100644
> --- a/tests/qtest/fdc-test.c
> +++ b/tests/qtest/fdc-test.c
> @@ -68,7 +68,7 @@ enum {
>      DSKCHG  = 0x80,
>  };
>  
> -static char test_image[] = "/tmp/qtest.XXXXXX";
> +static char *test_image;
>  
>  #define assert_bit_set(data, mask) g_assert_cmphex((data) & (mask), ==, (mask))
>  #define assert_bit_clear(data, mask) g_assert_cmphex((data) & (mask), ==, 0)
> @@ -608,6 +608,7 @@ int main(int argc, char **argv)
>      int ret;
>  
>      /* Create a temporary raw image */
> +    test_image = g_strdup_printf("%s/qtest.XXXXXX", g_get_tmp_dir());
>      fd = mkstemp(test_image);
>      g_assert(fd >= 0);
>      ret = ftruncate(fd, TEST_IMAGE_SIZE);
> @@ -640,6 +641,7 @@ int main(int argc, char **argv)
>      /* Cleanup */
>      qtest_end();
>      unlink(test_image);
> +    g_free(test_image);
>  
>      return ret;
>  }
> diff --git a/tests/qtest/fuzz/virtio_blk_fuzz.c b/tests/qtest/fuzz/virtio_blk_fuzz.c
> index 236d078cc8..3e9541a38a 100644
> --- a/tests/qtest/fuzz/virtio_blk_fuzz.c
> +++ b/tests/qtest/fuzz/virtio_blk_fuzz.c
> @@ -181,7 +181,7 @@ static void drive_destroy(void *path)
>  static char *drive_create(void)
>  {
>      int fd, ret;
> -    char *t_path = g_strdup("/tmp/qtest.XXXXXX");
> +    char *t_path = g_strdup_printf("%s/qtest.XXXXXX", g_get_tmp_dir());
>  
>      /* Create a temporary raw image */
>      fd = mkstemp(t_path);
> diff --git a/tests/qtest/hd-geo-test.c b/tests/qtest/hd-geo-test.c
> index 413cf964c0..dc5d8422ea 100644
> --- a/tests/qtest/hd-geo-test.c
> +++ b/tests/qtest/hd-geo-test.c
> @@ -27,7 +27,7 @@
>  
>  static char *create_test_img(int secs)
>  {
> -    char *template = strdup("/tmp/qtest.XXXXXX");
> +    char *template = g_strdup_printf("%s/qtest.XXXXXX", g_get_tmp_dir());
>      int fd, ret;
>  
>      fd = mkstemp(template);
> @@ -36,7 +36,7 @@ static char *create_test_img(int secs)
>      close(fd);
>  
>      if (ret) {
> -        free(template);
> +        g_free(template);
>          template = NULL;
>      }
>  
> @@ -422,7 +422,7 @@ static MBRpartitions empty_mbr = { {false, 0, 0, 0, 0, 0, 0, 0, 0},
>  
>  static char *create_qcow2_with_mbr(MBRpartitions mbr, uint64_t sectors)
>  {
> -    const char *template = "/tmp/qtest.XXXXXX";
> +    const char *template = g_strdup_printf("%s/qtest.XXXXXX", g_get_tmp_dir());
>      char *raw_path = strdup(template);
>      char *qcow2_path = strdup(template);
>      char cmd[100 + 2 * PATH_MAX];
> @@ -987,7 +987,7 @@ test_add_done:
>      for (i = 0; i < backend_last; i++) {
>          if (img_file_name[i]) {
>              unlink(img_file_name[i]);
> -            free(img_file_name[i]);
> +            g_free(img_file_name[i]);
>          }
>      }
>  
> diff --git a/tests/qtest/ide-test.c b/tests/qtest/ide-test.c
> index 5bcb75a7e5..ebbf8e0126 100644
> --- a/tests/qtest/ide-test.c
> +++ b/tests/qtest/ide-test.c
> @@ -121,8 +121,8 @@ enum {
>  static QPCIBus *pcibus = NULL;
>  static QGuestAllocator guest_malloc;
>  
> -static char tmp_path[] = "/tmp/qtest.XXXXXX";
> -static char debug_path[] = "/tmp/qtest-blkdebug.XXXXXX";
> +static char *tmp_path;
> +static char *debug_path;
>  
>  static QTestState *ide_test_start(const char *cmdline_fmt, ...)
>  {
> @@ -1015,11 +1015,13 @@ int main(int argc, char **argv)
>      int ret;
>  
>      /* Create temporary blkdebug instructions */
> +    debug_path = g_strdup_printf("%s/qtest-blkdebug.XXXXXX", g_get_tmp_dir());
>      fd = mkstemp(debug_path);
>      g_assert(fd >= 0);
>      close(fd);
>  
>      /* Create a temporary raw image */
> +    tmp_path = g_strdup_printf("%s/qtest.XXXXXX", g_get_tmp_dir());
>      fd = mkstemp(tmp_path);
>      g_assert(fd >= 0);
>      ret = ftruncate(fd, TEST_IMAGE_SIZE);
> @@ -1049,7 +1051,9 @@ int main(int argc, char **argv)
>  
>      /* Cleanup */
>      unlink(tmp_path);
> +    g_free(tmp_path);
>      unlink(debug_path);
> +    g_free(debug_path);
>  
>      return ret;
>  }
> diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
> index 7c9fc07de4..34744ace7c 100644
> --- a/tests/qtest/libqtest.c
> +++ b/tests/qtest/libqtest.c
> @@ -265,8 +265,10 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args)
>  
>      s = g_new(QTestState, 1);
>  
> -    socket_path = g_strdup_printf("/tmp/qtest-%d.sock", getpid());
> -    qmp_socket_path = g_strdup_printf("/tmp/qtest-%d.qmp", getpid());
> +    socket_path = g_strdup_printf("%s/qtest-%d.sock",
> +                                  g_get_tmp_dir(), getpid());
> +    qmp_socket_path = g_strdup_printf("%s/qtest-%d.qmp",
> +                                      g_get_tmp_dir(), getpid());
>  
>      /* It's possible that if an earlier test run crashed it might
>       * have left a stale unix socket lying around. Delete any
> @@ -390,9 +392,10 @@ QTestState *qtest_initf(const char *fmt, ...)
>  QTestState *qtest_init_with_serial(const char *extra_args, int *sock_fd)
>  {
>      int sock_fd_init;
> -    char *sock_path, sock_dir[] = "/tmp/qtest-serial-XXXXXX";
> +    char *sock_path, *sock_dir;
>      QTestState *qts;
>  
> +    sock_dir = g_strdup_printf("%s/qtest-serial-XXXXXX", g_get_tmp_dir());
>      g_assert_true(g_mkdtemp(sock_dir) != NULL);
>      sock_path = g_strdup_printf("%s/sock", sock_dir);
>  
> @@ -406,6 +409,7 @@ QTestState *qtest_init_with_serial(const char *extra_args, int *sock_fd)
>      unlink(sock_path);
>      g_free(sock_path);
>      rmdir(sock_dir);
> +    g_free(sock_dir);
>  
>      g_assert_true(*sock_fd >= 0);
>  
> diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
> index 52988b86eb..5fa4ffeff0 100644
> --- a/tests/qtest/migration-test.c
> +++ b/tests/qtest/migration-test.c
> @@ -2422,7 +2422,8 @@ static bool kvm_dirty_ring_supported(void)
>  
>  int main(int argc, char **argv)
>  {
> -    char template[] = "/tmp/migration-test-XXXXXX";
> +    char *template = g_strdup_printf("%s/migration-test-XXXXXX",
> +                                     g_get_tmp_dir());
>      const bool has_kvm = qtest_has_accel("kvm");
>      const bool has_uffd = ufd_version_check();
>      const char *arch = qtest_get_arch();
> @@ -2576,6 +2577,7 @@ int main(int argc, char **argv)
>          g_test_message("unable to rmdir: path (%s): %s",
>                         tmpfs, strerror(errno));
>      }
> +    g_free(template);
>  
>      return ret;
>  }
> diff --git a/tests/qtest/pflash-cfi02-test.c b/tests/qtest/pflash-cfi02-test.c
> index 7fce614b64..6de83717dd 100644
> --- a/tests/qtest/pflash-cfi02-test.c
> +++ b/tests/qtest/pflash-cfi02-test.c
> @@ -56,7 +56,7 @@ typedef struct {
>      QTestState *qtest;
>  } FlashConfig;
>  
> -static char image_path[] = "/tmp/qtest.XXXXXX";
> +static char *image_path;
>  
>  /*
>   * The pflash implementation allows some parameters to be unspecified. We want
> @@ -608,6 +608,7 @@ static void test_cfi_in_autoselect(const void *opaque)
>  static void cleanup(void *opaque)
>  {
>      unlink(image_path);
> +    g_free(image_path);
>  }
>  
>  /*
> @@ -635,16 +636,18 @@ static const FlashConfig configuration[] = {
>  
>  int main(int argc, char **argv)
>  {
> +    image_path = g_strdup_printf("%s/qtest.XXXXXX", g_get_tmp_dir());
>      int fd = mkstemp(image_path);
>      if (fd == -1) {
>          g_printerr("Failed to create temporary file %s: %s\n", image_path,
>                     strerror(errno));
> +        g_free(image_path);
>          exit(EXIT_FAILURE);
>      }
>      if (ftruncate(fd, UNIFORM_FLASH_SIZE) < 0) {
>          int error_code = errno;
>          close(fd);
> -        unlink(image_path);
> +        cleanup(NULL);
>          g_printerr("Failed to truncate file %s to %u MB: %s\n", image_path,
>                     UNIFORM_FLASH_SIZE, strerror(error_code));
>          exit(EXIT_FAILURE);
> diff --git a/tests/qtest/qmp-test.c b/tests/qtest/qmp-test.c
> index bf7304c7dc..b950dbafaf 100644
> --- a/tests/qtest/qmp-test.c
> +++ b/tests/qtest/qmp-test.c
> @@ -161,11 +161,12 @@ static void test_qmp_protocol(void)
>  
>  /* Out-of-band tests */
>  
> -char tmpdir[] = "/tmp/qmp-test-XXXXXX";
> +char *tmpdir;
>  char *fifo_name;
>  
>  static void setup_blocking_cmd(void)
>  {
> +    tmpdir = g_strdup_printf("%s/qmp-test-XXXXXX", g_get_tmp_dir());
>      if (!g_mkdtemp(tmpdir)) {
>          g_error("g_mkdtemp: %s", strerror(errno));
>      }
> @@ -179,6 +180,7 @@ static void cleanup_blocking_cmd(void)
>  {
>      unlink(fifo_name);
>      rmdir(tmpdir);
> +    g_free(tmpdir);
>  }
>  
>  static void send_cmd_that_blocks(QTestState *s, const char *id)
> diff --git a/tests/qtest/vhost-user-blk-test.c b/tests/qtest/vhost-user-blk-test.c
> index a81c2a2715..07a4c2d500 100644
> --- a/tests/qtest/vhost-user-blk-test.c
> +++ b/tests/qtest/vhost-user-blk-test.c
> @@ -841,7 +841,8 @@ static char *create_listen_socket(int *fd)
>      char *path;
>  
>      /* No race because our pid makes the path unique */
> -    path = g_strdup_printf("/tmp/qtest-%d-sock.XXXXXX", getpid());
> +    path = g_strdup_printf("%s/qtest-%d-sock.XXXXXX",
> +                           g_get_tmp_dir(), getpid());
>      tmp_fd = mkstemp(path);
>      g_assert_cmpint(tmp_fd, >=, 0);
>      close(tmp_fd);
> diff --git a/tests/qtest/vhost-user-test.c b/tests/qtest/vhost-user-test.c
> index d7d6cfc9bd..a41168de25 100644
> --- a/tests/qtest/vhost-user-test.c
> +++ b/tests/qtest/vhost-user-test.c
> @@ -482,7 +482,7 @@ static TestServer *test_server_new(const gchar *name,
>          struct vhost_user_ops *ops)
>  {
>      TestServer *server = g_new0(TestServer, 1);
> -    char template[] = "/tmp/vhost-test-XXXXXX";
> +    char *template = g_strdup_printf("%s/vhost-test-XXXXXX", g_get_tmp_dir());
>      const char *tmpfs;
>  
>      server->context = g_main_context_new();
> @@ -501,6 +501,7 @@ static TestServer *test_server_new(const gchar *name,
>      server->socket_path = g_strdup_printf("%s/%s.sock", tmpfs, name);
>      server->mig_path = g_strdup_printf("%s/%s.mig", tmpfs, name);
>      server->chr_name = g_strdup_printf("chr-%s", name);
> +    g_free(template);
>  
>      g_mutex_init(&server->data_mutex);
>      g_cond_init(&server->data_cond);
> diff --git a/tests/qtest/virtio-blk-test.c b/tests/qtest/virtio-blk-test.c
> index dc5eed31c8..8920ce7c46 100644
> --- a/tests/qtest/virtio-blk-test.c
> +++ b/tests/qtest/virtio-blk-test.c
> @@ -49,7 +49,7 @@ static void drive_destroy(void *path)
>  static char *drive_create(void)
>  {
>      int fd, ret;
> -    char *t_path = g_strdup("/tmp/qtest.XXXXXX");
> +    char *t_path = g_strdup_printf("%s/qtest.XXXXXX", g_get_tmp_dir());
>  
>      /* Create a temporary raw image */
>      fd = mkstemp(t_path);
> diff --git a/tests/qtest/virtio-scsi-test.c b/tests/qtest/virtio-scsi-test.c
> index 8ceb12aacd..33ab6ec685 100644
> --- a/tests/qtest/virtio-scsi-test.c
> +++ b/tests/qtest/virtio-scsi-test.c
> @@ -268,7 +268,7 @@ static void test_iothread_attach_node(void *obj, void *data,
>      QVirtioSCSIPCI *scsi_pci = obj;
>      QVirtioSCSI *scsi = &scsi_pci->scsi;
>      QVirtioSCSIQueues *vs;
> -    char tmp_path[] = "/tmp/qtest.XXXXXX";
> +    char *tmp_path = g_strdup_printf("%s/qtest.XXXXXX", g_get_tmp_dir());
>      int fd;
>      int ret;
>  
> @@ -309,6 +309,7 @@ static void test_iothread_attach_node(void *obj, void *data,
>  fail:
>      qvirtio_scsi_pci_free(vs);
>      unlink(tmp_path);
> +    g_free(tmp_path);
>  }
>  
>  static void *virtio_scsi_hotplug_setup(GString *cmd_line, void *arg)
> diff --git a/tests/unit/test-image-locking.c b/tests/unit/test-image-locking.c
> index ba057bd66c..795c602ff6 100644
> --- a/tests/unit/test-image-locking.c
> +++ b/tests/unit/test-image-locking.c
> @@ -76,7 +76,7 @@ static void check_locked_bytes(int fd, uint64_t perm_locks,
>  static void test_image_locking_basic(void)
>  {
>      BlockBackend *blk1, *blk2, *blk3;
> -    char img_path[] = "/tmp/qtest.XXXXXX";
> +    char *img_path = g_strdup_printf("%s/qtest.XXXXXX", g_get_tmp_dir());
>      uint64_t perm, shared_perm;
>  
>      int fd = mkstemp(img_path);
> @@ -112,12 +112,13 @@ static void test_image_locking_basic(void)
>      blk_unref(blk3);
>      close(fd);
>      unlink(img_path);
> +    g_free(img_path);
>  }
>  
>  static void test_set_perm_abort(void)
>  {
>      BlockBackend *blk1, *blk2;
> -    char img_path[] = "/tmp/qtest.XXXXXX";
> +    char *img_path = g_strdup_printf("%s/qtest.XXXXXX", g_get_tmp_dir());
>      uint64_t perm, shared_perm;
>      int r;
>      int fd = mkstemp(img_path);
> @@ -140,6 +141,7 @@ static void test_set_perm_abort(void)
>      check_locked_bytes(fd, perm, ~shared_perm);
>      blk_unref(blk1);
>      blk_unref(blk2);
> +    g_free(img_path);
>  }
>  
>  int main(int argc, char **argv)
> diff --git a/tests/unit/test-qga.c b/tests/unit/test-qga.c
> index a05a4628ed..b73d231cd5 100644
> --- a/tests/unit/test-qga.c
> +++ b/tests/unit/test-qga.c
> @@ -59,7 +59,7 @@ fixture_setup(TestFixture *fixture, gconstpointer data, gchar **envp)
>  
>      fixture->loop = g_main_loop_new(NULL, FALSE);
>  
> -    fixture->test_dir = g_strdup("/tmp/qgatest.XXXXXX");
> +    fixture->test_dir = g_strdup_printf("%s/qgatest.XXXXXX", g_get_tmp_dir());
>      g_assert_nonnull(g_mkdtemp(fixture->test_dir));
>  
>      path = g_build_filename(fixture->test_dir, "sock", NULL);
> diff --git a/tests/vhost-user-bridge.c b/tests/vhost-user-bridge.c
> index 9b1dab2f28..0da6a6157f 100644
> --- a/tests/vhost-user-bridge.c
> +++ b/tests/vhost-user-bridge.c
> @@ -631,7 +631,7 @@ static void *notifier_thread(void *arg)
>  static void
>  vubr_host_notifier_setup(VubrDev *dev)
>  {
> -    char template[] = "/tmp/vubr-XXXXXX";
> +    char *template = g_strdup_printf("%s/vubr-XXXXXX", g_get_tmp_dir());
>      pthread_t thread;
>      size_t length;
>      void *addr;
> @@ -640,6 +640,7 @@ vubr_host_notifier_setup(VubrDev *dev)
>      length = qemu_real_host_page_size() * VHOST_USER_BRIDGE_MAX_QUEUES;
>  
>      fd = mkstemp(template);
> +    g_free(template);
>      if (fd < 0) {
>          vubr_die("mkstemp()");
>      }
> -- 
> 2.34.1
> 
-- 
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK



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

* Re: [PATCH 12/51] tests: Use g_mkdir_with_parents()
  2022-08-24  9:39 ` [PATCH 12/51] tests: " Bin Meng
@ 2022-08-24 17:58   ` Dr. David Alan Gilbert
  2022-08-26 14:49     ` Bin Meng
  0 siblings, 1 reply; 174+ messages in thread
From: Dr. David Alan Gilbert @ 2022-08-24 17:58 UTC (permalink / raw)
  To: Bin Meng
  Cc: qemu-devel, Bin Meng, Daniel P. Berrangé,
	Juan Quintela, Laurent Vivier, Paolo Bonzini, Thomas Huth

* Bin Meng (bmeng.cn@gmail.com) wrote:
> From: Bin Meng <bin.meng@windriver.com>
> 
> Use the same g_mkdir_with_parents() call to create a directory on
> all platforms.
> 
> Signed-off-by: Bin Meng <bin.meng@windriver.com>

Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>

> ---
> 
>  tests/migration/stress.c              | 2 +-
>  tests/qtest/migration-test.c          | 6 +++---
>  tests/unit/test-crypto-tlscredsx509.c | 4 ++--
>  tests/unit/test-crypto-tlssession.c   | 6 +++---
>  tests/unit/test-io-channel-tls.c      | 6 +++---
>  5 files changed, 12 insertions(+), 12 deletions(-)
> 
> diff --git a/tests/migration/stress.c b/tests/migration/stress.c
> index b7240a15c8..88acf8dc25 100644
> --- a/tests/migration/stress.c
> +++ b/tests/migration/stress.c
> @@ -232,7 +232,7 @@ static void stress(unsigned long long ramsizeGB, int ncpus)
>  
>  static int mount_misc(const char *fstype, const char *dir)
>  {
> -    if (mkdir(dir, 0755) < 0 && errno != EEXIST) {
> +    if (g_mkdir_with_parents(dir, 0755) < 0 && errno != EEXIST) {
>          fprintf(stderr, "%s (%05d): ERROR: cannot create %s: %s\n",
>                  argv0, gettid(), dir, strerror(errno));
>          return -1;
> diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
> index 5fa4ffeff0..38356d4aba 100644
> --- a/tests/qtest/migration-test.c
> +++ b/tests/qtest/migration-test.c
> @@ -761,14 +761,14 @@ test_migrate_tls_psk_start_common(QTestState *from,
>      data->workdir = g_strdup_printf("%s/tlscredspsk0", tmpfs);
>      data->pskfile = g_strdup_printf("%s/%s", data->workdir,
>                                      QCRYPTO_TLS_CREDS_PSKFILE);
> -    mkdir(data->workdir, 0700);
> +    g_mkdir_with_parents(data->workdir, 0700);
>      test_tls_psk_init(data->pskfile);
>  
>      if (mismatch) {
>          data->workdiralt = g_strdup_printf("%s/tlscredspskalt0", tmpfs);
>          data->pskfilealt = g_strdup_printf("%s/%s", data->workdiralt,
>                                             QCRYPTO_TLS_CREDS_PSKFILE);
> -        mkdir(data->workdiralt, 0700);
> +        g_mkdir_with_parents(data->workdiralt, 0700);
>          test_tls_psk_init_alt(data->pskfilealt);
>      }
>  
> @@ -873,7 +873,7 @@ test_migrate_tls_x509_start_common(QTestState *from,
>          data->clientcert = g_strdup_printf("%s/client-cert.pem", data->workdir);
>      }
>  
> -    mkdir(data->workdir, 0700);
> +    g_mkdir_with_parents(data->workdir, 0700);
>  
>      test_tls_init(data->keyfile);
>      g_assert(link(data->keyfile, data->serverkey) == 0);
> diff --git a/tests/unit/test-crypto-tlscredsx509.c b/tests/unit/test-crypto-tlscredsx509.c
> index aab4149b56..3c25d75ca1 100644
> --- a/tests/unit/test-crypto-tlscredsx509.c
> +++ b/tests/unit/test-crypto-tlscredsx509.c
> @@ -75,7 +75,7 @@ static void test_tls_creds(const void *opaque)
>      QCryptoTLSCreds *creds;
>  
>  #define CERT_DIR "tests/test-crypto-tlscredsx509-certs/"
> -    mkdir(CERT_DIR, 0700);
> +    g_mkdir_with_parents(CERT_DIR, 0700);
>  
>      unlink(CERT_DIR QCRYPTO_TLS_CREDS_X509_CA_CERT);
>      if (data->isServer) {
> @@ -141,7 +141,7 @@ int main(int argc, char **argv)
>      g_test_init(&argc, &argv, NULL);
>      g_setenv("GNUTLS_FORCE_FIPS_MODE", "2", 1);
>  
> -    mkdir(WORKDIR, 0700);
> +    g_mkdir_with_parents(WORKDIR, 0700);
>  
>      test_tls_init(KEYFILE);
>  
> diff --git a/tests/unit/test-crypto-tlssession.c b/tests/unit/test-crypto-tlssession.c
> index f222959d36..615a1344b4 100644
> --- a/tests/unit/test-crypto-tlssession.c
> +++ b/tests/unit/test-crypto-tlssession.c
> @@ -249,8 +249,8 @@ static void test_crypto_tls_session_x509(const void *opaque)
>  
>  #define CLIENT_CERT_DIR "tests/test-crypto-tlssession-client/"
>  #define SERVER_CERT_DIR "tests/test-crypto-tlssession-server/"
> -    mkdir(CLIENT_CERT_DIR, 0700);
> -    mkdir(SERVER_CERT_DIR, 0700);
> +    g_mkdir_with_parents(CLIENT_CERT_DIR, 0700);
> +    g_mkdir_with_parents(SERVER_CERT_DIR, 0700);
>  
>      unlink(SERVER_CERT_DIR QCRYPTO_TLS_CREDS_X509_CA_CERT);
>      unlink(SERVER_CERT_DIR QCRYPTO_TLS_CREDS_X509_SERVER_CERT);
> @@ -398,7 +398,7 @@ int main(int argc, char **argv)
>      g_test_init(&argc, &argv, NULL);
>      g_setenv("GNUTLS_FORCE_FIPS_MODE", "2", 1);
>  
> -    mkdir(WORKDIR, 0700);
> +    g_mkdir_with_parents(WORKDIR, 0700);
>  
>      test_tls_init(KEYFILE);
>      test_tls_psk_init(PSKFILE);
> diff --git a/tests/unit/test-io-channel-tls.c b/tests/unit/test-io-channel-tls.c
> index f6fb988c01..cc39247556 100644
> --- a/tests/unit/test-io-channel-tls.c
> +++ b/tests/unit/test-io-channel-tls.c
> @@ -125,8 +125,8 @@ static void test_io_channel_tls(const void *opaque)
>  
>  #define CLIENT_CERT_DIR "tests/test-io-channel-tls-client/"
>  #define SERVER_CERT_DIR "tests/test-io-channel-tls-server/"
> -    mkdir(CLIENT_CERT_DIR, 0700);
> -    mkdir(SERVER_CERT_DIR, 0700);
> +    g_mkdir_with_parents(CLIENT_CERT_DIR, 0700);
> +    g_mkdir_with_parents(SERVER_CERT_DIR, 0700);
>  
>      unlink(SERVER_CERT_DIR QCRYPTO_TLS_CREDS_X509_CA_CERT);
>      unlink(SERVER_CERT_DIR QCRYPTO_TLS_CREDS_X509_SERVER_CERT);
> @@ -273,7 +273,7 @@ int main(int argc, char **argv)
>      g_test_init(&argc, &argv, NULL);
>      g_setenv("GNUTLS_FORCE_FIPS_MODE", "2", 1);
>  
> -    mkdir(WORKDIR, 0700);
> +    g_mkdir_with_parents(WORKDIR, 0700);
>  
>      test_tls_init(KEYFILE);
>  
> -- 
> 2.34.1
> 
-- 
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK



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

* Re: [PATCH 13/51] tests/qtest: migration-test: Handle link() for win32
  2022-08-24  9:39 ` [PATCH 13/51] tests/qtest: migration-test: Handle link() for win32 Bin Meng
@ 2022-08-24 18:41   ` Dr. David Alan Gilbert
  0 siblings, 0 replies; 174+ messages in thread
From: Dr. David Alan Gilbert @ 2022-08-24 18:41 UTC (permalink / raw)
  To: Bin Meng
  Cc: qemu-devel, Bin Meng, Juan Quintela, Laurent Vivier,
	Paolo Bonzini, Thomas Huth

* Bin Meng (bmeng.cn@gmail.com) wrote:
> From: Bin Meng <bin.meng@windriver.com>
> 
> Windows does not provide a link() API like POSIX. Instead it provides
> a similar API CreateHardLink() that does the same thing, but with
> different argument order and return value.
> 
> Signed-off-by: Bin Meng <bin.meng@windriver.com>

Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>

> ---
> 
>  tests/qtest/migration-test.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
> index 38356d4aba..af9250750b 100644
> --- a/tests/qtest/migration-test.c
> +++ b/tests/qtest/migration-test.c
> @@ -876,9 +876,17 @@ test_migrate_tls_x509_start_common(QTestState *from,
>      g_mkdir_with_parents(data->workdir, 0700);
>  
>      test_tls_init(data->keyfile);
> +#ifndef _WIN32
>      g_assert(link(data->keyfile, data->serverkey) == 0);
> +#else
> +    g_assert(CreateHardLink(data->serverkey, data->keyfile, NULL) != 0);
> +#endif
>      if (args->clientcert) {
> +#ifndef _WIN32
>          g_assert(link(data->keyfile, data->clientkey) == 0);
> +#else
> +        g_assert(CreateHardLink(data->clientkey, data->keyfile, NULL) != 0);
> +#endif
>      }
>  
>      TLS_ROOT_REQ_SIMPLE(cacertreq, data->cacert);
> -- 
> 2.34.1
> 
-- 
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK



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

* Re: [PATCH 21/51] tests/qtest: migration-test: Skip running test_migrate_fd_proto on win32
  2022-08-24  9:39 ` [PATCH 21/51] tests/qtest: migration-test: Skip running test_migrate_fd_proto on win32 Bin Meng
@ 2022-08-24 18:49   ` Dr. David Alan Gilbert
  2022-09-04 14:15   ` Philippe Mathieu-Daudé via
  1 sibling, 0 replies; 174+ messages in thread
From: Dr. David Alan Gilbert @ 2022-08-24 18:49 UTC (permalink / raw)
  To: Bin Meng
  Cc: qemu-devel, Bin Meng, Juan Quintela, Laurent Vivier,
	Paolo Bonzini, Thomas Huth

* Bin Meng (bmeng.cn@gmail.com) wrote:
> From: Bin Meng <bin.meng@windriver.com>
> 
> The test case 'test_migrate_fd_proto' calls socketpair() which does
> not exist on win32. Exclude it. The helper function wait_command_fd()
> is not needed anymore, hence exclude it too.
> 
> Signed-off-by: Bin Meng <bin.meng@windriver.com>

Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>

> ---
> 
>  tests/qtest/migration-helpers.h | 2 ++
>  tests/qtest/migration-helpers.c | 2 ++
>  tests/qtest/migration-test.c    | 4 ++++
>  3 files changed, 8 insertions(+)
> 
> diff --git a/tests/qtest/migration-helpers.h b/tests/qtest/migration-helpers.h
> index 59561898d0..db0684de48 100644
> --- a/tests/qtest/migration-helpers.h
> +++ b/tests/qtest/migration-helpers.h
> @@ -17,8 +17,10 @@
>  
>  extern bool got_stop;
>  
> +#ifndef _WIN32
>  G_GNUC_PRINTF(3, 4)
>  QDict *wait_command_fd(QTestState *who, int fd, const char *command, ...);
> +#endif
>  
>  G_GNUC_PRINTF(2, 3)
>  QDict *wait_command(QTestState *who, const char *command, ...);
> diff --git a/tests/qtest/migration-helpers.c b/tests/qtest/migration-helpers.c
> index c6fbeb3974..f6f3c6680f 100644
> --- a/tests/qtest/migration-helpers.c
> +++ b/tests/qtest/migration-helpers.c
> @@ -34,6 +34,7 @@ static void check_stop_event(QTestState *who)
>      }
>  }
>  
> +#ifndef _WIN32
>  /*
>   * Events can get in the way of responses we are actually waiting for.
>   */
> @@ -58,6 +59,7 @@ QDict *wait_command_fd(QTestState *who, int fd, const char *command, ...)
>  
>      return ret;
>  }
> +#endif
>  
>  /*
>   * Events can get in the way of responses we are actually waiting for.
> diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
> index af9250750b..2ae7498d5d 100644
> --- a/tests/qtest/migration-test.c
> +++ b/tests/qtest/migration-test.c
> @@ -1629,6 +1629,7 @@ static void test_precopy_tcp_tls_x509_reject_anon_client(void)
>  #endif /* CONFIG_TASN1 */
>  #endif /* CONFIG_GNUTLS */
>  
> +#ifndef _WIN32
>  static void *test_migrate_fd_start_hook(QTestState *from,
>                                          QTestState *to)
>  {
> @@ -1697,6 +1698,7 @@ static void test_migrate_fd_proto(void)
>      };
>      test_precopy_common(&args);
>  }
> +#endif /* _WIN32 */
>  
>  static void do_test_validate_uuid(MigrateStart *args, bool should_fail)
>  {
> @@ -2531,7 +2533,9 @@ int main(int argc, char **argv)
>  #endif /* CONFIG_GNUTLS */
>  
>      /* qtest_add_func("/migration/ignore_shared", test_ignore_shared); */
> +#ifndef _WIN32
>      qtest_add_func("/migration/fd_proto", test_migrate_fd_proto);
> +#endif
>      qtest_add_func("/migration/validate_uuid", test_validate_uuid);
>      qtest_add_func("/migration/validate_uuid_error", test_validate_uuid_error);
>      qtest_add_func("/migration/validate_uuid_src_not_set",
> -- 
> 2.34.1
> 
-- 
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK



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

* Re: [PATCH 37/51] tests/qtest: migration-test: Disable IO redirection for win32
  2022-08-24  9:40 ` [PATCH 37/51] tests/qtest: migration-test: Disable IO redirection for win32 Bin Meng
@ 2022-08-24 18:53   ` Dr. David Alan Gilbert
  2022-08-26 10:48     ` Bin Meng
  0 siblings, 1 reply; 174+ messages in thread
From: Dr. David Alan Gilbert @ 2022-08-24 18:53 UTC (permalink / raw)
  To: Bin Meng
  Cc: qemu-devel, Bin Meng, Juan Quintela, Laurent Vivier,
	Paolo Bonzini, Thomas Huth

* Bin Meng (bmeng.cn@gmail.com) wrote:
> From: Bin Meng <bin.meng@windriver.com>
> 
> On Windows the QEMU executable is created via CreateProcess() and IO
> redirection does not work, so we need to set MigrateStart::hide_stderr
> to false to disable adding IO redirection to the command line.
> 
> Signed-off-by: Bin Meng <bin.meng@windriver.com>

Isn't it easier just to change the one place that tests this?

Dave

> ---
> 
>  tests/qtest/migration-test.c | 39 +++++++++++++++++++++++-------------
>  1 file changed, 25 insertions(+), 14 deletions(-)
> 
> diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
> index 2ae7498d5d..125d48d855 100644
> --- a/tests/qtest/migration-test.c
> +++ b/tests/qtest/migration-test.c
> @@ -53,6 +53,17 @@ static bool uffd_feature_thread_id;
>   */
>  #define DIRTYLIMIT_TOLERANCE_RANGE  25  /* MB/s */
>  
> +/*
> + * On Windows the QEMU executable is created via CreateProcess() and IO
> + * redirection does not work, so we need to set MigrateStart::hide_stderr
> + * to false to disable adding IO redirection to the command line.
> + */
> +#ifndef _WIN32
> +# define HIDE_STDERR true
> +#else
> +# define HIDE_STDERR false
> +#endif
> +
>  #if defined(__linux__)
>  #include <sys/syscall.h>
>  #include <sys/vfs.h>
> @@ -1186,7 +1197,7 @@ static void test_postcopy_recovery_common(MigrateCommon *args)
>      g_autofree char *uri = NULL;
>  
>      /* Always hide errors for postcopy recover tests since they're expected */
> -    args->start.hide_stderr = true;
> +    args->start.hide_stderr = HIDE_STDERR;
>  
>      if (migrate_postcopy_prepare(&from, &to, args)) {
>          return;
> @@ -1287,7 +1298,7 @@ static void test_postcopy_preempt_all(void)
>  static void test_baddest(void)
>  {
>      MigrateStart args = {
> -        .hide_stderr = true
> +        .hide_stderr = HIDE_STDERR
>      };
>      QTestState *from, *to;
>  
> @@ -1410,7 +1421,7 @@ static void test_precopy_unix_tls_x509_default_host(void)
>      g_autofree char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
>      MigrateCommon args = {
>          .start = {
> -            .hide_stderr = true,
> +            .hide_stderr = HIDE_STDERR,
>          },
>          .connect_uri = uri,
>          .listen_uri = uri,
> @@ -1526,7 +1537,7 @@ static void test_precopy_tcp_tls_psk_mismatch(void)
>  {
>      MigrateCommon args = {
>          .start = {
> -            .hide_stderr = true,
> +            .hide_stderr = HIDE_STDERR,
>          },
>          .listen_uri = "tcp:127.0.0.1:0",
>          .start_hook = test_migrate_tls_psk_start_mismatch,
> @@ -1564,7 +1575,7 @@ static void test_precopy_tcp_tls_x509_mismatch_host(void)
>  {
>      MigrateCommon args = {
>          .start = {
> -            .hide_stderr = true,
> +            .hide_stderr = HIDE_STDERR,
>          },
>          .listen_uri = "tcp:127.0.0.1:0",
>          .start_hook = test_migrate_tls_x509_start_mismatch_host,
> @@ -1590,7 +1601,7 @@ static void test_precopy_tcp_tls_x509_hostile_client(void)
>  {
>      MigrateCommon args = {
>          .start = {
> -            .hide_stderr = true,
> +            .hide_stderr = HIDE_STDERR,
>          },
>          .listen_uri = "tcp:127.0.0.1:0",
>          .start_hook = test_migrate_tls_x509_start_hostile_client,
> @@ -1616,7 +1627,7 @@ static void test_precopy_tcp_tls_x509_reject_anon_client(void)
>  {
>      MigrateCommon args = {
>          .start = {
> -            .hide_stderr = true,
> +            .hide_stderr = HIDE_STDERR,
>          },
>          .listen_uri = "tcp:127.0.0.1:0",
>          .start_hook = test_migrate_tls_x509_start_reject_anon_client,
> @@ -1747,7 +1758,7 @@ static void test_validate_uuid_error(void)
>      MigrateStart args = {
>          .opts_source = "-uuid 11111111-1111-1111-1111-111111111111",
>          .opts_target = "-uuid 22222222-2222-2222-2222-222222222222",
> -        .hide_stderr = true,
> +        .hide_stderr = HIDE_STDERR,
>      };
>  
>      do_test_validate_uuid(&args, true);
> @@ -1757,7 +1768,7 @@ static void test_validate_uuid_src_not_set(void)
>  {
>      MigrateStart args = {
>          .opts_target = "-uuid 22222222-2222-2222-2222-222222222222",
> -        .hide_stderr = true,
> +        .hide_stderr = HIDE_STDERR,
>      };
>  
>      do_test_validate_uuid(&args, false);
> @@ -1767,7 +1778,7 @@ static void test_validate_uuid_dst_not_set(void)
>  {
>      MigrateStart args = {
>          .opts_source = "-uuid 11111111-1111-1111-1111-111111111111",
> -        .hide_stderr = true,
> +        .hide_stderr = HIDE_STDERR,
>      };
>  
>      do_test_validate_uuid(&args, false);
> @@ -1990,7 +2001,7 @@ static void test_multifd_tcp_tls_psk_mismatch(void)
>  {
>      MigrateCommon args = {
>          .start = {
> -            .hide_stderr = true,
> +            .hide_stderr = HIDE_STDERR,
>          },
>          .listen_uri = "defer",
>          .start_hook = test_migrate_multifd_tcp_tls_psk_start_mismatch,
> @@ -2038,7 +2049,7 @@ static void test_multifd_tcp_tls_x509_mismatch_host(void)
>       */
>      MigrateCommon args = {
>          .start = {
> -            .hide_stderr = true,
> +            .hide_stderr = HIDE_STDERR,
>          },
>          .listen_uri = "defer",
>          .start_hook = test_migrate_multifd_tls_x509_start_mismatch_host,
> @@ -2062,7 +2073,7 @@ static void test_multifd_tcp_tls_x509_reject_anon_client(void)
>  {
>      MigrateCommon args = {
>          .start = {
> -            .hide_stderr = true,
> +            .hide_stderr = HIDE_STDERR,
>          },
>          .listen_uri = "defer",
>          .start_hook = test_migrate_multifd_tls_x509_start_reject_anon_client,
> @@ -2088,7 +2099,7 @@ static void test_multifd_tcp_tls_x509_reject_anon_client(void)
>  static void test_multifd_tcp_cancel(void)
>  {
>      MigrateStart args = {
> -        .hide_stderr = true,
> +        .hide_stderr = HIDE_STDERR,
>      };
>      QTestState *from, *to, *to2;
>      QDict *rsp;
> -- 
> 2.34.1
> 
-- 
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK



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

* Re: [PATCH 41/51] tests/qtest: migration-test: Kill "to" after migration is canceled
  2022-08-24  9:40 ` [PATCH 41/51] tests/qtest: migration-test: Kill "to" after migration is canceled Bin Meng
@ 2022-08-24 18:56   ` Dr. David Alan Gilbert
  2022-09-01 11:35     ` Marc-André Lureau
  0 siblings, 1 reply; 174+ messages in thread
From: Dr. David Alan Gilbert @ 2022-08-24 18:56 UTC (permalink / raw)
  To: Bin Meng
  Cc: qemu-devel, Xuzhou Cheng, Bin Meng, Juan Quintela,
	Laurent Vivier, Paolo Bonzini, Thomas Huth

* Bin Meng (bmeng.cn@gmail.com) wrote:
> From: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> 
> Make sure QEMU process "to" is killed before launching another target
> for migration in the test_multifd_tcp_cancel case.
> 
> Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
> 
>  tests/qtest/migration-test.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
> index 125d48d855..18ec079abf 100644
> --- a/tests/qtest/migration-test.c
> +++ b/tests/qtest/migration-test.c
> @@ -2132,6 +2132,10 @@ static void test_multifd_tcp_cancel(void)
>      wait_for_migration_pass(from);
>  
>      migrate_cancel(from);
> +    /* Make sure QEMU process "to" is killed */
> +    if (qtest_probe_child(to)) {
> +        qtest_kill_qemu(to);
> +    }

I'm not sure that's safe - what happens if the qemu exits between the
probe and kill?

Dave

>      args = (MigrateStart){
>          .only_target = true,
> -- 
> 2.34.1
> 
-- 
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK



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

* Re: [PATCH 40/51] chardev/char-file: Add FILE_SHARE_WRITE when openning the file for win32
  2022-08-24  9:40 ` [PATCH 40/51] chardev/char-file: Add FILE_SHARE_WRITE when openning the file " Bin Meng
@ 2022-08-25  7:58   ` Marc-André Lureau
  2022-08-26 13:15     ` Bin Meng
  0 siblings, 1 reply; 174+ messages in thread
From: Marc-André Lureau @ 2022-08-25  7:58 UTC (permalink / raw)
  To: Bin Meng; +Cc: qemu-devel, Xuzhou Cheng, Bin Meng, Paolo Bonzini

Hi

On Wed, Aug 24, 2022 at 1:43 PM Bin Meng <bmeng.cn@gmail.com> wrote:
>
> From: Xuzhou Cheng <xuzhou.cheng@windriver.com>
>
> The combination of GENERIC_WRITE and FILE_SHARE_READ options does
> not allow the same file to be opened again by CreateFile() from
> another QEMU process with the same options when the previous QEMU
> process still holds the file handle openned.

opened

>
> As per [1] we should add FILE_SHARE_WRITE to the share mode to allow
> such use case. This change makes the behavior be consisten with the
> POSIX platforms.
>

consistent

> [1] https://docs.microsoft.com/en-us/windows/win32/fileio/creating-and-opening-files
>
> Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---


What's the benefit to allow multiple processes write access to the
same file? It seems it could easily lead to corruption or unexpected
results.

To me, it's the other way around, the POSIX implementation should
learn to lock the file opened for write..

>
>  chardev/char-file.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/chardev/char-file.c b/chardev/char-file.c
> index 2fd80707e5..66385211eb 100644
> --- a/chardev/char-file.c
> +++ b/chardev/char-file.c
> @@ -60,8 +60,8 @@ static void qmp_chardev_open_file(Chardev *chr,
>          flags = CREATE_ALWAYS;
>      }
>
> -    out = CreateFile(file->out, accessmode, FILE_SHARE_READ, NULL, flags,
> -                     FILE_ATTRIBUTE_NORMAL, NULL);
> +    out = CreateFile(file->out, accessmode, FILE_SHARE_READ | FILE_SHARE_WRITE,
> +                     NULL, flags, FILE_ATTRIBUTE_NORMAL, NULL);
>      if (out == INVALID_HANDLE_VALUE) {
>          error_setg(errp, "open %s failed", file->out);
>          return;
> --
> 2.34.1
>



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

* Re: [PATCH 50/51] .gitlab-ci.d/windows.yml: Increase the timeout to the runner limit
  2022-08-24  9:40 ` [PATCH 50/51] .gitlab-ci.d/windows.yml: Increase the timeout to the runner limit Bin Meng
@ 2022-08-25  8:18   ` Thomas Huth
  2022-08-26 11:25     ` Bin Meng
  2022-08-26 11:33     ` Daniel P. Berrangé
  0 siblings, 2 replies; 174+ messages in thread
From: Thomas Huth @ 2022-08-25  8:18 UTC (permalink / raw)
  To: Bin Meng, qemu-devel
  Cc: Bin Meng, Alex Bennée, Beraldo Leal,
	Philippe Mathieu-Daudé,
	Wainer dos Santos Moschetta, Daniel P. Berrange

On 24/08/2022 11.40, Bin Meng wrote:
> From: Bin Meng <bin.meng@windriver.com>
> 
> commit 9f8e6cad65a6 ("gitlab-ci: Speed up the msys2-64bit job by using --without-default-devices"
> changed to compile QEMU with the --without-default-devices switch for
> the msys2-64bit job, due to the build could not complete within the
> project timeout (1h), and also mentioned that a bigger timeout was
> getting ignored on the shared Gitlab-CI Windows runners.
> 
> However as of today it seems the shared Gitlab-CI Windows runners does
> honor the job timeout, and the runner has the timeout limit of 2h, so
> let's increase the timeout to the runner limit and drop the configure
> switch "--without-default-devices" to get a larger build coverage.
> 
> As a result of this, the check-qtest starts running on Windows in CI.
> 
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
> 
>   .gitlab-ci.d/windows.yml | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/.gitlab-ci.d/windows.yml b/.gitlab-ci.d/windows.yml
> index c4bde758be..d4fd821b5f 100644
> --- a/.gitlab-ci.d/windows.yml
> +++ b/.gitlab-ci.d/windows.yml
> @@ -10,7 +10,7 @@
>         - ${CI_PROJECT_DIR}/msys64/var/cache
>     needs: []
>     stage: build
> -  timeout: 70m
> +  timeout: 2h

IMHO 2 hours are too long ... we're normally trying to limit the time of 
each job to 1h only and only extend it a little bit if we cannot really 
make, but we should not double the amount of time here. The highest timeout 
that we currently have are 90 minutes ... would that still be OK for this 
job, too? If so, please use 90 minutes here. Otherwise, it might still be 
necessary to cut down this job here and there a little bit...
(maybe the tests now also work a little bit faster now that the migration 
test has been speed up in 7.1-rc4 ?)

  Thomas



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

* Re: [PATCH 15/51] tests/qtest: Adapt {m48t59,rtc}-test cases for win32
  2022-08-24  9:39 ` [PATCH 15/51] tests/qtest: Adapt {m48t59,rtc}-test cases for win32 Bin Meng
@ 2022-08-25  8:20   ` Thomas Huth
  0 siblings, 0 replies; 174+ messages in thread
From: Thomas Huth @ 2022-08-25  8:20 UTC (permalink / raw)
  To: Bin Meng, qemu-devel; +Cc: Bin Meng, Laurent Vivier, Paolo Bonzini

On 24/08/2022 11.39, Bin Meng wrote:
> From: Bin Meng <bin.meng@windriver.com>
> 
> There is no tm_gmtoff member in 'struct tm' on Windows.
> Update rtc-test.c and m48t59-test.c accordingly.
> 
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
> 
>   tests/qtest/m48t59-test.c | 2 +-
>   tests/qtest/rtc-test.c    | 2 +-
>   2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/tests/qtest/m48t59-test.c b/tests/qtest/m48t59-test.c
> index b94a1230f7..843d2ced8e 100644
> --- a/tests/qtest/m48t59-test.c
> +++ b/tests/qtest/m48t59-test.c
> @@ -137,7 +137,7 @@ static void cmos_get_date_time(QTestState *s, struct tm *date)
>       date->tm_mday = mday;
>       date->tm_mon = mon - 1;
>       date->tm_year = base_year + year - 1900;
> -#ifndef __sun__
> +#if !defined(__sun__) && !defined(_WIN32)
>       date->tm_gmtoff = 0;
>   #endif
>   
> diff --git a/tests/qtest/rtc-test.c b/tests/qtest/rtc-test.c
> index 8126ab1bdb..02ed4e1238 100644
> --- a/tests/qtest/rtc-test.c
> +++ b/tests/qtest/rtc-test.c
> @@ -111,7 +111,7 @@ static void cmos_get_date_time(struct tm *date)
>       date->tm_mday = mday;
>       date->tm_mon = mon - 1;
>       date->tm_year = base_year + year - 1900;
> -#ifndef __sun__
> +#if !defined(__sun__) && !defined(_WIN32)
>       date->tm_gmtoff = 0;
>   #endif
>   

Reviewed-by: Thomas Huth <thuth@redhat.com>



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

* Re: [PATCH 07/51] tests: Avoid using hardcoded /tmp in test cases
  2022-08-24  9:39 ` [PATCH 07/51] tests: Avoid using hardcoded /tmp in test cases Bin Meng
  2022-08-24 17:51   ` Dr. David Alan Gilbert
@ 2022-08-25  8:41   ` Thomas Huth
  1 sibling, 0 replies; 174+ messages in thread
From: Thomas Huth @ 2022-08-25  8:41 UTC (permalink / raw)
  To: Bin Meng, qemu-devel
  Cc: Bin Meng, Alexander Bulekov, Andrew Jeffery, Bandan Das,
	Coiby Xu, Cédric Le Goater, Darren Kenny,
	Dr. David Alan Gilbert, Fam Zheng, Joel Stanley, John Snow,
	Juan Quintela, Konstantin Kostiuk, Laurent Vivier,
	Markus Armbruster, Michael Roth, Paolo Bonzini, Peter Maydell,
	Qiuhao Li, Stefan Hajnoczi, qemu-arm, qemu-block

On 24/08/2022 11.39, Bin Meng wrote:
> From: Bin Meng <bin.meng@windriver.com>
> 
> Use g_get_tmp_dir() to get the directory to use for temporary files.
> 
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
> 
>   tests/qtest/fuzz/generic_fuzz_configs.h |  6 ++++--
>   tests/qtest/ahci-test.c                 | 15 +++++++++++----
>   tests/qtest/aspeed_smc-test.c           |  4 +++-
>   tests/qtest/boot-serial-test.c          |  8 ++++++--
>   tests/qtest/cxl-test.c                  |  9 ++++++---
>   tests/qtest/fdc-test.c                  |  4 +++-
>   tests/qtest/fuzz/virtio_blk_fuzz.c      |  2 +-
>   tests/qtest/hd-geo-test.c               |  8 ++++----
>   tests/qtest/ide-test.c                  |  8 ++++++--
>   tests/qtest/libqtest.c                  | 10 +++++++---
>   tests/qtest/migration-test.c            |  4 +++-
>   tests/qtest/pflash-cfi02-test.c         |  7 +++++--
>   tests/qtest/qmp-test.c                  |  4 +++-
>   tests/qtest/vhost-user-blk-test.c       |  3 ++-
>   tests/qtest/vhost-user-test.c           |  3 ++-
>   tests/qtest/virtio-blk-test.c           |  2 +-
>   tests/qtest/virtio-scsi-test.c          |  3 ++-
>   tests/unit/test-image-locking.c         |  6 ++++--
>   tests/unit/test-qga.c                   |  2 +-
>   tests/vhost-user-bridge.c               |  3 ++-
>   20 files changed, 76 insertions(+), 35 deletions(-)
> 
> diff --git a/tests/qtest/fuzz/generic_fuzz_configs.h b/tests/qtest/fuzz/generic_fuzz_configs.h
> index 0775e6702b..d0f9961187 100644
> --- a/tests/qtest/fuzz/generic_fuzz_configs.h
> +++ b/tests/qtest/fuzz/generic_fuzz_configs.h
> @@ -20,13 +20,15 @@ typedef struct generic_fuzz_config {
>   } generic_fuzz_config;
>   
>   static inline gchar *generic_fuzzer_virtio_9p_args(void){
> -    char tmpdir[] = "/tmp/qemu-fuzz.XXXXXX";
> +    char *tmpdir = g_strdup_printf("%s/qemu-fuzz.XXXXXX", g_get_tmp_dir());
>       g_assert_nonnull(g_mkdtemp(tmpdir));

Could you switch this to g_dir_make_tmp(), please ? (see 
https://docs.gtk.org/glib/type_func.Dir.make_tmp.html )

(and as David said, please use g_autofree to avoid the g_free() later)

> -    return g_strdup_printf("-machine q35 -nodefaults "
> +    gchar *args = g_strdup_printf("-machine q35 -nodefaults "
>       "-device virtio-9p,fsdev=hshare,mount_tag=hshare "
>       "-fsdev local,id=hshare,path=%s,security_model=mapped-xattr,"
>       "writeout=immediate,fmode=0600,dmode=0700", tmpdir);
> +    g_free(tmpdir);
> +    return args;
>   }
>   
>   const generic_fuzz_config predefined_configs[] = {
> diff --git a/tests/qtest/ahci-test.c b/tests/qtest/ahci-test.c
> index f1e510b0ac..f26cd6f86f 100644
> --- a/tests/qtest/ahci-test.c
> +++ b/tests/qtest/ahci-test.c
> @@ -44,9 +44,9 @@
>   #define TEST_IMAGE_SIZE_MB_SMALL 64
>   
>   /*** Globals ***/
> -static char tmp_path[] = "/tmp/qtest.XXXXXX";
> -static char debug_path[] = "/tmp/qtest-blkdebug.XXXXXX";
> -static char mig_socket[] = "/tmp/qtest-migration.XXXXXX";
> +static char *tmp_path;
> +static char *debug_path;
> +static char *mig_socket;
>   static bool ahci_pedantic;
>   static const char *imgfmt;
>   static unsigned test_image_size_mb;
> @@ -1437,7 +1437,7 @@ static void test_ncq_simple(void)
>   
>   static int prepare_iso(size_t size, unsigned char **buf, char **name)
>   {
> -    char cdrom_path[] = "/tmp/qtest.iso.XXXXXX";
> +    char *cdrom_path = g_strdup_printf("%s/qtest.iso.XXXXXX", g_get_tmp_dir());
>       unsigned char *patt;
>       ssize_t ret;
>       int fd = mkstemp(cdrom_path);

Would it be better to use g_file_open_tmp() here?
(see https://docs.gtk.org/glib/func.file_open_tmp.html)

> @@ -1872,6 +1873,7 @@ int main(int argc, char **argv)
>       }
>   
>       /* Create a temporary image */
> +    tmp_path = g_strdup_printf("%s/qtest.XXXXXX", g_get_tmp_dir());
>       fd = mkstemp(tmp_path);
>       g_assert(fd >= 0);

g_file_open_tmp() ?

Also for the other temporary files in this test?

> diff --git a/tests/qtest/aspeed_smc-test.c b/tests/qtest/aspeed_smc-test.c
> index 05ce941566..cab769459c 100644
> --- a/tests/qtest/aspeed_smc-test.c
> +++ b/tests/qtest/aspeed_smc-test.c
> @@ -608,7 +608,7 @@ static void test_write_block_protect_bottom_bit(void)
>       flash_reset();
>   }
>   
> -static char tmp_path[] = "/tmp/qtest.m25p80.XXXXXX";
> +static char *tmp_path;
>   
>   int main(int argc, char **argv)
>   {
> @@ -617,6 +617,7 @@ int main(int argc, char **argv)
>   
>       g_test_init(&argc, &argv, NULL);
>   
> +    tmp_path = g_strdup_printf("%s/qtest.m25p80.XXXXXX", g_get_tmp_dir());
>       fd = mkstemp(tmp_path);

g_file_open_tmp() ?

> diff --git a/tests/qtest/boot-serial-test.c b/tests/qtest/boot-serial-test.c
> index 2f99d71cab..404adcfa20 100644
> --- a/tests/qtest/boot-serial-test.c
> +++ b/tests/qtest/boot-serial-test.c
> @@ -224,8 +224,10 @@ static bool check_guest_output(QTestState *qts, const testdef_t *test, int fd)
>   static void test_machine(const void *data)
>   {
>       const testdef_t *test = data;
> -    char serialtmp[] = "/tmp/qtest-boot-serial-sXXXXXX";
> -    char codetmp[] = "/tmp/qtest-boot-serial-cXXXXXX";
> +    char *serialtmp = g_strdup_printf("%s/qtest-boot-serial-sXXXXXX",
> +                                      g_get_tmp_dir());
> +    char *codetmp = g_strdup_printf("%s/qtest-boot-serial-cXXXXXX",
> +                                    g_get_tmp_dir());

These look like good candidates for g_file_open_tmp(), too.

Please check also the other spots in this patch, I haven't looked through 
all of them now...

  Thomas



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

* Re: [PATCH 16/51] tests/qtest: Build e1000e-test for posix only
  2022-08-24  9:39 ` [PATCH 16/51] tests/qtest: Build e1000e-test for posix only Bin Meng
@ 2022-08-25 10:59   ` Thomas Huth
  0 siblings, 0 replies; 174+ messages in thread
From: Thomas Huth @ 2022-08-25 10:59 UTC (permalink / raw)
  To: Bin Meng, qemu-devel; +Cc: Bin Meng, Laurent Vivier, Paolo Bonzini

On 24/08/2022 11.39, Bin Meng wrote:
> From: Bin Meng <bin.meng@windriver.com>
> 
> The whole e1000e-test test case relies on socketpair() which does
> not exist on win32.
> 
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
> 
>   tests/qtest/meson.build | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
> index be4b30dea2..9d0f82bf1c 100644
> --- a/tests/qtest/meson.build
> +++ b/tests/qtest/meson.build
> @@ -239,7 +239,6 @@ qos_test_ss.add(
>     'adm1272-test.c',
>     'ds1338-test.c',
>     'e1000-test.c',
> -  'e1000e-test.c',
>     'eepro100-test.c',
>     'es1370-test.c',
>     'ipoctal232-test.c',
> @@ -267,6 +266,9 @@ qos_test_ss.add(
>     'virtio-iommu-test.c',
>     'vmxnet3-test.c',
>   )
> +if config_host.has_key('CONFIG_POSIX')
> +  qos_test_ss.add(files('e1000e-test.c'))
> +endif
>   if have_virtfs
>     qos_test_ss.add(files('virtio-9p-test.c'))
>   endif

Reviewed-by: Thomas Huth <thuth@redhat.com>



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

* Re: [PATCH 17/51] tests/qtest: Build virtio-net-test for posix only
  2022-08-24  9:39 ` [PATCH 17/51] tests/qtest: Build virtio-net-test " Bin Meng
@ 2022-08-25 11:27   ` Thomas Huth
  2022-08-31 13:25   ` Marc-André Lureau
  1 sibling, 0 replies; 174+ messages in thread
From: Thomas Huth @ 2022-08-25 11:27 UTC (permalink / raw)
  To: Bin Meng, qemu-devel; +Cc: Bin Meng, Jason Wang, Laurent Vivier, Paolo Bonzini

On 24/08/2022 11.39, Bin Meng wrote:
> From: Bin Meng <bin.meng@windriver.com>
> 
> All of the virtio-net-test test cases require socketpair() to do the
> test setup.

I think that is not true. Look at the end of the file, after the comment 
"These tests do not need a loopback backend" ... these tests are using 
virtio_net_test_setup_nosocket which does not need socketpair().

You likely have to put the #ifdefs in different locations here instead.

  Thomas



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

* Re: [PATCH 19/51] tests/qtest: Build test-filter-{mirror, redirector} cases for posix only
  2022-08-24  9:39 ` [PATCH 19/51] tests/qtest: Build test-filter-{mirror, redirector} cases " Bin Meng
@ 2022-08-25 11:37   ` Thomas Huth
  2022-08-31 13:27   ` Marc-André Lureau
  1 sibling, 0 replies; 174+ messages in thread
From: Thomas Huth @ 2022-08-25 11:37 UTC (permalink / raw)
  To: Bin Meng, qemu-devel; +Cc: Bin Meng, Laurent Vivier, Paolo Bonzini

On 24/08/2022 11.39, Bin Meng wrote:
> From: Bin Meng <bin.meng@windriver.com>
> 
> The test-filter-{mirror,redirector} cases use socketpair() API that
> is only available on POSIX and should only be built for POSIX.
> 
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
> 
>   tests/qtest/meson.build | 28 ++++++++++++++++++----------
>   1 file changed, 18 insertions(+), 10 deletions(-)
> 
> diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
> index 9e484e60ba..c97da5a062 100644
> --- a/tests/qtest/meson.build
> +++ b/tests/qtest/meson.build
> @@ -42,6 +42,7 @@ qtests_cxl = \
>   qtests_i386 = \
>     (slirp.found() ? ['pxe-test', 'test-netfilter'] : []) +             \
>     (config_host.has_key('CONFIG_POSIX') ? ['test-filter-mirror'] : []) +                     \
> +  (config_host.has_key('CONFIG_POSIX') ? ['test-filter-redirector'] : []) +                 \
>     (have_tools ? ['ahci-test'] : []) +                                                       \
>     (config_all_devices.has_key('CONFIG_ISA_TESTDEV') ? ['endianness-test'] : []) +           \
>     (config_all_devices.has_key('CONFIG_SGA') ? ['boot-serial-test'] : []) +                  \
> @@ -95,8 +96,7 @@ qtests_i386 = \
>      'vmgenid-test',
>      'migration-test',
>      'test-x86-cpuid-compat',
> -   'numa-test',
> -   'test-filter-redirector'
> +   'numa-test'
>     ]
>   
>   if dbus_display
> @@ -120,29 +120,34 @@ endif
>   qtests_x86_64 = qtests_i386
>   
>   qtests_alpha = ['boot-serial-test'] + \
> -  ['test-filter-mirror', 'test-filter-redirector'] + \
> +  (config_host.has_key('CONFIG_POSIX') ? ['test-filter-mirror'] : []) +     \
> +  (config_host.has_key('CONFIG_POSIX') ? ['test-filter-redirector'] : []) + \
>     (slirp.found() ? ['test-netfilter'] : []) + \
>     (config_all_devices.has_key('CONFIG_VGA') ? ['display-vga-test'] : [])
>   
>   qtests_avr = [ 'boot-serial-test' ]
>   
>   qtests_hppa = ['boot-serial-test'] + \
> -  ['test-filter-mirror', 'test-filter-redirector'] + \
> +  (config_host.has_key('CONFIG_POSIX') ? ['test-filter-mirror'] : []) +     \
> +  (config_host.has_key('CONFIG_POSIX') ? ['test-filter-redirector'] : []) + \
>     (slirp.found() ? ['test-netfilter'] : []) + \
>     (config_all_devices.has_key('CONFIG_VGA') ? ['display-vga-test'] : [])
>   
>   qtests_m68k = ['boot-serial-test'] + \
> -  ['test-filter-mirror', 'test-filter-redirector'] + \
> +  (config_host.has_key('CONFIG_POSIX') ? ['test-filter-mirror'] : []) +     \
> +  (config_host.has_key('CONFIG_POSIX') ? ['test-filter-redirector'] : []) + \
>     (slirp.found() ? ['test-netfilter'] : [])
>   
>   qtests_microblaze = ['boot-serial-test'] + \
> -  ['test-filter-mirror', 'test-filter-redirector'] + \
> +  (config_host.has_key('CONFIG_POSIX') ? ['test-filter-mirror'] : []) +     \
> +  (config_host.has_key('CONFIG_POSIX') ? ['test-filter-redirector'] : []) + \
>     (slirp.found() ? ['test-netfilter'] : [])
>   
>   qtests_microblazeel = qtests_microblaze
>   
>   qtests_mips = \
> -  ['test-filter-mirror', 'test-filter-redirector'] + \
> +  (config_host.has_key('CONFIG_POSIX') ? ['test-filter-mirror'] : []) +     \
> +  (config_host.has_key('CONFIG_POSIX') ? ['test-filter-redirector'] : []) + \
>     (slirp.found() ? ['test-netfilter'] : []) + \
>     (config_all_devices.has_key('CONFIG_ISA_TESTDEV') ? ['endianness-test'] : []) +            \
>     (config_all_devices.has_key('CONFIG_VGA') ? ['display-vga-test'] : [])
> @@ -152,7 +157,8 @@ qtests_mips64 = qtests_mips
>   qtests_mips64el = qtests_mips
>   
>   qtests_ppc = \
> -  ['test-filter-mirror', 'test-filter-redirector'] + \
> +  (config_host.has_key('CONFIG_POSIX') ? ['test-filter-mirror'] : []) +     \
> +  (config_host.has_key('CONFIG_POSIX') ? ['test-filter-redirector'] : []) + \
>     (slirp.found() ? ['test-netfilter'] : []) + \
>     (config_all_devices.has_key('CONFIG_ISA_TESTDEV') ? ['endianness-test'] : []) +            \
>     (config_all_devices.has_key('CONFIG_M48T59') ? ['m48t59-test'] : []) +                     \
> @@ -174,13 +180,15 @@ qtests_sh4 = (config_all_devices.has_key('CONFIG_ISA_TESTDEV') ? ['endianness-te
>   qtests_sh4eb = (config_all_devices.has_key('CONFIG_ISA_TESTDEV') ? ['endianness-test'] : [])
>   
>   qtests_sparc = ['prom-env-test', 'm48t59-test', 'boot-serial-test'] + \
> -  ['test-filter-mirror', 'test-filter-redirector'] + \
> +  (config_host.has_key('CONFIG_POSIX') ? ['test-filter-mirror'] : []) +     \
> +  (config_host.has_key('CONFIG_POSIX') ? ['test-filter-redirector'] : []) + \
>     (slirp.found() ? ['test-netfilter'] : [])
>   
>   qtests_sparc64 = \
>     (config_all_devices.has_key('CONFIG_ISA_TESTDEV') ? ['endianness-test'] : []) +            \
>     (slirp.found() ? ['test-netfilter'] : []) + \
> -  ['test-filter-mirror', 'test-filter-redirector'] + \
> +  (config_host.has_key('CONFIG_POSIX') ? ['test-filter-mirror'] : []) +     \
> +  (config_host.has_key('CONFIG_POSIX') ? ['test-filter-redirector'] : []) + \
>     ['prom-env-test', 'boot-serial-test']
>   
>   qtests_npcm7xx = \

It might be easier to introduce a new variable à la:

filter_qtests = \
   (slirp.found() ? ['test-netfilter'] : []) + \
   (config_host.has_key('CONFIG_POSIX') ? ['test-filter-mirror'] : []) + \
   (config_host.has_key('CONFIG_POSIX') ? ['test-filter-redirector'] : [])

And then add that to the qtest_ARCH variables instead?

  Thomas



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

* Re: [PATCH 20/51] tests/qtest: i440fx-test: Skip running request_{bios,pflash} for win32
  2022-08-24  9:39 ` [PATCH 20/51] tests/qtest: i440fx-test: Skip running request_{bios, pflash} for win32 Bin Meng
@ 2022-08-25 11:40   ` Thomas Huth
  2022-08-31 13:40   ` [PATCH 20/51] tests/qtest: i440fx-test: Skip running request_{bios, pflash} " Marc-André Lureau
  1 sibling, 0 replies; 174+ messages in thread
From: Thomas Huth @ 2022-08-25 11:40 UTC (permalink / raw)
  To: Bin Meng, qemu-devel; +Cc: Bin Meng, Laurent Vivier, Paolo Bonzini

On 24/08/2022 11.39, Bin Meng wrote:
> From: Bin Meng <bin.meng@windriver.com>
> 
> The request_{bios,pflash} test cases call mmap() which does not
> exist on win32. Exclude them.
> 
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
> 
>   tests/qtest/i440fx-test.c | 6 ++++++
>   1 file changed, 6 insertions(+)
> 
> diff --git a/tests/qtest/i440fx-test.c b/tests/qtest/i440fx-test.c
> index 6d7d4d8d8f..3890f1237c 100644
> --- a/tests/qtest/i440fx-test.c
> +++ b/tests/qtest/i440fx-test.c
> @@ -278,6 +278,8 @@ static void test_i440fx_pam(gconstpointer opaque)
>       qtest_end();
>   }
>   
> +#ifndef _WIN32
> +
>   #define BLOB_SIZE ((size_t)65536)
>   #define ISA_BIOS_MAXSZ ((size_t)(128 * 1024))
>   
> @@ -396,6 +398,8 @@ static void request_pflash(FirmwareTestFixture *fixture,
>       fixture->is_bios = false;
>   }
>   
> +#endif /* _WIN32 */
> +
>   int main(int argc, char **argv)
>   {
>       TestData data;
> @@ -406,8 +410,10 @@ int main(int argc, char **argv)
>   
>       qtest_add_data_func("i440fx/defaults", &data, test_i440fx_defaults);
>       qtest_add_data_func("i440fx/pam", &data, test_i440fx_pam);
> +#ifndef _WIN32
>       add_firmware_test("i440fx/firmware/bios", request_bios);
>       add_firmware_test("i440fx/firmware/pflash", request_pflash);
> +#endif
>   
>       return g_test_run();
>   }

Reviewed-by: Thomas Huth <thuth@redhat.com>



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

* Re: [PATCH 22/51] tests/qtest: qmp-test: Skip running test_qmp_oob for win32
  2022-08-24  9:40 ` [PATCH 22/51] tests/qtest: qmp-test: Skip running test_qmp_oob for win32 Bin Meng
@ 2022-08-25 11:45   ` Thomas Huth
  2022-08-29 13:14   ` Markus Armbruster
  1 sibling, 0 replies; 174+ messages in thread
From: Thomas Huth @ 2022-08-25 11:45 UTC (permalink / raw)
  To: Bin Meng, qemu-devel
  Cc: Bin Meng, Laurent Vivier, Markus Armbruster, Paolo Bonzini

On 24/08/2022 11.40, Bin Meng wrote:
> From: Bin Meng <bin.meng@windriver.com>
> 
> The test_qmp_oob test case calls mkfifo() which does not exist on
> win32. Exclude it.
> 
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
> 
>   tests/qtest/qmp-test.c | 6 ++++++
>   1 file changed, 6 insertions(+)

Reviewed-by: Thomas Huth <thuth@redhat.com>



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

* Re: [PATCH 25/51] tests/qtest: libqos: Rename malloc.h to libqos-malloc.h
  2022-08-24  9:40 ` [PATCH 25/51] tests/qtest: libqos: Rename malloc.h to libqos-malloc.h Bin Meng
@ 2022-08-25 11:51   ` Thomas Huth
  2022-08-31 13:51   ` Marc-André Lureau
  1 sibling, 0 replies; 174+ messages in thread
From: Thomas Huth @ 2022-08-25 11:51 UTC (permalink / raw)
  To: Bin Meng, qemu-devel
  Cc: Xuzhou Cheng, Bin Meng, Alexander Bulekov, Bandan Das,
	Cédric Le Goater, Daniel Henrique Barboza, Darren Kenny,
	David Gibson, Greg Kurz, Laurent Vivier, Paolo Bonzini,
	Qiuhao Li, Stefan Hajnoczi, qemu-ppc

On 24/08/2022 11.40, Bin Meng wrote:
> From: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> 
> The qtest/libqos directory is included via the "-I" option to search
> for header files when building qtest. Unfortunately the malloc.h has
> a name conflict with the standard libc header, leading to a build
> failure on the Windows host, due to the MinGW libc stdlib.h header
> file includes malloc.h and it now gets wrongly pointed to the one
> in the qtest/libqos directory.
> 
> Rename "qtest/libqos/malloc.h" to "qtest/libqos/libqos-malloc.h" to
> avoid the namespace pollution.
> 
> Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---

Reviewed-by: Thomas Huth <thuth@redhat.com>



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

* Re: [PATCH 24/51] tests/qtest: libqos: Drop inclusion of <sys/wait.h>
  2022-08-24  9:40 ` [PATCH 24/51] tests/qtest: libqos: Drop inclusion of <sys/wait.h> Bin Meng
@ 2022-08-25 11:55   ` Thomas Huth
  2022-08-31 13:50   ` Marc-André Lureau
  1 sibling, 0 replies; 174+ messages in thread
From: Thomas Huth @ 2022-08-25 11:55 UTC (permalink / raw)
  To: Bin Meng, qemu-devel
  Cc: Xuzhou Cheng, Bin Meng, Laurent Vivier, Paolo Bonzini, John Snow

On 24/08/2022 11.40, Bin Meng wrote:
> From: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> 
> There is no <sys/wait.h> in the Windows build environment. Actually
> this is not needed in the non-win32 builds too. Drop it.
> 
> Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
> 
>   tests/qtest/libqos/libqos.c | 2 --
>   1 file changed, 2 deletions(-)
> 
> diff --git a/tests/qtest/libqos/libqos.c b/tests/qtest/libqos/libqos.c
> index 85c7641add..5ffda080ec 100644
> --- a/tests/qtest/libqos/libqos.c
> +++ b/tests/qtest/libqos/libqos.c
> @@ -1,6 +1,4 @@
>   #include "qemu/osdep.h"
> -#include <sys/wait.h>

Works for me:

Tested-by: Thomas Huth <thuth@redhat.com>



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

* Re: [PATCH 26/51] tests/qtest: libqtest: Move global_qtest definition back to libqtest.c
  2022-08-24  9:40 ` [PATCH 26/51] tests/qtest: libqtest: Move global_qtest definition back to libqtest.c Bin Meng
@ 2022-08-25 11:59   ` Thomas Huth
  0 siblings, 0 replies; 174+ messages in thread
From: Thomas Huth @ 2022-08-25 11:59 UTC (permalink / raw)
  To: Bin Meng, qemu-devel
  Cc: Xuzhou Cheng, Bin Meng, Laurent Vivier, Paolo Bonzini

On 24/08/2022 11.40, Bin Meng wrote:
> From: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> 
> Commit dd2107497275 ("tests/libqtest: Use libqtest-single.h in tests that require global_qtest")
> moved global_qtest to libqtest-single.h, by declaring global_qtest
> attribute to be common and weak.
> 
> This trick unfortunately does not work on Windows, and building
> qtest test cases results in multiple definition errors of the weak
> symbol global_qtest, as Windows PE does not have the concept of
> the so-called weak symbol like ELF in the *nix world.
> 
> Let's move the definition of global_qtest back to libqtest.c.
> 
> Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
> 
>   tests/qtest/libqtest-single.h | 2 +-
>   tests/qtest/libqtest.c        | 2 ++
>   2 files changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/tests/qtest/libqtest-single.h b/tests/qtest/libqtest-single.h
> index 4e7d0ae1dc..3294985d7b 100644
> --- a/tests/qtest/libqtest-single.h
> +++ b/tests/qtest/libqtest-single.h
> @@ -13,7 +13,7 @@
>   
>   #include "libqtest.h"
>   
> -QTestState *global_qtest __attribute__((common, weak));
> +extern QTestState *global_qtest;
>   
>   /**
>    * qtest_start:
> diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
> index 34744ace7c..909583dad3 100644
> --- a/tests/qtest/libqtest.c
> +++ b/tests/qtest/libqtest.c
> @@ -65,6 +65,8 @@ struct QTestState
>       GList *pending_events;
>   };
>   
> +QTestState *global_qtest;
> +
>   static GHookList abrt_hooks;
>   static struct sigaction sigact_old;

I'm a little bit afraid that this could cause people to abuse global_qtest 
again in code that should be usable by multiple test instances. This was 
very painful to get rid off in the past...

Could you maybe use some #ifdef WIN32 here to keep the common+weak case on 
Linux and just declare it in libqtest.c on Windows?

  Thomas



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

* Re: [PATCH 30/51] tests: Skip iotests and qtest when '--without-default-devices'
  2022-08-24  9:40 ` [PATCH 30/51] tests: Skip iotests and qtest when '--without-default-devices' Bin Meng
@ 2022-08-25 12:03   ` Thomas Huth
  2022-09-02 15:18     ` Bin Meng
  0 siblings, 1 reply; 174+ messages in thread
From: Thomas Huth @ 2022-08-25 12:03 UTC (permalink / raw)
  To: Bin Meng, qemu-devel
  Cc: Bin Meng, Hanna Reitz, Kevin Wolf, Laurent Vivier, Paolo Bonzini,
	qemu-block

On 24/08/2022 11.40, Bin Meng wrote:
> From: Bin Meng <bin.meng@windriver.com>
> 
> When QEMU is configured with '--without-default-devices', we should
> not build and run iotests and qtest because devices used by these
> test cases are not built in.
> 
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
> 
>   tests/qemu-iotests/meson.build | 5 +++++
>   tests/qtest/meson.build        | 5 +++++
>   2 files changed, 10 insertions(+)
> 
> diff --git a/tests/qemu-iotests/meson.build b/tests/qemu-iotests/meson.build
> index 323a4acb6a..38d9a874d2 100644
> --- a/tests/qemu-iotests/meson.build
> +++ b/tests/qemu-iotests/meson.build
> @@ -2,6 +2,11 @@ if not have_tools or targetos == 'windows' or get_option('gprof')
>     subdir_done()
>   endif
>   
> +# Skip iotests if configured without a default selection of devices
> +if not get_option('default_devices')
> +  subdir_done()
> +endif
> +
>   foreach cflag: config_host['QEMU_CFLAGS'].split()
>     if cflag.startswith('-fsanitize') and \
>        not cflag.contains('safe-stack') and not cflag.contains('cfi-icall')
> diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
> index c97da5a062..0291b3966c 100644
> --- a/tests/qtest/meson.build
> +++ b/tests/qtest/meson.build
> @@ -4,6 +4,11 @@ if not config_host.has_key('CONFIG_POSIX')
>     subdir_done()
>   endif
>   
> +# Skip QTests if configured without a default selection of devices
> +if not get_option('default_devices')
> +  subdir_done()
> +endif
> +
>   slow_qtests = {
>     'ahci-test' : 60,
>     'bios-tables-test' : 120,

That's a very big hammer already ... I'd prefer if we could work on the 
tests instead to adapt for the availability of devices instead (we've done 
quite a lot of work in this area in the past already, but apparently still 
not enough yet ...)

  Thomas



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

* Re: [PATCH 32/51] tests/qtest: Fix ERROR_SHARING_VIOLATION for win32
  2022-08-24  9:40 ` [PATCH 32/51] tests/qtest: Fix ERROR_SHARING_VIOLATION for win32 Bin Meng
@ 2022-08-25 12:06   ` Thomas Huth
  2022-09-02 10:59     ` Bin Meng
  2022-09-01  8:42   ` Marc-André Lureau
  1 sibling, 1 reply; 174+ messages in thread
From: Thomas Huth @ 2022-08-25 12:06 UTC (permalink / raw)
  To: Bin Meng, qemu-devel
  Cc: Bin Meng, John Snow, Laurent Vivier, Paolo Bonzini, qemu-block

On 24/08/2022 11.40, Bin Meng wrote:
> From: Bin Meng <bin.meng@windriver.com>
> 
> On Windows, the MinGW provided mkstemp() API opens the file with
> exclusive access, denying other processes to read/write the file.
> Such behavior prevents the QEMU executable from opening the file,
> (e.g.: CreateFile returns ERROR_SHARING_VIOLATION).
> 
> This can be fixed by closing the file and reopening it.

Would it work to use the glib functions instead (like g_file_open_tmp() ?)

  Thomas




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

* Re: [PATCH 35/51] tests/qtest: device-plug-test: Reverse the usage of double/single quotes
  2022-08-24  9:40 ` [PATCH 35/51] tests/qtest: device-plug-test: Reverse the usage of double/single quotes Bin Meng
@ 2022-08-25 12:20   ` Thomas Huth
  0 siblings, 0 replies; 174+ messages in thread
From: Thomas Huth @ 2022-08-25 12:20 UTC (permalink / raw)
  To: Bin Meng, qemu-devel; +Cc: Bin Meng, Laurent Vivier, Paolo Bonzini

On 24/08/2022 11.40, Bin Meng wrote:
> From: Bin Meng <bin.meng@windriver.com>
> 
> The usage of double/single quotes in test_pci_unplug_json_request()
> should be reversed to work on both win32 and non-win32 platforms:
> 
> - The value of -device parameter needs to be surrounded by "" as
>    Windows does not drop '' when passing it to QEMU which causes
>    QEMU command line option parser failure.
> - The JSON key/value pairs need to be surrounded by '' to make the
>    JSON parser happy on Windows.
> 
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
> 
>   tests/qtest/device-plug-test.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tests/qtest/device-plug-test.c b/tests/qtest/device-plug-test.c
> index 2e3137843e..a1fb99c8ff 100644
> --- a/tests/qtest/device-plug-test.c
> +++ b/tests/qtest/device-plug-test.c
> @@ -95,7 +95,7 @@ static void test_pci_unplug_json_request(void)
>       }
>   
>       QTestState *qtest = qtest_initf(
> -        "%s -device '{\"driver\": \"virtio-mouse-pci\", \"id\": \"dev0\"}'",
> +        "%s -device \"{'driver': 'virtio-mouse-pci', 'id': 'dev0'}\"",
>           machine_addition);

It's also a shorter string, so that's even nicer to read!

Reviewed-by: Thomas Huth <thuth@redhat.com>



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

* Re: [PATCH 36/51] tests/qtest: machine-none-test: Use double quotes to pass the cpu option
  2022-08-24  9:40 ` [PATCH 36/51] tests/qtest: machine-none-test: Use double quotes to pass the cpu option Bin Meng
@ 2022-08-25 12:22   ` Thomas Huth
  0 siblings, 0 replies; 174+ messages in thread
From: Thomas Huth @ 2022-08-25 12:22 UTC (permalink / raw)
  To: Bin Meng, qemu-devel; +Cc: Bin Meng, Laurent Vivier, Paolo Bonzini

On 24/08/2022 11.40, Bin Meng wrote:
> From: Bin Meng <bin.meng@windriver.com>
> 
> Single quotes in the arguments (e.g.: -cpu 'qemu64,apic-id=0') are
> not removed in the Windows environment before it is passed to the
> QEMU executable. Such argument causes a failure in the QEMU CPU
> option parser codes.
> 
> Change to use double quotes which works fine on all platforms.
> 
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
> 
>   tests/qtest/machine-none-test.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tests/qtest/machine-none-test.c b/tests/qtest/machine-none-test.c
> index f92fab479f..31cc0bfb01 100644
> --- a/tests/qtest/machine-none-test.c
> +++ b/tests/qtest/machine-none-test.c
> @@ -81,7 +81,7 @@ static void test_machine_cpu_cli(void)
>                   " add it to cpus_map\n", arch);
>           return; /* TODO: die here to force all targets have a test */
>       }
> -    qts = qtest_initf("-machine none -cpu '%s'", cpu_model);
> +    qts = qtest_initf("-machine none -cpu \"%s\"", cpu_model);
>   
>       response = qtest_qmp(qts, "{ 'execute': 'quit' }");
>       g_assert(qdict_haskey(response, "return"));

Reviewed-by: Thomas Huth <thuth@redhat.com>



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

* Re: [PATCH 38/51] tests/qtest: {ahci,ide}-test: Open file in binary mode
  2022-08-24  9:40 ` [PATCH 38/51] tests/qtest: {ahci,ide}-test: Open file in binary mode Bin Meng
@ 2022-08-25 12:28   ` Thomas Huth
  2022-09-01  9:08   ` [PATCH 38/51] tests/qtest: {ahci, ide}-test: " Marc-André Lureau
  1 sibling, 0 replies; 174+ messages in thread
From: Thomas Huth @ 2022-08-25 12:28 UTC (permalink / raw)
  To: Bin Meng, qemu-devel
  Cc: Xuzhou Cheng, Bin Meng, John Snow, Laurent Vivier, Paolo Bonzini,
	qemu-block

On 24/08/2022 11.40, Bin Meng wrote:
> From: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> 
> By default Windows opens file in text mode, while a POSIX compliant
> implementation treats text files and binary files the same.
> 
> The fopen() 'mode' string can include the letter 'b' to indicate
> binary mode shall be used. POSIX spec says the character 'b' shall
> have no effect, but is allowed for ISO C standard conformance.
> Let's add the letter 'b' which works on both POSIX and Windows.
> 
> Similar situation applies to the open() 'flags' where O_BINARY is
> used for binary mode.
> 
> Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
> 
>   tests/qtest/ahci-test.c | 2 +-
>   tests/qtest/ide-test.c  | 4 ++--
>   2 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/tests/qtest/ahci-test.c b/tests/qtest/ahci-test.c
> index bce9ff770c..be11508c75 100644
> --- a/tests/qtest/ahci-test.c
> +++ b/tests/qtest/ahci-test.c
> @@ -1453,7 +1453,7 @@ static int prepare_iso(size_t size, unsigned char **buf, char **name)
>        * Close the file and reopen it.
>        */
>       close(fd);
> -    fd = open(cdrom_path, O_WRONLY);
> +    fd = open(cdrom_path, O_WRONLY | O_BINARY);
>       g_assert(fd != -1);
>   #endif

Could you please squash this hunk into patch 32/51 where you introduced this 
code?

  Thomas



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

* Re: [PATCH 43/51] tests/qtest: npcm7xx_emc-test: Skip running test_{tx,rx} on win32
  2022-08-24  9:40 ` [PATCH 43/51] tests/qtest: npcm7xx_emc-test: Skip running test_{tx, rx} on win32 Bin Meng
@ 2022-08-25 12:32   ` Thomas Huth
  2022-08-25 16:40   ` [PATCH 43/51] tests/qtest: npcm7xx_emc-test: Skip running test_{tx, rx} " Hao Wu
  1 sibling, 0 replies; 174+ messages in thread
From: Thomas Huth @ 2022-08-25 12:32 UTC (permalink / raw)
  To: Bin Meng, qemu-devel
  Cc: Bin Meng, Havard Skinnemoen, Laurent Vivier, Paolo Bonzini,
	Tyrone Ting, qemu-arm

On 24/08/2022 11.40, Bin Meng wrote:
> From: Bin Meng <bin.meng@windriver.com>
> 
> The test cases 'test_{tx,rx}' call socketpair() which does not exist
> on win32. Exclude them.
> 
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
> 
>   tests/qtest/npcm7xx_emc-test.c | 8 ++++++++
>   1 file changed, 8 insertions(+)

Reviewed-by: Thomas Huth <thuth@redhat.com>



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

* Re: [PATCH 45/51] tests/qtest: prom-env-test: Use double quotes to pass the prom-env option
  2022-08-24  9:40 ` [PATCH 45/51] tests/qtest: prom-env-test: Use double quotes to pass the prom-env option Bin Meng
@ 2022-08-25 12:33   ` Thomas Huth
  0 siblings, 0 replies; 174+ messages in thread
From: Thomas Huth @ 2022-08-25 12:33 UTC (permalink / raw)
  To: Bin Meng, qemu-devel; +Cc: Bin Meng, Laurent Vivier, Paolo Bonzini

On 24/08/2022 11.40, Bin Meng wrote:
> From: Bin Meng <bin.meng@windriver.com>
> 
> Single quotes like -prom-env 'nvramrc=cafec0de 4000 l!' in the arguments
> are not removed in the Windows environment before it is passed to the
> QEMU executable. Such argument causes a failure in the QEMU prom-env
> option parser codes.
> 
> Change to use double quotes which works fine on all platforms.
> 
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
> 
>   tests/qtest/prom-env-test.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/tests/qtest/prom-env-test.c b/tests/qtest/prom-env-test.c
> index c2b0448e55..39ccb59797 100644
> --- a/tests/qtest/prom-env-test.c
> +++ b/tests/qtest/prom-env-test.c
> @@ -58,8 +58,8 @@ static void test_machine(const void *machine)
>               " -machine " PSERIES_DEFAULT_CAPABILITIES;
>       }
>   
> -    qts = qtest_initf("-M %s -accel tcg %s -prom-env 'use-nvramrc?=true' "
> -                      "-prom-env 'nvramrc=%x %x l!' ", (const char *)machine,
> +    qts = qtest_initf("-M %s -accel tcg %s -prom-env \"use-nvramrc?=true\" "
> +                      "-prom-env \"nvramrc=%x %x l!\" ", (const char *)machine,
>                         extra_args, MAGIC, ADDRESS);
>       check_guest_memory(qts);
>       qtest_quit(qts);

Reviewed-by: Thomas Huth <thuth@redhat.com>



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

* Re: [PATCH 18/51] tests/qtest: Build cases that use memory-backend-file for posix only
  2022-08-24  9:39 ` [PATCH 18/51] tests/qtest: Build cases that use memory-backend-file " Bin Meng
@ 2022-08-25 12:39   ` Thomas Huth
  0 siblings, 0 replies; 174+ messages in thread
From: Thomas Huth @ 2022-08-25 12:39 UTC (permalink / raw)
  To: Bin Meng, qemu-devel
  Cc: Bin Meng, Ani Sinha, Igor Mammedov, Laurent Vivier,
	Michael S. Tsirkin, Paolo Bonzini

On 24/08/2022 11.39, Bin Meng wrote:
> From: Bin Meng <bin.meng@windriver.com>
> 
> As backends/meson.build tells us, hostmem-file.c is only supported on
> POSIX platforms, hence any test case that utilizes the memory backend
> file should be guarded by CONFIG_POSIX too.
> 
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
> 
>   tests/qtest/bios-tables-test.c | 10 ++++++++++
>   tests/qtest/cxl-test.c         |  4 ++++
>   tests/qtest/meson.build        |  3 ++-
>   3 files changed, 16 insertions(+), 1 deletion(-)

Acked-by: Thomas Huth <thuth@redhat.com>



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

* Re: [PATCH 27/51] tests/qtest: Use send/recv for socket communication
  2022-08-24  9:40 ` [PATCH 27/51] tests/qtest: Use send/recv for socket communication Bin Meng
@ 2022-08-25 13:04   ` Thomas Huth
  2022-08-26 14:59     ` Bin Meng
  0 siblings, 1 reply; 174+ messages in thread
From: Thomas Huth @ 2022-08-25 13:04 UTC (permalink / raw)
  To: Bin Meng, qemu-devel
  Cc: Xuzhou Cheng, Bin Meng, Laurent Vivier, Paolo Bonzini

On 24/08/2022 11.40, Bin Meng wrote:
> From: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> 
> Socket communication in the libqtest and libqmp codes uses read()
> and write() which work on any file descriptor on *nix, and sockets
> in *nix are an example of a file descriptor.
> 
> However sockets on Windows do not use *nix-style file descriptors,
> so read() and write() cannot be used on sockets on Windows.
> Switch over to use send() and recv() instead which work on both
> Windows and *nix.
> 
> Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
> 
>   tests/qtest/libqmp.c   | 4 ++--
>   tests/qtest/libqtest.c | 4 ++--
>   2 files changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/tests/qtest/libqmp.c b/tests/qtest/libqmp.c
> index ade26c15f0..995a39c1f8 100644
> --- a/tests/qtest/libqmp.c
> +++ b/tests/qtest/libqmp.c
> @@ -36,7 +36,7 @@ typedef struct {
>   
>   static void socket_send(int fd, const char *buf, size_t size)
>   {
> -    size_t res = qemu_write_full(fd, buf, size);
> +    ssize_t res = send(fd, buf, size, 0);

This way we're losing the extra logic from qemu_write_full() here (i.e. the 
looping and EINTR handling) ... not sure whether that's really OK? Maybe you 
have to introduce a qemu_send_full() first?

  Thomas




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

* Re: [PATCH 43/51] tests/qtest: npcm7xx_emc-test: Skip running test_{tx, rx} on win32
  2022-08-24  9:40 ` [PATCH 43/51] tests/qtest: npcm7xx_emc-test: Skip running test_{tx, rx} on win32 Bin Meng
  2022-08-25 12:32   ` [PATCH 43/51] tests/qtest: npcm7xx_emc-test: Skip running test_{tx,rx} " Thomas Huth
@ 2022-08-25 16:40   ` Hao Wu
  1 sibling, 0 replies; 174+ messages in thread
From: Hao Wu @ 2022-08-25 16:40 UTC (permalink / raw)
  To: Bin Meng
  Cc: QEMU Developers, Bin Meng, Havard Skinnemoen, Laurent Vivier,
	Paolo Bonzini, Thomas Huth, Tyrone Ting, qemu-arm

[-- Attachment #1: Type: text/plain, Size: 2509 bytes --]

On Wed, Aug 24, 2022 at 3:35 AM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Bin Meng <bin.meng@windriver.com>
>
> The test cases 'test_{tx,rx}' call socketpair() which does not exist
> on win32. Exclude them.
>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
>
Reviewed-by: Hao Wu <wuhaotsh@google.com>

> ---
>
>  tests/qtest/npcm7xx_emc-test.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
>
> diff --git a/tests/qtest/npcm7xx_emc-test.c
> b/tests/qtest/npcm7xx_emc-test.c
> index a353fef0ca..c373d24e1e 100644
> --- a/tests/qtest/npcm7xx_emc-test.c
> +++ b/tests/qtest/npcm7xx_emc-test.c
> @@ -209,6 +209,7 @@ static int emc_module_index(const EMCModule *mod)
>      return diff;
>  }
>
> +#ifndef _WIN32
>  static void packet_test_clear(void *sockets)
>  {
>      int *test_sockets = sockets;
> @@ -243,6 +244,7 @@ static int *packet_test_init(int module_num, GString
> *cmd_line)
>      g_test_queue_destroy(packet_test_clear, test_sockets);
>      return test_sockets;
>  }
> +#endif /* _WIN32 */
>
>  static uint32_t emc_read(QTestState *qts, const EMCModule *mod,
>                           NPCM7xxPWMRegister regno)
> @@ -250,6 +252,7 @@ static uint32_t emc_read(QTestState *qts, const
> EMCModule *mod,
>      return qtest_readl(qts, mod->base_addr + regno * sizeof(uint32_t));
>  }
>
> +#ifndef _WIN32
>  static void emc_write(QTestState *qts, const EMCModule *mod,
>                        NPCM7xxPWMRegister regno, uint32_t value)
>  {
> @@ -339,6 +342,7 @@ static bool emc_soft_reset(QTestState *qts, const
> EMCModule *mod)
>      g_message("%s: Timeout expired", __func__);
>      return false;
>  }
> +#endif /* _WIN32 */
>
>  /* Check emc registers are reset to default value. */
>  static void test_init(gconstpointer test_data)
> @@ -387,6 +391,7 @@ static void test_init(gconstpointer test_data)
>      qtest_quit(qts);
>  }
>
> +#ifndef _WIN32
>  static bool emc_wait_irq(QTestState *qts, const EMCModule *mod, int step,
>                           bool is_tx)
>  {
> @@ -843,6 +848,7 @@ static void test_rx(gconstpointer test_data)
>
>      qtest_quit(qts);
>  }
> +#endif /* _WIN32 */
>
>  static void emc_add_test(const char *name, const TestData* td,
>                           GTestDataFunc fn)
> @@ -865,8 +871,10 @@ int main(int argc, char **argv)
>          td->module = &emc_module_list[i];
>
>          add_test(init, td);
> +#ifndef _WIN32
>          add_test(tx, td);
>          add_test(rx, td);
> +#endif
>      }
>
>      return g_test_run();
> --
> 2.34.1
>
>
>

[-- Attachment #2: Type: text/html, Size: 3526 bytes --]

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

* Re: [PATCH 09/51] fsdev/virtfs-proxy-helper: Use g_mkdir_with_parents()
  2022-08-24  9:39 ` [PATCH 09/51] fsdev/virtfs-proxy-helper: Use g_mkdir_with_parents() Bin Meng
@ 2022-08-26 10:09   ` Christian Schoenebeck
  2022-08-26 10:30     ` Bin Meng
  0 siblings, 1 reply; 174+ messages in thread
From: Christian Schoenebeck @ 2022-08-26 10:09 UTC (permalink / raw)
  To: qemu-devel; +Cc: Bin Meng, Greg Kurz, Bin Meng

On Mittwoch, 24. August 2022 11:39:47 CEST Bin Meng wrote:
> From: Bin Meng <bin.meng@windriver.com>
> 
> Use the same g_mkdir_with_parents() call to create a directory on
> all platforms.

The same would be g_mkdir(), not g_mkdir_with_parents(), so please use that 
instead.

> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
> 
>  fsdev/virtfs-proxy-helper.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fsdev/virtfs-proxy-helper.c b/fsdev/virtfs-proxy-helper.c
> index 2dde27922f..d0cf76d6d1 100644
> --- a/fsdev/virtfs-proxy-helper.c
> +++ b/fsdev/virtfs-proxy-helper.c
> @@ -639,7 +639,7 @@ static int do_create_others(int type, struct iovec
> *iovec) if (retval < 0) {
>              goto err_out;
>          }
> -        retval = mkdir(path.data, mode);
> +        retval = g_mkdir_with_parents(path.data, mode);
>          break;
>      case T_SYMLINK:
>          retval = proxy_unmarshal(iovec, offset, "ss", &oldpath, &path);





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

* Re: [PATCH 09/51] fsdev/virtfs-proxy-helper: Use g_mkdir_with_parents()
  2022-08-26 10:09   ` Christian Schoenebeck
@ 2022-08-26 10:30     ` Bin Meng
  2022-08-26 11:16       ` Christian Schoenebeck
  0 siblings, 1 reply; 174+ messages in thread
From: Bin Meng @ 2022-08-26 10:30 UTC (permalink / raw)
  To: Christian Schoenebeck
  Cc: qemu-devel@nongnu.org Developers, Bin Meng, Greg Kurz

On Fri, Aug 26, 2022 at 6:09 PM Christian Schoenebeck
<qemu_oss@crudebyte.com> wrote:
>
> On Mittwoch, 24. August 2022 11:39:47 CEST Bin Meng wrote:
> > From: Bin Meng <bin.meng@windriver.com>
> >
> > Use the same g_mkdir_with_parents() call to create a directory on
> > all platforms.
>
> The same would be g_mkdir(), not g_mkdir_with_parents(), so please use that
> instead.
>

No, g_mkdir() is a deprecated API.

Search result (https://docs.gtk.org/glib/?q=mkdir) shows only
g_mkdir_with_parents().

Regards,
Bin


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

* Re: [PATCH 34/51] tests/qtest: bios-tables-test: Adapt the case for win32
  2022-08-24 12:42   ` Ani Sinha
@ 2022-08-26 10:38     ` Bin Meng
  0 siblings, 0 replies; 174+ messages in thread
From: Bin Meng @ 2022-08-26 10:38 UTC (permalink / raw)
  To: Ani Sinha
  Cc: qemu-devel@nongnu.org Developers, Bin Meng, Igor Mammedov,
	Michael S. Tsirkin

On Wed, Aug 24, 2022 at 8:42 PM Ani Sinha <ani@anisinha.ca> wrote:
>
>
>
> On Wed, 24 Aug 2022, Bin Meng wrote:
>
> > From: Bin Meng <bin.meng@windriver.com>
> >
> > Single quotes in the arguments (oem_id='CRASH ') are not removed in
> > the Windows environment before it is passed to the QEMU executable.
> > The space in the argument causes the "-acpitable" option parser to
> > think that all of its parameters are done, hence it complains:
> >
> >   '-acpitable' requires one of 'data' or 'file'
> >
> > Change to use double quotes which works fine on all platforms.
> >
> > Also /dev/null does not work on win32, and nul should be used.
> >
> > Signed-off-by: Bin Meng <bin.meng@windriver.com>
> > ---
> >
> >  tests/qtest/bios-tables-test.c | 12 +++++++++---
> >  1 file changed, 9 insertions(+), 3 deletions(-)
> >
> > diff --git a/tests/qtest/bios-tables-test.c b/tests/qtest/bios-tables-test.c
> > index 36783966b0..0148ce388c 100644
> > --- a/tests/qtest/bios-tables-test.c
> > +++ b/tests/qtest/bios-tables-test.c
> > @@ -1615,6 +1615,12 @@ static void test_acpi_virt_viot(void)
> >      free_test_data(&data);
> >  }
> >
> > +#ifndef _WIN32
> > +# define DEV_NULL "/dev/null"
> > +#else
> > +# define DEV_NULL "nul"
> > +#endif
> > +
> >  static void test_acpi_q35_slic(void)
> >  {
> >      test_data data = {
> > @@ -1622,9 +1628,9 @@ static void test_acpi_q35_slic(void)
> >          .variant = ".slic",
> >      };
> >
> > -    test_acpi_one("-acpitable sig=SLIC,oem_id='CRASH ',oem_table_id='ME',"
> > -                  "oem_rev=00002210,asl_compiler_id='qemu',"
> > -                  "asl_compiler_rev=00000000,data=/dev/null",
> > +    test_acpi_one("-acpitable sig=SLIC,oem_id=\"CRASH \",oem_table_id=ME,"
> > +                  "oem_rev=00002210,asl_compiler_id=qemu,"
>
> ME and qemu should be surrounded by quotes. They are string arguments.
> https://www.qemu.org/docs/master/interop/qemu-qmp-ref.html?highlight=oem_table_id
>

The doc also says sig is a string, but the original code does not
surround it by quotes.

The parameter is of string type by default, so there is no need to
surround it by quotes unless it contains some special characters.

Regards,
Bin


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

* Re: [PATCH 37/51] tests/qtest: migration-test: Disable IO redirection for win32
  2022-08-24 18:53   ` Dr. David Alan Gilbert
@ 2022-08-26 10:48     ` Bin Meng
  0 siblings, 0 replies; 174+ messages in thread
From: Bin Meng @ 2022-08-26 10:48 UTC (permalink / raw)
  To: Dr. David Alan Gilbert
  Cc: qemu-devel@nongnu.org Developers, Bin Meng, Juan Quintela,
	Laurent Vivier, Paolo Bonzini, Thomas Huth

On Thu, Aug 25, 2022 at 2:53 AM Dr. David Alan Gilbert
<dgilbert@redhat.com> wrote:
>
> * Bin Meng (bmeng.cn@gmail.com) wrote:
> > From: Bin Meng <bin.meng@windriver.com>
> >
> > On Windows the QEMU executable is created via CreateProcess() and IO
> > redirection does not work, so we need to set MigrateStart::hide_stderr
> > to false to disable adding IO redirection to the command line.
> >
> > Signed-off-by: Bin Meng <bin.meng@windriver.com>
>
> Isn't it easier just to change the one place that tests this?
>

Yeah, will do in v2.

Regards,
Bin


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

* Re: [PATCH 09/51] fsdev/virtfs-proxy-helper: Use g_mkdir_with_parents()
  2022-08-26 10:30     ` Bin Meng
@ 2022-08-26 11:16       ` Christian Schoenebeck
  2022-08-26 12:38         ` Bin Meng
  0 siblings, 1 reply; 174+ messages in thread
From: Christian Schoenebeck @ 2022-08-26 11:16 UTC (permalink / raw)
  To: qemu-devel, Bin Meng; +Cc: Greg Kurz, Bin Meng

On Freitag, 26. August 2022 12:30:20 CEST Bin Meng wrote:
> On Fri, Aug 26, 2022 at 6:09 PM Christian Schoenebeck
> 
> <qemu_oss@crudebyte.com> wrote:
> > On Mittwoch, 24. August 2022 11:39:47 CEST Bin Meng wrote:
> > > From: Bin Meng <bin.meng@windriver.com>
> > > 
> > > Use the same g_mkdir_with_parents() call to create a directory on
> > > all platforms.
> > 
> > The same would be g_mkdir(), not g_mkdir_with_parents(), so please use
> > that
> > instead.
> 
> No, g_mkdir() is a deprecated API.

Where did you got that from? AFAICS g_mkdir() does not seem to be deprecated:
https://gitlab.gnome.org/GNOME/glib/-/blob/main/glib/gstdio.c#L1201
https://gitlab.gnome.org/GNOME/glib/-/blob/main/glib/gstdio.h#L131

> Search result (https://docs.gtk.org/glib/?q=mkdir) shows only
> g_mkdir_with_parents().

Yeah, but that does not say that it was deprecated.

> Regards,
> Bin




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

* Re: [PATCH 50/51] .gitlab-ci.d/windows.yml: Increase the timeout to the runner limit
  2022-08-25  8:18   ` Thomas Huth
@ 2022-08-26 11:25     ` Bin Meng
  2022-08-26 11:33     ` Daniel P. Berrangé
  1 sibling, 0 replies; 174+ messages in thread
From: Bin Meng @ 2022-08-26 11:25 UTC (permalink / raw)
  To: Thomas Huth
  Cc: qemu-devel@nongnu.org Developers, Bin Meng, Alex Bennée,
	Beraldo Leal, Philippe Mathieu-Daudé,
	Wainer dos Santos Moschetta, Daniel P. Berrange

On Thu, Aug 25, 2022 at 4:18 PM Thomas Huth <thuth@redhat.com> wrote:
>
> On 24/08/2022 11.40, Bin Meng wrote:
> > From: Bin Meng <bin.meng@windriver.com>
> >
> > commit 9f8e6cad65a6 ("gitlab-ci: Speed up the msys2-64bit job by using --without-default-devices"
> > changed to compile QEMU with the --without-default-devices switch for
> > the msys2-64bit job, due to the build could not complete within the
> > project timeout (1h), and also mentioned that a bigger timeout was
> > getting ignored on the shared Gitlab-CI Windows runners.
> >
> > However as of today it seems the shared Gitlab-CI Windows runners does
> > honor the job timeout, and the runner has the timeout limit of 2h, so
> > let's increase the timeout to the runner limit and drop the configure
> > switch "--without-default-devices" to get a larger build coverage.
> >
> > As a result of this, the check-qtest starts running on Windows in CI.
> >
> > Signed-off-by: Bin Meng <bin.meng@windriver.com>
> > ---
> >
> >   .gitlab-ci.d/windows.yml | 4 ++--
> >   1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/.gitlab-ci.d/windows.yml b/.gitlab-ci.d/windows.yml
> > index c4bde758be..d4fd821b5f 100644
> > --- a/.gitlab-ci.d/windows.yml
> > +++ b/.gitlab-ci.d/windows.yml
> > @@ -10,7 +10,7 @@
> >         - ${CI_PROJECT_DIR}/msys64/var/cache
> >     needs: []
> >     stage: build
> > -  timeout: 70m
> > +  timeout: 2h
>
> IMHO 2 hours are too long ... we're normally trying to limit the time of
> each job to 1h only and only extend it a little bit if we cannot really
> make, but we should not double the amount of time here. The highest timeout
> that we currently have are 90 minutes ... would that still be OK for this

90 minutes is okay for "make -j2" on the CI machine, but if we disable
the parallel build I am afraid 90 minutes is not enough.

> job, too? If so, please use 90 minutes here. Otherwise, it might still be
> necessary to cut down this job here and there a little bit...
> (maybe the tests now also work a little bit faster now that the migration
> test has been speed up in 7.1-rc4 ?)

I believe the build takes more time than the testing. But definitely
the latest migration test speed up patch will help on windows too.

Regards,
Bin


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

* Re: [PATCH 50/51] .gitlab-ci.d/windows.yml: Increase the timeout to the runner limit
  2022-08-25  8:18   ` Thomas Huth
  2022-08-26 11:25     ` Bin Meng
@ 2022-08-26 11:33     ` Daniel P. Berrangé
  1 sibling, 0 replies; 174+ messages in thread
From: Daniel P. Berrangé @ 2022-08-26 11:33 UTC (permalink / raw)
  To: Thomas Huth
  Cc: Bin Meng, qemu-devel, Bin Meng, Alex Bennée, Beraldo Leal,
	Philippe Mathieu-Daudé,
	Wainer dos Santos Moschetta

On Thu, Aug 25, 2022 at 10:18:06AM +0200, Thomas Huth wrote:
> On 24/08/2022 11.40, Bin Meng wrote:
> > From: Bin Meng <bin.meng@windriver.com>
> > 
> > commit 9f8e6cad65a6 ("gitlab-ci: Speed up the msys2-64bit job by using --without-default-devices"
> > changed to compile QEMU with the --without-default-devices switch for
> > the msys2-64bit job, due to the build could not complete within the
> > project timeout (1h), and also mentioned that a bigger timeout was
> > getting ignored on the shared Gitlab-CI Windows runners.
> > 
> > However as of today it seems the shared Gitlab-CI Windows runners does
> > honor the job timeout, and the runner has the timeout limit of 2h, so
> > let's increase the timeout to the runner limit and drop the configure
> > switch "--without-default-devices" to get a larger build coverage.
> > 
> > As a result of this, the check-qtest starts running on Windows in CI.
> > 
> > Signed-off-by: Bin Meng <bin.meng@windriver.com>
> > ---
> > 
> >   .gitlab-ci.d/windows.yml | 4 ++--
> >   1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/.gitlab-ci.d/windows.yml b/.gitlab-ci.d/windows.yml
> > index c4bde758be..d4fd821b5f 100644
> > --- a/.gitlab-ci.d/windows.yml
> > +++ b/.gitlab-ci.d/windows.yml
> > @@ -10,7 +10,7 @@
> >         - ${CI_PROJECT_DIR}/msys64/var/cache
> >     needs: []
> >     stage: build
> > -  timeout: 70m
> > +  timeout: 2h
> 
> IMHO 2 hours are too long ... we're normally trying to limit the time of
> each job to 1h only and only extend it a little bit if we cannot really
> make, but we should not double the amount of time here. The highest timeout
> that we currently have are 90 minutes ... would that still be OK for this
> job, too? If so, please use 90 minutes here. Otherwise, it might still be
> necessary to cut down this job here and there a little bit...

Also note that 90 minutes is not considered the typical execution
time. For a 90 minute timeout, we should expect the job to run
much quicker than that under normal CI load. eg a 90 minute timeout
should imply a job typically runs in 60-70 minutes, leaving some slack.

IMHO if normal execution of a job takes >60 minutes, we need to
turn off features in CI to get it faster, or split it across
multiple jobs, not increase the timeout even more.


With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|



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

* Re: [PATCH 09/51] fsdev/virtfs-proxy-helper: Use g_mkdir_with_parents()
  2022-08-26 11:16       ` Christian Schoenebeck
@ 2022-08-26 12:38         ` Bin Meng
  2022-08-26 13:27           ` Christian Schoenebeck
  0 siblings, 1 reply; 174+ messages in thread
From: Bin Meng @ 2022-08-26 12:38 UTC (permalink / raw)
  To: Christian Schoenebeck
  Cc: qemu-devel@nongnu.org Developers, Bin Meng, Greg Kurz

On Fri, Aug 26, 2022 at 7:16 PM Christian Schoenebeck
<qemu_oss@crudebyte.com> wrote:
>
> On Freitag, 26. August 2022 12:30:20 CEST Bin Meng wrote:
> > On Fri, Aug 26, 2022 at 6:09 PM Christian Schoenebeck
> >
> > <qemu_oss@crudebyte.com> wrote:
> > > On Mittwoch, 24. August 2022 11:39:47 CEST Bin Meng wrote:
> > > > From: Bin Meng <bin.meng@windriver.com>
> > > >
> > > > Use the same g_mkdir_with_parents() call to create a directory on
> > > > all platforms.
> > >
> > > The same would be g_mkdir(), not g_mkdir_with_parents(), so please use
> > > that
> > > instead.
> >
> > No, g_mkdir() is a deprecated API.
>
> Where did you got that from? AFAICS g_mkdir() does not seem to be deprecated:
> https://gitlab.gnome.org/GNOME/glib/-/blob/main/glib/gstdio.c#L1201
> https://gitlab.gnome.org/GNOME/glib/-/blob/main/glib/gstdio.h#L131
>
> > Search result (https://docs.gtk.org/glib/?q=mkdir) shows only
> > g_mkdir_with_parents().
>
> Yeah, but that does not say that it was deprecated.
>

Umm, correct. However I don't remember where I got the statement that
it was deprecated.

Maybe I was misled by the doc. Do you know why does the doc not
document g_mkdir()?

Regards,
Bin


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

* Re: [PATCH 40/51] chardev/char-file: Add FILE_SHARE_WRITE when openning the file for win32
  2022-08-25  7:58   ` Marc-André Lureau
@ 2022-08-26 13:15     ` Bin Meng
  2022-08-26 13:23       ` Marc-André Lureau
  0 siblings, 1 reply; 174+ messages in thread
From: Bin Meng @ 2022-08-26 13:15 UTC (permalink / raw)
  To: Marc-André Lureau
  Cc: qemu-devel@nongnu.org Developers, Xuzhou Cheng, Bin Meng, Paolo Bonzini

On Thu, Aug 25, 2022 at 3:59 PM Marc-André Lureau
<marcandre.lureau@redhat.com> wrote:
>
> Hi
>
> On Wed, Aug 24, 2022 at 1:43 PM Bin Meng <bmeng.cn@gmail.com> wrote:
> >
> > From: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> >
> > The combination of GENERIC_WRITE and FILE_SHARE_READ options does
> > not allow the same file to be opened again by CreateFile() from
> > another QEMU process with the same options when the previous QEMU
> > process still holds the file handle openned.
>
> opened
>
> >
> > As per [1] we should add FILE_SHARE_WRITE to the share mode to allow
> > such use case. This change makes the behavior be consisten with the
> > POSIX platforms.
> >
>
> consistent
>
> > [1] https://docs.microsoft.com/en-us/windows/win32/fileio/creating-and-opening-files
> >
> > Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> > Signed-off-by: Bin Meng <bin.meng@windriver.com>
> > ---
>
>
> What's the benefit to allow multiple processes write access to the
> same file? It seems it could easily lead to corruption or unexpected
> results.

This was triggered by running the test_multifd_tcp_cancel() case on
windows, which cancels the migration, and launches another QEMU
process to migrate with the same file opened for write. Chances are
that the previous QEMU process does not quit before the new QEMU
process runs hence the new one still holds the file handle that does
not allow shared write permission then the new QEMU process will fail.

> To me, it's the other way around, the POSIX implementation should
> learn to lock the file opened for write..
>

Regards,
Bin


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

* Re: [PATCH 40/51] chardev/char-file: Add FILE_SHARE_WRITE when openning the file for win32
  2022-08-26 13:15     ` Bin Meng
@ 2022-08-26 13:23       ` Marc-André Lureau
  2022-08-27 23:19         ` Bin Meng
  0 siblings, 1 reply; 174+ messages in thread
From: Marc-André Lureau @ 2022-08-26 13:23 UTC (permalink / raw)
  To: Bin Meng
  Cc: qemu-devel@nongnu.org Developers, Xuzhou Cheng, Bin Meng, Paolo Bonzini

[-- Attachment #1: Type: text/plain, Size: 1831 bytes --]

Hi

On Fri, Aug 26, 2022 at 5:16 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> On Thu, Aug 25, 2022 at 3:59 PM Marc-André Lureau
> <marcandre.lureau@redhat.com> wrote:
> >
> > Hi
> >
> > On Wed, Aug 24, 2022 at 1:43 PM Bin Meng <bmeng.cn@gmail.com> wrote:
> > >
> > > From: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> > >
> > > The combination of GENERIC_WRITE and FILE_SHARE_READ options does
> > > not allow the same file to be opened again by CreateFile() from
> > > another QEMU process with the same options when the previous QEMU
> > > process still holds the file handle openned.
> >
> > opened
> >
> > >
> > > As per [1] we should add FILE_SHARE_WRITE to the share mode to allow
> > > such use case. This change makes the behavior be consisten with the
> > > POSIX platforms.
> > >
> >
> > consistent
> >
> > > [1]
> https://docs.microsoft.com/en-us/windows/win32/fileio/creating-and-opening-files
> > >
> > > Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> > > Signed-off-by: Bin Meng <bin.meng@windriver.com>
> > > ---
> >
> >
> > What's the benefit to allow multiple processes write access to the
> > same file? It seems it could easily lead to corruption or unexpected
> > results.
>
> This was triggered by running the test_multifd_tcp_cancel() case on
> windows, which cancels the migration, and launches another QEMU
> process to migrate with the same file opened for write. Chances are
> that the previous QEMU process does not quit before the new QEMU
> process runs hence the new one still holds the file handle that does
> not allow shared write permission then the new QEMU process will fail.
>
>
Thanks for the details, that's worth to add in commit message imho.

But can't we fix the test instead to use different paths?

-- 
Marc-André Lureau

[-- Attachment #2: Type: text/html, Size: 2946 bytes --]

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

* Re: [PATCH 09/51] fsdev/virtfs-proxy-helper: Use g_mkdir_with_parents()
  2022-08-26 12:38         ` Bin Meng
@ 2022-08-26 13:27           ` Christian Schoenebeck
  0 siblings, 0 replies; 174+ messages in thread
From: Christian Schoenebeck @ 2022-08-26 13:27 UTC (permalink / raw)
  To: qemu-devel, Bin Meng; +Cc: Greg Kurz, Bin Meng

On Freitag, 26. August 2022 14:38:27 CEST Bin Meng wrote:
> On Fri, Aug 26, 2022 at 7:16 PM Christian Schoenebeck
> 
> <qemu_oss@crudebyte.com> wrote:
> > On Freitag, 26. August 2022 12:30:20 CEST Bin Meng wrote:
> > > On Fri, Aug 26, 2022 at 6:09 PM Christian Schoenebeck
> > > 
> > > <qemu_oss@crudebyte.com> wrote:
> > > > On Mittwoch, 24. August 2022 11:39:47 CEST Bin Meng wrote:
> > > > > From: Bin Meng <bin.meng@windriver.com>
> > > > > 
> > > > > Use the same g_mkdir_with_parents() call to create a directory on
> > > > > all platforms.
> > > > 
> > > > The same would be g_mkdir(), not g_mkdir_with_parents(), so please use
> > > > that
> > > > instead.
> > > 
> > > No, g_mkdir() is a deprecated API.
> > 
> > Where did you got that from? AFAICS g_mkdir() does not seem to be
> > deprecated:
> > https://gitlab.gnome.org/GNOME/glib/-/blob/main/glib/gstdio.c#L1201
> > https://gitlab.gnome.org/GNOME/glib/-/blob/main/glib/gstdio.h#L131> 
> > > Search result (https://docs.gtk.org/glib/?q=mkdir) shows only
> > > g_mkdir_with_parents().
> > 
> > Yeah, but that does not say that it was deprecated.
> 
> Umm, correct. However I don't remember where I got the statement that
> it was deprecated.
> 
> Maybe I was misled by the doc. Do you know why does the doc not
> document g_mkdir()?

Maybe gtk-doc does not define G_STDIO_WRAP_ON_UNIX?

Other functions like g_chmod() are missing in the generated docs as well, 
whereas g_access() et al. are there, those are declared in both conditions.
 
> Regards,
> Bin




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

* Re: [PATCH 11/51] qga/commands-posix-ssh: Use g_mkdir_with_parents()
  2022-08-24 14:41   ` Konstantin Kostiuk
@ 2022-08-26 14:46     ` Bin Meng
  0 siblings, 0 replies; 174+ messages in thread
From: Bin Meng @ 2022-08-26 14:46 UTC (permalink / raw)
  To: Konstantin Kostiuk
  Cc: qemu-devel@nongnu.org Developers, Bin Meng, Michael Roth

On Wed, Aug 24, 2022 at 10:41 PM Konstantin Kostiuk <kkostiuk@redhat.com> wrote:
>
> Reviewed-by: Konstantin Kostiuk <kkostiuk@redhat.com>
>
> On Wed, Aug 24, 2022 at 12:42 PM Bin Meng <bmeng.cn@gmail.com> wrote:
>>
>> From: Bin Meng <bin.meng@windriver.com>
>>
>> g_mkdir() is a deprecated API and newer codes should use
>> g_mkdir_with_parents().
>>
>> Signed-off-by: Bin Meng <bin.meng@windriver.com>
>> ---
>>
>>  qga/commands-posix-ssh.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>

I was wrong that g_mkdir() is deprecated. I must have been misled by
the GTK glib doc.

Using g_mkdir() is still fine so this patch can be dropped. Sorry about that.

Regards,
Bin


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

* Re: [PATCH 12/51] tests: Use g_mkdir_with_parents()
  2022-08-24 17:58   ` Dr. David Alan Gilbert
@ 2022-08-26 14:49     ` Bin Meng
  0 siblings, 0 replies; 174+ messages in thread
From: Bin Meng @ 2022-08-26 14:49 UTC (permalink / raw)
  To: Dr. David Alan Gilbert
  Cc: qemu-devel@nongnu.org Developers, Bin Meng,
	Daniel P. Berrangé,
	Juan Quintela, Laurent Vivier, Paolo Bonzini, Thomas Huth

On Thu, Aug 25, 2022 at 1:58 AM Dr. David Alan Gilbert
<dgilbert@redhat.com> wrote:
>
> * Bin Meng (bmeng.cn@gmail.com) wrote:
> > From: Bin Meng <bin.meng@windriver.com>
> >
> > Use the same g_mkdir_with_parents() call to create a directory on
> > all platforms.
> >
> > Signed-off-by: Bin Meng <bin.meng@windriver.com>
>
> Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
>
> > ---
> >
> >  tests/migration/stress.c              | 2 +-
> >  tests/qtest/migration-test.c          | 6 +++---
> >  tests/unit/test-crypto-tlscredsx509.c | 4 ++--
> >  tests/unit/test-crypto-tlssession.c   | 6 +++---
> >  tests/unit/test-io-channel-tls.c      | 6 +++---
> >  5 files changed, 12 insertions(+), 12 deletions(-)
> >

The exact portable replacement for mkdir() in glib is g_mkdir(), not
g_mkdir_with_parents().

I was misled by the GTK glib doc [1] before. I will change it to
g_mkdir() in v2 instead.

[1] https://docs.gtk.org/glib/?q=mkdir

Regards,
Bin


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

* Re: [PATCH 27/51] tests/qtest: Use send/recv for socket communication
  2022-08-25 13:04   ` Thomas Huth
@ 2022-08-26 14:59     ` Bin Meng
  2022-08-26 18:26       ` Thomas Huth
  0 siblings, 1 reply; 174+ messages in thread
From: Bin Meng @ 2022-08-26 14:59 UTC (permalink / raw)
  To: Thomas Huth
  Cc: qemu-devel@nongnu.org Developers, Xuzhou Cheng, Bin Meng,
	Laurent Vivier, Paolo Bonzini

On Thu, Aug 25, 2022 at 9:04 PM Thomas Huth <thuth@redhat.com> wrote:
>
> On 24/08/2022 11.40, Bin Meng wrote:
> > From: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> >
> > Socket communication in the libqtest and libqmp codes uses read()
> > and write() which work on any file descriptor on *nix, and sockets
> > in *nix are an example of a file descriptor.
> >
> > However sockets on Windows do not use *nix-style file descriptors,
> > so read() and write() cannot be used on sockets on Windows.
> > Switch over to use send() and recv() instead which work on both
> > Windows and *nix.
> >
> > Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> > Signed-off-by: Bin Meng <bin.meng@windriver.com>
> > ---
> >
> >   tests/qtest/libqmp.c   | 4 ++--
> >   tests/qtest/libqtest.c | 4 ++--
> >   2 files changed, 4 insertions(+), 4 deletions(-)
> >
> > diff --git a/tests/qtest/libqmp.c b/tests/qtest/libqmp.c
> > index ade26c15f0..995a39c1f8 100644
> > --- a/tests/qtest/libqmp.c
> > +++ b/tests/qtest/libqmp.c
> > @@ -36,7 +36,7 @@ typedef struct {
> >
> >   static void socket_send(int fd, const char *buf, size_t size)
> >   {
> > -    size_t res = qemu_write_full(fd, buf, size);
> > +    ssize_t res = send(fd, buf, size, 0);
>
> This way we're losing the extra logic from qemu_write_full() here (i.e. the
> looping and EINTR handling) ... not sure whether that's really OK? Maybe you
> have to introduce a qemu_send_full() first?
>

I am not sure if qemu_send_full() is really needed because there is an
assert() right after the send() call.

Regards,
Bin


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

* Re: [PATCH 27/51] tests/qtest: Use send/recv for socket communication
  2022-08-26 14:59     ` Bin Meng
@ 2022-08-26 18:26       ` Thomas Huth
  2022-08-31 14:05         ` Marc-André Lureau
  0 siblings, 1 reply; 174+ messages in thread
From: Thomas Huth @ 2022-08-26 18:26 UTC (permalink / raw)
  To: Bin Meng
  Cc: qemu-devel@nongnu.org Developers, Xuzhou Cheng, Bin Meng,
	Laurent Vivier, Paolo Bonzini

On 26/08/2022 16.59, Bin Meng wrote:
> On Thu, Aug 25, 2022 at 9:04 PM Thomas Huth <thuth@redhat.com> wrote:
>>
>> On 24/08/2022 11.40, Bin Meng wrote:
>>> From: Xuzhou Cheng <xuzhou.cheng@windriver.com>
>>>
>>> Socket communication in the libqtest and libqmp codes uses read()
>>> and write() which work on any file descriptor on *nix, and sockets
>>> in *nix are an example of a file descriptor.
>>>
>>> However sockets on Windows do not use *nix-style file descriptors,
>>> so read() and write() cannot be used on sockets on Windows.
>>> Switch over to use send() and recv() instead which work on both
>>> Windows and *nix.
>>>
>>> Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
>>> Signed-off-by: Bin Meng <bin.meng@windriver.com>
>>> ---
>>>
>>>    tests/qtest/libqmp.c   | 4 ++--
>>>    tests/qtest/libqtest.c | 4 ++--
>>>    2 files changed, 4 insertions(+), 4 deletions(-)
>>>
>>> diff --git a/tests/qtest/libqmp.c b/tests/qtest/libqmp.c
>>> index ade26c15f0..995a39c1f8 100644
>>> --- a/tests/qtest/libqmp.c
>>> +++ b/tests/qtest/libqmp.c
>>> @@ -36,7 +36,7 @@ typedef struct {
>>>
>>>    static void socket_send(int fd, const char *buf, size_t size)
>>>    {
>>> -    size_t res = qemu_write_full(fd, buf, size);
>>> +    ssize_t res = send(fd, buf, size, 0);
>>
>> This way we're losing the extra logic from qemu_write_full() here (i.e. the
>> looping and EINTR handling) ... not sure whether that's really OK? Maybe you
>> have to introduce a qemu_send_full() first?
>>
> 
> I am not sure if qemu_send_full() is really needed because there is an
> assert() right after the send() call.

That's just a sanity check ... I think this function still has to take care 
of EINTR - it originally looked like this:

  https://git.qemu.org/?p=qemu.git;a=commitdiff;h=c3e5704af19ac6

... and you can also see the while loop there.

  Thomas




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

* Re: [PATCH 40/51] chardev/char-file: Add FILE_SHARE_WRITE when openning the file for win32
  2022-08-26 13:23       ` Marc-André Lureau
@ 2022-08-27 23:19         ` Bin Meng
  2022-08-30 12:30           ` Marc-André Lureau
  0 siblings, 1 reply; 174+ messages in thread
From: Bin Meng @ 2022-08-27 23:19 UTC (permalink / raw)
  To: Marc-André Lureau
  Cc: qemu-devel@nongnu.org Developers, Xuzhou Cheng, Bin Meng, Paolo Bonzini

On Fri, Aug 26, 2022 at 9:23 PM Marc-André Lureau
<marcandre.lureau@gmail.com> wrote:
>
> Hi
>
> On Fri, Aug 26, 2022 at 5:16 PM Bin Meng <bmeng.cn@gmail.com> wrote:
>>
>> On Thu, Aug 25, 2022 at 3:59 PM Marc-André Lureau
>> <marcandre.lureau@redhat.com> wrote:
>> >
>> > Hi
>> >
>> > On Wed, Aug 24, 2022 at 1:43 PM Bin Meng <bmeng.cn@gmail.com> wrote:
>> > >
>> > > From: Xuzhou Cheng <xuzhou.cheng@windriver.com>
>> > >
>> > > The combination of GENERIC_WRITE and FILE_SHARE_READ options does
>> > > not allow the same file to be opened again by CreateFile() from
>> > > another QEMU process with the same options when the previous QEMU
>> > > process still holds the file handle openned.
>> >
>> > opened
>> >
>> > >
>> > > As per [1] we should add FILE_SHARE_WRITE to the share mode to allow
>> > > such use case. This change makes the behavior be consisten with the
>> > > POSIX platforms.
>> > >
>> >
>> > consistent
>> >
>> > > [1] https://docs.microsoft.com/en-us/windows/win32/fileio/creating-and-opening-files
>> > >
>> > > Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
>> > > Signed-off-by: Bin Meng <bin.meng@windriver.com>
>> > > ---
>> >
>> >
>> > What's the benefit to allow multiple processes write access to the
>> > same file? It seems it could easily lead to corruption or unexpected
>> > results.
>>
>> This was triggered by running the test_multifd_tcp_cancel() case on
>> windows, which cancels the migration, and launches another QEMU
>> process to migrate with the same file opened for write. Chances are
>> that the previous QEMU process does not quit before the new QEMU
>> process runs hence the new one still holds the file handle that does
>> not allow shared write permission then the new QEMU process will fail.
>>
>
> Thanks for the details, that's worth to add in commit message imho.

Sure, I can add this in the commit message.

>
> But can't we fix the test instead to use different paths?
>

Yeah, the test case fix is here:
https://lore.kernel.org/qemu-devel/20220824094029.1634519-42-bmeng.cn@gmail.com/

I think this patch is still needed as it makes the Windows char-file
behavior be consistent with the posix because there is no lock
mechanism in posix.

Regards,
Bin


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

* Re: [PATCH 22/51] tests/qtest: qmp-test: Skip running test_qmp_oob for win32
  2022-08-24  9:40 ` [PATCH 22/51] tests/qtest: qmp-test: Skip running test_qmp_oob for win32 Bin Meng
  2022-08-25 11:45   ` Thomas Huth
@ 2022-08-29 13:14   ` Markus Armbruster
  2022-08-29 14:23     ` Bin Meng
  1 sibling, 1 reply; 174+ messages in thread
From: Markus Armbruster @ 2022-08-29 13:14 UTC (permalink / raw)
  To: Bin Meng; +Cc: qemu-devel, Bin Meng, Laurent Vivier, Paolo Bonzini, Thomas Huth

Bin Meng <bmeng.cn@gmail.com> writes:

> From: Bin Meng <bin.meng@windriver.com>
>
> The test_qmp_oob test case calls mkfifo() which does not exist on
> win32. Exclude it.
>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
>
>  tests/qtest/qmp-test.c | 6 ++++++
>  1 file changed, 6 insertions(+)
>
> diff --git a/tests/qtest/qmp-test.c b/tests/qtest/qmp-test.c
> index b950dbafaf..4a165447f8 100644
> --- a/tests/qtest/qmp-test.c
> +++ b/tests/qtest/qmp-test.c
> @@ -159,6 +159,8 @@ static void test_qmp_protocol(void)
>      qtest_quit(qts);
>  }
>  
> +#ifndef _WIN32
> +
>  /* Out-of-band tests */
>  
>  char *tmpdir;
> @@ -279,6 +281,8 @@ static void test_qmp_oob(void)
>      qtest_quit(qts);
>  }
>  
> +#endif /* _WIN32 */
> +
>  /* Preconfig tests */
>  
>  static void test_qmp_preconfig(void)
> @@ -338,7 +342,9 @@ int main(int argc, char *argv[])
>      g_test_init(&argc, &argv, NULL);
>  
>      qtest_add_func("qmp/protocol", test_qmp_protocol);
> +#ifndef _WIN32
>      qtest_add_func("qmp/oob", test_qmp_oob);
> +#endif
>      qtest_add_func("qmp/preconfig", test_qmp_preconfig);
>      qtest_add_func("qmp/missing-any-arg", test_qmp_missing_any_arg);

I'd appreciate a comment explaining why we have to disable this test on
Windows.



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

* Re: [PATCH 22/51] tests/qtest: qmp-test: Skip running test_qmp_oob for win32
  2022-08-29 13:14   ` Markus Armbruster
@ 2022-08-29 14:23     ` Bin Meng
  2022-08-29 15:06       ` Markus Armbruster
  0 siblings, 1 reply; 174+ messages in thread
From: Bin Meng @ 2022-08-29 14:23 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: qemu-devel@nongnu.org Developers, Bin Meng, Laurent Vivier,
	Paolo Bonzini, Thomas Huth

Hi Markus,

On Mon, Aug 29, 2022 at 9:14 PM Markus Armbruster <armbru@redhat.com> wrote:
>
> Bin Meng <bmeng.cn@gmail.com> writes:
>
> > From: Bin Meng <bin.meng@windriver.com>
> >
> > The test_qmp_oob test case calls mkfifo() which does not exist on
> > win32. Exclude it.
> >
> > Signed-off-by: Bin Meng <bin.meng@windriver.com>
> > ---
> >
> >  tests/qtest/qmp-test.c | 6 ++++++
> >  1 file changed, 6 insertions(+)
> >
> > diff --git a/tests/qtest/qmp-test.c b/tests/qtest/qmp-test.c
> > index b950dbafaf..4a165447f8 100644
> > --- a/tests/qtest/qmp-test.c
> > +++ b/tests/qtest/qmp-test.c
> > @@ -159,6 +159,8 @@ static void test_qmp_protocol(void)
> >      qtest_quit(qts);
> >  }
> >
> > +#ifndef _WIN32
> > +
> >  /* Out-of-band tests */
> >
> >  char *tmpdir;
> > @@ -279,6 +281,8 @@ static void test_qmp_oob(void)
> >      qtest_quit(qts);
> >  }
> >
> > +#endif /* _WIN32 */
> > +
> >  /* Preconfig tests */
> >
> >  static void test_qmp_preconfig(void)
> > @@ -338,7 +342,9 @@ int main(int argc, char *argv[])
> >      g_test_init(&argc, &argv, NULL);
> >
> >      qtest_add_func("qmp/protocol", test_qmp_protocol);
> > +#ifndef _WIN32
> >      qtest_add_func("qmp/oob", test_qmp_oob);
> > +#endif
> >      qtest_add_func("qmp/preconfig", test_qmp_preconfig);
> >      qtest_add_func("qmp/missing-any-arg", test_qmp_missing_any_arg);
>
> I'd appreciate a comment explaining why we have to disable this test on
> Windows.

The reason is explained in the commit message.

Regards,
Bin


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

* Re: [PATCH 22/51] tests/qtest: qmp-test: Skip running test_qmp_oob for win32
  2022-08-29 14:23     ` Bin Meng
@ 2022-08-29 15:06       ` Markus Armbruster
  2022-09-04 14:07         ` Philippe Mathieu-Daudé via
  0 siblings, 1 reply; 174+ messages in thread
From: Markus Armbruster @ 2022-08-29 15:06 UTC (permalink / raw)
  To: Bin Meng
  Cc: qemu-devel@nongnu.org Developers, Bin Meng, Laurent Vivier,
	Paolo Bonzini, Thomas Huth

Bin Meng <bmeng.cn@gmail.com> writes:

> Hi Markus,
>
> On Mon, Aug 29, 2022 at 9:14 PM Markus Armbruster <armbru@redhat.com> wrote:
>>
>> Bin Meng <bmeng.cn@gmail.com> writes:
>>
>> > From: Bin Meng <bin.meng@windriver.com>
>> >
>> > The test_qmp_oob test case calls mkfifo() which does not exist on
>> > win32. Exclude it.
>> >
>> > Signed-off-by: Bin Meng <bin.meng@windriver.com>
>> > ---
>> >
>> >  tests/qtest/qmp-test.c | 6 ++++++
>> >  1 file changed, 6 insertions(+)
>> >
>> > diff --git a/tests/qtest/qmp-test.c b/tests/qtest/qmp-test.c
>> > index b950dbafaf..4a165447f8 100644
>> > --- a/tests/qtest/qmp-test.c
>> > +++ b/tests/qtest/qmp-test.c
>> > @@ -159,6 +159,8 @@ static void test_qmp_protocol(void)
>> >      qtest_quit(qts);
>> >  }
>> >
>> > +#ifndef _WIN32
>> > +
>> >  /* Out-of-band tests */
>> >
>> >  char *tmpdir;
>> > @@ -279,6 +281,8 @@ static void test_qmp_oob(void)
>> >      qtest_quit(qts);
>> >  }
>> >
>> > +#endif /* _WIN32 */
>> > +
>> >  /* Preconfig tests */
>> >
>> >  static void test_qmp_preconfig(void)
>> > @@ -338,7 +342,9 @@ int main(int argc, char *argv[])
>> >      g_test_init(&argc, &argv, NULL);
>> >
>> >      qtest_add_func("qmp/protocol", test_qmp_protocol);
>> > +#ifndef _WIN32
>> >      qtest_add_func("qmp/oob", test_qmp_oob);
>> > +#endif
>> >      qtest_add_func("qmp/preconfig", test_qmp_preconfig);
>> >      qtest_add_func("qmp/missing-any-arg", test_qmp_missing_any_arg);
>>
>> I'd appreciate a comment explaining why we have to disable this test on
>> Windows.
>
> The reason is explained in the commit message.

Yes, and putting it there is a good idea.  But I'd appreciate if you
*also* put it in the code, so future readers of the code don't have to
dig through git history.



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

* Re: [PATCH 40/51] chardev/char-file: Add FILE_SHARE_WRITE when openning the file for win32
  2022-08-27 23:19         ` Bin Meng
@ 2022-08-30 12:30           ` Marc-André Lureau
  0 siblings, 0 replies; 174+ messages in thread
From: Marc-André Lureau @ 2022-08-30 12:30 UTC (permalink / raw)
  To: Bin Meng
  Cc: qemu-devel@nongnu.org Developers, Xuzhou Cheng, Bin Meng, Paolo Bonzini

[-- Attachment #1: Type: text/plain, Size: 2663 bytes --]

Hi

On Sun, Aug 28, 2022 at 3:19 AM Bin Meng <bmeng.cn@gmail.com> wrote:

> On Fri, Aug 26, 2022 at 9:23 PM Marc-André Lureau
> <marcandre.lureau@gmail.com> wrote:
> >
> > Hi
> >
> > On Fri, Aug 26, 2022 at 5:16 PM Bin Meng <bmeng.cn@gmail.com> wrote:
> >>
> >> On Thu, Aug 25, 2022 at 3:59 PM Marc-André Lureau
> >> <marcandre.lureau@redhat.com> wrote:
> >> >
> >> > Hi
> >> >
> >> > On Wed, Aug 24, 2022 at 1:43 PM Bin Meng <bmeng.cn@gmail.com> wrote:
> >> > >
> >> > > From: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> >> > >
> >> > > The combination of GENERIC_WRITE and FILE_SHARE_READ options does
> >> > > not allow the same file to be opened again by CreateFile() from
> >> > > another QEMU process with the same options when the previous QEMU
> >> > > process still holds the file handle openned.
> >> >
> >> > opened
> >> >
> >> > >
> >> > > As per [1] we should add FILE_SHARE_WRITE to the share mode to allow
> >> > > such use case. This change makes the behavior be consisten with the
> >> > > POSIX platforms.
> >> > >
> >> >
> >> > consistent
> >> >
> >> > > [1]
> https://docs.microsoft.com/en-us/windows/win32/fileio/creating-and-opening-files
> >> > >
> >> > > Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> >> > > Signed-off-by: Bin Meng <bin.meng@windriver.com>
> >> > > ---
> >> >
> >> >
> >> > What's the benefit to allow multiple processes write access to the
> >> > same file? It seems it could easily lead to corruption or unexpected
> >> > results.
> >>
> >> This was triggered by running the test_multifd_tcp_cancel() case on
> >> windows, which cancels the migration, and launches another QEMU
> >> process to migrate with the same file opened for write. Chances are
> >> that the previous QEMU process does not quit before the new QEMU
> >> process runs hence the new one still holds the file handle that does
> >> not allow shared write permission then the new QEMU process will fail.
> >>
> >
> > Thanks for the details, that's worth to add in commit message imho.
>
> Sure, I can add this in the commit message.
>
> >
> > But can't we fix the test instead to use different paths?
> >
>
> Yeah, the test case fix is here:
>
> https://lore.kernel.org/qemu-devel/20220824094029.1634519-42-bmeng.cn@gmail.com/
>
> I think this patch is still needed as it makes the Windows char-file
> behavior be consistent with the posix because there is no lock
> mechanism in posix.
>

In this case, I would rather make posix consistent with the windows
behaviour :)

I am not sure how to proceed from there, but I would discard your windows
patch for now.

[-- Attachment #2: Type: text/html, Size: 4304 bytes --]

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

* Re: [PATCH 03/51] block: Unify the get_tmp_filename() implementation
  2022-08-24  9:39 ` [PATCH 03/51] block: Unify the get_tmp_filename() implementation Bin Meng
@ 2022-08-31 12:54   ` Marc-André Lureau
  2022-08-31 13:19     ` Daniel P. Berrangé
  2022-09-01  6:41     ` Bin Meng
  0 siblings, 2 replies; 174+ messages in thread
From: Marc-André Lureau @ 2022-08-31 12:54 UTC (permalink / raw)
  To: Bin Meng; +Cc: qemu-devel, Bin Meng, Hanna Reitz, Kevin Wolf, qemu-block

[-- Attachment #1: Type: text/plain, Size: 1866 bytes --]

Hi Bin

On Wed, Aug 24, 2022 at 1:42 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Bin Meng <bin.meng@windriver.com>
>
> At present get_tmp_filename() has platform specific implementations
> to get the directory to use for temporary files. Switch over to use
> g_get_tmp_dir() which works on all supported platforms.
>
>
It "works" quite differently though. Is this patch really necessary here?

If yes, please explain why.

If not, I suggest you drop optional / rfc / "nice to have" patches from the
series. It will help to get it merged faster.

thanks



> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
>
>  block.c | 16 ++--------------
>  1 file changed, 2 insertions(+), 14 deletions(-)
>
> diff --git a/block.c b/block.c
> index bc85f46eed..d06df47f72 100644
> --- a/block.c
> +++ b/block.c
> @@ -864,21 +864,10 @@ int bdrv_probe_geometry(BlockDriverState *bs,
> HDGeometry *geo)
>   */
>  int get_tmp_filename(char *filename, int size)
>  {
> -#ifdef _WIN32
> -    char temp_dir[MAX_PATH];
> -    /* GetTempFileName requires that its output buffer (4th param)
> -       have length MAX_PATH or greater.  */
> -    assert(size >= MAX_PATH);
> -    return (GetTempPath(MAX_PATH, temp_dir)
> -            && GetTempFileName(temp_dir, "qem", 0, filename)
> -            ? 0 : -GetLastError());
> -#else
>      int fd;
>      const char *tmpdir;
> -    tmpdir = getenv("TMPDIR");
> -    if (!tmpdir) {
> -        tmpdir = "/var/tmp";
> -    }
> +    tmpdir = g_get_tmp_dir();
> +
>      if (snprintf(filename, size, "%s/vl.XXXXXX", tmpdir) >= size) {
>          return -EOVERFLOW;
>      }
> @@ -891,7 +880,6 @@ int get_tmp_filename(char *filename, int size)
>          return -errno;
>      }
>      return 0;
> -#endif
>  }
>
>  /*
> --
> 2.34.1
>
>
>

-- 
Marc-André Lureau

[-- Attachment #2: Type: text/html, Size: 2867 bytes --]

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

* Re: [PATCH 04/51] semihosting/arm-compat-semi: Avoid using hardcoded /tmp
  2022-08-24  9:39 ` [PATCH 04/51] semihosting/arm-compat-semi: Avoid using hardcoded /tmp Bin Meng
@ 2022-08-31 12:59   ` Marc-André Lureau
  2022-09-01  7:11     ` Bin Meng
  0 siblings, 1 reply; 174+ messages in thread
From: Marc-André Lureau @ 2022-08-31 12:59 UTC (permalink / raw)
  To: Bin Meng; +Cc: qemu-devel, Bin Meng, Alex Bennée

[-- Attachment #1: Type: text/plain, Size: 1193 bytes --]

Hi

On Wed, Aug 24, 2022 at 1:54 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Bin Meng <bin.meng@windriver.com>
>
> Use g_get_tmp_dir() to get the directory to use for temporary files.
>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
>
>  semihosting/arm-compat-semi.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c
> index e741674238..d5e66cc298 100644
> --- a/semihosting/arm-compat-semi.c
> +++ b/semihosting/arm-compat-semi.c
> @@ -503,7 +503,8 @@ void do_common_semihosting(CPUState *cs)
>          GET_ARG(0);
>          GET_ARG(1);
>          GET_ARG(2);
> -        len = asprintf(&s, "/tmp/qemu-%x%02x", getpid(), (int)arg1 &
> 0xff);
> +        len = asprintf(&s, "%s/qemu-%x%02x", g_get_tmp_dir(),
> +                       getpid(), (int)arg1 & 0xff);
>

This is most likely wrong. I am not familiar with semihosting, but I
believe we are implementing tmpnam(), it should return a POSIX filename.


>          if (len < 0) {
>              common_semi_set_ret(cs, -1);
>              break;
> --
> 2.34.1
>
>
>

-- 
Marc-André Lureau

[-- Attachment #2: Type: text/html, Size: 2012 bytes --]

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

* Re: [PATCH 05/51] tcg: Avoid using hardcoded /tmp
  2022-08-24  9:39 ` [PATCH 05/51] tcg: " Bin Meng
@ 2022-08-31 13:02   ` Marc-André Lureau
  0 siblings, 0 replies; 174+ messages in thread
From: Marc-André Lureau @ 2022-08-31 13:02 UTC (permalink / raw)
  To: Bin Meng; +Cc: qemu-devel, Bin Meng, Richard Henderson

[-- Attachment #1: Type: text/plain, Size: 1416 bytes --]

Hi

On Wed, Aug 24, 2022 at 2:06 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Bin Meng <bin.meng@windriver.com>
>
> Use g_get_tmp_dir() to get the directory to use for temporary files.
>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
>
>  tcg/tcg.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/tcg/tcg.c b/tcg/tcg.c
> index 0f9cfe96f2..932156a352 100644
> --- a/tcg/tcg.c
> +++ b/tcg/tcg.c
> @@ -4729,13 +4729,15 @@ static void tcg_register_jit_int(const void
> *buf_ptr, size_t buf_size,
>      /* Enable this block to be able to debug the ELF image file creation.
>         One can use readelf, objdump, or other inspection utilities.  */
>      {
> -        FILE *f = fopen("/tmp/qemu.jit", "w+b");
> +        char *jit = g_strdup_printf("%s/qemu.jit", g_get_tmp_dir());
> +        FILE *f = fopen(jit, "w+b");
>

(this is only enabled if DEBUG_JIT)

Why not? you may also use g_autofree to avoid the call to g_free() below if
you respin.

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



>          if (f) {
>              if (fwrite(img, img_size, 1, f) != img_size) {
>                  /* Avoid stupid unused return value warning for fwrite.
> */
>              }
>              fclose(f);
>          }
> +        g_free(jit);
>      }
>  #endif
>
> --
> 2.34.1
>
>
>

-- 
Marc-André Lureau

[-- Attachment #2: Type: text/html, Size: 2379 bytes --]

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

* Re: [PATCH 06/51] util/qemu-sockets: Use g_get_tmp_dir() to get the directory for temporary files
  2022-08-24  9:39 ` [PATCH 06/51] util/qemu-sockets: Use g_get_tmp_dir() to get the directory for temporary files Bin Meng
@ 2022-08-31 13:05   ` Marc-André Lureau
  0 siblings, 0 replies; 174+ messages in thread
From: Marc-André Lureau @ 2022-08-31 13:05 UTC (permalink / raw)
  To: Bin Meng; +Cc: qemu-devel, Bin Meng, Daniel P. Berrangé

[-- Attachment #1: Type: text/plain, Size: 1229 bytes --]

Hi

On Wed, Aug 24, 2022 at 1:59 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Bin Meng <bin.meng@windriver.com>
>
> Replace the existing logic to get the directory for temporary files
> with g_get_tmp_dir(), which works for win32 too.
>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
>

Makes sense to me here,
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>


> ---
>
>  util/qemu-sockets.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c
> index 83f4bd6fd2..0c41ca9e42 100644
> --- a/util/qemu-sockets.c
> +++ b/util/qemu-sockets.c
> @@ -919,9 +919,8 @@ static int unix_listen_saddr(UnixSocketAddress *saddr,
>      if (saddr->path[0] || abstract) {
>          path = saddr->path;
>      } else {
> -        const char *tmpdir = getenv("TMPDIR");
> -        tmpdir = tmpdir ? tmpdir : "/tmp";
> -        path = pathbuf = g_strdup_printf("%s/qemu-socket-XXXXXX", tmpdir);
> +        path = pathbuf = g_strdup_printf("%s/qemu-socket-XXXXXX",
> +                                         g_get_tmp_dir());
>      }
>
>      pathlen = strlen(path);
> --
> 2.34.1
>
>
>

-- 
Marc-André Lureau

[-- Attachment #2: Type: text/html, Size: 2126 bytes --]

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

* Re: [PATCH 08/51] block/vvfat: Unify the mkdir() call
  2022-08-24  9:39 ` [PATCH 08/51] block/vvfat: Unify the mkdir() call Bin Meng
@ 2022-08-31 13:08   ` Marc-André Lureau
  0 siblings, 0 replies; 174+ messages in thread
From: Marc-André Lureau @ 2022-08-31 13:08 UTC (permalink / raw)
  To: Bin Meng; +Cc: qemu-devel, Bin Meng, Hanna Reitz, Kevin Wolf, qemu-block

[-- Attachment #1: Type: text/plain, Size: 1401 bytes --]

Hi

On Wed, Aug 24, 2022 at 2:20 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Bin Meng <bin.meng@windriver.com>
>
> There is a difference in the mkdir() call for win32 and non-win32
> platforms, and currently is handled in the codes with #ifdefs.
>
> glib provides a portable g_mkdir_with_parents() API and we can use
> it to unify the codes without #ifdefs.
>

Why use the _with_parents() version?

You should replace with g_mkdir(), or explain the reasons.

thanks


>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
>
>  block/vvfat.c | 8 ++------
>  1 file changed, 2 insertions(+), 6 deletions(-)
>
> diff --git a/block/vvfat.c b/block/vvfat.c
> index d6dd919683..9c389ce5ea 100644
> --- a/block/vvfat.c
> +++ b/block/vvfat.c
> @@ -2726,13 +2726,9 @@ static int
> handle_renames_and_mkdirs(BDRVVVFATState* s)
>              mapping_t* mapping;
>              int j, parent_path_len;
>
> -#ifdef __MINGW32__
> -            if (mkdir(commit->path))
> +            if (g_mkdir_with_parents(commit->path, 0755)) {
>                  return -5;
> -#else
> -            if (mkdir(commit->path, 0755))
> -                return -5;
> -#endif
> +            }
>
>              mapping = insert_mapping(s, commit->param.mkdir.cluster,
>                      commit->param.mkdir.cluster + 1);
> --
> 2.34.1
>
>
>

-- 
Marc-André Lureau

[-- Attachment #2: Type: text/html, Size: 2284 bytes --]

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

* Re: [PATCH 10/51] hw/usb: dev-mtp: Use g_mkdir_with_parents()
  2022-08-24  9:39 ` [PATCH 10/51] hw/usb: dev-mtp: " Bin Meng
@ 2022-08-31 13:09   ` Marc-André Lureau
  0 siblings, 0 replies; 174+ messages in thread
From: Marc-André Lureau @ 2022-08-31 13:09 UTC (permalink / raw)
  To: Bin Meng; +Cc: qemu-devel, Bin Meng, Gerd Hoffmann

[-- Attachment #1: Type: text/plain, Size: 1160 bytes --]

On Wed, Aug 24, 2022 at 1:48 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Bin Meng <bin.meng@windriver.com>
>
> Use the same g_mkdir_with_parents() call to create a directory on
> all platforms.
>
>
Same comment as earlier regarding g_mkdir() vs _with_parent().


> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
>
>  hw/usb/dev-mtp.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/hw/usb/dev-mtp.c b/hw/usb/dev-mtp.c
> index 5831395cef..97c894f231 100644
> --- a/hw/usb/dev-mtp.c
> +++ b/hw/usb/dev-mtp.c
> @@ -1622,7 +1622,7 @@ static void usb_mtp_write_data(MTPState *s, uint32_t
> handle)
>          if (s->dataset.filename) {
>              path = g_strdup_printf("%s/%s", parent->path,
> s->dataset.filename);
>              if (s->dataset.format == FMT_ASSOCIATION) {
> -                ret = mkdir(path, mask);
> +                ret = g_mkdir_with_parents(path, mask);
>                  if (!ret) {
>                      usb_mtp_queue_result(s, RES_OK, d->trans, 3,
>                                           QEMU_STORAGE_ID,
> --
> 2.34.1
>
>
>

-- 
Marc-André Lureau

[-- Attachment #2: Type: text/html, Size: 1987 bytes --]

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

* Re: [PATCH 03/51] block: Unify the get_tmp_filename() implementation
  2022-08-31 12:54   ` Marc-André Lureau
@ 2022-08-31 13:19     ` Daniel P. Berrangé
  2022-09-01  6:41     ` Bin Meng
  1 sibling, 0 replies; 174+ messages in thread
From: Daniel P. Berrangé @ 2022-08-31 13:19 UTC (permalink / raw)
  To: Marc-André Lureau
  Cc: Bin Meng, qemu-devel, Bin Meng, Hanna Reitz, Kevin Wolf, qemu-block

On Wed, Aug 31, 2022 at 04:54:41PM +0400, Marc-André Lureau wrote:
> Hi Bin
> 
> On Wed, Aug 24, 2022 at 1:42 PM Bin Meng <bmeng.cn@gmail.com> wrote:
> 
> > From: Bin Meng <bin.meng@windriver.com>
> >
> > At present get_tmp_filename() has platform specific implementations
> > to get the directory to use for temporary files. Switch over to use
> > g_get_tmp_dir() which works on all supported platforms.
> >
> >
> It "works" quite differently though. Is this patch really necessary here?
> 
> If yes, please explain why.
> 
> If not, I suggest you drop optional / rfc / "nice to have" patches from the
> series. It will help to get it merged faster.
> 
> thanks
> 
> 
> 
> > Signed-off-by: Bin Meng <bin.meng@windriver.com>
> > ---
> >
> >  block.c | 16 ++--------------
> >  1 file changed, 2 insertions(+), 14 deletions(-)
> >
> > diff --git a/block.c b/block.c
> > index bc85f46eed..d06df47f72 100644
> > --- a/block.c
> > +++ b/block.c
> > @@ -864,21 +864,10 @@ int bdrv_probe_geometry(BlockDriverState *bs,
> > HDGeometry *geo)
> >   */
> >  int get_tmp_filename(char *filename, int size)
> >  {
> > -#ifdef _WIN32
> > -    char temp_dir[MAX_PATH];
> > -    /* GetTempFileName requires that its output buffer (4th param)
> > -       have length MAX_PATH or greater.  */
> > -    assert(size >= MAX_PATH);
> > -    return (GetTempPath(MAX_PATH, temp_dir)
> > -            && GetTempFileName(temp_dir, "qem", 0, filename)
> > -            ? 0 : -GetLastError());
> > -#else
> >      int fd;
> >      const char *tmpdir;
> > -    tmpdir = getenv("TMPDIR");
> > -    if (!tmpdir) {
> > -        tmpdir = "/var/tmp";
> > -    }
> > +    tmpdir = g_get_tmp_dir();
> > +
> >      if (snprintf(filename, size, "%s/vl.XXXXXX", tmpdir) >= size) {
> >          return -EOVERFLOW;
> >      }

I know this is pre-existing, but this use of snprintf is really
undesirable and should be culled while we're touching this code.

There are only two callers of get_tmp_filename and they're
inconsistent too

One does

    /* TODO: extra byte is a hack to ensure MAX_PATH space on Windows. */
    char *tmp_filename = g_malloc0(PATH_MAX + 1);
    ...
    ret = get_tmp_filename(tmp_filename, PATH_MAX + 1);

while the other does

    s->qcow_filename = g_malloc(PATH_MAX);
    ret = get_tmp_filename(s->qcow_filename, PATH_MAX);

either the comment is wrong and adding "+1" to PATH_MAX is not
required, or the second caller is wrong on Windows. This may even
be totally irrelevant with the switch to g_get_tmp_dir. Whatever
the answer is, at least 1 of the callers needs updating.

It would be way better if the method signature was

  char *get_tmp_filename(void);

and we uses g_strdup_printf() instead of snprintf so the corret
size is allocated right away, removing the question about whether
we need PATH_MAX or PATH_MAX + 1 entirely.

With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|



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

* Re: [PATCH 14/51] backends/tpm: Exclude headers and macros that don't exist on win32
  2022-08-24 12:35   ` Stefan Berger
@ 2022-08-31 13:20     ` Marc-André Lureau
  0 siblings, 0 replies; 174+ messages in thread
From: Marc-André Lureau @ 2022-08-31 13:20 UTC (permalink / raw)
  To: Stefan Berger; +Cc: Bin Meng, qemu-devel, Bin Meng, Stefan Berger

[-- Attachment #1: Type: text/plain, Size: 1674 bytes --]

Hi

On Wed, Aug 24, 2022 at 5:26 PM Stefan Berger <stefanb@linux.ibm.com> wrote:

>
>
> On 8/24/22 05:39, Bin Meng wrote:
> > From: Bin Meng <bin.meng@windriver.com>
> >
> > These headers and macros do not exist on Windows. Exclude them.
> >
> > Signed-off-by: Bin Meng <bin.meng@windriver.com>
> > ---
> >
> >   backends/tpm/tpm_ioctl.h | 4 ++++
> >   1 file changed, 4 insertions(+)
> >
> > diff --git a/backends/tpm/tpm_ioctl.h b/backends/tpm/tpm_ioctl.h
> > index bd6c12cb86..d67bf0283b 100644
> > --- a/backends/tpm/tpm_ioctl.h
> > +++ b/backends/tpm/tpm_ioctl.h
> > @@ -9,8 +9,10 @@
> >   #ifndef TPM_IOCTL_H
> >   #define TPM_IOCTL_H
> >
> > +#ifndef _WIN32
> >   #include <sys/uio.h>
> >   #include <sys/ioctl.h>
> > +#endif
> >
> >   #ifdef HAVE_SYS_IOCCOM_H
> >   #include <sys/ioccom.h>
> > @@ -222,6 +224,7 @@ typedef struct ptm_setbuffersize ptm_setbuffersize;
> >   #define PTM_CAP_SET_DATAFD         (1 << 12)
> >   #define PTM_CAP_SET_BUFFERSIZE     (1 << 13)
> >
> > +#ifndef _WIN32
> >   enum {
> >       PTM_GET_CAPABILITY     = _IOR('P', 0, ptm_cap),
> >       PTM_INIT               = _IOWR('P', 1, ptm_init),
> > @@ -241,6 +244,7 @@ enum {
> >       PTM_SET_DATAFD         = _IOR('P', 15, ptm_res),
> >       PTM_SET_BUFFERSIZE     = _IOWR('P', 16, ptm_setbuffersize),
> >   };
> > +#endif
> >
> >   /*
> >    * Commands used by the non-CUSE TPMs
>
> Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
>
>
I guess it would be worthy to make libtpms/swtpm work under windows too,
but this is a larger goal.

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

-- 
Marc-André Lureau

[-- Attachment #2: Type: text/html, Size: 2687 bytes --]

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

* Re: [PATCH 17/51] tests/qtest: Build virtio-net-test for posix only
  2022-08-24  9:39 ` [PATCH 17/51] tests/qtest: Build virtio-net-test " Bin Meng
  2022-08-25 11:27   ` Thomas Huth
@ 2022-08-31 13:25   ` Marc-André Lureau
  1 sibling, 0 replies; 174+ messages in thread
From: Marc-André Lureau @ 2022-08-31 13:25 UTC (permalink / raw)
  To: Bin Meng
  Cc: qemu-devel, Bin Meng, Jason Wang, Laurent Vivier, Paolo Bonzini,
	Thomas Huth

[-- Attachment #1: Type: text/plain, Size: 2763 bytes --]

Hi

On Wed, Aug 24, 2022 at 2:24 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Bin Meng <bin.meng@windriver.com>
>
> All of the virtio-net-test test cases require socketpair() to do the
> test setup.
>

It is possible to implement a pretty good alternative, like I did for glib (
https://gitlab.gnome.org/GNOME/glib/-/blob/main/gio/tests/socket.c#L2193)

I intend to add that in another series (based on yours), we can enable more
tests later.


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

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


> ---
>
>  tests/qtest/virtio-net-test.c | 6 ------
>  tests/qtest/meson.build       | 3 +--
>  2 files changed, 1 insertion(+), 8 deletions(-)
>
> diff --git a/tests/qtest/virtio-net-test.c b/tests/qtest/virtio-net-test.c
> index 6ded252901..d44c3d9666 100644
> --- a/tests/qtest/virtio-net-test.c
> +++ b/tests/qtest/virtio-net-test.c
> @@ -26,8 +26,6 @@
>  #define QVIRTIO_NET_TIMEOUT_US (30 * 1000 * 1000)
>  #define VNET_HDR_SIZE sizeof(struct virtio_net_hdr_mrg_rxbuf)
>
> -#ifndef _WIN32
> -
>  static void rx_test(QVirtioDevice *dev,
>                      QGuestAllocator *alloc, QVirtQueue *vq,
>                      int socket)
> @@ -165,8 +163,6 @@ static void stop_cont_test(void *obj, void *data,
> QGuestAllocator *t_alloc)
>      rx_stop_cont_test(dev, t_alloc, rx, sv[0]);
>  }
>
> -#endif
> -
>  static void hotplug(void *obj, void *data, QGuestAllocator *t_alloc)
>  {
>      QVirtioPCIDevice *dev = obj;
> @@ -324,10 +320,8 @@ static void register_virtio_net_test(void)
>      };
>
>      qos_add_test("hotplug", "virtio-net-pci", hotplug, &opts);
> -#ifndef _WIN32
>      qos_add_test("basic", "virtio-net", send_recv_test, &opts);
>      qos_add_test("rx_stop_cont", "virtio-net", stop_cont_test, &opts);
> -#endif
>      qos_add_test("announce-self", "virtio-net", announce_self, &opts);
>
>      /* These tests do not need a loopback backend.  */
> diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
> index 9d0f82bf1c..72bb9e21f3 100644
> --- a/tests/qtest/meson.build
> +++ b/tests/qtest/meson.build
> @@ -259,7 +259,6 @@ qos_test_ss.add(
>    'usb-hcd-ohci-test.c',
>    'virtio-test.c',
>    'virtio-blk-test.c',
> -  'virtio-net-test.c',
>    'virtio-rng-test.c',
>    'virtio-scsi-test.c',
>    'virtio-serial-test.c',
> @@ -267,7 +266,7 @@ qos_test_ss.add(
>    'vmxnet3-test.c',
>  )
>  if config_host.has_key('CONFIG_POSIX')
> -  qos_test_ss.add(files('e1000e-test.c'))
> +  qos_test_ss.add(files('e1000e-test.c', 'virtio-net-test.c'))
>  endif
>  if have_virtfs
>    qos_test_ss.add(files('virtio-9p-test.c'))
> --
> 2.34.1
>
>
>

-- 
Marc-André Lureau

[-- Attachment #2: Type: text/html, Size: 4183 bytes --]

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

* Re: [PATCH 19/51] tests/qtest: Build test-filter-{mirror, redirector} cases for posix only
  2022-08-24  9:39 ` [PATCH 19/51] tests/qtest: Build test-filter-{mirror, redirector} cases " Bin Meng
  2022-08-25 11:37   ` Thomas Huth
@ 2022-08-31 13:27   ` Marc-André Lureau
  1 sibling, 0 replies; 174+ messages in thread
From: Marc-André Lureau @ 2022-08-31 13:27 UTC (permalink / raw)
  To: Bin Meng; +Cc: qemu-devel, Bin Meng, Laurent Vivier, Paolo Bonzini, Thomas Huth

[-- Attachment #1: Type: text/plain, Size: 5535 bytes --]

On Wed, Aug 24, 2022 at 2:10 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Bin Meng <bin.meng@windriver.com>
>
> The test-filter-{mirror,redirector} cases use socketpair() API that
> is only available on POSIX and should only be built for POSIX.
>

It is possible to implement a pretty good alternative, like I did for glib (
https://gitlab.gnome.org/GNOME/glib/-/blob/main/gio/tests/socket.c#L2193)

I intend to add that in another series (based on yours), we can enable more
tests later.



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

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


> ---
>
>  tests/qtest/meson.build | 28 ++++++++++++++++++----------
>  1 file changed, 18 insertions(+), 10 deletions(-)
>
> diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
> index 9e484e60ba..c97da5a062 100644
> --- a/tests/qtest/meson.build
> +++ b/tests/qtest/meson.build
> @@ -42,6 +42,7 @@ qtests_cxl = \
>  qtests_i386 = \
>    (slirp.found() ? ['pxe-test', 'test-netfilter'] : []) +             \
>    (config_host.has_key('CONFIG_POSIX') ? ['test-filter-mirror'] : []) +
>                    \
> +  (config_host.has_key('CONFIG_POSIX') ? ['test-filter-redirector'] : [])
> +                 \
>    (have_tools ? ['ahci-test'] : []) +
>                    \
>    (config_all_devices.has_key('CONFIG_ISA_TESTDEV') ? ['endianness-test']
> : []) +           \
>    (config_all_devices.has_key('CONFIG_SGA') ? ['boot-serial-test'] : [])
> +                  \
> @@ -95,8 +96,7 @@ qtests_i386 = \
>     'vmgenid-test',
>     'migration-test',
>     'test-x86-cpuid-compat',
> -   'numa-test',
> -   'test-filter-redirector'
> +   'numa-test'
>    ]
>
>  if dbus_display
> @@ -120,29 +120,34 @@ endif
>  qtests_x86_64 = qtests_i386
>
>  qtests_alpha = ['boot-serial-test'] + \
> -  ['test-filter-mirror', 'test-filter-redirector'] + \
> +  (config_host.has_key('CONFIG_POSIX') ? ['test-filter-mirror'] : []) +
>    \
> +  (config_host.has_key('CONFIG_POSIX') ? ['test-filter-redirector'] : [])
> + \
>    (slirp.found() ? ['test-netfilter'] : []) + \
>    (config_all_devices.has_key('CONFIG_VGA') ? ['display-vga-test'] : [])
>
>  qtests_avr = [ 'boot-serial-test' ]
>
>  qtests_hppa = ['boot-serial-test'] + \
> -  ['test-filter-mirror', 'test-filter-redirector'] + \
> +  (config_host.has_key('CONFIG_POSIX') ? ['test-filter-mirror'] : []) +
>    \
> +  (config_host.has_key('CONFIG_POSIX') ? ['test-filter-redirector'] : [])
> + \
>    (slirp.found() ? ['test-netfilter'] : []) + \
>    (config_all_devices.has_key('CONFIG_VGA') ? ['display-vga-test'] : [])
>
>  qtests_m68k = ['boot-serial-test'] + \
> -  ['test-filter-mirror', 'test-filter-redirector'] + \
> +  (config_host.has_key('CONFIG_POSIX') ? ['test-filter-mirror'] : []) +
>    \
> +  (config_host.has_key('CONFIG_POSIX') ? ['test-filter-redirector'] : [])
> + \
>    (slirp.found() ? ['test-netfilter'] : [])
>
>  qtests_microblaze = ['boot-serial-test'] + \
> -  ['test-filter-mirror', 'test-filter-redirector'] + \
> +  (config_host.has_key('CONFIG_POSIX') ? ['test-filter-mirror'] : []) +
>    \
> +  (config_host.has_key('CONFIG_POSIX') ? ['test-filter-redirector'] : [])
> + \
>    (slirp.found() ? ['test-netfilter'] : [])
>
>  qtests_microblazeel = qtests_microblaze
>
>  qtests_mips = \
> -  ['test-filter-mirror', 'test-filter-redirector'] + \
> +  (config_host.has_key('CONFIG_POSIX') ? ['test-filter-mirror'] : []) +
>    \
> +  (config_host.has_key('CONFIG_POSIX') ? ['test-filter-redirector'] : [])
> + \
>    (slirp.found() ? ['test-netfilter'] : []) + \
>    (config_all_devices.has_key('CONFIG_ISA_TESTDEV') ? ['endianness-test']
> : []) +            \
>    (config_all_devices.has_key('CONFIG_VGA') ? ['display-vga-test'] : [])
> @@ -152,7 +157,8 @@ qtests_mips64 = qtests_mips
>  qtests_mips64el = qtests_mips
>
>  qtests_ppc = \
> -  ['test-filter-mirror', 'test-filter-redirector'] + \
> +  (config_host.has_key('CONFIG_POSIX') ? ['test-filter-mirror'] : []) +
>    \
> +  (config_host.has_key('CONFIG_POSIX') ? ['test-filter-redirector'] : [])
> + \
>    (slirp.found() ? ['test-netfilter'] : []) + \
>    (config_all_devices.has_key('CONFIG_ISA_TESTDEV') ? ['endianness-test']
> : []) +            \
>    (config_all_devices.has_key('CONFIG_M48T59') ? ['m48t59-test'] : []) +
>                    \
> @@ -174,13 +180,15 @@ qtests_sh4 =
> (config_all_devices.has_key('CONFIG_ISA_TESTDEV') ? ['endianness-te
>  qtests_sh4eb = (config_all_devices.has_key('CONFIG_ISA_TESTDEV') ?
> ['endianness-test'] : [])
>
>  qtests_sparc = ['prom-env-test', 'm48t59-test', 'boot-serial-test'] + \
> -  ['test-filter-mirror', 'test-filter-redirector'] + \
> +  (config_host.has_key('CONFIG_POSIX') ? ['test-filter-mirror'] : []) +
>    \
> +  (config_host.has_key('CONFIG_POSIX') ? ['test-filter-redirector'] : [])
> + \
>    (slirp.found() ? ['test-netfilter'] : [])
>
>  qtests_sparc64 = \
>    (config_all_devices.has_key('CONFIG_ISA_TESTDEV') ? ['endianness-test']
> : []) +            \
>    (slirp.found() ? ['test-netfilter'] : []) + \
> -  ['test-filter-mirror', 'test-filter-redirector'] + \
> +  (config_host.has_key('CONFIG_POSIX') ? ['test-filter-mirror'] : []) +
>    \
> +  (config_host.has_key('CONFIG_POSIX') ? ['test-filter-redirector'] : [])
> + \
>    ['prom-env-test', 'boot-serial-test']
>
>  qtests_npcm7xx = \
> --
> 2.34.1
>
>
>

-- 
Marc-André Lureau

[-- Attachment #2: Type: text/html, Size: 7771 bytes --]

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

* Re: [PATCH 20/51] tests/qtest: i440fx-test: Skip running request_{bios, pflash} for win32
  2022-08-24  9:39 ` [PATCH 20/51] tests/qtest: i440fx-test: Skip running request_{bios, pflash} for win32 Bin Meng
  2022-08-25 11:40   ` [PATCH 20/51] tests/qtest: i440fx-test: Skip running request_{bios,pflash} " Thomas Huth
@ 2022-08-31 13:40   ` Marc-André Lureau
  2022-09-02  8:29     ` Bin Meng
  1 sibling, 1 reply; 174+ messages in thread
From: Marc-André Lureau @ 2022-08-31 13:40 UTC (permalink / raw)
  To: Bin Meng; +Cc: qemu-devel, Bin Meng, Laurent Vivier, Paolo Bonzini, Thomas Huth

[-- Attachment #1: Type: text/plain, Size: 2025 bytes --]

Hi

On Wed, Aug 24, 2022 at 2:15 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Bin Meng <bin.meng@windriver.com>
>
> The request_{bios,pflash} test cases call mmap() which does not
> exist on win32. Exclude them.
>
>
We can fairly easily rewrite the create_blob_file() function to be portable
though, something like:

static char *create_blob_file(void)
{
    g_autofree uint8_t *buf = g_malloc(BLOB_SIZE);
    GError *error = NULL;
    char *pathname;
    int fd;
    size_t i;

    fd = g_file_open_tmp("blob_XXXXXX", &pathname, &error);
    g_assert_no_error(error);

    for (i = 0; i < BLOB_SIZE; ++i) {
        buf[i] = i;
    }

    g_file_set_contents(pathname, (char *)buf, BLOB_SIZE, &error);
    g_assert_no_error(error);
    close(fd);

    return pathname;
}

Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
>
>  tests/qtest/i440fx-test.c | 6 ++++++
>  1 file changed, 6 insertions(+)
>
> diff --git a/tests/qtest/i440fx-test.c b/tests/qtest/i440fx-test.c
> index 6d7d4d8d8f..3890f1237c 100644
> --- a/tests/qtest/i440fx-test.c
> +++ b/tests/qtest/i440fx-test.c
> @@ -278,6 +278,8 @@ static void test_i440fx_pam(gconstpointer opaque)
>      qtest_end();
>  }
>
> +#ifndef _WIN32
> +
>  #define BLOB_SIZE ((size_t)65536)
>  #define ISA_BIOS_MAXSZ ((size_t)(128 * 1024))
>
> @@ -396,6 +398,8 @@ static void request_pflash(FirmwareTestFixture
> *fixture,
>      fixture->is_bios = false;
>  }
>
> +#endif /* _WIN32 */
> +
>  int main(int argc, char **argv)
>  {
>      TestData data;
> @@ -406,8 +410,10 @@ int main(int argc, char **argv)
>
>      qtest_add_data_func("i440fx/defaults", &data, test_i440fx_defaults);
>      qtest_add_data_func("i440fx/pam", &data, test_i440fx_pam);
> +#ifndef _WIN32
>      add_firmware_test("i440fx/firmware/bios", request_bios);
>      add_firmware_test("i440fx/firmware/pflash", request_pflash);
> +#endif
>
>      return g_test_run();
>  }
> --
> 2.34.1
>
>
>

-- 
Marc-André Lureau

[-- Attachment #2: Type: text/html, Size: 2995 bytes --]

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

* Re: [PATCH 23/51] accel/qtest: Support qtest accelerator for Windows
  2022-08-24  9:40 ` [PATCH 23/51] accel/qtest: Support qtest accelerator for Windows Bin Meng
@ 2022-08-31 13:49   ` Marc-André Lureau
  2022-09-02  8:28     ` Bin Meng
  0 siblings, 1 reply; 174+ messages in thread
From: Marc-André Lureau @ 2022-08-31 13:49 UTC (permalink / raw)
  To: Bin Meng, Richard Henderson, Paolo Bonzini
  Cc: qemu-devel, Xuzhou Cheng, Bin Meng, Eduardo Habkost,
	Laurent Vivier, Marcel Apfelbaum, Philippe Mathieu-Daudé,
	Thomas Huth, Yanan Wang

[-- Attachment #1: Type: text/plain, Size: 4385 bytes --]

Hi

On Wed, Aug 24, 2022 at 2:31 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Xuzhou Cheng <xuzhou.cheng@windriver.com>
>
> Currently signal SIGIPI [=SIGUSR1] is used to kick the dummy CPU
> when qtest accelerator is used. However SIGUSR1 is unsupported on
> Windows. To support Windows, we add a QemuSemaphore CPUState::sem
> to kick the dummy CPU instead for Windows.
>
> Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
>

What if we replace signals by the semaphore on posix as well?

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


> ---
>
>  include/hw/core/cpu.h   |  1 +
>  accel/dummy-cpus.c      | 14 ++++++++++++--
>  softmmu/cpus.c          |  9 +++++----
>  accel/meson.build       |  1 +
>  accel/qtest/meson.build |  1 +
>  5 files changed, 20 insertions(+), 6 deletions(-)
>
> diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
> index 500503da13..c564108877 100644
> --- a/include/hw/core/cpu.h
> +++ b/include/hw/core/cpu.h
> @@ -325,6 +325,7 @@ struct CPUState {
>      struct QemuThread *thread;
>  #ifdef _WIN32
>      HANDLE hThread;
> +    QemuSemaphore sem;
>  #endif
>      int thread_id;
>      bool running, has_waiter;
> diff --git a/accel/dummy-cpus.c b/accel/dummy-cpus.c
> index 10429fdfb2..d6a1b8d0a2 100644
> --- a/accel/dummy-cpus.c
> +++ b/accel/dummy-cpus.c
> @@ -21,8 +21,6 @@
>  static void *dummy_cpu_thread_fn(void *arg)
>  {
>      CPUState *cpu = arg;
> -    sigset_t waitset;
> -    int r;
>
>      rcu_register_thread();
>
> @@ -32,8 +30,13 @@ static void *dummy_cpu_thread_fn(void *arg)
>      cpu->can_do_io = 1;
>      current_cpu = cpu;
>
> +#ifndef _WIN32
> +    sigset_t waitset;
> +    int r;
> +
>      sigemptyset(&waitset);
>      sigaddset(&waitset, SIG_IPI);
> +#endif
>
>      /* signal CPU creation */
>      cpu_thread_signal_created(cpu);
> @@ -41,6 +44,7 @@ static void *dummy_cpu_thread_fn(void *arg)
>
>      do {
>          qemu_mutex_unlock_iothread();
> +#ifndef _WIN32
>          do {
>              int sig;
>              r = sigwait(&waitset, &sig);
> @@ -49,6 +53,9 @@ static void *dummy_cpu_thread_fn(void *arg)
>              perror("sigwait");
>              exit(1);
>          }
> +#else
> +        qemu_sem_wait(&cpu->sem);
> +#endif
>          qemu_mutex_lock_iothread();
>          qemu_wait_io_event(cpu);
>      } while (!cpu->unplug);
> @@ -69,4 +76,7 @@ void dummy_start_vcpu_thread(CPUState *cpu)
>               cpu->cpu_index);
>      qemu_thread_create(cpu->thread, thread_name, dummy_cpu_thread_fn, cpu,
>                         QEMU_THREAD_JOINABLE);
> +#ifdef _WIN32
> +    qemu_sem_init(&cpu->sem, 0);
> +#endif
>  }
> diff --git a/softmmu/cpus.c b/softmmu/cpus.c
> index 23b30484b2..fd10db927a 100644
> --- a/softmmu/cpus.c
> +++ b/softmmu/cpus.c
> @@ -437,18 +437,19 @@ void qemu_wait_io_event(CPUState *cpu)
>
>  void cpus_kick_thread(CPUState *cpu)
>  {
> -#ifndef _WIN32
> -    int err;
> -
>      if (cpu->thread_kicked) {
>          return;
>      }
>      cpu->thread_kicked = true;
> -    err = pthread_kill(cpu->thread->thread, SIG_IPI);
> +
> +#ifndef _WIN32
> +    int err = pthread_kill(cpu->thread->thread, SIG_IPI);
>      if (err && err != ESRCH) {
>          fprintf(stderr, "qemu:%s: %s", __func__, strerror(err));
>          exit(1);
>      }
> +#else
> +    qemu_sem_post(&cpu->sem);
>  #endif
>  }
>
> diff --git a/accel/meson.build b/accel/meson.build
> index b9a963cf80..b21c85dc0a 100644
> --- a/accel/meson.build
> +++ b/accel/meson.build
> @@ -17,4 +17,5 @@ dummy_ss.add(files(
>  ))
>
>  specific_ss.add_all(when: ['CONFIG_SOFTMMU', 'CONFIG_POSIX'], if_true:
> dummy_ss)
> +specific_ss.add_all(when: ['CONFIG_WIN32'], if_true: dummy_ss)
>  specific_ss.add_all(when: ['CONFIG_XEN'], if_true: dummy_ss)
> diff --git a/accel/qtest/meson.build b/accel/qtest/meson.build
> index 4c65600293..a4876fc0f2 100644
> --- a/accel/qtest/meson.build
> +++ b/accel/qtest/meson.build
> @@ -1,2 +1,3 @@
>  qtest_module_ss.add(when: ['CONFIG_SOFTMMU', 'CONFIG_POSIX'],
>                      if_true: files('qtest.c'))
> +qtest_module_ss.add(when: ['CONFIG_WIN32'], if_true: files('qtest.c'))
> --
> 2.34.1
>
>
>

-- 
Marc-André Lureau

[-- Attachment #2: Type: text/html, Size: 5874 bytes --]

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

* Re: [PATCH 24/51] tests/qtest: libqos: Drop inclusion of <sys/wait.h>
  2022-08-24  9:40 ` [PATCH 24/51] tests/qtest: libqos: Drop inclusion of <sys/wait.h> Bin Meng
  2022-08-25 11:55   ` Thomas Huth
@ 2022-08-31 13:50   ` Marc-André Lureau
  1 sibling, 0 replies; 174+ messages in thread
From: Marc-André Lureau @ 2022-08-31 13:50 UTC (permalink / raw)
  To: Bin Meng
  Cc: qemu-devel, Xuzhou Cheng, Bin Meng, Laurent Vivier,
	Paolo Bonzini, Thomas Huth

[-- Attachment #1: Type: text/plain, Size: 922 bytes --]

On Wed, Aug 24, 2022 at 2:43 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Xuzhou Cheng <xuzhou.cheng@windriver.com>
>
> There is no <sys/wait.h> in the Windows build environment. Actually
> this is not needed in the non-win32 builds too. Drop it.
>
> Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
>

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


> ---
>
>  tests/qtest/libqos/libqos.c | 2 --
>  1 file changed, 2 deletions(-)
>
> diff --git a/tests/qtest/libqos/libqos.c b/tests/qtest/libqos/libqos.c
> index 85c7641add..5ffda080ec 100644
> --- a/tests/qtest/libqos/libqos.c
> +++ b/tests/qtest/libqos/libqos.c
> @@ -1,6 +1,4 @@
>  #include "qemu/osdep.h"
> -#include <sys/wait.h>
> -
>  #include "../libqtest.h"
>  #include "libqos.h"
>  #include "pci.h"
> --
> 2.34.1
>
>
>

-- 
Marc-André Lureau

[-- Attachment #2: Type: text/html, Size: 1835 bytes --]

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

* Re: [PATCH 25/51] tests/qtest: libqos: Rename malloc.h to libqos-malloc.h
  2022-08-24  9:40 ` [PATCH 25/51] tests/qtest: libqos: Rename malloc.h to libqos-malloc.h Bin Meng
  2022-08-25 11:51   ` Thomas Huth
@ 2022-08-31 13:51   ` Marc-André Lureau
  1 sibling, 0 replies; 174+ messages in thread
From: Marc-André Lureau @ 2022-08-31 13:51 UTC (permalink / raw)
  To: Bin Meng
  Cc: qemu-devel, Xuzhou Cheng, Bin Meng, Alexander Bulekov,
	Bandan Das, Cédric Le Goater, Daniel Henrique Barboza,
	Darren Kenny, David Gibson, Greg Kurz, Laurent Vivier,
	Paolo Bonzini, Qiuhao Li, Stefan Hajnoczi, Thomas Huth, qemu-ppc

[-- Attachment #1: Type: text/plain, Size: 14884 bytes --]

On Wed, Aug 24, 2022 at 2:22 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Xuzhou Cheng <xuzhou.cheng@windriver.com>
>
> The qtest/libqos directory is included via the "-I" option to search
> for header files when building qtest. Unfortunately the malloc.h has
> a name conflict with the standard libc header, leading to a build
> failure on the Windows host, due to the MinGW libc stdlib.h header
> file includes malloc.h and it now gets wrongly pointed to the one
> in the qtest/libqos directory.
>
> Rename "qtest/libqos/malloc.h" to "qtest/libqos/libqos-malloc.h" to
> avoid the namespace pollution.
>
> Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
>

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


> ---
>
>  tests/qtest/libqos/generic-pcihost.h             | 2 +-
>  tests/qtest/libqos/{malloc.h => libqos-malloc.h} | 0
>  tests/qtest/libqos/libqos.h                      | 2 +-
>  tests/qtest/libqos/malloc-pc.h                   | 2 +-
>  tests/qtest/libqos/malloc-spapr.h                | 2 +-
>  tests/qtest/libqos/pci-pc.h                      | 2 +-
>  tests/qtest/libqos/pci-spapr.h                   | 2 +-
>  tests/qtest/libqos/qgraph.h                      | 2 +-
>  tests/qtest/libqos/qos_external.h                | 2 +-
>  tests/qtest/libqos/rtas.h                        | 2 +-
>  tests/qtest/libqos/virtio.h                      | 2 +-
>  tests/qtest/e1000e-test.c                        | 2 +-
>  tests/qtest/fuzz/qos_fuzz.c                      | 2 +-
>  tests/qtest/libqos/aarch64-xlnx-zcu102-machine.c | 2 +-
>  tests/qtest/libqos/arm-imx25-pdk-machine.c       | 2 +-
>  tests/qtest/libqos/arm-n800-machine.c            | 2 +-
>  tests/qtest/libqos/arm-raspi2-machine.c          | 2 +-
>  tests/qtest/libqos/arm-sabrelite-machine.c       | 2 +-
>  tests/qtest/libqos/arm-smdkc210-machine.c        | 2 +-
>  tests/qtest/libqos/arm-virt-machine.c            | 2 +-
>  tests/qtest/libqos/arm-xilinx-zynq-a9-machine.c  | 2 +-
>  tests/qtest/libqos/e1000e.c                      | 2 +-
>  tests/qtest/libqos/{malloc.c => libqos-malloc.c} | 2 +-
>  tests/qtest/libqos/qos_external.c                | 2 +-
>  tests/qtest/libqos/virtio-mmio.c                 | 2 +-
>  tests/qtest/libqos/virtio-pci.c                  | 2 +-
>  tests/qtest/qos-test.c                           | 2 +-
>  tests/qtest/libqos/meson.build                   | 2 +-
>  28 files changed, 27 insertions(+), 27 deletions(-)
>  rename tests/qtest/libqos/{malloc.h => libqos-malloc.h} (100%)
>  rename tests/qtest/libqos/{malloc.c => libqos-malloc.c} (99%)
>
> diff --git a/tests/qtest/libqos/generic-pcihost.h
> b/tests/qtest/libqos/generic-pcihost.h
> index c693c769df..6493a8712a 100644
> --- a/tests/qtest/libqos/generic-pcihost.h
> +++ b/tests/qtest/libqos/generic-pcihost.h
> @@ -14,7 +14,7 @@
>  #define LIBQOS_GENERIC_PCIHOST_H
>
>  #include "pci.h"
> -#include "malloc.h"
> +#include "libqos-malloc.h"
>  #include "qgraph.h"
>
>  typedef struct QGenericPCIBus {
> diff --git a/tests/qtest/libqos/malloc.h
> b/tests/qtest/libqos/libqos-malloc.h
> similarity index 100%
> rename from tests/qtest/libqos/malloc.h
> rename to tests/qtest/libqos/libqos-malloc.h
> diff --git a/tests/qtest/libqos/libqos.h b/tests/qtest/libqos/libqos.h
> index ba7df448ca..9b4dd509f0 100644
> --- a/tests/qtest/libqos/libqos.h
> +++ b/tests/qtest/libqos/libqos.h
> @@ -3,7 +3,7 @@
>
>  #include "../libqtest.h"
>  #include "pci.h"
> -#include "malloc.h"
> +#include "libqos-malloc.h"
>
>  typedef struct QOSState QOSState;
>
> diff --git a/tests/qtest/libqos/malloc-pc.h
> b/tests/qtest/libqos/malloc-pc.h
> index d8d79853c8..e531473601 100644
> --- a/tests/qtest/libqos/malloc-pc.h
> +++ b/tests/qtest/libqos/malloc-pc.h
> @@ -13,7 +13,7 @@
>  #ifndef LIBQOS_MALLOC_PC_H
>  #define LIBQOS_MALLOC_PC_H
>
> -#include "malloc.h"
> +#include "libqos-malloc.h"
>
>  void pc_alloc_init(QGuestAllocator *s, QTestState *qts, QAllocOpts flags);
>
> diff --git a/tests/qtest/libqos/malloc-spapr.h
> b/tests/qtest/libqos/malloc-spapr.h
> index f99572fd71..f544c0d611 100644
> --- a/tests/qtest/libqos/malloc-spapr.h
> +++ b/tests/qtest/libqos/malloc-spapr.h
> @@ -8,7 +8,7 @@
>  #ifndef LIBQOS_MALLOC_SPAPR_H
>  #define LIBQOS_MALLOC_SPAPR_H
>
> -#include "malloc.h"
> +#include "libqos-malloc.h"
>
>  void spapr_alloc_init(QGuestAllocator *s, QTestState *qts, QAllocOpts
> flags);
>
> diff --git a/tests/qtest/libqos/pci-pc.h b/tests/qtest/libqos/pci-pc.h
> index 49ec9507f2..849bd493de 100644
> --- a/tests/qtest/libqos/pci-pc.h
> +++ b/tests/qtest/libqos/pci-pc.h
> @@ -14,7 +14,7 @@
>  #define LIBQOS_PCI_PC_H
>
>  #include "pci.h"
> -#include "malloc.h"
> +#include "libqos-malloc.h"
>  #include "qgraph.h"
>
>  typedef struct QPCIBusPC {
> diff --git a/tests/qtest/libqos/pci-spapr.h
> b/tests/qtest/libqos/pci-spapr.h
> index 20a43718b7..3dbf1e58ae 100644
> --- a/tests/qtest/libqos/pci-spapr.h
> +++ b/tests/qtest/libqos/pci-spapr.h
> @@ -8,7 +8,7 @@
>  #ifndef LIBQOS_PCI_SPAPR_H
>  #define LIBQOS_PCI_SPAPR_H
>
> -#include "malloc.h"
> +#include "libqos-malloc.h"
>  #include "pci.h"
>  #include "qgraph.h"
>
> diff --git a/tests/qtest/libqos/qgraph.h b/tests/qtest/libqos/qgraph.h
> index 871740c0dc..6e94824d09 100644
> --- a/tests/qtest/libqos/qgraph.h
> +++ b/tests/qtest/libqos/qgraph.h
> @@ -21,7 +21,7 @@
>
>  #include <gmodule.h>
>  #include "qemu/module.h"
> -#include "malloc.h"
> +#include "libqos-malloc.h"
>
>  /* maximum path length */
>  #define QOS_PATH_MAX_ELEMENT_SIZE 50
> diff --git a/tests/qtest/libqos/qos_external.h
> b/tests/qtest/libqos/qos_external.h
> index 8446e3df0b..ea37364887 100644
> --- a/tests/qtest/libqos/qos_external.h
> +++ b/tests/qtest/libqos/qos_external.h
> @@ -21,7 +21,7 @@
>
>  #include "qgraph.h"
>
> -#include "malloc.h"
> +#include "libqos-malloc.h"
>  #include "qapi/qapi-types-machine.h"
>  #include "qapi/qapi-types-qom.h"
>
> diff --git a/tests/qtest/libqos/rtas.h b/tests/qtest/libqos/rtas.h
> index f38f99dfab..be8353d505 100644
> --- a/tests/qtest/libqos/rtas.h
> +++ b/tests/qtest/libqos/rtas.h
> @@ -5,7 +5,7 @@
>
>  #ifndef LIBQOS_RTAS_H
>  #define LIBQOS_RTAS_H
> -#include "malloc.h"
> +#include "libqos-malloc.h"
>
>  int qrtas_get_time_of_day(QTestState *qts, QGuestAllocator *alloc,
>                            struct tm *tm, uint32_t *ns);
> diff --git a/tests/qtest/libqos/virtio.h b/tests/qtest/libqos/virtio.h
> index b8bd06e1b8..7adc7cbd10 100644
> --- a/tests/qtest/libqos/virtio.h
> +++ b/tests/qtest/libqos/virtio.h
> @@ -10,7 +10,7 @@
>  #ifndef LIBQOS_VIRTIO_H
>  #define LIBQOS_VIRTIO_H
>
> -#include "malloc.h"
> +#include "libqos-malloc.h"
>  #include "standard-headers/linux/virtio_ring.h"
>
>  #define QVIRTIO_F_BAD_FEATURE           0x40000000ull
> diff --git a/tests/qtest/e1000e-test.c b/tests/qtest/e1000e-test.c
> index c98779c7c0..4cdd8238f2 100644
> --- a/tests/qtest/e1000e-test.c
> +++ b/tests/qtest/e1000e-test.c
> @@ -31,7 +31,7 @@
>  #include "qemu/iov.h"
>  #include "qemu/module.h"
>  #include "qemu/bitops.h"
> -#include "libqos/malloc.h"
> +#include "libqos/libqos-malloc.h"
>  #include "libqos/e1000e.h"
>
>  static void e1000e_send_verify(QE1000E *d, int *test_sockets,
> QGuestAllocator *alloc)
> diff --git a/tests/qtest/fuzz/qos_fuzz.c b/tests/qtest/fuzz/qos_fuzz.c
> index c856d3d500..3a3d9c16dd 100644
> --- a/tests/qtest/fuzz/qos_fuzz.c
> +++ b/tests/qtest/fuzz/qos_fuzz.c
> @@ -23,7 +23,7 @@
>  #include "qemu/main-loop.h"
>
>  #include "tests/qtest/libqtest.h"
> -#include "tests/qtest/libqos/malloc.h"
> +#include "tests/qtest/libqos/libqos-malloc.h"
>  #include "tests/qtest/libqos/qgraph.h"
>  #include "tests/qtest/libqos/qgraph_internal.h"
>  #include "tests/qtest/libqos/qos_external.h"
> diff --git a/tests/qtest/libqos/aarch64-xlnx-zcu102-machine.c
> b/tests/qtest/libqos/aarch64-xlnx-zcu102-machine.c
> index c8a3ea11eb..ab24add8eb 100644
> --- a/tests/qtest/libqos/aarch64-xlnx-zcu102-machine.c
> +++ b/tests/qtest/libqos/aarch64-xlnx-zcu102-machine.c
> @@ -19,7 +19,7 @@
>  #include "qemu/osdep.h"
>  #include "../libqtest.h"
>  #include "qemu/module.h"
> -#include "malloc.h"
> +#include "libqos-malloc.h"
>  #include "qgraph.h"
>  #include "sdhci.h"
>
> diff --git a/tests/qtest/libqos/arm-imx25-pdk-machine.c
> b/tests/qtest/libqos/arm-imx25-pdk-machine.c
> index 54d0c95330..8fe128fae8 100644
> --- a/tests/qtest/libqos/arm-imx25-pdk-machine.c
> +++ b/tests/qtest/libqos/arm-imx25-pdk-machine.c
> @@ -20,7 +20,7 @@
>
>  #include "qemu/osdep.h"
>  #include "../libqtest.h"
> -#include "malloc.h"
> +#include "libqos-malloc.h"
>  #include "qgraph.h"
>  #include "i2c.h"
>
> diff --git a/tests/qtest/libqos/arm-n800-machine.c
> b/tests/qtest/libqos/arm-n800-machine.c
> index ecd46b1daf..4e5afe0164 100644
> --- a/tests/qtest/libqos/arm-n800-machine.c
> +++ b/tests/qtest/libqos/arm-n800-machine.c
> @@ -20,7 +20,7 @@
>
>  #include "qemu/osdep.h"
>  #include "../libqtest.h"
> -#include "malloc.h"
> +#include "libqos-malloc.h"
>  #include "qgraph.h"
>  #include "i2c.h"
>
> diff --git a/tests/qtest/libqos/arm-raspi2-machine.c
> b/tests/qtest/libqos/arm-raspi2-machine.c
> index 0a2943440b..367c6c17a5 100644
> --- a/tests/qtest/libqos/arm-raspi2-machine.c
> +++ b/tests/qtest/libqos/arm-raspi2-machine.c
> @@ -19,7 +19,7 @@
>  #include "qemu/osdep.h"
>  #include "../libqtest.h"
>  #include "qemu/module.h"
> -#include "malloc.h"
> +#include "libqos-malloc.h"
>  #include "qgraph.h"
>  #include "sdhci.h"
>
> diff --git a/tests/qtest/libqos/arm-sabrelite-machine.c
> b/tests/qtest/libqos/arm-sabrelite-machine.c
> index ec19a01660..94f6a20fc7 100644
> --- a/tests/qtest/libqos/arm-sabrelite-machine.c
> +++ b/tests/qtest/libqos/arm-sabrelite-machine.c
> @@ -19,7 +19,7 @@
>  #include "qemu/osdep.h"
>  #include "../libqtest.h"
>  #include "qemu/module.h"
> -#include "malloc.h"
> +#include "libqos-malloc.h"
>  #include "qgraph.h"
>  #include "sdhci.h"
>
> diff --git a/tests/qtest/libqos/arm-smdkc210-machine.c
> b/tests/qtest/libqos/arm-smdkc210-machine.c
> index 4bff249ee8..9bbce924ea 100644
> --- a/tests/qtest/libqos/arm-smdkc210-machine.c
> +++ b/tests/qtest/libqos/arm-smdkc210-machine.c
> @@ -19,7 +19,7 @@
>  #include "qemu/osdep.h"
>  #include "../libqtest.h"
>  #include "qemu/module.h"
> -#include "malloc.h"
> +#include "libqos-malloc.h"
>  #include "qgraph.h"
>  #include "sdhci.h"
>
> diff --git a/tests/qtest/libqos/arm-virt-machine.c
> b/tests/qtest/libqos/arm-virt-machine.c
> index 139eaba142..4e87405b58 100644
> --- a/tests/qtest/libqos/arm-virt-machine.c
> +++ b/tests/qtest/libqos/arm-virt-machine.c
> @@ -19,7 +19,7 @@
>  #include "qemu/osdep.h"
>  #include "../libqtest.h"
>  #include "qemu/module.h"
> -#include "malloc.h"
> +#include "libqos-malloc.h"
>  #include "qgraph.h"
>  #include "virtio-mmio.h"
>  #include "generic-pcihost.h"
> diff --git a/tests/qtest/libqos/arm-xilinx-zynq-a9-machine.c
> b/tests/qtest/libqos/arm-xilinx-zynq-a9-machine.c
> index 3be80020a6..daac762a06 100644
> --- a/tests/qtest/libqos/arm-xilinx-zynq-a9-machine.c
> +++ b/tests/qtest/libqos/arm-xilinx-zynq-a9-machine.c
> @@ -19,7 +19,7 @@
>  #include "qemu/osdep.h"
>  #include "../libqtest.h"
>  #include "qemu/module.h"
> -#include "malloc.h"
> +#include "libqos-malloc.h"
>  #include "qgraph.h"
>  #include "sdhci.h"
>
> diff --git a/tests/qtest/libqos/e1000e.c b/tests/qtest/libqos/e1000e.c
> index f87e0e84b2..fc14b07884 100644
> --- a/tests/qtest/libqos/e1000e.c
> +++ b/tests/qtest/libqos/e1000e.c
> @@ -23,7 +23,7 @@
>  #include "qemu/iov.h"
>  #include "qemu/module.h"
>  #include "qemu/bitops.h"
> -#include "malloc.h"
> +#include "libqos-malloc.h"
>  #include "qgraph.h"
>  #include "e1000e.h"
>
> diff --git a/tests/qtest/libqos/malloc.c
> b/tests/qtest/libqos/libqos-malloc.c
> similarity index 99%
> rename from tests/qtest/libqos/malloc.c
> rename to tests/qtest/libqos/libqos-malloc.c
> index f0c8f950c8..d7566972c4 100644
> --- a/tests/qtest/libqos/malloc.c
> +++ b/tests/qtest/libqos/libqos-malloc.c
> @@ -11,7 +11,7 @@
>   */
>
>  #include "qemu/osdep.h"
> -#include "malloc.h"
> +#include "libqos-malloc.h"
>  #include "qemu/host-utils.h"
>
>  typedef struct MemBlock {
> diff --git a/tests/qtest/libqos/qos_external.c
> b/tests/qtest/libqos/qos_external.c
> index b7a0b873a3..c6bb8bff09 100644
> --- a/tests/qtest/libqos/qos_external.c
> +++ b/tests/qtest/libqos/qos_external.c
> @@ -24,7 +24,7 @@
>  #include "qapi/qmp/qstring.h"
>  #include "qemu/module.h"
>  #include "qapi/qmp/qlist.h"
> -#include "malloc.h"
> +#include "libqos-malloc.h"
>  #include "qgraph.h"
>  #include "qgraph_internal.h"
>  #include "qos_external.h"
> diff --git a/tests/qtest/libqos/virtio-mmio.c
> b/tests/qtest/libqos/virtio-mmio.c
> index a6cca8613b..bd0b1d890b 100644
> --- a/tests/qtest/libqos/virtio-mmio.c
> +++ b/tests/qtest/libqos/virtio-mmio.c
> @@ -12,7 +12,7 @@
>  #include "qemu/module.h"
>  #include "virtio.h"
>  #include "virtio-mmio.h"
> -#include "malloc.h"
> +#include "libqos-malloc.h"
>  #include "qgraph.h"
>  #include "standard-headers/linux/virtio_ring.h"
>
> diff --git a/tests/qtest/libqos/virtio-pci.c
> b/tests/qtest/libqos/virtio-pci.c
> index 67c2498c84..485b8f6b7e 100644
> --- a/tests/qtest/libqos/virtio-pci.c
> +++ b/tests/qtest/libqos/virtio-pci.c
> @@ -13,7 +13,7 @@
>  #include "virtio-pci.h"
>  #include "pci.h"
>  #include "pci-pc.h"
> -#include "malloc.h"
> +#include "libqos-malloc.h"
>  #include "malloc-pc.h"
>  #include "qgraph.h"
>  #include "standard-headers/linux/virtio_ring.h"
> diff --git a/tests/qtest/qos-test.c b/tests/qtest/qos-test.c
> index f97d0a08fd..831db5cf2a 100644
> --- a/tests/qtest/qos-test.c
> +++ b/tests/qtest/qos-test.c
> @@ -25,7 +25,7 @@
>  #include "qapi/qobject-input-visitor.h"
>  #include "qapi/qapi-visit-machine.h"
>  #include "qapi/qapi-visit-qom.h"
> -#include "libqos/malloc.h"
> +#include "libqos/libqos-malloc.h"
>  #include "libqos/qgraph.h"
>  #include "libqos/qgraph_internal.h"
>  #include "libqos/qos_external.h"
> diff --git a/tests/qtest/libqos/meson.build
> b/tests/qtest/libqos/meson.build
> index fd5d6e5ae1..cff83c86d9 100644
> --- a/tests/qtest/libqos/meson.build
> +++ b/tests/qtest/libqos/meson.build
> @@ -6,7 +6,7 @@ libqos_srcs = files(
>          'qos_external.c',
>          'pci.c',
>          'fw_cfg.c',
> -        'malloc.c',
> +        'libqos-malloc.c',
>          'libqos.c',
>          'sdhci-cmd.c',
>
> --
> 2.34.1
>
>
>

-- 
Marc-André Lureau

[-- Attachment #2: Type: text/html, Size: 18442 bytes --]

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

* Re: [PATCH 27/51] tests/qtest: Use send/recv for socket communication
  2022-08-26 18:26       ` Thomas Huth
@ 2022-08-31 14:05         ` Marc-André Lureau
  2022-08-31 14:19           ` Daniel P. Berrangé
  2022-09-02 14:24           ` Bin Meng
  0 siblings, 2 replies; 174+ messages in thread
From: Marc-André Lureau @ 2022-08-31 14:05 UTC (permalink / raw)
  To: Thomas Huth, Daniel P. Berrange
  Cc: Bin Meng, qemu-devel@nongnu.org Developers, Xuzhou Cheng,
	Bin Meng, Laurent Vivier, Paolo Bonzini

[-- Attachment #1: Type: text/plain, Size: 2687 bytes --]

Hi

On Fri, Aug 26, 2022 at 10:27 PM Thomas Huth <thuth@redhat.com> wrote:

> On 26/08/2022 16.59, Bin Meng wrote:
> > On Thu, Aug 25, 2022 at 9:04 PM Thomas Huth <thuth@redhat.com> wrote:
> >>
> >> On 24/08/2022 11.40, Bin Meng wrote:
> >>> From: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> >>>
> >>> Socket communication in the libqtest and libqmp codes uses read()
> >>> and write() which work on any file descriptor on *nix, and sockets
> >>> in *nix are an example of a file descriptor.
> >>>
> >>> However sockets on Windows do not use *nix-style file descriptors,
> >>> so read() and write() cannot be used on sockets on Windows.
> >>> Switch over to use send() and recv() instead which work on both
> >>> Windows and *nix.
> >>>
> >>> Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> >>> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> >>> ---
> >>>
> >>>    tests/qtest/libqmp.c   | 4 ++--
> >>>    tests/qtest/libqtest.c | 4 ++--
> >>>    2 files changed, 4 insertions(+), 4 deletions(-)
> >>>
> >>> diff --git a/tests/qtest/libqmp.c b/tests/qtest/libqmp.c
> >>> index ade26c15f0..995a39c1f8 100644
> >>> --- a/tests/qtest/libqmp.c
> >>> +++ b/tests/qtest/libqmp.c
> >>> @@ -36,7 +36,7 @@ typedef struct {
> >>>
> >>>    static void socket_send(int fd, const char *buf, size_t size)
> >>>    {
> >>> -    size_t res = qemu_write_full(fd, buf, size);
> >>> +    ssize_t res = send(fd, buf, size, 0);
> >>
> >> This way we're losing the extra logic from qemu_write_full() here (i.e.
> the
> >> looping and EINTR handling) ... not sure whether that's really OK?
> Maybe you
> >> have to introduce a qemu_send_full() first?
> >>
> >
> > I am not sure if qemu_send_full() is really needed because there is an
> > assert() right after the send() call.
>
> That's just a sanity check ... I think this function still has to take
> care
> of EINTR - it originally looked like this:
>
>   https://git.qemu.org/?p=qemu.git;a=commitdiff;h=c3e5704af19ac6
>
> ... and you can also see the while loop there.
>
>
Agree, that would be the correct thing to do.

Fwiw, the SOCKET vs fd situation is giving me some nervous feelings,
sometimes.

For ex, as I checked recently, it seems close(fd) correctly closes the
underlying SOCKET - as if closesocket() was called on it.. but this is not
really documented.

And it's easy to mix fd vs SOCKET in QEMU code paths (we cast/map SOCKET to
"int fd" in general), and reach a close() on a SOCKET. That wouldn't be
valid, and would likely create leaks or other issues.

Maybe we should introduce a type for safety / documentation purposes...

-- 
Marc-André Lureau

[-- Attachment #2: Type: text/html, Size: 4011 bytes --]

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

* Re: [PATCH 28/51] tests/qtest: libqtest: Exclude the *_fds APIs for win32
  2022-08-24  9:40 ` [PATCH 28/51] tests/qtest: libqtest: Exclude the *_fds APIs for win32 Bin Meng
@ 2022-08-31 14:10   ` Marc-André Lureau
  0 siblings, 0 replies; 174+ messages in thread
From: Marc-André Lureau @ 2022-08-31 14:10 UTC (permalink / raw)
  To: Bin Meng; +Cc: qemu-devel, Bin Meng, Laurent Vivier, Paolo Bonzini, Thomas Huth

[-- Attachment #1: Type: text/plain, Size: 5477 bytes --]

On Wed, Aug 24, 2022 at 2:38 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Bin Meng <bin.meng@windriver.com>
>
> libqmp.c::qmp_fd_vsend_fds() is not available on Windows, hence any
> APIs in libqtest that call libqmp.c::qmp_fd_vsend_fds() should be
> excluded for win32 too. This includes the following:
>
>   * qtest_qmp_vsend_fds()
>   * qtest_vqmp_fds()
>   * qtest_qmp_fds()
>   * qtest_qmp_add_client()
>
> Note qtest_qmp_vsend() was wrongly written to call qmp_fd_vsend_fds()
> previously, but it should call the non fds version API qmp_fd_vsend().
>

This doesn't look relevant anymore


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

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


> ---
>
>  tests/qtest/libqtest.h |  8 ++++++++
>  tests/qtest/libqtest.c | 10 +++++++++-
>  2 files changed, 17 insertions(+), 1 deletion(-)
>
> diff --git a/tests/qtest/libqtest.h b/tests/qtest/libqtest.h
> index 94b187837d..3abc75964d 100644
> --- a/tests/qtest/libqtest.h
> +++ b/tests/qtest/libqtest.h
> @@ -94,6 +94,7 @@ void qtest_kill_qemu(QTestState *s);
>   */
>  void qtest_quit(QTestState *s);
>
> +#ifndef _WIN32
>  /**
>   * qtest_qmp_fds:
>   * @s: #QTestState instance to operate on.
> @@ -108,6 +109,7 @@ void qtest_quit(QTestState *s);
>  QDict *qtest_qmp_fds(QTestState *s, int *fds, size_t fds_num,
>                       const char *fmt, ...)
>      G_GNUC_PRINTF(4, 5);
> +#endif /* _WIN32 */
>
>  /**
>   * qtest_qmp:
> @@ -152,6 +154,7 @@ void qtest_qmp_send_raw(QTestState *s, const char
> *fmt, ...)
>   */
>  int qtest_socket_server(const char *socket_path);
>
> +#ifndef _WIN32
>  /**
>   * qtest_vqmp_fds:
>   * @s: #QTestState instance to operate on.
> @@ -167,6 +170,7 @@ int qtest_socket_server(const char *socket_path);
>  QDict *qtest_vqmp_fds(QTestState *s, int *fds, size_t fds_num,
>                        const char *fmt, va_list ap)
>      G_GNUC_PRINTF(4, 0);
> +#endif /* _WIN32 */
>
>  /**
>   * qtest_vqmp:
> @@ -181,6 +185,7 @@ QDict *qtest_vqmp_fds(QTestState *s, int *fds, size_t
> fds_num,
>  QDict *qtest_vqmp(QTestState *s, const char *fmt, va_list ap)
>      G_GNUC_PRINTF(2, 0);
>
> +#ifndef _WIN32
>  /**
>   * qtest_qmp_vsend_fds:
>   * @s: #QTestState instance to operate on.
> @@ -196,6 +201,7 @@ QDict *qtest_vqmp(QTestState *s, const char *fmt,
> va_list ap)
>  void qtest_qmp_vsend_fds(QTestState *s, int *fds, size_t fds_num,
>                           const char *fmt, va_list ap)
>      G_GNUC_PRINTF(4, 0);
> +#endif /* _WIN32 */
>
>  /**
>   * qtest_qmp_vsend:
> @@ -743,6 +749,7 @@ void qtest_qmp_device_add_qdict(QTestState *qts, const
> char *drv,
>  void qtest_qmp_device_add(QTestState *qts, const char *driver, const char
> *id,
>                            const char *fmt, ...) G_GNUC_PRINTF(4, 5);
>
> +#ifndef _WIN32
>  /**
>   * qtest_qmp_add_client:
>   * @qts: QTestState instance to operate on
> @@ -752,6 +759,7 @@ void qtest_qmp_device_add(QTestState *qts, const char
> *driver, const char *id,
>   * Call QMP ``getfd`` followed by ``add_client`` with the given @fd.
>   */
>  void qtest_qmp_add_client(QTestState *qts, const char *protocol, int fd);
> +#endif /* _WIN32 */
>
>  /**
>   * qtest_qmp_device_del:
> diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
> index b7b7c9c541..1b24a4f1f7 100644
> --- a/tests/qtest/libqtest.c
> +++ b/tests/qtest/libqtest.c
> @@ -594,17 +594,20 @@ int qtest_socket_server(const char *socket_path)
>      return sock;
>  }
>
> +#ifndef _WIN32
>  void qtest_qmp_vsend_fds(QTestState *s, int *fds, size_t fds_num,
>                           const char *fmt, va_list ap)
>  {
>      qmp_fd_vsend_fds(s->qmp_fd, fds, fds_num, fmt, ap);
>  }
> +#endif
>
>  void qtest_qmp_vsend(QTestState *s, const char *fmt, va_list ap)
>  {
> -    qmp_fd_vsend_fds(s->qmp_fd, NULL, 0, fmt, ap);
> +    qmp_fd_vsend(s->qmp_fd, fmt, ap);
>  }
>
> +#ifndef _WIN32
>  QDict *qtest_vqmp_fds(QTestState *s, int *fds, size_t fds_num,
>                        const char *fmt, va_list ap)
>  {
> @@ -613,6 +616,7 @@ QDict *qtest_vqmp_fds(QTestState *s, int *fds, size_t
> fds_num,
>      /* Receive reply */
>      return qtest_qmp_receive(s);
>  }
> +#endif
>
>  QDict *qtest_vqmp(QTestState *s, const char *fmt, va_list ap)
>  {
> @@ -622,6 +626,7 @@ QDict *qtest_vqmp(QTestState *s, const char *fmt,
> va_list ap)
>      return qtest_qmp_receive(s);
>  }
>
> +#ifndef _WIN32
>  QDict *qtest_qmp_fds(QTestState *s, int *fds, size_t fds_num,
>                       const char *fmt, ...)
>  {
> @@ -633,6 +638,7 @@ QDict *qtest_qmp_fds(QTestState *s, int *fds, size_t
> fds_num,
>      va_end(ap);
>      return response;
>  }
> +#endif
>
>  QDict *qtest_qmp(QTestState *s, const char *fmt, ...)
>  {
> @@ -1329,6 +1335,7 @@ void qtest_qmp_device_add(QTestState *qts, const
> char *driver, const char *id,
>      qobject_unref(args);
>  }
>
> +#ifndef _WIN32
>  void qtest_qmp_add_client(QTestState *qts, const char *protocol, int fd)
>  {
>      QDict *resp;
> @@ -1348,6 +1355,7 @@ void qtest_qmp_add_client(QTestState *qts, const
> char *protocol, int fd)
>      g_assert(!qdict_haskey(resp, "error"));
>      qobject_unref(resp);
>  }
> +#endif
>
>  /*
>   * Generic hot-unplugging test via the device_del QMP command.
> --
> 2.34.1
>
>
>

-- 
Marc-André Lureau

[-- Attachment #2: Type: text/html, Size: 6895 bytes --]

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

* Re: [PATCH 29/51] tests/qtest: libqtest: Install signal handler via signal()
  2022-08-24  9:40 ` [PATCH 29/51] tests/qtest: libqtest: Install signal handler via signal() Bin Meng
@ 2022-08-31 14:16   ` Marc-André Lureau
  2022-09-02 15:49     ` Bin Meng
  0 siblings, 1 reply; 174+ messages in thread
From: Marc-André Lureau @ 2022-08-31 14:16 UTC (permalink / raw)
  To: Bin Meng; +Cc: qemu-devel, Bin Meng, Laurent Vivier, Paolo Bonzini, Thomas Huth

[-- Attachment #1: Type: text/plain, Size: 2004 bytes --]

Hi

On Wed, Aug 24, 2022 at 2:47 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Bin Meng <bin.meng@windriver.com>
>
> At present the codes uses sigaction() to install signal handler with
> a flag SA_RESETHAND. Such usage can be covered by the signal() API
> that is a simplified interface to the general sigaction() facility.
>
> Update to use signal() to install the signal handler, as it is
> avaiable on Windows which we are going to support.
>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
>
>  tests/qtest/libqtest.c | 14 +++-----------
>  1 file changed, 3 insertions(+), 11 deletions(-)
>
> diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
> index 1b24a4f1f7..70d7578740 100644
> --- a/tests/qtest/libqtest.c
> +++ b/tests/qtest/libqtest.c
> @@ -68,7 +68,7 @@ struct QTestState
>  QTestState *global_qtest;
>
>  static GHookList abrt_hooks;
> -static struct sigaction sigact_old;
> +static sighandler_t sighandler_old;
>
>  static int qtest_query_target_endianness(QTestState *s);
>
> @@ -181,20 +181,12 @@ static void sigabrt_handler(int signo)
>
>  static void setup_sigabrt_handler(void)
>  {
> -    struct sigaction sigact;
> -
> -    /* Catch SIGABRT to clean up on g_assert() failure */
> -    sigact = (struct sigaction){
> -        .sa_handler = sigabrt_handler,
> -        .sa_flags = SA_RESETHAND,
> -    };
> -    sigemptyset(&sigact.sa_mask);
> -    sigaction(SIGABRT, &sigact, &sigact_old);
> +    sighandler_old = signal(SIGABRT, sigabrt_handler);
>  }
>
>  static void cleanup_sigabrt_handler(void)
>  {
> -    sigaction(SIGABRT, &sigact_old, NULL);
> +    signal(SIGABRT, sighandler_old);
>  }
>
>  static bool hook_list_is_empty(GHookList *hook_list)
> --
>


We should keep the sigaction() version for !WIN32, it has notoriously less
issues, more modern etc. signal() only on win32.

Although in this particular usage, I don't think that makes much
difference...

-- 
Marc-André Lureau

[-- Attachment #2: Type: text/html, Size: 2724 bytes --]

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

* Re: [PATCH 27/51] tests/qtest: Use send/recv for socket communication
  2022-08-31 14:05         ` Marc-André Lureau
@ 2022-08-31 14:19           ` Daniel P. Berrangé
  2022-09-02 14:24           ` Bin Meng
  1 sibling, 0 replies; 174+ messages in thread
From: Daniel P. Berrangé @ 2022-08-31 14:19 UTC (permalink / raw)
  To: Marc-André Lureau
  Cc: Thomas Huth, Bin Meng, qemu-devel@nongnu.org Developers,
	Xuzhou Cheng, Bin Meng, Laurent Vivier, Paolo Bonzini

On Wed, Aug 31, 2022 at 06:05:51PM +0400, Marc-André Lureau wrote:
> Hi
> 
> On Fri, Aug 26, 2022 at 10:27 PM Thomas Huth <thuth@redhat.com> wrote:
> 
> > On 26/08/2022 16.59, Bin Meng wrote:
> > > On Thu, Aug 25, 2022 at 9:04 PM Thomas Huth <thuth@redhat.com> wrote:
> > >>
> > >> On 24/08/2022 11.40, Bin Meng wrote:
> > >>> From: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> > >>>
> > >>> Socket communication in the libqtest and libqmp codes uses read()
> > >>> and write() which work on any file descriptor on *nix, and sockets
> > >>> in *nix are an example of a file descriptor.
> > >>>
> > >>> However sockets on Windows do not use *nix-style file descriptors,
> > >>> so read() and write() cannot be used on sockets on Windows.
> > >>> Switch over to use send() and recv() instead which work on both
> > >>> Windows and *nix.
> > >>>
> > >>> Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> > >>> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> > >>> ---
> > >>>
> > >>>    tests/qtest/libqmp.c   | 4 ++--
> > >>>    tests/qtest/libqtest.c | 4 ++--
> > >>>    2 files changed, 4 insertions(+), 4 deletions(-)
> > >>>
> > >>> diff --git a/tests/qtest/libqmp.c b/tests/qtest/libqmp.c
> > >>> index ade26c15f0..995a39c1f8 100644
> > >>> --- a/tests/qtest/libqmp.c
> > >>> +++ b/tests/qtest/libqmp.c
> > >>> @@ -36,7 +36,7 @@ typedef struct {
> > >>>
> > >>>    static void socket_send(int fd, const char *buf, size_t size)
> > >>>    {
> > >>> -    size_t res = qemu_write_full(fd, buf, size);
> > >>> +    ssize_t res = send(fd, buf, size, 0);
> > >>
> > >> This way we're losing the extra logic from qemu_write_full() here (i.e.
> > the
> > >> looping and EINTR handling) ... not sure whether that's really OK?
> > Maybe you
> > >> have to introduce a qemu_send_full() first?
> > >>
> > >
> > > I am not sure if qemu_send_full() is really needed because there is an
> > > assert() right after the send() call.
> >
> > That's just a sanity check ... I think this function still has to take
> > care
> > of EINTR - it originally looked like this:
> >
> >   https://git.qemu.org/?p=qemu.git;a=commitdiff;h=c3e5704af19ac6
> >
> > ... and you can also see the while loop there.
> >
> >
> Agree, that would be the correct thing to do.
> 
> Fwiw, the SOCKET vs fd situation is giving me some nervous feelings,
> sometimes.
> 
> For ex, as I checked recently, it seems close(fd) correctly closes the
> underlying SOCKET - as if closesocket() was called on it.. but this is not
> really documented.
> 
> And it's easy to mix fd vs SOCKET in QEMU code paths (we cast/map SOCKET to
> "int fd" in general), and reach a close() on a SOCKET. That wouldn't be
> valid, and would likely create leaks or other issues.
> 
> Maybe we should introduce a type for safety / documentation purposes...

We already have QIOChannel APIs, the problem here is that libtest is still
using low level sockets APIs and needs converting to the high level APIs
instead.

With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|



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

* Re: [PATCH 31/51] tests/qtest: Support libqtest to build and run on Windows
  2022-08-24  9:40 ` [PATCH 31/51] tests/qtest: Support libqtest to build and run on Windows Bin Meng
@ 2022-08-31 16:28   ` Marc-André Lureau
  2022-09-19 10:00     ` Bin Meng
  2022-09-01 11:38   ` Marc-André Lureau
  1 sibling, 1 reply; 174+ messages in thread
From: Marc-André Lureau @ 2022-08-31 16:28 UTC (permalink / raw)
  To: Bin Meng
  Cc: qemu-devel, Bin Meng, Xuzhou Cheng, Laurent Vivier,
	Paolo Bonzini, Thomas Huth

[-- Attachment #1: Type: text/plain, Size: 9699 bytes --]

Hi

On Wed, Aug 24, 2022 at 2:46 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Bin Meng <bin.meng@windriver.com>
>
> At present the libqtest codes were written to depend on several
> POSIX APIs, including fork(), kill() and waitpid(). Unfortunately
> these APIs are not available on Windows.
>
> This commit implements the corresponding functionalities using
> win32 native APIs. With this change, all qtest cases can build
> successfully on a Windows host, and we can start qtest testing
> on Windows now.
>
> Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
>
>  tests/qtest/libqtest.c  | 101 +++++++++++++++++++++++++++++++++++++++-
>  tests/qtest/meson.build |   5 +-
>  2 files changed, 101 insertions(+), 5 deletions(-)
>
> diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
> index 70d7578740..99e52ff571 100644
> --- a/tests/qtest/libqtest.c
> +++ b/tests/qtest/libqtest.c
> @@ -16,9 +16,11 @@
>
>  #include "qemu/osdep.h"
>
> +#ifndef _WIN32
>  #include <sys/socket.h>
>  #include <sys/wait.h>
>  #include <sys/un.h>
> +#endif /* _WIN32 */
>  #ifdef __linux__
>  #include <sys/prctl.h>
>  #endif /* __linux__ */
> @@ -27,6 +29,7 @@
>  #include "libqmp.h"
>  #include "qemu/ctype.h"
>  #include "qemu/cutils.h"
> +#include "qemu/sockets.h"
>  #include "qapi/qmp/qdict.h"
>  #include "qapi/qmp/qjson.h"
>  #include "qapi/qmp/qlist.h"
> @@ -35,6 +38,16 @@
>  #define MAX_IRQ 256
>  #define SOCKET_TIMEOUT 50
>
> +#ifndef _WIN32
> +# define CMD_EXEC   "exec "
> +# define DEV_STDERR "/dev/fd/2"
> +# define DEV_NULL   "/dev/null"
> +#else
> +# define CMD_EXEC   ""
> +# define DEV_STDERR "2"
> +# define DEV_NULL   "nul"
> +#endif
> +
>  typedef void (*QTestSendFn)(QTestState *s, const char *buf);
>  typedef void (*ExternalSendFn)(void *s, const char *buf);
>  typedef GString* (*QTestRecvFn)(QTestState *);
> @@ -68,6 +81,9 @@ struct QTestState
>  QTestState *global_qtest;
>
>  static GHookList abrt_hooks;
> +#ifdef _WIN32
> +typedef void (*sighandler_t)(int);
> +#endif
>  static sighandler_t sighandler_old;
>
>  static int qtest_query_target_endianness(QTestState *s);
> @@ -120,10 +136,18 @@ bool qtest_probe_child(QTestState *s)
>      pid_t pid = s->qemu_pid;
>
>      if (pid != -1) {
> +#ifndef _WIN32
>          pid = waitpid(pid, &s->wstatus, WNOHANG);
>          if (pid == 0) {
>              return true;
>          }
> +#else
> +        DWORD exit_code;
> +        GetExitCodeProcess((HANDLE)pid, &exit_code);
> +        if (exit_code == STILL_ACTIVE) {
> +            return true;
> +        }
> +#endif
>          s->qemu_pid = -1;
>      }
>      return false;
> @@ -137,13 +161,23 @@ void qtest_set_expected_status(QTestState *s, int
> status)
>  void qtest_kill_qemu(QTestState *s)
>  {
>      pid_t pid = s->qemu_pid;
> +#ifndef _WIN32
>      int wstatus;
> +#else
> +    DWORD ret, exit_code;
> +#endif
>
>      /* Skip wait if qtest_probe_child already reaped.  */
>      if (pid != -1) {
> +#ifndef _WIN32
>          kill(pid, SIGTERM);
>          TFR(pid = waitpid(s->qemu_pid, &s->wstatus, 0));
>          assert(pid == s->qemu_pid);
> +#else
> +        TerminateProcess((HANDLE)pid, s->expected_status);
> +        ret = WaitForSingleObject((HANDLE)pid, INFINITE);
> +        assert(ret == WAIT_OBJECT_0);
> +#endif
>          s->qemu_pid = -1;
>      }
>
> @@ -151,6 +185,7 @@ void qtest_kill_qemu(QTestState *s)
>       * Check whether qemu exited with expected exit status; anything else
> is
>       * fishy and should be logged with as much detail as possible.
>       */
> +#ifndef _WIN32
>      wstatus = s->wstatus;
>      if (WIFEXITED(wstatus) && WEXITSTATUS(wstatus) != s->expected_status)
> {
>          fprintf(stderr, "%s:%d: kill_qemu() tried to terminate QEMU "
> @@ -167,6 +202,16 @@ void qtest_kill_qemu(QTestState *s)
>                  __FILE__, __LINE__, sig, signame, dump);
>          abort();
>      }
> +#else
> +    GetExitCodeProcess((HANDLE)pid, &exit_code);
> +    CloseHandle((HANDLE)pid);
> +    if (exit_code != s->expected_status) {
> +        fprintf(stderr, "%s:%d: kill_qemu() tried to terminate QEMU "
> +                "process but encountered exit status %ld (expected %d)\n",
> +                __FILE__, __LINE__, exit_code, s->expected_status);
> +        abort();
> +    }
> +#endif
>  }
>
>  static void kill_qemu_hook_func(void *s)
> @@ -245,6 +290,38 @@ static const char *qtest_qemu_binary(void)
>      return qemu_bin;
>  }
>
> +#ifdef _WIN32
> +static pid_t qtest_create_process(char *cmd)
> +{
> +    STARTUPINFO si;
> +    PROCESS_INFORMATION pi;
> +    BOOL ret;
> +
> +    ZeroMemory(&si, sizeof(si));
> +    si.cb = sizeof(si);
> +    ZeroMemory(&pi, sizeof(pi));
> +
> +    ret = CreateProcess(NULL,   /* module name */
> +                        cmd,    /* command line */
> +                        NULL,   /* process handle not inheritable */
> +                        NULL,   /* thread handle not inheritable */
> +                        FALSE,  /* set handle inheritance to FALSE */
> +                        0,      /* No creation flags */
> +                        NULL,   /* use parent's environment block */
> +                        NULL,   /* use parent's starting directory */
> +                        &si,    /* pointer to STARTUPINFO structure */
> +                        &pi     /* pointer to PROCESS_INFORMATION
> structure */
> +                        );
> +    if (ret == 0) {
> +        fprintf(stderr, "%s:%d: unable to create a new process (%s)\n",
> +                __FILE__, __LINE__, strerror(GetLastError()));
> +        abort();
> +    }
> +
> +    return (pid_t)pi.hProcess;
> +}
> +#endif /* _WIN32 */
> +
>  QTestState *qtest_init_without_qmp_handshake(const char *extra_args)
>  {
>      QTestState *s;
> @@ -272,6 +349,9 @@ QTestState *qtest_init_without_qmp_handshake(const
> char *extra_args)
>      unlink(socket_path);
>      unlink(qmp_socket_path);
>
> +#ifdef _WIN32
> +    socket_init();
> +#endif
>

You can call this unconditionally, afaict


>      sock = init_socket(socket_path);
>      qmpsock = init_socket(qmp_socket_path);
>
> @@ -280,7 +360,7 @@ QTestState *qtest_init_without_qmp_handshake(const
> char *extra_args)
>
>      qtest_add_abrt_handler(kill_qemu_hook_func, s);
>
> -    command = g_strdup_printf("exec %s %s"
> +    command = g_strdup_printf(CMD_EXEC "%s %s"
>                                "-qtest unix:%s "
>                                "-qtest-log %s "
>                                "-chardev socket,path=%s,id=char0 "
> @@ -289,7 +369,7 @@ QTestState *qtest_init_without_qmp_handshake(const
> char *extra_args)
>                                "%s"
>                                " -accel qtest",
>                                qemu_binary, tracearg, socket_path,
> -                              getenv("QTEST_LOG") ? "/dev/fd/2" :
> "/dev/null",
> +                              getenv("QTEST_LOG") ? DEV_STDERR : DEV_NULL,
>                                qmp_socket_path,
>                                extra_args ?: "");
>
> @@ -298,6 +378,7 @@ QTestState *qtest_init_without_qmp_handshake(const
> char *extra_args)
>      s->pending_events = NULL;
>      s->wstatus = 0;
>      s->expected_status = 0;
> +#ifndef _WIN32
>      s->qemu_pid = fork();
>      if (s->qemu_pid == 0) {
>  #ifdef __linux__
> @@ -320,6 +401,9 @@ QTestState *qtest_init_without_qmp_handshake(const
> char *extra_args)
>          execlp("/bin/sh", "sh", "-c", command, NULL);
>          exit(1);
>      }
> +#else
> +    s->qemu_pid = qtest_create_process(command);
>

Why not replace the fork/exec with g_spawn_async() ?


> +#endif /* _WIN32 */
>
>      g_free(command);
>      s->fd = socket_accept(sock);
> @@ -338,9 +422,19 @@ QTestState *qtest_init_without_qmp_handshake(const
> char *extra_args)
>          s->irq_level[i] = false;
>      }
>
> +    /*
> +     * Stopping QEMU for debugging is not supported on Windows.
> +     *
> +     * Using DebugActiveProcess() API can suspend the QEMU process,
> +     * but gdb cannot attach to the process. Using the undocumented
> +     * NtSuspendProcess() can suspend the QEMU process and gdb can
> +     * attach to the process, but gdb cannot resume it.
> +     */
> +#ifndef _WIN32
>      if (getenv("QTEST_STOP")) {
>          kill(s->qemu_pid, SIGSTOP);
>      }
> +#endif
>
>      /* ask endianness of the target */
>
> @@ -393,6 +487,9 @@ QTestState *qtest_init_with_serial(const char
> *extra_args, int *sock_fd)
>      g_assert_true(g_mkdtemp(sock_dir) != NULL);
>      sock_path = g_strdup_printf("%s/sock", sock_dir);
>
> +#ifdef _WIN32
> +    socket_init();
> +#endif
>

same


>      sock_fd_init = init_socket(sock_path);
>
>      qts = qtest_initf("-chardev socket,id=s0,path=%s -serial chardev:s0
> %s",
> diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
> index 0291b3966c..6d469a1822 100644
> --- a/tests/qtest/meson.build
> +++ b/tests/qtest/meson.build
> @@ -1,6 +1,5 @@
> -# All QTests for now are POSIX-only, but the dependencies are
> -# really in libqtest, not in the testcases themselves.
> -if not config_host.has_key('CONFIG_POSIX')
> +# Build all QTests for POSIX and Windows
> +if not config_host.has_key('CONFIG_POSIX') and not
> config_host.has_key('CONFIG_WIN32')
>    subdir_done()
>  endif
>
> --
> 2.34.1
>
>
>
lgtm otherwise

-- 
Marc-André Lureau

[-- Attachment #2: Type: text/html, Size: 12538 bytes --]

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

* Re: [PATCH 03/51] block: Unify the get_tmp_filename() implementation
  2022-08-31 12:54   ` Marc-André Lureau
  2022-08-31 13:19     ` Daniel P. Berrangé
@ 2022-09-01  6:41     ` Bin Meng
  1 sibling, 0 replies; 174+ messages in thread
From: Bin Meng @ 2022-09-01  6:41 UTC (permalink / raw)
  To: Marc-André Lureau
  Cc: qemu-devel@nongnu.org Developers, Bin Meng, Hanna Reitz,
	Kevin Wolf, Qemu-block

Hi Marc-André,

On Wed, Aug 31, 2022 at 8:54 PM Marc-André Lureau
<marcandre.lureau@gmail.com> wrote:
>
> Hi Bin
>
> On Wed, Aug 24, 2022 at 1:42 PM Bin Meng <bmeng.cn@gmail.com> wrote:
>>
>> From: Bin Meng <bin.meng@windriver.com>
>>
>> At present get_tmp_filename() has platform specific implementations
>> to get the directory to use for temporary files. Switch over to use
>> g_get_tmp_dir() which works on all supported platforms.
>>
>
> It "works" quite differently though. Is this patch really necessary here?

Without this patch the qtest cases builds on Windows do not have any
problem. So it is optional. I put it in the same series as it has the
same context of using hardcoded /tmp directory name.

>
> If yes, please explain why.
>
> If not, I suggest you drop optional / rfc / "nice to have" patches from the series. It will help to get it merged faster.

I can drop this single patch and send another single patch if this is
the desired practice.

>
> thanks

Regards,
Bin


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

* Re: [PATCH 04/51] semihosting/arm-compat-semi: Avoid using hardcoded /tmp
  2022-08-31 12:59   ` Marc-André Lureau
@ 2022-09-01  7:11     ` Bin Meng
  2022-09-01  9:20       ` Richard Henderson
  0 siblings, 1 reply; 174+ messages in thread
From: Bin Meng @ 2022-09-01  7:11 UTC (permalink / raw)
  To: Marc-André Lureau
  Cc: qemu-devel@nongnu.org Developers, Bin Meng, Alex Bennée

On Wed, Aug 31, 2022 at 8:59 PM Marc-André Lureau
<marcandre.lureau@gmail.com> wrote:
>
> Hi
>
> On Wed, Aug 24, 2022 at 1:54 PM Bin Meng <bmeng.cn@gmail.com> wrote:
>>
>> From: Bin Meng <bin.meng@windriver.com>
>>
>> Use g_get_tmp_dir() to get the directory to use for temporary files.
>>
>> Signed-off-by: Bin Meng <bin.meng@windriver.com>
>> ---
>>
>>  semihosting/arm-compat-semi.c | 3 ++-
>>  1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c
>> index e741674238..d5e66cc298 100644
>> --- a/semihosting/arm-compat-semi.c
>> +++ b/semihosting/arm-compat-semi.c
>> @@ -503,7 +503,8 @@ void do_common_semihosting(CPUState *cs)
>>          GET_ARG(0);
>>          GET_ARG(1);
>>          GET_ARG(2);
>> -        len = asprintf(&s, "/tmp/qemu-%x%02x", getpid(), (int)arg1 & 0xff);
>> +        len = asprintf(&s, "%s/qemu-%x%02x", g_get_tmp_dir(),
>> +                       getpid(), (int)arg1 & 0xff);
>
>
> This is most likely wrong. I am not familiar with semihosting, but I believe we are implementing tmpnam(), it should return a POSIX filename.

Replacing /tmp with g_get_tmp_dir() is not wrong, correct?

I checked the semihosting spec, it does not mention the file name
should be a POSIX compliant path.
https://developer.arm.com/documentation/dui0058/d/semihosting/semihosting-swis/sys-tmpnam--0x0d-

Certainly this needs a semihosting expert to take a look.

>
>>
>>          if (len < 0) {
>>              common_semi_set_ret(cs, -1);
>>              break;
>> --

Regards,
Bin


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

* Re: [PATCH 32/51] tests/qtest: Fix ERROR_SHARING_VIOLATION for win32
  2022-08-24  9:40 ` [PATCH 32/51] tests/qtest: Fix ERROR_SHARING_VIOLATION for win32 Bin Meng
  2022-08-25 12:06   ` Thomas Huth
@ 2022-09-01  8:42   ` Marc-André Lureau
  2022-09-02 11:02     ` Bin Meng
  1 sibling, 1 reply; 174+ messages in thread
From: Marc-André Lureau @ 2022-09-01  8:42 UTC (permalink / raw)
  To: Bin Meng
  Cc: qemu-devel, Bin Meng, John Snow, Laurent Vivier, Paolo Bonzini,
	Thomas Huth, qemu-block

[-- Attachment #1: Type: text/plain, Size: 2611 bytes --]

Hi

On Wed, Aug 24, 2022 at 2:03 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Bin Meng <bin.meng@windriver.com>
>
> On Windows, the MinGW provided mkstemp() API opens the file with
> exclusive access, denying other processes to read/write the file.
> Such behavior prevents the QEMU executable from opening the file,
> (e.g.: CreateFile returns ERROR_SHARING_VIOLATION).
>

g_mkstemp() doesn't have this behaviour (after running a quick test). Use
it?


>
> This can be fixed by closing the file and reopening it.
>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
>
>  tests/qtest/ahci-test.c        | 14 ++++++++++++++
>  tests/qtest/boot-serial-test.c | 13 +++++++++++++
>  2 files changed, 27 insertions(+)
>
> diff --git a/tests/qtest/ahci-test.c b/tests/qtest/ahci-test.c
> index f26cd6f86f..0e88cd0eef 100644
> --- a/tests/qtest/ahci-test.c
> +++ b/tests/qtest/ahci-test.c
> @@ -1443,6 +1443,20 @@ static int prepare_iso(size_t size, unsigned char
> **buf, char **name)
>      int fd = mkstemp(cdrom_path);
>
>      g_assert(fd != -1);
> +#ifdef _WIN32
> +    /*
> +     * On Windows, the MinGW provided mkstemp() API opens the file with
> +     * exclusive access, denying other processes to read/write the file.
> +     * Such behavior prevents the QEMU executable from opening the file,
> +     * (e.g.: CreateFile returns ERROR_SHARING_VIOLATION).
> +     *
> +     * Close the file and reopen it.
> +     */
> +    close(fd);
> +    fd = open(cdrom_path, O_WRONLY);
> +    g_assert(fd != -1);
> +#endif
> +
>      g_assert(buf);
>      g_assert(name);
>      patt = g_malloc(size);
> diff --git a/tests/qtest/boot-serial-test.c
> b/tests/qtest/boot-serial-test.c
> index 404adcfa20..fb6c81bf35 100644
> --- a/tests/qtest/boot-serial-test.c
> +++ b/tests/qtest/boot-serial-test.c
> @@ -235,6 +235,19 @@ static void test_machine(const void *data)
>
>      ser_fd = mkstemp(serialtmp);
>      g_assert(ser_fd != -1);
> +#ifdef _WIN32
> +    /*
> +     * On Windows, the MinGW provided mkstemp() API opens the file with
> +     * exclusive access, denying other processes to read/write the file.
> +     * Such behavior prevents the QEMU executable from opening the file,
> +     * (e.g.: CreateFile returns ERROR_SHARING_VIOLATION).
> +     *
> +     * Close the file and reopen it.
> +     */
> +    close(ser_fd);
> +    ser_fd = open(serialtmp, O_RDONLY);
> +    g_assert(ser_fd != -1);
> +#endif
>
>      if (test->kernel) {
>          code = test->kernel;
> --
> 2.34.1
>
>
>

-- 
Marc-André Lureau

[-- Attachment #2: Type: text/html, Size: 3522 bytes --]

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

* Re: [PATCH 33/51] tests/qtest: {ahci, ide}-test: Use relative path for temporary files
  2022-08-24  9:40 ` [PATCH 33/51] tests/qtest: {ahci, ide}-test: Use relative path for temporary files Bin Meng
@ 2022-09-01  8:58   ` Marc-André Lureau
  2022-09-03 13:30     ` Bin Meng
  0 siblings, 1 reply; 174+ messages in thread
From: Marc-André Lureau @ 2022-09-01  8:58 UTC (permalink / raw)
  To: Bin Meng, Kevin Wolf, Hanna Reitz
  Cc: qemu-devel, Bin Meng, John Snow, Laurent Vivier, Paolo Bonzini,
	Thomas Huth, qemu-block

[-- Attachment #1: Type: text/plain, Size: 3710 bytes --]

On Wed, Aug 24, 2022 at 2:55 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Bin Meng <bin.meng@windriver.com>
>
> These test cases uses "blkdebug:path/to/config:path/to/image" for
> testing. On Windows, absolute file paths contain the delimiter ':'
> which causes the blkdebug filename parser fail to parse filenames.
>
>
hmm.. maybe it should learn to escape paths..


Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
>
>  tests/qtest/ahci-test.c | 19 ++++++++++++++++---
>  tests/qtest/ide-test.c  | 18 ++++++++++++++++--
>  2 files changed, 32 insertions(+), 5 deletions(-)
>
> diff --git a/tests/qtest/ahci-test.c b/tests/qtest/ahci-test.c
> index 0e88cd0eef..bce9ff770c 100644
> --- a/tests/qtest/ahci-test.c
> +++ b/tests/qtest/ahci-test.c
> @@ -1848,7 +1848,7 @@ static void create_ahci_io_test(enum IOMode type,
> enum AddrMode addr,
>
>  int main(int argc, char **argv)
>  {
> -    const char *arch;
> +    const char *arch, *base;
>      int ret;
>      int fd;
>      int c;
> @@ -1886,8 +1886,21 @@ int main(int argc, char **argv)
>          return 0;
>      }
>
> +    /*
> +     * "base" stores the starting point where we create temporary files.
> +     *
> +     * On Windows, this is set to the relative path of current working
> +     * directory, because the absolute path causes the blkdebug filename
> +     * parser fail to parse "blkdebug:path/to/config:path/to/image".
> +     */
> +#ifndef _WIN32
> +    base = g_get_tmp_dir();
> +#else
> +    base = ".";
> +#endif
>

Meanwhile, that seems reasonable. Perhaps chdir() to the temporary
directory first? (assuming other paths are absolute)


> +
>      /* Create a temporary image */
> -    tmp_path = g_strdup_printf("%s/qtest.XXXXXX", g_get_tmp_dir());
> +    tmp_path = g_strdup_printf("%s/qtest.XXXXXX", base);
>      fd = mkstemp(tmp_path);
>      g_assert(fd >= 0);
>      if (have_qemu_img()) {
> @@ -1905,7 +1918,7 @@ int main(int argc, char **argv)
>      close(fd);
>
>      /* Create temporary blkdebug instructions */
> -    debug_path = g_strdup_printf("%s/qtest-blkdebug.XXXXXX",
> g_get_tmp_dir());
> +    debug_path = g_strdup_printf("%s/qtest-blkdebug.XXXXXX", base);
>      fd = mkstemp(debug_path);
>      g_assert(fd >= 0);
>      close(fd);
> diff --git a/tests/qtest/ide-test.c b/tests/qtest/ide-test.c
> index ebbf8e0126..c5cad6c0be 100644
> --- a/tests/qtest/ide-test.c
> +++ b/tests/qtest/ide-test.c
> @@ -1011,17 +1011,31 @@ static void test_cdrom_dma(void)
>
>  int main(int argc, char **argv)
>  {
> +    const char *base;
>      int fd;
>      int ret;
>
> +    /*
> +     * "base" stores the starting point where we create temporary files.
> +     *
> +     * On Windows, this is set to the relative path of current working
> +     * directory, because the absolute path causes the blkdebug filename
> +     * parser fail to parse "blkdebug:path/to/config:path/to/image".
> +     */
> +#ifndef _WIN32
> +    base = g_get_tmp_dir();
> +#else
> +    base = ".";
> +#endif
> +
>      /* Create temporary blkdebug instructions */
> -    debug_path = g_strdup_printf("%s/qtest-blkdebug.XXXXXX",
> g_get_tmp_dir());
> +    debug_path = g_strdup_printf("%s/qtest-blkdebug.XXXXXX", base);
>      fd = mkstemp(debug_path);
>      g_assert(fd >= 0);
>      close(fd);
>
>      /* Create a temporary raw image */
> -    tmp_path = g_strdup_printf("%s/qtest.XXXXXX", g_get_tmp_dir());
> +    tmp_path = g_strdup_printf("%s/qtest.XXXXXX", base);
>      fd = mkstemp(tmp_path);
>      g_assert(fd >= 0);
>      ret = ftruncate(fd, TEST_IMAGE_SIZE);
> --
> 2.34.1
>
>
>

-- 
Marc-André Lureau

[-- Attachment #2: Type: text/html, Size: 5083 bytes --]

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

* Re: [PATCH 34/51] tests/qtest: bios-tables-test: Adapt the case for win32
  2022-08-24  9:40 ` [PATCH 34/51] tests/qtest: bios-tables-test: Adapt the case for win32 Bin Meng
  2022-08-24 12:42   ` Ani Sinha
@ 2022-09-01  9:05   ` Marc-André Lureau
  1 sibling, 0 replies; 174+ messages in thread
From: Marc-André Lureau @ 2022-09-01  9:05 UTC (permalink / raw)
  To: Bin Meng
  Cc: qemu-devel, Bin Meng, Ani Sinha, Igor Mammedov, Michael S. Tsirkin

[-- Attachment #1: Type: text/plain, Size: 1965 bytes --]

On Wed, Aug 24, 2022 at 3:02 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Bin Meng <bin.meng@windriver.com>
>
> Single quotes in the arguments (oem_id='CRASH ') are not removed in
> the Windows environment before it is passed to the QEMU executable.
> The space in the argument causes the "-acpitable" option parser to
> think that all of its parameters are done, hence it complains:
>
>   '-acpitable' requires one of 'data' or 'file'
>
> Change to use double quotes which works fine on all platforms.
>
> Also /dev/null does not work on win32, and nul should be used.
>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
>

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


> ---
>
>  tests/qtest/bios-tables-test.c | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/tests/qtest/bios-tables-test.c
> b/tests/qtest/bios-tables-test.c
> index 36783966b0..0148ce388c 100644
> --- a/tests/qtest/bios-tables-test.c
> +++ b/tests/qtest/bios-tables-test.c
> @@ -1615,6 +1615,12 @@ static void test_acpi_virt_viot(void)
>      free_test_data(&data);
>  }
>
> +#ifndef _WIN32
> +# define DEV_NULL "/dev/null"
> +#else
> +# define DEV_NULL "nul"
> +#endif
> +
>  static void test_acpi_q35_slic(void)
>  {
>      test_data data = {
> @@ -1622,9 +1628,9 @@ static void test_acpi_q35_slic(void)
>          .variant = ".slic",
>      };
>
> -    test_acpi_one("-acpitable sig=SLIC,oem_id='CRASH ',oem_table_id='ME',"
> -                  "oem_rev=00002210,asl_compiler_id='qemu',"
> -                  "asl_compiler_rev=00000000,data=/dev/null",
> +    test_acpi_one("-acpitable sig=SLIC,oem_id=\"CRASH \",oem_table_id=ME,"
> +                  "oem_rev=00002210,asl_compiler_id=qemu,"
> +                  "asl_compiler_rev=00000000,data=" DEV_NULL,
>                    &data);
>      free_test_data(&data);
>  }
> --
> 2.34.1
>
>
>

-- 
Marc-André Lureau

[-- Attachment #2: Type: text/html, Size: 3052 bytes --]

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

* Re: [PATCH 38/51] tests/qtest: {ahci, ide}-test: Open file in binary mode
  2022-08-24  9:40 ` [PATCH 38/51] tests/qtest: {ahci,ide}-test: Open file in binary mode Bin Meng
  2022-08-25 12:28   ` Thomas Huth
@ 2022-09-01  9:08   ` Marc-André Lureau
  1 sibling, 0 replies; 174+ messages in thread
From: Marc-André Lureau @ 2022-09-01  9:08 UTC (permalink / raw)
  To: Bin Meng
  Cc: qemu-devel, Xuzhou Cheng, Bin Meng, John Snow, Laurent Vivier,
	Paolo Bonzini, Thomas Huth, qemu-block

[-- Attachment #1: Type: text/plain, Size: 2513 bytes --]

Hi

On Wed, Aug 24, 2022 at 3:08 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Xuzhou Cheng <xuzhou.cheng@windriver.com>
>
> By default Windows opens file in text mode, while a POSIX compliant
> implementation treats text files and binary files the same.
>
> The fopen() 'mode' string can include the letter 'b' to indicate
> binary mode shall be used. POSIX spec says the character 'b' shall
> have no effect, but is allowed for ISO C standard conformance.
> Let's add the letter 'b' which works on both POSIX and Windows.
>
> Similar situation applies to the open() 'flags' where O_BINARY is
> used for binary mode.
>
> Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
>
>  tests/qtest/ahci-test.c | 2 +-
>  tests/qtest/ide-test.c  | 4 ++--
>  2 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/tests/qtest/ahci-test.c b/tests/qtest/ahci-test.c
> index bce9ff770c..be11508c75 100644
> --- a/tests/qtest/ahci-test.c
> +++ b/tests/qtest/ahci-test.c
> @@ -1453,7 +1453,7 @@ static int prepare_iso(size_t size, unsigned char
> **buf, char **name)
>       * Close the file and reopen it.
>       */
>      close(fd);
> -    fd = open(cdrom_path, O_WRONLY);
> +    fd = open(cdrom_path, O_WRONLY | O_BINARY);
>      g_assert(fd != -1);
>

that should be gone in next iteration, with g_mkstemp() usage.


>  #endif
>
> diff --git a/tests/qtest/ide-test.c b/tests/qtest/ide-test.c
> index c5cad6c0be..ee03dea4fa 100644
> --- a/tests/qtest/ide-test.c
> +++ b/tests/qtest/ide-test.c
> @@ -892,7 +892,7 @@ static void cdrom_pio_impl(int nblocks)
>
>      /* Prepopulate the CDROM with an interesting pattern */
>      generate_pattern(pattern, patt_len, ATAPI_BLOCK_SIZE);
> -    fh = fopen(tmp_path, "w+");
> +    fh = fopen(tmp_path, "wb+");
>      ret = fwrite(pattern, ATAPI_BLOCK_SIZE, patt_blocks, fh);
>      g_assert_cmpint(ret, ==, patt_blocks);
>      fclose(fh);
> @@ -993,7 +993,7 @@ static void test_cdrom_dma(void)
>      prdt[0].size = cpu_to_le32(len | PRDT_EOT);
>
>      generate_pattern(pattern, ATAPI_BLOCK_SIZE * 16, ATAPI_BLOCK_SIZE);
> -    fh = fopen(tmp_path, "w+");
> +    fh = fopen(tmp_path, "wb+");
>      ret = fwrite(pattern, ATAPI_BLOCK_SIZE, 16, fh);
>      g_assert_cmpint(ret, ==, 16);
>      fclose(fh);
> --
> 2.34.1
>
>
>
ack this part,
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>


-- 
Marc-André Lureau

[-- Attachment #2: Type: text/html, Size: 3609 bytes --]

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

* Re: [PATCH 04/51] semihosting/arm-compat-semi: Avoid using hardcoded /tmp
  2022-09-01  7:11     ` Bin Meng
@ 2022-09-01  9:20       ` Richard Henderson
  0 siblings, 0 replies; 174+ messages in thread
From: Richard Henderson @ 2022-09-01  9:20 UTC (permalink / raw)
  To: Bin Meng, Marc-André Lureau
  Cc: qemu-devel@nongnu.org Developers, Bin Meng, Alex Bennée

On 9/1/22 08:11, Bin Meng wrote:
>>> -        len = asprintf(&s, "/tmp/qemu-%x%02x", getpid(), (int)arg1 & 0xff);
>>> +        len = asprintf(&s, "%s/qemu-%x%02x", g_get_tmp_dir(),
>>> +                       getpid(), (int)arg1 & 0xff);
>>
>>
>> This is most likely wrong. I am not familiar with semihosting, but I believe we are implementing tmpnam(), it should return a POSIX filename.
> 
> Replacing /tmp with g_get_tmp_dir() is not wrong, correct?

The replacement is correct.


r~


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

* Re: [PATCH 41/51] tests/qtest: migration-test: Kill "to" after migration is canceled
  2022-08-24 18:56   ` Dr. David Alan Gilbert
@ 2022-09-01 11:35     ` Marc-André Lureau
  2022-09-02 16:33       ` Bin Meng
  0 siblings, 1 reply; 174+ messages in thread
From: Marc-André Lureau @ 2022-09-01 11:35 UTC (permalink / raw)
  To: Dr. David Alan Gilbert
  Cc: Bin Meng, qemu-devel, Xuzhou Cheng, Bin Meng, Juan Quintela,
	Laurent Vivier, Paolo Bonzini, Thomas Huth

[-- Attachment #1: Type: text/plain, Size: 1504 bytes --]

Hi

On Wed, Aug 24, 2022 at 10:56 PM Dr. David Alan Gilbert <dgilbert@redhat.com>
wrote:

> * Bin Meng (bmeng.cn@gmail.com) wrote:
> > From: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> >
> > Make sure QEMU process "to" is killed before launching another target
> > for migration in the test_multifd_tcp_cancel case.
> >
> > Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> > Signed-off-by: Bin Meng <bin.meng@windriver.com>
> > ---
> >
> >  tests/qtest/migration-test.c | 4 ++++
> >  1 file changed, 4 insertions(+)
> >
> > diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
> > index 125d48d855..18ec079abf 100644
> > --- a/tests/qtest/migration-test.c
> > +++ b/tests/qtest/migration-test.c
> > @@ -2132,6 +2132,10 @@ static void test_multifd_tcp_cancel(void)
> >      wait_for_migration_pass(from);
> >
> >      migrate_cancel(from);
> > +    /* Make sure QEMU process "to" is killed */
> > +    if (qtest_probe_child(to)) {
> > +        qtest_kill_qemu(to);
> > +    }
>
> I'm not sure that's safe - what happens if the qemu exits between the
> probe and kill?
>

It looks safe to me, qtest_probe_child() resets the qemu_pid if it already
exited. Otherwise, there is a process/handle waiting for
waitpid/CloseHandle done in qtest_kill_qemu().

We are missing a CloseHandle() in qtest_probe_child() though, I'll send a
patch.

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

-- 
Marc-André Lureau

[-- Attachment #2: Type: text/html, Size: 2447 bytes --]

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

* Re: [PATCH 31/51] tests/qtest: Support libqtest to build and run on Windows
  2022-08-24  9:40 ` [PATCH 31/51] tests/qtest: Support libqtest to build and run on Windows Bin Meng
  2022-08-31 16:28   ` Marc-André Lureau
@ 2022-09-01 11:38   ` Marc-André Lureau
  1 sibling, 0 replies; 174+ messages in thread
From: Marc-André Lureau @ 2022-09-01 11:38 UTC (permalink / raw)
  To: Bin Meng
  Cc: qemu-devel, Bin Meng, Xuzhou Cheng, Laurent Vivier,
	Paolo Bonzini, Thomas Huth

[-- Attachment #1: Type: text/plain, Size: 9604 bytes --]

Hi

On Wed, Aug 24, 2022 at 2:46 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Bin Meng <bin.meng@windriver.com>
>
> At present the libqtest codes were written to depend on several
> POSIX APIs, including fork(), kill() and waitpid(). Unfortunately
> these APIs are not available on Windows.
>
> This commit implements the corresponding functionalities using
> win32 native APIs. With this change, all qtest cases can build
> successfully on a Windows host, and we can start qtest testing
> on Windows now.
>
> Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
>
>  tests/qtest/libqtest.c  | 101 +++++++++++++++++++++++++++++++++++++++-
>  tests/qtest/meson.build |   5 +-
>  2 files changed, 101 insertions(+), 5 deletions(-)
>
> diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
> index 70d7578740..99e52ff571 100644
> --- a/tests/qtest/libqtest.c
> +++ b/tests/qtest/libqtest.c
> @@ -16,9 +16,11 @@
>
>  #include "qemu/osdep.h"
>
> +#ifndef _WIN32
>  #include <sys/socket.h>
>  #include <sys/wait.h>
>  #include <sys/un.h>
> +#endif /* _WIN32 */
>  #ifdef __linux__
>  #include <sys/prctl.h>
>  #endif /* __linux__ */
> @@ -27,6 +29,7 @@
>  #include "libqmp.h"
>  #include "qemu/ctype.h"
>  #include "qemu/cutils.h"
> +#include "qemu/sockets.h"
>  #include "qapi/qmp/qdict.h"
>  #include "qapi/qmp/qjson.h"
>  #include "qapi/qmp/qlist.h"
> @@ -35,6 +38,16 @@
>  #define MAX_IRQ 256
>  #define SOCKET_TIMEOUT 50
>
> +#ifndef _WIN32
> +# define CMD_EXEC   "exec "
> +# define DEV_STDERR "/dev/fd/2"
> +# define DEV_NULL   "/dev/null"
> +#else
> +# define CMD_EXEC   ""
> +# define DEV_STDERR "2"
> +# define DEV_NULL   "nul"
> +#endif
> +
>  typedef void (*QTestSendFn)(QTestState *s, const char *buf);
>  typedef void (*ExternalSendFn)(void *s, const char *buf);
>  typedef GString* (*QTestRecvFn)(QTestState *);
> @@ -68,6 +81,9 @@ struct QTestState
>  QTestState *global_qtest;
>
>  static GHookList abrt_hooks;
> +#ifdef _WIN32
> +typedef void (*sighandler_t)(int);
> +#endif
>  static sighandler_t sighandler_old;
>
>  static int qtest_query_target_endianness(QTestState *s);
> @@ -120,10 +136,18 @@ bool qtest_probe_child(QTestState *s)
>      pid_t pid = s->qemu_pid;
>
>      if (pid != -1) {
> +#ifndef _WIN32
>          pid = waitpid(pid, &s->wstatus, WNOHANG);
>          if (pid == 0) {
>              return true;
>          }
> +#else
> +        DWORD exit_code;
> +        GetExitCodeProcess((HANDLE)pid, &exit_code);
> +        if (exit_code == STILL_ACTIVE) {
> +            return true;
> +        }
>

Missing a CloseHandle((HANDLE)pid) here.


> +#endif
>          s->qemu_pid = -1;
>      }
>      return false;
> @@ -137,13 +161,23 @@ void qtest_set_expected_status(QTestState *s, int
> status)
>  void qtest_kill_qemu(QTestState *s)
>  {
>      pid_t pid = s->qemu_pid;
> +#ifndef _WIN32
>      int wstatus;
> +#else
> +    DWORD ret, exit_code;
> +#endif
>
>      /* Skip wait if qtest_probe_child already reaped.  */
>      if (pid != -1) {
> +#ifndef _WIN32
>          kill(pid, SIGTERM);
>          TFR(pid = waitpid(s->qemu_pid, &s->wstatus, 0));
>          assert(pid == s->qemu_pid);
> +#else
> +        TerminateProcess((HANDLE)pid, s->expected_status);
> +        ret = WaitForSingleObject((HANDLE)pid, INFINITE);
> +        assert(ret == WAIT_OBJECT_0);
> +#endif
>          s->qemu_pid = -1;
>      }
>
> @@ -151,6 +185,7 @@ void qtest_kill_qemu(QTestState *s)
>       * Check whether qemu exited with expected exit status; anything else
> is
>       * fishy and should be logged with as much detail as possible.
>       */
> +#ifndef _WIN32
>      wstatus = s->wstatus;
>      if (WIFEXITED(wstatus) && WEXITSTATUS(wstatus) != s->expected_status)
> {
>          fprintf(stderr, "%s:%d: kill_qemu() tried to terminate QEMU "
> @@ -167,6 +202,16 @@ void qtest_kill_qemu(QTestState *s)
>                  __FILE__, __LINE__, sig, signame, dump);
>          abort();
>      }
> +#else
> +    GetExitCodeProcess((HANDLE)pid, &exit_code);
> +    CloseHandle((HANDLE)pid);
> +    if (exit_code != s->expected_status) {
> +        fprintf(stderr, "%s:%d: kill_qemu() tried to terminate QEMU "
> +                "process but encountered exit status %ld (expected %d)\n",
> +                __FILE__, __LINE__, exit_code, s->expected_status);
> +        abort();
> +    }
> +#endif
>  }
>
>  static void kill_qemu_hook_func(void *s)
> @@ -245,6 +290,38 @@ static const char *qtest_qemu_binary(void)
>      return qemu_bin;
>  }
>
> +#ifdef _WIN32
> +static pid_t qtest_create_process(char *cmd)
> +{
> +    STARTUPINFO si;
> +    PROCESS_INFORMATION pi;
> +    BOOL ret;
> +
> +    ZeroMemory(&si, sizeof(si));
> +    si.cb = sizeof(si);
> +    ZeroMemory(&pi, sizeof(pi));
> +
> +    ret = CreateProcess(NULL,   /* module name */
> +                        cmd,    /* command line */
> +                        NULL,   /* process handle not inheritable */
> +                        NULL,   /* thread handle not inheritable */
> +                        FALSE,  /* set handle inheritance to FALSE */
> +                        0,      /* No creation flags */
> +                        NULL,   /* use parent's environment block */
> +                        NULL,   /* use parent's starting directory */
> +                        &si,    /* pointer to STARTUPINFO structure */
> +                        &pi     /* pointer to PROCESS_INFORMATION
> structure */
> +                        );
> +    if (ret == 0) {
> +        fprintf(stderr, "%s:%d: unable to create a new process (%s)\n",
> +                __FILE__, __LINE__, strerror(GetLastError()));
> +        abort();
> +    }
> +
> +    return (pid_t)pi.hProcess;
> +}
> +#endif /* _WIN32 */
> +
>  QTestState *qtest_init_without_qmp_handshake(const char *extra_args)
>  {
>      QTestState *s;
> @@ -272,6 +349,9 @@ QTestState *qtest_init_without_qmp_handshake(const
> char *extra_args)
>      unlink(socket_path);
>      unlink(qmp_socket_path);
>
> +#ifdef _WIN32
> +    socket_init();
> +#endif
>      sock = init_socket(socket_path);
>      qmpsock = init_socket(qmp_socket_path);
>
> @@ -280,7 +360,7 @@ QTestState *qtest_init_without_qmp_handshake(const
> char *extra_args)
>
>      qtest_add_abrt_handler(kill_qemu_hook_func, s);
>
> -    command = g_strdup_printf("exec %s %s"
> +    command = g_strdup_printf(CMD_EXEC "%s %s"
>                                "-qtest unix:%s "
>                                "-qtest-log %s "
>                                "-chardev socket,path=%s,id=char0 "
> @@ -289,7 +369,7 @@ QTestState *qtest_init_without_qmp_handshake(const
> char *extra_args)
>                                "%s"
>                                " -accel qtest",
>                                qemu_binary, tracearg, socket_path,
> -                              getenv("QTEST_LOG") ? "/dev/fd/2" :
> "/dev/null",
> +                              getenv("QTEST_LOG") ? DEV_STDERR : DEV_NULL,
>                                qmp_socket_path,
>                                extra_args ?: "");
>
> @@ -298,6 +378,7 @@ QTestState *qtest_init_without_qmp_handshake(const
> char *extra_args)
>      s->pending_events = NULL;
>      s->wstatus = 0;
>      s->expected_status = 0;
> +#ifndef _WIN32
>      s->qemu_pid = fork();
>      if (s->qemu_pid == 0) {
>  #ifdef __linux__
> @@ -320,6 +401,9 @@ QTestState *qtest_init_without_qmp_handshake(const
> char *extra_args)
>          execlp("/bin/sh", "sh", "-c", command, NULL);
>          exit(1);
>      }
> +#else
> +    s->qemu_pid = qtest_create_process(command);
> +#endif /* _WIN32 */
>
>      g_free(command);
>      s->fd = socket_accept(sock);
> @@ -338,9 +422,19 @@ QTestState *qtest_init_without_qmp_handshake(const
> char *extra_args)
>          s->irq_level[i] = false;
>      }
>
> +    /*
> +     * Stopping QEMU for debugging is not supported on Windows.
> +     *
> +     * Using DebugActiveProcess() API can suspend the QEMU process,
> +     * but gdb cannot attach to the process. Using the undocumented
> +     * NtSuspendProcess() can suspend the QEMU process and gdb can
> +     * attach to the process, but gdb cannot resume it.
> +     */
> +#ifndef _WIN32
>      if (getenv("QTEST_STOP")) {
>          kill(s->qemu_pid, SIGSTOP);
>      }
> +#endif
>
>      /* ask endianness of the target */
>
> @@ -393,6 +487,9 @@ QTestState *qtest_init_with_serial(const char
> *extra_args, int *sock_fd)
>      g_assert_true(g_mkdtemp(sock_dir) != NULL);
>      sock_path = g_strdup_printf("%s/sock", sock_dir);
>
> +#ifdef _WIN32
> +    socket_init();
> +#endif
>      sock_fd_init = init_socket(sock_path);
>
>      qts = qtest_initf("-chardev socket,id=s0,path=%s -serial chardev:s0
> %s",
> diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
> index 0291b3966c..6d469a1822 100644
> --- a/tests/qtest/meson.build
> +++ b/tests/qtest/meson.build
> @@ -1,6 +1,5 @@
> -# All QTests for now are POSIX-only, but the dependencies are
> -# really in libqtest, not in the testcases themselves.
> -if not config_host.has_key('CONFIG_POSIX')
> +# Build all QTests for POSIX and Windows
> +if not config_host.has_key('CONFIG_POSIX') and not
> config_host.has_key('CONFIG_WIN32')
>    subdir_done()
>  endif
>
> --
> 2.34.1
>
>
>

-- 
Marc-André Lureau

[-- Attachment #2: Type: text/html, Size: 12069 bytes --]

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

* Re: [PATCH 42/51] hw/ppc: spapr: Use qemu_vfree() to free spapr->htab
  2022-08-24  9:40 ` [PATCH 42/51] hw/ppc: spapr: Use qemu_vfree() to free spapr->htab Bin Meng
  2022-08-24 17:32   ` Daniel Henrique Barboza
@ 2022-09-01 11:40   ` Marc-André Lureau
  1 sibling, 0 replies; 174+ messages in thread
From: Marc-André Lureau @ 2022-09-01 11:40 UTC (permalink / raw)
  To: Bin Meng
  Cc: qemu-devel, Xuzhou Cheng, Bin Meng, Cédric Le Goater,
	Daniel Henrique Barboza, David Gibson, Greg Kurz, qemu-ppc

[-- Attachment #1: Type: text/plain, Size: 1140 bytes --]

On Wed, Aug 24, 2022 at 3:18 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Xuzhou Cheng <xuzhou.cheng@windriver.com>
>
> spapr->htab is allocated by qemu_memalign(), hence we should use
> qemu_vfree() to free it.
>
> Fixes: c5f54f3e31bf ("pseries: Move hash page table allocation to reset
> time")
> Fixes: b4db54132ffe ("target/ppc: Implement H_REGISTER_PROCESS_TABLE
> H_CALL"")
> Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
>

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


> ---
>
>  hw/ppc/spapr.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
> index bc9ba6e6dc..4034f4d130 100644
> --- a/hw/ppc/spapr.c
> +++ b/hw/ppc/spapr.c
> @@ -1522,7 +1522,7 @@ int spapr_hpt_shift_for_ramsize(uint64_t ramsize)
>
>  void spapr_free_hpt(SpaprMachineState *spapr)
>  {
> -    g_free(spapr->htab);
> +    qemu_vfree(spapr->htab);
>      spapr->htab = NULL;
>      spapr->htab_shift = 0;
>      close_htab_fd(spapr);
> --
> 2.34.1
>
>
>

-- 
Marc-André Lureau

[-- Attachment #2: Type: text/html, Size: 2055 bytes --]

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

* Re: [PATCH 44/51] tests/qtest: microbit-test: Fix socket access for win32
  2022-08-24  9:40 ` [PATCH 44/51] tests/qtest: microbit-test: Fix socket access for win32 Bin Meng
@ 2022-09-01 11:44   ` Marc-André Lureau
  0 siblings, 0 replies; 174+ messages in thread
From: Marc-André Lureau @ 2022-09-01 11:44 UTC (permalink / raw)
  To: Bin Meng
  Cc: qemu-devel, Bin Meng, Joel Stanley, Laurent Vivier,
	Paolo Bonzini, Peter Maydell, Thomas Huth, qemu-arm

[-- Attachment #1: Type: text/plain, Size: 2450 bytes --]

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

[-- Attachment #2: Type: text/html, Size: 3482 bytes --]

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

* Re: [PATCH 46/51] tests/qtest: libqtest: Replace the call to close a socket with closesocket()
  2022-08-24  9:40 ` [PATCH 46/51] tests/qtest: libqtest: Replace the call to close a socket with closesocket() Bin Meng
@ 2022-09-01 11:46   ` Marc-André Lureau
  0 siblings, 0 replies; 174+ messages in thread
From: Marc-André Lureau @ 2022-09-01 11:46 UTC (permalink / raw)
  To: Bin Meng; +Cc: qemu-devel, Bin Meng, Laurent Vivier, Paolo Bonzini, Thomas Huth

[-- Attachment #1: Type: text/plain, Size: 2185 bytes --]

On Wed, Aug 24, 2022 at 3:09 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Bin Meng <bin.meng@windriver.com>
>
> close() is a *nix function. It works on any file descriptor, and
> sockets in *nix are an example of a file descriptor.
>
> closesocket() is a Windows-specific function, which works only
> specifically with sockets. Sockets on Windows do not use *nix-style
> file descriptors, and socket() returns a handle to a kernel object
> instead, so it must be closed with closesocket().
>
> In QEMU there is already a logic to handle such platform difference
> in os-posix.h and os-win32.h, that:
>
>   * closesocket maps to close on POSIX
>   * closesocket maps to a wrapper that calls the real closesocket()
>     on Windows
>
> Replace the call to close a socket with closesocket() instead.
>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
>

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


> ---
>
>  tests/qtest/libqtest.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
> index 99e52ff571..918f4657ed 100644
> --- a/tests/qtest/libqtest.c
> +++ b/tests/qtest/libqtest.c
> @@ -115,7 +115,7 @@ static int socket_accept(int sock)
>                     (void *)&timeout, sizeof(timeout))) {
>          fprintf(stderr, "%s failed to set SO_RCVTIMEO: %s\n",
>                  __func__, strerror(errno));
> -        close(sock);
> +        closesocket(sock);
>          return -1;
>      }
>
> @@ -126,7 +126,7 @@ static int socket_accept(int sock)
>      if (ret == -1) {
>          fprintf(stderr, "%s failed: %s\n", __func__, strerror(errno));
>      }
> -    close(sock);
> +    closesocket(sock);
>
>      return ret;
>  }
> @@ -512,8 +512,8 @@ void qtest_quit(QTestState *s)
>      qtest_remove_abrt_handler(s);
>
>      qtest_kill_qemu(s);
> -    close(s->fd);
> -    close(s->qmp_fd);
> +    closesocket(s->fd);
> +    closesocket(s->qmp_fd);
>      g_string_free(s->rx, true);
>
>      for (GList *it = s->pending_events; it != NULL; it = it->next) {
> --
> 2.34.1
>
>
>

-- 
Marc-André Lureau

[-- Attachment #2: Type: text/html, Size: 3174 bytes --]

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

* Re: [PATCH 47/51] tests/qtest: libqtest: Correct the timeout unit of blocking receive calls for win32
  2022-08-24  9:40 ` [PATCH 47/51] tests/qtest: libqtest: Correct the timeout unit of blocking receive calls for win32 Bin Meng
@ 2022-09-01 11:57   ` Marc-André Lureau
  0 siblings, 0 replies; 174+ messages in thread
From: Marc-André Lureau @ 2022-09-01 11:57 UTC (permalink / raw)
  To: Bin Meng; +Cc: qemu-devel, Bin Meng, Laurent Vivier, Paolo Bonzini, Thomas Huth

[-- Attachment #1: Type: text/plain, Size: 2196 bytes --]

Hi

On Wed, Aug 24, 2022 at 3:44 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Bin Meng <bin.meng@windriver.com>
>
> Some qtest cases don't get response from the the QEMU executable
>

"the the"


> under test in time on Windows. It turns out that the socket receive
> call got timeout before it receive the complete response.
>
> The timeout value is supposed to be set to 50 seconds via the
> setsockopt() call, but there is a difference among platforms.
> The timeout unit of blocking receive calls is measured in
> seconds on non-Windows platforms but milliseconds on Windows.
>

Ahah, interesting :) Well, it's not the only difference, windows uses DWORD
instead of timeval


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

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


> ---
>
>  tests/qtest/libqtest.c | 11 ++++++++++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
> index 918f4657ed..7b41971347 100644
> --- a/tests/qtest/libqtest.c
> +++ b/tests/qtest/libqtest.c
> @@ -36,13 +36,14 @@
>  #include "qapi/qmp/qstring.h"
>
>  #define MAX_IRQ 256
> -#define SOCKET_TIMEOUT 50
>
>  #ifndef _WIN32
> +# define SOCKET_TIMEOUT 50
>  # define CMD_EXEC   "exec "
>  # define DEV_STDERR "/dev/fd/2"
>  # define DEV_NULL   "/dev/null"
>  #else
> +# define SOCKET_TIMEOUT 50000
>  # define CMD_EXEC   ""
>  # define DEV_STDERR "2"
>  # define DEV_NULL   "nul"
> @@ -108,8 +109,16 @@ static int socket_accept(int sock)
>      struct sockaddr_un addr;
>      socklen_t addrlen;
>      int ret;
> +    /*
> +     * timeout unit of blocking receive calls is different among platfoms.
> +     * It's in seconds on non-Windows platforms but milliseconds on
> Windows.
> +     */
> +#ifndef _WIN32
>      struct timeval timeout = { .tv_sec = SOCKET_TIMEOUT,
>                                 .tv_usec = 0 };
> +#else
> +    DWORD timeout = SOCKET_TIMEOUT;
> +#endif
>
>      if (setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO,
>                     (void *)&timeout, sizeof(timeout))) {
> --
> 2.34.1
>
>
>

-- 
Marc-André Lureau

[-- Attachment #2: Type: text/html, Size: 3541 bytes --]

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

* Re: [PATCH 48/51] io/channel-watch: Drop a superfluous '#ifdef WIN32'
  2022-08-24  9:40 ` [PATCH 48/51] io/channel-watch: Drop a superfluous '#ifdef WIN32' Bin Meng
@ 2022-09-01 12:24   ` Marc-André Lureau
  2022-10-17 12:34   ` Daniel P. Berrangé
  1 sibling, 0 replies; 174+ messages in thread
From: Marc-André Lureau @ 2022-09-01 12:24 UTC (permalink / raw)
  To: Bin Meng; +Cc: qemu-devel, Bin Meng, Daniel P. Berrangé

[-- Attachment #1: Type: text/plain, Size: 1100 bytes --]

On Wed, Aug 24, 2022 at 2:37 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Bin Meng <bin.meng@windriver.com>
>
> In the win32 version qio_channel_create_socket_watch() body there is
> no need to do a '#ifdef WIN32'.
>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
>

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


> ---
>
>  io/channel-watch.c | 2 --
>  1 file changed, 2 deletions(-)
>
> diff --git a/io/channel-watch.c b/io/channel-watch.c
> index 0289b3647c..89f3c8a88a 100644
> --- a/io/channel-watch.c
> +++ b/io/channel-watch.c
> @@ -285,11 +285,9 @@ GSource *qio_channel_create_socket_watch(QIOChannel
> *ioc,
>      GSource *source;
>      QIOChannelSocketSource *ssource;
>
> -#ifdef WIN32
>      WSAEventSelect(socket, ioc->event,
>                     FD_READ | FD_ACCEPT | FD_CLOSE |
>                     FD_CONNECT | FD_WRITE | FD_OOB);
> -#endif
>
>      source = g_source_new(&qio_channel_socket_source_funcs,
>                            sizeof(QIOChannelSocketSource));
> --
> 2.34.1
>
>
>

-- 
Marc-André Lureau

[-- Attachment #2: Type: text/html, Size: 1951 bytes --]

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

* Re: [PATCH 49/51] io/channel-watch: Fix socket watch on Windows
  2022-08-24  9:40 ` [PATCH 49/51] io/channel-watch: Fix socket watch on Windows Bin Meng
@ 2022-09-01 12:58   ` Marc-André Lureau
  2022-09-04  6:24     ` Bin Meng
  2022-10-17 12:35   ` Daniel P. Berrangé
  1 sibling, 1 reply; 174+ messages in thread
From: Marc-André Lureau @ 2022-09-01 12:58 UTC (permalink / raw)
  To: Bin Meng; +Cc: qemu-devel, Bin Meng, Daniel P. Berrangé

[-- Attachment #1: Type: text/plain, Size: 3762 bytes --]

Hi

On Wed, Aug 24, 2022 at 2:49 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Bin Meng <bin.meng@windriver.com>
>
> Random failure was observed when running qtests on Windows due to
> "Broken pipe" detected by qmp_fd_receive(). What happened is that
> the qtest executable sends testing data over a socket to the QEMU
> under test but no response is received. The errno of the recv()
> call from the qtest executable indicates ETIMEOUT, due to the qmp
> chardev's tcp_chr_read() is never called to receive testing data
> hence no response is sent to the other side.
>
> tcp_chr_read() is registered as the callback of the socket watch
> GSource. The reason of the callback not being called by glib, is
> that the source check fails to indicate the source is ready. There
> are two socket watch sources created to monitor the same socket
> event object from the char-socket backend in update_ioc_handlers().
>
During the source check phase, qio_channel_socket_source_check()
> calls WSAEnumNetworkEvents() to discovers occurrences of network
> events for the indicated socket, clear internal network event records,
> and reset the event object. Testing shows that if we don't reset the
> event object by not passing the event handle to WSAEnumNetworkEvents()
> the symptom goes away and qtest runs very stably.
>
> It looks we don't need to call WSAEnumNetworkEvents() at all, as we
> don't parse the result of WSANETWORKEVENTS returned from this API.
> We use select() to poll the socket status. Fix this instability by
> dropping the WSAEnumNetworkEvents() call.
>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
>

What clears the event then?



> ---
> During the testing, I removed the following codes in update_ioc_handlers():
>
>     remove_hup_source(s);
>     s->hup_source = qio_channel_create_watch(s->ioc, G_IO_HUP);
>     g_source_set_callback(s->hup_source, (GSourceFunc)tcp_chr_hup,
>                           chr, NULL);
>     g_source_attach(s->hup_source, chr->gcontext);
>
> and such change also makes the symptom go away.
>
> And if I moved the above codes to the beginning, before the call to
> io_add_watch_poll(), the symptom also goes away.
>
> It seems two sources watching on the same socket event object is
> the key that leads to the instability. The order of adding a source
> watch seems to also play a role but I can't explain why.
> Hopefully a Windows and glib expert could explain this behavior.
>
>
Feel free to leave that comment in the commit message.

This is strange, as both sources should have different events, clearing one
shouldn't affect the other.

I guess it's WSAEnumNetworkEvents clearing of the internal network event
records that is problematic.

Can you check if you replace the call with ResetEvent() everything works?



>  io/channel-watch.c | 4 ----
>  1 file changed, 4 deletions(-)
>
> diff --git a/io/channel-watch.c b/io/channel-watch.c
> index 89f3c8a88a..e34d86e810 100644
> --- a/io/channel-watch.c
> +++ b/io/channel-watch.c
> @@ -115,17 +115,13 @@ static gboolean
>  qio_channel_socket_source_check(GSource *source)
>  {
>      static struct timeval tv0;
> -
>      QIOChannelSocketSource *ssource = (QIOChannelSocketSource *)source;
> -    WSANETWORKEVENTS ev;
>      fd_set rfds, wfds, xfds;
>
>      if (!ssource->condition) {
>          return 0;
>      }
>
> -    WSAEnumNetworkEvents(ssource->socket, ssource->ioc->event, &ev);
> -
>      FD_ZERO(&rfds);
>      FD_ZERO(&wfds);
>      FD_ZERO(&xfds);
>

Unrelated, after this chunk, there is
        FD_SET((SOCKET)ssource->socket, &rfds);

it seems we can drop the cast. Feel free to send another patch.

-- 
Marc-André Lureau

[-- Attachment #2: Type: text/html, Size: 5164 bytes --]

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

* Re: [PATCH 51/51] docs/devel: testing: Document writing portable test cases
  2022-08-24  9:40 ` [PATCH 51/51] docs/devel: testing: Document writing portable test cases Bin Meng
@ 2022-09-01 13:02   ` Marc-André Lureau
  0 siblings, 0 replies; 174+ messages in thread
From: Marc-André Lureau @ 2022-09-01 13:02 UTC (permalink / raw)
  To: Bin Meng
  Cc: qemu-devel, Bin Meng, Emanuele Giuseppe Esposito, Hanna Reitz,
	Philippe Mathieu-Daudé,
	Vladimir Sementsov-Ogievskiy, Willian Rampazzo

[-- Attachment #1: Type: text/plain, Size: 2924 bytes --]

Hi

On Wed, Aug 24, 2022 at 2:57 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Bin Meng <bin.meng@windriver.com>
>
> Update the best practices of how to write portable test cases that
> can be built and run successfully on both Linux and Windows hosts.
>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
>

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


> ---
>
>  docs/devel/testing.rst | 30 ++++++++++++++++++++++++++++++
>  1 file changed, 30 insertions(+)
>
> diff --git a/docs/devel/testing.rst b/docs/devel/testing.rst
> index 3f6ebd5073..8fcabda30f 100644
> --- a/docs/devel/testing.rst
> +++ b/docs/devel/testing.rst
> @@ -115,6 +115,36 @@ check-block
>  are in the "auto" group).
>  See the "QEMU iotests" section below for more information.
>
> +Writing portable test cases
> +~~~~~~~~~~~~~~~~~~~~~~~~~~~
> +Both unit tests and qtests can run on a Linux host as well as a Windows
> host.
>

I believe they can work on other hosts too :)

"can run on a Windows host."


> +Care must be taken when writing portable test cases that can be built and
> run
> +successfully on both hosts. The following are some best practices:
>

"on various hosts"


> +
> +* Use portable APIs from glib whenever necessary, e.g.: g_setenv(),
> +  g_mkdtemp(), g_mkdir_with_parents().
> +* Avoid using hardcoded /tmp for temporary file directory.
> +  Use g_get_tmp_dir() instead.
> +* Bear in mind that Windows has different special string representation
> for
> +  stdin/stdout/stderr and null devices. For example if your test case uses
> +  "/dev/fd/2" and "/dev/null" on Linux, remember to use "2" and "nul" on
> +  Windows instead. Also IO redirection does not work on Windows, so avoid
> +  using "2>nul" whenever necessary.
> +* If your test cases uses the blkdebug feature, use relative path to pass
> +  the config and image file paths in the command line as Windows absolute
> +  path contains the delimeter ":" which will confuse the blkdebug parser.
> +* Use double quotes in your extra QEMU commmand line in your test cases
> +  instead of single quotes, as Windows does not drop single quotes when
> +  passing the command line to QEMU.
> +* Windows opens a file in text mode by default, while a POSIX compliant
> +  implementation treats text files and binary files the same. So if your
> +  test cases opens a file to write some data and later wants to compare
> the
> +  written data with the original one, be sure to pass the letter 'b' as
> +  part of the mode string to fopen(), or O_BINARY flag for the open()
> call.
> +* If a certain test case can only run on POSIX or Linux hosts, use a
> proper
> +  #ifdef in the codes. If the whole test suite cannot run on Windows,
> disable
> +  the build in the meson.build file.
> +
>  QEMU iotests
>  ------------
>
> --
> 2.34.1
>
>
>

-- 
Marc-André Lureau

[-- Attachment #2: Type: text/html, Size: 4231 bytes --]

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

* Re: [PATCH 23/51] accel/qtest: Support qtest accelerator for Windows
  2022-08-31 13:49   ` Marc-André Lureau
@ 2022-09-02  8:28     ` Bin Meng
  0 siblings, 0 replies; 174+ messages in thread
From: Bin Meng @ 2022-09-02  8:28 UTC (permalink / raw)
  To: Marc-André Lureau
  Cc: Richard Henderson, Paolo Bonzini,
	qemu-devel@nongnu.org Developers, Xuzhou Cheng, Bin Meng,
	Eduardo Habkost, Laurent Vivier, Marcel Apfelbaum,
	Philippe Mathieu-Daudé,
	Thomas Huth, Yanan Wang

On Wed, Aug 31, 2022 at 9:50 PM Marc-André Lureau
<marcandre.lureau@gmail.com> wrote:
>
> Hi
>
> On Wed, Aug 24, 2022 at 2:31 PM Bin Meng <bmeng.cn@gmail.com> wrote:
>>
>> From: Xuzhou Cheng <xuzhou.cheng@windriver.com>
>>
>> Currently signal SIGIPI [=SIGUSR1] is used to kick the dummy CPU
>> when qtest accelerator is used. However SIGUSR1 is unsupported on
>> Windows. To support Windows, we add a QemuSemaphore CPUState::sem
>> to kick the dummy CPU instead for Windows.
>>
>> Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
>> Signed-off-by: Bin Meng <bin.meng@windriver.com>
>
>
> What if we replace signals by the semaphore on posix as well?

Yeah, with that we can make this a complete portable implementation.
Will do in v2.

>
> but lgtm,
> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
>
>>
>> ---
>>
>>  include/hw/core/cpu.h   |  1 +
>>  accel/dummy-cpus.c      | 14 ++++++++++++--
>>  softmmu/cpus.c          |  9 +++++----
>>  accel/meson.build       |  1 +
>>  accel/qtest/meson.build |  1 +
>>  5 files changed, 20 insertions(+), 6 deletions(-)
>>

Regards,
Bin


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

* Re: [PATCH 20/51] tests/qtest: i440fx-test: Skip running request_{bios, pflash} for win32
  2022-08-31 13:40   ` [PATCH 20/51] tests/qtest: i440fx-test: Skip running request_{bios, pflash} " Marc-André Lureau
@ 2022-09-02  8:29     ` Bin Meng
  0 siblings, 0 replies; 174+ messages in thread
From: Bin Meng @ 2022-09-02  8:29 UTC (permalink / raw)
  To: Marc-André Lureau
  Cc: qemu-devel@nongnu.org Developers, Bin Meng, Laurent Vivier,
	Paolo Bonzini, Thomas Huth

On Wed, Aug 31, 2022 at 9:40 PM Marc-André Lureau
<marcandre.lureau@gmail.com> wrote:
>
> Hi
>
> On Wed, Aug 24, 2022 at 2:15 PM Bin Meng <bmeng.cn@gmail.com> wrote:
>>
>> From: Bin Meng <bin.meng@windriver.com>
>>
>> The request_{bios,pflash} test cases call mmap() which does not
>> exist on win32. Exclude them.
>>
>
> We can fairly easily rewrite the create_blob_file() function to be portable though, something like:

Thanks for the suggestion!

Will spin a patch in v2.

>
> static char *create_blob_file(void)
> {
>     g_autofree uint8_t *buf = g_malloc(BLOB_SIZE);
>     GError *error = NULL;
>     char *pathname;
>     int fd;
>     size_t i;
>
>     fd = g_file_open_tmp("blob_XXXXXX", &pathname, &error);
>     g_assert_no_error(error);
>
>     for (i = 0; i < BLOB_SIZE; ++i) {
>         buf[i] = i;
>     }
>
>     g_file_set_contents(pathname, (char *)buf, BLOB_SIZE, &error);
>     g_assert_no_error(error);
>     close(fd);
>
>     return pathname;
> }
>
>> Signed-off-by: Bin Meng <bin.meng@windriver.com>
>> ---
>>
>>  tests/qtest/i440fx-test.c | 6 ++++++
>>  1 file changed, 6 insertions(+)
>>

Regards,
Bin


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

* Re: [PATCH 32/51] tests/qtest: Fix ERROR_SHARING_VIOLATION for win32
  2022-08-25 12:06   ` Thomas Huth
@ 2022-09-02 10:59     ` Bin Meng
  0 siblings, 0 replies; 174+ messages in thread
From: Bin Meng @ 2022-09-02 10:59 UTC (permalink / raw)
  To: Thomas Huth
  Cc: qemu-devel@nongnu.org Developers, Bin Meng, John Snow,
	Laurent Vivier, Paolo Bonzini, Qemu-block

On Thu, Aug 25, 2022 at 8:06 PM Thomas Huth <thuth@redhat.com> wrote:
>
> On 24/08/2022 11.40, Bin Meng wrote:
> > From: Bin Meng <bin.meng@windriver.com>
> >
> > On Windows, the MinGW provided mkstemp() API opens the file with
> > exclusive access, denying other processes to read/write the file.
> > Such behavior prevents the QEMU executable from opening the file,
> > (e.g.: CreateFile returns ERROR_SHARING_VIOLATION).
> >
> > This can be fixed by closing the file and reopening it.
>
> Would it work to use the glib functions instead (like g_file_open_tmp() ?)
>

Yep, I've switched to using g_file_open_tmp() in patch #7 "tests:
Avoid using hardcoded /tmp in test cases", and testing shows that it
does not have such an issue.

So this patch can be dropped.

Regards,
Bin


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

* Re: [PATCH 32/51] tests/qtest: Fix ERROR_SHARING_VIOLATION for win32
  2022-09-01  8:42   ` Marc-André Lureau
@ 2022-09-02 11:02     ` Bin Meng
  0 siblings, 0 replies; 174+ messages in thread
From: Bin Meng @ 2022-09-02 11:02 UTC (permalink / raw)
  To: Marc-André Lureau
  Cc: qemu-devel@nongnu.org Developers, Bin Meng, John Snow,
	Laurent Vivier, Paolo Bonzini, Thomas Huth, Qemu-block

On Thu, Sep 1, 2022 at 4:42 PM Marc-André Lureau
<marcandre.lureau@gmail.com> wrote:
>
> Hi
>
> On Wed, Aug 24, 2022 at 2:03 PM Bin Meng <bmeng.cn@gmail.com> wrote:
>>
>> From: Bin Meng <bin.meng@windriver.com>
>>
>> On Windows, the MinGW provided mkstemp() API opens the file with
>> exclusive access, denying other processes to read/write the file.
>> Such behavior prevents the QEMU executable from opening the file,
>> (e.g.: CreateFile returns ERROR_SHARING_VIOLATION).
>
>
> g_mkstemp() doesn't have this behaviour (after running a quick test). Use it?
>

Thanks for the suggestion!

I've switched to using g_file_open_tmp() in patch #7 "tests: Avoid
using hardcoded /tmp in test cases", and testing shows that it does
not have such an issue.

I checked glib sources and see both g_mkstemp() and g_file_open_tmp()
call g_open() which allows shared read/write on Windows.

So this patch can be dropped.

Regards,
Bin


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

* Re: [PATCH 27/51] tests/qtest: Use send/recv for socket communication
  2022-08-31 14:05         ` Marc-André Lureau
  2022-08-31 14:19           ` Daniel P. Berrangé
@ 2022-09-02 14:24           ` Bin Meng
  1 sibling, 0 replies; 174+ messages in thread
From: Bin Meng @ 2022-09-02 14:24 UTC (permalink / raw)
  To: Marc-André Lureau
  Cc: Thomas Huth, Daniel P. Berrange,
	qemu-devel@nongnu.org Developers, Xuzhou Cheng, Bin Meng,
	Laurent Vivier, Paolo Bonzini

On Wed, Aug 31, 2022 at 10:06 PM Marc-André Lureau
<marcandre.lureau@gmail.com> wrote:
>
> Hi
>
> On Fri, Aug 26, 2022 at 10:27 PM Thomas Huth <thuth@redhat.com> wrote:
>>
>> On 26/08/2022 16.59, Bin Meng wrote:
>> > On Thu, Aug 25, 2022 at 9:04 PM Thomas Huth <thuth@redhat.com> wrote:
>> >>
>> >> On 24/08/2022 11.40, Bin Meng wrote:
>> >>> From: Xuzhou Cheng <xuzhou.cheng@windriver.com>
>> >>>
>> >>> Socket communication in the libqtest and libqmp codes uses read()
>> >>> and write() which work on any file descriptor on *nix, and sockets
>> >>> in *nix are an example of a file descriptor.
>> >>>
>> >>> However sockets on Windows do not use *nix-style file descriptors,
>> >>> so read() and write() cannot be used on sockets on Windows.
>> >>> Switch over to use send() and recv() instead which work on both
>> >>> Windows and *nix.
>> >>>
>> >>> Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
>> >>> Signed-off-by: Bin Meng <bin.meng@windriver.com>
>> >>> ---
>> >>>
>> >>>    tests/qtest/libqmp.c   | 4 ++--
>> >>>    tests/qtest/libqtest.c | 4 ++--
>> >>>    2 files changed, 4 insertions(+), 4 deletions(-)
>> >>>
>> >>> diff --git a/tests/qtest/libqmp.c b/tests/qtest/libqmp.c
>> >>> index ade26c15f0..995a39c1f8 100644
>> >>> --- a/tests/qtest/libqmp.c
>> >>> +++ b/tests/qtest/libqmp.c
>> >>> @@ -36,7 +36,7 @@ typedef struct {
>> >>>
>> >>>    static void socket_send(int fd, const char *buf, size_t size)
>> >>>    {
>> >>> -    size_t res = qemu_write_full(fd, buf, size);
>> >>> +    ssize_t res = send(fd, buf, size, 0);
>> >>
>> >> This way we're losing the extra logic from qemu_write_full() here (i.e. the
>> >> looping and EINTR handling) ... not sure whether that's really OK? Maybe you
>> >> have to introduce a qemu_send_full() first?
>> >>
>> >
>> > I am not sure if qemu_send_full() is really needed because there is an
>> > assert() right after the send() call.
>>
>> That's just a sanity check ... I think this function still has to take care
>> of EINTR - it originally looked like this:
>>
>>   https://git.qemu.org/?p=qemu.git;a=commitdiff;h=c3e5704af19ac6
>>
>> ... and you can also see the while loop there.
>>
>
> Agree, that would be the correct thing to do.
>
> Fwiw, the SOCKET vs fd situation is giving me some nervous feelings, sometimes.
>
> For ex, as I checked recently, it seems close(fd) correctly closes the underlying SOCKET - as if closesocket() was called on it.. but this is not really documented.

Really? If you use gdb to step over close(socket) on Windows, you will
see a Windows debug message is thrown to gdb saying that:

"warning: Invalid parameter passed to C runtime function."

MSDN only says closesocket() should be used on socket. This is why in
the QEMU codes we map closesocket to close on POSIX, and always use
closesocket.

>
> And it's easy to mix fd vs SOCKET in QEMU code paths (we cast/map SOCKET to "int fd" in general), and reach a close() on a SOCKET. That wouldn't be valid, and would likely create leaks or other issues.
>
> Maybe we should introduce a type for safety / documentation purposes...
>

Regards,
Bin


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

* Re: [PATCH 30/51] tests: Skip iotests and qtest when '--without-default-devices'
  2022-08-25 12:03   ` Thomas Huth
@ 2022-09-02 15:18     ` Bin Meng
  0 siblings, 0 replies; 174+ messages in thread
From: Bin Meng @ 2022-09-02 15:18 UTC (permalink / raw)
  To: Thomas Huth
  Cc: qemu-devel@nongnu.org Developers, Bin Meng, Hanna Reitz,
	Kevin Wolf, Laurent Vivier, Paolo Bonzini, Qemu-block

On Thu, Aug 25, 2022 at 8:04 PM Thomas Huth <thuth@redhat.com> wrote:
>
> On 24/08/2022 11.40, Bin Meng wrote:
> > From: Bin Meng <bin.meng@windriver.com>
> >
> > When QEMU is configured with '--without-default-devices', we should
> > not build and run iotests and qtest because devices used by these
> > test cases are not built in.
> >
> > Signed-off-by: Bin Meng <bin.meng@windriver.com>
> > ---
> >
> >   tests/qemu-iotests/meson.build | 5 +++++
> >   tests/qtest/meson.build        | 5 +++++
> >   2 files changed, 10 insertions(+)
> >
> > diff --git a/tests/qemu-iotests/meson.build b/tests/qemu-iotests/meson.build
> > index 323a4acb6a..38d9a874d2 100644
> > --- a/tests/qemu-iotests/meson.build
> > +++ b/tests/qemu-iotests/meson.build
> > @@ -2,6 +2,11 @@ if not have_tools or targetos == 'windows' or get_option('gprof')
> >     subdir_done()
> >   endif
> >
> > +# Skip iotests if configured without a default selection of devices
> > +if not get_option('default_devices')
> > +  subdir_done()
> > +endif
> > +
> >   foreach cflag: config_host['QEMU_CFLAGS'].split()
> >     if cflag.startswith('-fsanitize') and \
> >        not cflag.contains('safe-stack') and not cflag.contains('cfi-icall')
> > diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
> > index c97da5a062..0291b3966c 100644
> > --- a/tests/qtest/meson.build
> > +++ b/tests/qtest/meson.build
> > @@ -4,6 +4,11 @@ if not config_host.has_key('CONFIG_POSIX')
> >     subdir_done()
> >   endif
> >
> > +# Skip QTests if configured without a default selection of devices
> > +if not get_option('default_devices')
> > +  subdir_done()
> > +endif
> > +
> >   slow_qtests = {
> >     'ahci-test' : 60,
> >     'bios-tables-test' : 120,
>
> That's a very big hammer already ... I'd prefer if we could work on the
> tests instead to adapt for the availability of devices instead (we've done
> quite a lot of work in this area in the past already, but apparently still
> not enough yet ...)

Adapting tests for the availability of devices is a large scope. I may
not have time to work on this.

I will have to drop this patch in v2, and adjust the patches in the
series to keep bisectability then.

Regards,
Bin


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

* Re: [PATCH 29/51] tests/qtest: libqtest: Install signal handler via signal()
  2022-08-31 14:16   ` Marc-André Lureau
@ 2022-09-02 15:49     ` Bin Meng
  0 siblings, 0 replies; 174+ messages in thread
From: Bin Meng @ 2022-09-02 15:49 UTC (permalink / raw)
  To: Marc-André Lureau
  Cc: qemu-devel@nongnu.org Developers, Bin Meng, Laurent Vivier,
	Paolo Bonzini, Thomas Huth

On Wed, Aug 31, 2022 at 10:16 PM Marc-André Lureau
<marcandre.lureau@gmail.com> wrote:
>
> Hi
>
> On Wed, Aug 24, 2022 at 2:47 PM Bin Meng <bmeng.cn@gmail.com> wrote:
>>
>> From: Bin Meng <bin.meng@windriver.com>
>>
>> At present the codes uses sigaction() to install signal handler with
>> a flag SA_RESETHAND. Such usage can be covered by the signal() API
>> that is a simplified interface to the general sigaction() facility.
>>
>> Update to use signal() to install the signal handler, as it is
>> avaiable on Windows which we are going to support.
>>
>> Signed-off-by: Bin Meng <bin.meng@windriver.com>
>> ---
>>
>>  tests/qtest/libqtest.c | 14 +++-----------
>>  1 file changed, 3 insertions(+), 11 deletions(-)
>>
>> diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
>> index 1b24a4f1f7..70d7578740 100644
>> --- a/tests/qtest/libqtest.c
>> +++ b/tests/qtest/libqtest.c
>> @@ -68,7 +68,7 @@ struct QTestState
>>  QTestState *global_qtest;
>>
>>  static GHookList abrt_hooks;
>> -static struct sigaction sigact_old;
>> +static sighandler_t sighandler_old;
>>
>>  static int qtest_query_target_endianness(QTestState *s);
>>
>> @@ -181,20 +181,12 @@ static void sigabrt_handler(int signo)
>>
>>  static void setup_sigabrt_handler(void)
>>  {
>> -    struct sigaction sigact;
>> -
>> -    /* Catch SIGABRT to clean up on g_assert() failure */
>> -    sigact = (struct sigaction){
>> -        .sa_handler = sigabrt_handler,
>> -        .sa_flags = SA_RESETHAND,
>> -    };
>> -    sigemptyset(&sigact.sa_mask);
>> -    sigaction(SIGABRT, &sigact, &sigact_old);
>> +    sighandler_old = signal(SIGABRT, sigabrt_handler);
>>  }
>>
>>  static void cleanup_sigabrt_handler(void)
>>  {
>> -    sigaction(SIGABRT, &sigact_old, NULL);
>> +    signal(SIGABRT, sighandler_old);
>>  }
>>
>>  static bool hook_list_is_empty(GHookList *hook_list)
>> --
>
>
>
> We should keep the sigaction() version for !WIN32, it has notoriously less issues, more modern etc. signal() only on win32.
>
> Although in this particular usage, I don't think that makes much difference...


Yes, as I mentioned in the commit message, the codes uses sigaction()
to install signal handler with a flag SA_RESETHAND, and such can be
replaced by the signal() API.

It is still a supported API in POSIX so we should be safe to use it to
simplify the code paths. Unless you are strongly against this?

Regards,
Bin


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

* Re: [PATCH 41/51] tests/qtest: migration-test: Kill "to" after migration is canceled
  2022-09-01 11:35     ` Marc-André Lureau
@ 2022-09-02 16:33       ` Bin Meng
  0 siblings, 0 replies; 174+ messages in thread
From: Bin Meng @ 2022-09-02 16:33 UTC (permalink / raw)
  To: Marc-André Lureau
  Cc: Dr. David Alan Gilbert, qemu-devel@nongnu.org Developers,
	Xuzhou Cheng, Bin Meng, Juan Quintela, Laurent Vivier,
	Paolo Bonzini, Thomas Huth

On Thu, Sep 1, 2022 at 7:35 PM Marc-André Lureau
<marcandre.lureau@gmail.com> wrote:
>
> Hi
>
> On Wed, Aug 24, 2022 at 10:56 PM Dr. David Alan Gilbert <dgilbert@redhat.com> wrote:
>>
>> * Bin Meng (bmeng.cn@gmail.com) wrote:
>> > From: Xuzhou Cheng <xuzhou.cheng@windriver.com>
>> >
>> > Make sure QEMU process "to" is killed before launching another target
>> > for migration in the test_multifd_tcp_cancel case.
>> >
>> > Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
>> > Signed-off-by: Bin Meng <bin.meng@windriver.com>
>> > ---
>> >
>> >  tests/qtest/migration-test.c | 4 ++++
>> >  1 file changed, 4 insertions(+)
>> >
>> > diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
>> > index 125d48d855..18ec079abf 100644
>> > --- a/tests/qtest/migration-test.c
>> > +++ b/tests/qtest/migration-test.c
>> > @@ -2132,6 +2132,10 @@ static void test_multifd_tcp_cancel(void)
>> >      wait_for_migration_pass(from);
>> >
>> >      migrate_cancel(from);
>> > +    /* Make sure QEMU process "to" is killed */
>> > +    if (qtest_probe_child(to)) {
>> > +        qtest_kill_qemu(to);
>> > +    }
>>
>> I'm not sure that's safe - what happens if the qemu exits between the
>> probe and kill?
>

Umm, indeed there will be an issue if qemu exists between the probe and kill.

I will change to a busy wait in v2.

>
> It looks safe to me, qtest_probe_child() resets the qemu_pid if it already exited. Otherwise, there is a process/handle waiting for waitpid/CloseHandle done in qtest_kill_qemu().
>
> We are missing a CloseHandle() in qtest_probe_child() though, I'll send a patch.
>
> so lgtm,
> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>

Regards,
Bin


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

* Re: [PATCH 33/51] tests/qtest: {ahci, ide}-test: Use relative path for temporary files
  2022-09-01  8:58   ` Marc-André Lureau
@ 2022-09-03 13:30     ` Bin Meng
  0 siblings, 0 replies; 174+ messages in thread
From: Bin Meng @ 2022-09-03 13:30 UTC (permalink / raw)
  To: Marc-André Lureau
  Cc: Kevin Wolf, Hanna Reitz, qemu-devel@nongnu.org Developers,
	Bin Meng, John Snow, Laurent Vivier, Paolo Bonzini, Thomas Huth,
	Qemu-block

On Thu, Sep 1, 2022 at 4:58 PM Marc-André Lureau
<marcandre.lureau@gmail.com> wrote:
>
>
>
> On Wed, Aug 24, 2022 at 2:55 PM Bin Meng <bmeng.cn@gmail.com> wrote:
>>
>> From: Bin Meng <bin.meng@windriver.com>
>>
>> These test cases uses "blkdebug:path/to/config:path/to/image" for
>> testing. On Windows, absolute file paths contain the delimiter ':'
>> which causes the blkdebug filename parser fail to parse filenames.
>>
>
> hmm.. maybe it should learn to escape paths..
>
>
>> Signed-off-by: Bin Meng <bin.meng@windriver.com>
>> ---
>>
>>  tests/qtest/ahci-test.c | 19 ++++++++++++++++---
>>  tests/qtest/ide-test.c  | 18 ++++++++++++++++--
>>  2 files changed, 32 insertions(+), 5 deletions(-)
>>
>> diff --git a/tests/qtest/ahci-test.c b/tests/qtest/ahci-test.c
>> index 0e88cd0eef..bce9ff770c 100644
>> --- a/tests/qtest/ahci-test.c
>> +++ b/tests/qtest/ahci-test.c
>> @@ -1848,7 +1848,7 @@ static void create_ahci_io_test(enum IOMode type, enum AddrMode addr,
>>
>>  int main(int argc, char **argv)
>>  {
>> -    const char *arch;
>> +    const char *arch, *base;
>>      int ret;
>>      int fd;
>>      int c;
>> @@ -1886,8 +1886,21 @@ int main(int argc, char **argv)
>>          return 0;
>>      }
>>
>> +    /*
>> +     * "base" stores the starting point where we create temporary files.
>> +     *
>> +     * On Windows, this is set to the relative path of current working
>> +     * directory, because the absolute path causes the blkdebug filename
>> +     * parser fail to parse "blkdebug:path/to/config:path/to/image".
>> +     */
>> +#ifndef _WIN32
>> +    base = g_get_tmp_dir();
>> +#else
>> +    base = ".";
>> +#endif
>
>
> Meanwhile, that seems reasonable. Perhaps chdir() to the temporary directory first? (assuming other paths are absolute)

Other paths in the QEMU command line indeed are absolute, however the
QEMU executable path is set to a relative path from meson.build thus
we cannot chdir() to the temporary directory here.

>
>>
>> +
>>      /* Create a temporary image */
>> -    tmp_path = g_strdup_printf("%s/qtest.XXXXXX", g_get_tmp_dir());
>> +    tmp_path = g_strdup_printf("%s/qtest.XXXXXX", base);
>>      fd = mkstemp(tmp_path);
>>      g_assert(fd >= 0);
>>      if (have_qemu_img()) {
>> @@ -1905,7 +1918,7 @@ int main(int argc, char **argv)
>>      close(fd);
>>
>>      /* Create temporary blkdebug instructions */
>> -    debug_path = g_strdup_printf("%s/qtest-blkdebug.XXXXXX", g_get_tmp_dir());
>> +    debug_path = g_strdup_printf("%s/qtest-blkdebug.XXXXXX", base);
>>      fd = mkstemp(debug_path);
>>      g_assert(fd >= 0);
>>      close(fd);
>> diff --git a/tests/qtest/ide-test.c b/tests/qtest/ide-test.c
>> index ebbf8e0126..c5cad6c0be 100644
>> --- a/tests/qtest/ide-test.c
>> +++ b/tests/qtest/ide-test.c
>> @@ -1011,17 +1011,31 @@ static void test_cdrom_dma(void)
>>
>>  int main(int argc, char **argv)
>>  {
>> +    const char *base;
>>      int fd;
>>      int ret;
>>
>> +    /*
>> +     * "base" stores the starting point where we create temporary files.
>> +     *
>> +     * On Windows, this is set to the relative path of current working
>> +     * directory, because the absolute path causes the blkdebug filename
>> +     * parser fail to parse "blkdebug:path/to/config:path/to/image".
>> +     */
>> +#ifndef _WIN32
>> +    base = g_get_tmp_dir();
>> +#else
>> +    base = ".";
>> +#endif
>> +
>>      /* Create temporary blkdebug instructions */
>> -    debug_path = g_strdup_printf("%s/qtest-blkdebug.XXXXXX", g_get_tmp_dir());
>> +    debug_path = g_strdup_printf("%s/qtest-blkdebug.XXXXXX", base);
>>      fd = mkstemp(debug_path);
>>      g_assert(fd >= 0);
>>      close(fd);
>>
>>      /* Create a temporary raw image */
>> -    tmp_path = g_strdup_printf("%s/qtest.XXXXXX", g_get_tmp_dir());
>> +    tmp_path = g_strdup_printf("%s/qtest.XXXXXX", base);
>>      fd = mkstemp(tmp_path);
>>      g_assert(fd >= 0);
>>      ret = ftruncate(fd, TEST_IMAGE_SIZE);
>> --
>> 2.34.1

Regards,
Bin


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

* Re: [PATCH 49/51] io/channel-watch: Fix socket watch on Windows
  2022-09-01 12:58   ` Marc-André Lureau
@ 2022-09-04  6:24     ` Bin Meng
  2022-09-05  6:04       ` Marc-André Lureau
  0 siblings, 1 reply; 174+ messages in thread
From: Bin Meng @ 2022-09-04  6:24 UTC (permalink / raw)
  To: Marc-André Lureau
  Cc: qemu-devel@nongnu.org Developers, Bin Meng, Daniel P. Berrangé

On Thu, Sep 1, 2022 at 8:58 PM Marc-André Lureau
<marcandre.lureau@gmail.com> wrote:
>
> Hi
>
> On Wed, Aug 24, 2022 at 2:49 PM Bin Meng <bmeng.cn@gmail.com> wrote:
>>
>> From: Bin Meng <bin.meng@windriver.com>
>>
>> Random failure was observed when running qtests on Windows due to
>> "Broken pipe" detected by qmp_fd_receive(). What happened is that
>> the qtest executable sends testing data over a socket to the QEMU
>> under test but no response is received. The errno of the recv()
>> call from the qtest executable indicates ETIMEOUT, due to the qmp
>> chardev's tcp_chr_read() is never called to receive testing data
>> hence no response is sent to the other side.
>>
>> tcp_chr_read() is registered as the callback of the socket watch
>> GSource. The reason of the callback not being called by glib, is
>> that the source check fails to indicate the source is ready. There
>> are two socket watch sources created to monitor the same socket
>> event object from the char-socket backend in update_ioc_handlers().
>>
>> During the source check phase, qio_channel_socket_source_check()
>> calls WSAEnumNetworkEvents() to discovers occurrences of network
>> events for the indicated socket, clear internal network event records,
>> and reset the event object. Testing shows that if we don't reset the
>> event object by not passing the event handle to WSAEnumNetworkEvents()
>> the symptom goes away and qtest runs very stably.
>>
>> It looks we don't need to call WSAEnumNetworkEvents() at all, as we
>> don't parse the result of WSANETWORKEVENTS returned from this API.
>> We use select() to poll the socket status. Fix this instability by
>> dropping the WSAEnumNetworkEvents() call.
>>
>> Signed-off-by: Bin Meng <bin.meng@windriver.com>
>
>
> What clears the event then?
>

It seems we don't need to clear the event as everything still works as expected.

>>
>> ---
>> During the testing, I removed the following codes in update_ioc_handlers():
>>
>>     remove_hup_source(s);
>>     s->hup_source = qio_channel_create_watch(s->ioc, G_IO_HUP);
>>     g_source_set_callback(s->hup_source, (GSourceFunc)tcp_chr_hup,
>>                           chr, NULL);
>>     g_source_attach(s->hup_source, chr->gcontext);
>>
>> and such change also makes the symptom go away.
>>
>> And if I moved the above codes to the beginning, before the call to
>> io_add_watch_poll(), the symptom also goes away.
>>
>> It seems two sources watching on the same socket event object is
>> the key that leads to the instability. The order of adding a source
>> watch seems to also play a role but I can't explain why.
>> Hopefully a Windows and glib expert could explain this behavior.
>>
>
> Feel free to leave that comment in the commit message.

Sure, will add the above message into the commit in v2.

>
> This is strange, as both sources should have different events, clearing one shouldn't affect the other.

Both sources have the same event, as one QIO channel only has one
socket, and one socket can only be bound to one event.

>
> I guess it's WSAEnumNetworkEvents clearing of the internal network event records that is problematic.
>
> Can you check if you replace the call with ResetEvent() everything works?

No, ResetEvent() does not work, and is not recommended by MSDN [1]
too, which says:

The proper way to reset the state of an event object used with the
WSAEventSelect function is to pass the handle of the event object to
the WSAEnumNetworkEvents function in the hEventObject parameter. This
will reset the event object and adjust the status of active FD events
on the socket in an atomic fashion.

[1] https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsaeventselect

>
>
>>
>>  io/channel-watch.c | 4 ----
>>  1 file changed, 4 deletions(-)
>>
>> diff --git a/io/channel-watch.c b/io/channel-watch.c
>> index 89f3c8a88a..e34d86e810 100644
>> --- a/io/channel-watch.c
>> +++ b/io/channel-watch.c
>> @@ -115,17 +115,13 @@ static gboolean
>>  qio_channel_socket_source_check(GSource *source)
>>  {
>>      static struct timeval tv0;
>> -
>>      QIOChannelSocketSource *ssource = (QIOChannelSocketSource *)source;
>> -    WSANETWORKEVENTS ev;
>>      fd_set rfds, wfds, xfds;
>>
>>      if (!ssource->condition) {
>>          return 0;
>>      }
>>
>> -    WSAEnumNetworkEvents(ssource->socket, ssource->ioc->event, &ev);
>> -
>>      FD_ZERO(&rfds);
>>      FD_ZERO(&wfds);
>>      FD_ZERO(&xfds);
>
>
> Unrelated, after this chunk, there is
>         FD_SET((SOCKET)ssource->socket, &rfds);
>
> it seems we can drop the cast. Feel free to send another patch.
>

Yeah, this cast is unnecessary. Will spin a new patch in v2. Thanks!

Regards,
Bin


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

* Re: [PATCH 22/51] tests/qtest: qmp-test: Skip running test_qmp_oob for win32
  2022-08-29 15:06       ` Markus Armbruster
@ 2022-09-04 14:07         ` Philippe Mathieu-Daudé via
  0 siblings, 0 replies; 174+ messages in thread
From: Philippe Mathieu-Daudé via @ 2022-09-04 14:07 UTC (permalink / raw)
  To: Markus Armbruster, Bin Meng
  Cc: qemu-devel@nongnu.org Developers, Bin Meng, Laurent Vivier,
	Paolo Bonzini, Thomas Huth

On 29/8/22 17:06, Markus Armbruster wrote:
> Bin Meng <bmeng.cn@gmail.com> writes:
> 
>> Hi Markus,
>>
>> On Mon, Aug 29, 2022 at 9:14 PM Markus Armbruster <armbru@redhat.com> wrote:
>>>
>>> Bin Meng <bmeng.cn@gmail.com> writes:
>>>
>>>> From: Bin Meng <bin.meng@windriver.com>
>>>>
>>>> The test_qmp_oob test case calls mkfifo() which does not exist on
>>>> win32. Exclude it.
>>>>
>>>> Signed-off-by: Bin Meng <bin.meng@windriver.com>
>>>> ---
>>>>
>>>>   tests/qtest/qmp-test.c | 6 ++++++
>>>>   1 file changed, 6 insertions(+)
>>>>
>>>> diff --git a/tests/qtest/qmp-test.c b/tests/qtest/qmp-test.c
>>>> index b950dbafaf..4a165447f8 100644
>>>> --- a/tests/qtest/qmp-test.c
>>>> +++ b/tests/qtest/qmp-test.c
>>>> @@ -159,6 +159,8 @@ static void test_qmp_protocol(void)
>>>>       qtest_quit(qts);
>>>>   }
>>>>
>>>> +#ifndef _WIN32
>>>> +
>>>>   /* Out-of-band tests */
>>>>
>>>>   char *tmpdir;
>>>> @@ -279,6 +281,8 @@ static void test_qmp_oob(void)
>>>>       qtest_quit(qts);
>>>>   }
>>>>
>>>> +#endif /* _WIN32 */
>>>> +
>>>>   /* Preconfig tests */
>>>>
>>>>   static void test_qmp_preconfig(void)
>>>> @@ -338,7 +342,9 @@ int main(int argc, char *argv[])
>>>>       g_test_init(&argc, &argv, NULL);
>>>>
>>>>       qtest_add_func("qmp/protocol", test_qmp_protocol);
>>>> +#ifndef _WIN32
>>>>       qtest_add_func("qmp/oob", test_qmp_oob);
>>>> +#endif
>>>>       qtest_add_func("qmp/preconfig", test_qmp_preconfig);
>>>>       qtest_add_func("qmp/missing-any-arg", test_qmp_missing_any_arg);
>>>
>>> I'd appreciate a comment explaining why we have to disable this test on
>>> Windows.
>>
>> The reason is explained in the commit message.
> 
> Yes, and putting it there is a good idea.  But I'd appreciate if you
> *also* put it in the code, so future readers of the code don't have to
> dig through git history.

This could be self-explicit using instead:

   #if HAVE_POSIX_MKFIFO


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

* Re: [PATCH 01/51] tests/qtest: Use g_setenv()
  2022-08-24  9:39 ` [PATCH 01/51] tests/qtest: Use g_setenv() Bin Meng
  2022-08-24 11:45   ` Thomas Huth
@ 2022-09-04 14:10   ` Philippe Mathieu-Daudé via
  1 sibling, 0 replies; 174+ messages in thread
From: Philippe Mathieu-Daudé via @ 2022-09-04 14:10 UTC (permalink / raw)
  To: Bin Meng, qemu-devel
  Cc: Bin Meng, Alexander Bulekov, Bandan Das, Darren Kenny,
	Laurent Vivier, Paolo Bonzini, Qiuhao Li, Stefan Hajnoczi,
	Thomas Huth

On 24/8/22 11:39, Bin Meng wrote:
> From: Bin Meng <bin.meng@windriver.com>
> 
> Windows does not provide a setenv() API, but glib does.
> Replace setenv() call with the glib version.
> 
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
> 
>   tests/qtest/fuzz/generic_fuzz.c | 8 ++++----
>   tests/qtest/libqtest.c          | 2 +-
>   2 files changed, 5 insertions(+), 5 deletions(-)

Should we warn for 'setenv' use in checkpatch?

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>


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

* Re: [PATCH 21/51] tests/qtest: migration-test: Skip running test_migrate_fd_proto on win32
  2022-08-24  9:39 ` [PATCH 21/51] tests/qtest: migration-test: Skip running test_migrate_fd_proto on win32 Bin Meng
  2022-08-24 18:49   ` Dr. David Alan Gilbert
@ 2022-09-04 14:15   ` Philippe Mathieu-Daudé via
  1 sibling, 0 replies; 174+ messages in thread
From: Philippe Mathieu-Daudé via @ 2022-09-04 14:15 UTC (permalink / raw)
  To: Bin Meng, qemu-devel
  Cc: Bin Meng, Dr. David Alan Gilbert, Juan Quintela, Laurent Vivier,
	Paolo Bonzini, Thomas Huth

On 24/8/22 11:39, Bin Meng wrote:
> From: Bin Meng <bin.meng@windriver.com>
> 
> The test case 'test_migrate_fd_proto' calls socketpair() which does
> not exist on win32. Exclude it. The helper function wait_command_fd()
> is not needed anymore, hence exclude it too.

I'd rather use a feature test, then check for the HAVE_POSIX_SOCKETPAIR
definition.

> 
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
> 
>   tests/qtest/migration-helpers.h | 2 ++
>   tests/qtest/migration-helpers.c | 2 ++
>   tests/qtest/migration-test.c    | 4 ++++
>   3 files changed, 8 insertions(+)


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

* Re: [PATCH 49/51] io/channel-watch: Fix socket watch on Windows
  2022-09-04  6:24     ` Bin Meng
@ 2022-09-05  6:04       ` Marc-André Lureau
  2022-09-05  6:13         ` Bin Meng
  0 siblings, 1 reply; 174+ messages in thread
From: Marc-André Lureau @ 2022-09-05  6:04 UTC (permalink / raw)
  To: Bin Meng
  Cc: qemu-devel@nongnu.org Developers, Bin Meng, Daniel P. Berrangé

[-- Attachment #1: Type: text/plain, Size: 5630 bytes --]

Hi

On Sun, Sep 4, 2022 at 10:24 AM Bin Meng <bmeng.cn@gmail.com> wrote:

> On Thu, Sep 1, 2022 at 8:58 PM Marc-André Lureau
> <marcandre.lureau@gmail.com> wrote:
> >
> > Hi
> >
> > On Wed, Aug 24, 2022 at 2:49 PM Bin Meng <bmeng.cn@gmail.com> wrote:
> >>
> >> From: Bin Meng <bin.meng@windriver.com>
> >>
> >> Random failure was observed when running qtests on Windows due to
> >> "Broken pipe" detected by qmp_fd_receive(). What happened is that
> >> the qtest executable sends testing data over a socket to the QEMU
> >> under test but no response is received. The errno of the recv()
> >> call from the qtest executable indicates ETIMEOUT, due to the qmp
> >> chardev's tcp_chr_read() is never called to receive testing data
> >> hence no response is sent to the other side.
> >>
> >> tcp_chr_read() is registered as the callback of the socket watch
> >> GSource. The reason of the callback not being called by glib, is
> >> that the source check fails to indicate the source is ready. There
> >> are two socket watch sources created to monitor the same socket
> >> event object from the char-socket backend in update_ioc_handlers().
> >>
> >> During the source check phase, qio_channel_socket_source_check()
> >> calls WSAEnumNetworkEvents() to discovers occurrences of network
> >> events for the indicated socket, clear internal network event records,
> >> and reset the event object. Testing shows that if we don't reset the
> >> event object by not passing the event handle to WSAEnumNetworkEvents()
> >> the symptom goes away and qtest runs very stably.
> >>
> >> It looks we don't need to call WSAEnumNetworkEvents() at all, as we
> >> don't parse the result of WSANETWORKEVENTS returned from this API.
> >> We use select() to poll the socket status. Fix this instability by
> >> dropping the WSAEnumNetworkEvents() call.
> >>
> >> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> >
> >
> > What clears the event then?
> >
>
> It seems we don't need to clear the event as everything still works as
> expected.
>

Well, it can "work" but are you sure it doesn't have a busy loop?

>>
> >> ---
> >> During the testing, I removed the following codes in
> update_ioc_handlers():
> >>
> >>     remove_hup_source(s);
> >>     s->hup_source = qio_channel_create_watch(s->ioc, G_IO_HUP);
> >>     g_source_set_callback(s->hup_source, (GSourceFunc)tcp_chr_hup,
> >>                           chr, NULL);
> >>     g_source_attach(s->hup_source, chr->gcontext);
> >>
> >> and such change also makes the symptom go away.
> >>
> >> And if I moved the above codes to the beginning, before the call to
> >> io_add_watch_poll(), the symptom also goes away.
> >>
> >> It seems two sources watching on the same socket event object is
> >> the key that leads to the instability. The order of adding a source
> >> watch seems to also play a role but I can't explain why.
> >> Hopefully a Windows and glib expert could explain this behavior.
> >>
> >
> > Feel free to leave that comment in the commit message.
>
> Sure, will add the above message into the commit in v2.
>
> >
> > This is strange, as both sources should have different events, clearing
> one shouldn't affect the other.
>
> Both sources have the same event, as one QIO channel only has one
> socket, and one socket can only be bound to one event.
>

 "one socket can only be bound to one event", is that a WSAEventSelect
limitation?


> >
> > I guess it's WSAEnumNetworkEvents clearing of the internal network event
> records that is problematic.
> >
> > Can you check if you replace the call with ResetEvent() everything works?
>
> No, ResetEvent() does not work, and is not recommended by MSDN [1]
> too, which says:
>

It probably works to some extent (I see glib is using it
https://gitlab.gnome.org/GNOME/glib/-/blob/main/glib/giowin32.c#L903), What
you mean is that it doesn't solve the issue, I guess.

>
> The proper way to reset the state of an event object used with the
> WSAEventSelect function is to pass the handle of the event object to
> the WSAEnumNetworkEvents function in the hEventObject parameter. This
> will reset the event object and adjust the status of active FD events
> on the socket in an atomic fashion.
>
>
This is not what you want though if you have multiple event objects for the
same socket.


> [1]
> https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsaeventselect
>
> >
> >
> >>
> >>  io/channel-watch.c | 4 ----
> >>  1 file changed, 4 deletions(-)
> >>
> >> diff --git a/io/channel-watch.c b/io/channel-watch.c
> >> index 89f3c8a88a..e34d86e810 100644
> >> --- a/io/channel-watch.c
> >> +++ b/io/channel-watch.c
> >> @@ -115,17 +115,13 @@ static gboolean
> >>  qio_channel_socket_source_check(GSource *source)
> >>  {
> >>      static struct timeval tv0;
> >> -
> >>      QIOChannelSocketSource *ssource = (QIOChannelSocketSource *)source;
> >> -    WSANETWORKEVENTS ev;
> >>      fd_set rfds, wfds, xfds;
> >>
> >>      if (!ssource->condition) {
> >>          return 0;
> >>      }
> >>
> >> -    WSAEnumNetworkEvents(ssource->socket, ssource->ioc->event, &ev);
> >> -
> >>      FD_ZERO(&rfds);
> >>      FD_ZERO(&wfds);
> >>      FD_ZERO(&xfds);
> >
> >
> > Unrelated, after this chunk, there is
> >         FD_SET((SOCKET)ssource->socket, &rfds);
> >
> > it seems we can drop the cast. Feel free to send another patch.
> >
>
> Yeah, this cast is unnecessary. Will spin a new patch in v2. Thanks!
>
> Regards,
> Bin
>


-- 
Marc-André Lureau

[-- Attachment #2: Type: text/html, Size: 8131 bytes --]

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

* Re: [PATCH 49/51] io/channel-watch: Fix socket watch on Windows
  2022-09-05  6:04       ` Marc-André Lureau
@ 2022-09-05  6:13         ` Bin Meng
  2022-09-05  8:10           ` Clément Chigot
  0 siblings, 1 reply; 174+ messages in thread
From: Bin Meng @ 2022-09-05  6:13 UTC (permalink / raw)
  To: Marc-André Lureau
  Cc: qemu-devel@nongnu.org Developers, Bin Meng, Daniel P. Berrangé

On Mon, Sep 5, 2022 at 2:04 PM Marc-André Lureau
<marcandre.lureau@gmail.com> wrote:
>
> Hi
>
> On Sun, Sep 4, 2022 at 10:24 AM Bin Meng <bmeng.cn@gmail.com> wrote:
>>
>> On Thu, Sep 1, 2022 at 8:58 PM Marc-André Lureau
>> <marcandre.lureau@gmail.com> wrote:
>> >
>> > Hi
>> >
>> > On Wed, Aug 24, 2022 at 2:49 PM Bin Meng <bmeng.cn@gmail.com> wrote:
>> >>
>> >> From: Bin Meng <bin.meng@windriver.com>
>> >>
>> >> Random failure was observed when running qtests on Windows due to
>> >> "Broken pipe" detected by qmp_fd_receive(). What happened is that
>> >> the qtest executable sends testing data over a socket to the QEMU
>> >> under test but no response is received. The errno of the recv()
>> >> call from the qtest executable indicates ETIMEOUT, due to the qmp
>> >> chardev's tcp_chr_read() is never called to receive testing data
>> >> hence no response is sent to the other side.
>> >>
>> >> tcp_chr_read() is registered as the callback of the socket watch
>> >> GSource. The reason of the callback not being called by glib, is
>> >> that the source check fails to indicate the source is ready. There
>> >> are two socket watch sources created to monitor the same socket
>> >> event object from the char-socket backend in update_ioc_handlers().
>> >>
>> >> During the source check phase, qio_channel_socket_source_check()
>> >> calls WSAEnumNetworkEvents() to discovers occurrences of network
>> >> events for the indicated socket, clear internal network event records,
>> >> and reset the event object. Testing shows that if we don't reset the
>> >> event object by not passing the event handle to WSAEnumNetworkEvents()
>> >> the symptom goes away and qtest runs very stably.
>> >>
>> >> It looks we don't need to call WSAEnumNetworkEvents() at all, as we
>> >> don't parse the result of WSANETWORKEVENTS returned from this API.
>> >> We use select() to poll the socket status. Fix this instability by
>> >> dropping the WSAEnumNetworkEvents() call.
>> >>
>> >> Signed-off-by: Bin Meng <bin.meng@windriver.com>
>> >
>> >
>> > What clears the event then?
>> >
>>
>> It seems we don't need to clear the event as everything still works as expected.
>
>
> Well, it can "work" but are you sure it doesn't have a busy loop?

You mean busy loop in g_poll()?

>> >>
>> >> ---
>> >> During the testing, I removed the following codes in update_ioc_handlers():
>> >>
>> >>     remove_hup_source(s);
>> >>     s->hup_source = qio_channel_create_watch(s->ioc, G_IO_HUP);
>> >>     g_source_set_callback(s->hup_source, (GSourceFunc)tcp_chr_hup,
>> >>                           chr, NULL);
>> >>     g_source_attach(s->hup_source, chr->gcontext);
>> >>
>> >> and such change also makes the symptom go away.
>> >>
>> >> And if I moved the above codes to the beginning, before the call to
>> >> io_add_watch_poll(), the symptom also goes away.
>> >>
>> >> It seems two sources watching on the same socket event object is
>> >> the key that leads to the instability. The order of adding a source
>> >> watch seems to also play a role but I can't explain why.
>> >> Hopefully a Windows and glib expert could explain this behavior.
>> >>
>> >
>> > Feel free to leave that comment in the commit message.
>>
>> Sure, will add the above message into the commit in v2.
>>
>> >
>> > This is strange, as both sources should have different events, clearing one shouldn't affect the other.
>>
>> Both sources have the same event, as one QIO channel only has one
>> socket, and one socket can only be bound to one event.
>
>
>  "one socket can only be bound to one event", is that a WSAEventSelect limitation?
>

Yes, please see the MSDN:

It is not possible to specify different event objects for different
network events. The following code will not work; the second call will
cancel the effects of the first, and only the FD_WRITE network event
will be associated with hEventObject2:

rc = WSAEventSelect(s, hEventObject1, FD_READ);
rc = WSAEventSelect(s, hEventObject2, FD_WRITE); //bad

>>
>> >
>> > I guess it's WSAEnumNetworkEvents clearing of the internal network event records that is problematic.
>> >
>> > Can you check if you replace the call with ResetEvent() everything works?
>>
>> No, ResetEvent() does not work, and is not recommended by MSDN [1]
>> too, which says:
>
>
> It probably works to some extent (I see glib is using it https://gitlab.gnome.org/GNOME/glib/-/blob/main/glib/giowin32.c#L903), What you mean is that it doesn't solve the issue, I guess.

Correct, it does not solve the issue.

>>
>>
>> The proper way to reset the state of an event object used with the
>> WSAEventSelect function is to pass the handle of the event object to
>> the WSAEnumNetworkEvents function in the hEventObject parameter. This
>> will reset the event object and adjust the status of active FD events
>> on the socket in an atomic fashion.
>>
>
> This is not what you want though if you have multiple event objects for the same socket.
>
>>
>> [1] https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsaeventselect

Regards,
Bin


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

* Re: [PATCH 49/51] io/channel-watch: Fix socket watch on Windows
  2022-09-05  6:13         ` Bin Meng
@ 2022-09-05  8:10           ` Clément Chigot
  2022-09-06  7:00             ` Bin Meng
  0 siblings, 1 reply; 174+ messages in thread
From: Clément Chigot @ 2022-09-05  8:10 UTC (permalink / raw)
  To: Bin Meng
  Cc: Marc-André Lureau, qemu-devel@nongnu.org Developers,
	Bin Meng, Daniel P. Berrangé

[-- Attachment #1: Type: text/plain, Size: 4284 bytes --]

Hi all,

I did reach the same issue while trying to connect a gdb to qemu on
Windows hosts. Some inputs send by gdb aren't getting correctly pulled,
they will be retrieved only once g_poll times out.

As you explained earlier, the issue, AFAICT, is that WSAEnumNetworkEvents
will reset the internal events before select can detect them.
Sadly, I didn't find any way to adjust the current code using select to
avoid that. As select and any cleaner (ever WSAEnumNetworkEvents or
WSEResetEvent) cannot be called in an atomic way, it seems that events
can always be received between the reset and the select. At least, all
my attempts failed.

The only solution I've found is to move completely to the Windows API
and stop calling select. This, however, needs some tricks. In Particular, we
need to "remove" the support of GSources having only G_IO_HUP.
This is already kind of done as we currently don't detect them in
qio_channel_socket_source_check anyway.
This is mandatory because of the two GSources created on the same socket.
IIRC, the first one (I'll call it the master GSource) is created during
the initialization of the channel-socket by update_ioc_handlers and will
have only G_IO_HUP to catch up.
The second one is created during the "prepare" phase of the first one,
in io_watch_poll_prepare. This one will have all the events we want
to pull (G_IO_IN here).
As they are referring to the same socket, the Windows API cannot know
on which GSources we want to catch which events. The solution is then
to avoid WSAEnumNetworkEvents for the master GSource which only has
G_IO_HUP (or for any GSource having only that).
As I said above, the current code doesn't do anything with it anyway.
So, IMO, it's safe to do so.

I'll send you my patch attached. I was planning to send it in the following
weeks anyway. I was just waiting to be sure everything looks fine on our
CI. Feel free to test and modify it if needed.

PS: I don't know if it will correctly extend if I simply attach it to
my mail. If not, tell me I'll simply copy-paste it, even if it might
mess up the space/tab stuff.

> >> >>
> >> >> ---
> >> >> During the testing, I removed the following codes in update_ioc_handlers():
> >> >>
> >> >>     remove_hup_source(s);
> >> >>     s->hup_source = qio_channel_create_watch(s->ioc, G_IO_HUP);
> >> >>     g_source_set_callback(s->hup_source, (GSourceFunc)tcp_chr_hup,
> >> >>                           chr, NULL);
> >> >>     g_source_attach(s->hup_source, chr->gcontext);
> >> >>
> >> >> and such change also makes the symptom go away.
> >> >>
> >> >> And if I moved the above codes to the beginning, before the call to
> >> >> io_add_watch_poll(), the symptom also goes away.
> >> >>
> >> >> It seems two sources watching on the same socket event object is
> >> >> the key that leads to the instability. The order of adding a source
> >> >> watch seems to also play a role but I can't explain why.
> >> >> Hopefully a Windows and glib expert could explain this behavior.
> >> >>
> >> >
> >> > Feel free to leave that comment in the commit message.
> >>
> >> Sure, will add the above message into the commit in v2.
> >>
> >> >
> >> > This is strange, as both sources should have different events, clearing one shouldn't affect the other.
> >>
> >> Both sources have the same event, as one QIO channel only has one
> >> socket, and one socket can only be bound to one event.
> >
> >
> >  "one socket can only be bound to one event", is that a WSAEventSelect limitation?
> >
>
> Yes, please see the MSDN:
>
> It is not possible to specify different event objects for different
> network events. The following code will not work; the second call will
> cancel the effects of the first, and only the FD_WRITE network event
> will be associated with hEventObject2:
>
> rc = WSAEventSelect(s, hEventObject1, FD_READ);
> rc = WSAEventSelect(s, hEventObject2, FD_WRITE); //bad

Yes, the Windows API is handled at socket levels. That's why having
two GSources on the same sockets is problematic.
Note that maybe there is a mix to be done between your patch with
the update_ioc_handlers part to be removed and my patch which improves
the polling of channel-watch.

Thanks,
Clément

[-- Attachment #2: 0001-io-switch-completely-to-Windows-API-for-socket-watch.patch --]
[-- Type: text/x-patch, Size: 5218 bytes --]

From 1948fc273c4f4b78f90c8ca8fbc22647e30f431c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cl=C3=A9ment=20Chigot?= <chigot@adacore.com>
Date: Wed, 24 Aug 2022 15:42:33 +0200
Subject: [PATCH] io: switch completely to Windows API for socket watch on
 win32

The current implementation is using a mixed of select and the Windows
API (WSASelectEvent, etc).
As select doesn't clear the Windows events, WSAENumNetworkEvents must be
called before select to do it.
However, as this operation isn't made atomically, some events might be
reset before being retrieved by select. Resulting in them being skipped
by the polling.

In order to avoid this issue, this patch improves socket watch to be
based solely on Windows API.

Note that because several GSources might be created for the same HANDLE,
this implementation has no way to know on which GSources an event must be
returned. However, it seems that only two GSources are created, a master
one with just "G_IO_HUP" and the child one which aims to retrieve all
the events (ie with "G_IO_IN", "G_IO_OUT", etc). So, to avoid the master
GSource receiving events meant for the child, we aren't calling
WSAEnumNetworkEvents for it (or for any GSource having only G_IO_HUP as
condition). As G_IO_HUP was never returned by the previous, I supposed
that it should be safe to do so.

TN: V812-020
Change-Id: I037fbe93e0641894b0096c39ace5d0d68db8e2e3
---
 io/channel-socket.c |  2 +-
 io/channel-watch.c  | 57 +++++++++++++++++++++++----------------------
 2 files changed, 30 insertions(+), 29 deletions(-)

diff --git a/io/channel-socket.c b/io/channel-socket.c
index b76dca9cc1..75500e5647 100644
--- a/io/channel-socket.c
+++ b/io/channel-socket.c
@@ -69,7 +69,7 @@ qio_channel_socket_new(void)
     qio_channel_set_feature(ioc, QIO_CHANNEL_FEATURE_SHUTDOWN);
 
 #ifdef WIN32
-    ioc->event = CreateEvent(NULL, FALSE, FALSE, NULL);
+    ioc->event = WSACreateEvent();
 #endif
 
     trace_qio_channel_socket_new(sioc);
diff --git a/io/channel-watch.c b/io/channel-watch.c
index 0289b3647c..9c9aca41f5 100644
--- a/io/channel-watch.c
+++ b/io/channel-watch.c
@@ -114,46 +114,39 @@ qio_channel_socket_source_prepare(GSource *source G_GNUC_UNUSED,
 static gboolean
 qio_channel_socket_source_check(GSource *source)
 {
-    static struct timeval tv0;
-
     QIOChannelSocketSource *ssource = (QIOChannelSocketSource *)source;
     WSANETWORKEVENTS ev;
-    fd_set rfds, wfds, xfds;
 
     if (!ssource->condition) {
         return 0;
     }
 
-    WSAEnumNetworkEvents(ssource->socket, ssource->ioc->event, &ev);
-
-    FD_ZERO(&rfds);
-    FD_ZERO(&wfds);
-    FD_ZERO(&xfds);
-    if (ssource->condition & G_IO_IN) {
-        FD_SET((SOCKET)ssource->socket, &rfds);
-    }
-    if (ssource->condition & G_IO_OUT) {
-        FD_SET((SOCKET)ssource->socket, &wfds);
-    }
-    if (ssource->condition & G_IO_PRI) {
-        FD_SET((SOCKET)ssource->socket, &xfds);
+    /* For now, we don't support G_IO_HUP checks.
+       We want to avoid calling WSAEnumNetworkEvents for any GSource
+       having just G_IO_HUP. It might hide events aimed to be retrieved by
+       other GSources waiting inputs or outputs (ie with G_IO_IN or G_IO_OUT).
+       The reason is that the Windows API is based on HANDLE but we often
+       create several GSources for the same HANDLE. Thus, input events might
+       be picked and cleared by the G_IO_HUP GSource.  */
+    if (ssource->condition == G_IO_HUP) {
+        return 0;
     }
-    ssource->revents = 0;
-    if (select(0, &rfds, &wfds, &xfds, &tv0) == 0) {
+
+    if (WSAEnumNetworkEvents(ssource->socket, ssource->ioc->event, &ev)) {
         return 0;
     }
 
-    if (FD_ISSET(ssource->socket, &rfds)) {
+    ssource->revents = 0;
+
+    if (ev.lNetworkEvents & (FD_READ | FD_ACCEPT | FD_OOB)) {
         ssource->revents |= G_IO_IN;
     }
-    if (FD_ISSET(ssource->socket, &wfds)) {
+
+    if (ev.lNetworkEvents & (FD_WRITE | FD_CONNECT)) {
         ssource->revents |= G_IO_OUT;
     }
-    if (FD_ISSET(ssource->socket, &xfds)) {
-        ssource->revents |= G_IO_PRI;
-    }
 
-    return ssource->revents;
+    return ssource->revents & ssource->condition;
 }
 
 
@@ -174,6 +167,7 @@ qio_channel_socket_source_finalize(GSource *source)
 {
     QIOChannelSocketSource *ssource = (QIOChannelSocketSource *)source;
 
+
     object_unref(OBJECT(ssource->ioc));
 }
 
@@ -286,9 +280,16 @@ GSource *qio_channel_create_socket_watch(QIOChannel *ioc,
     QIOChannelSocketSource *ssource;
 
 #ifdef WIN32
-    WSAEventSelect(socket, ioc->event,
-                   FD_READ | FD_ACCEPT | FD_CLOSE |
-                   FD_CONNECT | FD_WRITE | FD_OOB);
+    int ev = 0;
+
+    if (condition & G_IO_IN) {
+        ev |= (FD_READ | FD_ACCEPT | FD_OOB);
+    }
+    if (condition & G_IO_OUT) {
+        ev |= (FD_WRITE | FD_CONNECT);
+    }
+
+    WSAEventSelect(socket, ioc->event, ev);
 #endif
 
     source = g_source_new(&qio_channel_socket_source_funcs,
@@ -303,7 +304,7 @@ GSource *qio_channel_create_socket_watch(QIOChannel *ioc,
     ssource->revents = 0;
 
     ssource->fd.fd = (gintptr)ioc->event;
-    ssource->fd.events = G_IO_IN;
+    ssource->fd.events = condition;
 
     g_source_add_poll(source, &ssource->fd);
 
-- 
2.25.1


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

* Re: [PATCH 49/51] io/channel-watch: Fix socket watch on Windows
  2022-09-05  8:10           ` Clément Chigot
@ 2022-09-06  7:00             ` Bin Meng
  2022-09-06  7:41               ` Clément Chigot
  0 siblings, 1 reply; 174+ messages in thread
From: Bin Meng @ 2022-09-06  7:00 UTC (permalink / raw)
  To: Clément Chigot, Paolo Bonzini
  Cc: Marc-André Lureau, qemu-devel@nongnu.org Developers,
	Bin Meng, Daniel P. Berrangé

Hi Clément,

On Mon, Sep 5, 2022 at 4:10 PM Clément Chigot <chigot@adacore.com> wrote:
>
> Hi all,
>
> I did reach the same issue while trying to connect a gdb to qemu on
> Windows hosts. Some inputs send by gdb aren't getting correctly pulled,
> they will be retrieved only once g_poll times out.
>
> As you explained earlier, the issue, AFAICT, is that WSAEnumNetworkEvents
> will reset the internal events before select can detect them.

No, I don't think WSAEnumNetworkEvents and select cannot be used together.

MSDN says:
https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-select

"The select function has no effect on the persistence of socket events
registered with WSAAsyncSelect or WSAEventSelect."

That sounds to me like current usage in QEMU codes does not have a problem.

> Sadly, I didn't find any way to adjust the current code using select to
> avoid that. As select and any cleaner (ever WSAEnumNetworkEvents or
> WSEResetEvent) cannot be called in an atomic way, it seems that events
> can always be received between the reset and the select. At least, all
> my attempts failed.

According to MSDN:
https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsaeventselect

"Having successfully recorded the occurrence of the network event (by
setting the corresponding bit in the internal network event record)
and signaled the associated event object, no further actions are taken
for that network event until the application makes the function call
that implicitly reenables the setting of that network event and
signaling of the associated event object."

So events will be kept unsignaled after they are signaled, until the
reenable routine is called. For example, recv() for the FD_READ event.

>
> The only solution I've found is to move completely to the Windows API
> and stop calling select. This, however, needs some tricks. In Particular, we
> need to "remove" the support of GSources having only G_IO_HUP.
> This is already kind of done as we currently don't detect them in
> qio_channel_socket_source_check anyway.
> This is mandatory because of the two GSources created on the same socket.
> IIRC, the first one (I'll call it the master GSource) is created during
> the initialization of the channel-socket by update_ioc_handlers and will
> have only G_IO_HUP to catch up.
> The second one is created during the "prepare" phase of the first one,
> in io_watch_poll_prepare. This one will have all the events we want
> to pull (G_IO_IN here).
> As they are referring to the same socket, the Windows API cannot know
> on which GSources we want to catch which events. The solution is then

I think Windows knows which events to catch. As WSAEventSelect() in
channel-watch.c::qio_channel_create_socket_watch() tells Windows which
event it should monitor.

Both the "master" and "child" GSources are watching on the same socket
with G_IO_IN condition (see qio_channel_create_socket_watch), and GLib
is smart enough to merge these two resources into one in the event
handle array which is passed to WaitForMultipleObjectsEx() in
g_poll().

I checked your patch, what you did seems to be something one would
naturally write, but what is currently in the QEMU sources seems to be
written intentionally.

+Paolo Bonzini , you are the one who implemented the socket watch on
Windows. Could you please help analyze this issue?

> to avoid WSAEnumNetworkEvents for the master GSource which only has
> G_IO_HUP (or for any GSource having only that).
> As I said above, the current code doesn't do anything with it anyway.
> So, IMO, it's safe to do so.
>
> I'll send you my patch attached. I was planning to send it in the following
> weeks anyway. I was just waiting to be sure everything looks fine on our
> CI. Feel free to test and modify it if needed.

I tested your patch. Unfortunately there is still one test case
(migration-test.exe) throwing up the "Broken pipe" message.

Can you test my patch instead to see if your gdb issue can be fixed?

>
> PS: I don't know if it will correctly extend if I simply attach it to
> my mail. If not, tell me I'll simply copy-paste it, even if it might
> mess up the space/tab stuff.
>
> > >> >>
> > >> >> ---
> > >> >> During the testing, I removed the following codes in update_ioc_handlers():
> > >> >>
> > >> >>     remove_hup_source(s);
> > >> >>     s->hup_source = qio_channel_create_watch(s->ioc, G_IO_HUP);
> > >> >>     g_source_set_callback(s->hup_source, (GSourceFunc)tcp_chr_hup,
> > >> >>                           chr, NULL);
> > >> >>     g_source_attach(s->hup_source, chr->gcontext);
> > >> >>
> > >> >> and such change also makes the symptom go away.
> > >> >>
> > >> >> And if I moved the above codes to the beginning, before the call to
> > >> >> io_add_watch_poll(), the symptom also goes away.
> > >> >>
> > >> >> It seems two sources watching on the same socket event object is
> > >> >> the key that leads to the instability. The order of adding a source
> > >> >> watch seems to also play a role but I can't explain why.
> > >> >> Hopefully a Windows and glib expert could explain this behavior.
> > >> >>
> > >> >
> > >> > Feel free to leave that comment in the commit message.
> > >>
> > >> Sure, will add the above message into the commit in v2.
> > >>
> > >> >
> > >> > This is strange, as both sources should have different events, clearing one shouldn't affect the other.
> > >>
> > >> Both sources have the same event, as one QIO channel only has one
> > >> socket, and one socket can only be bound to one event.
> > >
> > >
> > >  "one socket can only be bound to one event", is that a WSAEventSelect limitation?
> > >
> >
> > Yes, please see the MSDN:
> >
> > It is not possible to specify different event objects for different
> > network events. The following code will not work; the second call will
> > cancel the effects of the first, and only the FD_WRITE network event
> > will be associated with hEventObject2:
> >
> > rc = WSAEventSelect(s, hEventObject1, FD_READ);
> > rc = WSAEventSelect(s, hEventObject2, FD_WRITE); //bad
>
> Yes, the Windows API is handled at socket levels. That's why having
> two GSources on the same sockets is problematic.
> Note that maybe there is a mix to be done between your patch with
> the update_ioc_handlers part to be removed and my patch which improves
> the polling of channel-watch.

Regards,
Bin


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

* Re: [PATCH 49/51] io/channel-watch: Fix socket watch on Windows
  2022-09-06  7:00             ` Bin Meng
@ 2022-09-06  7:41               ` Clément Chigot
  2022-09-06  8:14                 ` Bin Meng
  0 siblings, 1 reply; 174+ messages in thread
From: Clément Chigot @ 2022-09-06  7:41 UTC (permalink / raw)
  To: Bin Meng
  Cc: Paolo Bonzini, Marc-André Lureau,
	qemu-devel@nongnu.org Developers, Bin Meng,
	Daniel P. Berrangé

Hi Bin,

> On Mon, Sep 5, 2022 at 4:10 PM Clément Chigot <chigot@adacore.com> wrote:
> >
> > Hi all,
> >
> > I did reach the same issue while trying to connect a gdb to qemu on
> > Windows hosts. Some inputs send by gdb aren't getting correctly pulled,
> > they will be retrieved only once g_poll times out.
> >
> > As you explained earlier, the issue, AFAICT, is that WSAEnumNetworkEvents
> > will reset the internal events before select can detect them.
>
> No, I don't think WSAEnumNetworkEvents and select cannot be used together.
>
> MSDN says:
> https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-select
>
> "The select function has no effect on the persistence of socket events
> registered with WSAAsyncSelect or WSAEventSelect."
>
> That sounds to me like current usage in QEMU codes does not have a problem.

Yes, but WSAEnumNetworkEvents has effects. Thus, it might reset the
events before
select detects them no ?
Moreover, I'm not sure what they mean by "persistence of WSAEventSelect".
Does that mean that select doesn't change the events wanted to be
notified as set
by WSAEventSelect or that select isn't resetting the events once
retrieved, as you
imply ?
Moreover, the current code is creating the event object with
CreateEvent(NULL, FALSE, FALSE, NULL). The first FALSE implies that we want
an auto-reset. The MSDN doc says:

"Boolean that specifies whether a manual-reset or auto-reset event
object is created.
If TRUE, then you must use the ResetEvent function to manually reset
the state to
nonsignaled. If FALSE, the system automatically resets the state to nonsignaled
after a single waiting thread has been released."

However, I'm not sure if I understand correctly what "after a single
waiting thread
has been released." signified. Is the reset occuring after recv() or
after select or
WSAEnumNetworkEvents calls ? AFAIR, I've tried to move to manual-reset with
the current qemu but it doesn't change anything.

> > Sadly, I didn't find any way to adjust the current code using select to
> > avoid that. As select and any cleaner (ever WSAEnumNetworkEvents or
> > WSEResetEvent) cannot be called in an atomic way, it seems that events
> > can always be received between the reset and the select. At least, all
> > my attempts failed.
>
> According to MSDN:
> https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsaeventselect
>
> "Having successfully recorded the occurrence of the network event (by
> setting the corresponding bit in the internal network event record)
> and signaled the associated event object, no further actions are taken
> for that network event until the application makes the function call
> that implicitly reenables the setting of that network event and
> signaling of the associated event object."
>
> So events will be kept unsignaled after they are signaled, until the
> reenable routine is called. For example, recv() for the FD_READ event.

In my understanding, WSAEnumNetworkEvents states the opposite:
https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsaenumnetworkevents

"The Windows Sockets provider guarantees that the operations of copying
the network event record, clearing it and resetting any associated event
object are atomic, such that the next occurrence of a nominated network
event will cause the event object to become set."

> > The only solution I've found is to move completely to the Windows API
> > and stop calling select. This, however, needs some tricks. In Particular, we
> > need to "remove" the support of GSources having only G_IO_HUP.
> > This is already kind of done as we currently don't detect them in
> > qio_channel_socket_source_check anyway.
> > This is mandatory because of the two GSources created on the same socket.
> > IIRC, the first one (I'll call it the master GSource) is created during
> > the initialization of the channel-socket by update_ioc_handlers and will
> > have only G_IO_HUP to catch up.
> > The second one is created during the "prepare" phase of the first one,
> > in io_watch_poll_prepare. This one will have all the events we want
> > to pull (G_IO_IN here).
> > As they are referring to the same socket, the Windows API cannot know
> > on which GSources we want to catch which events. The solution is then
>
> I think Windows knows which events to catch. As WSAEventSelect() in
> channel-watch.c::qio_channel_create_socket_watch() tells Windows which
> event it should monitor.
>
> Both the "master" and "child" GSources are watching on the same socket
> with G_IO_IN condition (see qio_channel_create_socket_watch), and GLib
> is smart enough to merge these two resources into one in the event
> handle array which is passed to WaitForMultipleObjectsEx() in
> g_poll().

I've forgotten to mention it. But the current code only fails with newer glib
versions. I wasn't able to test all of them but it's working with 2.54 and
starts failing with versions after 2.60.
The qemu master isn't supporting 2.54 anymore. Thus I've tested that with
our internal qemu-6 which runs with 2.54. When upgrading glib, it starts
behaving like our issue.
Sadly, I wasn't able to test with glib-2.56/2.58 nor to find anything relevant
in glib code which would explain our issue. (But I wasn't aware of the
two GSources at that time so maybe it's worth investigating again).

> I checked your patch, what you did seems to be something one would
> naturally write, but what is currently in the QEMU sources seems to be
> written intentionally.
>
> +Paolo Bonzini , you are the one who implemented the socket watch on
> Windows. Could you please help analyze this issue?
>
> > to avoid WSAEnumNetworkEvents for the master GSource which only has
> > G_IO_HUP (or for any GSource having only that).
> > As I said above, the current code doesn't do anything with it anyway.
> > So, IMO, it's safe to do so.
> >
> > I'll send you my patch attached. I was planning to send it in the following
> > weeks anyway. I was just waiting to be sure everything looks fine on our
> > CI. Feel free to test and modify it if needed.
>
> I tested your patch. Unfortunately there is still one test case
> (migration-test.exe) throwing up the "Broken pipe" message.

I must say I didn't fully test it against qemu testsuite yet. Maybe there are
some refinements to be done. "Broken pipe" might be linked to the missing
G_IO_HUP support.

> Can you test my patch instead to see if your gdb issue can be fixed?

Yeah sure. I'll try to do it this afternoon.


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

* Re: [PATCH 49/51] io/channel-watch: Fix socket watch on Windows
  2022-09-06  7:41               ` Clément Chigot
@ 2022-09-06  8:14                 ` Bin Meng
  2022-09-06 12:06                   ` Clément Chigot
  0 siblings, 1 reply; 174+ messages in thread
From: Bin Meng @ 2022-09-06  8:14 UTC (permalink / raw)
  To: Clément Chigot
  Cc: Paolo Bonzini, Marc-André Lureau,
	qemu-devel@nongnu.org Developers, Bin Meng,
	Daniel P. Berrangé

Hi Clément,

On Tue, Sep 6, 2022 at 3:41 PM Clément Chigot <chigot@adacore.com> wrote:
>
> Hi Bin,
>
> > On Mon, Sep 5, 2022 at 4:10 PM Clément Chigot <chigot@adacore.com> wrote:
> > >
> > > Hi all,
> > >
> > > I did reach the same issue while trying to connect a gdb to qemu on
> > > Windows hosts. Some inputs send by gdb aren't getting correctly pulled,
> > > they will be retrieved only once g_poll times out.
> > >
> > > As you explained earlier, the issue, AFAICT, is that WSAEnumNetworkEvents
> > > will reset the internal events before select can detect them.
> >
> > No, I don't think WSAEnumNetworkEvents and select cannot be used together.
> >
> > MSDN says:
> > https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-select
> >
> > "The select function has no effect on the persistence of socket events
> > registered with WSAAsyncSelect or WSAEventSelect."
> >
> > That sounds to me like current usage in QEMU codes does not have a problem.
>
> Yes, but WSAEnumNetworkEvents has effects. Thus, it might reset the
> events before
> select detects them no ?

Even if the event *handle* is reset, select can still detect the
network event has happened. I think the above MSDN statement is trying
to explain this.

> Moreover, I'm not sure what they mean by "persistence of WSAEventSelect".
> Does that mean that select doesn't change the events wanted to be
> notified as set
> by WSAEventSelect or that select isn't resetting the events once
> retrieved, as you
> imply ?

My understanding is that select just determines the socket status
neither from the event handle associated with the socket, nor does it
change anything on the event handle.

> Moreover, the current code is creating the event object with
> CreateEvent(NULL, FALSE, FALSE, NULL). The first FALSE implies that we want
> an auto-reset. The MSDN doc says:
>
> "Boolean that specifies whether a manual-reset or auto-reset event
> object is created.
> If TRUE, then you must use the ResetEvent function to manually reset
> the state to
> nonsignaled. If FALSE, the system automatically resets the state to nonsignaled
> after a single waiting thread has been released."

Yes, I think this is a bug however when I changed to CreateEvent(NULL,
TRUE, FALSE, NULL) or WSACreateEvent() there are still "Broken pipe"
errors ...

> However, I'm not sure if I understand correctly what "after a single
> waiting thread
> has been released." signified. Is the reset occuring after recv() or
> after select or
> WSAEnumNetworkEvents calls ? AFAIR, I've tried to move to manual-reset with
> the current qemu but it doesn't change anything.

The same here :(

>
> > > Sadly, I didn't find any way to adjust the current code using select to
> > > avoid that. As select and any cleaner (ever WSAEnumNetworkEvents or
> > > WSEResetEvent) cannot be called in an atomic way, it seems that events
> > > can always be received between the reset and the select. At least, all
> > > my attempts failed.
> >
> > According to MSDN:
> > https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsaeventselect
> >
> > "Having successfully recorded the occurrence of the network event (by
> > setting the corresponding bit in the internal network event record)
> > and signaled the associated event object, no further actions are taken
> > for that network event until the application makes the function call
> > that implicitly reenables the setting of that network event and
> > signaling of the associated event object."
> >
> > So events will be kept unsignaled after they are signaled, until the
> > reenable routine is called. For example, recv() for the FD_READ event.
>
> In my understanding, WSAEnumNetworkEvents states the opposite:
> https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsaenumnetworkevents
>
> "The Windows Sockets provider guarantees that the operations of copying
> the network event record, clearing it and resetting any associated event
> object are atomic, such that the next occurrence of a nominated network
> event will cause the event object to become set."

My interpretation of this does not conflict with the WSAEventSelect().
I think they are just two things.

>
> > > The only solution I've found is to move completely to the Windows API
> > > and stop calling select. This, however, needs some tricks. In Particular, we
> > > need to "remove" the support of GSources having only G_IO_HUP.
> > > This is already kind of done as we currently don't detect them in
> > > qio_channel_socket_source_check anyway.
> > > This is mandatory because of the two GSources created on the same socket.
> > > IIRC, the first one (I'll call it the master GSource) is created during
> > > the initialization of the channel-socket by update_ioc_handlers and will
> > > have only G_IO_HUP to catch up.
> > > The second one is created during the "prepare" phase of the first one,
> > > in io_watch_poll_prepare. This one will have all the events we want
> > > to pull (G_IO_IN here).
> > > As they are referring to the same socket, the Windows API cannot know
> > > on which GSources we want to catch which events. The solution is then
> >
> > I think Windows knows which events to catch. As WSAEventSelect() in
> > channel-watch.c::qio_channel_create_socket_watch() tells Windows which
> > event it should monitor.
> >
> > Both the "master" and "child" GSources are watching on the same socket
> > with G_IO_IN condition (see qio_channel_create_socket_watch), and GLib
> > is smart enough to merge these two resources into one in the event
> > handle array which is passed to WaitForMultipleObjectsEx() in
> > g_poll().
>
> I've forgotten to mention it. But the current code only fails with newer glib
> versions. I wasn't able to test all of them but it's working with 2.54 and
> starts failing with versions after 2.60.
> The qemu master isn't supporting 2.54 anymore. Thus I've tested that with
> our internal qemu-6 which runs with 2.54. When upgrading glib, it starts
> behaving like our issue.
> Sadly, I wasn't able to test with glib-2.56/2.58 nor to find anything relevant
> in glib code which would explain our issue. (But I wasn't aware of the
> two GSources at that time so maybe it's worth investigating again).
>

Ah, good to know glib version matters.

> > I checked your patch, what you did seems to be something one would
> > naturally write, but what is currently in the QEMU sources seems to be
> > written intentionally.
> >
> > +Paolo Bonzini , you are the one who implemented the socket watch on
> > Windows. Could you please help analyze this issue?
> >
> > > to avoid WSAEnumNetworkEvents for the master GSource which only has
> > > G_IO_HUP (or for any GSource having only that).
> > > As I said above, the current code doesn't do anything with it anyway.
> > > So, IMO, it's safe to do so.
> > >
> > > I'll send you my patch attached. I was planning to send it in the following
> > > weeks anyway. I was just waiting to be sure everything looks fine on our
> > > CI. Feel free to test and modify it if needed.
> >
> > I tested your patch. Unfortunately there is still one test case
> > (migration-test.exe) throwing up the "Broken pipe" message.
>
> I must say I didn't fully test it against qemu testsuite yet. Maybe there are
> some refinements to be done. "Broken pipe" might be linked to the missing
> G_IO_HUP support.
>
> > Can you test my patch instead to see if your gdb issue can be fixed?
>
> Yeah sure. I'll try to do it this afternoon.

Thanks!

Regards,
Bin


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

* Re: [PATCH 49/51] io/channel-watch: Fix socket watch on Windows
  2022-09-06  8:14                 ` Bin Meng
@ 2022-09-06 12:06                   ` Clément Chigot
  2022-09-07  5:07                     ` Bin Meng
  0 siblings, 1 reply; 174+ messages in thread
From: Clément Chigot @ 2022-09-06 12:06 UTC (permalink / raw)
  To: Bin Meng
  Cc: Paolo Bonzini, Marc-André Lureau,
	qemu-devel@nongnu.org Developers, Bin Meng,
	Daniel P. Berrangé

> > > I checked your patch, what you did seems to be something one would
> > > naturally write, but what is currently in the QEMU sources seems to be
> > > written intentionally.
> > >
> > > +Paolo Bonzini , you are the one who implemented the socket watch on
> > > Windows. Could you please help analyze this issue?
> > >
> > > > to avoid WSAEnumNetworkEvents for the master GSource which only has
> > > > G_IO_HUP (or for any GSource having only that).
> > > > As I said above, the current code doesn't do anything with it anyway.
> > > > So, IMO, it's safe to do so.
> > > >
> > > > I'll send you my patch attached. I was planning to send it in the following
> > > > weeks anyway. I was just waiting to be sure everything looks fine on our
> > > > CI. Feel free to test and modify it if needed.
> > >
> > > I tested your patch. Unfortunately there is still one test case
> > > (migration-test.exe) throwing up the "Broken pipe" message.
> >
> > I must say I didn't fully test it against qemu testsuite yet. Maybe there are
> > some refinements to be done. "Broken pipe" might be linked to the missing
> > G_IO_HUP support.
> >
> > > Can you test my patch instead to see if your gdb issue can be fixed?
> >
> > Yeah sure. I'll try to do it this afternoon.

I can't explain how mad at me I am... I'm pretty sure your patch was the first
thing I've tried when I encountered this issue. But it wasn't working
or IIRC the
issue went away but that was because the polling was actually disabled (looping
indefinitely)...I'm suspecting that I already had changed the CreateEvent for
WSACreateEvent which forces you to handle the reset.
Finally, I end up struggling reworking the whole check function...
But yeah, your patch does work fine on my gdb issues too.

And I guess the events are reset when recv() is being called because of the
auto-reset feature set up by CreateEvent().
IIUC, what Marc-André means by busy loop is the polling being looping
indefinitely as I encountered. I can ensure that this patch doesn't do that.
It can be easily checked by setting the env variable G_MAIN_POLL_DEBUG.
It'll show what g_poll is doing and it's normally always available on
Windows.

Anyway, we'll wait for Paolo to see if he remembers why he had to call
WSAEnumNetworkEvents. Otherwize, let's go for your patch. Mine might
be a good start to improve the whole polling on Windows but if it doesn't
work in your case, it then needs some refinements.

Thanks,
Clément


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

* Re: [PATCH 49/51] io/channel-watch: Fix socket watch on Windows
  2022-09-06 12:06                   ` Clément Chigot
@ 2022-09-07  5:07                     ` Bin Meng
  2022-09-14  8:08                       ` Bin Meng
  0 siblings, 1 reply; 174+ messages in thread
From: Bin Meng @ 2022-09-07  5:07 UTC (permalink / raw)
  To: Clément Chigot
  Cc: Paolo Bonzini, Marc-André Lureau,
	qemu-devel@nongnu.org Developers, Bin Meng,
	Daniel P. Berrangé

Hi Clément,

On Tue, Sep 6, 2022 at 8:06 PM Clément Chigot <chigot@adacore.com> wrote:
>
> > > > I checked your patch, what you did seems to be something one would
> > > > naturally write, but what is currently in the QEMU sources seems to be
> > > > written intentionally.
> > > >
> > > > +Paolo Bonzini , you are the one who implemented the socket watch on
> > > > Windows. Could you please help analyze this issue?
> > > >
> > > > > to avoid WSAEnumNetworkEvents for the master GSource which only has
> > > > > G_IO_HUP (or for any GSource having only that).
> > > > > As I said above, the current code doesn't do anything with it anyway.
> > > > > So, IMO, it's safe to do so.
> > > > >
> > > > > I'll send you my patch attached. I was planning to send it in the following
> > > > > weeks anyway. I was just waiting to be sure everything looks fine on our
> > > > > CI. Feel free to test and modify it if needed.
> > > >
> > > > I tested your patch. Unfortunately there is still one test case
> > > > (migration-test.exe) throwing up the "Broken pipe" message.
> > >
> > > I must say I didn't fully test it against qemu testsuite yet. Maybe there are
> > > some refinements to be done. "Broken pipe" might be linked to the missing
> > > G_IO_HUP support.
> > >
> > > > Can you test my patch instead to see if your gdb issue can be fixed?
> > >
> > > Yeah sure. I'll try to do it this afternoon.
>
> I can't explain how mad at me I am... I'm pretty sure your patch was the first
> thing I've tried when I encountered this issue. But it wasn't working
> or IIRC the
> issue went away but that was because the polling was actually disabled (looping
> indefinitely)...I'm suspecting that I already had changed the CreateEvent for
> WSACreateEvent which forces you to handle the reset.
> Finally, I end up struggling reworking the whole check function...
> But yeah, your patch does work fine on my gdb issues too.

Good to know this patch works for you too.

> And I guess the events are reset when recv() is being called because of the
> auto-reset feature set up by CreateEvent().
> IIUC, what Marc-André means by busy loop is the polling being looping
> indefinitely as I encountered. I can ensure that this patch doesn't do that.
> It can be easily checked by setting the env variable G_MAIN_POLL_DEBUG.
> It'll show what g_poll is doing and it's normally always available on
> Windows.
>
> Anyway, we'll wait for Paolo to see if he remembers why he had to call
> WSAEnumNetworkEvents. Otherwize, let's go for your patch. Mine might
> be a good start to improve the whole polling on Windows but if it doesn't
> work in your case, it then needs some refinements.
>

Yeah, this issue bugged me quite a lot. If we want to reset the event
in qio_channel_socket_source_check(), we will have to do the following
to make sure qtests are happy.

diff --git a/io/channel-watch.c b/io/channel-watch.c
index 43d38494f7..f1e1650b81 100644
--- a/io/channel-watch.c
+++ b/io/channel-watch.c
@@ -124,8 +124,6 @@ qio_channel_socket_source_check(GSource *source)
return 0;
}
- WSAEnumNetworkEvents(ssource->socket, ssource->ioc->event, &ev);
-
FD_ZERO(&rfds);
FD_ZERO(&wfds);
FD_ZERO(&xfds);
@@ -153,6 +151,10 @@ qio_channel_socket_source_check(GSource *source)
ssource->revents |= G_IO_PRI;
}
+ if (ssource->revents) {
+ WSAEnumNetworkEvents(ssource->socket, ssource->ioc->event, &ev);
+ }
+
return ssource->revents;
}

Removing "if (ssource->revents)" won't work.

It seems to me that resetting the event twice (one time with the
master Gsource, and the other time with the child GSource) causes some
bizarre behavior. But MSDN [1] says

    "Resetting an event that is already reset has no effect."

[1] https://docs.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-resetevent

Regards,
Bin


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

* Re: [PATCH 49/51] io/channel-watch: Fix socket watch on Windows
  2022-09-07  5:07                     ` Bin Meng
@ 2022-09-14  8:08                       ` Bin Meng
  2022-09-21  1:02                         ` Bin Meng
  0 siblings, 1 reply; 174+ messages in thread
From: Bin Meng @ 2022-09-14  8:08 UTC (permalink / raw)
  To: Clément Chigot
  Cc: Paolo Bonzini, Marc-André Lureau,
	qemu-devel@nongnu.org Developers, Bin Meng,
	Daniel P. Berrangé

On Wed, Sep 7, 2022 at 1:07 PM Bin Meng <bmeng.cn@gmail.com> wrote:
>
> Hi Clément,
>
> On Tue, Sep 6, 2022 at 8:06 PM Clément Chigot <chigot@adacore.com> wrote:
> >
> > > > > I checked your patch, what you did seems to be something one would
> > > > > naturally write, but what is currently in the QEMU sources seems to be
> > > > > written intentionally.
> > > > >
> > > > > +Paolo Bonzini , you are the one who implemented the socket watch on
> > > > > Windows. Could you please help analyze this issue?
> > > > >
> > > > > > to avoid WSAEnumNetworkEvents for the master GSource which only has
> > > > > > G_IO_HUP (or for any GSource having only that).
> > > > > > As I said above, the current code doesn't do anything with it anyway.
> > > > > > So, IMO, it's safe to do so.
> > > > > >
> > > > > > I'll send you my patch attached. I was planning to send it in the following
> > > > > > weeks anyway. I was just waiting to be sure everything looks fine on our
> > > > > > CI. Feel free to test and modify it if needed.
> > > > >
> > > > > I tested your patch. Unfortunately there is still one test case
> > > > > (migration-test.exe) throwing up the "Broken pipe" message.
> > > >
> > > > I must say I didn't fully test it against qemu testsuite yet. Maybe there are
> > > > some refinements to be done. "Broken pipe" might be linked to the missing
> > > > G_IO_HUP support.
> > > >
> > > > > Can you test my patch instead to see if your gdb issue can be fixed?
> > > >
> > > > Yeah sure. I'll try to do it this afternoon.
> >
> > I can't explain how mad at me I am... I'm pretty sure your patch was the first
> > thing I've tried when I encountered this issue. But it wasn't working
> > or IIRC the
> > issue went away but that was because the polling was actually disabled (looping
> > indefinitely)...I'm suspecting that I already had changed the CreateEvent for
> > WSACreateEvent which forces you to handle the reset.
> > Finally, I end up struggling reworking the whole check function...
> > But yeah, your patch does work fine on my gdb issues too.
>
> Good to know this patch works for you too.
>
> > And I guess the events are reset when recv() is being called because of the
> > auto-reset feature set up by CreateEvent().
> > IIUC, what Marc-André means by busy loop is the polling being looping
> > indefinitely as I encountered. I can ensure that this patch doesn't do that.
> > It can be easily checked by setting the env variable G_MAIN_POLL_DEBUG.
> > It'll show what g_poll is doing and it's normally always available on
> > Windows.
> >
> > Anyway, we'll wait for Paolo to see if he remembers why he had to call
> > WSAEnumNetworkEvents. Otherwize, let's go for your patch. Mine might
> > be a good start to improve the whole polling on Windows but if it doesn't
> > work in your case, it then needs some refinements.
> >
>
> Yeah, this issue bugged me quite a lot. If we want to reset the event
> in qio_channel_socket_source_check(), we will have to do the following
> to make sure qtests are happy.
>
> diff --git a/io/channel-watch.c b/io/channel-watch.c
> index 43d38494f7..f1e1650b81 100644
> --- a/io/channel-watch.c
> +++ b/io/channel-watch.c
> @@ -124,8 +124,6 @@ qio_channel_socket_source_check(GSource *source)
> return 0;
> }
> - WSAEnumNetworkEvents(ssource->socket, ssource->ioc->event, &ev);
> -
> FD_ZERO(&rfds);
> FD_ZERO(&wfds);
> FD_ZERO(&xfds);
> @@ -153,6 +151,10 @@ qio_channel_socket_source_check(GSource *source)
> ssource->revents |= G_IO_PRI;
> }
> + if (ssource->revents) {
> + WSAEnumNetworkEvents(ssource->socket, ssource->ioc->event, &ev);
> + }
> +
> return ssource->revents;
> }
>
> Removing "if (ssource->revents)" won't work.
>
> It seems to me that resetting the event twice (one time with the
> master Gsource, and the other time with the child GSource) causes some
> bizarre behavior. But MSDN [1] says
>
>     "Resetting an event that is already reset has no effect."
>
> [1] https://docs.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-resetevent
>

Paolo, any comments about this issue?

Regards,
Bin


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

* Re: [PATCH 31/51] tests/qtest: Support libqtest to build and run on Windows
  2022-08-31 16:28   ` Marc-André Lureau
@ 2022-09-19 10:00     ` Bin Meng
  0 siblings, 0 replies; 174+ messages in thread
From: Bin Meng @ 2022-09-19 10:00 UTC (permalink / raw)
  To: Marc-André Lureau
  Cc: qemu-devel@nongnu.org Developers, Bin Meng, Xuzhou Cheng,
	Laurent Vivier, Paolo Bonzini, Thomas Huth

Hi,

On Thu, Sep 1, 2022 at 12:29 AM Marc-André Lureau
<marcandre.lureau@gmail.com> wrote:
>
> Hi
>
> On Wed, Aug 24, 2022 at 2:46 PM Bin Meng <bmeng.cn@gmail.com> wrote:
>>
>> From: Bin Meng <bin.meng@windriver.com>
>>
>> At present the libqtest codes were written to depend on several
>> POSIX APIs, including fork(), kill() and waitpid(). Unfortunately
>> these APIs are not available on Windows.
>>
>> This commit implements the corresponding functionalities using
>> win32 native APIs. With this change, all qtest cases can build
>> successfully on a Windows host, and we can start qtest testing
>> on Windows now.
>>
>> Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
>> Signed-off-by: Bin Meng <bin.meng@windriver.com>
>> ---
>>
>>  tests/qtest/libqtest.c  | 101 +++++++++++++++++++++++++++++++++++++++-
>>  tests/qtest/meson.build |   5 +-
>>  2 files changed, 101 insertions(+), 5 deletions(-)
>>
>> diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
>> index 70d7578740..99e52ff571 100644
>> --- a/tests/qtest/libqtest.c
>> +++ b/tests/qtest/libqtest.c
>> @@ -16,9 +16,11 @@
>>
>>  #include "qemu/osdep.h"
>>
>> +#ifndef _WIN32
>>  #include <sys/socket.h>
>>  #include <sys/wait.h>
>>  #include <sys/un.h>
>> +#endif /* _WIN32 */
>>  #ifdef __linux__
>>  #include <sys/prctl.h>
>>  #endif /* __linux__ */
>> @@ -27,6 +29,7 @@
>>  #include "libqmp.h"
>>  #include "qemu/ctype.h"
>>  #include "qemu/cutils.h"
>> +#include "qemu/sockets.h"
>>  #include "qapi/qmp/qdict.h"
>>  #include "qapi/qmp/qjson.h"
>>  #include "qapi/qmp/qlist.h"
>> @@ -35,6 +38,16 @@
>>  #define MAX_IRQ 256
>>  #define SOCKET_TIMEOUT 50
>>
>> +#ifndef _WIN32
>> +# define CMD_EXEC   "exec "
>> +# define DEV_STDERR "/dev/fd/2"
>> +# define DEV_NULL   "/dev/null"
>> +#else
>> +# define CMD_EXEC   ""
>> +# define DEV_STDERR "2"
>> +# define DEV_NULL   "nul"
>> +#endif
>> +
>>  typedef void (*QTestSendFn)(QTestState *s, const char *buf);
>>  typedef void (*ExternalSendFn)(void *s, const char *buf);
>>  typedef GString* (*QTestRecvFn)(QTestState *);
>> @@ -68,6 +81,9 @@ struct QTestState
>>  QTestState *global_qtest;
>>
>>  static GHookList abrt_hooks;
>> +#ifdef _WIN32
>> +typedef void (*sighandler_t)(int);
>> +#endif
>>  static sighandler_t sighandler_old;
>>
>>  static int qtest_query_target_endianness(QTestState *s);
>> @@ -120,10 +136,18 @@ bool qtest_probe_child(QTestState *s)
>>      pid_t pid = s->qemu_pid;
>>
>>      if (pid != -1) {
>> +#ifndef _WIN32
>>          pid = waitpid(pid, &s->wstatus, WNOHANG);
>>          if (pid == 0) {
>>              return true;
>>          }
>> +#else
>> +        DWORD exit_code;
>> +        GetExitCodeProcess((HANDLE)pid, &exit_code);
>> +        if (exit_code == STILL_ACTIVE) {
>> +            return true;
>> +        }
>> +#endif
>>          s->qemu_pid = -1;
>>      }
>>      return false;
>> @@ -137,13 +161,23 @@ void qtest_set_expected_status(QTestState *s, int status)
>>  void qtest_kill_qemu(QTestState *s)
>>  {
>>      pid_t pid = s->qemu_pid;
>> +#ifndef _WIN32
>>      int wstatus;
>> +#else
>> +    DWORD ret, exit_code;
>> +#endif
>>
>>      /* Skip wait if qtest_probe_child already reaped.  */
>>      if (pid != -1) {
>> +#ifndef _WIN32
>>          kill(pid, SIGTERM);
>>          TFR(pid = waitpid(s->qemu_pid, &s->wstatus, 0));
>>          assert(pid == s->qemu_pid);
>> +#else
>> +        TerminateProcess((HANDLE)pid, s->expected_status);
>> +        ret = WaitForSingleObject((HANDLE)pid, INFINITE);
>> +        assert(ret == WAIT_OBJECT_0);
>> +#endif
>>          s->qemu_pid = -1;
>>      }
>>
>> @@ -151,6 +185,7 @@ void qtest_kill_qemu(QTestState *s)
>>       * Check whether qemu exited with expected exit status; anything else is
>>       * fishy and should be logged with as much detail as possible.
>>       */
>> +#ifndef _WIN32
>>      wstatus = s->wstatus;
>>      if (WIFEXITED(wstatus) && WEXITSTATUS(wstatus) != s->expected_status) {
>>          fprintf(stderr, "%s:%d: kill_qemu() tried to terminate QEMU "
>> @@ -167,6 +202,16 @@ void qtest_kill_qemu(QTestState *s)
>>                  __FILE__, __LINE__, sig, signame, dump);
>>          abort();
>>      }
>> +#else
>> +    GetExitCodeProcess((HANDLE)pid, &exit_code);
>> +    CloseHandle((HANDLE)pid);
>> +    if (exit_code != s->expected_status) {
>> +        fprintf(stderr, "%s:%d: kill_qemu() tried to terminate QEMU "
>> +                "process but encountered exit status %ld (expected %d)\n",
>> +                __FILE__, __LINE__, exit_code, s->expected_status);
>> +        abort();
>> +    }
>> +#endif
>>  }
>>
>>  static void kill_qemu_hook_func(void *s)
>> @@ -245,6 +290,38 @@ static const char *qtest_qemu_binary(void)
>>      return qemu_bin;
>>  }
>>
>> +#ifdef _WIN32
>> +static pid_t qtest_create_process(char *cmd)
>> +{
>> +    STARTUPINFO si;
>> +    PROCESS_INFORMATION pi;
>> +    BOOL ret;
>> +
>> +    ZeroMemory(&si, sizeof(si));
>> +    si.cb = sizeof(si);
>> +    ZeroMemory(&pi, sizeof(pi));
>> +
>> +    ret = CreateProcess(NULL,   /* module name */
>> +                        cmd,    /* command line */
>> +                        NULL,   /* process handle not inheritable */
>> +                        NULL,   /* thread handle not inheritable */
>> +                        FALSE,  /* set handle inheritance to FALSE */
>> +                        0,      /* No creation flags */
>> +                        NULL,   /* use parent's environment block */
>> +                        NULL,   /* use parent's starting directory */
>> +                        &si,    /* pointer to STARTUPINFO structure */
>> +                        &pi     /* pointer to PROCESS_INFORMATION structure */
>> +                        );
>> +    if (ret == 0) {
>> +        fprintf(stderr, "%s:%d: unable to create a new process (%s)\n",
>> +                __FILE__, __LINE__, strerror(GetLastError()));
>> +        abort();
>> +    }
>> +
>> +    return (pid_t)pi.hProcess;
>> +}
>> +#endif /* _WIN32 */
>> +
>>  QTestState *qtest_init_without_qmp_handshake(const char *extra_args)
>>  {
>>      QTestState *s;
>> @@ -272,6 +349,9 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args)
>>      unlink(socket_path);
>>      unlink(qmp_socket_path);
>>
>> +#ifdef _WIN32
>> +    socket_init();
>> +#endif
>
>
> You can call this unconditionally, afaict
>

Will fix in v2.

>>
>>      sock = init_socket(socket_path);
>>      qmpsock = init_socket(qmp_socket_path);
>>
>> @@ -280,7 +360,7 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args)
>>
>>      qtest_add_abrt_handler(kill_qemu_hook_func, s);
>>
>> -    command = g_strdup_printf("exec %s %s"
>> +    command = g_strdup_printf(CMD_EXEC "%s %s"
>>                                "-qtest unix:%s "
>>                                "-qtest-log %s "
>>                                "-chardev socket,path=%s,id=char0 "
>> @@ -289,7 +369,7 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args)
>>                                "%s"
>>                                " -accel qtest",
>>                                qemu_binary, tracearg, socket_path,
>> -                              getenv("QTEST_LOG") ? "/dev/fd/2" : "/dev/null",
>> +                              getenv("QTEST_LOG") ? DEV_STDERR : DEV_NULL,
>>                                qmp_socket_path,
>>                                extra_args ?: "");
>>
>> @@ -298,6 +378,7 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args)
>>      s->pending_events = NULL;
>>      s->wstatus = 0;
>>      s->expected_status = 0;
>> +#ifndef _WIN32
>>      s->qemu_pid = fork();
>>      if (s->qemu_pid == 0) {
>>  #ifdef __linux__
>> @@ -320,6 +401,9 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args)
>>          execlp("/bin/sh", "sh", "-c", command, NULL);
>>          exit(1);
>>      }
>> +#else
>> +    s->qemu_pid = qtest_create_process(command);
>
>
> Why not replace the fork/exec with g_spawn_async() ?
>

I tried g_spawn_async(), but I am getting in trouble creating the
argument vector of the QEMU command lines, to pass in g_spawn_async().

g_strsplit() with SPACE as the delimiter does not work, as there might
be space in the command line surrounded by quotes.

g_shell_parse_argv() does not work either, as it just ate all Windows
path separator "\", so a patch name like
"D:\msys64\tmp/qtest-4220.qmp" becomes "D:msys64tmp/qtest-4220.qmp".

Do you have any suggestions?

>>
>> +#endif /* _WIN32 */
>>
>>      g_free(command);
>>      s->fd = socket_accept(sock);
>> @@ -338,9 +422,19 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args)
>>          s->irq_level[i] = false;
>>      }
>>
>> +    /*
>> +     * Stopping QEMU for debugging is not supported on Windows.
>> +     *
>> +     * Using DebugActiveProcess() API can suspend the QEMU process,
>> +     * but gdb cannot attach to the process. Using the undocumented
>> +     * NtSuspendProcess() can suspend the QEMU process and gdb can
>> +     * attach to the process, but gdb cannot resume it.
>> +     */
>> +#ifndef _WIN32
>>      if (getenv("QTEST_STOP")) {
>>          kill(s->qemu_pid, SIGSTOP);
>>      }
>> +#endif
>>
>>      /* ask endianness of the target */
>>
>> @@ -393,6 +487,9 @@ QTestState *qtest_init_with_serial(const char *extra_args, int *sock_fd)
>>      g_assert_true(g_mkdtemp(sock_dir) != NULL);
>>      sock_path = g_strdup_printf("%s/sock", sock_dir);
>>
>> +#ifdef _WIN32
>> +    socket_init();
>> +#endif
>
>
> same
>
>>
>>      sock_fd_init = init_socket(sock_path);
>>
>>      qts = qtest_initf("-chardev socket,id=s0,path=%s -serial chardev:s0 %s",
>> diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
>> index 0291b3966c..6d469a1822 100644
>> --- a/tests/qtest/meson.build
>> +++ b/tests/qtest/meson.build
>> @@ -1,6 +1,5 @@
>> -# All QTests for now are POSIX-only, but the dependencies are
>> -# really in libqtest, not in the testcases themselves.
>> -if not config_host.has_key('CONFIG_POSIX')
>> +# Build all QTests for POSIX and Windows
>> +if not config_host.has_key('CONFIG_POSIX') and not config_host.has_key('CONFIG_WIN32')
>>    subdir_done()
>>  endif
>>

Regards,
Bin


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

* Re: [PATCH 49/51] io/channel-watch: Fix socket watch on Windows
  2022-09-14  8:08                       ` Bin Meng
@ 2022-09-21  1:02                         ` Bin Meng
  2022-09-28  6:10                           ` Bin Meng
  0 siblings, 1 reply; 174+ messages in thread
From: Bin Meng @ 2022-09-21  1:02 UTC (permalink / raw)
  To: Clément Chigot
  Cc: Paolo Bonzini, Marc-André Lureau,
	qemu-devel@nongnu.org Developers, Bin Meng,
	Daniel P. Berrangé

On Wed, Sep 14, 2022 at 4:08 PM Bin Meng <bmeng.cn@gmail.com> wrote:
>
> On Wed, Sep 7, 2022 at 1:07 PM Bin Meng <bmeng.cn@gmail.com> wrote:
> >
> > Hi Clément,
> >
> > On Tue, Sep 6, 2022 at 8:06 PM Clément Chigot <chigot@adacore.com> wrote:
> > >
> > > > > > I checked your patch, what you did seems to be something one would
> > > > > > naturally write, but what is currently in the QEMU sources seems to be
> > > > > > written intentionally.
> > > > > >
> > > > > > +Paolo Bonzini , you are the one who implemented the socket watch on
> > > > > > Windows. Could you please help analyze this issue?
> > > > > >
> > > > > > > to avoid WSAEnumNetworkEvents for the master GSource which only has
> > > > > > > G_IO_HUP (or for any GSource having only that).
> > > > > > > As I said above, the current code doesn't do anything with it anyway.
> > > > > > > So, IMO, it's safe to do so.
> > > > > > >
> > > > > > > I'll send you my patch attached. I was planning to send it in the following
> > > > > > > weeks anyway. I was just waiting to be sure everything looks fine on our
> > > > > > > CI. Feel free to test and modify it if needed.
> > > > > >
> > > > > > I tested your patch. Unfortunately there is still one test case
> > > > > > (migration-test.exe) throwing up the "Broken pipe" message.
> > > > >
> > > > > I must say I didn't fully test it against qemu testsuite yet. Maybe there are
> > > > > some refinements to be done. "Broken pipe" might be linked to the missing
> > > > > G_IO_HUP support.
> > > > >
> > > > > > Can you test my patch instead to see if your gdb issue can be fixed?
> > > > >
> > > > > Yeah sure. I'll try to do it this afternoon.
> > >
> > > I can't explain how mad at me I am... I'm pretty sure your patch was the first
> > > thing I've tried when I encountered this issue. But it wasn't working
> > > or IIRC the
> > > issue went away but that was because the polling was actually disabled (looping
> > > indefinitely)...I'm suspecting that I already had changed the CreateEvent for
> > > WSACreateEvent which forces you to handle the reset.
> > > Finally, I end up struggling reworking the whole check function...
> > > But yeah, your patch does work fine on my gdb issues too.
> >
> > Good to know this patch works for you too.
> >
> > > And I guess the events are reset when recv() is being called because of the
> > > auto-reset feature set up by CreateEvent().
> > > IIUC, what Marc-André means by busy loop is the polling being looping
> > > indefinitely as I encountered. I can ensure that this patch doesn't do that.
> > > It can be easily checked by setting the env variable G_MAIN_POLL_DEBUG.
> > > It'll show what g_poll is doing and it's normally always available on
> > > Windows.
> > >
> > > Anyway, we'll wait for Paolo to see if he remembers why he had to call
> > > WSAEnumNetworkEvents. Otherwize, let's go for your patch. Mine might
> > > be a good start to improve the whole polling on Windows but if it doesn't
> > > work in your case, it then needs some refinements.
> > >
> >
> > Yeah, this issue bugged me quite a lot. If we want to reset the event
> > in qio_channel_socket_source_check(), we will have to do the following
> > to make sure qtests are happy.
> >
> > diff --git a/io/channel-watch.c b/io/channel-watch.c
> > index 43d38494f7..f1e1650b81 100644
> > --- a/io/channel-watch.c
> > +++ b/io/channel-watch.c
> > @@ -124,8 +124,6 @@ qio_channel_socket_source_check(GSource *source)
> > return 0;
> > }
> > - WSAEnumNetworkEvents(ssource->socket, ssource->ioc->event, &ev);
> > -
> > FD_ZERO(&rfds);
> > FD_ZERO(&wfds);
> > FD_ZERO(&xfds);
> > @@ -153,6 +151,10 @@ qio_channel_socket_source_check(GSource *source)
> > ssource->revents |= G_IO_PRI;
> > }
> > + if (ssource->revents) {
> > + WSAEnumNetworkEvents(ssource->socket, ssource->ioc->event, &ev);
> > + }
> > +
> > return ssource->revents;
> > }
> >
> > Removing "if (ssource->revents)" won't work.
> >
> > It seems to me that resetting the event twice (one time with the
> > master Gsource, and the other time with the child GSource) causes some
> > bizarre behavior. But MSDN [1] says
> >
> >     "Resetting an event that is already reset has no effect."
> >
> > [1] https://docs.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-resetevent
> >
>
> Paolo, any comments about this issue?
>

v2 series has been sent out, and this patch remains unchanged.

Paolo, still would appreciate your comments.

Regards,
Bin


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

* Re: [PATCH 49/51] io/channel-watch: Fix socket watch on Windows
  2022-09-21  1:02                         ` Bin Meng
@ 2022-09-28  6:10                           ` Bin Meng
  2022-10-06  3:03                             ` Bin Meng
  0 siblings, 1 reply; 174+ messages in thread
From: Bin Meng @ 2022-09-28  6:10 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Marc-André Lureau, qemu-devel@nongnu.org Developers,
	Bin Meng, Daniel P. Berrangé,
	Clément Chigot

Hi Paolo,

On Wed, Sep 21, 2022 at 9:02 AM Bin Meng <bmeng.cn@gmail.com> wrote:
>
> On Wed, Sep 14, 2022 at 4:08 PM Bin Meng <bmeng.cn@gmail.com> wrote:
> >
> > On Wed, Sep 7, 2022 at 1:07 PM Bin Meng <bmeng.cn@gmail.com> wrote:
> > >
> > > Hi Clément,
> > >
> > > On Tue, Sep 6, 2022 at 8:06 PM Clément Chigot <chigot@adacore.com> wrote:
> > > >
> > > > > > > I checked your patch, what you did seems to be something one would
> > > > > > > naturally write, but what is currently in the QEMU sources seems to be
> > > > > > > written intentionally.
> > > > > > >
> > > > > > > +Paolo Bonzini , you are the one who implemented the socket watch on
> > > > > > > Windows. Could you please help analyze this issue?
> > > > > > >
> > > > > > > > to avoid WSAEnumNetworkEvents for the master GSource which only has
> > > > > > > > G_IO_HUP (or for any GSource having only that).
> > > > > > > > As I said above, the current code doesn't do anything with it anyway.
> > > > > > > > So, IMO, it's safe to do so.
> > > > > > > >
> > > > > > > > I'll send you my patch attached. I was planning to send it in the following
> > > > > > > > weeks anyway. I was just waiting to be sure everything looks fine on our
> > > > > > > > CI. Feel free to test and modify it if needed.
> > > > > > >
> > > > > > > I tested your patch. Unfortunately there is still one test case
> > > > > > > (migration-test.exe) throwing up the "Broken pipe" message.
> > > > > >
> > > > > > I must say I didn't fully test it against qemu testsuite yet. Maybe there are
> > > > > > some refinements to be done. "Broken pipe" might be linked to the missing
> > > > > > G_IO_HUP support.
> > > > > >
> > > > > > > Can you test my patch instead to see if your gdb issue can be fixed?
> > > > > >
> > > > > > Yeah sure. I'll try to do it this afternoon.
> > > >
> > > > I can't explain how mad at me I am... I'm pretty sure your patch was the first
> > > > thing I've tried when I encountered this issue. But it wasn't working
> > > > or IIRC the
> > > > issue went away but that was because the polling was actually disabled (looping
> > > > indefinitely)...I'm suspecting that I already had changed the CreateEvent for
> > > > WSACreateEvent which forces you to handle the reset.
> > > > Finally, I end up struggling reworking the whole check function...
> > > > But yeah, your patch does work fine on my gdb issues too.
> > >
> > > Good to know this patch works for you too.
> > >
> > > > And I guess the events are reset when recv() is being called because of the
> > > > auto-reset feature set up by CreateEvent().
> > > > IIUC, what Marc-André means by busy loop is the polling being looping
> > > > indefinitely as I encountered. I can ensure that this patch doesn't do that.
> > > > It can be easily checked by setting the env variable G_MAIN_POLL_DEBUG.
> > > > It'll show what g_poll is doing and it's normally always available on
> > > > Windows.
> > > >
> > > > Anyway, we'll wait for Paolo to see if he remembers why he had to call
> > > > WSAEnumNetworkEvents. Otherwize, let's go for your patch. Mine might
> > > > be a good start to improve the whole polling on Windows but if it doesn't
> > > > work in your case, it then needs some refinements.
> > > >
> > >
> > > Yeah, this issue bugged me quite a lot. If we want to reset the event
> > > in qio_channel_socket_source_check(), we will have to do the following
> > > to make sure qtests are happy.
> > >
> > > diff --git a/io/channel-watch.c b/io/channel-watch.c
> > > index 43d38494f7..f1e1650b81 100644
> > > --- a/io/channel-watch.c
> > > +++ b/io/channel-watch.c
> > > @@ -124,8 +124,6 @@ qio_channel_socket_source_check(GSource *source)
> > > return 0;
> > > }
> > > - WSAEnumNetworkEvents(ssource->socket, ssource->ioc->event, &ev);
> > > -
> > > FD_ZERO(&rfds);
> > > FD_ZERO(&wfds);
> > > FD_ZERO(&xfds);
> > > @@ -153,6 +151,10 @@ qio_channel_socket_source_check(GSource *source)
> > > ssource->revents |= G_IO_PRI;
> > > }
> > > + if (ssource->revents) {
> > > + WSAEnumNetworkEvents(ssource->socket, ssource->ioc->event, &ev);
> > > + }
> > > +
> > > return ssource->revents;
> > > }
> > >
> > > Removing "if (ssource->revents)" won't work.
> > >
> > > It seems to me that resetting the event twice (one time with the
> > > master Gsource, and the other time with the child GSource) causes some
> > > bizarre behavior. But MSDN [1] says
> > >
> > >     "Resetting an event that is already reset has no effect."
> > >
> > > [1] https://docs.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-resetevent
> > >
> >
> > Paolo, any comments about this issue?
> >
>
> v2 series has been sent out, and this patch remains unchanged.
>
> Paolo, still would appreciate your comments.
>

Ping?

Regards,
Bin


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

* Re: [PATCH 49/51] io/channel-watch: Fix socket watch on Windows
  2022-09-28  6:10                           ` Bin Meng
@ 2022-10-06  3:03                             ` Bin Meng
  2022-10-11 10:42                               ` Bin Meng
  0 siblings, 1 reply; 174+ messages in thread
From: Bin Meng @ 2022-10-06  3:03 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Marc-André Lureau, qemu-devel@nongnu.org Developers,
	Bin Meng, Daniel P. Berrangé,
	Clément Chigot

Hi Paolo,

On Wed, Sep 28, 2022 at 2:10 PM Bin Meng <bmeng.cn@gmail.com> wrote:
>
> Hi Paolo,
>
> On Wed, Sep 21, 2022 at 9:02 AM Bin Meng <bmeng.cn@gmail.com> wrote:
> >
> > On Wed, Sep 14, 2022 at 4:08 PM Bin Meng <bmeng.cn@gmail.com> wrote:
> > >
> > > On Wed, Sep 7, 2022 at 1:07 PM Bin Meng <bmeng.cn@gmail.com> wrote:
> > > >
> > > > Hi Clément,
> > > >
> > > > On Tue, Sep 6, 2022 at 8:06 PM Clément Chigot <chigot@adacore.com> wrote:
> > > > >
> > > > > > > > I checked your patch, what you did seems to be something one would
> > > > > > > > naturally write, but what is currently in the QEMU sources seems to be
> > > > > > > > written intentionally.
> > > > > > > >
> > > > > > > > +Paolo Bonzini , you are the one who implemented the socket watch on
> > > > > > > > Windows. Could you please help analyze this issue?
> > > > > > > >
> > > > > > > > > to avoid WSAEnumNetworkEvents for the master GSource which only has
> > > > > > > > > G_IO_HUP (or for any GSource having only that).
> > > > > > > > > As I said above, the current code doesn't do anything with it anyway.
> > > > > > > > > So, IMO, it's safe to do so.
> > > > > > > > >
> > > > > > > > > I'll send you my patch attached. I was planning to send it in the following
> > > > > > > > > weeks anyway. I was just waiting to be sure everything looks fine on our
> > > > > > > > > CI. Feel free to test and modify it if needed.
> > > > > > > >
> > > > > > > > I tested your patch. Unfortunately there is still one test case
> > > > > > > > (migration-test.exe) throwing up the "Broken pipe" message.
> > > > > > >
> > > > > > > I must say I didn't fully test it against qemu testsuite yet. Maybe there are
> > > > > > > some refinements to be done. "Broken pipe" might be linked to the missing
> > > > > > > G_IO_HUP support.
> > > > > > >
> > > > > > > > Can you test my patch instead to see if your gdb issue can be fixed?
> > > > > > >
> > > > > > > Yeah sure. I'll try to do it this afternoon.
> > > > >
> > > > > I can't explain how mad at me I am... I'm pretty sure your patch was the first
> > > > > thing I've tried when I encountered this issue. But it wasn't working
> > > > > or IIRC the
> > > > > issue went away but that was because the polling was actually disabled (looping
> > > > > indefinitely)...I'm suspecting that I already had changed the CreateEvent for
> > > > > WSACreateEvent which forces you to handle the reset.
> > > > > Finally, I end up struggling reworking the whole check function...
> > > > > But yeah, your patch does work fine on my gdb issues too.
> > > >
> > > > Good to know this patch works for you too.
> > > >
> > > > > And I guess the events are reset when recv() is being called because of the
> > > > > auto-reset feature set up by CreateEvent().
> > > > > IIUC, what Marc-André means by busy loop is the polling being looping
> > > > > indefinitely as I encountered. I can ensure that this patch doesn't do that.
> > > > > It can be easily checked by setting the env variable G_MAIN_POLL_DEBUG.
> > > > > It'll show what g_poll is doing and it's normally always available on
> > > > > Windows.
> > > > >
> > > > > Anyway, we'll wait for Paolo to see if he remembers why he had to call
> > > > > WSAEnumNetworkEvents. Otherwize, let's go for your patch. Mine might
> > > > > be a good start to improve the whole polling on Windows but if it doesn't
> > > > > work in your case, it then needs some refinements.
> > > > >
> > > >
> > > > Yeah, this issue bugged me quite a lot. If we want to reset the event
> > > > in qio_channel_socket_source_check(), we will have to do the following
> > > > to make sure qtests are happy.
> > > >
> > > > diff --git a/io/channel-watch.c b/io/channel-watch.c
> > > > index 43d38494f7..f1e1650b81 100644
> > > > --- a/io/channel-watch.c
> > > > +++ b/io/channel-watch.c
> > > > @@ -124,8 +124,6 @@ qio_channel_socket_source_check(GSource *source)
> > > > return 0;
> > > > }
> > > > - WSAEnumNetworkEvents(ssource->socket, ssource->ioc->event, &ev);
> > > > -
> > > > FD_ZERO(&rfds);
> > > > FD_ZERO(&wfds);
> > > > FD_ZERO(&xfds);
> > > > @@ -153,6 +151,10 @@ qio_channel_socket_source_check(GSource *source)
> > > > ssource->revents |= G_IO_PRI;
> > > > }
> > > > + if (ssource->revents) {
> > > > + WSAEnumNetworkEvents(ssource->socket, ssource->ioc->event, &ev);
> > > > + }
> > > > +
> > > > return ssource->revents;
> > > > }
> > > >
> > > > Removing "if (ssource->revents)" won't work.
> > > >
> > > > It seems to me that resetting the event twice (one time with the
> > > > master Gsource, and the other time with the child GSource) causes some
> > > > bizarre behavior. But MSDN [1] says
> > > >
> > > >     "Resetting an event that is already reset has no effect."
> > > >
> > > > [1] https://docs.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-resetevent
> > > >
> > >
> > > Paolo, any comments about this issue?
> > >
> >
> > v2 series has been sent out, and this patch remains unchanged.
> >
> > Paolo, still would appreciate your comments.
> >
>
> Ping?
>

Ping? Can you please comment??

Regards,
Bin


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

* Re: [PATCH 49/51] io/channel-watch: Fix socket watch on Windows
  2022-10-06  3:03                             ` Bin Meng
@ 2022-10-11 10:42                               ` Bin Meng
  2022-10-17 12:21                                 ` Bin Meng
  0 siblings, 1 reply; 174+ messages in thread
From: Bin Meng @ 2022-10-11 10:42 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Marc-André Lureau, qemu-devel@nongnu.org Developers,
	Bin Meng, Daniel P. Berrangé,
	Clément Chigot

Hi Paolo,

On Thu, Oct 6, 2022 at 11:03 AM Bin Meng <bmeng.cn@gmail.com> wrote:
>
> Hi Paolo,
>
> On Wed, Sep 28, 2022 at 2:10 PM Bin Meng <bmeng.cn@gmail.com> wrote:
> >
> > Hi Paolo,
> >
> > On Wed, Sep 21, 2022 at 9:02 AM Bin Meng <bmeng.cn@gmail.com> wrote:
> > >
> > > On Wed, Sep 14, 2022 at 4:08 PM Bin Meng <bmeng.cn@gmail.com> wrote:
> > > >
> > > > On Wed, Sep 7, 2022 at 1:07 PM Bin Meng <bmeng.cn@gmail.com> wrote:
> > > > >
> > > > > Hi Clément,
> > > > >
> > > > > On Tue, Sep 6, 2022 at 8:06 PM Clément Chigot <chigot@adacore.com> wrote:
> > > > > >
> > > > > > > > > I checked your patch, what you did seems to be something one would
> > > > > > > > > naturally write, but what is currently in the QEMU sources seems to be
> > > > > > > > > written intentionally.
> > > > > > > > >
> > > > > > > > > +Paolo Bonzini , you are the one who implemented the socket watch on
> > > > > > > > > Windows. Could you please help analyze this issue?
> > > > > > > > >
> > > > > > > > > > to avoid WSAEnumNetworkEvents for the master GSource which only has
> > > > > > > > > > G_IO_HUP (or for any GSource having only that).
> > > > > > > > > > As I said above, the current code doesn't do anything with it anyway.
> > > > > > > > > > So, IMO, it's safe to do so.
> > > > > > > > > >
> > > > > > > > > > I'll send you my patch attached. I was planning to send it in the following
> > > > > > > > > > weeks anyway. I was just waiting to be sure everything looks fine on our
> > > > > > > > > > CI. Feel free to test and modify it if needed.
> > > > > > > > >
> > > > > > > > > I tested your patch. Unfortunately there is still one test case
> > > > > > > > > (migration-test.exe) throwing up the "Broken pipe" message.
> > > > > > > >
> > > > > > > > I must say I didn't fully test it against qemu testsuite yet. Maybe there are
> > > > > > > > some refinements to be done. "Broken pipe" might be linked to the missing
> > > > > > > > G_IO_HUP support.
> > > > > > > >
> > > > > > > > > Can you test my patch instead to see if your gdb issue can be fixed?
> > > > > > > >
> > > > > > > > Yeah sure. I'll try to do it this afternoon.
> > > > > >
> > > > > > I can't explain how mad at me I am... I'm pretty sure your patch was the first
> > > > > > thing I've tried when I encountered this issue. But it wasn't working
> > > > > > or IIRC the
> > > > > > issue went away but that was because the polling was actually disabled (looping
> > > > > > indefinitely)...I'm suspecting that I already had changed the CreateEvent for
> > > > > > WSACreateEvent which forces you to handle the reset.
> > > > > > Finally, I end up struggling reworking the whole check function...
> > > > > > But yeah, your patch does work fine on my gdb issues too.
> > > > >
> > > > > Good to know this patch works for you too.
> > > > >
> > > > > > And I guess the events are reset when recv() is being called because of the
> > > > > > auto-reset feature set up by CreateEvent().
> > > > > > IIUC, what Marc-André means by busy loop is the polling being looping
> > > > > > indefinitely as I encountered. I can ensure that this patch doesn't do that.
> > > > > > It can be easily checked by setting the env variable G_MAIN_POLL_DEBUG.
> > > > > > It'll show what g_poll is doing and it's normally always available on
> > > > > > Windows.
> > > > > >
> > > > > > Anyway, we'll wait for Paolo to see if he remembers why he had to call
> > > > > > WSAEnumNetworkEvents. Otherwize, let's go for your patch. Mine might
> > > > > > be a good start to improve the whole polling on Windows but if it doesn't
> > > > > > work in your case, it then needs some refinements.
> > > > > >
> > > > >
> > > > > Yeah, this issue bugged me quite a lot. If we want to reset the event
> > > > > in qio_channel_socket_source_check(), we will have to do the following
> > > > > to make sure qtests are happy.
> > > > >
> > > > > diff --git a/io/channel-watch.c b/io/channel-watch.c
> > > > > index 43d38494f7..f1e1650b81 100644
> > > > > --- a/io/channel-watch.c
> > > > > +++ b/io/channel-watch.c
> > > > > @@ -124,8 +124,6 @@ qio_channel_socket_source_check(GSource *source)
> > > > > return 0;
> > > > > }
> > > > > - WSAEnumNetworkEvents(ssource->socket, ssource->ioc->event, &ev);
> > > > > -
> > > > > FD_ZERO(&rfds);
> > > > > FD_ZERO(&wfds);
> > > > > FD_ZERO(&xfds);
> > > > > @@ -153,6 +151,10 @@ qio_channel_socket_source_check(GSource *source)
> > > > > ssource->revents |= G_IO_PRI;
> > > > > }
> > > > > + if (ssource->revents) {
> > > > > + WSAEnumNetworkEvents(ssource->socket, ssource->ioc->event, &ev);
> > > > > + }
> > > > > +
> > > > > return ssource->revents;
> > > > > }
> > > > >
> > > > > Removing "if (ssource->revents)" won't work.
> > > > >
> > > > > It seems to me that resetting the event twice (one time with the
> > > > > master Gsource, and the other time with the child GSource) causes some
> > > > > bizarre behavior. But MSDN [1] says
> > > > >
> > > > >     "Resetting an event that is already reset has no effect."
> > > > >
> > > > > [1] https://docs.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-resetevent
> > > > >
> > > >
> > > > Paolo, any comments about this issue?
> > > >
> > >
> > > v2 series has been sent out, and this patch remains unchanged.
> > >
> > > Paolo, still would appreciate your comments.
> > >
> >
> > Ping?
> >
>
> Ping? Can you please comment??
>

Ping?

Regards,
Bin


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

* Re: [PATCH 49/51] io/channel-watch: Fix socket watch on Windows
  2022-10-11 10:42                               ` Bin Meng
@ 2022-10-17 12:21                                 ` Bin Meng
  2022-10-17 12:30                                   ` Daniel P. Berrangé
  0 siblings, 1 reply; 174+ messages in thread
From: Bin Meng @ 2022-10-17 12:21 UTC (permalink / raw)
  To: Paolo Bonzini, Peter Maydell, Stefan Hajnoczi, Thomas Huth,
	Alex Bennée, Richard Henderson
  Cc: Marc-André Lureau, qemu-devel@nongnu.org Developers,
	Bin Meng, Daniel P. Berrangé,
	Clément Chigot

+more people

On Tue, Oct 11, 2022 at 6:42 PM Bin Meng <bmeng.cn@gmail.com> wrote:
>
> Hi Paolo,
>
> On Thu, Oct 6, 2022 at 11:03 AM Bin Meng <bmeng.cn@gmail.com> wrote:
> >
> > Hi Paolo,
> >
> > On Wed, Sep 28, 2022 at 2:10 PM Bin Meng <bmeng.cn@gmail.com> wrote:
> > >
> > > Hi Paolo,
> > >
> > > On Wed, Sep 21, 2022 at 9:02 AM Bin Meng <bmeng.cn@gmail.com> wrote:
> > > >
> > > > On Wed, Sep 14, 2022 at 4:08 PM Bin Meng <bmeng.cn@gmail.com> wrote:
> > > > >
> > > > > On Wed, Sep 7, 2022 at 1:07 PM Bin Meng <bmeng.cn@gmail.com> wrote:
> > > > > >
> > > > > > Hi Clément,
> > > > > >
> > > > > > On Tue, Sep 6, 2022 at 8:06 PM Clément Chigot <chigot@adacore.com> wrote:
> > > > > > >
> > > > > > > > > > I checked your patch, what you did seems to be something one would
> > > > > > > > > > naturally write, but what is currently in the QEMU sources seems to be
> > > > > > > > > > written intentionally.
> > > > > > > > > >
> > > > > > > > > > +Paolo Bonzini , you are the one who implemented the socket watch on
> > > > > > > > > > Windows. Could you please help analyze this issue?
> > > > > > > > > >
> > > > > > > > > > > to avoid WSAEnumNetworkEvents for the master GSource which only has
> > > > > > > > > > > G_IO_HUP (or for any GSource having only that).
> > > > > > > > > > > As I said above, the current code doesn't do anything with it anyway.
> > > > > > > > > > > So, IMO, it's safe to do so.
> > > > > > > > > > >
> > > > > > > > > > > I'll send you my patch attached. I was planning to send it in the following
> > > > > > > > > > > weeks anyway. I was just waiting to be sure everything looks fine on our
> > > > > > > > > > > CI. Feel free to test and modify it if needed.
> > > > > > > > > >
> > > > > > > > > > I tested your patch. Unfortunately there is still one test case
> > > > > > > > > > (migration-test.exe) throwing up the "Broken pipe" message.
> > > > > > > > >
> > > > > > > > > I must say I didn't fully test it against qemu testsuite yet. Maybe there are
> > > > > > > > > some refinements to be done. "Broken pipe" might be linked to the missing
> > > > > > > > > G_IO_HUP support.
> > > > > > > > >
> > > > > > > > > > Can you test my patch instead to see if your gdb issue can be fixed?
> > > > > > > > >
> > > > > > > > > Yeah sure. I'll try to do it this afternoon.
> > > > > > >
> > > > > > > I can't explain how mad at me I am... I'm pretty sure your patch was the first
> > > > > > > thing I've tried when I encountered this issue. But it wasn't working
> > > > > > > or IIRC the
> > > > > > > issue went away but that was because the polling was actually disabled (looping
> > > > > > > indefinitely)...I'm suspecting that I already had changed the CreateEvent for
> > > > > > > WSACreateEvent which forces you to handle the reset.
> > > > > > > Finally, I end up struggling reworking the whole check function...
> > > > > > > But yeah, your patch does work fine on my gdb issues too.
> > > > > >
> > > > > > Good to know this patch works for you too.
> > > > > >
> > > > > > > And I guess the events are reset when recv() is being called because of the
> > > > > > > auto-reset feature set up by CreateEvent().
> > > > > > > IIUC, what Marc-André means by busy loop is the polling being looping
> > > > > > > indefinitely as I encountered. I can ensure that this patch doesn't do that.
> > > > > > > It can be easily checked by setting the env variable G_MAIN_POLL_DEBUG.
> > > > > > > It'll show what g_poll is doing and it's normally always available on
> > > > > > > Windows.
> > > > > > >
> > > > > > > Anyway, we'll wait for Paolo to see if he remembers why he had to call
> > > > > > > WSAEnumNetworkEvents. Otherwize, let's go for your patch. Mine might
> > > > > > > be a good start to improve the whole polling on Windows but if it doesn't
> > > > > > > work in your case, it then needs some refinements.
> > > > > > >
> > > > > >
> > > > > > Yeah, this issue bugged me quite a lot. If we want to reset the event
> > > > > > in qio_channel_socket_source_check(), we will have to do the following
> > > > > > to make sure qtests are happy.
> > > > > >
> > > > > > diff --git a/io/channel-watch.c b/io/channel-watch.c
> > > > > > index 43d38494f7..f1e1650b81 100644
> > > > > > --- a/io/channel-watch.c
> > > > > > +++ b/io/channel-watch.c
> > > > > > @@ -124,8 +124,6 @@ qio_channel_socket_source_check(GSource *source)
> > > > > > return 0;
> > > > > > }
> > > > > > - WSAEnumNetworkEvents(ssource->socket, ssource->ioc->event, &ev);
> > > > > > -
> > > > > > FD_ZERO(&rfds);
> > > > > > FD_ZERO(&wfds);
> > > > > > FD_ZERO(&xfds);
> > > > > > @@ -153,6 +151,10 @@ qio_channel_socket_source_check(GSource *source)
> > > > > > ssource->revents |= G_IO_PRI;
> > > > > > }
> > > > > > + if (ssource->revents) {
> > > > > > + WSAEnumNetworkEvents(ssource->socket, ssource->ioc->event, &ev);
> > > > > > + }
> > > > > > +
> > > > > > return ssource->revents;
> > > > > > }
> > > > > >
> > > > > > Removing "if (ssource->revents)" won't work.
> > > > > >
> > > > > > It seems to me that resetting the event twice (one time with the
> > > > > > master Gsource, and the other time with the child GSource) causes some
> > > > > > bizarre behavior. But MSDN [1] says
> > > > > >
> > > > > >     "Resetting an event that is already reset has no effect."
> > > > > >
> > > > > > [1] https://docs.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-resetevent
> > > > > >
> > > > >
> > > > > Paolo, any comments about this issue?
> > > > >
> > > >
> > > > v2 series has been sent out, and this patch remains unchanged.
> > > >
> > > > Paolo, still would appreciate your comments.
> > > >
> > >
> > > Ping?
> > >
> >
> > Ping? Can you please comment??
> >
>
> Ping?
>

Hi,

Paolo remains silent. Please let me know who else could approve this
change. Thanks.

Regards,
Bin


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

* Re: [PATCH 49/51] io/channel-watch: Fix socket watch on Windows
  2022-10-17 12:21                                 ` Bin Meng
@ 2022-10-17 12:30                                   ` Daniel P. Berrangé
  2022-10-17 13:03                                     ` Bin Meng
  0 siblings, 1 reply; 174+ messages in thread
From: Daniel P. Berrangé @ 2022-10-17 12:30 UTC (permalink / raw)
  To: Bin Meng
  Cc: Paolo Bonzini, Peter Maydell, Stefan Hajnoczi, Thomas Huth,
	Alex Bennée, Richard Henderson, Marc-André Lureau,
	qemu-devel@nongnu.org Developers, Bin Meng, Clément Chigot

On Mon, Oct 17, 2022 at 08:21:37PM +0800, Bin Meng wrote:
> +more people
> 
> On Tue, Oct 11, 2022 at 6:42 PM Bin Meng <bmeng.cn@gmail.com> wrote:
> >
> > Hi Paolo,
> >
> > On Thu, Oct 6, 2022 at 11:03 AM Bin Meng <bmeng.cn@gmail.com> wrote:
> > >
> > > Hi Paolo,
> > >
> > > On Wed, Sep 28, 2022 at 2:10 PM Bin Meng <bmeng.cn@gmail.com> wrote:
> > > >
> > > > Hi Paolo,
> > > >
> > > > On Wed, Sep 21, 2022 at 9:02 AM Bin Meng <bmeng.cn@gmail.com> wrote:
> > > > >
> > > > > On Wed, Sep 14, 2022 at 4:08 PM Bin Meng <bmeng.cn@gmail.com> wrote:
> > > > > >
> > > > > > On Wed, Sep 7, 2022 at 1:07 PM Bin Meng <bmeng.cn@gmail.com> wrote:
> > > > > > > It seems to me that resetting the event twice (one time with the
> > > > > > > master Gsource, and the other time with the child GSource) causes some
> > > > > > > bizarre behavior. But MSDN [1] says
> > > > > > >
> > > > > > >     "Resetting an event that is already reset has no effect."
> > > > > > >
> > > > > > > [1] https://docs.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-resetevent
> > > > > > >
> > > > > >
> > > > > > Paolo, any comments about this issue?
> > > > >
> > > > > v2 series has been sent out, and this patch remains unchanged.
> > > > >
> > > > > Paolo, still would appreciate your comments.
> > > >
> > > > Ping?
> > >
> > > Ping? Can you please comment??
> >
> > Ping?
> 
> Paolo remains silent. Please let me know who else could approve this
> change. Thanks.

Given there has been plenty of time for objecting, I'll queue this
patch on the basis that you've tested it on a real Windows host
and found it better than what we have today.

With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|



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

* Re: [PATCH 48/51] io/channel-watch: Drop a superfluous '#ifdef WIN32'
  2022-08-24  9:40 ` [PATCH 48/51] io/channel-watch: Drop a superfluous '#ifdef WIN32' Bin Meng
  2022-09-01 12:24   ` Marc-André Lureau
@ 2022-10-17 12:34   ` Daniel P. Berrangé
  1 sibling, 0 replies; 174+ messages in thread
From: Daniel P. Berrangé @ 2022-10-17 12:34 UTC (permalink / raw)
  To: Bin Meng; +Cc: qemu-devel, Bin Meng

On Wed, Aug 24, 2022 at 05:40:26PM +0800, Bin Meng wrote:
> From: Bin Meng <bin.meng@windriver.com>
> 
> In the win32 version qio_channel_create_socket_watch() body there is
> no need to do a '#ifdef WIN32'.
> 
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
> 
>  io/channel-watch.c | 2 --
>  1 file changed, 2 deletions(-)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>

and queued

With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|



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

* Re: [PATCH 49/51] io/channel-watch: Fix socket watch on Windows
  2022-08-24  9:40 ` [PATCH 49/51] io/channel-watch: Fix socket watch on Windows Bin Meng
  2022-09-01 12:58   ` Marc-André Lureau
@ 2022-10-17 12:35   ` Daniel P. Berrangé
  1 sibling, 0 replies; 174+ messages in thread
From: Daniel P. Berrangé @ 2022-10-17 12:35 UTC (permalink / raw)
  To: Bin Meng; +Cc: qemu-devel, Bin Meng

On Wed, Aug 24, 2022 at 05:40:27PM +0800, Bin Meng wrote:
> From: Bin Meng <bin.meng@windriver.com>
> 
> Random failure was observed when running qtests on Windows due to
> "Broken pipe" detected by qmp_fd_receive(). What happened is that
> the qtest executable sends testing data over a socket to the QEMU
> under test but no response is received. The errno of the recv()
> call from the qtest executable indicates ETIMEOUT, due to the qmp
> chardev's tcp_chr_read() is never called to receive testing data
> hence no response is sent to the other side.
> 
> tcp_chr_read() is registered as the callback of the socket watch
> GSource. The reason of the callback not being called by glib, is
> that the source check fails to indicate the source is ready. There
> are two socket watch sources created to monitor the same socket
> event object from the char-socket backend in update_ioc_handlers().
> During the source check phase, qio_channel_socket_source_check()
> calls WSAEnumNetworkEvents() to discovers occurrences of network
> events for the indicated socket, clear internal network event records,
> and reset the event object. Testing shows that if we don't reset the
> event object by not passing the event handle to WSAEnumNetworkEvents()
> the symptom goes away and qtest runs very stably.
> 
> It looks we don't need to call WSAEnumNetworkEvents() at all, as we
> don't parse the result of WSANETWORKEVENTS returned from this API.
> We use select() to poll the socket status. Fix this instability by
> dropping the WSAEnumNetworkEvents() call.
> 
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
> During the testing, I removed the following codes in update_ioc_handlers():
> 
>     remove_hup_source(s);
>     s->hup_source = qio_channel_create_watch(s->ioc, G_IO_HUP);
>     g_source_set_callback(s->hup_source, (GSourceFunc)tcp_chr_hup,
>                           chr, NULL);
>     g_source_attach(s->hup_source, chr->gcontext);
> 
> and such change also makes the symptom go away.
> 
> And if I moved the above codes to the beginning, before the call to
> io_add_watch_poll(), the symptom also goes away.
> 
> It seems two sources watching on the same socket event object is
> the key that leads to the instability. The order of adding a source
> watch seems to also play a role but I can't explain why.
> Hopefully a Windows and glib expert could explain this behavior.
> 
>  io/channel-watch.c | 4 ----
>  1 file changed, 4 deletions(-)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>

and queued


With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|



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

* Re: [PATCH 49/51] io/channel-watch: Fix socket watch on Windows
  2022-10-17 12:30                                   ` Daniel P. Berrangé
@ 2022-10-17 13:03                                     ` Bin Meng
  2022-10-17 13:29                                       ` Daniel P. Berrangé
  0 siblings, 1 reply; 174+ messages in thread
From: Bin Meng @ 2022-10-17 13:03 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: Paolo Bonzini, Peter Maydell, Stefan Hajnoczi, Thomas Huth,
	Alex Bennée, Richard Henderson, Marc-André Lureau,
	qemu-devel@nongnu.org Developers, Bin Meng, Clément Chigot

On Mon, Oct 17, 2022 at 8:30 PM Daniel P. Berrangé <berrange@redhat.com> wrote:
>
> On Mon, Oct 17, 2022 at 08:21:37PM +0800, Bin Meng wrote:
> > +more people
> >
> > On Tue, Oct 11, 2022 at 6:42 PM Bin Meng <bmeng.cn@gmail.com> wrote:
> > >
> > > Hi Paolo,
> > >
> > > On Thu, Oct 6, 2022 at 11:03 AM Bin Meng <bmeng.cn@gmail.com> wrote:
> > > >
> > > > Hi Paolo,
> > > >
> > > > On Wed, Sep 28, 2022 at 2:10 PM Bin Meng <bmeng.cn@gmail.com> wrote:
> > > > >
> > > > > Hi Paolo,
> > > > >
> > > > > On Wed, Sep 21, 2022 at 9:02 AM Bin Meng <bmeng.cn@gmail.com> wrote:
> > > > > >
> > > > > > On Wed, Sep 14, 2022 at 4:08 PM Bin Meng <bmeng.cn@gmail.com> wrote:
> > > > > > >
> > > > > > > On Wed, Sep 7, 2022 at 1:07 PM Bin Meng <bmeng.cn@gmail.com> wrote:
> > > > > > > > It seems to me that resetting the event twice (one time with the
> > > > > > > > master Gsource, and the other time with the child GSource) causes some
> > > > > > > > bizarre behavior. But MSDN [1] says
> > > > > > > >
> > > > > > > >     "Resetting an event that is already reset has no effect."
> > > > > > > >
> > > > > > > > [1] https://docs.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-resetevent
> > > > > > > >
> > > > > > >
> > > > > > > Paolo, any comments about this issue?
> > > > > >
> > > > > > v2 series has been sent out, and this patch remains unchanged.
> > > > > >
> > > > > > Paolo, still would appreciate your comments.
> > > > >
> > > > > Ping?
> > > >
> > > > Ping? Can you please comment??
> > >
> > > Ping?
> >
> > Paolo remains silent. Please let me know who else could approve this
> > change. Thanks.
>
> Given there has been plenty of time for objecting, I'll queue this
> patch on the basis that you've tested it on a real Windows host
> and found it better than what we have today.
>

Thank you Daniel!

Please queue the following patches from v5 instead.

Message-ids:

20221006151927.2079583-15-bmeng.cn@gmail.com
20221006151927.2079583-16-bmeng.cn@gmail.com
20221006151927.2079583-17-bmeng.cn@gmail.com

Regards,
Bin


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

* Re: [PATCH 49/51] io/channel-watch: Fix socket watch on Windows
  2022-10-17 13:03                                     ` Bin Meng
@ 2022-10-17 13:29                                       ` Daniel P. Berrangé
  0 siblings, 0 replies; 174+ messages in thread
From: Daniel P. Berrangé @ 2022-10-17 13:29 UTC (permalink / raw)
  To: Bin Meng
  Cc: Paolo Bonzini, Peter Maydell, Stefan Hajnoczi, Thomas Huth,
	Alex Bennée, Richard Henderson, Marc-André Lureau,
	qemu-devel@nongnu.org Developers, Bin Meng, Clément Chigot

On Mon, Oct 17, 2022 at 09:03:15PM +0800, Bin Meng wrote:
> On Mon, Oct 17, 2022 at 8:30 PM Daniel P. Berrangé <berrange@redhat.com> wrote:
> >
> > On Mon, Oct 17, 2022 at 08:21:37PM +0800, Bin Meng wrote:
> > > +more people
> > >
> > > On Tue, Oct 11, 2022 at 6:42 PM Bin Meng <bmeng.cn@gmail.com> wrote:
> > > >
> > > > Hi Paolo,
> > > >
> > > > On Thu, Oct 6, 2022 at 11:03 AM Bin Meng <bmeng.cn@gmail.com> wrote:
> > > > >
> > > > > Hi Paolo,
> > > > >
> > > > > On Wed, Sep 28, 2022 at 2:10 PM Bin Meng <bmeng.cn@gmail.com> wrote:
> > > > > >
> > > > > > Hi Paolo,
> > > > > >
> > > > > > On Wed, Sep 21, 2022 at 9:02 AM Bin Meng <bmeng.cn@gmail.com> wrote:
> > > > > > >
> > > > > > > On Wed, Sep 14, 2022 at 4:08 PM Bin Meng <bmeng.cn@gmail.com> wrote:
> > > > > > > >
> > > > > > > > On Wed, Sep 7, 2022 at 1:07 PM Bin Meng <bmeng.cn@gmail.com> wrote:
> > > > > > > > > It seems to me that resetting the event twice (one time with the
> > > > > > > > > master Gsource, and the other time with the child GSource) causes some
> > > > > > > > > bizarre behavior. But MSDN [1] says
> > > > > > > > >
> > > > > > > > >     "Resetting an event that is already reset has no effect."
> > > > > > > > >
> > > > > > > > > [1] https://docs.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-resetevent
> > > > > > > > >
> > > > > > > >
> > > > > > > > Paolo, any comments about this issue?
> > > > > > >
> > > > > > > v2 series has been sent out, and this patch remains unchanged.
> > > > > > >
> > > > > > > Paolo, still would appreciate your comments.
> > > > > >
> > > > > > Ping?
> > > > >
> > > > > Ping? Can you please comment??
> > > >
> > > > Ping?
> > >
> > > Paolo remains silent. Please let me know who else could approve this
> > > change. Thanks.
> >
> > Given there has been plenty of time for objecting, I'll queue this
> > patch on the basis that you've tested it on a real Windows host
> > and found it better than what we have today.
> >
> 
> Thank you Daniel!
> 
> Please queue the following patches from v5 instead.
> 
> Message-ids:
> 
> 20221006151927.2079583-15-bmeng.cn@gmail.com
> 20221006151927.2079583-16-bmeng.cn@gmail.com
> 20221006151927.2079583-17-bmeng.cn@gmail.com

Ok, have done so.

With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|



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

end of thread, other threads:[~2022-10-17 13:38 UTC | newest]

Thread overview: 174+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-24  9:39 [PATCH 00/51] tests/qtest: Enable running qtest on Windows Bin Meng
2022-08-24  9:39 ` [PATCH 01/51] tests/qtest: Use g_setenv() Bin Meng
2022-08-24 11:45   ` Thomas Huth
2022-09-04 14:10   ` Philippe Mathieu-Daudé via
2022-08-24  9:39 ` [PATCH 02/51] tests/qtest: Use g_mkdtemp() Bin Meng
2022-08-24 14:42   ` Thomas Huth
2022-08-24  9:39 ` [PATCH 03/51] block: Unify the get_tmp_filename() implementation Bin Meng
2022-08-31 12:54   ` Marc-André Lureau
2022-08-31 13:19     ` Daniel P. Berrangé
2022-09-01  6:41     ` Bin Meng
2022-08-24  9:39 ` [PATCH 04/51] semihosting/arm-compat-semi: Avoid using hardcoded /tmp Bin Meng
2022-08-31 12:59   ` Marc-André Lureau
2022-09-01  7:11     ` Bin Meng
2022-09-01  9:20       ` Richard Henderson
2022-08-24  9:39 ` [PATCH 05/51] tcg: " Bin Meng
2022-08-31 13:02   ` Marc-André Lureau
2022-08-24  9:39 ` [PATCH 06/51] util/qemu-sockets: Use g_get_tmp_dir() to get the directory for temporary files Bin Meng
2022-08-31 13:05   ` Marc-André Lureau
2022-08-24  9:39 ` [PATCH 07/51] tests: Avoid using hardcoded /tmp in test cases Bin Meng
2022-08-24 17:51   ` Dr. David Alan Gilbert
2022-08-25  8:41   ` Thomas Huth
2022-08-24  9:39 ` [PATCH 08/51] block/vvfat: Unify the mkdir() call Bin Meng
2022-08-31 13:08   ` Marc-André Lureau
2022-08-24  9:39 ` [PATCH 09/51] fsdev/virtfs-proxy-helper: Use g_mkdir_with_parents() Bin Meng
2022-08-26 10:09   ` Christian Schoenebeck
2022-08-26 10:30     ` Bin Meng
2022-08-26 11:16       ` Christian Schoenebeck
2022-08-26 12:38         ` Bin Meng
2022-08-26 13:27           ` Christian Schoenebeck
2022-08-24  9:39 ` [PATCH 10/51] hw/usb: dev-mtp: " Bin Meng
2022-08-31 13:09   ` Marc-André Lureau
2022-08-24  9:39 ` [PATCH 11/51] qga/commands-posix-ssh: " Bin Meng
2022-08-24 14:41   ` Konstantin Kostiuk
2022-08-26 14:46     ` Bin Meng
2022-08-24  9:39 ` [PATCH 12/51] tests: " Bin Meng
2022-08-24 17:58   ` Dr. David Alan Gilbert
2022-08-26 14:49     ` Bin Meng
2022-08-24  9:39 ` [PATCH 13/51] tests/qtest: migration-test: Handle link() for win32 Bin Meng
2022-08-24 18:41   ` Dr. David Alan Gilbert
2022-08-24  9:39 ` [PATCH 14/51] backends/tpm: Exclude headers and macros that don't exist on win32 Bin Meng
2022-08-24 12:35   ` Stefan Berger
2022-08-31 13:20     ` Marc-André Lureau
2022-08-24  9:39 ` [PATCH 15/51] tests/qtest: Adapt {m48t59,rtc}-test cases for win32 Bin Meng
2022-08-25  8:20   ` Thomas Huth
2022-08-24  9:39 ` [PATCH 16/51] tests/qtest: Build e1000e-test for posix only Bin Meng
2022-08-25 10:59   ` Thomas Huth
2022-08-24  9:39 ` [PATCH 17/51] tests/qtest: Build virtio-net-test " Bin Meng
2022-08-25 11:27   ` Thomas Huth
2022-08-31 13:25   ` Marc-André Lureau
2022-08-24  9:39 ` [PATCH 18/51] tests/qtest: Build cases that use memory-backend-file " Bin Meng
2022-08-25 12:39   ` Thomas Huth
2022-08-24  9:39 ` [PATCH 19/51] tests/qtest: Build test-filter-{mirror, redirector} cases " Bin Meng
2022-08-25 11:37   ` Thomas Huth
2022-08-31 13:27   ` Marc-André Lureau
2022-08-24  9:39 ` [PATCH 20/51] tests/qtest: i440fx-test: Skip running request_{bios, pflash} for win32 Bin Meng
2022-08-25 11:40   ` [PATCH 20/51] tests/qtest: i440fx-test: Skip running request_{bios,pflash} " Thomas Huth
2022-08-31 13:40   ` [PATCH 20/51] tests/qtest: i440fx-test: Skip running request_{bios, pflash} " Marc-André Lureau
2022-09-02  8:29     ` Bin Meng
2022-08-24  9:39 ` [PATCH 21/51] tests/qtest: migration-test: Skip running test_migrate_fd_proto on win32 Bin Meng
2022-08-24 18:49   ` Dr. David Alan Gilbert
2022-09-04 14:15   ` Philippe Mathieu-Daudé via
2022-08-24  9:40 ` [PATCH 22/51] tests/qtest: qmp-test: Skip running test_qmp_oob for win32 Bin Meng
2022-08-25 11:45   ` Thomas Huth
2022-08-29 13:14   ` Markus Armbruster
2022-08-29 14:23     ` Bin Meng
2022-08-29 15:06       ` Markus Armbruster
2022-09-04 14:07         ` Philippe Mathieu-Daudé via
2022-08-24  9:40 ` [PATCH 23/51] accel/qtest: Support qtest accelerator for Windows Bin Meng
2022-08-31 13:49   ` Marc-André Lureau
2022-09-02  8:28     ` Bin Meng
2022-08-24  9:40 ` [PATCH 24/51] tests/qtest: libqos: Drop inclusion of <sys/wait.h> Bin Meng
2022-08-25 11:55   ` Thomas Huth
2022-08-31 13:50   ` Marc-André Lureau
2022-08-24  9:40 ` [PATCH 25/51] tests/qtest: libqos: Rename malloc.h to libqos-malloc.h Bin Meng
2022-08-25 11:51   ` Thomas Huth
2022-08-31 13:51   ` Marc-André Lureau
2022-08-24  9:40 ` [PATCH 26/51] tests/qtest: libqtest: Move global_qtest definition back to libqtest.c Bin Meng
2022-08-25 11:59   ` Thomas Huth
2022-08-24  9:40 ` [PATCH 27/51] tests/qtest: Use send/recv for socket communication Bin Meng
2022-08-25 13:04   ` Thomas Huth
2022-08-26 14:59     ` Bin Meng
2022-08-26 18:26       ` Thomas Huth
2022-08-31 14:05         ` Marc-André Lureau
2022-08-31 14:19           ` Daniel P. Berrangé
2022-09-02 14:24           ` Bin Meng
2022-08-24  9:40 ` [PATCH 28/51] tests/qtest: libqtest: Exclude the *_fds APIs for win32 Bin Meng
2022-08-31 14:10   ` Marc-André Lureau
2022-08-24  9:40 ` [PATCH 29/51] tests/qtest: libqtest: Install signal handler via signal() Bin Meng
2022-08-31 14:16   ` Marc-André Lureau
2022-09-02 15:49     ` Bin Meng
2022-08-24  9:40 ` [PATCH 30/51] tests: Skip iotests and qtest when '--without-default-devices' Bin Meng
2022-08-25 12:03   ` Thomas Huth
2022-09-02 15:18     ` Bin Meng
2022-08-24  9:40 ` [PATCH 31/51] tests/qtest: Support libqtest to build and run on Windows Bin Meng
2022-08-31 16:28   ` Marc-André Lureau
2022-09-19 10:00     ` Bin Meng
2022-09-01 11:38   ` Marc-André Lureau
2022-08-24  9:40 ` [PATCH 32/51] tests/qtest: Fix ERROR_SHARING_VIOLATION for win32 Bin Meng
2022-08-25 12:06   ` Thomas Huth
2022-09-02 10:59     ` Bin Meng
2022-09-01  8:42   ` Marc-André Lureau
2022-09-02 11:02     ` Bin Meng
2022-08-24  9:40 ` [PATCH 33/51] tests/qtest: {ahci, ide}-test: Use relative path for temporary files Bin Meng
2022-09-01  8:58   ` Marc-André Lureau
2022-09-03 13:30     ` Bin Meng
2022-08-24  9:40 ` [PATCH 34/51] tests/qtest: bios-tables-test: Adapt the case for win32 Bin Meng
2022-08-24 12:42   ` Ani Sinha
2022-08-26 10:38     ` Bin Meng
2022-09-01  9:05   ` Marc-André Lureau
2022-08-24  9:40 ` [PATCH 35/51] tests/qtest: device-plug-test: Reverse the usage of double/single quotes Bin Meng
2022-08-25 12:20   ` Thomas Huth
2022-08-24  9:40 ` [PATCH 36/51] tests/qtest: machine-none-test: Use double quotes to pass the cpu option Bin Meng
2022-08-25 12:22   ` Thomas Huth
2022-08-24  9:40 ` [PATCH 37/51] tests/qtest: migration-test: Disable IO redirection for win32 Bin Meng
2022-08-24 18:53   ` Dr. David Alan Gilbert
2022-08-26 10:48     ` Bin Meng
2022-08-24  9:40 ` [PATCH 38/51] tests/qtest: {ahci,ide}-test: Open file in binary mode Bin Meng
2022-08-25 12:28   ` Thomas Huth
2022-09-01  9:08   ` [PATCH 38/51] tests/qtest: {ahci, ide}-test: " Marc-André Lureau
2022-08-24  9:40 ` [PATCH 39/51] tests/qtest: virtio-net-failover: Disable migration tests for win32 Bin Meng
2022-08-24  9:40 ` [PATCH 40/51] chardev/char-file: Add FILE_SHARE_WRITE when openning the file " Bin Meng
2022-08-25  7:58   ` Marc-André Lureau
2022-08-26 13:15     ` Bin Meng
2022-08-26 13:23       ` Marc-André Lureau
2022-08-27 23:19         ` Bin Meng
2022-08-30 12:30           ` Marc-André Lureau
2022-08-24  9:40 ` [PATCH 41/51] tests/qtest: migration-test: Kill "to" after migration is canceled Bin Meng
2022-08-24 18:56   ` Dr. David Alan Gilbert
2022-09-01 11:35     ` Marc-André Lureau
2022-09-02 16:33       ` Bin Meng
2022-08-24  9:40 ` [PATCH 42/51] hw/ppc: spapr: Use qemu_vfree() to free spapr->htab Bin Meng
2022-08-24 17:32   ` Daniel Henrique Barboza
2022-09-01 11:40   ` Marc-André Lureau
2022-08-24  9:40 ` [PATCH 43/51] tests/qtest: npcm7xx_emc-test: Skip running test_{tx, rx} on win32 Bin Meng
2022-08-25 12:32   ` [PATCH 43/51] tests/qtest: npcm7xx_emc-test: Skip running test_{tx,rx} " Thomas Huth
2022-08-25 16:40   ` [PATCH 43/51] tests/qtest: npcm7xx_emc-test: Skip running test_{tx, rx} " Hao Wu
2022-08-24  9:40 ` [PATCH 44/51] tests/qtest: microbit-test: Fix socket access for win32 Bin Meng
2022-09-01 11:44   ` Marc-André Lureau
2022-08-24  9:40 ` [PATCH 45/51] tests/qtest: prom-env-test: Use double quotes to pass the prom-env option Bin Meng
2022-08-25 12:33   ` Thomas Huth
2022-08-24  9:40 ` [PATCH 46/51] tests/qtest: libqtest: Replace the call to close a socket with closesocket() Bin Meng
2022-09-01 11:46   ` Marc-André Lureau
2022-08-24  9:40 ` [PATCH 47/51] tests/qtest: libqtest: Correct the timeout unit of blocking receive calls for win32 Bin Meng
2022-09-01 11:57   ` Marc-André Lureau
2022-08-24  9:40 ` [PATCH 48/51] io/channel-watch: Drop a superfluous '#ifdef WIN32' Bin Meng
2022-09-01 12:24   ` Marc-André Lureau
2022-10-17 12:34   ` Daniel P. Berrangé
2022-08-24  9:40 ` [PATCH 49/51] io/channel-watch: Fix socket watch on Windows Bin Meng
2022-09-01 12:58   ` Marc-André Lureau
2022-09-04  6:24     ` Bin Meng
2022-09-05  6:04       ` Marc-André Lureau
2022-09-05  6:13         ` Bin Meng
2022-09-05  8:10           ` Clément Chigot
2022-09-06  7:00             ` Bin Meng
2022-09-06  7:41               ` Clément Chigot
2022-09-06  8:14                 ` Bin Meng
2022-09-06 12:06                   ` Clément Chigot
2022-09-07  5:07                     ` Bin Meng
2022-09-14  8:08                       ` Bin Meng
2022-09-21  1:02                         ` Bin Meng
2022-09-28  6:10                           ` Bin Meng
2022-10-06  3:03                             ` Bin Meng
2022-10-11 10:42                               ` Bin Meng
2022-10-17 12:21                                 ` Bin Meng
2022-10-17 12:30                                   ` Daniel P. Berrangé
2022-10-17 13:03                                     ` Bin Meng
2022-10-17 13:29                                       ` Daniel P. Berrangé
2022-10-17 12:35   ` Daniel P. Berrangé
2022-08-24  9:40 ` [PATCH 50/51] .gitlab-ci.d/windows.yml: Increase the timeout to the runner limit Bin Meng
2022-08-25  8:18   ` Thomas Huth
2022-08-26 11:25     ` Bin Meng
2022-08-26 11:33     ` Daniel P. Berrangé
2022-08-24  9:40 ` [PATCH 51/51] docs/devel: testing: Document writing portable test cases Bin Meng
2022-09-01 13:02   ` Marc-André Lureau

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.