Skip to contentSkip to conversation

tests/qtest: Enable running qtest on Windows

PATCH Superseded Bin Meng 16 participants 174 messages Aug 24, 2022 – Oct 17, 2022 Page 1 of 2

Subsystems (5)

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Bin Meng

author
#0 lore raw

cover tests/qtest: Enable running qtest on Windows

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: <[email protected]>

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%)
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH 1/51 tests/qtest: Use g_setenv()

From: Bin Meng <[email protected]>

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

---

 tests/qtest/fuzz/generic_fuzz.c | 8 ++++----
 tests/qtest/libqtest.c          | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)
tests/qtest/fuzz/generic_fuzz.c +4 -4
index 447ffe8178..afc1d20355 100644
@@ -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);
 }
 
tests/qtest/libqtest.c +1 -1
index 8c159eacf5..ad6860d774 100644
@@ -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;
Signature · 1 line
2.34.1
Reviewed-by Philippe Mathieu-Daudé on v1 1/51
#3 lore raw

Re: [PATCH 01/51] tests/qtest: Use g_setenv()

In reply to Bin Meng
Quoted 11 lines · Bin Meng

From: Bin Meng <[email protected]>

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

---

  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?

author
#4 lore raw

PATCH 2/51 tests/qtest: Use g_mkdtemp()

In reply to Bin Meng

From: Bin Meng <[email protected]>

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

---

 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(-)
tests/qtest/fuzz/generic_fuzz_configs.h +1 -1
index 004c701915..0775e6702b 100644
@@ -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 "
tests/qtest/cdrom-test.c +1 -1
index a7766a9e65..26a2400181 100644
@@ -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;
     }
tests/qtest/cxl-test.c +3 -3
index 2133e973f4..4e6d285061 100644
@@ -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,
tests/qtest/ivshmem-test.c +2 -2
index e23a97fa8e..9611d05eb5 100644
@@ -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);
tests/qtest/libqos/virtio-9p.c +2 -2
index 70aea8bf62..ae9b0a20e2 100644
@@ -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);
tests/qtest/libqtest.c +1 -1
index ad6860d774..7c9fc07de4 100644
@@ -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);
tests/qtest/migration-test.c +2 -2
index 520a5f917c..52988b86eb 100644
@@ -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);
 
tests/qtest/qmp-test.c +2 -2
index 9a42480cef..bf7304c7dc 100644
@@ -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)) {
tests/qtest/vhost-user-test.c +2 -2
index 8bf390be20..d7d6cfc9bd 100644
@@ -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);
 
tests/unit/test-qga.c +1 -1
index b27c77a695..a05a4628ed 100644
@@ -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();
Signature · 1 line
2.34.1
Reviewed-by on v1 2/51
#5 lore raw

Re: [PATCH 02/51] tests/qtest: Use g_mkdtemp()

Quoted 8 lines · Bin Meng

From: Bin Meng <[email protected]>

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

---

Quoted 11 lines
  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(-)
author
#6 lore raw

PATCH 3/51 block: Unify the get_tmp_filename() implementation

In reply to Bin Meng

From: Bin Meng <[email protected]>

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.

---

 block.c | 16 ++--------------
 1 file changed, 2 insertions(+), 14 deletions(-)
block.c +2 -14
index bc85f46eed..d06df47f72 100644
@@ -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
 }
 
 /*
Signature · 1 line
2.34.1
#7 lore raw

Re: [PATCH 03/51] block: Unify the get_tmp_filename() implementation

Hi Bin

Quoted 7 lines · Bin Meng

From: Bin Meng <[email protected]>

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

Quoted 48 lines

---

 block.c | 16 ++--------------
 1 file changed, 2 insertions(+), 14 deletions(-)
block.c +2 -13
index bc85f46eed..d06df47f72 100644
@@ -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;
     }
block.c +0 -2
@@ -891,7 +880,6 @@ int get_tmp_filename(char *filename, int size)
         return -errno;
     }
     return 0;
-#endif
 }
 
 /*
--

2.34.1

Signature · 1 line
Marc-André Lureau
#8 lore raw

Re: [PATCH 03/51] block: Unify the get_tmp_filename() implementation

Quoted 49 lines · Marc-André Lureau

Hi Bin

Quoted 7 lines · Bin Meng

From: Bin Meng <[email protected]>

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

Quoted 27 lines

---

 block.c | 16 ++--------------
 1 file changed, 2 insertions(+), 14 deletions(-)
block.c +0 -10
index bc85f46eed..d06df47f72 100644
@@ -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");
Quoted 8 lines
Quoted 8 lines
block.c +2 -3
-    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

Signature · 3 lines
|: 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 :|
author
#9 lore raw

Re: [PATCH 03/51] block: Unify the get_tmp_filename() implementation

In reply to Marc-André Lureau

Hi Marc-André,

Quoted 5 lines · Marc-André Lureau

Hi Bin

Quoted 1 line · Bin Meng
Quoted 8 lines
Quoted 6 lines

From: Bin Meng <[email protected]>

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.

Quoted 4 lines

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.

Quoted 2 lines

thanks

Regards,
Bin

author
#10 lore raw

PATCH 4/51 semihosting/arm-compat-semi: Avoid using hardcoded /tmp

In reply to Bin Meng

From: Bin Meng <[email protected]>

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

---

 semihosting/arm-compat-semi.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
semihosting/arm-compat-semi.c +2 -1
index e741674238..d5e66cc298 100644
@@ -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;
Signature · 1 line
2.34.1
#11 lore raw

Re: [PATCH 04/51] semihosting/arm-compat-semi: Avoid using hardcoded /tmp

Hi

Quoted 15 lines · Bin Meng

From: Bin Meng <[email protected]>

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

---

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

semihosting/arm-compat-semi.c void do_common_semihosting(CPUState *cs) · line 509

Quoted 8 lines
semihosting/arm-compat-semi.c +2 -1
@@ -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.

Quoted 8 lines
semihosting/arm-compat-semi.c +0 -0
         if (len < 0) {
             common_semi_set_ret(cs, -1);
             break;

--
2.34.1

Signature · 1 line
Marc-André Lureau
author
#12 lore raw

Re: [PATCH 04/51] semihosting/arm-compat-semi: Avoid using hardcoded /tmp

Quoted 15 lines · Marc-André Lureau

Hi

Quoted 11 lines · Bin Meng

From: Bin Meng <[email protected]>

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

---

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

semihosting/arm-compat-semi.c void do_common_semihosting(CPUState *cs) · line 507

Quoted 11 lines
semihosting/arm-compat-semi.c +2 -1
index e741674238..d5e66cc298 100644
@@ -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.

Quoted 6 lines

semihosting/arm-compat-semi.c void do_common_semihosting(CPUState *cs)

Quoted 6 lines
semihosting/arm-compat-semi.c +0 -1
         if (len < 0) {
             common_semi_set_ret(cs, -1);
             break;
--

Regards,
Bin

#13 lore raw

Re: [PATCH 04/51] semihosting/arm-compat-semi: Avoid using hardcoded /tmp

Quoted 8 lines · Bin Meng
Quoted 6 lines

semihosting/arm-compat-semi.c void do_common_semihosting(CPUState *cs) · line 507

Quoted 3 lines
semihosting/arm-compat-semi.c +2 -1
-        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~

author
#14 lore raw

PATCH 5/51 tcg: Avoid using hardcoded /tmp

In reply to Bin Meng

From: Bin Meng <[email protected]>

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

---

 tcg/tcg.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
tcg/tcg.c +3 -1
index 0f9cfe96f2..932156a352 100644
@@ -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
 
Signature · 1 line
2.34.1
Reviewed-by on v1 5/51
#15 lore raw

Re: [PATCH 05/51] tcg: Avoid using hardcoded /tmp

Hi

Quoted 15 lines · Bin Meng

From: Bin Meng <[email protected]>

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

---

 tcg/tcg.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
tcg/tcg.c +0 -0
index 0f9cfe96f2..932156a352 100644

tcg/tcg.c static void tcg_register_jit_int(const void · line 4735

Quoted 8 lines
tcg/tcg.c +2 -1
@@ -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.

Quoted 16 lines
tcg/tcg.c +1 -0
         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

Signature · 1 line
Marc-André Lureau
author
#16 lore raw

PATCH 6/51 util/qemu-sockets: Use g_get_tmp_dir() to get the directory for temporary files

In reply to Bin Meng

From: Bin Meng <[email protected]>

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

---

 util/qemu-sockets.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
util/qemu-sockets.c +2 -3
index 83f4bd6fd2..0c41ca9e42 100644
@@ -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);
Signature · 1 line
2.34.1
Reviewed-by on v1 6/51
#17 lore raw

Re: [PATCH 06/51] util/qemu-sockets: Use g_get_tmp_dir() to get the directory for temporary files

Hi

Quoted 7 lines · Bin Meng

From: Bin Meng <[email protected]>

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

Makes sense to me here,

Quoted 26 lines

---

 util/qemu-sockets.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
util/qemu-sockets.c +2 -4
index 83f4bd6fd2..0c41ca9e42 100644
@@ -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

Signature · 1 line
Marc-André Lureau
author
#18 lore raw

PATCH 7/51 tests: Avoid using hardcoded /tmp in test cases

In reply to Bin Meng

From: Bin Meng <[email protected]>

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

---

 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(-)
tests/qtest/fuzz/generic_fuzz_configs.h +4 -2
index 0775e6702b..d0f9961187 100644
@@ -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[] = {
tests/qtest/ahci-test.c +11 -4
index f1e510b0ac..f26cd6f86f 100644
@@ -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;
 }
tests/qtest/aspeed_smc-test.c +3 -1
index 05ce941566..cab769459c 100644
@@ -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;
 }
tests/qtest/boot-serial-test.c +6 -2
index 2f99d71cab..404adcfa20 100644
@@ -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);
 
tests/qtest/cxl-test.c +6 -3
index 4e6d285061..b3733cdb5f 100644
@@ -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();
tests/qtest/fdc-test.c +3 -1
index 52ade90a7d..8651100b05 100644
@@ -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;
 }
tests/qtest/fuzz/virtio_blk_fuzz.c +1 -1
index 236d078cc8..3e9541a38a 100644
@@ -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);
tests/qtest/hd-geo-test.c +4 -4
index 413cf964c0..dc5d8422ea 100644
@@ -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]);
         }
     }
 
tests/qtest/ide-test.c +6 -2
index 5bcb75a7e5..ebbf8e0126 100644
@@ -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;
 }
tests/qtest/libqtest.c +7 -3
index 7c9fc07de4..34744ace7c 100644
@@ -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);
 
tests/qtest/migration-test.c +3 -1
index 52988b86eb..5fa4ffeff0 100644
@@ -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;
 }
tests/qtest/pflash-cfi02-test.c +5 -2
index 7fce614b64..6de83717dd 100644
@@ -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);
tests/qtest/qmp-test.c +3 -1
index bf7304c7dc..b950dbafaf 100644
@@ -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)
tests/qtest/vhost-user-blk-test.c +2 -1
index a81c2a2715..07a4c2d500 100644
@@ -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);
tests/qtest/vhost-user-test.c +2 -1
index d7d6cfc9bd..a41168de25 100644
@@ -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);
tests/qtest/virtio-blk-test.c +1 -1
index dc5eed31c8..8920ce7c46 100644
@@ -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);
tests/qtest/virtio-scsi-test.c +2 -1
index 8ceb12aacd..33ab6ec685 100644
@@ -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)
tests/unit/test-image-locking.c +4 -2
index ba057bd66c..795c602ff6 100644
@@ -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)
tests/unit/test-qga.c +1 -1
index a05a4628ed..b73d231cd5 100644
@@ -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);
tests/vhost-user-bridge.c +2 -1
index 9b1dab2f28..0da6a6157f 100644
@@ -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()");
     }
Signature · 1 line
2.34.1
#19 lore raw

Re: [PATCH 07/51] tests: Avoid using hardcoded /tmp in test cases

Quoted 34 lines · * Bin Meng ([email protected]) wrote:

From: Bin Meng <[email protected]>

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

---

 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(-)
tests/qtest/fuzz/generic_fuzz_configs.h +0 -0
index 0775e6702b..d0f9961187 100644

tests/qtest/fuzz/generic_fuzz_configs.h typedef struct generic_fuzz_config { · line 23

Quoted 5 lines
tests/qtest/fuzz/generic_fuzz_configs.h +1 -1
@@ -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

Quoted 582 lines
tests/qtest/fuzz/generic_fuzz_configs.h +3 -1
     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[] = {
tests/qtest/ahci-test.c +11 -4
index f1e510b0ac..f26cd6f86f 100644
@@ -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;
 }
tests/qtest/aspeed_smc-test.c +3 -1
index 05ce941566..cab769459c 100644
@@ -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;
 }
tests/qtest/boot-serial-test.c +6 -2
index 2f99d71cab..404adcfa20 100644
@@ -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);
 
tests/qtest/cxl-test.c +6 -3
index 4e6d285061..b3733cdb5f 100644
@@ -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();
tests/qtest/fdc-test.c +3 -1
index 52ade90a7d..8651100b05 100644
@@ -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;
 }
tests/qtest/fuzz/virtio_blk_fuzz.c +1 -1
index 236d078cc8..3e9541a38a 100644
@@ -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);
tests/qtest/hd-geo-test.c +4 -4
index 413cf964c0..dc5d8422ea 100644
@@ -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]);
         }
     }
 
tests/qtest/ide-test.c +6 -2
index 5bcb75a7e5..ebbf8e0126 100644
@@ -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;
 }
tests/qtest/libqtest.c +7 -3
index 7c9fc07de4..34744ace7c 100644
@@ -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);
 
tests/qtest/migration-test.c +3 -1
index 52988b86eb..5fa4ffeff0 100644
@@ -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;
 }
tests/qtest/pflash-cfi02-test.c +5 -2
index 7fce614b64..6de83717dd 100644
@@ -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);
tests/qtest/qmp-test.c +3 -1
index bf7304c7dc..b950dbafaf 100644
@@ -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)
tests/qtest/vhost-user-blk-test.c +2 -1
index a81c2a2715..07a4c2d500 100644
@@ -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);
tests/qtest/vhost-user-test.c +2 -1
index d7d6cfc9bd..a41168de25 100644
@@ -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);
tests/qtest/virtio-blk-test.c +1 -1
index dc5eed31c8..8920ce7c46 100644
@@ -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);
tests/qtest/virtio-scsi-test.c +2 -1
index 8ceb12aacd..33ab6ec685 100644
@@ -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)
tests/unit/test-image-locking.c +4 -2
index ba057bd66c..795c602ff6 100644
@@ -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)
tests/unit/test-qga.c +1 -1
index a05a4628ed..b73d231cd5 100644
@@ -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);
tests/vhost-user-bridge.c +2 -1
index 9b1dab2f28..0da6a6157f 100644
@@ -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()");
     }
Signature · 1 line
2.34.1
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
#20 lore raw

Re: [PATCH 07/51] tests: Avoid using hardcoded /tmp in test cases

In reply to Bin Meng
Quoted 34 lines · Bin Meng

From: Bin Meng <[email protected]>

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

---

  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(-)
tests/qtest/fuzz/generic_fuzz_configs.h +0 -0
index 0775e6702b..d0f9961187 100644

tests/qtest/fuzz/generic_fuzz_configs.h typedef struct generic_fuzz_config { · line 24

Quoted 6 lines
tests/qtest/fuzz/generic_fuzz_configs.h +1 -1
@@ -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)

Quoted 28 lines
tests/qtest/fuzz/generic_fuzz_configs.h +3 -1
-    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[] = {
tests/qtest/ahci-test.c +3 -3
index f1e510b0ac..f26cd6f86f 100644
@@ -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;

tests/qtest/ahci-test.c static void test_ncq_simple(void) · line 1443

Quoted 8 lines
tests/qtest/ahci-test.c +1 -1
@@ -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)

tests/qtest/ahci-test.c int main(int argc, char **argv) · line 1878

Quoted 7 lines
tests/qtest/ahci-test.c +1 -0
@@ -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?

Quoted 14 lines
tests/qtest/aspeed_smc-test.c +1 -1
index 05ce941566..cab769459c 100644
@@ -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)
  {

tests/qtest/aspeed_smc-test.c int main(int argc, char **argv) · line 621

Quoted 5 lines
tests/qtest/aspeed_smc-test.c +1 -0
@@ -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() ?

Quoted 5 lines
tests/qtest/boot-serial-test.c +0 -0
index 2f99d71cab..404adcfa20 100644

tests/qtest/boot-serial-test.c static bool check_guest_output(QTestState *qts, const testdef_t *test, int fd) · line 230

Quoted 9 lines
tests/qtest/boot-serial-test.c +4 -2
@@ -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

author
#21 lore raw

PATCH 8/51 block/vvfat: Unify the mkdir() call

In reply to Bin Meng

From: Bin Meng <[email protected]>

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.

---

 block/vvfat.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
block/vvfat.c +2 -6
index d6dd919683..9c389ce5ea 100644
@@ -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);
Signature · 1 line
2.34.1
#22 lore raw

Re: [PATCH 08/51] block/vvfat: Unify the mkdir() call

Hi

Quoted 8 lines · Bin Meng

From: Bin Meng <[email protected]>

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

Quoted 33 lines

---

 block/vvfat.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
block/vvfat.c +2 -6
index d6dd919683..9c389ce5ea 100644
@@ -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

Signature · 1 line
Marc-André Lureau
author
#23 lore raw

PATCH 9/51 fsdev/virtfs-proxy-helper: Use g_mkdir_with_parents()

In reply to Bin Meng

From: Bin Meng <[email protected]>

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

---

 fsdev/virtfs-proxy-helper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fsdev/virtfs-proxy-helper.c +1 -1
index 2dde27922f..d0cf76d6d1 100644
@@ -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);
Signature · 1 line
2.34.1
#24 lore raw

Re: [PATCH 09/51] fsdev/virtfs-proxy-helper: Use g_mkdir_with_parents()

Quoted 4 lines · On Mittwoch, 24. August 2022 11:39:47 CEST Bin Meng wrote:

From: Bin Meng <[email protected]>

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.

Quoted 19 lines

---

 fsdev/virtfs-proxy-helper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fsdev/virtfs-proxy-helper.c +1 -1
index 2dde27922f..d0cf76d6d1 100644
@@ -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);
author
#25 lore raw

Re: [PATCH 09/51] fsdev/virtfs-proxy-helper: Use g_mkdir_with_parents()

Quoted 10 lines · Christian Schoenebeck
Quoted 4 lines · On Mittwoch, 24. August 2022 11:39:47 CEST Bin Meng wrote:

From: Bin Meng <[email protected]>

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

#26 lore raw

Re: [PATCH 09/51] fsdev/virtfs-proxy-helper: Use g_mkdir_with_parents()

Quoted 6 lines · On Freitag, 26. August 2022 12:30:20 CEST Bin Meng wrote:

On Fri, Aug 26, 2022 at 6:09 PM Christian Schoenebeck

Quoted 3 lines · <[email protected]> wrote:
Quoted 2 lines · On Mittwoch, 24. August 2022 11:39:47 CEST Bin Meng wrote:

From: Bin Meng <[email protected]>

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

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

Quoted 2 lines

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.

Quoted 2 lines

Regards,
Bin

author
#27 lore raw

Re: [PATCH 09/51] fsdev/virtfs-proxy-helper: Use g_mkdir_with_parents()

Quoted 17 lines · Christian Schoenebeck
Quoted 6 lines · On Freitag, 26. August 2022 12:30:20 CEST Bin Meng wrote:

On Fri, Aug 26, 2022 at 6:09 PM Christian Schoenebeck

Quoted 3 lines · <[email protected]> wrote:
Quoted 2 lines · On Mittwoch, 24. August 2022 11:39:47 CEST Bin Meng wrote:

From: Bin Meng <[email protected]>

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

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.

Quoted 9 lines

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

Quoted 2 lines

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

#28 lore raw

Re: [PATCH 09/51] fsdev/virtfs-proxy-helper: Use g_mkdir_with_parents()

Quoted 26 lines · On Freitag, 26. August 2022 14:38:27 CEST Bin Meng wrote:

On Fri, Aug 26, 2022 at 7:16 PM Christian Schoenebeck

Quoted 23 lines · <[email protected]> wrote:
Quoted 6 lines · On Freitag, 26. August 2022 12:30:20 CEST Bin Meng wrote:

On Fri, Aug 26, 2022 at 6:09 PM Christian Schoenebeck

Quoted 3 lines · <[email protected]> wrote:
Quoted 2 lines · On Mittwoch, 24. August 2022 11:39:47 CEST Bin Meng wrote:

From: Bin Meng <[email protected]>

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

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>

Quoted 2 lines

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

Quoted 7 lines
Quoted 1 line

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.

Quoted 2 lines

Regards,
Bin

author
#29 lore raw

PATCH 10/51 hw/usb: dev-mtp: Use g_mkdir_with_parents()

In reply to Bin Meng

From: Bin Meng <[email protected]>

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

---

 hw/usb/dev-mtp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/usb/dev-mtp.c +1 -1
index 5831395cef..97c894f231 100644
@@ -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,
Signature · 1 line
2.34.1
#30 lore raw

Re: [PATCH 10/51] hw/usb: dev-mtp: Use g_mkdir_with_parents()

Quoted 6 lines · Bin Meng

From: Bin Meng <[email protected]>

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().

Quoted 26 lines

---

 hw/usb/dev-mtp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/usb/dev-mtp.c +1 -1
index 5831395cef..97c894f231 100644
@@ -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

Signature · 1 line
Marc-André Lureau
author
#31 lore raw

PATCH 11/51 qga/commands-posix-ssh: Use g_mkdir_with_parents()

In reply to Bin Meng

From: Bin Meng <[email protected]>

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

---

 qga/commands-posix-ssh.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
qga/commands-posix-ssh.c +1 -1
index f3a580b8cc..2460112a38 100644
@@ -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;
Signature · 1 line
2.34.1
Reviewed-by on v1 11/51
#32 lore raw

Re: [PATCH 11/51] qga/commands-posix-ssh: Use g_mkdir_with_parents()

Quoted 28 lines · Bin Meng

From: Bin Meng <[email protected]>

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

---

 qga/commands-posix-ssh.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
qga/commands-posix-ssh.c +1 -2
index f3a580b8cc..2460112a38 100644
@@ -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

author
#33 lore raw

Re: [PATCH 11/51] qga/commands-posix-ssh: Use g_mkdir_with_parents()

Quoted 16 lines · Konstantin Kostiuk
Quoted 12 lines · Bin Meng

From: Bin Meng <[email protected]>

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

---

 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

author
#34 lore raw

PATCH 12/51 tests: Use g_mkdir_with_parents()

In reply to Bin Meng

From: Bin Meng <[email protected]>

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

---

 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(-)
tests/migration/stress.c +1 -1
index b7240a15c8..88acf8dc25 100644
@@ -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;
tests/qtest/migration-test.c +3 -3
index 5fa4ffeff0..38356d4aba 100644
@@ -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);
tests/unit/test-crypto-tlscredsx509.c +2 -2
index aab4149b56..3c25d75ca1 100644
@@ -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);
 
tests/unit/test-crypto-tlssession.c +3 -3
index f222959d36..615a1344b4 100644
@@ -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);
tests/unit/test-io-channel-tls.c +3 -3
index f6fb988c01..cc39247556 100644
@@ -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);
 
Signature · 1 line
2.34.1
Reviewed-by on v1 12/51
#35 lore raw

Re: [PATCH 12/51] tests: Use g_mkdir_with_parents()

Quoted 6 lines · * Bin Meng ([email protected]) wrote:

From: Bin Meng <[email protected]>

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

Quoted 125 lines

---

 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(-)
tests/migration/stress.c +1 -1
index b7240a15c8..88acf8dc25 100644
@@ -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;
tests/qtest/migration-test.c +3 -3
index 5fa4ffeff0..38356d4aba 100644
@@ -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);
tests/unit/test-crypto-tlscredsx509.c +2 -2
index aab4149b56..3c25d75ca1 100644
@@ -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);
 
tests/unit/test-crypto-tlssession.c +3 -3
index f222959d36..615a1344b4 100644
@@ -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);
tests/unit/test-io-channel-tls.c +3 -3
index f6fb988c01..cc39247556 100644
@@ -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);
 
Signature · 1 line
2.34.1
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
author
#36 lore raw

Re: [PATCH 12/51] tests: Use g_mkdir_with_parents()

Quoted 20 lines · Dr. David Alan Gilbert
Quoted 6 lines · * Bin Meng ([email protected]) wrote:

From: Bin Meng <[email protected]>

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

Quoted 9 lines

---

 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

author
#37 lore raw

PATCH 13/51 tests/qtest: migration-test: Handle link() for win32

In reply to Bin Meng

From: Bin Meng <[email protected]>

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.

---

 tests/qtest/migration-test.c | 8 ++++++++
 1 file changed, 8 insertions(+)
tests/qtest/migration-test.c +8 -0
index 38356d4aba..af9250750b 100644
@@ -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);
Signature · 1 line
2.34.1
Reviewed-by on v1 13/51
#38 lore raw

Re: [PATCH 13/51] tests/qtest: migration-test: Handle link() for win32

Quoted 7 lines · * Bin Meng ([email protected]) wrote:

From: Bin Meng <[email protected]>

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.

Quoted 30 lines

---

 tests/qtest/migration-test.c | 8 ++++++++
 1 file changed, 8 insertions(+)
tests/qtest/migration-test.c +8 -0
index 38356d4aba..af9250750b 100644
@@ -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);
Signature · 1 line
2.34.1
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
author
#39 lore raw

PATCH 14/51 backends/tpm: Exclude headers and macros that don't exist on win32

In reply to Bin Meng

From: Bin Meng <[email protected]>

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

---

 backends/tpm/tpm_ioctl.h | 4 ++++
 1 file changed, 4 insertions(+)
backends/tpm/tpm_ioctl.h +4 -0
index bd6c12cb86..d67bf0283b 100644
@@ -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
Signature · 1 line
2.34.1
Reviewed-by on v1 14/51
#40 lore raw

Re: [PATCH 14/51] backends/tpm: Exclude headers and macros that don't exist on win32

Quoted 34 lines · Bin Meng

From: Bin Meng <[email protected]>

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

---

  backends/tpm/tpm_ioctl.h | 4 ++++
  1 file changed, 4 insertions(+)
backends/tpm/tpm_ioctl.h +3 -0
index bd6c12cb86..d67bf0283b 100644
@@ -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),

backends/tpm/tpm_ioctl.h enum { · line 250

Quoted 7 lines
backends/tpm/tpm_ioctl.h +1 -0
@@ -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
#41 lore raw

Re: [PATCH 14/51] backends/tpm: Exclude headers and macros that don't exist on win32

Hi

Quoted 42 lines · Stefan Berger
Quoted 39 lines · Bin Meng

From: Bin Meng <[email protected]>

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

---

  backends/tpm/tpm_ioctl.h | 4 ++++
  1 file changed, 4 insertions(+)
backends/tpm/tpm_ioctl.h +4 -0
index bd6c12cb86..d67bf0283b 100644
@@ -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
 
Quoted 6 lines

backends/tpm/tpm_ioctl.h enum { · line 250

Quoted 2 lines
backends/tpm/tpm_ioctl.h +0 -0
  /*
   * Commands used by the non-CUSE TPMs

I guess it would be worthy to make libtpms/swtpm work under windows too, but this is a larger goal.

Signature · 1 line
Marc-André Lureau
author
#42 lore raw

PATCH 15/51 tests/qtest: Adapt {m48t59,rtc}-test cases for win32

In reply to Bin Meng

From: Bin Meng <[email protected]>

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

---

 tests/qtest/m48t59-test.c | 2 +-
 tests/qtest/rtc-test.c    | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
tests/qtest/m48t59-test.c +1 -1
index b94a1230f7..843d2ced8e 100644
@@ -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
 
tests/qtest/rtc-test.c +1 -1
index 8126ab1bdb..02ed4e1238 100644
@@ -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
 
Signature · 1 line
2.34.1
Reviewed-by on v1 15/51
#43 lore raw

Re: [PATCH 15/51] tests/qtest: Adapt {m48t59,rtc}-test cases for win32

Quoted 30 lines · Bin Meng

From: Bin Meng <[email protected]>

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

---

  tests/qtest/m48t59-test.c | 2 +-
  tests/qtest/rtc-test.c    | 2 +-
  2 files changed, 2 insertions(+), 2 deletions(-)
tests/qtest/m48t59-test.c +1 -1
index b94a1230f7..843d2ced8e 100644
@@ -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
 
tests/qtest/rtc-test.c +0 -0
index 8126ab1bdb..02ed4e1238 100644

tests/qtest/rtc-test.c static void cmos_get_date_time(struct tm *date) · line 117

Quoted 8 lines
tests/qtest/rtc-test.c +1 -1
@@ -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
 
author
#44 lore raw

PATCH 16/51 tests/qtest: Build e1000e-test for posix only

In reply to Bin Meng

From: Bin Meng <[email protected]>

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

---

 tests/qtest/meson.build | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
tests/qtest/meson.build +3 -1
index be4b30dea2..9d0f82bf1c 100644
@@ -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
Signature · 1 line
2.34.1
Reviewed-by on v1 16/51
#45 lore raw

Re: [PATCH 16/51] tests/qtest: Build e1000e-test for posix only

Quoted 24 lines · Bin Meng

From: Bin Meng <[email protected]>

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

---

  tests/qtest/meson.build | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
tests/qtest/meson.build +0 -1
index be4b30dea2..9d0f82bf1c 100644
@@ -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',

tests/qtest/meson.build qos_test_ss.add( · line 274

Quoted 9 lines
tests/qtest/meson.build +3 -0
@@ -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
author
#46 lore raw

PATCH 17/51 tests/qtest: Build virtio-net-test for posix only

In reply to Bin Meng

From: Bin Meng <[email protected]>

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

---

 tests/qtest/virtio-net-test.c | 6 ------
 tests/qtest/meson.build       | 3 +--
 2 files changed, 1 insertion(+), 8 deletions(-)
tests/qtest/virtio-net-test.c +0 -6
index 6ded252901..d44c3d9666 100644
@@ -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.  */
tests/qtest/meson.build +1 -2
index 9d0f82bf1c..72bb9e21f3 100644
@@ -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'))
Signature · 1 line
2.34.1
#47 lore raw

Re: [PATCH 17/51] tests/qtest: Build virtio-net-test for posix only

Quoted 4 lines · Bin Meng

From: Bin Meng <[email protected]>

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

Reviewed-by on v1 17/51
#48 lore raw

Re: [PATCH 17/51] tests/qtest: Build virtio-net-test for posix only

In reply to Bin Meng

Hi

Quoted 5 lines · Bin Meng

From: Bin Meng <[email protected]>

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.

Quoted 3 lines
Quoted 66 lines

---

 tests/qtest/virtio-net-test.c | 6 ------
 tests/qtest/meson.build       | 3 +--
 2 files changed, 1 insertion(+), 8 deletions(-)
tests/qtest/virtio-net-test.c +0 -4
index 6ded252901..d44c3d9666 100644
@@ -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;
tests/qtest/virtio-net-test.c +0 -2
@@ -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.  */
tests/qtest/meson.build +1 -3
index 9d0f82bf1c..72bb9e21f3 100644
@@ -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

Signature · 1 line
Marc-André Lureau
author
#49 lore raw

PATCH 18/51 tests/qtest: Build cases that use memory-backend-file for posix only

In reply to Bin Meng

From: Bin Meng <[email protected]>

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.

---

 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(-)
tests/qtest/bios-tables-test.c +10 -0
index 7c5f736b51..36783966b0 100644
@@ -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) {
tests/qtest/cxl-test.c +4 -0
index b3733cdb5f..4b4e7e5088 100644
@@ -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();
 }
tests/qtest/meson.build +2 -1
index 72bb9e21f3..9e484e60ba 100644
@@ -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                                      \
Signature · 1 line
2.34.1
Acked-by on v1 18/51
#50 lore raw

Re: [PATCH 18/51] tests/qtest: Build cases that use memory-backend-file for posix only

Quoted 6 lines · Bin Meng

From: Bin Meng <[email protected]>

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.

Quoted 7 lines

---

  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(-)
author
#51 lore raw

PATCH 19/51 tests/qtest: Build test-filter-{mirror, redirector} cases for posix only

In reply to Bin Meng

From: Bin Meng <[email protected]>

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

---

 tests/qtest/meson.build | 28 ++++++++++++++++++----------
 1 file changed, 18 insertions(+), 10 deletions(-)
tests/qtest/meson.build +18 -10
index 9e484e60ba..c97da5a062 100644
@@ -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 = \
Signature · 1 line
2.34.1
#52 lore raw

Re: [PATCH 19/51] tests/qtest: Build test-filter-{mirror, redirector} cases for posix only

Quoted 91 lines · Bin Meng

From: Bin Meng <[email protected]>

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

---

  tests/qtest/meson.build | 28 ++++++++++++++++++----------
  1 file changed, 18 insertions(+), 10 deletions(-)
tests/qtest/meson.build +16 -9
index 9e484e60ba..c97da5a062 100644
@@ -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'] : [])

tests/qtest/meson.build qtests_sh4 = (config_all_devices.has_key('CONFIG_ISA_TESTDEV') ? ['endianness-te · line 194

Quoted 10 lines
tests/qtest/meson.build +2 -1
 
  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

Reviewed-by on v1 19/51
#53 lore raw

Re: [PATCH 19/51] tests/qtest: Build test-filter-{mirror, redirector} cases for posix only

In reply to Bin Meng
Quoted 5 lines · Bin Meng

From: Bin Meng <[email protected]>

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.

Quoted 3 lines
Quoted 127 lines

---

 tests/qtest/meson.build | 28 ++++++++++++++++++----------
 1 file changed, 18 insertions(+), 10 deletions(-)
tests/qtest/meson.build +2 -0
index 9e484e60ba..c97da5a062 100644
@@ -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'] : [])
tests/qtest/meson.build +17 -7
+                  \
@@ -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'] : [])
tests/qtest/meson.build +3 -1
@@ -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'] : []) +
                   \
tests/qtest/meson.build +0 -0
@@ -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'] + \

tests/qtest/meson.build +3 -1
-  ['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'] : []) + \
tests/qtest/meson.build +3 -2
-  ['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

Signature · 1 line
Marc-André Lureau
author
#54 lore raw

PATCH 20/51 tests/qtest: i440fx-test: Skip running request_{bios, pflash} for win32

In reply to Bin Meng

From: Bin Meng <[email protected]>

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

---

 tests/qtest/i440fx-test.c | 6 ++++++
 1 file changed, 6 insertions(+)
tests/qtest/i440fx-test.c +6 -0
index 6d7d4d8d8f..3890f1237c 100644
@@ -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();
 }
Signature · 1 line
2.34.1
Reviewed-by on v1 20/51
#55 lore raw

Re: [PATCH 20/51] tests/qtest: i440fx-test: Skip running request_{bios,pflash} for win32

Quoted 34 lines · Bin Meng

From: Bin Meng <[email protected]>

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

---

  tests/qtest/i440fx-test.c | 6 ++++++
  1 file changed, 6 insertions(+)
tests/qtest/i440fx-test.c +4 -0
index 6d7d4d8d8f..3890f1237c 100644
@@ -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;

tests/qtest/i440fx-test.c int main(int argc, char **argv) · line 419

Quoted 10 lines
tests/qtest/i440fx-test.c +2 -0
@@ -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();
  }
#56 lore raw

Re: [PATCH 20/51] tests/qtest: i440fx-test: Skip running request_{bios, pflash} for win32

In reply to Bin Meng

Hi

Quoted 6 lines · Bin Meng

From: Bin Meng <[email protected]>

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;
}
Quoted 44 lines

---

 tests/qtest/i440fx-test.c | 6 ++++++
 1 file changed, 6 insertions(+)
tests/qtest/i440fx-test.c +4 -0
index 6d7d4d8d8f..3890f1237c 100644
@@ -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;
tests/qtest/i440fx-test.c +2 -1
@@ -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

Signature · 1 line
Marc-André Lureau
author
#57 lore raw

Re: [PATCH 20/51] tests/qtest: i440fx-test: Skip running request_{bios, pflash} for win32

Quoted 5 lines · Marc-André Lureau

Hi

Quoted 1 line · Bin Meng
Quoted 7 lines
Quoted 5 lines

From: Bin Meng <[email protected]>

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.

Quoted 14 lines

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;
Quoted 15 lines
    }

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

    return pathname;
}
Quoted 6 lines

---

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

Regards,
Bin

author
#58 lore raw

PATCH 21/51 tests/qtest: migration-test: Skip running test_migrate_fd_proto on win32

In reply to Bin Meng

From: Bin Meng <[email protected]>

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.

---

 tests/qtest/migration-helpers.h | 2 ++
 tests/qtest/migration-helpers.c | 2 ++
 tests/qtest/migration-test.c    | 4 ++++
 3 files changed, 8 insertions(+)
tests/qtest/migration-helpers.h +2 -0
index 59561898d0..db0684de48 100644
@@ -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, ...);
tests/qtest/migration-helpers.c +2 -0
index c6fbeb3974..f6f3c6680f 100644
@@ -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.
tests/qtest/migration-test.c +4 -0
index af9250750b..2ae7498d5d 100644
@@ -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",
Signature · 1 line
2.34.1
Reviewed-by on v1 21/51
#59 lore raw

Re: [PATCH 21/51] tests/qtest: migration-test: Skip running test_migrate_fd_proto on win32

Quoted 7 lines · * Bin Meng ([email protected]) wrote:

From: Bin Meng <[email protected]>

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.

Quoted 75 lines

---

 tests/qtest/migration-helpers.h | 2 ++
 tests/qtest/migration-helpers.c | 2 ++
 tests/qtest/migration-test.c    | 4 ++++
 3 files changed, 8 insertions(+)
tests/qtest/migration-helpers.h +2 -0
index 59561898d0..db0684de48 100644
@@ -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, ...);
tests/qtest/migration-helpers.c +2 -0
index c6fbeb3974..f6f3c6680f 100644
@@ -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.
tests/qtest/migration-test.c +4 -0
index af9250750b..2ae7498d5d 100644
@@ -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",
Signature · 1 line
2.34.1
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
#60 lore raw

Re: [PATCH 21/51] tests/qtest: migration-test: Skip running test_migrate_fd_proto on win32

In reply to Bin Meng
Quoted 5 lines · Bin Meng

From: Bin Meng <[email protected]>

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.

Quoted 8 lines

---

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

PATCH 22/51 tests/qtest: qmp-test: Skip running test_qmp_oob for win32

In reply to Bin Meng

From: Bin Meng <[email protected]>

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

---

 tests/qtest/qmp-test.c | 6 ++++++
 1 file changed, 6 insertions(+)
tests/qtest/qmp-test.c +6 -0
index b950dbafaf..4a165447f8 100644
@@ -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);
 
Signature · 1 line
2.34.1
#63 lore raw

Re: [PATCH 22/51] tests/qtest: qmp-test: Skip running test_qmp_oob for win32

In reply to Bin Meng
Quoted 34 lines · Bin Meng

From: Bin Meng <[email protected]>

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

---

 tests/qtest/qmp-test.c | 6 ++++++
 1 file changed, 6 insertions(+)
tests/qtest/qmp-test.c +4 -0
index b950dbafaf..4a165447f8 100644
@@ -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)

tests/qtest/qmp-test.c int main(int argc, char *argv[]) · line 349

Quoted 8 lines
tests/qtest/qmp-test.c +2 -0
@@ -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.

author
#64 lore raw

Re: [PATCH 22/51] tests/qtest: qmp-test: Skip running test_qmp_oob for win32

Hi Markus,

Quoted 39 lines · Markus Armbruster
Quoted 36 lines · Bin Meng

From: Bin Meng <[email protected]>

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

---

 tests/qtest/qmp-test.c | 6 ++++++
 1 file changed, 6 insertions(+)
tests/qtest/qmp-test.c +4 -0
index b950dbafaf..4a165447f8 100644
@@ -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);
 
Quoted 9 lines

tests/qtest/qmp-test.c int main(int argc, char *argv[]) · line 349

Quoted 6 lines
tests/qtest/qmp-test.c +2 -0
     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

#65 lore raw

Re: [PATCH 22/51] tests/qtest: qmp-test: Skip running test_qmp_oob for win32

Quoted 52 lines · Bin Meng

Hi Markus,

Quoted 39 lines · Markus Armbruster
Quoted 36 lines · Bin Meng

From: Bin Meng <[email protected]>

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

---

 tests/qtest/qmp-test.c | 6 ++++++
 1 file changed, 6 insertions(+)
tests/qtest/qmp-test.c +4 -0
index b950dbafaf..4a165447f8 100644
@@ -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);
 
Quoted 9 lines

tests/qtest/qmp-test.c int main(int argc, char *argv[]) · line 349

Quoted 6 lines
tests/qtest/qmp-test.c +2 -0
     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.

Quoted 1 line

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.

#66 lore raw

Re: [PATCH 22/51] tests/qtest: qmp-test: Skip running test_qmp_oob for win32

Quoted 54 lines · Markus Armbruster
Quoted 52 lines · Bin Meng

Hi Markus,

Quoted 48 lines · Markus Armbruster
Quoted 34 lines · Bin Meng

From: Bin Meng <[email protected]>

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

---

  tests/qtest/qmp-test.c | 6 ++++++
  1 file changed, 6 insertions(+)
tests/qtest/qmp-test.c +4 -0
index b950dbafaf..4a165447f8 100644
@@ -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)

tests/qtest/qmp-test.c int main(int argc, char *argv[]) · line 349

Quoted 8 lines
tests/qtest/qmp-test.c +2 -0
@@ -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.

Quoted 5 lines
Quoted 1 line

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
author
#67 lore raw

PATCH 23/51 accel/qtest: Support qtest accelerator for Windows

In reply to Bin Meng

From: Xuzhou Cheng <[email protected]>

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.

---

 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(-)
include/hw/core/cpu.h +1 -0
index 500503da13..c564108877 100644
@@ -325,6 +325,7 @@ struct CPUState {
     struct QemuThread *thread;
 #ifdef _WIN32
     HANDLE hThread;
+    QemuSemaphore sem;
 #endif
     int thread_id;
     bool running, has_waiter;
accel/dummy-cpus.c +12 -2
index 10429fdfb2..d6a1b8d0a2 100644
@@ -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
 }
softmmu/cpus.c +5 -4
index 23b30484b2..fd10db927a 100644
@@ -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
 }
 
accel/meson.build +1 -0
index b9a963cf80..b21c85dc0a 100644
@@ -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)
accel/qtest/meson.build +1 -0
index 4c65600293..a4876fc0f2 100644
@@ -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'))
Signature · 1 line
2.34.1
Reviewed-by on v1 23/51
#68 lore raw

Re: [PATCH 23/51] accel/qtest: Support qtest accelerator for Windows

Hi

Quoted 10 lines · Bin Meng

From: Xuzhou Cheng <[email protected]>

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.

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

but lgtm,

Quoted 126 lines

---

 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(-)
include/hw/core/cpu.h +1 -0
index 500503da13..c564108877 100644
@@ -325,6 +325,7 @@ struct CPUState {
     struct QemuThread *thread;
 #ifdef _WIN32
     HANDLE hThread;
+    QemuSemaphore sem;
 #endif
     int thread_id;
     bool running, has_waiter;
accel/dummy-cpus.c +12 -2
index 10429fdfb2..d6a1b8d0a2 100644
@@ -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
 }
softmmu/cpus.c +5 -4
index 23b30484b2..fd10db927a 100644
@@ -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
 }
 
accel/meson.build +1 -0
index b9a963cf80..b21c85dc0a 100644
@@ -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)

accel/qtest/meson.build +1 -1
index 4c65600293..a4876fc0f2 100644
@@ -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

Signature · 1 line
Marc-André Lureau
author
#69 lore raw

Re: [PATCH 23/51] accel/qtest: Support qtest accelerator for Windows

Quoted 12 lines · Marc-André Lureau

Hi

Quoted 8 lines · Bin Meng

From: Xuzhou Cheng <[email protected]>

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.

Quoted 5 lines
Quoted 2 lines

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.

Quoted 14 lines

but lgtm,

Quoted 10 lines

---

 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

author
#70 lore raw

PATCH 24/51 tests/qtest: libqos: Drop inclusion of <sys/wait.h>

In reply to Bin Meng

From: Xuzhou Cheng <[email protected]>

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

---

 tests/qtest/libqos/libqos.c | 2 --
 1 file changed, 2 deletions(-)
tests/qtest/libqos/libqos.c +0 -2
index 85c7641add..5ffda080ec 100644
@@ -1,6 +1,4 @@
 #include "qemu/osdep.h"
-#include <sys/wait.h>
-
 #include "../libqtest.h"
 #include "libqos.h"
 #include "pci.h"
Signature · 1 line
2.34.1
Tested-by on v1 24/51
#71 lore raw

Re: [PATCH 24/51] tests/qtest: libqos: Drop inclusion of <sys/wait.h>

Quoted 17 lines · Bin Meng

From: Xuzhou Cheng <[email protected]>

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

---

  tests/qtest/libqos/libqos.c | 2 --
  1 file changed, 2 deletions(-)
tests/qtest/libqos/libqos.c +0 -0
index 85c7641add..5ffda080ec 100644

tests/qtest/libqos/libqos.c line 2

Quoted 2 lines
tests/qtest/libqos/libqos.c +0 -1
@@ -1,6 +1,4 @@
  #include "qemu/osdep.h"
-#include <sys/wait.h>

Works for me:

Reviewed-by on v1 24/51
#72 lore raw

Re: [PATCH 24/51] tests/qtest: libqos: Drop inclusion of <sys/wait.h>

In reply to Bin Meng
Quoted 8 lines · Bin Meng

From: Xuzhou Cheng <[email protected]>

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

Quoted 21 lines

---

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

2.34.1

Signature · 1 line
Marc-André Lureau
author
#73 lore raw

PATCH 25/51 tests/qtest: libqos: Rename malloc.h to libqos-malloc.h

In reply to Bin Meng

From: Xuzhou Cheng <[email protected]>

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.

---

 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%)
tests/qtest/libqos/generic-pcihost.h +1 -1
index c693c769df..6493a8712a 100644
@@ -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 {
tests/qtest/libqos/libqos-malloc.h renamed from tests/qtest/libqos/malloc.h +0 -0
similarity index 100%
rename from tests/qtest/libqos/malloc.h
rename to tests/qtest/libqos/libqos-malloc.h
tests/qtest/libqos/libqos.h +1 -1
index ba7df448ca..9b4dd509f0 100644
@@ -3,7 +3,7 @@
 
 #include "../libqtest.h"
 #include "pci.h"
-#include "malloc.h"
+#include "libqos-malloc.h"
 
 typedef struct QOSState QOSState;
 
tests/qtest/libqos/malloc-pc.h +1 -1
index d8d79853c8..e531473601 100644
@@ -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);
 
tests/qtest/libqos/malloc-spapr.h +1 -1
index f99572fd71..f544c0d611 100644
@@ -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);
 
tests/qtest/libqos/pci-pc.h +1 -1
index 49ec9507f2..849bd493de 100644
@@ -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 {
tests/qtest/libqos/pci-spapr.h +1 -1
index 20a43718b7..3dbf1e58ae 100644
@@ -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"
 
tests/qtest/libqos/qgraph.h +1 -1
index 871740c0dc..6e94824d09 100644
@@ -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
tests/qtest/libqos/qos_external.h +1 -1
index 8446e3df0b..ea37364887 100644
@@ -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"
 
tests/qtest/libqos/rtas.h +1 -1
index f38f99dfab..be8353d505 100644
@@ -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);
tests/qtest/libqos/virtio.h +1 -1
index b8bd06e1b8..7adc7cbd10 100644
@@ -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
tests/qtest/e1000e-test.c +1 -1
index c98779c7c0..4cdd8238f2 100644
@@ -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)
tests/qtest/fuzz/qos_fuzz.c +1 -1
index c856d3d500..3a3d9c16dd 100644
@@ -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"
tests/qtest/libqos/aarch64-xlnx-zcu102-machine.c +1 -1
index c8a3ea11eb..ab24add8eb 100644
@@ -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"
 
tests/qtest/libqos/arm-imx25-pdk-machine.c +1 -1
index 54d0c95330..8fe128fae8 100644
@@ -20,7 +20,7 @@
 
 #include "qemu/osdep.h"
 #include "../libqtest.h"
-#include "malloc.h"
+#include "libqos-malloc.h"
 #include "qgraph.h"
 #include "i2c.h"
 
tests/qtest/libqos/arm-n800-machine.c +1 -1
index ecd46b1daf..4e5afe0164 100644
@@ -20,7 +20,7 @@
 
 #include "qemu/osdep.h"
 #include "../libqtest.h"
-#include "malloc.h"
+#include "libqos-malloc.h"
 #include "qgraph.h"
 #include "i2c.h"
 
tests/qtest/libqos/arm-raspi2-machine.c +1 -1
index 0a2943440b..367c6c17a5 100644
@@ -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"
 
tests/qtest/libqos/arm-sabrelite-machine.c +1 -1
index ec19a01660..94f6a20fc7 100644
@@ -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"
 
tests/qtest/libqos/arm-smdkc210-machine.c +1 -1
index 4bff249ee8..9bbce924ea 100644
@@ -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"
 
tests/qtest/libqos/arm-virt-machine.c +1 -1
index 139eaba142..4e87405b58 100644
@@ -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"
tests/qtest/libqos/arm-xilinx-zynq-a9-machine.c +1 -1
index 3be80020a6..daac762a06 100644
@@ -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"
 
tests/qtest/libqos/e1000e.c +1 -1
index f87e0e84b2..fc14b07884 100644
@@ -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"
 
tests/qtest/libqos/libqos-malloc.c renamed from tests/qtest/libqos/malloc.c +1 -1
similarity index 99%
rename from tests/qtest/libqos/malloc.c
rename to tests/qtest/libqos/libqos-malloc.c
index f0c8f950c8..d7566972c4 100644
@@ -11,7 +11,7 @@
  */
 
 #include "qemu/osdep.h"
-#include "malloc.h"
+#include "libqos-malloc.h"
 #include "qemu/host-utils.h"
 
 typedef struct MemBlock {
tests/qtest/libqos/qos_external.c +1 -1
index b7a0b873a3..c6bb8bff09 100644
@@ -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"
tests/qtest/libqos/virtio-mmio.c +1 -1
index a6cca8613b..bd0b1d890b 100644
@@ -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"
 
tests/qtest/libqos/virtio-pci.c +1 -1
index 67c2498c84..485b8f6b7e 100644
@@ -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"
tests/qtest/qos-test.c +1 -1
index f97d0a08fd..831db5cf2a 100644
@@ -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"
tests/qtest/libqos/meson.build +1 -1
index fd5d6e5ae1..cff83c86d9 100644
@@ -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',
 
Signature · 1 line
2.34.1
Reviewed-by on v1 25/51
#74 lore raw

Re: [PATCH 25/51] tests/qtest: libqos: Rename malloc.h to libqos-malloc.h

Quoted 9 lines · Bin Meng

From: Xuzhou Cheng <[email protected]>

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.

Quoted 6 lines

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

---

Reviewed-by on v1 25/51
#75 lore raw

Re: [PATCH 25/51] tests/qtest: libqos: Rename malloc.h to libqos-malloc.h

In reply to Bin Meng
Quoted 9 lines · Bin Meng

From: Xuzhou Cheng <[email protected]>

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.

Quoted 6 lines

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

Quoted 418 lines

---

 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%)
tests/qtest/libqos/generic-pcihost.h +1 -1
index c693c769df..6493a8712a 100644
@@ -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 {
tests/qtest/libqos/libqos-malloc.h renamed from tests/qtest/libqos/malloc.h +0 -0
similarity index 100%
rename from tests/qtest/libqos/malloc.h
rename to tests/qtest/libqos/libqos-malloc.h
tests/qtest/libqos/libqos.h +1 -1
index ba7df448ca..9b4dd509f0 100644
@@ -3,7 +3,7 @@
 
 #include "../libqtest.h"
 #include "pci.h"
-#include "malloc.h"
+#include "libqos-malloc.h"
 
 typedef struct QOSState QOSState;
 
tests/qtest/libqos/malloc-pc.h +1 -1
index d8d79853c8..e531473601 100644
@@ -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);
 
tests/qtest/libqos/malloc-spapr.h +1 -1
index f99572fd71..f544c0d611 100644
@@ -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);
tests/qtest/libqos/pci-pc.h +1 -1
index 49ec9507f2..849bd493de 100644
@@ -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 {
tests/qtest/libqos/pci-spapr.h +1 -1
index 20a43718b7..3dbf1e58ae 100644
@@ -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"
 
tests/qtest/libqos/qgraph.h +1 -1
index 871740c0dc..6e94824d09 100644
@@ -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
tests/qtest/libqos/qos_external.h +1 -1
index 8446e3df0b..ea37364887 100644
@@ -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"
 
tests/qtest/libqos/rtas.h +1 -1
index f38f99dfab..be8353d505 100644
@@ -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);
tests/qtest/libqos/virtio.h +1 -1
index b8bd06e1b8..7adc7cbd10 100644
@@ -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
tests/qtest/e1000e-test.c +1 -1
index c98779c7c0..4cdd8238f2 100644
@@ -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)

tests/qtest/fuzz/qos_fuzz.c +1 -1
index c856d3d500..3a3d9c16dd 100644
@@ -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"
tests/qtest/libqos/aarch64-xlnx-zcu102-machine.c +1 -1
index c8a3ea11eb..ab24add8eb 100644
@@ -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"
 
tests/qtest/libqos/arm-imx25-pdk-machine.c +1 -1
index 54d0c95330..8fe128fae8 100644
@@ -20,7 +20,7 @@
 
 #include "qemu/osdep.h"
 #include "../libqtest.h"
-#include "malloc.h"
+#include "libqos-malloc.h"
 #include "qgraph.h"
 #include "i2c.h"
 
tests/qtest/libqos/arm-n800-machine.c +1 -1
index ecd46b1daf..4e5afe0164 100644
@@ -20,7 +20,7 @@
 
 #include "qemu/osdep.h"
 #include "../libqtest.h"
-#include "malloc.h"
+#include "libqos-malloc.h"
 #include "qgraph.h"
 #include "i2c.h"
 
tests/qtest/libqos/arm-raspi2-machine.c +1 -1
index 0a2943440b..367c6c17a5 100644
@@ -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"
 
tests/qtest/libqos/arm-sabrelite-machine.c +1 -1
index ec19a01660..94f6a20fc7 100644
@@ -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"
 
tests/qtest/libqos/arm-smdkc210-machine.c +1 -1
index 4bff249ee8..9bbce924ea 100644
@@ -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"
 
tests/qtest/libqos/arm-virt-machine.c +1 -1
index 139eaba142..4e87405b58 100644
@@ -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"
tests/qtest/libqos/arm-xilinx-zynq-a9-machine.c +1 -1
index 3be80020a6..daac762a06 100644
@@ -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"
 
tests/qtest/libqos/e1000e.c +1 -1
index f87e0e84b2..fc14b07884 100644
@@ -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"
 
tests/qtest/libqos/libqos-malloc.c renamed from tests/qtest/libqos/malloc.c +1 -1
similarity index 99%
rename from tests/qtest/libqos/malloc.c
rename to tests/qtest/libqos/libqos-malloc.c
index f0c8f950c8..d7566972c4 100644
@@ -11,7 +11,7 @@
  */
 
 #include "qemu/osdep.h"
-#include "malloc.h"
+#include "libqos-malloc.h"
 #include "qemu/host-utils.h"
 
 typedef struct MemBlock {
tests/qtest/libqos/qos_external.c +1 -1
index b7a0b873a3..c6bb8bff09 100644
@@ -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"
tests/qtest/libqos/virtio-mmio.c +1 -1
index a6cca8613b..bd0b1d890b 100644
@@ -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"
 
tests/qtest/libqos/virtio-pci.c +1 -1
index 67c2498c84..485b8f6b7e 100644
@@ -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"
tests/qtest/qos-test.c +1 -1
index f97d0a08fd..831db5cf2a 100644
@@ -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"
tests/qtest/libqos/meson.build +1 -2
index fd5d6e5ae1..cff83c86d9 100644
@@ -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

Signature · 1 line
Marc-André Lureau
author
#76 lore raw

PATCH 26/51 tests/qtest: libqtest: Move global_qtest definition back to libqtest.c

In reply to Bin Meng

From: Xuzhou Cheng <[email protected]>

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.

---

 tests/qtest/libqtest-single.h | 2 +-
 tests/qtest/libqtest.c        | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)
tests/qtest/libqtest-single.h +1 -1
index 4e7d0ae1dc..3294985d7b 100644
@@ -13,7 +13,7 @@
 
 #include "libqtest.h"
 
-QTestState *global_qtest __attribute__((common, weak));
+extern QTestState *global_qtest;
 
 /**
  * qtest_start:
tests/qtest/libqtest.c +2 -0
index 34744ace7c..909583dad3 100644
@@ -65,6 +65,8 @@ struct QTestState
     GList *pending_events;
 };
 
+QTestState *global_qtest;
+
 static GHookList abrt_hooks;
 static struct sigaction sigact_old;
 
Signature · 1 line
2.34.1
#77 lore raw

Re: [PATCH 26/51] tests/qtest: libqtest: Move global_qtest definition back to libqtest.c

Quoted 39 lines · Bin Meng

From: Xuzhou Cheng <[email protected]>

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.

---

  tests/qtest/libqtest-single.h | 2 +-
  tests/qtest/libqtest.c        | 2 ++
  2 files changed, 3 insertions(+), 1 deletion(-)
tests/qtest/libqtest-single.h +1 -1
index 4e7d0ae1dc..3294985d7b 100644
@@ -13,7 +13,7 @@
 
  #include "libqtest.h"
 
-QTestState *global_qtest __attribute__((common, weak));
+extern QTestState *global_qtest;
 
  /**
   * qtest_start:
tests/qtest/libqtest.c +0 -0
index 34744ace7c..909583dad3 100644

tests/qtest/libqtest.c struct QTestState · line 71

Quoted 7 lines
tests/qtest/libqtest.c +2 -0
@@ -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

author
#78 lore raw

PATCH 27/51 tests/qtest: Use send/recv for socket communication

In reply to Bin Meng

From: Xuzhou Cheng <[email protected]>

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.

---

 tests/qtest/libqmp.c   | 4 ++--
 tests/qtest/libqtest.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
tests/qtest/libqmp.c +2 -2
index ade26c15f0..995a39c1f8 100644
@@ -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;
         }
tests/qtest/libqtest.c +2 -2
index 909583dad3..b7b7c9c541 100644
@@ -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;
         }
Signature · 1 line
2.34.1
#79 lore raw

Re: [PATCH 27/51] tests/qtest: Use send/recv for socket communication

Quoted 24 lines · Bin Meng

From: Xuzhou Cheng <[email protected]>

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.

---

  tests/qtest/libqmp.c   | 4 ++--
  tests/qtest/libqtest.c | 4 ++--
  2 files changed, 4 insertions(+), 4 deletions(-)
tests/qtest/libqmp.c +0 -0
index ade26c15f0..995a39c1f8 100644

tests/qtest/libqmp.c typedef struct { · line 39

Quoted 5 lines
tests/qtest/libqmp.c +1 -1
@@ -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

author
#80 lore raw

Re: [PATCH 27/51] tests/qtest: Use send/recv for socket communication

Quoted 27 lines · Thomas Huth
Quoted 25 lines · Bin Meng

From: Xuzhou Cheng <[email protected]>

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.

---

  tests/qtest/libqmp.c   | 4 ++--
  tests/qtest/libqtest.c | 4 ++--
  2 files changed, 4 insertions(+), 4 deletions(-)
tests/qtest/libqmp.c +0 -0
index ade26c15f0..995a39c1f8 100644
@@ -36,7 +36,7 @@ typedef struct {
 
Quoted 9 lines

tests/qtest/libqmp.c typedef struct { · line 39

Quoted 4 lines
tests/qtest/libqmp.c +1 -1
  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

#81 lore raw

Re: [PATCH 27/51] tests/qtest: Use send/recv for socket communication

Quoted 38 lines · Bin Meng
Quoted 27 lines · Thomas Huth
Quoted 25 lines · Bin Meng

From: Xuzhou Cheng <[email protected]>

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.

---

   tests/qtest/libqmp.c   | 4 ++--
   tests/qtest/libqtest.c | 4 ++--
   2 files changed, 4 insertions(+), 4 deletions(-)
tests/qtest/libqmp.c +0 -0
index ade26c15f0..995a39c1f8 100644
@@ -36,7 +36,7 @@ typedef struct {
 
Quoted 9 lines

tests/qtest/libqmp.c typedef struct { · line 39

Quoted 4 lines
tests/qtest/libqmp.c +1 -1
   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?

Quoted 2 lines

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

#82 lore raw

Re: [PATCH 27/51] tests/qtest: Use send/recv for socket communication

Hi

Quoted 44 lines · Thomas Huth
Quoted 28 lines · Bin Meng
Quoted 27 lines · Thomas Huth
Quoted 25 lines · Bin Meng

From: Xuzhou Cheng <[email protected]>

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.

---

   tests/qtest/libqmp.c   | 4 ++--
   tests/qtest/libqtest.c | 4 ++--
   2 files changed, 4 insertions(+), 4 deletions(-)
tests/qtest/libqmp.c +0 -0
index ade26c15f0..995a39c1f8 100644
@@ -36,7 +36,7 @@ typedef struct {
 
Quoted 6 lines
Quoted 6 lines

tests/qtest/libqmp.c typedef struct { · line 39

Quoted 4 lines
tests/qtest/libqmp.c +1 -1
   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

Quoted 1 line
Quoted 1 line

looping and EINTR handling) ... not sure whether that's really OK?

Maybe you

Quoted 5 lines
Quoted 2 lines

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.

Quoted 9 lines

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...

Signature · 1 line
Marc-André Lureau
#83 lore raw

Re: [PATCH 27/51] tests/qtest: Use send/recv for socket communication

Quoted 66 lines · Marc-André Lureau

Hi

Quoted 44 lines · Thomas Huth
Quoted 28 lines · Bin Meng
Quoted 27 lines · Thomas Huth
Quoted 25 lines · Bin Meng

From: Xuzhou Cheng <[email protected]>

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.

---

   tests/qtest/libqmp.c   | 4 ++--
   tests/qtest/libqtest.c | 4 ++--
   2 files changed, 4 insertions(+), 4 deletions(-)
tests/qtest/libqmp.c +0 -0
index ade26c15f0..995a39c1f8 100644
@@ -36,7 +36,7 @@ typedef struct {
 
Quoted 6 lines
Quoted 6 lines

tests/qtest/libqmp.c typedef struct { · line 39

Quoted 4 lines
tests/qtest/libqmp.c +1 -1
   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

Quoted 1 line
Quoted 1 line

looping and EINTR handling) ... not sure whether that's really OK?

Maybe you

Quoted 5 lines
Quoted 2 lines

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.

Quoted 9 lines

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.

Quoted 5 lines

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

Signature · 3 lines
|: 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 :|
author
#84 lore raw

Re: [PATCH 27/51] tests/qtest: Use send/recv for socket communication

In reply to Marc-André Lureau
Quoted 52 lines · Marc-André Lureau

Hi

Quoted 48 lines · Thomas Huth
Quoted 38 lines · Bin Meng
Quoted 27 lines · Thomas Huth
Quoted 25 lines · Bin Meng

From: Xuzhou Cheng <[email protected]>

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.

---

   tests/qtest/libqmp.c   | 4 ++--
   tests/qtest/libqtest.c | 4 ++--
   2 files changed, 4 insertions(+), 4 deletions(-)
tests/qtest/libqmp.c +0 -0
index ade26c15f0..995a39c1f8 100644
@@ -36,7 +36,7 @@ typedef struct {
 
Quoted 9 lines

tests/qtest/libqmp.c typedef struct { · line 39

Quoted 4 lines
tests/qtest/libqmp.c +1 -1
   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?

Quoted 2 lines

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

Quoted 8 lines
Quoted 2 lines

... 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.

Quoted 5 lines

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

author
#85 lore raw

PATCH 28/51 tests/qtest: libqtest: Exclude the *_fds APIs for win32

In reply to Bin Meng

From: Bin Meng <[email protected]>

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().

---

 tests/qtest/libqtest.h |  8 ++++++++
 tests/qtest/libqtest.c | 10 +++++++++-
 2 files changed, 17 insertions(+), 1 deletion(-)
tests/qtest/libqtest.h +8 -0
index 94b187837d..3abc75964d 100644
@@ -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:
tests/qtest/libqtest.c +9 -1
index b7b7c9c541..1b24a4f1f7 100644
@@ -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.
Signature · 1 line
2.34.1
Reviewed-by on v1 28/51
#86 lore raw

Re: [PATCH 28/51] tests/qtest: libqtest: Exclude the *_fds APIs for win32

Quoted 6 lines · Bin Meng

From: Bin Meng <[email protected]>

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:

Quoted 8 lines

* 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

Quoted 3 lines
Quoted 156 lines

---

 tests/qtest/libqtest.h |  8 ++++++++
 tests/qtest/libqtest.c | 10 +++++++++-
 2 files changed, 17 insertions(+), 1 deletion(-)
tests/qtest/libqtest.h +3 -0
index 94b187837d..3abc75964d 100644
@@ -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.

tests/qtest/libqtest.h +2 -0
@@ -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.

tests/qtest/libqtest.h +1 -0
@@ -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:

tests/qtest/libqtest.h +1 -0
@@ -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

tests/qtest/libqtest.h +1 -0
@@ -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:

tests/qtest/libqtest.c +5 -1
index b7b7c9c541..1b24a4f1f7 100644
@@ -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)

{

tests/qtest/libqtest.c +1 -0
@@ -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, ...)

{

tests/qtest/libqtest.c +1 -0
@@ -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, ...)

{

tests/qtest/libqtest.c +1 -0
@@ -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;
tests/qtest/libqtest.c +1 -0
@@ -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

Signature · 1 line
Marc-André Lureau
author
#87 lore raw

PATCH 29/51 tests/qtest: libqtest: Install signal handler via signal()

In reply to Bin Meng

From: Bin Meng <[email protected]>

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.

---

 tests/qtest/libqtest.c | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)
tests/qtest/libqtest.c +3 -11
index 1b24a4f1f7..70d7578740 100644
@@ -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)
Signature · 1 line
2.34.1
#88 lore raw

Re: [PATCH 29/51] tests/qtest: libqtest: Install signal handler via signal()

Hi

Quoted 43 lines · Bin Meng

From: Bin Meng <[email protected]>

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.

---

 tests/qtest/libqtest.c | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)
tests/qtest/libqtest.c +2 -10
index 1b24a4f1f7..70d7578740 100644
@@ -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);

tests/qtest/libqtest.c static void sigabrt_handler(int signo)

Quoted 10 lines
tests/qtest/libqtest.c +1 -2
 }
 
 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...

Signature · 1 line
Marc-André Lureau
author
#89 lore raw

Re: [PATCH 29/51] tests/qtest: libqtest: Install signal handler via signal()

Quoted 55 lines · Marc-André Lureau

Hi

Quoted 51 lines · Bin Meng

From: Bin Meng <[email protected]>

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.

---

 tests/qtest/libqtest.c | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)
tests/qtest/libqtest.c +3 -11
index 1b24a4f1f7..70d7578740 100644
@@ -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);
 }
 
Quoted 8 lines

tests/qtest/libqtest.c static void sigabrt_handler(int signo)

Quoted 2 lines
tests/qtest/libqtest.c +0 -1
 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

author
#90 lore raw

PATCH 30/51 tests: Skip iotests and qtest when '--without-default-devices'

In reply to Bin Meng

From: Bin Meng <[email protected]>

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.

---

 tests/qemu-iotests/meson.build | 5 +++++
 tests/qtest/meson.build        | 5 +++++
 2 files changed, 10 insertions(+)
tests/qemu-iotests/meson.build +5 -0
index 323a4acb6a..38d9a874d2 100644
@@ -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')
tests/qtest/meson.build +5 -0
index c97da5a062..0291b3966c 100644
@@ -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,
Signature · 1 line
2.34.1
#91 lore raw

Re: [PATCH 30/51] tests: Skip iotests and qtest when '--without-default-devices'

Quoted 35 lines · Bin Meng

From: Bin Meng <[email protected]>

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.

---

  tests/qemu-iotests/meson.build | 5 +++++
  tests/qtest/meson.build        | 5 +++++
  2 files changed, 10 insertions(+)
tests/qemu-iotests/meson.build +5 -0
index 323a4acb6a..38d9a874d2 100644
@@ -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')
tests/qtest/meson.build +0 -0
index c97da5a062..0291b3966c 100644
@@ -4,6 +4,11 @@ if not config_host.has_key('CONFIG_POSIX')
    subdir_done()

tests/qtest/meson.build if not config_host.has_key('CONFIG_POSIX') · line 14

Quoted 10 lines
tests/qtest/meson.build +5 -0
  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

author
#92 lore raw

Re: [PATCH 30/51] tests: Skip iotests and qtest when '--without-default-devices'

Quoted 39 lines · Thomas Huth
Quoted 37 lines · Bin Meng

From: Bin Meng <[email protected]>

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.

---

  tests/qemu-iotests/meson.build | 5 +++++
  tests/qtest/meson.build        | 5 +++++
  2 files changed, 10 insertions(+)
tests/qemu-iotests/meson.build +5 -0
index 323a4acb6a..38d9a874d2 100644
@@ -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')
tests/qtest/meson.build +0 -0
index c97da5a062..0291b3966c 100644
@@ -4,6 +4,11 @@ if not config_host.has_key('CONFIG_POSIX')
    subdir_done()
  endif
 
Quoted 13 lines

tests/qtest/meson.build if not config_host.has_key('CONFIG_POSIX') · line 14

Quoted 8 lines
tests/qtest/meson.build +5 -0
+# 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

author
#93 lore raw

PATCH 31/51 tests/qtest: Support libqtest to build and run on Windows

In reply to Bin Meng

From: Bin Meng <[email protected]>

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.

---

 tests/qtest/libqtest.c  | 101 +++++++++++++++++++++++++++++++++++++++-
 tests/qtest/meson.build |   5 +-
 2 files changed, 101 insertions(+), 5 deletions(-)
tests/qtest/libqtest.c +99 -2
index 70d7578740..99e52ff571 100644
@@ -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",
tests/qtest/meson.build +2 -3
index 0291b3966c..6d469a1822 100644
@@ -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
 
Signature · 1 line
2.34.1
#94 lore raw

Re: [PATCH 31/51] tests/qtest: Support libqtest to build and run on Windows

Hi

Quoted 182 lines · Bin Meng

From: Bin Meng <[email protected]>

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.

---

 tests/qtest/libqtest.c  | 101 +++++++++++++++++++++++++++++++++++++++-
 tests/qtest/meson.build |   5 +-
 2 files changed, 101 insertions(+), 5 deletions(-)
tests/qtest/libqtest.c +34 -0
index 70d7578740..99e52ff571 100644
@@ -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 "

tests/qtest/libqtest.c +31 -0
@@ -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 */

tests/qtest/libqtest.c +11 -0
+                        );
+    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;

tests/qtest/libqtest.c QTestState *qtest_init_without_qmp_handshake(const · line 356

Quoted 8 lines
tests/qtest/libqtest.c +3 -0
@@ -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

Quoted 34 lines
tests/qtest/libqtest.c +0 -0
     sock = init_socket(socket_path);
     qmpsock = init_socket(qmp_socket_path);
tests/qtest/libqtest.c +1 -1
@@ -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 "
tests/qtest/libqtest.c +1 -1
@@ -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 ?: "");
tests/qtest/libqtest.c +1 -0
@@ -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__

tests/qtest/libqtest.c QTestState *qtest_init_without_qmp_handshake(const · line 407

Quoted 7 lines
tests/qtest/libqtest.c +2 -0
@@ -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() ?

Quoted 26 lines
tests/qtest/libqtest.c +1 -0
+#endif /* _WIN32 */
 
     g_free(command);
     s->fd = socket_accept(sock);
tests/qtest/libqtest.c +10 -0
@@ -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 */

tests/qtest/libqtest.c QTestState *qtest_init_with_serial(const char · line 494

Quoted 8 lines
tests/qtest/libqtest.c +3 -0
@@ -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

Quoted 19 lines
tests/qtest/libqtest.c +0 -0
     sock_fd_init = init_socket(sock_path);

qts = qtest_initf("-chardev socket,id=s0,path=%s -serial chardev:s0
%s",

tests/qtest/meson.build +2 -4
index 0291b3966c..6d469a1822 100644
@@ -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
 
--
Quoted 4 lines

2.34.1

lgtm otherwise

Signature · 1 line
Marc-André Lureau
author
#95 lore raw

Re: [PATCH 31/51] tests/qtest: Support libqtest to build and run on Windows

Hi,

Quoted 186 lines · Marc-André Lureau

Hi

Quoted 182 lines · Bin Meng

From: Bin Meng <[email protected]>

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.

---

 tests/qtest/libqtest.c  | 101 +++++++++++++++++++++++++++++++++++++++-
 tests/qtest/meson.build |   5 +-
 2 files changed, 101 insertions(+), 5 deletions(-)
tests/qtest/libqtest.c +77 -0
index 70d7578740..99e52ff571 100644
@@ -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);
 
Quoted 7 lines

tests/qtest/libqtest.c QTestState *qtest_init_without_qmp_handshake(const char *extra_args) · line 354

Quoted 3 lines
tests/qtest/libqtest.c +3 -0
+#ifdef _WIN32
+    socket_init();
+#endif

You can call this unconditionally, afaict

Will fix in v2.

Quoted 31 lines
Quoted 31 lines
tests/qtest/libqtest.c +3 -2
     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)
Quoted 9 lines

tests/qtest/libqtest.c QTestState *qtest_init_without_qmp_handshake(const char *extra_args) · line 405

Quoted 5 lines
tests/qtest/libqtest.c +2 -0
         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?

Quoted 39 lines
Quoted 26 lines
tests/qtest/libqtest.c +11 -0
+#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 */
 

tests/qtest/libqtest.c QTestState *qtest_init_with_serial(const char *extra_args, int *sock_fd) · line 492

Quoted 6 lines
tests/qtest/libqtest.c +3 -0
@@ -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

Quoted 3 lines
tests/qtest/libqtest.c +0 -0
     sock_fd_init = init_socket(sock_path);
 
Quoted 14 lines
Quoted 6 lines
tests/qtest/libqtest.c +0 -0
     qts = qtest_initf("-chardev socket,id=s0,path=%s -serial chardev:s0 %s",
tests/qtest/meson.build +0 -0
index 0291b3966c..6d469a1822 100644

tests/qtest/meson.build line 5

Quoted 8 lines
tests/qtest/meson.build +2 -3
@@ -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

#96 lore raw

Re: [PATCH 31/51] tests/qtest: Support libqtest to build and run on Windows

In reply to Bin Meng

Hi

Quoted 76 lines · Bin Meng

From: Bin Meng <[email protected]>

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.

---

 tests/qtest/libqtest.c  | 101 +++++++++++++++++++++++++++++++++++++++-
 tests/qtest/meson.build |   5 +-
 2 files changed, 101 insertions(+), 5 deletions(-)
tests/qtest/libqtest.c +17 -0
index 70d7578740..99e52ff571 100644
@@ -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);

tests/qtest/libqtest.c bool qtest_probe_child(QTestState *s) · line 150

Quoted 10 lines
tests/qtest/libqtest.c +6 -0
         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.

Quoted 200 lines
tests/qtest/libqtest.c +1 -0
+#endif
         s->qemu_pid = -1;
     }
     return false;
tests/qtest/libqtest.c +10 -0
@@ -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 "

tests/qtest/libqtest.c +31 -0
@@ -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 */

tests/qtest/libqtest.c +15 -1
+                        );
+    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 "
tests/qtest/libqtest.c +1 -1
@@ -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 ?: "");
tests/qtest/libqtest.c +1 -0
@@ -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__

tests/qtest/libqtest.c +3 -0
@@ -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);
tests/qtest/libqtest.c +13 -0
@@ -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",

tests/qtest/meson.build +2 -4
index 0291b3966c..6d469a1822 100644
@@ -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

Signature · 1 line
Marc-André Lureau
author
#97 lore raw

PATCH 32/51 tests/qtest: Fix ERROR_SHARING_VIOLATION for win32

In reply to Bin Meng

From: Bin Meng <[email protected]>

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.

---

 tests/qtest/ahci-test.c        | 14 ++++++++++++++
 tests/qtest/boot-serial-test.c | 13 +++++++++++++
 2 files changed, 27 insertions(+)
tests/qtest/ahci-test.c +14 -0
index f26cd6f86f..0e88cd0eef 100644
@@ -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);
tests/qtest/boot-serial-test.c +13 -0
index 404adcfa20..fb6c81bf35 100644
@@ -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;
Signature · 1 line
2.34.1
#98 lore raw

Re: [PATCH 32/51] tests/qtest: Fix ERROR_SHARING_VIOLATION for win32

Quoted 8 lines · Bin Meng

From: Bin Meng <[email protected]>

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

author
#99 lore raw

Re: [PATCH 32/51] tests/qtest: Fix ERROR_SHARING_VIOLATION for win32

Quoted 4 lines · Thomas Huth
Quoted 2 lines · Bin Meng

From: Bin Meng <[email protected]>

Quoted 9 lines
Quoted 6 lines

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

#100 lore raw

Re: [PATCH 32/51] tests/qtest: Fix ERROR_SHARING_VIOLATION for win32

In reply to Bin Meng

Hi

Quoted 7 lines · Bin Meng

From: Bin Meng <[email protected]>

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?

Quoted 66 lines

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

---

 tests/qtest/ahci-test.c        | 14 ++++++++++++++
 tests/qtest/boot-serial-test.c | 13 +++++++++++++
 2 files changed, 27 insertions(+)
tests/qtest/ahci-test.c +14 -0
index f26cd6f86f..0e88cd0eef 100644
@@ -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);
tests/qtest/boot-serial-test.c +13 -1
index 404adcfa20..fb6c81bf35 100644
@@ -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

Signature · 1 line
Marc-André Lureau
author
#101 lore raw

Re: [PATCH 32/51] tests/qtest: Fix ERROR_SHARING_VIOLATION for win32

Quoted 7 lines · Marc-André Lureau

Hi

Quoted 3 lines · Bin Meng

From: Bin Meng <[email protected]>

Quoted 8 lines
Quoted 4 lines

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

author
#102 lore raw

PATCH 33/51 tests/qtest: {ahci, ide}-test: Use relative path for temporary files

In reply to Bin Meng

From: Bin Meng <[email protected]>

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.

---

 tests/qtest/ahci-test.c | 19 ++++++++++++++++---
 tests/qtest/ide-test.c  | 18 ++++++++++++++++--
 2 files changed, 32 insertions(+), 5 deletions(-)
tests/qtest/ahci-test.c +16 -3
index 0e88cd0eef..bce9ff770c 100644
@@ -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);
tests/qtest/ide-test.c +16 -2
index ebbf8e0126..c5cad6c0be 100644
@@ -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);
Signature · 1 line
2.34.1
#103 lore raw

Re: [PATCH 33/51] tests/qtest: {ahci, ide}-test: Use relative path for temporary files

Quoted 7 lines · Bin Meng

From: Bin Meng <[email protected]>

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..

Quoted 27 lines

---

 tests/qtest/ahci-test.c | 19 ++++++++++++++++---
 tests/qtest/ide-test.c  | 18 ++++++++++++++++--
 2 files changed, 32 insertions(+), 5 deletions(-)
tests/qtest/ahci-test.c +1 -1
index 0e88cd0eef..bce9ff770c 100644
@@ -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;
tests/qtest/ahci-test.c +3 -0
@@ -1886,8 +1886,21 @@ int main(int argc, char **argv)
         return 0;
     }
 
+    /*
+     * "base" stores the starting point where we create temporary files.
+     *

tests/qtest/ahci-test.c int main(int argc, char **argv) · line 1901

Quoted 10 lines
tests/qtest/ahci-test.c +9 -0
+     * 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)

Quoted 61 lines
tests/qtest/ahci-test.c +2 -1
+
     /* 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()) {
tests/qtest/ahci-test.c +1 -1
@@ -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);
tests/qtest/ide-test.c +16 -2
index ebbf8e0126..c5cad6c0be 100644
@@ -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

Signature · 1 line
Marc-André Lureau
author
#104 lore raw

Re: [PATCH 33/51] tests/qtest: {ahci, ide}-test: Use relative path for temporary files

Quoted 39 lines · Marc-André Lureau
Quoted 7 lines · Bin Meng

From: Bin Meng <[email protected]>

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..

Quoted 24 lines

---

 tests/qtest/ahci-test.c | 19 ++++++++++++++++---
 tests/qtest/ide-test.c  | 18 ++++++++++++++++--
 2 files changed, 32 insertions(+), 5 deletions(-)
tests/qtest/ahci-test.c +1 -1
index 0e88cd0eef..bce9ff770c 100644
@@ -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;
     }
 
Quoted 15 lines

tests/qtest/ahci-test.c int main(int argc, char **argv) · line 1900

Quoted 12 lines
tests/qtest/ahci-test.c +12 -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.

Quoted 50 lines
Quoted 50 lines
tests/qtest/ahci-test.c +3 -2
+
     /* 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);
tests/qtest/ide-test.c +15 -1
index ebbf8e0126..c5cad6c0be 100644
@@ -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);
 
Quoted 8 lines
Quoted 8 lines
tests/qtest/ide-test.c +1 -2
     /* 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

author
#105 lore raw

PATCH 34/51 tests/qtest: bios-tables-test: Adapt the case for win32

In reply to Bin Meng

From: Bin Meng <[email protected]>

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.

---

 tests/qtest/bios-tables-test.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
tests/qtest/bios-tables-test.c +9 -3
index 36783966b0..0148ce388c 100644
@@ -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);
 }
Signature · 1 line
2.34.1
#106 lore raw

Re: [PATCH 34/51] tests/qtest: bios-tables-test: Adapt the case for win32

Quoted 37 lines · Bin Meng

From: Bin Meng <[email protected]>

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.

---

 tests/qtest/bios-tables-test.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
tests/qtest/bios-tables-test.c +6 -0
index 36783966b0..0148ce388c 100644
@@ -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 = {

tests/qtest/bios-tables-test.c static void test_acpi_q35_slic(void) · line 1632

Quoted 8 lines
tests/qtest/bios-tables-test.c +2 -3
@@ -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

Quoted 8 lines
tests/qtest/bios-tables-test.c +1 -1
+                  "asl_compiler_rev=00000000,data=" DEV_NULL,
                   &data);
     free_test_data(&data);
 }
--

2.34.1

author
#107 lore raw

Re: [PATCH 34/51] tests/qtest: bios-tables-test: Adapt the case for win32

Quoted 45 lines · Ani Sinha
Quoted 40 lines · Bin Meng

From: Bin Meng <[email protected]>

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.

---

 tests/qtest/bios-tables-test.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
tests/qtest/bios-tables-test.c +6 -0
index 36783966b0..0148ce388c 100644
@@ -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",
     };
 
Quoted 9 lines

tests/qtest/bios-tables-test.c static void test_acpi_q35_slic(void) · line 1632

Quoted 5 lines
tests/qtest/bios-tables-test.c +2 -3
-    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

Reviewed-by on v1 34/51
#108 lore raw

Re: [PATCH 34/51] tests/qtest: bios-tables-test: Adapt the case for win32

In reply to Bin Meng
Quoted 7 lines · Bin Meng

From: Bin Meng <[email protected]>

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:

Quoted 8 lines

'-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.

Quoted 41 lines

---

 tests/qtest/bios-tables-test.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
tests/qtest/bios-tables-test.c +9 -4
index 36783966b0..0148ce388c 100644
@@ -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

Signature · 1 line
Marc-André Lureau
author
#109 lore raw

PATCH 35/51 tests/qtest: device-plug-test: Reverse the usage of double/single quotes

In reply to Bin Meng

From: Bin Meng <[email protected]>

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.

---

 tests/qtest/device-plug-test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tests/qtest/device-plug-test.c +1 -1
index 2e3137843e..a1fb99c8ff 100644
@@ -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);
 
     /*
Signature · 1 line
2.34.1
Reviewed-by on v1 35/51
#110 lore raw

Re: [PATCH 35/51] tests/qtest: device-plug-test: Reverse the usage of double/single quotes

Quoted 22 lines · Bin Meng

From: Bin Meng <[email protected]>

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.

---

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

tests/qtest/device-plug-test.c static void test_pci_unplug_json_request(void) · line 99

Quoted 6 lines
tests/qtest/device-plug-test.c +1 -1
@@ -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!

author
#111 lore raw

PATCH 36/51 tests/qtest: machine-none-test: Use double quotes to pass the cpu option

In reply to Bin Meng

From: Bin Meng <[email protected]>

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.

---

 tests/qtest/machine-none-test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tests/qtest/machine-none-test.c +1 -1
index f92fab479f..31cc0bfb01 100644
@@ -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"));
Signature · 1 line
2.34.1
Reviewed-by on v1 36/51
#112 lore raw

Re: [PATCH 36/51] tests/qtest: machine-none-test: Use double quotes to pass the cpu option

Quoted 20 lines · Bin Meng

From: Bin Meng <[email protected]>

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.

---

  tests/qtest/machine-none-test.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
tests/qtest/machine-none-test.c +0 -0
index f92fab479f..31cc0bfb01 100644

tests/qtest/machine-none-test.c static void test_machine_cpu_cli(void) · line 87

Quoted 8 lines
tests/qtest/machine-none-test.c +1 -1
@@ -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"));
author
#113 lore raw

PATCH 37/51 tests/qtest: migration-test: Disable IO redirection for win32

In reply to Bin Meng

From: Bin Meng <[email protected]>

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.

---

 tests/qtest/migration-test.c | 39 +++++++++++++++++++++++-------------
 1 file changed, 25 insertions(+), 14 deletions(-)
tests/qtest/migration-test.c +25 -14
index 2ae7498d5d..125d48d855 100644
@@ -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;
Signature · 1 line
2.34.1
#114 lore raw

Re: [PATCH 37/51] tests/qtest: migration-test: Disable IO redirection for win32

Quoted 7 lines · * Bin Meng ([email protected]) wrote:

From: Bin Meng <[email protected]>

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.

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

Dave

Quoted 156 lines

---

 tests/qtest/migration-test.c | 39 +++++++++++++++++++++++-------------
 1 file changed, 25 insertions(+), 14 deletions(-)
tests/qtest/migration-test.c +25 -14
index 2ae7498d5d..125d48d855 100644
@@ -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;
Signature · 1 line
2.34.1
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
author
#115 lore raw

Re: [PATCH 37/51] tests/qtest: migration-test: Disable IO redirection for win32

Quoted 4 lines · Dr. David Alan Gilbert
Quoted 2 lines · * Bin Meng ([email protected]) wrote:

From: Bin Meng <[email protected]>

Quoted 8 lines
Quoted 5 lines

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.

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

Yeah, will do in v2.

Regards,
Bin

author
#116 lore raw

PATCH 38/51 tests/qtest: {ahci,ide}-test: Open file in binary mode

In reply to Bin Meng

From: Xuzhou Cheng <[email protected]>

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.

---

 tests/qtest/ahci-test.c | 2 +-
 tests/qtest/ide-test.c  | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
tests/qtest/ahci-test.c +1 -1
index bce9ff770c..be11508c75 100644
@@ -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
 
tests/qtest/ide-test.c +2 -2
index c5cad6c0be..ee03dea4fa 100644
@@ -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);
Signature · 1 line
2.34.1
#117 lore raw

Re: [PATCH 38/51] tests/qtest: {ahci,ide}-test: Open file in binary mode

Quoted 26 lines · Bin Meng

From: Xuzhou Cheng <[email protected]>

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.

---

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

tests/qtest/ahci-test.c static int prepare_iso(size_t size, unsigned char **buf, char **name) · line 1458

Quoted 7 lines
tests/qtest/ahci-test.c +1 -1
@@ -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

Reviewed-by on v1 38/51
#118 lore raw

Re: [PATCH 38/51] tests/qtest: {ahci, ide}-test: Open file in binary mode

In reply to Bin Meng

Hi

Quoted 26 lines · Bin Meng

From: Xuzhou Cheng <[email protected]>

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.

---

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

tests/qtest/ahci-test.c static int prepare_iso(size_t size, unsigned char · line 1459

Quoted 8 lines
tests/qtest/ahci-test.c +1 -1
@@ -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.

Quoted 25 lines

#endif

tests/qtest/ide-test.c +2 -3
index c5cad6c0be..ee03dea4fa 100644
@@ -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);
--
Quoted 4 lines

2.34.1

ack this part,

Signature · 1 line
Marc-André Lureau
author
#119 lore raw

PATCH 39/51 tests/qtest: virtio-net-failover: Disable migration tests for win32

In reply to Bin Meng

From: Xuzhou Cheng <[email protected]>

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

---

 tests/qtest/virtio-net-failover.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
tests/qtest/virtio-net-failover.c +8 -1
index 443ee56de9..4a809590bf 100644
@@ -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();
 
Signature · 1 line
2.34.1
author
#120 lore raw

PATCH 40/51 chardev/char-file: Add FILE_SHARE_WRITE when openning the file for win32

In reply to Bin Meng

From: Xuzhou Cheng <[email protected]>

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

---

 chardev/char-file.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
chardev/char-file.c +2 -2
index 2fd80707e5..66385211eb 100644
@@ -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;
Signature · 1 line
2.34.1
#121 lore raw

Re: [PATCH 40/51] chardev/char-file: Add FILE_SHARE_WRITE when openning the file for win32

Hi

Quoted 7 lines · Bin Meng

From: Xuzhou Cheng <[email protected]>

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

Quoted 5 lines

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

Quoted 5 lines

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

---

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..

Quoted 22 lines
 chardev/char-file.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
chardev/char-file.c +2 -3
index 2fd80707e5..66385211eb 100644
@@ -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

author
#122 lore raw

Re: [PATCH 40/51] chardev/char-file: Add FILE_SHARE_WRITE when openning the file for win32

Quoted 24 lines · Marc-André Lureau

Hi

Quoted 7 lines · Bin Meng

From: Xuzhou Cheng <[email protected]>

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

Quoted 5 lines

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

Quoted 2 lines

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

Quoted 8 lines
Quoted 3 lines

---

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.

Quoted 3 lines

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

Regards,
Bin

#123 lore raw

Re: [PATCH 40/51] chardev/char-file: Add FILE_SHARE_WRITE when openning the file for win32

Hi

Quoted 36 lines · Bin Meng
Quoted 15 lines · Marc-André Lureau

Hi

Quoted 7 lines · Bin Meng

From: Xuzhou Cheng <[email protected]>

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

Quoted 1 line
Quoted 8 lines
Quoted 4 lines

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

Quoted 1 line

[1]

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

Quoted 9 lines
Quoted 4 lines

---

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.

Quoted 8 lines

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?

Signature · 1 line
Marc-André Lureau
author
#124 lore raw

Re: [PATCH 40/51] chardev/char-file: Add FILE_SHARE_WRITE when openning the file for win32

Quoted 48 lines · Marc-André Lureau

Hi

Quoted 36 lines · Bin Meng
Quoted 24 lines · Marc-André Lureau

Hi

Quoted 7 lines · Bin Meng

From: Xuzhou Cheng <[email protected]>

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

Quoted 5 lines

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

Quoted 2 lines

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

Quoted 8 lines
Quoted 3 lines

---

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.

Quoted 7 lines

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.

Quoted 1 line

Thanks for the details, that's worth to add in commit message imho.

Sure, I can add this in the commit message.

Quoted 3 lines

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/[email protected]/

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

#125 lore raw

Re: [PATCH 40/51] chardev/char-file: Add FILE_SHARE_WRITE when openning the file for win32

Hi

Quoted 59 lines · Bin Meng
Quoted 30 lines · Marc-André Lureau

Hi

Quoted 26 lines · Bin Meng
Quoted 23 lines · Marc-André Lureau

Hi

Quoted 7 lines · Bin Meng

From: Xuzhou Cheng <[email protected]>

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

Quoted 5 lines

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

Quoted 1 line

[1]

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

Quoted 18 lines
Quoted 10 lines
Quoted 9 lines
Quoted 4 lines

---

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.

Quoted 7 lines

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.

Quoted 1 line

Thanks for the details, that's worth to add in commit message imho.

Sure, I can add this in the commit message.

Quoted 3 lines

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

Quoted 8 lines

Yeah, the test case fix is here:

https://lore.kernel.org/qemu-devel/[email protected]/

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.

author
#126 lore raw

PATCH 41/51 tests/qtest: migration-test: Kill "to" after migration is canceled

In reply to Bin Meng

From: Xuzhou Cheng <[email protected]>

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

---

 tests/qtest/migration-test.c | 4 ++++
 1 file changed, 4 insertions(+)
tests/qtest/migration-test.c +4 -0
index 125d48d855..18ec079abf 100644
@@ -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,
Signature · 1 line
2.34.1
#127 lore raw

Re: [PATCH 41/51] tests/qtest: migration-test: Kill "to" after migration is canceled

Quoted 17 lines · * Bin Meng ([email protected]) wrote:

From: Xuzhou Cheng <[email protected]>

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

---

 tests/qtest/migration-test.c | 4 ++++
 1 file changed, 4 insertions(+)
tests/qtest/migration-test.c +0 -0
index 125d48d855..18ec079abf 100644

tests/qtest/migration-test.c static void test_multifd_tcp_cancel(void) · line 2138

Quoted 7 lines
tests/qtest/migration-test.c +4 -0
@@ -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

Quoted 5 lines
tests/qtest/migration-test.c +0 -0
     args = (MigrateStart){
         .only_target = true,
Signature · 1 line
2.34.1
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Reviewed-by
#128 lore raw

Re: [PATCH 41/51] tests/qtest: migration-test: Kill "to" after migration is canceled

Hi

Quoted 20 lines · Dr. David Alan Gilbert
Quoted 19 lines · * Bin Meng ([email protected]) wrote:

From: Xuzhou Cheng <[email protected]>

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

---

 tests/qtest/migration-test.c | 4 ++++
 1 file changed, 4 insertions(+)
tests/qtest/migration-test.c +0 -0
index 125d48d855..18ec079abf 100644
@@ -2132,6 +2132,10 @@ static void test_multifd_tcp_cancel(void)
     wait_for_migration_pass(from);
 
Quoted 9 lines

tests/qtest/migration-test.c static void test_multifd_tcp_cancel(void) · line 2138

Quoted 5 lines
tests/qtest/migration-test.c +4 -0
     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,

Signature · 1 line
Marc-André Lureau
author
#129 lore raw

Re: [PATCH 41/51] tests/qtest: migration-test: Kill "to" after migration is canceled

Quoted 34 lines · Marc-André Lureau

Hi

Quoted 29 lines · Dr. David Alan Gilbert
Quoted 17 lines · * Bin Meng ([email protected]) wrote:

From: Xuzhou Cheng <[email protected]>

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

---

 tests/qtest/migration-test.c | 4 ++++
 1 file changed, 4 insertions(+)
tests/qtest/migration-test.c +0 -0
index 125d48d855..18ec079abf 100644

tests/qtest/migration-test.c static void test_multifd_tcp_cancel(void) · line 2138

Quoted 7 lines
tests/qtest/migration-test.c +4 -0
@@ -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.

Quoted 7 lines

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,

Regards,
Bin

author
#130 lore raw

PATCH 42/51 hw/ppc: spapr: Use qemu_vfree() to free spapr->htab

In reply to Bin Meng

From: Xuzhou Cheng <[email protected]>

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"")

---

 hw/ppc/spapr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/ppc/spapr.c +1 -1
index bc9ba6e6dc..4034f4d130 100644
@@ -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);
Signature · 1 line
2.34.1
Reviewed-by on v1 42/51
#131 lore raw

Re: [PATCH 42/51] hw/ppc: spapr: Use qemu_vfree() to free spapr->htab

Quoted 10 lines · Bin Meng

From: Xuzhou Cheng <[email protected]>

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"")

---

Quoted 17 lines
  hw/ppc/spapr.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
hw/ppc/spapr.c +1 -1
index bc9ba6e6dc..4034f4d130 100644
@@ -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);
Reviewed-by on v1 42/51
#132 lore raw

Re: [PATCH 42/51] hw/ppc: spapr: Use qemu_vfree() to free spapr->htab

In reply to Bin Meng
Quoted 5 lines · Bin Meng

From: Xuzhou Cheng <[email protected]>

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

Quoted 7 lines
Fixes c5f54f3e31bf ("pseries: Move hash page table allocation to reset

time")

Fixes b4db54132ffe ("target/ppc: Implement H_REGISTER_PROCESS_TABLE

H_CALL"")

Quoted 23 lines

---

 hw/ppc/spapr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/ppc/spapr.c +1 -2
index bc9ba6e6dc..4034f4d130 100644
@@ -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

Signature · 1 line
Marc-André Lureau
author
#133 lore raw

PATCH 43/51 tests/qtest: npcm7xx_emc-test: Skip running test_{tx, rx} on win32

In reply to Bin Meng

From: Bin Meng <[email protected]>

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

---

 tests/qtest/npcm7xx_emc-test.c | 8 ++++++++
 1 file changed, 8 insertions(+)
tests/qtest/npcm7xx_emc-test.c +8 -0
index a353fef0ca..c373d24e1e 100644
@@ -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();
Signature · 1 line
2.34.1
Reviewed-by on v1 43/51
#135 lore raw

Re: [PATCH 43/51] tests/qtest: npcm7xx_emc-test: Skip running test_{tx, rx} on win32

In reply to Bin Meng
Quoted 7 lines · Bin Meng

From: Bin Meng <[email protected]>

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

Quoted 77 lines

---

 tests/qtest/npcm7xx_emc-test.c | 8 ++++++++
 1 file changed, 8 insertions(+)
tests/qtest/npcm7xx_emc-test.c +2 -0
index a353fef0ca..c373d24e1e 100644
@@ -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)

tests/qtest/npcm7xx_emc-test.c +1 -0
@@ -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)

{

tests/qtest/npcm7xx_emc-test.c +1 -0
@@ -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)

tests/qtest/npcm7xx_emc-test.c +4 -1
@@ -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

author
#136 lore raw

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

In reply to Bin Meng

From: Bin Meng <[email protected]>

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.

---

 tests/qtest/microbit-test.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
tests/qtest/microbit-test.c +5 -5
index b71daae9a9..4bc267020b 100644
@@ -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);
 }
Signature · 1 line
2.34.1
Reviewed-by on v1 44/51
#137 lore raw

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

Quoted 10 lines · Bin Meng

From: Bin Meng <[email protected]>

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.

Quoted 55 lines

---

 tests/qtest/microbit-test.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
tests/qtest/microbit-test.c +1 -1
index b71daae9a9..4bc267020b 100644
@@ -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));
tests/qtest/microbit-test.c +1 -1
@@ -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);
tests/qtest/microbit-test.c +3 -4
@@ -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

Signature · 1 line
Marc-André Lureau
author
#138 lore raw

PATCH 45/51 tests/qtest: prom-env-test: Use double quotes to pass the prom-env option

In reply to Bin Meng

From: Bin Meng <[email protected]>

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.

---

 tests/qtest/prom-env-test.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tests/qtest/prom-env-test.c +2 -2
index c2b0448e55..39ccb59797 100644
@@ -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);
Signature · 1 line
2.34.1
Reviewed-by on v1 45/51
#139 lore raw

Re: [PATCH 45/51] tests/qtest: prom-env-test: Use double quotes to pass the prom-env option

Quoted 20 lines · Bin Meng

From: Bin Meng <[email protected]>

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.

---

  tests/qtest/prom-env-test.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
tests/qtest/prom-env-test.c +0 -0
index c2b0448e55..39ccb59797 100644

tests/qtest/prom-env-test.c static void test_machine(const void *machine) · line 65

Quoted 10 lines
tests/qtest/prom-env-test.c +2 -2
@@ -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);
author
#140 lore raw

PATCH 46/51 tests/qtest: libqtest: Replace the call to close a socket with closesocket()

In reply to Bin Meng

From: Bin Meng <[email protected]>

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.

---

 tests/qtest/libqtest.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
tests/qtest/libqtest.c +4 -4
index 99e52ff571..918f4657ed 100644
@@ -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) {
Signature · 1 line
2.34.1
Reviewed-by on v1 46/51
#141 lore raw

Re: [PATCH 46/51] tests/qtest: libqtest: Replace the call to close a socket with closesocket()

Quoted 13 lines · Bin Meng

From: Bin Meng <[email protected]>

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:

Quoted 8 lines

* 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.

Quoted 43 lines

---

 tests/qtest/libqtest.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
tests/qtest/libqtest.c +4 -5
index 99e52ff571..918f4657ed 100644
@@ -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

Signature · 1 line
Marc-André Lureau
author
#142 lore raw

PATCH 47/51 tests/qtest: libqtest: Correct the timeout unit of blocking receive calls for win32

In reply to Bin Meng

From: Bin Meng <[email protected]>

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.

---

 tests/qtest/libqtest.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
tests/qtest/libqtest.c +10 -1
index 918f4657ed..7b41971347 100644
@@ -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))) {
Signature · 1 line
2.34.1
Reviewed-by on v1 47/51
#143 lore raw

Re: [PATCH 47/51] tests/qtest: libqtest: Correct the timeout unit of blocking receive calls for win32

Hi

Quoted 4 lines · Bin Meng

From: Bin Meng <[email protected]>

Some qtest cases don't get response from the the QEMU executable

"the the"

Quoted 8 lines

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

Quoted 3 lines
Quoted 48 lines

---

 tests/qtest/libqtest.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
tests/qtest/libqtest.c +5 -1
index 918f4657ed..7b41971347 100644
@@ -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.

tests/qtest/libqtest.c +5 -1
+     */
+#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

Signature · 1 line
Marc-André Lureau
author
#144 lore raw

PATCH 48/51 io/channel-watch: Drop a superfluous '#ifdef WIN32'

In reply to Bin Meng

From: Bin Meng <[email protected]>

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

---

 io/channel-watch.c | 2 --
 1 file changed, 2 deletions(-)
io/channel-watch.c +0 -2
index 0289b3647c..89f3c8a88a 100644
@@ -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));
Signature · 1 line
2.34.1
Reviewed-by on v1 48/51
#145 lore raw

Re: [PATCH 48/51] io/channel-watch: Drop a superfluous '#ifdef WIN32'

Quoted 7 lines · Bin Meng

From: Bin Meng <[email protected]>

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

Quoted 27 lines

---

 io/channel-watch.c | 2 --
 1 file changed, 2 deletions(-)
io/channel-watch.c +0 -2
index 0289b3647c..89f3c8a88a 100644
@@ -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

Signature · 1 line
Marc-André Lureau
Reviewed-by on v1 48/51
#146 lore raw

Re: [PATCH 48/51] io/channel-watch: Drop a superfluous '#ifdef WIN32'

In reply to Bin Meng
Quoted 10 lines · Bin Meng

From: Bin Meng <[email protected]>

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

---

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

and queued

With regards,
Daniel

Signature · 3 lines
|: 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 :|
author
#147 lore raw

PATCH 49/51 io/channel-watch: Fix socket watch on Windows

In reply to Bin Meng

From: Bin Meng <[email protected]>

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.

---
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(-)
io/channel-watch.c +0 -4
index 89f3c8a88a..e34d86e810 100644
@@ -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);
Signature · 1 line
2.34.1
#148 lore raw

Re: [PATCH 49/51] io/channel-watch: Fix socket watch on Windows

Hi

Quoted 10 lines · Bin Meng

From: Bin Meng <[email protected]>

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.

Quoted 6 lines

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()

Quoted 6 lines

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.

Quoted 7 lines

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.

What clears the event then?

Quoted 11 lines

---
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.

Quoted 9 lines

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?

Quoted 16 lines
 io/channel-watch.c | 4 ----
 1 file changed, 4 deletions(-)
io/channel-watch.c +0 -2
index 89f3c8a88a..e34d86e810 100644
@@ -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;

io/channel-watch.c static gboolean · line 127

Quoted 10 lines
io/channel-watch.c +0 -2
 
     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.

Signature · 1 line
Marc-André Lureau
author
#149 lore raw

Re: [PATCH 49/51] io/channel-watch: Fix socket watch on Windows

Quoted 33 lines · Marc-André Lureau

Hi

Quoted 29 lines · Bin Meng

From: Bin Meng <[email protected]>

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.

Quoted 5 lines
Quoted 1 line

What clears the event then?

It seems we don't need to clear the event as everything still works as expected.

Quoted 15 lines
Quoted 15 lines

---
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.

Quoted 7 lines
Quoted 5 lines

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.

Quoted 2 lines

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.

Quoted 4 lines

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

Quoted 31 lines
Quoted 18 lines


 io/channel-watch.c | 4 ----
 1 file changed, 4 deletions(-)
io/channel-watch.c +0 -2
index 89f3c8a88a..e34d86e810 100644
@@ -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;

io/channel-watch.c static gboolean · line 127

Quoted 10 lines
io/channel-watch.c +0 -2
 
     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

Quoted 4 lines
        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

#150 lore raw

Re: [PATCH 49/51] io/channel-watch: Fix socket watch on Windows

Hi

Quoted 35 lines · Bin Meng
Quoted 33 lines · Marc-André Lureau

Hi

Quoted 29 lines · Bin Meng

From: Bin Meng <[email protected]>

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.

Quoted 9 lines
Quoted 5 lines
Quoted 1 line

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?

Quoted 24 lines
Quoted 3 lines
Quoted 3 lines

---
During the testing, I removed the following codes in

update_ioc_handlers():

Quoted 12 lines
Quoted 12 lines
    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.

Quoted 7 lines
Quoted 5 lines

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.

Quoted 9 lines

Sure, will add the above message into the commit in v2.

Quoted 2 lines

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?

Quoted 9 lines
Quoted 2 lines

I guess it's WSAEnumNetworkEvents clearing of the internal network event

records that is problematic.

Quoted 2 lines

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.

Quoted 8 lines

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.

Quoted 44 lines

[1]
https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsaeventselect

Quoted 31 lines
Quoted 18 lines


 io/channel-watch.c | 4 ----
 1 file changed, 4 deletions(-)
io/channel-watch.c +0 -2
index 89f3c8a88a..e34d86e810 100644
@@ -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;

io/channel-watch.c static gboolean · line 127

Quoted 10 lines
io/channel-watch.c +0 -2
 
     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

Quoted 4 lines
        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

Signature · 1 line
Marc-André Lureau
author
#151 lore raw

Re: [PATCH 49/51] io/channel-watch: Fix socket watch on Windows

Quoted 43 lines · Marc-André Lureau

Hi

Quoted 39 lines · Bin Meng
Quoted 36 lines · Marc-André Lureau

Hi

Quoted 30 lines · Bin Meng

From: Bin Meng <[email protected]>

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.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

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()?

Quoted 26 lines
Quoted 26 lines
Quoted 15 lines
Quoted 15 lines

---
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.

Quoted 7 lines
Quoted 5 lines

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.

Quoted 1 line
Quoted 8 lines
Quoted 4 lines
Quoted 1 line

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

Quoted 11 lines
Quoted 8 lines
Quoted 5 lines

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.

Quoted 13 lines
Quoted 8 lines

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.

Quoted 2 lines

[1] https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsaeventselect

Regards,
Bin

#152 lore raw

Re: [PATCH 49/51] io/channel-watch: Fix socket watch on Windows

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.

Quoted 37 lines
Quoted 26 lines
Quoted 26 lines
Quoted 15 lines
Quoted 15 lines

---
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.

Quoted 7 lines
Quoted 5 lines

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.

Quoted 1 line
Quoted 8 lines
Quoted 4 lines
Quoted 1 line

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:

Quoted 7 lines

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

From 1948fc273c4f4b78f90c8ca8fbc22647e30f431c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cl=C3=A9ment=20Chigot?= <[email protected]>
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(-)
io/channel-socket.c +1 -1
index b76dca9cc1..75500e5647 100644
@@ -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);
io/channel-watch.c +29 -28

97 lines not on this page · raw message

Signature · 1 line
2.25.1
author
#153 lore raw

Re: [PATCH 49/51] io/channel-watch: Fix socket watch on Windows

Hi Clément,

Quoted 9 lines · Clément Chigot

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.

Quoted 5 lines

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.

Quoted 15 lines

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?

Quoted 8 lines

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?

Quoted 47 lines

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.

Quoted 42 lines
Quoted 26 lines
Quoted 26 lines
Quoted 15 lines
Quoted 15 lines

---
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.

Quoted 7 lines
Quoted 5 lines

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.

Quoted 1 line
Quoted 8 lines
Quoted 4 lines
Quoted 1 line

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:

Quoted 8 lines
Quoted 2 lines

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

#154 lore raw

Re: [PATCH 49/51] io/channel-watch: Fix socket watch on Windows

Hi Bin,

Quoted 13 lines · Clément Chigot
Quoted 9 lines

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.

Quoted 7 lines

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.

Quoted 16 lines
Quoted 5 lines

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."

Quoted 2 lines

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."

Quoted 19 lines
Quoted 6 lines

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.

Quoted 8 lines

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.

Quoted 5 lines

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).

Quoted 12 lines

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?

Quoted 5 lines

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.

Quoted 6 lines
Quoted 3 lines

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.

Quoted 1 line

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.

author
#155 lore raw

Re: [PATCH 49/51] io/channel-watch: Fix socket watch on Windows

Hi Clément,

Quoted 19 lines · Clément Chigot

Hi Bin,

Quoted 16 lines · Clément Chigot
Quoted 9 lines

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

Quoted 8 lines
Quoted 4 lines

"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.

Quoted 6 lines

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.

Quoted 10 lines

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 ...

Quoted 6 lines

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 :(

Quoted 20 lines
Quoted 17 lines
Quoted 6 lines

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."

Quoted 2 lines

So events will be kept unsignaled after they are signaled, until the reenable routine is called. For example, recv() for the FD_READ event.

Quoted 7 lines

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.

Quoted 26 lines
Quoted 20 lines
Quoted 15 lines

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.

Quoted 5 lines

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().

Quoted 10 lines

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.

Quoted 19 lines
Quoted 12 lines

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?

Quoted 5 lines

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.

Quoted 6 lines
Quoted 3 lines

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.

Quoted 7 lines

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.

Quoted 1 line

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

#156 lore raw

Re: [PATCH 49/51] io/channel-watch: Fix socket watch on Windows

Quoted 19 lines
Quoted 19 lines
Quoted 18 lines

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?

Quoted 8 lines

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.

Quoted 7 lines
Quoted 7 lines

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.

Quoted 1 line

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

author
#157 lore raw

Re: [PATCH 49/51] io/channel-watch: Fix socket watch on Windows

Hi Clément,

Quoted 28 lines · Clément Chigot
Quoted 20 lines
Quoted 20 lines
Quoted 19 lines

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?

Quoted 8 lines

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.

Quoted 7 lines
Quoted 7 lines

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.

Quoted 1 line

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.

Quoted 8 lines

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.

Quoted 8 lines

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.

Quoted 5 lines

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.

io/channel-watch.c +0 -0
index 43d38494f7..f1e1650b81 100644
@@ -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