qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 00/54] tests/qtest: Enable running qtest on Windows
@ 2022-09-25 11:29 Bin Meng
  2022-09-25 11:29 ` [PATCH v3 01/54] tests/qtest: i440fx-test: Rewrite create_blob_file() to be portable Bin Meng
                   ` (53 more replies)
  0 siblings, 54 replies; 89+ messages in thread
From: Bin Meng @ 2022-09-25 11:29 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Alex Bennée, Alexander Bulekov,
	Andrew Jeffery, Ani Sinha, Bandan Das, Beraldo Leal, Bin Meng,
	Christian Schoenebeck, Coiby Xu, Cédric Le Goater,
	Daniel P. Berrangé,
	Darren Kenny, Dr. David Alan Gilbert, Eduardo Habkost, Fam Zheng,
	Gerd Hoffmann, Greg Kurz, Hanna Reitz, Igor Mammedov, Jason Wang,
	Joel Stanley, John Snow, Juan Quintela, Kevin Wolf,
	Konstantin Kostiuk, Laurent Vivier, Marcel Apfelbaum,
	Markus Armbruster, Michael Roth, Michael S. Tsirkin,
	Paolo Bonzini, Peter Maydell, Philippe Mathieu-Daudé,
	Qiuhao Li, Richard Henderson, Stefan Hajnoczi, Thomas Huth,
	Wainer dos Santos Moschetta, Willian Rampazzo, Yanan Wang,
	qemu-arm, qemu-block

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

Changes in v3:
- Remove unnecessary "error = NULL" statements
- Split patch "tests: Avoid using hardcoded /tmp in test cases" to separate patches
- Ensure g_autofree variable is initialized
- Use g_steal_pointer() in create_test_img()
- Add another case "boot-serial-test" to justify the change
- Add a usleep(1) in the busy wait loop
- Drop the host test
- Drop patch: "tests: Change to use g_mkdir()"
- Drop patch: "block: Unify the get_tmp_filename() implementation",
  and send it as a separate patch
- Drop patch: "chardev/char-file: Add FILE_SHARE_WRITE when openning the file for win32"

Changes in v2:
- new patch: "tests/qtest: i440fx-test: Rewrite create_blob_file() to be portable"
- Use g_autofree to declare the variable
- Change to use g_mkdir()
- Change to use g_mkdir()
- Change to use g_mkdir()
- Change to skip only part of the virtio-net-test cases that require
  socketpair() intead of disabling all of them
- Introduce a new variable qtests_filter and add that to the
  qtests_ARCH variables
- Add a comment in the code to explain why test_qmp_oob test case
  is skipped on win32
- Replace signal by the semaphore on posix too
- Use __declspec(selectany) for the common weak symbol on Windows
- Introduce qemu_send_full() and use it
- Move the enabling of building qtests on Windows to a separate
  patch to keep bisectablity
- Call socket_init() unconditionally
- Add a missing CloseHandle() call
- Change the place that sets IO redirection in the command line
- Drop ahci-test.c changes that are no longer needed
- Update commit message to include the use case why we should set
  FILE_SHARE_WRITE when opening the file for win32
- Change to a busy wait after migration is canceled
- new patch: "io/channel-watch: Drop the unnecessary cast"
- Change the timeout limit to 90 minutes
- new patch: Display meson test logs in the Windows CI
- new patch: "tests/qtest: Enable qtest build on Windows"
- Minor wording changes
- Drop patches that were already applied in the mainline
- Drop patch: "qga/commands-posix-ssh: Use g_mkdir_with_parents()"
- Drop patch: "tests: Skip iotests and qtest when '--without-default-devices'"
- Drop patch: "tests/qtest: Fix ERROR_SHARING_VIOLATION for win32"

Bin Meng (47):
  tests/qtest: i440fx-test: Rewrite create_blob_file() to be portable
  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/qtest: ahci-test: Avoid using hardcoded /tmp
  tests/qtest: aspeed_smc-test: Avoid using hardcoded /tmp
  tests/qtest: boot-serial-test: Avoid using hardcoded /tmp
  tests/qtest: cxl-test: Avoid using hardcoded /tmp
  tests/qtest: fdc-test: Avoid using hardcoded /tmp
  tests/qtest: generic_fuzz: Avoid using hardcoded /tmp
  tests/qtest: virtio_blk_fuzz: Avoid using hardcoded /tmp
  tests/qtest: hd-geo-test: Avoid using hardcoded /tmp
  tests/qtest: ide-test: Avoid using hardcoded /tmp
  tests/qtest: migration-test: Avoid using hardcoded /tmp
  tests/qtest: pflash-cfi02-test: Avoid using hardcoded /tmp
  tests/qtest: qmp-test: Avoid using hardcoded /tmp
  tests/qtest: vhost-user-blk-test: Avoid using hardcoded /tmp
  tests/qtest: vhost-user-test: Avoid using hardcoded /tmp
  tests/qtest: virtio-blk-test: Avoid using hardcoded /tmp
  tests/qtest: virtio-scsi-test: Avoid using hardcoded /tmp
  tests/qtest: libqtest: Avoid using hardcoded /tmp
  tests/unit: test-image-locking: Avoid using hardcoded /tmp
  tests/unit: test-qga: Avoid using hardcoded /tmp
  tests: vhost-user-bridge: Avoid using hardcoded /tmp
  block/vvfat: Unify the mkdir() call
  fsdev/virtfs-proxy-helper: Use g_mkdir()
  hw/usb: dev-mtp: Use g_mkdir()
  tests/qtest: Skip running virtio-net-test cases that require
    socketpair() for win32
  tests/qtest: Build test-filter-{mirror,redirector} cases for posix
    only
  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/qtest: Support libqtest to build and run on Windows
  tests/qtest: {ahci,ide}-test: Use relative path for temporary files
    for win32
  tests/qtest: bios-tables-test: Adapt the case for win32
  tests/qtest: migration-test: Disable IO redirection for win32
  tests/qtest: microbit-test: Fix socket access for win32
  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: Drop the unnecessary cast
  io/channel-watch: Fix socket watch on Windows
  tests/qtest: migration-test: Skip running some TLS cases for win32
  .gitlab-ci.d/windows.yml: Increase the timeout to 90 minutes
  .gitlab-ci.d/windows.yml: Display meson test logs
  tests/qtest: Enable qtest build on Windows
  docs/devel: testing: Document writing portable test cases

Xuzhou Cheng (7):
  accel/qtest: Implement a portable qtest accelerator
  tests/qtest: libqtest: Adapt global_qtest declaration for win32
  tests/qtest: Use send/recv for socket communication
  tests/qtest: 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 opening the file for
    win32
  tests/qtest: migration-test: Make sure QEMU process "to" exited after
    migration is canceled

 docs/devel/testing.rst                  |  30 +++++
 include/hw/core/cpu.h                   |   1 +
 include/qemu/sockets.h                  |   2 +
 tests/qtest/fuzz/generic_fuzz_configs.h |   4 +-
 tests/qtest/libqtest-single.h           |   4 +
 tests/qtest/libqtest.h                  |   8 ++
 accel/dummy-cpus.c                      |  15 +--
 block/vvfat.c                           |   9 +-
 chardev/char-file.c                     |   4 +-
 fsdev/virtfs-proxy-helper.c             |   3 +-
 hw/usb/dev-mtp.c                        |   4 +-
 io/channel-watch.c                      |  12 +-
 semihosting/arm-compat-semi.c           |   3 +-
 softmmu/cpus.c                          |  10 +-
 tcg/tcg.c                               |   3 +-
 tests/qtest/ahci-test.c                 |  36 ++++--
 tests/qtest/aspeed_smc-test.c           |   5 +-
 tests/qtest/bios-tables-test.c          |  12 +-
 tests/qtest/boot-serial-test.c          |   8 +-
 tests/qtest/cxl-test.c                  |  15 +--
 tests/qtest/fdc-test.c                  |   5 +-
 tests/qtest/fuzz/virtio_blk_fuzz.c      |   4 +-
 tests/qtest/hd-geo-test.c               |  25 ++--
 tests/qtest/i440fx-test.c               |  54 +++-----
 tests/qtest/ide-test.c                  |  30 ++++-
 tests/qtest/libqmp.c                    |   5 +-
 tests/qtest/libqtest.c                  | 157 ++++++++++++++++++++----
 tests/qtest/microbit-test.c             |  10 +-
 tests/qtest/migration-test.c            |  34 ++++-
 tests/qtest/pflash-cfi02-test.c         |   8 +-
 tests/qtest/qmp-test.c                  |  13 +-
 tests/qtest/vhost-user-blk-test.c       |   3 +-
 tests/qtest/vhost-user-test.c           |   8 +-
 tests/qtest/virtio-blk-test.c           |   4 +-
 tests/qtest/virtio-net-failover.c       |   9 +-
 tests/qtest/virtio-net-test.c           |  13 +-
 tests/qtest/virtio-scsi-test.c          |   4 +-
 tests/unit/test-image-locking.c         |   8 +-
 tests/unit/test-qga.c                   |   2 +-
 tests/vhost-user-bridge.c               |   3 +-
 util/osdep.c                            |  33 +++++
 util/qemu-sockets.c                     |   5 +-
 .gitlab-ci.d/windows.yml                |   8 +-
 accel/meson.build                       |   1 +
 accel/qtest/meson.build                 |   1 +
 tests/qtest/meson.build                 |  42 +++----
 46 files changed, 442 insertions(+), 235 deletions(-)

-- 
2.34.1



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

* [PATCH v3 01/54] tests/qtest: i440fx-test: Rewrite create_blob_file() to be portable
  2022-09-25 11:29 [PATCH v3 00/54] tests/qtest: Enable running qtest on Windows Bin Meng
@ 2022-09-25 11:29 ` Bin Meng
  2022-09-26 12:10   ` Thomas Huth
  2022-09-25 11:29 ` [PATCH v3 02/54] semihosting/arm-compat-semi: Avoid using hardcoded /tmp Bin Meng
                   ` (52 subsequent siblings)
  53 siblings, 1 reply; 89+ messages in thread
From: Bin Meng @ 2022-09-25 11:29 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Bin Meng, Laurent Vivier, Paolo Bonzini,
	Thomas Huth

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

Previously request_{bios, pflash} cases were skipped on win32, mainly
due to create_blob_file() calling mmap() which does not exist on win32.
This rewirtes create_blob_file() to be portable, so that we can enable
these cases on Windows.

Suggested-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Bin Meng <bin.meng@windriver.com>
---

Changes in v3:
- Remove unnecessary "error = NULL" statements

Changes in v2:
- new patch: "tests/qtest: i440fx-test: Rewrite create_blob_file() to be portable"

 tests/qtest/i440fx-test.c | 54 ++++++++++-----------------------------
 1 file changed, 14 insertions(+), 40 deletions(-)

diff --git a/tests/qtest/i440fx-test.c b/tests/qtest/i440fx-test.c
index 3890f1237c..795fd85343 100644
--- a/tests/qtest/i440fx-test.c
+++ b/tests/qtest/i440fx-test.c
@@ -278,56 +278,34 @@ 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))
 
-/* Create a blob file, and return its absolute pathname as a dynamically
+/*
+ * Create a blob file, and return its absolute pathname as a dynamically
  * allocated string.
  * The file is closed before the function returns.
- * In case of error, NULL is returned. The function prints the error message.
+ * In case of error, the function aborts and prints the error message.
  */
 static char *create_blob_file(void)
 {
-    int ret, fd;
+    int i, fd;
     char *pathname;
     GError *error = NULL;
+    g_autofree uint8_t *buf = g_malloc(BLOB_SIZE);
 
-    ret = -1;
     fd = g_file_open_tmp("blob_XXXXXX", &pathname, &error);
-    if (fd == -1) {
-        fprintf(stderr, "unable to create blob file: %s\n", error->message);
-        g_error_free(error);
-    } else {
-        if (ftruncate(fd, BLOB_SIZE) == -1) {
-            fprintf(stderr, "ftruncate(\"%s\", %zu): %s\n", pathname,
-                    BLOB_SIZE, strerror(errno));
-        } else {
-            void *buf;
-
-            buf = mmap(NULL, BLOB_SIZE, PROT_WRITE, MAP_SHARED, fd, 0);
-            if (buf == MAP_FAILED) {
-                fprintf(stderr, "mmap(\"%s\", %zu): %s\n", pathname, BLOB_SIZE,
-                        strerror(errno));
-            } else {
-                size_t i;
-
-                for (i = 0; i < BLOB_SIZE; ++i) {
-                    ((uint8_t *)buf)[i] = i;
-                }
-                munmap(buf, BLOB_SIZE);
-                ret = 0;
-            }
-        }
-        close(fd);
-        if (ret == -1) {
-            unlink(pathname);
-            g_free(pathname);
-        }
+    g_assert_no_error(error);
+    close(fd);
+
+    for (i = 0; i < BLOB_SIZE; i++) {
+        buf[i] = i;
     }
 
-    return ret == -1 ? NULL : pathname;
+    g_file_set_contents(pathname, (char *)buf, BLOB_SIZE, &error);
+    g_assert_no_error(error);
+
+    return pathname;
 }
 
 static void test_i440fx_firmware(FirmwareTestFixture *fixture,
@@ -398,8 +376,6 @@ static void request_pflash(FirmwareTestFixture *fixture,
     fixture->is_bios = false;
 }
 
-#endif /* _WIN32 */
-
 int main(int argc, char **argv)
 {
     TestData data;
@@ -410,10 +386,8 @@ int main(int argc, char **argv)
 
     qtest_add_data_func("i440fx/defaults", &data, test_i440fx_defaults);
     qtest_add_data_func("i440fx/pam", &data, test_i440fx_pam);
-#ifndef _WIN32
     add_firmware_test("i440fx/firmware/bios", request_bios);
     add_firmware_test("i440fx/firmware/pflash", request_pflash);
-#endif
 
     return g_test_run();
 }
-- 
2.34.1



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

* [PATCH v3 02/54] semihosting/arm-compat-semi: Avoid using hardcoded /tmp
  2022-09-25 11:29 [PATCH v3 00/54] tests/qtest: Enable running qtest on Windows Bin Meng
  2022-09-25 11:29 ` [PATCH v3 01/54] tests/qtest: i440fx-test: Rewrite create_blob_file() to be portable Bin Meng
@ 2022-09-25 11:29 ` Bin Meng
  2022-09-25 11:29 ` [PATCH v3 03/54] tcg: " Bin Meng
                   ` (51 subsequent siblings)
  53 siblings, 0 replies; 89+ messages in thread
From: Bin Meng @ 2022-09-25 11:29 UTC (permalink / raw)
  To: qemu-devel; +Cc: Marc-André Lureau, Bin Meng, Alex Bennée

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

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

Signed-off-by: Bin Meng <bin.meng@windriver.com>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
---

(no changes since v1)

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

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



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

* [PATCH v3 03/54] tcg: Avoid using hardcoded /tmp
  2022-09-25 11:29 [PATCH v3 00/54] tests/qtest: Enable running qtest on Windows Bin Meng
  2022-09-25 11:29 ` [PATCH v3 01/54] tests/qtest: i440fx-test: Rewrite create_blob_file() to be portable Bin Meng
  2022-09-25 11:29 ` [PATCH v3 02/54] semihosting/arm-compat-semi: Avoid using hardcoded /tmp Bin Meng
@ 2022-09-25 11:29 ` Bin Meng
  2022-09-25 11:29 ` [PATCH v3 04/54] util/qemu-sockets: Use g_get_tmp_dir() to get the directory for temporary files Bin Meng
                   ` (50 subsequent siblings)
  53 siblings, 0 replies; 89+ messages in thread
From: Bin Meng @ 2022-09-25 11:29 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Bin Meng, Alex Bennée, Richard Henderson

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

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

Signed-off-by: Bin Meng <bin.meng@windriver.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
---

(no changes since v2)

Changes in v2:
- Use g_autofree to declare the variable

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

diff --git a/tcg/tcg.c b/tcg/tcg.c
index 0f9cfe96f2..8847053176 100644
--- a/tcg/tcg.c
+++ b/tcg/tcg.c
@@ -4729,7 +4729,8 @@ 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");
+        g_autofree 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.  */
-- 
2.34.1



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

* [PATCH v3 04/54] util/qemu-sockets: Use g_get_tmp_dir() to get the directory for temporary files
  2022-09-25 11:29 [PATCH v3 00/54] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (2 preceding siblings ...)
  2022-09-25 11:29 ` [PATCH v3 03/54] tcg: " Bin Meng
@ 2022-09-25 11:29 ` Bin Meng
  2022-09-25 11:29 ` [PATCH v3 05/54] tests/qtest: ahci-test: Avoid using hardcoded /tmp Bin Meng
                   ` (49 subsequent siblings)
  53 siblings, 0 replies; 89+ messages in thread
From: Bin Meng @ 2022-09-25 11:29 UTC (permalink / raw)
  To: qemu-devel; +Cc: Marc-André Lureau, Bin Meng, Daniel P. Berrangé

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

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

Signed-off-by: Bin Meng <bin.meng@windriver.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---

(no changes since v1)

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

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



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

* [PATCH v3 05/54] tests/qtest: ahci-test: Avoid using hardcoded /tmp
  2022-09-25 11:29 [PATCH v3 00/54] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (3 preceding siblings ...)
  2022-09-25 11:29 ` [PATCH v3 04/54] util/qemu-sockets: Use g_get_tmp_dir() to get the directory for temporary files Bin Meng
@ 2022-09-25 11:29 ` Bin Meng
  2022-09-26 12:17   ` Thomas Huth
  2022-09-25 11:29 ` [PATCH v3 06/54] tests/qtest: aspeed_smc-test: " Bin Meng
                   ` (48 subsequent siblings)
  53 siblings, 1 reply; 89+ messages in thread
From: Bin Meng @ 2022-09-25 11:29 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Bin Meng, John Snow, Laurent Vivier,
	Paolo Bonzini, Thomas Huth, qemu-block

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

This case was written to use hardcoded /tmp directory for temporary
files. Update to use g_file_open_tmp() for a portable implementation.

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

Changes in v3:
- Split to a separate patch
- Ensure g_autofree variable is initialized

 tests/qtest/ahci-test.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/tests/qtest/ahci-test.c b/tests/qtest/ahci-test.c
index f1e510b0ac..1d5929d8c3 100644
--- a/tests/qtest/ahci-test.c
+++ b/tests/qtest/ahci-test.c
@@ -44,9 +44,9 @@
 #define TEST_IMAGE_SIZE_MB_SMALL 64
 
 /*** Globals ***/
-static char tmp_path[] = "/tmp/qtest.XXXXXX";
-static char debug_path[] = "/tmp/qtest-blkdebug.XXXXXX";
-static char mig_socket[] = "/tmp/qtest-migration.XXXXXX";
+static char *tmp_path;
+static char *debug_path;
+static char *mig_socket;
 static bool ahci_pedantic;
 static const char *imgfmt;
 static unsigned test_image_size_mb;
@@ -1437,10 +1437,10 @@ 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";
+    g_autofree char *cdrom_path = NULL;
     unsigned char *patt;
     ssize_t ret;
-    int fd = mkstemp(cdrom_path);
+    int fd = g_file_open_tmp("qtest.iso.XXXXXX", &cdrom_path, NULL);
 
     g_assert(fd != -1);
     g_assert(buf);
@@ -1872,7 +1872,7 @@ int main(int argc, char **argv)
     }
 
     /* Create a temporary image */
-    fd = mkstemp(tmp_path);
+    fd = g_file_open_tmp("qtest.XXXXXX", &tmp_path, NULL);
     g_assert(fd >= 0);
     if (have_qemu_img()) {
         imgfmt = "qcow2";
@@ -1889,12 +1889,12 @@ int main(int argc, char **argv)
     close(fd);
 
     /* Create temporary blkdebug instructions */
-    fd = mkstemp(debug_path);
+    fd = g_file_open_tmp("qtest-blkdebug.XXXXXX", &debug_path, NULL);
     g_assert(fd >= 0);
     close(fd);
 
     /* Reserve a hollow file to use as a socket for migration tests */
-    fd = mkstemp(mig_socket);
+    fd = g_file_open_tmp("qtest-migration.XXXXXX", &mig_socket, NULL);
     g_assert(fd >= 0);
     close(fd);
 
@@ -1947,8 +1947,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;
 }
-- 
2.34.1



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

* [PATCH v3 06/54] tests/qtest: aspeed_smc-test: Avoid using hardcoded /tmp
  2022-09-25 11:29 [PATCH v3 00/54] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (4 preceding siblings ...)
  2022-09-25 11:29 ` [PATCH v3 05/54] tests/qtest: ahci-test: Avoid using hardcoded /tmp Bin Meng
@ 2022-09-25 11:29 ` Bin Meng
  2022-09-25 16:20   ` Cédric Le Goater
  2022-09-26 12:18   ` Thomas Huth
  2022-09-25 11:29 ` [PATCH v3 07/54] tests/qtest: boot-serial-test: " Bin Meng
                   ` (47 subsequent siblings)
  53 siblings, 2 replies; 89+ messages in thread
From: Bin Meng @ 2022-09-25 11:29 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Bin Meng, Andrew Jeffery,
	Cédric Le Goater, Joel Stanley, Laurent Vivier,
	Paolo Bonzini, Peter Maydell, Thomas Huth, qemu-arm

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

This case was written to use hardcoded /tmp directory for temporary
files. Update to use g_file_open_tmp() for a portable implementation.

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

Changes in v3:
- Split to a separate patch
- Ensure g_autofree variable is initialized

 tests/qtest/aspeed_smc-test.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/tests/qtest/aspeed_smc-test.c b/tests/qtest/aspeed_smc-test.c
index 05ce941566..c713a3700b 100644
--- a/tests/qtest/aspeed_smc-test.c
+++ b/tests/qtest/aspeed_smc-test.c
@@ -608,16 +608,15 @@ static void test_write_block_protect_bottom_bit(void)
     flash_reset();
 }
 
-static char tmp_path[] = "/tmp/qtest.m25p80.XXXXXX";
-
 int main(int argc, char **argv)
 {
+    g_autofree char *tmp_path = NULL;
     int ret;
     int fd;
 
     g_test_init(&argc, &argv, NULL);
 
-    fd = mkstemp(tmp_path);
+    fd = g_file_open_tmp("qtest.m25p80.XXXXXX", &tmp_path, NULL);
     g_assert(fd >= 0);
     ret = ftruncate(fd, FLASH_SIZE);
     g_assert(ret == 0);
-- 
2.34.1



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

* [PATCH v3 07/54] tests/qtest: boot-serial-test: Avoid using hardcoded /tmp
  2022-09-25 11:29 [PATCH v3 00/54] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (5 preceding siblings ...)
  2022-09-25 11:29 ` [PATCH v3 06/54] tests/qtest: aspeed_smc-test: " Bin Meng
@ 2022-09-25 11:29 ` Bin Meng
  2022-09-26 12:22   ` Thomas Huth
  2022-09-25 11:29 ` [PATCH v3 08/54] tests/qtest: cxl-test: " Bin Meng
                   ` (46 subsequent siblings)
  53 siblings, 1 reply; 89+ messages in thread
From: Bin Meng @ 2022-09-25 11:29 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Bin Meng, Laurent Vivier, Paolo Bonzini,
	Thomas Huth

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

This case was written to use hardcoded /tmp directory for temporary
files. Update to use g_file_open_tmp() for a portable implementation.

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

Changes in v3:
- Split to a separate patch
- Ensure g_autofree variable is initialized

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

diff --git a/tests/qtest/boot-serial-test.c b/tests/qtest/boot-serial-test.c
index 2f99d71cab..72310ba30e 100644
--- a/tests/qtest/boot-serial-test.c
+++ b/tests/qtest/boot-serial-test.c
@@ -224,14 +224,14 @@ 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";
+    g_autofree char *serialtmp = NULL;
+    g_autofree char *codetmp = NULL;
     const char *codeparam = "";
     const uint8_t *code = NULL;
     QTestState *qts;
     int ser_fd;
 
-    ser_fd = mkstemp(serialtmp);
+    ser_fd = g_file_open_tmp("qtest-boot-serial-sXXXXXX", &serialtmp, NULL);
     g_assert(ser_fd != -1);
 
     if (test->kernel) {
@@ -246,7 +246,7 @@ static void test_machine(const void *data)
         ssize_t wlen;
         int code_fd;
 
-        code_fd = mkstemp(codetmp);
+        code_fd = g_file_open_tmp("qtest-boot-serial-cXXXXXX", &codetmp, NULL);
         g_assert(code_fd != -1);
         wlen = write(code_fd, code, test->codesize);
         g_assert(wlen == test->codesize);
-- 
2.34.1



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

* [PATCH v3 08/54] tests/qtest: cxl-test: Avoid using hardcoded /tmp
  2022-09-25 11:29 [PATCH v3 00/54] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (6 preceding siblings ...)
  2022-09-25 11:29 ` [PATCH v3 07/54] tests/qtest: boot-serial-test: " Bin Meng
@ 2022-09-25 11:29 ` Bin Meng
  2022-09-26 13:07   ` Marc-André Lureau
  2022-09-25 11:29 ` [PATCH v3 09/54] tests/qtest: fdc-test: " Bin Meng
                   ` (45 subsequent siblings)
  53 siblings, 1 reply; 89+ messages in thread
From: Bin Meng @ 2022-09-25 11:29 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Bin Meng, Laurent Vivier, Paolo Bonzini,
	Thomas Huth

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

This case was written to use hardcoded /tmp directory for temporary
files. Update to use g_dir_make_tmp() for a portable implementation.

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

Changes in v3:
- Split to a separate patch
- Ensure g_autofree variable is initialized

 tests/qtest/cxl-test.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/tests/qtest/cxl-test.c b/tests/qtest/cxl-test.c
index 2e14da7dee..cbe0fb549b 100644
--- a/tests/qtest/cxl-test.c
+++ b/tests/qtest/cxl-test.c
@@ -93,10 +93,9 @@ 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";
-    const char *tmpfs;
+    g_autofree const char *tmpfs = NULL;
 
-    tmpfs = g_mkdtemp(template);
+    tmpfs = g_dir_make_tmp("cxl-test-XXXXXX", NULL);
 
     g_string_printf(cmdline, QEMU_PXB_CMD QEMU_RP QEMU_T3D, tmpfs, tmpfs);
 
@@ -107,10 +106,9 @@ 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";
-    const char *tmpfs;
+    g_autofree const char *tmpfs = NULL;
 
-    tmpfs = g_mkdtemp(template);
+    tmpfs = g_dir_make_tmp("cxl-test-XXXXXX", NULL);
 
     g_string_printf(cmdline, QEMU_PXB_CMD QEMU_2RP QEMU_2T3D,
                     tmpfs, tmpfs, tmpfs, tmpfs);
@@ -122,10 +120,9 @@ 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";
-    const char *tmpfs;
+    g_autofree const char *tmpfs = NULL;
 
-    tmpfs = g_mkdtemp(template);
+    tmpfs = g_dir_make_tmp("cxl-test-XXXXXX", NULL);
 
     g_string_printf(cmdline, QEMU_2PXB_CMD QEMU_4RP QEMU_4T3D,
                     tmpfs, tmpfs, tmpfs, tmpfs, tmpfs, tmpfs,
-- 
2.34.1



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

* [PATCH v3 09/54] tests/qtest: fdc-test: Avoid using hardcoded /tmp
  2022-09-25 11:29 [PATCH v3 00/54] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (7 preceding siblings ...)
  2022-09-25 11:29 ` [PATCH v3 08/54] tests/qtest: cxl-test: " Bin Meng
@ 2022-09-25 11:29 ` Bin Meng
  2022-09-26 13:08   ` Marc-André Lureau
  2022-09-25 11:29 ` [PATCH v3 10/54] tests/qtest: generic_fuzz: " Bin Meng
                   ` (44 subsequent siblings)
  53 siblings, 1 reply; 89+ messages in thread
From: Bin Meng @ 2022-09-25 11:29 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Bin Meng, John Snow, Laurent Vivier,
	Paolo Bonzini, Thomas Huth, qemu-block

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

This case was written to use hardcoded /tmp directory for temporary
files. Update to use g_file_open_tmp() for a portable implementation.

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

Changes in v3:
- Split to a separate patch

 tests/qtest/fdc-test.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/tests/qtest/fdc-test.c b/tests/qtest/fdc-test.c
index 52ade90a7d..1f9b99ad6d 100644
--- a/tests/qtest/fdc-test.c
+++ b/tests/qtest/fdc-test.c
@@ -68,7 +68,7 @@ enum {
     DSKCHG  = 0x80,
 };
 
-static char test_image[] = "/tmp/qtest.XXXXXX";
+static char *test_image;
 
 #define assert_bit_set(data, mask) g_assert_cmphex((data) & (mask), ==, (mask))
 #define assert_bit_clear(data, mask) g_assert_cmphex((data) & (mask), ==, 0)
@@ -608,7 +608,7 @@ int main(int argc, char **argv)
     int ret;
 
     /* Create a temporary raw image */
-    fd = mkstemp(test_image);
+    fd = g_file_open_tmp("qtest.XXXXXX", &test_image, NULL);
     g_assert(fd >= 0);
     ret = ftruncate(fd, TEST_IMAGE_SIZE);
     g_assert(ret == 0);
@@ -640,6 +640,7 @@ int main(int argc, char **argv)
     /* Cleanup */
     qtest_end();
     unlink(test_image);
+    g_free(test_image);
 
     return ret;
 }
-- 
2.34.1



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

* [PATCH v3 10/54] tests/qtest: generic_fuzz: Avoid using hardcoded /tmp
  2022-09-25 11:29 [PATCH v3 00/54] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (8 preceding siblings ...)
  2022-09-25 11:29 ` [PATCH v3 09/54] tests/qtest: fdc-test: " Bin Meng
@ 2022-09-25 11:29 ` Bin Meng
  2022-09-26 13:09   ` Marc-André Lureau
  2022-09-25 11:29 ` [PATCH v3 11/54] tests/qtest: virtio_blk_fuzz: " Bin Meng
                   ` (43 subsequent siblings)
  53 siblings, 1 reply; 89+ messages in thread
From: Bin Meng @ 2022-09-25 11:29 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Bin Meng, Alexander Bulekov, Bandan Das,
	Darren Kenny, Laurent Vivier, Paolo Bonzini, Qiuhao Li,
	Stefan Hajnoczi, Thomas Huth

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

This case was written to use hardcoded /tmp directory for temporary
files. Update to use g_dir_make_tmp() for a portable implementation.

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

Changes in v3:
- Split to a separate patch

 tests/qtest/fuzz/generic_fuzz_configs.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tests/qtest/fuzz/generic_fuzz_configs.h b/tests/qtest/fuzz/generic_fuzz_configs.h
index 0775e6702b..a825b78c14 100644
--- a/tests/qtest/fuzz/generic_fuzz_configs.h
+++ b/tests/qtest/fuzz/generic_fuzz_configs.h
@@ -20,8 +20,8 @@ typedef struct generic_fuzz_config {
 } generic_fuzz_config;
 
 static inline gchar *generic_fuzzer_virtio_9p_args(void){
-    char tmpdir[] = "/tmp/qemu-fuzz.XXXXXX";
-    g_assert_nonnull(g_mkdtemp(tmpdir));
+    g_autofree char *tmpdir = g_dir_make_tmp("qemu-fuzz.XXXXXX", NULL);
+    g_assert_nonnull(tmpdir);
 
     return g_strdup_printf("-machine q35 -nodefaults "
     "-device virtio-9p,fsdev=hshare,mount_tag=hshare "
-- 
2.34.1



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

* [PATCH v3 11/54] tests/qtest: virtio_blk_fuzz: Avoid using hardcoded /tmp
  2022-09-25 11:29 [PATCH v3 00/54] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (9 preceding siblings ...)
  2022-09-25 11:29 ` [PATCH v3 10/54] tests/qtest: generic_fuzz: " Bin Meng
@ 2022-09-25 11:29 ` Bin Meng
  2022-09-26 13:11   ` Marc-André Lureau
  2022-09-25 11:29 ` [PATCH v3 12/54] tests/qtest: hd-geo-test: " Bin Meng
                   ` (42 subsequent siblings)
  53 siblings, 1 reply; 89+ messages in thread
From: Bin Meng @ 2022-09-25 11:29 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Bin Meng, Alexander Bulekov, Bandan Das,
	Darren Kenny, Laurent Vivier, Paolo Bonzini, Qiuhao Li,
	Stefan Hajnoczi, Thomas Huth

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

This case was written to use hardcoded /tmp directory for temporary
files. Update to use g_file_open_tmp() for a portable implementation.

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

Changes in v3:
- Split to a separate patch

 tests/qtest/fuzz/virtio_blk_fuzz.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tests/qtest/fuzz/virtio_blk_fuzz.c b/tests/qtest/fuzz/virtio_blk_fuzz.c
index 236d078cc8..a9fb9ecf6c 100644
--- a/tests/qtest/fuzz/virtio_blk_fuzz.c
+++ b/tests/qtest/fuzz/virtio_blk_fuzz.c
@@ -181,10 +181,10 @@ 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;
 
     /* Create a temporary raw image */
-    fd = mkstemp(t_path);
+    fd = g_file_open_tmp("qtest.XXXXXX", &t_path, NULL);
     g_assert_cmpint(fd, >=, 0);
     ret = ftruncate(fd, TEST_IMAGE_SIZE);
     g_assert_cmpint(ret, ==, 0);
-- 
2.34.1



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

* [PATCH v3 12/54] tests/qtest: hd-geo-test: Avoid using hardcoded /tmp
  2022-09-25 11:29 [PATCH v3 00/54] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (10 preceding siblings ...)
  2022-09-25 11:29 ` [PATCH v3 11/54] tests/qtest: virtio_blk_fuzz: " Bin Meng
@ 2022-09-25 11:29 ` Bin Meng
  2022-09-26 13:11   ` Marc-André Lureau
  2022-09-26 15:38   ` Thomas Huth
  2022-09-25 11:29 ` [PATCH v3 13/54] tests/qtest: ide-test: " Bin Meng
                   ` (41 subsequent siblings)
  53 siblings, 2 replies; 89+ messages in thread
From: Bin Meng @ 2022-09-25 11:29 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Bin Meng, Laurent Vivier, Paolo Bonzini,
	Thomas Huth

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

This case was written to use hardcoded /tmp directory for temporary
files. Update to use g_file_open_tmp() for a portable implementation.

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

Changes in v3:
- Split to a separate patch
- Ensure g_autofree variable is initialized
- Use g_steal_pointer() in create_test_img()

 tests/qtest/hd-geo-test.c | 25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)

diff --git a/tests/qtest/hd-geo-test.c b/tests/qtest/hd-geo-test.c
index 413cf964c0..455bc5db5c 100644
--- a/tests/qtest/hd-geo-test.c
+++ b/tests/qtest/hd-geo-test.c
@@ -27,20 +27,19 @@
 
 static char *create_test_img(int secs)
 {
-    char *template = strdup("/tmp/qtest.XXXXXX");
+    g_autofree char *template = NULL;
     int fd, ret;
 
-    fd = mkstemp(template);
+    fd = g_file_open_tmp("qtest.XXXXXX", &template, NULL);
     g_assert(fd >= 0);
     ret = ftruncate(fd, (off_t)secs * 512);
     close(fd);
 
     if (ret) {
-        free(template);
         template = NULL;
     }
 
-    return template;
+    return g_steal_pointer(&template);
 }
 
 typedef struct {
@@ -422,9 +421,8 @@ 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";
-    char *raw_path = strdup(template);
-    char *qcow2_path = strdup(template);
+    g_autofree char *raw_path = NULL;
+    char *qcow2_path;
     char cmd[100 + 2 * PATH_MAX];
     uint8_t buf[512] = {};
     int i, ret, fd, offset;
@@ -468,7 +466,7 @@ static char *create_qcow2_with_mbr(MBRpartitions mbr, uint64_t sectors)
         offset += 0x10;
     }
 
-    fd = mkstemp(raw_path);
+    fd = g_file_open_tmp("qtest.XXXXXX", &raw_path, NULL);
     g_assert(fd >= 0);
     close(fd);
 
@@ -478,7 +476,7 @@ static char *create_qcow2_with_mbr(MBRpartitions mbr, uint64_t sectors)
     g_assert(ret == sizeof(buf));
     close(fd);
 
-    fd = mkstemp(qcow2_path);
+    fd = g_file_open_tmp("qtest.XXXXXX", &qcow2_path, NULL);
     g_assert(fd >= 0);
     close(fd);
 
@@ -506,7 +504,6 @@ static char *create_qcow2_with_mbr(MBRpartitions mbr, uint64_t sectors)
     free(qemu_img_abs_path);
 
     unlink(raw_path);
-    free(raw_path);
 
     return qcow2_path;
 }
@@ -714,7 +711,7 @@ static void test_override(TestArgs *args, CHSResult expected[])
 
     for (i = 0; i < args->n_drives; i++) {
         unlink(args->drives[i]);
-        free(args->drives[i]);
+        g_free(args->drives[i]);
     }
     g_free(args->drives);
     g_strfreev(args->argv);
@@ -867,7 +864,7 @@ static void test_override_scsi_hot_unplug(void)
 
     for (i = 0; i < args->n_drives; i++) {
         unlink(args->drives[i]);
-        free(args->drives[i]);
+        g_free(args->drives[i]);
     }
     g_free(args->drives);
     g_strfreev(args->argv);
@@ -927,7 +924,7 @@ static void test_override_virtio_hot_unplug(void)
 
     for (i = 0; i < args->n_drives; i++) {
         unlink(args->drives[i]);
-        free(args->drives[i]);
+        g_free(args->drives[i]);
     }
     g_free(args->drives);
     g_strfreev(args->argv);
@@ -987,7 +984,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]);
         }
     }
 
-- 
2.34.1



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

* [PATCH v3 13/54] tests/qtest: ide-test: Avoid using hardcoded /tmp
  2022-09-25 11:29 [PATCH v3 00/54] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (11 preceding siblings ...)
  2022-09-25 11:29 ` [PATCH v3 12/54] tests/qtest: hd-geo-test: " Bin Meng
@ 2022-09-25 11:29 ` Bin Meng
  2022-09-26 13:12   ` Marc-André Lureau
  2022-09-25 11:29 ` [PATCH v3 14/54] tests/qtest: migration-test: " Bin Meng
                   ` (40 subsequent siblings)
  53 siblings, 1 reply; 89+ messages in thread
From: Bin Meng @ 2022-09-25 11:29 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Bin Meng, John Snow, Laurent Vivier,
	Paolo Bonzini, Thomas Huth, qemu-block

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

This case was written to use hardcoded /tmp directory for temporary
files. Update to use g_file_open_tmp() for a portable implementation.

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

Changes in v3:
- Split to a separate patch

 tests/qtest/ide-test.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/tests/qtest/ide-test.c b/tests/qtest/ide-test.c
index 5bcb75a7e5..25302be6dc 100644
--- a/tests/qtest/ide-test.c
+++ b/tests/qtest/ide-test.c
@@ -121,8 +121,8 @@ enum {
 static QPCIBus *pcibus = NULL;
 static QGuestAllocator guest_malloc;
 
-static char tmp_path[] = "/tmp/qtest.XXXXXX";
-static char debug_path[] = "/tmp/qtest-blkdebug.XXXXXX";
+static char *tmp_path;
+static char *debug_path;
 
 static QTestState *ide_test_start(const char *cmdline_fmt, ...)
 {
@@ -1015,12 +1015,12 @@ int main(int argc, char **argv)
     int ret;
 
     /* Create temporary blkdebug instructions */
-    fd = mkstemp(debug_path);
+    fd = g_file_open_tmp("qtest-blkdebug.XXXXXX", &debug_path, NULL);
     g_assert(fd >= 0);
     close(fd);
 
     /* Create a temporary raw image */
-    fd = mkstemp(tmp_path);
+    fd = g_file_open_tmp("qtest.XXXXXX", &tmp_path, NULL);
     g_assert(fd >= 0);
     ret = ftruncate(fd, TEST_IMAGE_SIZE);
     g_assert(ret == 0);
@@ -1049,7 +1049,9 @@ int main(int argc, char **argv)
 
     /* Cleanup */
     unlink(tmp_path);
+    g_free(tmp_path);
     unlink(debug_path);
+    g_free(debug_path);
 
     return ret;
 }
-- 
2.34.1



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

* [PATCH v3 14/54] tests/qtest: migration-test: Avoid using hardcoded /tmp
  2022-09-25 11:29 [PATCH v3 00/54] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (12 preceding siblings ...)
  2022-09-25 11:29 ` [PATCH v3 13/54] tests/qtest: ide-test: " Bin Meng
@ 2022-09-25 11:29 ` Bin Meng
  2022-09-26 13:15   ` Marc-André Lureau
  2022-09-25 11:29 ` [PATCH v3 15/54] tests/qtest: pflash-cfi02-test: " Bin Meng
                   ` (39 subsequent siblings)
  53 siblings, 1 reply; 89+ messages in thread
From: Bin Meng @ 2022-09-25 11:29 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Bin Meng, Dr. David Alan Gilbert,
	Juan Quintela, Laurent Vivier, Paolo Bonzini, Thomas Huth

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

This case was written to use hardcoded /tmp directory for temporary
files. Update to use g_dir_make_tmp() for a portable implementation.

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

Changes in v3:
- Split to a separate patch

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

diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index 4728d528bb..029c4f3a6a 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -2434,7 +2434,6 @@ static bool kvm_dirty_ring_supported(void)
 
 int main(int argc, char **argv)
 {
-    char template[] = "/tmp/migration-test-XXXXXX";
     const bool has_kvm = qtest_has_accel("kvm");
     const bool has_uffd = ufd_version_check();
     const char *arch = qtest_get_arch();
@@ -2462,9 +2461,10 @@ int main(int argc, char **argv)
         return g_test_run();
     }
 
-    tmpfs = g_mkdtemp(template);
+    tmpfs = g_dir_make_tmp("migration-test-XXXXXX", NULL);
     if (!tmpfs) {
-        g_test_message("g_mkdtemp on path (%s): %s", template, strerror(errno));
+        g_test_message("g_dir_make_tmp on path (%s): %s", tmpfs,
+                       strerror(errno));
     }
     g_assert(tmpfs);
 
@@ -2589,6 +2589,7 @@ int main(int argc, char **argv)
         g_test_message("unable to rmdir: path (%s): %s",
                        tmpfs, strerror(errno));
     }
+    g_free((gpointer)tmpfs);
 
     return ret;
 }
-- 
2.34.1



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

* [PATCH v3 15/54] tests/qtest: pflash-cfi02-test: Avoid using hardcoded /tmp
  2022-09-25 11:29 [PATCH v3 00/54] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (13 preceding siblings ...)
  2022-09-25 11:29 ` [PATCH v3 14/54] tests/qtest: migration-test: " Bin Meng
@ 2022-09-25 11:29 ` Bin Meng
  2022-09-26 13:18   ` Marc-André Lureau
  2022-09-25 11:29 ` [PATCH v3 16/54] tests/qtest: qmp-test: " Bin Meng
                   ` (38 subsequent siblings)
  53 siblings, 1 reply; 89+ messages in thread
From: Bin Meng @ 2022-09-25 11:29 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Bin Meng, Laurent Vivier, Paolo Bonzini,
	Thomas Huth

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

This case was written to use hardcoded /tmp directory for temporary
files. Update to use g_file_open_tmp() for a portable implementation.

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

Changes in v3:
- Split to a separate patch

 tests/qtest/pflash-cfi02-test.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/tests/qtest/pflash-cfi02-test.c b/tests/qtest/pflash-cfi02-test.c
index 7fce614b64..55890b7d95 100644
--- a/tests/qtest/pflash-cfi02-test.c
+++ b/tests/qtest/pflash-cfi02-test.c
@@ -56,7 +56,7 @@ typedef struct {
     QTestState *qtest;
 } FlashConfig;
 
-static char image_path[] = "/tmp/qtest.XXXXXX";
+static char *image_path;
 
 /*
  * The pflash implementation allows some parameters to be unspecified. We want
@@ -608,6 +608,7 @@ static void test_cfi_in_autoselect(const void *opaque)
 static void cleanup(void *opaque)
 {
     unlink(image_path);
+    g_free(image_path);
 }
 
 /*
@@ -635,16 +636,17 @@ static const FlashConfig configuration[] = {
 
 int main(int argc, char **argv)
 {
-    int fd = mkstemp(image_path);
+    int fd = g_file_open_tmp("qtest.XXXXXX", &image_path, NULL);
     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);
-- 
2.34.1



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

* [PATCH v3 16/54] tests/qtest: qmp-test: Avoid using hardcoded /tmp
  2022-09-25 11:29 [PATCH v3 00/54] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (14 preceding siblings ...)
  2022-09-25 11:29 ` [PATCH v3 15/54] tests/qtest: pflash-cfi02-test: " Bin Meng
@ 2022-09-25 11:29 ` Bin Meng
  2022-09-26 13:19   ` Marc-André Lureau
  2022-09-25 11:29 ` [PATCH v3 17/54] tests/qtest: vhost-user-blk-test: " Bin Meng
                   ` (37 subsequent siblings)
  53 siblings, 1 reply; 89+ messages in thread
From: Bin Meng @ 2022-09-25 11:29 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Bin Meng, Laurent Vivier,
	Markus Armbruster, Paolo Bonzini, Thomas Huth

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

This case was written to use hardcoded /tmp directory for temporary
files. Update to use g_dir_make_tmp() for a portable implementation.

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

Changes in v3:
- Split to a separate patch

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

diff --git a/tests/qtest/qmp-test.c b/tests/qtest/qmp-test.c
index bf7304c7dc..0fa00c12dc 100644
--- a/tests/qtest/qmp-test.c
+++ b/tests/qtest/qmp-test.c
@@ -161,12 +161,13 @@ 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)
 {
-    if (!g_mkdtemp(tmpdir)) {
+    tmpdir = g_dir_make_tmp("qmp-test-XXXXXX", NULL);
+    if (!tmpdir) {
         g_error("g_mkdtemp: %s", strerror(errno));
     }
     fifo_name = g_strdup_printf("%s/fifo", tmpdir);
@@ -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)
-- 
2.34.1



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

* [PATCH v3 17/54] tests/qtest: vhost-user-blk-test: Avoid using hardcoded /tmp
  2022-09-25 11:29 [PATCH v3 00/54] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (15 preceding siblings ...)
  2022-09-25 11:29 ` [PATCH v3 16/54] tests/qtest: qmp-test: " Bin Meng
@ 2022-09-25 11:29 ` Bin Meng
  2022-09-26 13:20   ` Marc-André Lureau
  2022-09-25 11:29 ` [PATCH v3 18/54] tests/qtest: vhost-user-test: " Bin Meng
                   ` (36 subsequent siblings)
  53 siblings, 1 reply; 89+ messages in thread
From: Bin Meng @ 2022-09-25 11:29 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Bin Meng, Coiby Xu, Laurent Vivier,
	Paolo Bonzini, Thomas Huth

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

This case was written to use hardcoded /tmp directory for temporary
files. Update to use g_get_tmp_dir() for a portable implementation.

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

Changes in v3:
- Split to a separate patch

 tests/qtest/vhost-user-blk-test.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tests/qtest/vhost-user-blk-test.c b/tests/qtest/vhost-user-blk-test.c
index a81c2a2715..07a4c2d500 100644
--- a/tests/qtest/vhost-user-blk-test.c
+++ b/tests/qtest/vhost-user-blk-test.c
@@ -841,7 +841,8 @@ static char *create_listen_socket(int *fd)
     char *path;
 
     /* No race because our pid makes the path unique */
-    path = g_strdup_printf("/tmp/qtest-%d-sock.XXXXXX", getpid());
+    path = g_strdup_printf("%s/qtest-%d-sock.XXXXXX",
+                           g_get_tmp_dir(), getpid());
     tmp_fd = mkstemp(path);
     g_assert_cmpint(tmp_fd, >=, 0);
     close(tmp_fd);
-- 
2.34.1



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

* [PATCH v3 18/54] tests/qtest: vhost-user-test: Avoid using hardcoded /tmp
  2022-09-25 11:29 [PATCH v3 00/54] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (16 preceding siblings ...)
  2022-09-25 11:29 ` [PATCH v3 17/54] tests/qtest: vhost-user-blk-test: " Bin Meng
@ 2022-09-25 11:29 ` Bin Meng
  2022-09-26 13:21   ` Marc-André Lureau
  2022-09-25 11:29 ` [PATCH v3 19/54] tests/qtest: virtio-blk-test: " Bin Meng
                   ` (35 subsequent siblings)
  53 siblings, 1 reply; 89+ messages in thread
From: Bin Meng @ 2022-09-25 11:29 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Bin Meng, Laurent Vivier, Paolo Bonzini,
	Thomas Huth

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

This case was written to use hardcoded /tmp directory for temporary
files. Update to use g_dir_make_tmp() for a portable implementation.

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

Changes in v3:
- Split to a separate patch
- Ensure g_autofree variable is initialized

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

diff --git a/tests/qtest/vhost-user-test.c b/tests/qtest/vhost-user-test.c
index d7d6cfc9bd..448fda3e7f 100644
--- a/tests/qtest/vhost-user-test.c
+++ b/tests/qtest/vhost-user-test.c
@@ -482,8 +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";
-    const char *tmpfs;
+    g_autofree const char *tmpfs = NULL;
 
     server->context = g_main_context_new();
     server->loop = g_main_loop_new(server->context, FALSE);
@@ -491,9 +490,10 @@ 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 = g_mkdtemp(template);
+    tmpfs = g_dir_make_tmp("vhost-test-XXXXXX", NULL);
     if (!tmpfs) {
-        g_test_message("g_mkdtemp on path (%s): %s", template, strerror(errno));
+        g_test_message("g_dir_make_tmp on path (%s): %s", tmpfs,
+                       strerror(errno));
     }
     g_assert(tmpfs);
 
-- 
2.34.1



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

* [PATCH v3 19/54] tests/qtest: virtio-blk-test: Avoid using hardcoded /tmp
  2022-09-25 11:29 [PATCH v3 00/54] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (17 preceding siblings ...)
  2022-09-25 11:29 ` [PATCH v3 18/54] tests/qtest: vhost-user-test: " Bin Meng
@ 2022-09-25 11:29 ` Bin Meng
  2022-09-26 13:21   ` Marc-André Lureau
  2022-09-25 11:29 ` [PATCH v3 20/54] tests/qtest: virtio-scsi-test: " Bin Meng
                   ` (34 subsequent siblings)
  53 siblings, 1 reply; 89+ messages in thread
From: Bin Meng @ 2022-09-25 11:29 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Bin Meng, Laurent Vivier, Paolo Bonzini,
	Stefan Hajnoczi, Thomas Huth, qemu-block

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

This case was written to use hardcoded /tmp directory for temporary
files. Update to use g_file_open_tmp() for a portable implementation.

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

Changes in v3:
- Split to a separate patch

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

diff --git a/tests/qtest/virtio-blk-test.c b/tests/qtest/virtio-blk-test.c
index dc5eed31c8..19c01f808b 100644
--- a/tests/qtest/virtio-blk-test.c
+++ b/tests/qtest/virtio-blk-test.c
@@ -49,10 +49,10 @@ 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;
 
     /* Create a temporary raw image */
-    fd = mkstemp(t_path);
+    fd = g_file_open_tmp("qtest.XXXXXX", &t_path, NULL);
     g_assert_cmpint(fd, >=, 0);
     ret = ftruncate(fd, TEST_IMAGE_SIZE);
     g_assert_cmpint(ret, ==, 0);
-- 
2.34.1



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

* [PATCH v3 20/54] tests/qtest: virtio-scsi-test: Avoid using hardcoded /tmp
  2022-09-25 11:29 [PATCH v3 00/54] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (18 preceding siblings ...)
  2022-09-25 11:29 ` [PATCH v3 19/54] tests/qtest: virtio-blk-test: " Bin Meng
@ 2022-09-25 11:29 ` Bin Meng
  2022-09-26 13:21   ` Marc-André Lureau
  2022-09-25 11:29 ` [PATCH v3 21/54] tests/qtest: libqtest: " Bin Meng
                   ` (33 subsequent siblings)
  53 siblings, 1 reply; 89+ messages in thread
From: Bin Meng @ 2022-09-25 11:29 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Bin Meng, Fam Zheng, Laurent Vivier,
	Paolo Bonzini, Thomas Huth

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

This case was written to use hardcoded /tmp directory for temporary
files. Update to use g_file_open_tmp() for a portable implementation.

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

Changes in v3:
- Split to a separate patch
- Ensure g_autofree variable is initialized

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

diff --git a/tests/qtest/virtio-scsi-test.c b/tests/qtest/virtio-scsi-test.c
index 8ceb12aacd..ceaa7f2415 100644
--- a/tests/qtest/virtio-scsi-test.c
+++ b/tests/qtest/virtio-scsi-test.c
@@ -268,7 +268,7 @@ static void test_iothread_attach_node(void *obj, void *data,
     QVirtioSCSIPCI *scsi_pci = obj;
     QVirtioSCSI *scsi = &scsi_pci->scsi;
     QVirtioSCSIQueues *vs;
-    char tmp_path[] = "/tmp/qtest.XXXXXX";
+    g_autofree char *tmp_path = NULL;
     int fd;
     int ret;
 
@@ -282,7 +282,7 @@ static void test_iothread_attach_node(void *obj, void *data,
     vs = qvirtio_scsi_init(scsi->vdev);
 
     /* Create a temporary qcow2 overlay*/
-    fd = mkstemp(tmp_path);
+    fd = g_file_open_tmp("qtest.XXXXXX", &tmp_path, NULL);
     g_assert(fd >= 0);
     close(fd);
 
-- 
2.34.1



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

* [PATCH v3 21/54] tests/qtest: libqtest: Avoid using hardcoded /tmp
  2022-09-25 11:29 [PATCH v3 00/54] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (19 preceding siblings ...)
  2022-09-25 11:29 ` [PATCH v3 20/54] tests/qtest: virtio-scsi-test: " Bin Meng
@ 2022-09-25 11:29 ` Bin Meng
  2022-09-26 13:22   ` Marc-André Lureau
  2022-09-25 11:30 ` [PATCH v3 22/54] tests/unit: test-image-locking: " Bin Meng
                   ` (32 subsequent siblings)
  53 siblings, 1 reply; 89+ messages in thread
From: Bin Meng @ 2022-09-25 11:29 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Bin Meng, Laurent Vivier, Paolo Bonzini,
	Thomas Huth

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

The qtest library was written to use hardcoded /tmp directory for
temporary files. Update to use g_get_tmp_dir() and g_dir_make_tmp()
for a portable implementation.

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

Changes in v3:
- Split to a separate patch
- Ensure g_autofree variable is initialized

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

diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
index 7c9fc07de4..d8ffa0e7b1 100644
--- a/tests/qtest/libqtest.c
+++ b/tests/qtest/libqtest.c
@@ -265,8 +265,10 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args)
 
     s = g_new(QTestState, 1);
 
-    socket_path = g_strdup_printf("/tmp/qtest-%d.sock", getpid());
-    qmp_socket_path = g_strdup_printf("/tmp/qtest-%d.qmp", getpid());
+    socket_path = g_strdup_printf("%s/qtest-%d.sock",
+                                  g_get_tmp_dir(), getpid());
+    qmp_socket_path = g_strdup_printf("%s/qtest-%d.qmp",
+                                      g_get_tmp_dir(), getpid());
 
     /* It's possible that if an earlier test run crashed it might
      * have left a stale unix socket lying around. Delete any
@@ -390,10 +392,12 @@ 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";
+    g_autofree char *sock_dir = NULL;
+    char *sock_path;
     QTestState *qts;
 
-    g_assert_true(g_mkdtemp(sock_dir) != NULL);
+    sock_dir = g_dir_make_tmp("qtest-serial-XXXXXX", NULL);
+    g_assert_true(sock_dir != NULL);
     sock_path = g_strdup_printf("%s/sock", sock_dir);
 
     sock_fd_init = init_socket(sock_path);
-- 
2.34.1



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

* [PATCH v3 22/54] tests/unit: test-image-locking: Avoid using hardcoded /tmp
  2022-09-25 11:29 [PATCH v3 00/54] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (20 preceding siblings ...)
  2022-09-25 11:29 ` [PATCH v3 21/54] tests/qtest: libqtest: " Bin Meng
@ 2022-09-25 11:30 ` Bin Meng
  2022-09-26 13:22   ` Marc-André Lureau
  2022-09-25 11:30 ` [PATCH v3 23/54] tests/unit: test-qga: " Bin Meng
                   ` (31 subsequent siblings)
  53 siblings, 1 reply; 89+ messages in thread
From: Bin Meng @ 2022-09-25 11:30 UTC (permalink / raw)
  To: qemu-devel; +Cc: Marc-André Lureau, Bin Meng

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

This case was written to use hardcoded /tmp directory for temporary
files. Update to use g_file_open_tmp() for a portable implementation.

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

Changes in v3:
- Split to a separate patch
- Ensure g_autofree variable is initialized

 tests/unit/test-image-locking.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/tests/unit/test-image-locking.c b/tests/unit/test-image-locking.c
index ba057bd66c..a47299c247 100644
--- a/tests/unit/test-image-locking.c
+++ b/tests/unit/test-image-locking.c
@@ -76,10 +76,10 @@ 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";
+    g_autofree char *img_path = NULL;
     uint64_t perm, shared_perm;
 
-    int fd = mkstemp(img_path);
+    int fd = g_file_open_tmp("qtest.XXXXXX", &img_path, NULL);
     assert(fd >= 0);
 
     perm = BLK_PERM_WRITE | BLK_PERM_CONSISTENT_READ;
@@ -117,10 +117,10 @@ static void test_image_locking_basic(void)
 static void test_set_perm_abort(void)
 {
     BlockBackend *blk1, *blk2;
-    char img_path[] = "/tmp/qtest.XXXXXX";
+    g_autofree char *img_path = NULL;
     uint64_t perm, shared_perm;
     int r;
-    int fd = mkstemp(img_path);
+    int fd = g_file_open_tmp("qtest.XXXXXX", &img_path, NULL);
     assert(fd >= 0);
 
     perm = BLK_PERM_WRITE | BLK_PERM_CONSISTENT_READ;
-- 
2.34.1



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

* [PATCH v3 23/54] tests/unit: test-qga: Avoid using hardcoded /tmp
  2022-09-25 11:29 [PATCH v3 00/54] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (21 preceding siblings ...)
  2022-09-25 11:30 ` [PATCH v3 22/54] tests/unit: test-image-locking: " Bin Meng
@ 2022-09-25 11:30 ` Bin Meng
  2022-09-26 13:23   ` Marc-André Lureau
  2022-09-25 11:30 ` [PATCH v3 24/54] tests: vhost-user-bridge: " Bin Meng
                   ` (30 subsequent siblings)
  53 siblings, 1 reply; 89+ messages in thread
From: Bin Meng @ 2022-09-25 11:30 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Bin Meng, Konstantin Kostiuk, Michael Roth

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

This case was written to use hardcoded /tmp directory for temporary
files. Update to use g_get_tmp_dir() for a portable implementation.

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

Changes in v3:
- Split to a separate patch

 tests/unit/test-qga.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/unit/test-qga.c b/tests/unit/test-qga.c
index b6ea7c7304..b4e0a14573 100644
--- a/tests/unit/test-qga.c
+++ b/tests/unit/test-qga.c
@@ -60,7 +60,7 @@ fixture_setup(TestFixture *fixture, gconstpointer data, gchar **envp)
 
     fixture->loop = g_main_loop_new(NULL, FALSE);
 
-    fixture->test_dir = g_strdup("/tmp/qgatest.XXXXXX");
+    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);
-- 
2.34.1



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

* [PATCH v3 24/54] tests: vhost-user-bridge: Avoid using hardcoded /tmp
  2022-09-25 11:29 [PATCH v3 00/54] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (22 preceding siblings ...)
  2022-09-25 11:30 ` [PATCH v3 23/54] tests/unit: test-qga: " Bin Meng
@ 2022-09-25 11:30 ` Bin Meng
  2022-09-26 13:23   ` Marc-André Lureau
  2022-09-25 11:30 ` [PATCH v3 25/54] block/vvfat: Unify the mkdir() call Bin Meng
                   ` (29 subsequent siblings)
  53 siblings, 1 reply; 89+ messages in thread
From: Bin Meng @ 2022-09-25 11:30 UTC (permalink / raw)
  To: qemu-devel; +Cc: Marc-André Lureau, Bin Meng, Paolo Bonzini

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

This case was written to use hardcoded /tmp directory for temporary
files. Update to use g_file_open_tmp() for a portable implementation.

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

Changes in v3:
- Split to a separate patch

 tests/vhost-user-bridge.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/tests/vhost-user-bridge.c b/tests/vhost-user-bridge.c
index 9b1dab2f28..fecdf915e7 100644
--- a/tests/vhost-user-bridge.c
+++ b/tests/vhost-user-bridge.c
@@ -631,7 +631,6 @@ static void *notifier_thread(void *arg)
 static void
 vubr_host_notifier_setup(VubrDev *dev)
 {
-    char template[] = "/tmp/vubr-XXXXXX";
     pthread_t thread;
     size_t length;
     void *addr;
@@ -639,7 +638,7 @@ vubr_host_notifier_setup(VubrDev *dev)
 
     length = qemu_real_host_page_size() * VHOST_USER_BRIDGE_MAX_QUEUES;
 
-    fd = mkstemp(template);
+    fd = g_file_open_tmp("vubr-XXXXXX", NULL, NULL);
     if (fd < 0) {
         vubr_die("mkstemp()");
     }
-- 
2.34.1



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

* [PATCH v3 25/54] block/vvfat: Unify the mkdir() call
  2022-09-25 11:29 [PATCH v3 00/54] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (23 preceding siblings ...)
  2022-09-25 11:30 ` [PATCH v3 24/54] tests: vhost-user-bridge: " Bin Meng
@ 2022-09-25 11:30 ` Bin Meng
  2022-09-25 11:30 ` [PATCH v3 26/54] fsdev/virtfs-proxy-helper: Use g_mkdir() Bin Meng
                   ` (28 subsequent siblings)
  53 siblings, 0 replies; 89+ messages in thread
From: Bin Meng @ 2022-09-25 11:30 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Bin Meng, Hanna Reitz, Kevin Wolf, qemu-block

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

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

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

Signed-off-by: Bin Meng <bin.meng@windriver.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---

(no changes since v2)

Changes in v2:
- Change to use g_mkdir()

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

diff --git a/block/vvfat.c b/block/vvfat.c
index d6dd919683..723beef025 100644
--- a/block/vvfat.c
+++ b/block/vvfat.c
@@ -25,6 +25,7 @@
 
 #include "qemu/osdep.h"
 #include <dirent.h>
+#include <glib/gstdio.h>
 #include "qapi/error.h"
 #include "block/block_int.h"
 #include "block/qdict.h"
@@ -2726,13 +2727,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(commit->path, 0755)) {
                 return -5;
-#else
-            if (mkdir(commit->path, 0755))
-                return -5;
-#endif
+            }
 
             mapping = insert_mapping(s, commit->param.mkdir.cluster,
                     commit->param.mkdir.cluster + 1);
-- 
2.34.1



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

* [PATCH v3 26/54] fsdev/virtfs-proxy-helper: Use g_mkdir()
  2022-09-25 11:29 [PATCH v3 00/54] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (24 preceding siblings ...)
  2022-09-25 11:30 ` [PATCH v3 25/54] block/vvfat: Unify the mkdir() call Bin Meng
@ 2022-09-25 11:30 ` Bin Meng
  2022-09-25 11:30 ` [PATCH v3 27/54] hw/usb: dev-mtp: " Bin Meng
                   ` (27 subsequent siblings)
  53 siblings, 0 replies; 89+ messages in thread
From: Bin Meng @ 2022-09-25 11:30 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Bin Meng, Christian Schoenebeck, Greg Kurz

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

Use g_mkdir() to create a directory on all platforms.

Signed-off-by: Bin Meng <bin.meng@windriver.com>
Reviewed-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
---

(no changes since v2)

Changes in v2:
- Change to use g_mkdir()

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

diff --git a/fsdev/virtfs-proxy-helper.c b/fsdev/virtfs-proxy-helper.c
index 2dde27922f..5cafcd7703 100644
--- a/fsdev/virtfs-proxy-helper.c
+++ b/fsdev/virtfs-proxy-helper.c
@@ -10,6 +10,7 @@
  */
 
 #include "qemu/osdep.h"
+#include <glib/gstdio.h>
 #include <sys/resource.h>
 #include <getopt.h>
 #include <syslog.h>
@@ -639,7 +640,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(path.data, mode);
         break;
     case T_SYMLINK:
         retval = proxy_unmarshal(iovec, offset, "ss", &oldpath, &path);
-- 
2.34.1



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

* [PATCH v3 27/54] hw/usb: dev-mtp: Use g_mkdir()
  2022-09-25 11:29 [PATCH v3 00/54] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (25 preceding siblings ...)
  2022-09-25 11:30 ` [PATCH v3 26/54] fsdev/virtfs-proxy-helper: Use g_mkdir() Bin Meng
@ 2022-09-25 11:30 ` Bin Meng
  2022-09-25 11:30 ` [PATCH v3 28/54] tests/qtest: Skip running virtio-net-test cases that require socketpair() for win32 Bin Meng
                   ` (26 subsequent siblings)
  53 siblings, 0 replies; 89+ messages in thread
From: Bin Meng @ 2022-09-25 11:30 UTC (permalink / raw)
  To: qemu-devel; +Cc: Marc-André Lureau, Bin Meng, Gerd Hoffmann

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

Use g_mkdir() to create a directory on all platforms.

Signed-off-by: Bin Meng <bin.meng@windriver.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
---

(no changes since v2)

Changes in v2:
- Change to use g_mkdir()

 hw/usb/dev-mtp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/usb/dev-mtp.c b/hw/usb/dev-mtp.c
index 5831395cef..1cac1cd435 100644
--- a/hw/usb/dev-mtp.c
+++ b/hw/usb/dev-mtp.c
@@ -14,7 +14,7 @@
 #include "qemu/error-report.h"
 #include <wchar.h>
 #include <dirent.h>
-
+#include <glib/gstdio.h>
 #include <sys/statvfs.h>
 
 
@@ -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(path, mask);
                 if (!ret) {
                     usb_mtp_queue_result(s, RES_OK, d->trans, 3,
                                          QEMU_STORAGE_ID,
-- 
2.34.1



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

* [PATCH v3 28/54] tests/qtest: Skip running virtio-net-test cases that require socketpair() for win32
  2022-09-25 11:29 [PATCH v3 00/54] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (26 preceding siblings ...)
  2022-09-25 11:30 ` [PATCH v3 27/54] hw/usb: dev-mtp: " Bin Meng
@ 2022-09-25 11:30 ` Bin Meng
  2022-09-25 11:30 ` [PATCH v3 29/54] tests/qtest: Build test-filter-{mirror, redirector} cases for posix only Bin Meng
                   ` (25 subsequent siblings)
  53 siblings, 0 replies; 89+ messages in thread
From: Bin Meng @ 2022-09-25 11:30 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Bin Meng, Jason Wang, Laurent Vivier,
	Paolo Bonzini, Thomas Huth

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

Some of the virtio-net-test test cases require socketpair() to do the
test setup. Skip them for win32.

Signed-off-by: Bin Meng <bin.meng@windriver.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---

(no changes since v2)

Changes in v2:
- Change to skip only part of the virtio-net-test cases that require
  socketpair() intead of disabling all of them

 tests/qtest/virtio-net-test.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/tests/qtest/virtio-net-test.c b/tests/qtest/virtio-net-test.c
index 6ded252901..dff43f0f60 100644
--- a/tests/qtest/virtio-net-test.c
+++ b/tests/qtest/virtio-net-test.c
@@ -165,8 +165,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;
@@ -286,6 +284,8 @@ static void *virtio_net_test_setup(GString *cmd_line, void *arg)
     return sv;
 }
 
+#endif /* _WIN32 */
+
 static void large_tx(void *obj, void *data, QGuestAllocator *t_alloc)
 {
     QVirtioNet *dev = obj;
@@ -319,16 +319,15 @@ static void *virtio_net_test_setup_nosocket(GString *cmd_line, void *arg)
 
 static void register_virtio_net_test(void)
 {
-    QOSGraphTestOptions opts = {
-        .before = virtio_net_test_setup,
-    };
+    QOSGraphTestOptions opts = { 0 };
 
-    qos_add_test("hotplug", "virtio-net-pci", hotplug, &opts);
 #ifndef _WIN32
+    opts.before = virtio_net_test_setup;
+    qos_add_test("hotplug", "virtio-net-pci", hotplug, &opts);
     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);
+#endif
 
     /* These tests do not need a loopback backend.  */
     opts.before = virtio_net_test_setup_nosocket;
-- 
2.34.1



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

* [PATCH v3 29/54] tests/qtest: Build test-filter-{mirror, redirector} cases for posix only
  2022-09-25 11:29 [PATCH v3 00/54] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (27 preceding siblings ...)
  2022-09-25 11:30 ` [PATCH v3 28/54] tests/qtest: Skip running virtio-net-test cases that require socketpair() for win32 Bin Meng
@ 2022-09-25 11:30 ` Bin Meng
  2022-09-25 11:30 ` [PATCH v3 30/54] tests/qtest: qmp-test: Skip running test_qmp_oob for win32 Bin Meng
                   ` (24 subsequent siblings)
  53 siblings, 0 replies; 89+ messages in thread
From: Bin Meng @ 2022-09-25 11:30 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Bin Meng, Laurent Vivier, Paolo Bonzini,
	Thomas Huth

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

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

Signed-off-by: Bin Meng <bin.meng@windriver.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---

(no changes since v2)

Changes in v2:
- Introduce a new variable qtests_filter and add that to the
  qtests_ARCH variables

 tests/qtest/meson.build | 36 ++++++++++++++++--------------------
 1 file changed, 16 insertions(+), 20 deletions(-)

diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
index e910cb32ca..455f1bbb7e 100644
--- a/tests/qtest/meson.build
+++ b/tests/qtest/meson.build
@@ -39,9 +39,14 @@ qtests_pci = \
 qtests_cxl = \
   (config_all_devices.has_key('CONFIG_CXL') ? ['cxl-test'] : [])
 
+qtests_filter = \
+  (slirp.found() ? ['test-netfilter'] : []) + \
+  (config_host.has_key('CONFIG_POSIX') ? ['test-filter-mirror'] : []) + \
+  (config_host.has_key('CONFIG_POSIX') ? ['test-filter-redirector'] : [])
+
 qtests_i386 = \
-  (slirp.found() ? ['pxe-test', 'test-netfilter'] : []) +             \
-  (config_host.has_key('CONFIG_POSIX') ? ['test-filter-mirror'] : []) +                     \
+  (slirp.found() ? ['pxe-test'] : []) + \
+  qtests_filter + \
   (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 +100,7 @@ qtests_i386 = \
    'vmgenid-test',
    'migration-test',
    'test-x86-cpuid-compat',
-   'numa-test',
-   'test-filter-redirector'
+   'numa-test'
   ]
 
 if dbus_display
@@ -120,30 +124,25 @@ endif
 qtests_x86_64 = qtests_i386
 
 qtests_alpha = ['boot-serial-test'] + \
-  ['test-filter-mirror', 'test-filter-redirector'] + \
-  (slirp.found() ? ['test-netfilter'] : []) + \
+  qtests_filter + \
   (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'] + \
-  (slirp.found() ? ['test-netfilter'] : []) + \
+  qtests_filter + \
   (config_all_devices.has_key('CONFIG_VGA') ? ['display-vga-test'] : [])
 
 qtests_m68k = ['boot-serial-test'] + \
-  ['test-filter-mirror', 'test-filter-redirector'] + \
-  (slirp.found() ? ['test-netfilter'] : [])
+  qtests_filter
 
 qtests_microblaze = ['boot-serial-test'] + \
-  ['test-filter-mirror', 'test-filter-redirector'] + \
-  (slirp.found() ? ['test-netfilter'] : [])
+  qtests_filter
 
 qtests_microblazeel = qtests_microblaze
 
 qtests_mips = \
-  ['test-filter-mirror', 'test-filter-redirector'] + \
-  (slirp.found() ? ['test-netfilter'] : []) + \
+  qtests_filter + \
   (config_all_devices.has_key('CONFIG_ISA_TESTDEV') ? ['endianness-test'] : []) +            \
   (config_all_devices.has_key('CONFIG_VGA') ? ['display-vga-test'] : [])
 
@@ -152,8 +151,7 @@ qtests_mips64 = qtests_mips
 qtests_mips64el = qtests_mips
 
 qtests_ppc = \
-  ['test-filter-mirror', 'test-filter-redirector'] + \
-  (slirp.found() ? ['test-netfilter'] : []) + \
+  qtests_filter + \
   (config_all_devices.has_key('CONFIG_ISA_TESTDEV') ? ['endianness-test'] : []) +            \
   (config_all_devices.has_key('CONFIG_M48T59') ? ['m48t59-test'] : []) +                     \
   (config_all_devices.has_key('CONFIG_TCG') ? ['prom-env-test'] : []) +                      \
@@ -174,13 +172,11 @@ 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'] + \
-  (slirp.found() ? ['test-netfilter'] : [])
+  qtests_filter
 
 qtests_sparc64 = \
   (config_all_devices.has_key('CONFIG_ISA_TESTDEV') ? ['endianness-test'] : []) +            \
-  (slirp.found() ? ['test-netfilter'] : []) + \
-  ['test-filter-mirror', 'test-filter-redirector'] + \
+  qtests_filter + \
   ['prom-env-test', 'boot-serial-test']
 
 qtests_npcm7xx = \
-- 
2.34.1



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

* [PATCH v3 30/54] tests/qtest: qmp-test: Skip running test_qmp_oob for win32
  2022-09-25 11:29 [PATCH v3 00/54] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (28 preceding siblings ...)
  2022-09-25 11:30 ` [PATCH v3 29/54] tests/qtest: Build test-filter-{mirror, redirector} cases for posix only Bin Meng
@ 2022-09-25 11:30 ` Bin Meng
  2022-09-25 11:30 ` [PATCH v3 31/54] accel/qtest: Implement a portable qtest accelerator Bin Meng
                   ` (23 subsequent siblings)
  53 siblings, 0 replies; 89+ messages in thread
From: Bin Meng @ 2022-09-25 11:30 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Bin Meng, Thomas Huth, Laurent Vivier,
	Markus Armbruster, Paolo Bonzini

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

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

Signed-off-by: Bin Meng <bin.meng@windriver.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
---

(no changes since v2)

Changes in v2:
- Add a comment in the code to explain why test_qmp_oob test case
  is skipped on win32

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

diff --git a/tests/qtest/qmp-test.c b/tests/qtest/qmp-test.c
index 0fa00c12dc..074953fdf0 100644
--- a/tests/qtest/qmp-test.c
+++ b/tests/qtest/qmp-test.c
@@ -159,6 +159,8 @@ static void test_qmp_protocol(void)
     qtest_quit(qts);
 }
 
+#ifndef _WIN32
+
 /* Out-of-band tests */
 
 char *tmpdir;
@@ -279,6 +281,8 @@ static void test_qmp_oob(void)
     qtest_quit(qts);
 }
 
+#endif /* _WIN32 */
+
 /* Preconfig tests */
 
 static void test_qmp_preconfig(void)
@@ -338,7 +342,10 @@ int main(int argc, char *argv[])
     g_test_init(&argc, &argv, NULL);
 
     qtest_add_func("qmp/protocol", test_qmp_protocol);
+#ifndef _WIN32
+    /* This case calls mkfifo() which does not exist on win32 */
     qtest_add_func("qmp/oob", test_qmp_oob);
+#endif
     qtest_add_func("qmp/preconfig", test_qmp_preconfig);
     qtest_add_func("qmp/missing-any-arg", test_qmp_missing_any_arg);
 
-- 
2.34.1



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

* [PATCH v3 31/54] accel/qtest: Implement a portable qtest accelerator
  2022-09-25 11:29 [PATCH v3 00/54] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (29 preceding siblings ...)
  2022-09-25 11:30 ` [PATCH v3 30/54] tests/qtest: qmp-test: Skip running test_qmp_oob for win32 Bin Meng
@ 2022-09-25 11:30 ` Bin Meng
  2022-09-25 11:30 ` [PATCH v3 32/54] tests/qtest: libqtest: Adapt global_qtest declaration for win32 Bin Meng
                   ` (22 subsequent siblings)
  53 siblings, 0 replies; 89+ messages in thread
From: Bin Meng @ 2022-09-25 11:30 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Xuzhou Cheng, Bin Meng, Eduardo Habkost,
	Laurent Vivier, Marcel Apfelbaum, Paolo Bonzini,
	Philippe Mathieu-Daudé,
	Richard Henderson, Thomas Huth, Yanan Wang

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

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

As a result of this, the POSIX implementation via signal is no
longer needed and can use the same path as Windows.

Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
Signed-off-by: Bin Meng <bin.meng@windriver.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---

(no changes since v2)

Changes in v2:
- Replace signal by the semaphore on posix too

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

diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index 500503da13..2f46c37dc1 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -326,6 +326,7 @@ struct CPUState {
 #ifdef _WIN32
     HANDLE hThread;
 #endif
+    QemuSemaphore sem;
     int thread_id;
     bool running, has_waiter;
     struct QemuCond *halt_cond;
diff --git a/accel/dummy-cpus.c b/accel/dummy-cpus.c
index 10429fdfb2..3769d3db0a 100644
--- a/accel/dummy-cpus.c
+++ b/accel/dummy-cpus.c
@@ -21,8 +21,6 @@
 static void *dummy_cpu_thread_fn(void *arg)
 {
     CPUState *cpu = arg;
-    sigset_t waitset;
-    int r;
 
     rcu_register_thread();
 
@@ -32,23 +30,13 @@ static void *dummy_cpu_thread_fn(void *arg)
     cpu->can_do_io = 1;
     current_cpu = cpu;
 
-    sigemptyset(&waitset);
-    sigaddset(&waitset, SIG_IPI);
-
     /* signal CPU creation */
     cpu_thread_signal_created(cpu);
     qemu_guest_random_seed_thread_part2(cpu->random_seed);
 
     do {
         qemu_mutex_unlock_iothread();
-        do {
-            int sig;
-            r = sigwait(&waitset, &sig);
-        } while (r == -1 && (errno == EAGAIN || errno == EINTR));
-        if (r == -1) {
-            perror("sigwait");
-            exit(1);
-        }
+        qemu_sem_wait(&cpu->sem);
         qemu_mutex_lock_iothread();
         qemu_wait_io_event(cpu);
     } while (!cpu->unplug);
@@ -67,6 +55,7 @@ void dummy_start_vcpu_thread(CPUState *cpu)
     qemu_cond_init(cpu->halt_cond);
     snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/DUMMY",
              cpu->cpu_index);
+    qemu_sem_init(&cpu->sem, 0);
     qemu_thread_create(cpu->thread, thread_name, dummy_cpu_thread_fn, cpu,
                        QEMU_THREAD_JOINABLE);
 }
diff --git a/softmmu/cpus.c b/softmmu/cpus.c
index 23b30484b2..2a992d0d5f 100644
--- a/softmmu/cpus.c
+++ b/softmmu/cpus.c
@@ -437,19 +437,11 @@ 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);
-    if (err && err != ESRCH) {
-        fprintf(stderr, "qemu:%s: %s", __func__, strerror(err));
-        exit(1);
-    }
-#endif
+    qemu_sem_post(&cpu->sem);
 }
 
 void qemu_cpu_kick(CPUState *cpu)
diff --git a/accel/meson.build b/accel/meson.build
index b9a963cf80..b21c85dc0a 100644
--- a/accel/meson.build
+++ b/accel/meson.build
@@ -17,4 +17,5 @@ dummy_ss.add(files(
 ))
 
 specific_ss.add_all(when: ['CONFIG_SOFTMMU', 'CONFIG_POSIX'], if_true: dummy_ss)
+specific_ss.add_all(when: ['CONFIG_WIN32'], if_true: dummy_ss)
 specific_ss.add_all(when: ['CONFIG_XEN'], if_true: dummy_ss)
diff --git a/accel/qtest/meson.build b/accel/qtest/meson.build
index 4c65600293..a4876fc0f2 100644
--- a/accel/qtest/meson.build
+++ b/accel/qtest/meson.build
@@ -1,2 +1,3 @@
 qtest_module_ss.add(when: ['CONFIG_SOFTMMU', 'CONFIG_POSIX'],
                     if_true: files('qtest.c'))
+qtest_module_ss.add(when: ['CONFIG_WIN32'], if_true: files('qtest.c'))
-- 
2.34.1



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

* [PATCH v3 32/54] tests/qtest: libqtest: Adapt global_qtest declaration for win32
  2022-09-25 11:29 [PATCH v3 00/54] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (30 preceding siblings ...)
  2022-09-25 11:30 ` [PATCH v3 31/54] accel/qtest: Implement a portable qtest accelerator Bin Meng
@ 2022-09-25 11:30 ` Bin Meng
  2022-09-26 16:07   ` Thomas Huth
  2022-09-25 11:30 ` [PATCH v3 33/54] tests/qtest: Use send/recv for socket communication Bin Meng
                   ` (21 subsequent siblings)
  53 siblings, 1 reply; 89+ messages in thread
From: Bin Meng @ 2022-09-25 11:30 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Xuzhou Cheng, Bin Meng, Laurent Vivier,
	Paolo Bonzini, Thomas Huth

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

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

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

However Windows does provide a trick to declare a variable to be
a common symbol, via __declspec(selectany) [1]. It does not provide
the "strong override weak" effect but we don't need it in our use
case anyway. So let's use it for win32.

[1] https://docs.microsoft.com/en-us/cpp/cpp/selectany

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

(no changes since v2)

Changes in v2:
- Use __declspec(selectany) for the common weak symbol on Windows

 tests/qtest/libqtest-single.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/tests/qtest/libqtest-single.h b/tests/qtest/libqtest-single.h
index 4e7d0ae1dc..851724cbcb 100644
--- a/tests/qtest/libqtest-single.h
+++ b/tests/qtest/libqtest-single.h
@@ -13,7 +13,11 @@
 
 #include "libqtest.h"
 
+#ifndef _WIN32
 QTestState *global_qtest __attribute__((common, weak));
+#else
+__declspec(selectany) QTestState *global_qtest;
+#endif
 
 /**
  * qtest_start:
-- 
2.34.1



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

* [PATCH v3 33/54] tests/qtest: Use send/recv for socket communication
  2022-09-25 11:29 [PATCH v3 00/54] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (31 preceding siblings ...)
  2022-09-25 11:30 ` [PATCH v3 32/54] tests/qtest: libqtest: Adapt global_qtest declaration for win32 Bin Meng
@ 2022-09-25 11:30 ` Bin Meng
  2022-09-25 11:30 ` [PATCH v3 34/54] tests/qtest: libqtest: Exclude the *_fds APIs for win32 Bin Meng
                   ` (20 subsequent siblings)
  53 siblings, 0 replies; 89+ messages in thread
From: Bin Meng @ 2022-09-25 11:30 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Xuzhou Cheng, Bin Meng,
	Daniel P. Berrangé,
	Laurent Vivier, Paolo Bonzini, Thomas Huth

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

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

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

Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
Signed-off-by: Bin Meng <bin.meng@windriver.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---

(no changes since v2)

Changes in v2:
- Introduce qemu_send_full() and use it

 include/qemu/sockets.h |  2 ++
 tests/qtest/libqmp.c   |  5 +++--
 tests/qtest/libqtest.c |  4 ++--
 util/osdep.c           | 33 +++++++++++++++++++++++++++++++++
 4 files changed, 40 insertions(+), 4 deletions(-)

diff --git a/include/qemu/sockets.h b/include/qemu/sockets.h
index 038faa157f..8ff7832eba 100644
--- a/include/qemu/sockets.h
+++ b/include/qemu/sockets.h
@@ -15,6 +15,8 @@ int inet_aton(const char *cp, struct in_addr *ia);
 bool fd_is_socket(int fd);
 int qemu_socket(int domain, int type, int protocol);
 int qemu_accept(int s, struct sockaddr *addr, socklen_t *addrlen);
+ssize_t qemu_send_full(int s, const void *buf, size_t count)
+    G_GNUC_WARN_UNUSED_RESULT;
 int socket_set_cork(int fd, int v);
 int socket_set_nodelay(int fd);
 void qemu_socket_set_block(int fd);
diff --git a/tests/qtest/libqmp.c b/tests/qtest/libqmp.c
index ade26c15f0..2b08382e5d 100644
--- a/tests/qtest/libqmp.c
+++ b/tests/qtest/libqmp.c
@@ -23,6 +23,7 @@
 #endif
 
 #include "qemu/cutils.h"
+#include "qemu/sockets.h"
 #include "qapi/error.h"
 #include "qapi/qmp/json-parser.h"
 #include "qapi/qmp/qjson.h"
@@ -36,7 +37,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 = qemu_send_full(fd, buf, size);
 
     assert(res == size);
 }
@@ -69,7 +70,7 @@ QDict *qmp_fd_receive(int fd)
         ssize_t len;
         char c;
 
-        len = read(fd, &c, 1);
+        len = recv(fd, &c, 1, 0);
         if (len == -1 && errno == EINTR) {
             continue;
         }
diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
index d8ffa0e7b1..0dfe630373 100644
--- a/tests/qtest/libqtest.c
+++ b/tests/qtest/libqtest.c
@@ -436,7 +436,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 = qemu_send_full(fd, buf, size);
 
     assert(res == size);
 }
@@ -468,7 +468,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;
         }
diff --git a/util/osdep.c b/util/osdep.c
index 60fcbbaebe..0342e754e1 100644
--- a/util/osdep.c
+++ b/util/osdep.c
@@ -502,6 +502,39 @@ int qemu_accept(int s, struct sockaddr *addr, socklen_t *addrlen)
     return ret;
 }
 
+/*
+ * A variant of send(2) which handles partial send.
+ *
+ * Return the number of bytes transferred over the socket.
+ * Set errno if fewer than `count' bytes are sent.
+ *
+ * This function don't work with non-blocking socket's.
+ * Any of the possibilities with non-blocking socket's is bad:
+ *   - return a short write (then name is wrong)
+ *   - busy wait adding (errno == EAGAIN) to the loop
+ */
+ssize_t qemu_send_full(int s, const void *buf, size_t count)
+{
+    ssize_t ret = 0;
+    ssize_t total = 0;
+
+    while (count) {
+        ret = send(s, buf, count, 0);
+        if (ret < 0) {
+            if (errno == EINTR) {
+                continue;
+            }
+            break;
+        }
+
+        count -= ret;
+        buf += ret;
+        total += ret;
+    }
+
+    return total;
+}
+
 void qemu_set_hw_version(const char *version)
 {
     hw_version = version;
-- 
2.34.1



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

* [PATCH v3 34/54] tests/qtest: libqtest: Exclude the *_fds APIs for win32
  2022-09-25 11:29 [PATCH v3 00/54] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (32 preceding siblings ...)
  2022-09-25 11:30 ` [PATCH v3 33/54] tests/qtest: Use send/recv for socket communication Bin Meng
@ 2022-09-25 11:30 ` Bin Meng
  2022-09-25 11:30 ` [PATCH v3 35/54] tests/qtest: libqtest: Install signal handler via signal() Bin Meng
                   ` (19 subsequent siblings)
  53 siblings, 0 replies; 89+ messages in thread
From: Bin Meng @ 2022-09-25 11:30 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Bin Meng, Laurent Vivier, Paolo Bonzini,
	Thomas Huth

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

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

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

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

Signed-off-by: Bin Meng <bin.meng@windriver.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---

(no changes since v1)

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

diff --git a/tests/qtest/libqtest.h b/tests/qtest/libqtest.h
index 94b187837d..3abc75964d 100644
--- a/tests/qtest/libqtest.h
+++ b/tests/qtest/libqtest.h
@@ -94,6 +94,7 @@ void qtest_kill_qemu(QTestState *s);
  */
 void qtest_quit(QTestState *s);
 
+#ifndef _WIN32
 /**
  * qtest_qmp_fds:
  * @s: #QTestState instance to operate on.
@@ -108,6 +109,7 @@ void qtest_quit(QTestState *s);
 QDict *qtest_qmp_fds(QTestState *s, int *fds, size_t fds_num,
                      const char *fmt, ...)
     G_GNUC_PRINTF(4, 5);
+#endif /* _WIN32 */
 
 /**
  * qtest_qmp:
@@ -152,6 +154,7 @@ void qtest_qmp_send_raw(QTestState *s, const char *fmt, ...)
  */
 int qtest_socket_server(const char *socket_path);
 
+#ifndef _WIN32
 /**
  * qtest_vqmp_fds:
  * @s: #QTestState instance to operate on.
@@ -167,6 +170,7 @@ int qtest_socket_server(const char *socket_path);
 QDict *qtest_vqmp_fds(QTestState *s, int *fds, size_t fds_num,
                       const char *fmt, va_list ap)
     G_GNUC_PRINTF(4, 0);
+#endif /* _WIN32 */
 
 /**
  * qtest_vqmp:
@@ -181,6 +185,7 @@ QDict *qtest_vqmp_fds(QTestState *s, int *fds, size_t fds_num,
 QDict *qtest_vqmp(QTestState *s, const char *fmt, va_list ap)
     G_GNUC_PRINTF(2, 0);
 
+#ifndef _WIN32
 /**
  * qtest_qmp_vsend_fds:
  * @s: #QTestState instance to operate on.
@@ -196,6 +201,7 @@ QDict *qtest_vqmp(QTestState *s, const char *fmt, va_list ap)
 void qtest_qmp_vsend_fds(QTestState *s, int *fds, size_t fds_num,
                          const char *fmt, va_list ap)
     G_GNUC_PRINTF(4, 0);
+#endif /* _WIN32 */
 
 /**
  * qtest_qmp_vsend:
@@ -743,6 +749,7 @@ void qtest_qmp_device_add_qdict(QTestState *qts, const char *drv,
 void qtest_qmp_device_add(QTestState *qts, const char *driver, const char *id,
                           const char *fmt, ...) G_GNUC_PRINTF(4, 5);
 
+#ifndef _WIN32
 /**
  * qtest_qmp_add_client:
  * @qts: QTestState instance to operate on
@@ -752,6 +759,7 @@ void qtest_qmp_device_add(QTestState *qts, const char *driver, const char *id,
  * Call QMP ``getfd`` followed by ``add_client`` with the given @fd.
  */
 void qtest_qmp_add_client(QTestState *qts, const char *protocol, int fd);
+#endif /* _WIN32 */
 
 /**
  * qtest_qmp_device_del:
diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
index 0dfe630373..269d622fe3 100644
--- a/tests/qtest/libqtest.c
+++ b/tests/qtest/libqtest.c
@@ -592,17 +592,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)
 {
@@ -611,6 +614,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)
 {
@@ -620,6 +624,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, ...)
 {
@@ -631,6 +636,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, ...)
 {
@@ -1327,6 +1333,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;
@@ -1346,6 +1353,7 @@ void qtest_qmp_add_client(QTestState *qts, const char *protocol, int fd)
     g_assert(!qdict_haskey(resp, "error"));
     qobject_unref(resp);
 }
+#endif
 
 /*
  * Generic hot-unplugging test via the device_del QMP command.
-- 
2.34.1



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

* [PATCH v3 35/54] tests/qtest: libqtest: Install signal handler via signal()
  2022-09-25 11:29 [PATCH v3 00/54] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (33 preceding siblings ...)
  2022-09-25 11:30 ` [PATCH v3 34/54] tests/qtest: libqtest: Exclude the *_fds APIs for win32 Bin Meng
@ 2022-09-25 11:30 ` Bin Meng
  2022-09-26 13:24   ` Marc-André Lureau
  2022-09-25 11:30 ` [PATCH v3 36/54] tests/qtest: Support libqtest to build and run on Windows Bin Meng
                   ` (18 subsequent siblings)
  53 siblings, 1 reply; 89+ messages in thread
From: Bin Meng @ 2022-09-25 11:30 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Bin Meng, Laurent Vivier, Paolo Bonzini,
	Thomas Huth

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

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

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

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

(no changes since v1)

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

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



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

* [PATCH v3 36/54] tests/qtest: Support libqtest to build and run on Windows
  2022-09-25 11:29 [PATCH v3 00/54] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (34 preceding siblings ...)
  2022-09-25 11:30 ` [PATCH v3 35/54] tests/qtest: libqtest: Install signal handler via signal() Bin Meng
@ 2022-09-25 11:30 ` Bin Meng
  2022-09-25 11:30 ` [PATCH v3 37/54] tests/qtest: {ahci, ide}-test: Use relative path for temporary files for win32 Bin Meng
                   ` (17 subsequent siblings)
  53 siblings, 0 replies; 89+ messages in thread
From: Bin Meng @ 2022-09-25 11:30 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Bin Meng, Xuzhou Cheng, Laurent Vivier,
	Paolo Bonzini, Thomas Huth

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

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

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

Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
Signed-off-by: Bin Meng <bin.meng@windriver.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---

(no changes since v2)

Changes in v2:
- Move the enabling of building qtests on Windows to a separate
  patch to keep bisectablity
- Call socket_init() unconditionally
- Add a missing CloseHandle() call

 tests/qtest/libqtest.c | 98 +++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 96 insertions(+), 2 deletions(-)

diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
index f0ac467903..12b1e85b51 100644
--- a/tests/qtest/libqtest.c
+++ b/tests/qtest/libqtest.c
@@ -16,9 +16,11 @@
 
 #include "qemu/osdep.h"
 
+#ifndef _WIN32
 #include <sys/socket.h>
 #include <sys/wait.h>
 #include <sys/un.h>
+#endif /* _WIN32 */
 #ifdef __linux__
 #include <sys/prctl.h>
 #endif /* __linux__ */
@@ -27,6 +29,7 @@
 #include "libqmp.h"
 #include "qemu/ctype.h"
 #include "qemu/cutils.h"
+#include "qemu/sockets.h"
 #include "qapi/qmp/qdict.h"
 #include "qapi/qmp/qjson.h"
 #include "qapi/qmp/qlist.h"
@@ -35,6 +38,16 @@
 #define MAX_IRQ 256
 #define SOCKET_TIMEOUT 50
 
+#ifndef _WIN32
+# define CMD_EXEC   "exec "
+# define DEV_STDERR "/dev/fd/2"
+# define DEV_NULL   "/dev/null"
+#else
+# define CMD_EXEC   ""
+# define DEV_STDERR "2"
+# define DEV_NULL   "nul"
+#endif
+
 typedef void (*QTestSendFn)(QTestState *s, const char *buf);
 typedef void (*ExternalSendFn)(void *s, const char *buf);
 typedef GString* (*QTestRecvFn)(QTestState *);
@@ -66,6 +79,9 @@ struct QTestState
 };
 
 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);
@@ -118,10 +134,19 @@ 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;
+        }
+        CloseHandle((HANDLE)pid);
+#endif
         s->qemu_pid = -1;
     }
     return false;
@@ -135,13 +160,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;
     }
 
@@ -149,6 +184,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 "
@@ -165,6 +201,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)
@@ -243,6 +289,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;
@@ -270,6 +348,7 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args)
     unlink(socket_path);
     unlink(qmp_socket_path);
 
+    socket_init();
     sock = init_socket(socket_path);
     qmpsock = init_socket(qmp_socket_path);
 
@@ -278,7 +357,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 "
@@ -287,7 +366,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 ?: "");
 
@@ -296,6 +375,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__
@@ -318,6 +398,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);
@@ -336,9 +419,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 */
 
@@ -392,6 +485,7 @@ QTestState *qtest_init_with_serial(const char *extra_args, int *sock_fd)
     g_assert_true(sock_dir != NULL);
     sock_path = g_strdup_printf("%s/sock", sock_dir);
 
+    socket_init();
     sock_fd_init = init_socket(sock_path);
 
     qts = qtest_initf("-chardev socket,id=s0,path=%s -serial chardev:s0 %s",
-- 
2.34.1



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

* [PATCH v3 37/54] tests/qtest: {ahci, ide}-test: Use relative path for temporary files for win32
  2022-09-25 11:29 [PATCH v3 00/54] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (35 preceding siblings ...)
  2022-09-25 11:30 ` [PATCH v3 36/54] tests/qtest: Support libqtest to build and run on Windows Bin Meng
@ 2022-09-25 11:30 ` Bin Meng
  2022-09-26 16:20   ` Thomas Huth
  2022-09-25 11:30 ` [PATCH v3 38/54] tests/qtest: bios-tables-test: Adapt the case " Bin Meng
                   ` (16 subsequent siblings)
  53 siblings, 1 reply; 89+ messages in thread
From: Bin Meng @ 2022-09-25 11:30 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Bin Meng, John Snow, Laurent Vivier,
	Paolo Bonzini, Thomas Huth, qemu-block

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

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

Signed-off-by: Bin Meng <bin.meng@windriver.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---

(no changes since v1)

 tests/qtest/ahci-test.c | 21 ++++++++++++++++++---
 tests/qtest/ide-test.c  | 20 ++++++++++++++++++--
 2 files changed, 36 insertions(+), 5 deletions(-)

diff --git a/tests/qtest/ahci-test.c b/tests/qtest/ahci-test.c
index 1d5929d8c3..66652fed04 100644
--- a/tests/qtest/ahci-test.c
+++ b/tests/qtest/ahci-test.c
@@ -1833,7 +1833,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;
@@ -1871,8 +1871,22 @@ 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 */
-    fd = g_file_open_tmp("qtest.XXXXXX", &tmp_path, NULL);
+    tmp_path = g_strdup_printf("%s/qtest.XXXXXX", base);
+    fd = g_mkstemp(tmp_path);
     g_assert(fd >= 0);
     if (have_qemu_img()) {
         imgfmt = "qcow2";
@@ -1889,7 +1903,8 @@ int main(int argc, char **argv)
     close(fd);
 
     /* Create temporary blkdebug instructions */
-    fd = g_file_open_tmp("qtest-blkdebug.XXXXXX", &debug_path, NULL);
+    debug_path = g_strdup_printf("%s/qtest-blkdebug.XXXXXX", base);
+    fd = g_mkstemp(debug_path);
     g_assert(fd >= 0);
     close(fd);
 
diff --git a/tests/qtest/ide-test.c b/tests/qtest/ide-test.c
index 25302be6dc..5e3e28aea2 100644
--- a/tests/qtest/ide-test.c
+++ b/tests/qtest/ide-test.c
@@ -1011,16 +1011,32 @@ 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 */
-    fd = g_file_open_tmp("qtest-blkdebug.XXXXXX", &debug_path, NULL);
+    debug_path = g_strdup_printf("%s/qtest-blkdebug.XXXXXX", base);
+    fd = g_mkstemp(debug_path);
     g_assert(fd >= 0);
     close(fd);
 
     /* Create a temporary raw image */
-    fd = g_file_open_tmp("qtest.XXXXXX", &tmp_path, NULL);
+    tmp_path = g_strdup_printf("%s/qtest.XXXXXX", base);
+    fd = g_mkstemp(tmp_path);
     g_assert(fd >= 0);
     ret = ftruncate(fd, TEST_IMAGE_SIZE);
     g_assert(ret == 0);
-- 
2.34.1



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

* [PATCH v3 38/54] tests/qtest: bios-tables-test: Adapt the case for win32
  2022-09-25 11:29 [PATCH v3 00/54] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (36 preceding siblings ...)
  2022-09-25 11:30 ` [PATCH v3 37/54] tests/qtest: {ahci, ide}-test: Use relative path for temporary files for win32 Bin Meng
@ 2022-09-25 11:30 ` Bin Meng
  2022-09-25 12:41   ` Michael S. Tsirkin
  2022-09-25 11:30 ` [PATCH v3 39/54] tests/qtest: migration-test: Disable IO redirection " Bin Meng
                   ` (15 subsequent siblings)
  53 siblings, 1 reply; 89+ messages in thread
From: Bin Meng @ 2022-09-25 11:30 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Bin Meng, Ani Sinha, Igor Mammedov,
	Michael S. Tsirkin

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

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

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

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

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

Signed-off-by: Bin Meng <bin.meng@windriver.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---

(no changes since v1)

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

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



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

* [PATCH v3 39/54] tests/qtest: migration-test: Disable IO redirection for win32
  2022-09-25 11:29 [PATCH v3 00/54] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (37 preceding siblings ...)
  2022-09-25 11:30 ` [PATCH v3 38/54] tests/qtest: bios-tables-test: Adapt the case " Bin Meng
@ 2022-09-25 11:30 ` Bin Meng
  2022-09-25 11:30 ` [PATCH v3 40/54] tests/qtest: ide-test: Open file in binary mode Bin Meng
                   ` (14 subsequent siblings)
  53 siblings, 0 replies; 89+ messages in thread
From: Bin Meng @ 2022-09-25 11:30 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Bin Meng, Dr. David Alan Gilbert,
	Juan Quintela, Laurent Vivier, Paolo Bonzini, Thomas Huth

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

On Windows the QEMU executable is created via CreateProcess() and
IO redirection does not work, so don't bother adding IO redirection
to the command line.

Signed-off-by: Bin Meng <bin.meng@windriver.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---

(no changes since v2)

Changes in v2:
- Change the place that sets IO redirection in the command line

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

diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index 029c4f3a6a..a1dd342739 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -647,7 +647,16 @@ static int test_migrate_start(QTestState **from, QTestState **to,
     }
 
     if (!getenv("QTEST_LOG") && args->hide_stderr) {
+#ifndef _WIN32
         ignore_stderr = "2>/dev/null";
+#else
+        /*
+         * On Windows the QEMU executable is created via CreateProcess() and
+         * IO redirection does not work, so don't bother adding IO redirection
+         * to the command line.
+         */
+        ignore_stderr = "";
+#endif
     } else {
         ignore_stderr = "";
     }
-- 
2.34.1



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

* [PATCH v3 40/54] tests/qtest: ide-test: Open file in binary mode
  2022-09-25 11:29 [PATCH v3 00/54] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (38 preceding siblings ...)
  2022-09-25 11:30 ` [PATCH v3 39/54] tests/qtest: migration-test: Disable IO redirection " Bin Meng
@ 2022-09-25 11:30 ` Bin Meng
  2022-09-25 11:30 ` [PATCH v3 41/54] tests/qtest: virtio-net-failover: Disable migration tests for win32 Bin Meng
                   ` (13 subsequent siblings)
  53 siblings, 0 replies; 89+ messages in thread
From: Bin Meng @ 2022-09-25 11:30 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Xuzhou Cheng, Bin Meng, John Snow,
	Laurent Vivier, Paolo Bonzini, Thomas Huth, qemu-block

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

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

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

Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
Signed-off-by: Bin Meng <bin.meng@windriver.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---

(no changes since v2)

Changes in v2:
- Drop ahci-test.c changes that are no longer needed

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

diff --git a/tests/qtest/ide-test.c b/tests/qtest/ide-test.c
index 5e3e28aea2..4ea89c26c9 100644
--- a/tests/qtest/ide-test.c
+++ b/tests/qtest/ide-test.c
@@ -892,7 +892,7 @@ static void cdrom_pio_impl(int nblocks)
 
     /* Prepopulate the CDROM with an interesting pattern */
     generate_pattern(pattern, patt_len, ATAPI_BLOCK_SIZE);
-    fh = fopen(tmp_path, "w+");
+    fh = fopen(tmp_path, "wb+");
     ret = fwrite(pattern, ATAPI_BLOCK_SIZE, patt_blocks, fh);
     g_assert_cmpint(ret, ==, patt_blocks);
     fclose(fh);
@@ -993,7 +993,7 @@ static void test_cdrom_dma(void)
     prdt[0].size = cpu_to_le32(len | PRDT_EOT);
 
     generate_pattern(pattern, ATAPI_BLOCK_SIZE * 16, ATAPI_BLOCK_SIZE);
-    fh = fopen(tmp_path, "w+");
+    fh = fopen(tmp_path, "wb+");
     ret = fwrite(pattern, ATAPI_BLOCK_SIZE, 16, fh);
     g_assert_cmpint(ret, ==, 16);
     fclose(fh);
-- 
2.34.1



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

* [PATCH v3 41/54] tests/qtest: virtio-net-failover: Disable migration tests for win32
  2022-09-25 11:29 [PATCH v3 00/54] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (39 preceding siblings ...)
  2022-09-25 11:30 ` [PATCH v3 40/54] tests/qtest: ide-test: Open file in binary mode Bin Meng
@ 2022-09-25 11:30 ` Bin Meng
  2022-09-25 11:30 ` [PATCH v3 42/54] chardev/char-file: Add FILE_SHARE_WRITE when opening the file " Bin Meng
                   ` (12 subsequent siblings)
  53 siblings, 0 replies; 89+ messages in thread
From: Bin Meng @ 2022-09-25 11:30 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Xuzhou Cheng, Bin Meng, Laurent Vivier,
	Paolo Bonzini, Thomas Huth

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

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

Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
Signed-off-by: Bin Meng <bin.meng@windriver.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---

(no changes since v1)

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

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



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

* [PATCH v3 42/54] chardev/char-file: Add FILE_SHARE_WRITE when opening the file for win32
  2022-09-25 11:29 [PATCH v3 00/54] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (40 preceding siblings ...)
  2022-09-25 11:30 ` [PATCH v3 41/54] tests/qtest: virtio-net-failover: Disable migration tests for win32 Bin Meng
@ 2022-09-25 11:30 ` Bin Meng
  2022-09-26 13:27   ` Marc-André Lureau
  2022-09-25 11:30 ` [PATCH v3 43/54] tests/qtest: migration-test: Make sure QEMU process "to" exited after migration is canceled Bin Meng
                   ` (11 subsequent siblings)
  53 siblings, 1 reply; 89+ messages in thread
From: Bin Meng @ 2022-09-25 11:30 UTC (permalink / raw)
  To: qemu-devel; +Cc: Marc-André Lureau, Xuzhou Cheng, Bin Meng, Paolo Bonzini

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

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

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 old one still holds the file handle that does
not allow shared write permission then the new QEMU process will fail.

There is another test case boot-serial-test that triggers the same
issue. The qtest executable created a serial chardev file to be
passed to the QEMU executable. The serial file was created by
g_file_open_tmp(), which internally opens the file with
FILE_SHARE_WRITE security attribute, and based on [1], there is
only one case that allows the first call to CreateFile() with
GENERIC_READ & FILE_SHARE_WRITE, and second call to CreateFile()
with GENERIC_WRITE & FILE_SHARE_READ. All other combinations
require FILE_SHARE_WRITE in the second call. But there is no way
for the second call (in this case the QEMU executable) to know
what combination was passed to the first call, so we will have to
add FILE_SHARE_WRITE to the second call.

For both scenarios we should add FILE_SHARE_WRITE in the chardev
file backend driver. This change also makes the behavior to be
consistent with the POSIX platforms.

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

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

Changes in v3:
- Add another case "boot-serial-test" to justify the change

Changes in v2:
- Update commit message to include the use case why we should set
  FILE_SHARE_WRITE when opening the file for win32

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

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



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

* [PATCH v3 43/54] tests/qtest: migration-test: Make sure QEMU process "to" exited after migration is canceled
  2022-09-25 11:29 [PATCH v3 00/54] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (41 preceding siblings ...)
  2022-09-25 11:30 ` [PATCH v3 42/54] chardev/char-file: Add FILE_SHARE_WRITE when opening the file " Bin Meng
@ 2022-09-25 11:30 ` Bin Meng
  2022-09-25 11:30 ` [PATCH v3 44/54] tests/qtest: microbit-test: Fix socket access for win32 Bin Meng
                   ` (10 subsequent siblings)
  53 siblings, 0 replies; 89+ messages in thread
From: Bin Meng @ 2022-09-25 11:30 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Xuzhou Cheng, Bin Meng,
	Dr. David Alan Gilbert, Juan Quintela, Laurent Vivier,
	Paolo Bonzini, Thomas Huth

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

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

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

Changes in v3:
- Add a usleep(1) in the busy wait loop

Changes in v2:
- Change to a busy wait after migration is canceled

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

diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index a1dd342739..9ec501d1eb 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -2132,6 +2132,10 @@ static void test_multifd_tcp_cancel(void)
     wait_for_migration_pass(from);
 
     migrate_cancel(from);
+    /* Make sure QEMU process "to" exited */
+    while (qtest_probe_child(to)) {
+        usleep(1);
+    }
 
     args = (MigrateStart){
         .only_target = true,
-- 
2.34.1



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

* [PATCH v3 44/54] tests/qtest: microbit-test: Fix socket access for win32
  2022-09-25 11:29 [PATCH v3 00/54] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (42 preceding siblings ...)
  2022-09-25 11:30 ` [PATCH v3 43/54] tests/qtest: migration-test: Make sure QEMU process "to" exited after migration is canceled Bin Meng
@ 2022-09-25 11:30 ` Bin Meng
  2022-09-25 11:30 ` [PATCH v3 45/54] tests/qtest: libqtest: Replace the call to close a socket with closesocket() Bin Meng
                   ` (9 subsequent siblings)
  53 siblings, 0 replies; 89+ messages in thread
From: Bin Meng @ 2022-09-25 11:30 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Bin Meng, Joel Stanley, Laurent Vivier,
	Paolo Bonzini, Peter Maydell, Thomas Huth, qemu-arm

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

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

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

Signed-off-by: Bin Meng <bin.meng@windriver.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---

(no changes since v1)

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

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



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

* [PATCH v3 45/54] tests/qtest: libqtest: Replace the call to close a socket with closesocket()
  2022-09-25 11:29 [PATCH v3 00/54] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (43 preceding siblings ...)
  2022-09-25 11:30 ` [PATCH v3 44/54] tests/qtest: microbit-test: Fix socket access for win32 Bin Meng
@ 2022-09-25 11:30 ` Bin Meng
  2022-09-25 11:30 ` [PATCH v3 46/54] tests/qtest: libqtest: Correct the timeout unit of blocking receive calls for win32 Bin Meng
                   ` (8 subsequent siblings)
  53 siblings, 0 replies; 89+ messages in thread
From: Bin Meng @ 2022-09-25 11:30 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Bin Meng, Laurent Vivier, Paolo Bonzini,
	Thomas Huth

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

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

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

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

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

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

Signed-off-by: Bin Meng <bin.meng@windriver.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---

(no changes since v1)

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

diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
index 12b1e85b51..1ae58624d9 100644
--- a/tests/qtest/libqtest.c
+++ b/tests/qtest/libqtest.c
@@ -113,7 +113,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;
     }
 
@@ -124,7 +124,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;
 }
@@ -507,8 +507,8 @@ void qtest_quit(QTestState *s)
     qtest_remove_abrt_handler(s);
 
     qtest_kill_qemu(s);
-    close(s->fd);
-    close(s->qmp_fd);
+    closesocket(s->fd);
+    closesocket(s->qmp_fd);
     g_string_free(s->rx, true);
 
     for (GList *it = s->pending_events; it != NULL; it = it->next) {
-- 
2.34.1



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

* [PATCH v3 46/54] tests/qtest: libqtest: Correct the timeout unit of blocking receive calls for win32
  2022-09-25 11:29 [PATCH v3 00/54] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (44 preceding siblings ...)
  2022-09-25 11:30 ` [PATCH v3 45/54] tests/qtest: libqtest: Replace the call to close a socket with closesocket() Bin Meng
@ 2022-09-25 11:30 ` Bin Meng
  2022-09-25 11:30 ` [PATCH v3 47/54] io/channel-watch: Drop a superfluous '#ifdef WIN32' Bin Meng
                   ` (7 subsequent siblings)
  53 siblings, 0 replies; 89+ messages in thread
From: Bin Meng @ 2022-09-25 11:30 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Bin Meng, Laurent Vivier, Paolo Bonzini,
	Thomas Huth

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

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

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

Signed-off-by: Bin Meng <bin.meng@windriver.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---

(no changes since v1)

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

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



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

* [PATCH v3 47/54] io/channel-watch: Drop a superfluous '#ifdef WIN32'
  2022-09-25 11:29 [PATCH v3 00/54] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (45 preceding siblings ...)
  2022-09-25 11:30 ` [PATCH v3 46/54] tests/qtest: libqtest: Correct the timeout unit of blocking receive calls for win32 Bin Meng
@ 2022-09-25 11:30 ` Bin Meng
  2022-09-25 11:30 ` [PATCH v3 48/54] io/channel-watch: Drop the unnecessary cast Bin Meng
                   ` (6 subsequent siblings)
  53 siblings, 0 replies; 89+ messages in thread
From: Bin Meng @ 2022-09-25 11:30 UTC (permalink / raw)
  To: qemu-devel; +Cc: Marc-André Lureau, Bin Meng, Daniel P. Berrangé

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

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

Signed-off-by: Bin Meng <bin.meng@windriver.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---

(no changes since v1)

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

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



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

* [PATCH v3 48/54] io/channel-watch: Drop the unnecessary cast
  2022-09-25 11:29 [PATCH v3 00/54] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (46 preceding siblings ...)
  2022-09-25 11:30 ` [PATCH v3 47/54] io/channel-watch: Drop a superfluous '#ifdef WIN32' Bin Meng
@ 2022-09-25 11:30 ` Bin Meng
  2022-09-25 11:30 ` [PATCH v3 49/54] io/channel-watch: Fix socket watch on Windows Bin Meng
                   ` (5 subsequent siblings)
  53 siblings, 0 replies; 89+ messages in thread
From: Bin Meng @ 2022-09-25 11:30 UTC (permalink / raw)
  To: qemu-devel; +Cc: Marc-André Lureau, Bin Meng, Daniel P. Berrangé

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

There is no need to do a type cast on ssource->socket as it is
already declared as a SOCKET.

Suggested-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Bin Meng <bin.meng@windriver.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---

(no changes since v2)

Changes in v2:
- new patch: "io/channel-watch: Drop the unnecessary cast"

 io/channel-watch.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/io/channel-watch.c b/io/channel-watch.c
index 89f3c8a88a..43d38494f7 100644
--- a/io/channel-watch.c
+++ b/io/channel-watch.c
@@ -130,13 +130,13 @@ qio_channel_socket_source_check(GSource *source)
     FD_ZERO(&wfds);
     FD_ZERO(&xfds);
     if (ssource->condition & G_IO_IN) {
-        FD_SET((SOCKET)ssource->socket, &rfds);
+        FD_SET(ssource->socket, &rfds);
     }
     if (ssource->condition & G_IO_OUT) {
-        FD_SET((SOCKET)ssource->socket, &wfds);
+        FD_SET(ssource->socket, &wfds);
     }
     if (ssource->condition & G_IO_PRI) {
-        FD_SET((SOCKET)ssource->socket, &xfds);
+        FD_SET(ssource->socket, &xfds);
     }
     ssource->revents = 0;
     if (select(0, &rfds, &wfds, &xfds, &tv0) == 0) {
-- 
2.34.1



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

* [PATCH v3 49/54] io/channel-watch: Fix socket watch on Windows
  2022-09-25 11:29 [PATCH v3 00/54] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (47 preceding siblings ...)
  2022-09-25 11:30 ` [PATCH v3 48/54] io/channel-watch: Drop the unnecessary cast Bin Meng
@ 2022-09-25 11:30 ` Bin Meng
  2022-09-25 11:30 ` [PATCH v3 50/54] tests/qtest: migration-test: Skip running some TLS cases for win32 Bin Meng
                   ` (4 subsequent siblings)
  53 siblings, 0 replies; 89+ messages in thread
From: Bin Meng @ 2022-09-25 11:30 UTC (permalink / raw)
  To: qemu-devel; +Cc: Marc-André Lureau, Bin Meng, Daniel P. Berrangé

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

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

tcp_chr_read() is registered as the callback of the socket watch
GSource. The reason of the callback not being called by glib, is
that the source check fails to indicate the source is ready. There
are two socket watch sources created to monitor the same socket
event object from the char-socket backend in update_ioc_handlers().
During the source check phase, qio_channel_socket_source_check()
calls WSAEnumNetworkEvents() to discover 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 seems 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.

Some side notes:

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.

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

(no changes since v1)

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

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



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

* [PATCH v3 50/54] tests/qtest: migration-test: Skip running some TLS cases for win32
  2022-09-25 11:29 [PATCH v3 00/54] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (48 preceding siblings ...)
  2022-09-25 11:30 ` [PATCH v3 49/54] io/channel-watch: Fix socket watch on Windows Bin Meng
@ 2022-09-25 11:30 ` Bin Meng
  2022-09-25 11:30 ` [PATCH v3 51/54] .gitlab-ci.d/windows.yml: Increase the timeout to 90 minutes Bin Meng
                   ` (3 subsequent siblings)
  53 siblings, 0 replies; 89+ messages in thread
From: Bin Meng @ 2022-09-25 11:30 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Bin Meng, Dr. David Alan Gilbert,
	Juan Quintela, Laurent Vivier, Paolo Bonzini, Thomas Huth

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

Some migration test cases use TLS to communicate, but they fail on
Windows with the following error messages:

  qemu-system-x86_64: TLS handshake failed: Insufficient credentials for that request.
  qemu-system-x86_64: TLS handshake failed: Error in the pull function.
  query-migrate shows failed migration: TLS handshake failed: Error in the pull function.

Disable them temporarily.

Signed-off-by: Bin Meng <bin.meng@windriver.com>
---
I am not familar with the gnutls and simply enabling the gnutls debug
output does not give me an immedidate hint on why it's failing on
Windows. Disable these cases for now until someone or maintainers
who may want to test this on Windows.

(no changes since v1)

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

diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index 9ec501d1eb..e22637a4e3 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -1402,6 +1402,7 @@ static void test_precopy_unix_dirty_ring(void)
 }
 
 #ifdef CONFIG_GNUTLS
+#ifndef _WIN32
 static void test_precopy_unix_tls_psk(void)
 {
     g_autofree char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs);
@@ -1414,6 +1415,7 @@ static void test_precopy_unix_tls_psk(void)
 
     test_precopy_common(&args);
 }
+#endif /* _WIN32 */
 
 #ifdef CONFIG_TASN1
 static void test_precopy_unix_tls_x509_default_host(void)
@@ -1522,6 +1524,7 @@ static void test_precopy_tcp_plain(void)
 }
 
 #ifdef CONFIG_GNUTLS
+#ifndef _WIN32
 static void test_precopy_tcp_tls_psk_match(void)
 {
     MigrateCommon args = {
@@ -1532,6 +1535,7 @@ static void test_precopy_tcp_tls_psk_match(void)
 
     test_precopy_common(&args);
 }
+#endif /* _WIN32 */
 
 static void test_precopy_tcp_tls_psk_mismatch(void)
 {
@@ -1929,6 +1933,7 @@ static void test_multifd_tcp_zstd(void)
 #endif
 
 #ifdef CONFIG_GNUTLS
+#ifndef _WIN32
 static void *
 test_migrate_multifd_tcp_tls_psk_start_match(QTestState *from,
                                              QTestState *to)
@@ -1936,6 +1941,7 @@ test_migrate_multifd_tcp_tls_psk_start_match(QTestState *from,
     test_migrate_precopy_tcp_multifd_start_common(from, to, "none");
     return test_migrate_tls_psk_start_match(from, to);
 }
+#endif /* _WIN32 */
 
 static void *
 test_migrate_multifd_tcp_tls_psk_start_mismatch(QTestState *from,
@@ -1987,6 +1993,7 @@ test_migrate_multifd_tls_x509_start_reject_anon_client(QTestState *from,
 }
 #endif /* CONFIG_TASN1 */
 
+#ifndef _WIN32
 static void test_multifd_tcp_tls_psk_match(void)
 {
     MigrateCommon args = {
@@ -1996,6 +2003,7 @@ static void test_multifd_tcp_tls_psk_match(void)
     };
     test_precopy_common(&args);
 }
+#endif /* _WIN32 */
 
 static void test_multifd_tcp_tls_psk_mismatch(void)
 {
@@ -2496,8 +2504,10 @@ int main(int argc, char **argv)
     qtest_add_func("/migration/precopy/unix/plain", test_precopy_unix_plain);
     qtest_add_func("/migration/precopy/unix/xbzrle", test_precopy_unix_xbzrle);
 #ifdef CONFIG_GNUTLS
+#ifndef _WIN32
     qtest_add_func("/migration/precopy/unix/tls/psk",
                    test_precopy_unix_tls_psk);
+#endif
 
     if (has_uffd) {
         /*
@@ -2523,8 +2533,10 @@ int main(int argc, char **argv)
 
     qtest_add_func("/migration/precopy/tcp/plain", test_precopy_tcp_plain);
 #ifdef CONFIG_GNUTLS
+#ifndef _WIN32
     qtest_add_func("/migration/precopy/tcp/tls/psk/match",
                    test_precopy_tcp_tls_psk_match);
+#endif
     qtest_add_func("/migration/precopy/tcp/tls/psk/mismatch",
                    test_precopy_tcp_tls_psk_mismatch);
 #ifdef CONFIG_TASN1
@@ -2568,8 +2580,10 @@ int main(int argc, char **argv)
                    test_multifd_tcp_zstd);
 #endif
 #ifdef CONFIG_GNUTLS
+#ifndef _WIN32
     qtest_add_func("/migration/multifd/tcp/tls/psk/match",
                    test_multifd_tcp_tls_psk_match);
+#endif
     qtest_add_func("/migration/multifd/tcp/tls/psk/mismatch",
                    test_multifd_tcp_tls_psk_mismatch);
 #ifdef CONFIG_TASN1
-- 
2.34.1



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

* [PATCH v3 51/54] .gitlab-ci.d/windows.yml: Increase the timeout to 90 minutes
  2022-09-25 11:29 [PATCH v3 00/54] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (49 preceding siblings ...)
  2022-09-25 11:30 ` [PATCH v3 50/54] tests/qtest: migration-test: Skip running some TLS cases for win32 Bin Meng
@ 2022-09-25 11:30 ` Bin Meng
  2022-09-25 11:30 ` [PATCH v3 52/54] .gitlab-ci.d/windows.yml: Display meson test logs Bin Meng
                   ` (2 subsequent siblings)
  53 siblings, 0 replies; 89+ messages in thread
From: Bin Meng @ 2022-09-25 11:30 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Bin Meng, Alex Bennée, Beraldo Leal,
	Philippe Mathieu-Daudé,
	Thomas Huth, Wainer dos Santos Moschetta

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

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

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

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

(no changes since v2)

Changes in v2:
- Change the timeout limit to 90 minutes

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

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



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

* [PATCH v3 52/54] .gitlab-ci.d/windows.yml: Display meson test logs
  2022-09-25 11:29 [PATCH v3 00/54] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (50 preceding siblings ...)
  2022-09-25 11:30 ` [PATCH v3 51/54] .gitlab-ci.d/windows.yml: Increase the timeout to 90 minutes Bin Meng
@ 2022-09-25 11:30 ` Bin Meng
  2022-09-26 16:46   ` Thomas Huth
  2022-09-25 11:30 ` [PATCH v3 53/54] tests/qtest: Enable qtest build on Windows Bin Meng
  2022-09-25 11:30 ` [PATCH v3 54/54] docs/devel: testing: Document writing portable test cases Bin Meng
  53 siblings, 1 reply; 89+ messages in thread
From: Bin Meng @ 2022-09-25 11:30 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Bin Meng, Alex Bennée, Beraldo Leal,
	Philippe Mathieu-Daudé,
	Thomas Huth, Wainer dos Santos Moschetta

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

When CI fails we don't know what causes the failure. Displaying the
meson test logs can be helpful.

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

(no changes since v2)

Changes in v2:
- new patch: Display meson test logs in the Windows CI

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

diff --git a/.gitlab-ci.d/windows.yml b/.gitlab-ci.d/windows.yml
index 9ef4667317..29a3ba04a4 100644
--- a/.gitlab-ci.d/windows.yml
+++ b/.gitlab-ci.d/windows.yml
@@ -61,7 +61,7 @@ msys2-64bit:
   - .\msys64\usr\bin\bash -lc './configure --target-list=x86_64-softmmu
       --enable-capstone'
   - .\msys64\usr\bin\bash -lc 'make'
-  - .\msys64\usr\bin\bash -lc 'make check'
+  - .\msys64\usr\bin\bash -lc 'make check || { cat build/meson-logs/testlog.txt; exit 1; } ;'
 
 msys2-32bit:
   extends: .shared_msys2_builder
@@ -94,4 +94,4 @@ msys2-32bit:
   - cd output
   - ..\msys64\usr\bin\bash -lc "../configure --target-list=ppc64-softmmu"
   - ..\msys64\usr\bin\bash -lc 'make'
-  - ..\msys64\usr\bin\bash -lc 'make check'
+  - ..\msys64\usr\bin\bash -lc 'make check || { cat meson-logs/testlog.txt; exit 1; } ;'
-- 
2.34.1



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

* [PATCH v3 53/54] tests/qtest: Enable qtest build on Windows
  2022-09-25 11:29 [PATCH v3 00/54] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (51 preceding siblings ...)
  2022-09-25 11:30 ` [PATCH v3 52/54] .gitlab-ci.d/windows.yml: Display meson test logs Bin Meng
@ 2022-09-25 11:30 ` Bin Meng
  2022-09-25 11:30 ` [PATCH v3 54/54] docs/devel: testing: Document writing portable test cases Bin Meng
  53 siblings, 0 replies; 89+ messages in thread
From: Bin Meng @ 2022-09-25 11:30 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Bin Meng, Laurent Vivier, Paolo Bonzini,
	Thomas Huth

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

Now that we have fixed various test case issues as seen when running
on Windows, let's enable the qtest build on Windows.

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

Changes in v3:
- Drop the host test

Changes in v2:
- new patch: "tests/qtest: Enable qtest build on Windows"

 tests/qtest/meson.build | 6 ------
 1 file changed, 6 deletions(-)

diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
index 455f1bbb7e..8701c3a8e7 100644
--- a/tests/qtest/meson.build
+++ b/tests/qtest/meson.build
@@ -1,9 +1,3 @@
-# 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')
-  subdir_done()
-endif
-
 slow_qtests = {
   'ahci-test' : 60,
   'bios-tables-test' : 120,
-- 
2.34.1



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

* [PATCH v3 54/54] docs/devel: testing: Document writing portable test cases
  2022-09-25 11:29 [PATCH v3 00/54] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (52 preceding siblings ...)
  2022-09-25 11:30 ` [PATCH v3 53/54] tests/qtest: Enable qtest build on Windows Bin Meng
@ 2022-09-25 11:30 ` Bin Meng
  2022-09-26 16:55   ` Thomas Huth
  53 siblings, 1 reply; 89+ messages in thread
From: Bin Meng @ 2022-09-25 11:30 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Bin Meng, Alex Bennée,
	Paolo Bonzini, Philippe Mathieu-Daudé,
	Thomas Huth, Willian Rampazzo

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

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

Signed-off-by: Bin Meng <bin.meng@windriver.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---

(no changes since v3)

Changes in v2:
- Minor wording changes
- Drop patches that were already applied in the mainline
- Drop patch: "qga/commands-posix-ssh: Use g_mkdir_with_parents()"
- Drop patch: "tests: Skip iotests and qtest when '--without-default-devices'"
- Drop patch: "tests/qtest: Fix ERROR_SHARING_VIOLATION for win32"

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

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



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

* Re: [PATCH v3 38/54] tests/qtest: bios-tables-test: Adapt the case for win32
  2022-09-25 11:30 ` [PATCH v3 38/54] tests/qtest: bios-tables-test: Adapt the case " Bin Meng
@ 2022-09-25 12:41   ` Michael S. Tsirkin
  0 siblings, 0 replies; 89+ messages in thread
From: Michael S. Tsirkin @ 2022-09-25 12:41 UTC (permalink / raw)
  To: Bin Meng
  Cc: qemu-devel, Marc-André Lureau, Bin Meng, Ani Sinha, Igor Mammedov

On Sun, Sep 25, 2022 at 07:30:16PM +0800, Bin Meng wrote:
> From: Bin Meng <bin.meng@windriver.com>
> 
> Single quotes in the arguments (oem_id='CRASH ') are not removed in
> the Windows environment before it is passed to the QEMU executable.
> The space in the argument causes the "-acpitable" option parser to
> think that all of its parameters are done, hence it complains:
> 
>   '-acpitable' requires one of 'data' or 'file'
> 
> Change to use double quotes which works fine on all platforms.
> 
> Also /dev/null does not work on win32, and nul should be used.
> 
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>

Acked-by: Michael S. Tsirkin <mst@redhat.com>

Feel free to merge with rest of the patchset.

> ---
> 
> (no changes since v1)
> 
>  tests/qtest/bios-tables-test.c | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
> 
> diff --git a/tests/qtest/bios-tables-test.c b/tests/qtest/bios-tables-test.c
> index 46a46fe0aa..2ebeb530b2 100644
> --- a/tests/qtest/bios-tables-test.c
> +++ b/tests/qtest/bios-tables-test.c
> @@ -1615,6 +1615,12 @@ static void test_acpi_virt_viot(void)
>      free_test_data(&data);
>  }
>  
> +#ifndef _WIN32
> +# define DEV_NULL "/dev/null"
> +#else
> +# define DEV_NULL "nul"
> +#endif
> +
>  static void test_acpi_q35_slic(void)
>  {
>      test_data data = {
> @@ -1622,9 +1628,9 @@ static void test_acpi_q35_slic(void)
>          .variant = ".slic",
>      };
>  
> -    test_acpi_one("-acpitable sig=SLIC,oem_id='CRASH ',oem_table_id='ME',"
> -                  "oem_rev=00002210,asl_compiler_id='qemu',"
> -                  "asl_compiler_rev=00000000,data=/dev/null",
> +    test_acpi_one("-acpitable sig=SLIC,oem_id=\"CRASH \",oem_table_id=ME,"
> +                  "oem_rev=00002210,asl_compiler_id=qemu,"
> +                  "asl_compiler_rev=00000000,data=" DEV_NULL,
>                    &data);
>      free_test_data(&data);
>  }
> -- 
> 2.34.1



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

* Re: [PATCH v3 06/54] tests/qtest: aspeed_smc-test: Avoid using hardcoded /tmp
  2022-09-25 11:29 ` [PATCH v3 06/54] tests/qtest: aspeed_smc-test: " Bin Meng
@ 2022-09-25 16:20   ` Cédric Le Goater
  2022-09-26 12:18   ` Thomas Huth
  1 sibling, 0 replies; 89+ messages in thread
From: Cédric Le Goater @ 2022-09-25 16:20 UTC (permalink / raw)
  To: Bin Meng, qemu-devel
  Cc: Marc-André Lureau, Bin Meng, Andrew Jeffery, Joel Stanley,
	Laurent Vivier, Paolo Bonzini, Peter Maydell, Thomas Huth,
	qemu-arm

On 9/25/22 13:29, Bin Meng wrote:
> From: Bin Meng <bin.meng@windriver.com>
> 
> This case was written to use hardcoded /tmp directory for temporary
> files. Update to use g_file_open_tmp() for a portable implementation.
> 
> Signed-off-by: Bin Meng <bin.meng@windriver.com>

Reviewed-by: Cédric Le Goater <clg@kaod.org>

Thanks,

C.

> ---
> 
> Changes in v3:
> - Split to a separate patch
> - Ensure g_autofree variable is initialized
> 
>   tests/qtest/aspeed_smc-test.c | 5 ++---
>   1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/tests/qtest/aspeed_smc-test.c b/tests/qtest/aspeed_smc-test.c
> index 05ce941566..c713a3700b 100644
> --- a/tests/qtest/aspeed_smc-test.c
> +++ b/tests/qtest/aspeed_smc-test.c
> @@ -608,16 +608,15 @@ static void test_write_block_protect_bottom_bit(void)
>       flash_reset();
>   }
>   
> -static char tmp_path[] = "/tmp/qtest.m25p80.XXXXXX";
> -
>   int main(int argc, char **argv)
>   {
> +    g_autofree char *tmp_path = NULL;
>       int ret;
>       int fd;
>   
>       g_test_init(&argc, &argv, NULL);
>   
> -    fd = mkstemp(tmp_path);
> +    fd = g_file_open_tmp("qtest.m25p80.XXXXXX", &tmp_path, NULL);
>       g_assert(fd >= 0);
>       ret = ftruncate(fd, FLASH_SIZE);
>       g_assert(ret == 0);



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

* Re: [PATCH v3 01/54] tests/qtest: i440fx-test: Rewrite create_blob_file() to be portable
  2022-09-25 11:29 ` [PATCH v3 01/54] tests/qtest: i440fx-test: Rewrite create_blob_file() to be portable Bin Meng
@ 2022-09-26 12:10   ` Thomas Huth
  0 siblings, 0 replies; 89+ messages in thread
From: Thomas Huth @ 2022-09-26 12:10 UTC (permalink / raw)
  To: Bin Meng, qemu-devel
  Cc: Marc-André Lureau, Bin Meng, Laurent Vivier, Paolo Bonzini

On 25/09/2022 13.29, Bin Meng wrote:
> From: Bin Meng <bin.meng@windriver.com>
> 
> Previously request_{bios, pflash} cases were skipped on win32, mainly
> due to create_blob_file() calling mmap() which does not exist on win32.
> This rewirtes create_blob_file() to be portable, so that we can enable
> these cases on Windows.
> 
> Suggested-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
> 
> Changes in v3:
> - Remove unnecessary "error = NULL" statements
> 
> Changes in v2:
> - new patch: "tests/qtest: i440fx-test: Rewrite create_blob_file() to be portable"
> 
>   tests/qtest/i440fx-test.c | 54 ++++++++++-----------------------------
>   1 file changed, 14 insertions(+), 40 deletions(-)

Nice clean-up!

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



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

* Re: [PATCH v3 05/54] tests/qtest: ahci-test: Avoid using hardcoded /tmp
  2022-09-25 11:29 ` [PATCH v3 05/54] tests/qtest: ahci-test: Avoid using hardcoded /tmp Bin Meng
@ 2022-09-26 12:17   ` Thomas Huth
  0 siblings, 0 replies; 89+ messages in thread
From: Thomas Huth @ 2022-09-26 12:17 UTC (permalink / raw)
  To: Bin Meng, qemu-devel
  Cc: Marc-André Lureau, Bin Meng, John Snow, Laurent Vivier,
	Paolo Bonzini, qemu-block

On 25/09/2022 13.29, Bin Meng wrote:
> From: Bin Meng <bin.meng@windriver.com>
> 
> This case was written to use hardcoded /tmp directory for temporary
> files. Update to use g_file_open_tmp() for a portable implementation.
> 
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
> 
> Changes in v3:
> - Split to a separate patch
> - Ensure g_autofree variable is initialized
> 
>   tests/qtest/ahci-test.c | 19 +++++++++++--------
>   1 file changed, 11 insertions(+), 8 deletions(-)

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



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

* Re: [PATCH v3 06/54] tests/qtest: aspeed_smc-test: Avoid using hardcoded /tmp
  2022-09-25 11:29 ` [PATCH v3 06/54] tests/qtest: aspeed_smc-test: " Bin Meng
  2022-09-25 16:20   ` Cédric Le Goater
@ 2022-09-26 12:18   ` Thomas Huth
  1 sibling, 0 replies; 89+ messages in thread
From: Thomas Huth @ 2022-09-26 12:18 UTC (permalink / raw)
  To: Bin Meng, qemu-devel
  Cc: Marc-André Lureau, Bin Meng, Andrew Jeffery,
	Cédric Le Goater, Joel Stanley, Laurent Vivier,
	Paolo Bonzini, Peter Maydell, qemu-arm

On 25/09/2022 13.29, Bin Meng wrote:
> From: Bin Meng <bin.meng@windriver.com>
> 
> This case was written to use hardcoded /tmp directory for temporary
> files. Update to use g_file_open_tmp() for a portable implementation.
> 
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
> 
> Changes in v3:
> - Split to a separate patch
> - Ensure g_autofree variable is initialized
> 
>   tests/qtest/aspeed_smc-test.c | 5 ++---
>   1 file changed, 2 insertions(+), 3 deletions(-)

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



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

* Re: [PATCH v3 07/54] tests/qtest: boot-serial-test: Avoid using hardcoded /tmp
  2022-09-25 11:29 ` [PATCH v3 07/54] tests/qtest: boot-serial-test: " Bin Meng
@ 2022-09-26 12:22   ` Thomas Huth
  0 siblings, 0 replies; 89+ messages in thread
From: Thomas Huth @ 2022-09-26 12:22 UTC (permalink / raw)
  To: Bin Meng, qemu-devel
  Cc: Marc-André Lureau, Bin Meng, Laurent Vivier, Paolo Bonzini

On 25/09/2022 13.29, Bin Meng wrote:
> From: Bin Meng <bin.meng@windriver.com>
> 
> This case was written to use hardcoded /tmp directory for temporary
> files. Update to use g_file_open_tmp() for a portable implementation.
> 
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
> 
> Changes in v3:
> - Split to a separate patch
> - Ensure g_autofree variable is initialized
> 
>   tests/qtest/boot-serial-test.c | 8 ++++----
>   1 file changed, 4 insertions(+), 4 deletions(-)

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



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

* Re: [PATCH v3 08/54] tests/qtest: cxl-test: Avoid using hardcoded /tmp
  2022-09-25 11:29 ` [PATCH v3 08/54] tests/qtest: cxl-test: " Bin Meng
@ 2022-09-26 13:07   ` Marc-André Lureau
  0 siblings, 0 replies; 89+ messages in thread
From: Marc-André Lureau @ 2022-09-26 13:07 UTC (permalink / raw)
  To: Bin Meng; +Cc: qemu-devel, Bin Meng, Laurent Vivier, Paolo Bonzini, Thomas Huth

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

On Sun, Sep 25, 2022 at 3:54 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Bin Meng <bin.meng@windriver.com>
>
> This case was written to use hardcoded /tmp directory for temporary
> files. Update to use g_dir_make_tmp() for a portable implementation.
>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
>

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


> ---
>
> Changes in v3:
> - Split to a separate patch
> - Ensure g_autofree variable is initialized
>
>  tests/qtest/cxl-test.c | 15 ++++++---------
>  1 file changed, 6 insertions(+), 9 deletions(-)
>
> diff --git a/tests/qtest/cxl-test.c b/tests/qtest/cxl-test.c
> index 2e14da7dee..cbe0fb549b 100644
> --- a/tests/qtest/cxl-test.c
> +++ b/tests/qtest/cxl-test.c
> @@ -93,10 +93,9 @@ 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";
> -    const char *tmpfs;
> +    g_autofree const char *tmpfs = NULL;
>
> -    tmpfs = g_mkdtemp(template);
> +    tmpfs = g_dir_make_tmp("cxl-test-XXXXXX", NULL);
>
>      g_string_printf(cmdline, QEMU_PXB_CMD QEMU_RP QEMU_T3D, tmpfs, tmpfs);
>
> @@ -107,10 +106,9 @@ 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";
> -    const char *tmpfs;
> +    g_autofree const char *tmpfs = NULL;
>
> -    tmpfs = g_mkdtemp(template);
> +    tmpfs = g_dir_make_tmp("cxl-test-XXXXXX", NULL);
>
>      g_string_printf(cmdline, QEMU_PXB_CMD QEMU_2RP QEMU_2T3D,
>                      tmpfs, tmpfs, tmpfs, tmpfs);
> @@ -122,10 +120,9 @@ 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";
> -    const char *tmpfs;
> +    g_autofree const char *tmpfs = NULL;
>
> -    tmpfs = g_mkdtemp(template);
> +    tmpfs = g_dir_make_tmp("cxl-test-XXXXXX", NULL);
>
>      g_string_printf(cmdline, QEMU_2PXB_CMD QEMU_4RP QEMU_4T3D,
>                      tmpfs, tmpfs, tmpfs, tmpfs, tmpfs, tmpfs,
> --
> 2.34.1
>
>
>

-- 
Marc-André Lureau

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

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

* Re: [PATCH v3 09/54] tests/qtest: fdc-test: Avoid using hardcoded /tmp
  2022-09-25 11:29 ` [PATCH v3 09/54] tests/qtest: fdc-test: " Bin Meng
@ 2022-09-26 13:08   ` Marc-André Lureau
  0 siblings, 0 replies; 89+ messages in thread
From: Marc-André Lureau @ 2022-09-26 13:08 UTC (permalink / raw)
  To: Bin Meng
  Cc: qemu-devel, Bin Meng, John Snow, Laurent Vivier, Paolo Bonzini,
	Thomas Huth, qemu-block

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

On Sun, Sep 25, 2022 at 3:49 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Bin Meng <bin.meng@windriver.com>
>
> This case was written to use hardcoded /tmp directory for temporary
> files. Update to use g_file_open_tmp() for a portable implementation.
>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
>

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



> ---
>
> Changes in v3:
> - Split to a separate patch
>
>  tests/qtest/fdc-test.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/tests/qtest/fdc-test.c b/tests/qtest/fdc-test.c
> index 52ade90a7d..1f9b99ad6d 100644
> --- a/tests/qtest/fdc-test.c
> +++ b/tests/qtest/fdc-test.c
> @@ -68,7 +68,7 @@ enum {
>      DSKCHG  = 0x80,
>  };
>
> -static char test_image[] = "/tmp/qtest.XXXXXX";
> +static char *test_image;
>
>  #define assert_bit_set(data, mask) g_assert_cmphex((data) & (mask), ==,
> (mask))
>  #define assert_bit_clear(data, mask) g_assert_cmphex((data) & (mask), ==,
> 0)
> @@ -608,7 +608,7 @@ int main(int argc, char **argv)
>      int ret;
>
>      /* Create a temporary raw image */
> -    fd = mkstemp(test_image);
> +    fd = g_file_open_tmp("qtest.XXXXXX", &test_image, NULL);
>      g_assert(fd >= 0);
>      ret = ftruncate(fd, TEST_IMAGE_SIZE);
>      g_assert(ret == 0);
> @@ -640,6 +640,7 @@ int main(int argc, char **argv)
>      /* Cleanup */
>      qtest_end();
>      unlink(test_image);
> +    g_free(test_image);
>
>      return ret;
>  }
> --
> 2.34.1
>
>
>

-- 
Marc-André Lureau

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

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

* Re: [PATCH v3 10/54] tests/qtest: generic_fuzz: Avoid using hardcoded /tmp
  2022-09-25 11:29 ` [PATCH v3 10/54] tests/qtest: generic_fuzz: " Bin Meng
@ 2022-09-26 13:09   ` Marc-André Lureau
  0 siblings, 0 replies; 89+ messages in thread
From: Marc-André Lureau @ 2022-09-26 13:09 UTC (permalink / raw)
  To: Bin Meng
  Cc: qemu-devel, Bin Meng, Alexander Bulekov, Bandan Das,
	Darren Kenny, Laurent Vivier, Paolo Bonzini, Qiuhao Li,
	Stefan Hajnoczi, Thomas Huth

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

On Sun, Sep 25, 2022 at 3:37 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Bin Meng <bin.meng@windriver.com>
>
> This case was written to use hardcoded /tmp directory for temporary
> files. Update to use g_dir_make_tmp() for a portable implementation.
>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
>
> Changes in v3:
> - Split to a separate patch
>
>  tests/qtest/fuzz/generic_fuzz_configs.h | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/tests/qtest/fuzz/generic_fuzz_configs.h
> b/tests/qtest/fuzz/generic_fuzz_configs.h
> index 0775e6702b..a825b78c14 100644
> --- a/tests/qtest/fuzz/generic_fuzz_configs.h
> +++ b/tests/qtest/fuzz/generic_fuzz_configs.h
> @@ -20,8 +20,8 @@ typedef struct generic_fuzz_config {
>  } generic_fuzz_config;
>
>  static inline gchar *generic_fuzzer_virtio_9p_args(void){
> -    char tmpdir[] = "/tmp/qemu-fuzz.XXXXXX";
> -    g_assert_nonnull(g_mkdtemp(tmpdir));
> +    g_autofree char *tmpdir = g_dir_make_tmp("qemu-fuzz.XXXXXX", NULL);
> +    g_assert_nonnull(tmpdir);
>

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



>
>      return g_strdup_printf("-machine q35 -nodefaults "
>      "-device virtio-9p,fsdev=hshare,mount_tag=hshare "
> --
> 2.34.1
>
>
>

-- 
Marc-André Lureau

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

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

* Re: [PATCH v3 11/54] tests/qtest: virtio_blk_fuzz: Avoid using hardcoded /tmp
  2022-09-25 11:29 ` [PATCH v3 11/54] tests/qtest: virtio_blk_fuzz: " Bin Meng
@ 2022-09-26 13:11   ` Marc-André Lureau
  0 siblings, 0 replies; 89+ messages in thread
From: Marc-André Lureau @ 2022-09-26 13:11 UTC (permalink / raw)
  To: Bin Meng
  Cc: qemu-devel, Bin Meng, Alexander Bulekov, Bandan Das,
	Darren Kenny, Laurent Vivier, Paolo Bonzini, Qiuhao Li,
	Stefan Hajnoczi, Thomas Huth

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

On Sun, Sep 25, 2022 at 3:41 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Bin Meng <bin.meng@windriver.com>
>
> This case was written to use hardcoded /tmp directory for temporary
> files. Update to use g_file_open_tmp() for a portable implementation.
>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
>

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


> ---
>
> Changes in v3:
> - Split to a separate patch
>
>  tests/qtest/fuzz/virtio_blk_fuzz.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/tests/qtest/fuzz/virtio_blk_fuzz.c
> b/tests/qtest/fuzz/virtio_blk_fuzz.c
> index 236d078cc8..a9fb9ecf6c 100644
> --- a/tests/qtest/fuzz/virtio_blk_fuzz.c
> +++ b/tests/qtest/fuzz/virtio_blk_fuzz.c
> @@ -181,10 +181,10 @@ 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;
>
>      /* Create a temporary raw image */
> -    fd = mkstemp(t_path);
> +    fd = g_file_open_tmp("qtest.XXXXXX", &t_path, NULL);
>      g_assert_cmpint(fd, >=, 0);
>      ret = ftruncate(fd, TEST_IMAGE_SIZE);
>      g_assert_cmpint(ret, ==, 0);
> --
> 2.34.1
>
>
>

-- 
Marc-André Lureau

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

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

* Re: [PATCH v3 12/54] tests/qtest: hd-geo-test: Avoid using hardcoded /tmp
  2022-09-25 11:29 ` [PATCH v3 12/54] tests/qtest: hd-geo-test: " Bin Meng
@ 2022-09-26 13:11   ` Marc-André Lureau
  2022-09-26 15:38   ` Thomas Huth
  1 sibling, 0 replies; 89+ messages in thread
From: Marc-André Lureau @ 2022-09-26 13:11 UTC (permalink / raw)
  To: Bin Meng; +Cc: qemu-devel, Bin Meng, Laurent Vivier, Paolo Bonzini, Thomas Huth

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

On Sun, Sep 25, 2022 at 3:58 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Bin Meng <bin.meng@windriver.com>
>
> This case was written to use hardcoded /tmp directory for temporary
> files. Update to use g_file_open_tmp() for a portable implementation.
>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
>

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



> ---
>
> Changes in v3:
> - Split to a separate patch
> - Ensure g_autofree variable is initialized
> - Use g_steal_pointer() in create_test_img()
>
>  tests/qtest/hd-geo-test.c | 25 +++++++++++--------------
>  1 file changed, 11 insertions(+), 14 deletions(-)
>
> diff --git a/tests/qtest/hd-geo-test.c b/tests/qtest/hd-geo-test.c
> index 413cf964c0..455bc5db5c 100644
> --- a/tests/qtest/hd-geo-test.c
> +++ b/tests/qtest/hd-geo-test.c
> @@ -27,20 +27,19 @@
>
>  static char *create_test_img(int secs)
>  {
> -    char *template = strdup("/tmp/qtest.XXXXXX");
> +    g_autofree char *template = NULL;
>      int fd, ret;
>
> -    fd = mkstemp(template);
> +    fd = g_file_open_tmp("qtest.XXXXXX", &template, NULL);
>      g_assert(fd >= 0);
>      ret = ftruncate(fd, (off_t)secs * 512);
>      close(fd);
>
>      if (ret) {
> -        free(template);
>          template = NULL;
>      }
>
> -    return template;
> +    return g_steal_pointer(&template);
>  }
>
>  typedef struct {
> @@ -422,9 +421,8 @@ 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";
> -    char *raw_path = strdup(template);
> -    char *qcow2_path = strdup(template);
> +    g_autofree char *raw_path = NULL;
> +    char *qcow2_path;
>      char cmd[100 + 2 * PATH_MAX];
>      uint8_t buf[512] = {};
>      int i, ret, fd, offset;
> @@ -468,7 +466,7 @@ static char *create_qcow2_with_mbr(MBRpartitions mbr,
> uint64_t sectors)
>          offset += 0x10;
>      }
>
> -    fd = mkstemp(raw_path);
> +    fd = g_file_open_tmp("qtest.XXXXXX", &raw_path, NULL);
>      g_assert(fd >= 0);
>      close(fd);
>
> @@ -478,7 +476,7 @@ static char *create_qcow2_with_mbr(MBRpartitions mbr,
> uint64_t sectors)
>      g_assert(ret == sizeof(buf));
>      close(fd);
>
> -    fd = mkstemp(qcow2_path);
> +    fd = g_file_open_tmp("qtest.XXXXXX", &qcow2_path, NULL);
>      g_assert(fd >= 0);
>      close(fd);
>
> @@ -506,7 +504,6 @@ static char *create_qcow2_with_mbr(MBRpartitions mbr,
> uint64_t sectors)
>      free(qemu_img_abs_path);
>
>      unlink(raw_path);
> -    free(raw_path);
>
>      return qcow2_path;
>  }
> @@ -714,7 +711,7 @@ static void test_override(TestArgs *args, CHSResult
> expected[])
>
>      for (i = 0; i < args->n_drives; i++) {
>          unlink(args->drives[i]);
> -        free(args->drives[i]);
> +        g_free(args->drives[i]);
>      }
>      g_free(args->drives);
>      g_strfreev(args->argv);
> @@ -867,7 +864,7 @@ static void test_override_scsi_hot_unplug(void)
>
>      for (i = 0; i < args->n_drives; i++) {
>          unlink(args->drives[i]);
> -        free(args->drives[i]);
> +        g_free(args->drives[i]);
>      }
>      g_free(args->drives);
>      g_strfreev(args->argv);
> @@ -927,7 +924,7 @@ static void test_override_virtio_hot_unplug(void)
>
>      for (i = 0; i < args->n_drives; i++) {
>          unlink(args->drives[i]);
> -        free(args->drives[i]);
> +        g_free(args->drives[i]);
>      }
>      g_free(args->drives);
>      g_strfreev(args->argv);
> @@ -987,7 +984,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]);
>          }
>      }
>
> --
> 2.34.1
>
>
>

-- 
Marc-André Lureau

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

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

* Re: [PATCH v3 13/54] tests/qtest: ide-test: Avoid using hardcoded /tmp
  2022-09-25 11:29 ` [PATCH v3 13/54] tests/qtest: ide-test: " Bin Meng
@ 2022-09-26 13:12   ` Marc-André Lureau
  0 siblings, 0 replies; 89+ messages in thread
From: Marc-André Lureau @ 2022-09-26 13:12 UTC (permalink / raw)
  To: Bin Meng
  Cc: qemu-devel, Bin Meng, John Snow, Laurent Vivier, Paolo Bonzini,
	Thomas Huth, qemu-block

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

On Sun, Sep 25, 2022 at 3:56 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Bin Meng <bin.meng@windriver.com>
>
> This case was written to use hardcoded /tmp directory for temporary
> files. Update to use g_file_open_tmp() for a portable implementation.
>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
>

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



> ---
>
> Changes in v3:
> - Split to a separate patch
>
>  tests/qtest/ide-test.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/tests/qtest/ide-test.c b/tests/qtest/ide-test.c
> index 5bcb75a7e5..25302be6dc 100644
> --- a/tests/qtest/ide-test.c
> +++ b/tests/qtest/ide-test.c
> @@ -121,8 +121,8 @@ enum {
>  static QPCIBus *pcibus = NULL;
>  static QGuestAllocator guest_malloc;
>
> -static char tmp_path[] = "/tmp/qtest.XXXXXX";
> -static char debug_path[] = "/tmp/qtest-blkdebug.XXXXXX";
> +static char *tmp_path;
> +static char *debug_path;
>
>  static QTestState *ide_test_start(const char *cmdline_fmt, ...)
>  {
> @@ -1015,12 +1015,12 @@ int main(int argc, char **argv)
>      int ret;
>
>      /* Create temporary blkdebug instructions */
> -    fd = mkstemp(debug_path);
> +    fd = g_file_open_tmp("qtest-blkdebug.XXXXXX", &debug_path, NULL);
>      g_assert(fd >= 0);
>      close(fd);
>
>      /* Create a temporary raw image */
> -    fd = mkstemp(tmp_path);
> +    fd = g_file_open_tmp("qtest.XXXXXX", &tmp_path, NULL);
>      g_assert(fd >= 0);
>      ret = ftruncate(fd, TEST_IMAGE_SIZE);
>      g_assert(ret == 0);
> @@ -1049,7 +1049,9 @@ int main(int argc, char **argv)
>
>      /* Cleanup */
>      unlink(tmp_path);
> +    g_free(tmp_path);
>      unlink(debug_path);
> +    g_free(debug_path);
>
>      return ret;
>  }
> --
> 2.34.1
>
>
>

-- 
Marc-André Lureau

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

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

* Re: [PATCH v3 14/54] tests/qtest: migration-test: Avoid using hardcoded /tmp
  2022-09-25 11:29 ` [PATCH v3 14/54] tests/qtest: migration-test: " Bin Meng
@ 2022-09-26 13:15   ` Marc-André Lureau
  0 siblings, 0 replies; 89+ messages in thread
From: Marc-André Lureau @ 2022-09-26 13:15 UTC (permalink / raw)
  To: Bin Meng
  Cc: qemu-devel, Bin Meng, Dr. David Alan Gilbert, Juan Quintela,
	Laurent Vivier, Paolo Bonzini, Thomas Huth

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

Hi

On Sun, Sep 25, 2022 at 3:52 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Bin Meng <bin.meng@windriver.com>
>
> This case was written to use hardcoded /tmp directory for temporary
> files. Update to use g_dir_make_tmp() for a portable implementation.
>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
>
> Changes in v3:
> - Split to a separate patch
>
>  tests/qtest/migration-test.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
> index 4728d528bb..029c4f3a6a 100644
> --- a/tests/qtest/migration-test.c
> +++ b/tests/qtest/migration-test.c
> @@ -2434,7 +2434,6 @@ static bool kvm_dirty_ring_supported(void)
>
>  int main(int argc, char **argv)
>  {
> -    char template[] = "/tmp/migration-test-XXXXXX";
>      const bool has_kvm = qtest_has_accel("kvm");
>      const bool has_uffd = ufd_version_check();
>      const char *arch = qtest_get_arch();
> @@ -2462,9 +2461,10 @@ int main(int argc, char **argv)
>          return g_test_run();
>      }
>
> -    tmpfs = g_mkdtemp(template);
> +    tmpfs = g_dir_make_tmp("migration-test-XXXXXX", NULL);
>      if (!tmpfs) {
> -        g_test_message("g_mkdtemp on path (%s): %s", template,
> strerror(errno));
> +        g_test_message("g_dir_make_tmp on path (%s): %s", tmpfs,
> +                       strerror(errno));
>

You need to update the error reporting by using the GError "error" argument
of g_dir_make_tmp().


>      }
>      g_assert(tmpfs);
>
> @@ -2589,6 +2589,7 @@ int main(int argc, char **argv)
>          g_test_message("unable to rmdir: path (%s): %s",
>                         tmpfs, strerror(errno));
>      }
> +    g_free((gpointer)tmpfs);
>

 argh, remove the const from tmpfs declaration!



>      return ret;
>  }
> --
> 2.34.1
>
>
>

-- 
Marc-André Lureau

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

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

* Re: [PATCH v3 15/54] tests/qtest: pflash-cfi02-test: Avoid using hardcoded /tmp
  2022-09-25 11:29 ` [PATCH v3 15/54] tests/qtest: pflash-cfi02-test: " Bin Meng
@ 2022-09-26 13:18   ` Marc-André Lureau
  0 siblings, 0 replies; 89+ messages in thread
From: Marc-André Lureau @ 2022-09-26 13:18 UTC (permalink / raw)
  To: Bin Meng; +Cc: qemu-devel, Bin Meng, Laurent Vivier, Paolo Bonzini, Thomas Huth

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

On Sun, Sep 25, 2022 at 4:04 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Bin Meng <bin.meng@windriver.com>
>
> This case was written to use hardcoded /tmp directory for temporary
> files. Update to use g_file_open_tmp() for a portable implementation.
>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
>




> ---
>
> Changes in v3:
> - Split to a separate patch
>
>  tests/qtest/pflash-cfi02-test.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/tests/qtest/pflash-cfi02-test.c
> b/tests/qtest/pflash-cfi02-test.c
> index 7fce614b64..55890b7d95 100644
> --- a/tests/qtest/pflash-cfi02-test.c
> +++ b/tests/qtest/pflash-cfi02-test.c
> @@ -56,7 +56,7 @@ typedef struct {
>      QTestState *qtest;
>  } FlashConfig;
>
> -static char image_path[] = "/tmp/qtest.XXXXXX";
> +static char *image_path;
>
>  /*
>   * The pflash implementation allows some parameters to be unspecified. We
> want
> @@ -608,6 +608,7 @@ static void test_cfi_in_autoselect(const void *opaque)
>  static void cleanup(void *opaque)
>  {
>      unlink(image_path);
> +    g_free(image_path);
>  }
>
>  /*
> @@ -635,16 +636,17 @@ static const FlashConfig configuration[] = {
>
>  int main(int argc, char **argv)
>  {
> -    int fd = mkstemp(image_path);
> +    int fd = g_file_open_tmp("qtest.XXXXXX", &image_path, NULL);
>      if (fd == -1) {
>          g_printerr("Failed to create temporary file %s: %s\n", image_path,
>                     strerror(errno));
>

You need to update error reporting using GError error argument.

> +        g_free(image_path);
>

No, image_path is likely still uninitialized here.

The easiest is probably to replace the whole block with a
g_assert_no_error(err).

         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);
> --
> 2.34.1
>
>
>

-- 
Marc-André Lureau

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

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

* Re: [PATCH v3 16/54] tests/qtest: qmp-test: Avoid using hardcoded /tmp
  2022-09-25 11:29 ` [PATCH v3 16/54] tests/qtest: qmp-test: " Bin Meng
@ 2022-09-26 13:19   ` Marc-André Lureau
  0 siblings, 0 replies; 89+ messages in thread
From: Marc-André Lureau @ 2022-09-26 13:19 UTC (permalink / raw)
  To: Bin Meng
  Cc: qemu-devel, Bin Meng, Laurent Vivier, Markus Armbruster,
	Paolo Bonzini, Thomas Huth

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

On Sun, Sep 25, 2022 at 3:51 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Bin Meng <bin.meng@windriver.com>
>
> This case was written to use hardcoded /tmp directory for temporary
> files. Update to use g_dir_make_tmp() for a portable implementation.
>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
>
> Changes in v3:
> - Split to a separate patch
>
>  tests/qtest/qmp-test.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/tests/qtest/qmp-test.c b/tests/qtest/qmp-test.c
> index bf7304c7dc..0fa00c12dc 100644
> --- a/tests/qtest/qmp-test.c
> +++ b/tests/qtest/qmp-test.c
> @@ -161,12 +161,13 @@ 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)
>  {
> -    if (!g_mkdtemp(tmpdir)) {
> +    tmpdir = g_dir_make_tmp("qmp-test-XXXXXX", NULL);
> +    if (!tmpdir) {
>          g_error("g_mkdtemp: %s", strerror(errno));
>      }
>

Again, errno usage is not correct for glib, using GError.

I would replace with  g_assert_no_error(err) here too

     fifo_name = g_strdup_printf("%s/fifo", tmpdir);
> @@ -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)
> --
> 2.34.1
>
>
>

-- 
Marc-André Lureau

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

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

* Re: [PATCH v3 17/54] tests/qtest: vhost-user-blk-test: Avoid using hardcoded /tmp
  2022-09-25 11:29 ` [PATCH v3 17/54] tests/qtest: vhost-user-blk-test: " Bin Meng
@ 2022-09-26 13:20   ` Marc-André Lureau
  0 siblings, 0 replies; 89+ messages in thread
From: Marc-André Lureau @ 2022-09-26 13:20 UTC (permalink / raw)
  To: Bin Meng
  Cc: qemu-devel, Bin Meng, Coiby Xu, Laurent Vivier, Paolo Bonzini,
	Thomas Huth

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

On Sun, Sep 25, 2022 at 3:59 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Bin Meng <bin.meng@windriver.com>
>
> This case was written to use hardcoded /tmp directory for temporary
> files. Update to use g_get_tmp_dir() for a portable implementation.
>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
>

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


> ---
>
> Changes in v3:
> - Split to a separate patch
>
>  tests/qtest/vhost-user-blk-test.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/tests/qtest/vhost-user-blk-test.c
> b/tests/qtest/vhost-user-blk-test.c
> index a81c2a2715..07a4c2d500 100644
> --- a/tests/qtest/vhost-user-blk-test.c
> +++ b/tests/qtest/vhost-user-blk-test.c
> @@ -841,7 +841,8 @@ static char *create_listen_socket(int *fd)
>      char *path;
>
>      /* No race because our pid makes the path unique */
> -    path = g_strdup_printf("/tmp/qtest-%d-sock.XXXXXX", getpid());
> +    path = g_strdup_printf("%s/qtest-%d-sock.XXXXXX",
> +                           g_get_tmp_dir(), getpid());
>      tmp_fd = mkstemp(path);
>      g_assert_cmpint(tmp_fd, >=, 0);
>      close(tmp_fd);
> --
> 2.34.1
>
>
>

-- 
Marc-André Lureau

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

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

* Re: [PATCH v3 18/54] tests/qtest: vhost-user-test: Avoid using hardcoded /tmp
  2022-09-25 11:29 ` [PATCH v3 18/54] tests/qtest: vhost-user-test: " Bin Meng
@ 2022-09-26 13:21   ` Marc-André Lureau
  0 siblings, 0 replies; 89+ messages in thread
From: Marc-André Lureau @ 2022-09-26 13:21 UTC (permalink / raw)
  To: Bin Meng; +Cc: qemu-devel, Bin Meng, Laurent Vivier, Paolo Bonzini, Thomas Huth

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

On Sun, Sep 25, 2022 at 4:13 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Bin Meng <bin.meng@windriver.com>
>
> This case was written to use hardcoded /tmp directory for temporary
> files. Update to use g_dir_make_tmp() for a portable implementation.
>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
>
> Changes in v3:
> - Split to a separate patch
> - Ensure g_autofree variable is initialized
>
>  tests/qtest/vhost-user-test.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/tests/qtest/vhost-user-test.c b/tests/qtest/vhost-user-test.c
> index d7d6cfc9bd..448fda3e7f 100644
> --- a/tests/qtest/vhost-user-test.c
> +++ b/tests/qtest/vhost-user-test.c
> @@ -482,8 +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";
> -    const char *tmpfs;
> +    g_autofree const char *tmpfs = NULL;
>
>      server->context = g_main_context_new();
>      server->loop = g_main_loop_new(server->context, FALSE);
> @@ -491,9 +490,10 @@ 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 = g_mkdtemp(template);
> +    tmpfs = g_dir_make_tmp("vhost-test-XXXXXX", NULL);
>      if (!tmpfs) {
> -        g_test_message("g_mkdtemp on path (%s): %s", template,
> strerror(errno));
> +        g_test_message("g_dir_make_tmp on path (%s): %s", tmpfs,
> +                       strerror(errno));
>

Same remark about error reporting as other patches in the series


>      }
>      g_assert(tmpfs);
>
> --
> 2.34.1
>
>
>

-- 
Marc-André Lureau

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

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

* Re: [PATCH v3 19/54] tests/qtest: virtio-blk-test: Avoid using hardcoded /tmp
  2022-09-25 11:29 ` [PATCH v3 19/54] tests/qtest: virtio-blk-test: " Bin Meng
@ 2022-09-26 13:21   ` Marc-André Lureau
  0 siblings, 0 replies; 89+ messages in thread
From: Marc-André Lureau @ 2022-09-26 13:21 UTC (permalink / raw)
  To: Bin Meng
  Cc: qemu-devel, Bin Meng, Laurent Vivier, Paolo Bonzini,
	Stefan Hajnoczi, Thomas Huth, qemu-block

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

On Sun, Sep 25, 2022 at 4:09 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Bin Meng <bin.meng@windriver.com>
>
> This case was written to use hardcoded /tmp directory for temporary
> files. Update to use g_file_open_tmp() for a portable implementation.
>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
>

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


> ---
>
> Changes in v3:
> - Split to a separate patch
>
>  tests/qtest/virtio-blk-test.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/tests/qtest/virtio-blk-test.c b/tests/qtest/virtio-blk-test.c
> index dc5eed31c8..19c01f808b 100644
> --- a/tests/qtest/virtio-blk-test.c
> +++ b/tests/qtest/virtio-blk-test.c
> @@ -49,10 +49,10 @@ 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;
>
>      /* Create a temporary raw image */
> -    fd = mkstemp(t_path);
> +    fd = g_file_open_tmp("qtest.XXXXXX", &t_path, NULL);
>      g_assert_cmpint(fd, >=, 0);
>      ret = ftruncate(fd, TEST_IMAGE_SIZE);
>      g_assert_cmpint(ret, ==, 0);
> --
> 2.34.1
>
>
>

-- 
Marc-André Lureau

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

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

* Re: [PATCH v3 20/54] tests/qtest: virtio-scsi-test: Avoid using hardcoded /tmp
  2022-09-25 11:29 ` [PATCH v3 20/54] tests/qtest: virtio-scsi-test: " Bin Meng
@ 2022-09-26 13:21   ` Marc-André Lureau
  0 siblings, 0 replies; 89+ messages in thread
From: Marc-André Lureau @ 2022-09-26 13:21 UTC (permalink / raw)
  To: Bin Meng
  Cc: qemu-devel, Bin Meng, Fam Zheng, Laurent Vivier, Paolo Bonzini,
	Thomas Huth

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

On Sun, Sep 25, 2022 at 4:10 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Bin Meng <bin.meng@windriver.com>
>
> This case was written to use hardcoded /tmp directory for temporary
> files. Update to use g_file_open_tmp() for a portable implementation.
>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
>

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


> ---
>
> Changes in v3:
> - Split to a separate patch
> - Ensure g_autofree variable is initialized
>
>  tests/qtest/virtio-scsi-test.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/tests/qtest/virtio-scsi-test.c
> b/tests/qtest/virtio-scsi-test.c
> index 8ceb12aacd..ceaa7f2415 100644
> --- a/tests/qtest/virtio-scsi-test.c
> +++ b/tests/qtest/virtio-scsi-test.c
> @@ -268,7 +268,7 @@ static void test_iothread_attach_node(void *obj, void
> *data,
>      QVirtioSCSIPCI *scsi_pci = obj;
>      QVirtioSCSI *scsi = &scsi_pci->scsi;
>      QVirtioSCSIQueues *vs;
> -    char tmp_path[] = "/tmp/qtest.XXXXXX";
> +    g_autofree char *tmp_path = NULL;
>      int fd;
>      int ret;
>
> @@ -282,7 +282,7 @@ static void test_iothread_attach_node(void *obj, void
> *data,
>      vs = qvirtio_scsi_init(scsi->vdev);
>
>      /* Create a temporary qcow2 overlay*/
> -    fd = mkstemp(tmp_path);
> +    fd = g_file_open_tmp("qtest.XXXXXX", &tmp_path, NULL);
>      g_assert(fd >= 0);
>      close(fd);
>
> --
> 2.34.1
>
>
>

-- 
Marc-André Lureau

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

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

* Re: [PATCH v3 21/54] tests/qtest: libqtest: Avoid using hardcoded /tmp
  2022-09-25 11:29 ` [PATCH v3 21/54] tests/qtest: libqtest: " Bin Meng
@ 2022-09-26 13:22   ` Marc-André Lureau
  0 siblings, 0 replies; 89+ messages in thread
From: Marc-André Lureau @ 2022-09-26 13:22 UTC (permalink / raw)
  To: Bin Meng; +Cc: qemu-devel, Bin Meng, Laurent Vivier, Paolo Bonzini, Thomas Huth

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

On Sun, Sep 25, 2022 at 3:54 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Bin Meng <bin.meng@windriver.com>
>
> The qtest library was written to use hardcoded /tmp directory for
> temporary files. Update to use g_get_tmp_dir() and g_dir_make_tmp()
> for a portable implementation.
>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
>

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


> ---
>
> Changes in v3:
> - Split to a separate patch
> - Ensure g_autofree variable is initialized
>
>  tests/qtest/libqtest.c | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
> index 7c9fc07de4..d8ffa0e7b1 100644
> --- a/tests/qtest/libqtest.c
> +++ b/tests/qtest/libqtest.c
> @@ -265,8 +265,10 @@ QTestState *qtest_init_without_qmp_handshake(const
> char *extra_args)
>
>      s = g_new(QTestState, 1);
>
> -    socket_path = g_strdup_printf("/tmp/qtest-%d.sock", getpid());
> -    qmp_socket_path = g_strdup_printf("/tmp/qtest-%d.qmp", getpid());
> +    socket_path = g_strdup_printf("%s/qtest-%d.sock",
> +                                  g_get_tmp_dir(), getpid());
> +    qmp_socket_path = g_strdup_printf("%s/qtest-%d.qmp",
> +                                      g_get_tmp_dir(), getpid());
>
>      /* It's possible that if an earlier test run crashed it might
>       * have left a stale unix socket lying around. Delete any
> @@ -390,10 +392,12 @@ 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";
> +    g_autofree char *sock_dir = NULL;
> +    char *sock_path;
>      QTestState *qts;
>
> -    g_assert_true(g_mkdtemp(sock_dir) != NULL);
> +    sock_dir = g_dir_make_tmp("qtest-serial-XXXXXX", NULL);
> +    g_assert_true(sock_dir != NULL);
>      sock_path = g_strdup_printf("%s/sock", sock_dir);
>
>      sock_fd_init = init_socket(sock_path);
> --
> 2.34.1
>
>
>

-- 
Marc-André Lureau

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

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

* Re: [PATCH v3 22/54] tests/unit: test-image-locking: Avoid using hardcoded /tmp
  2022-09-25 11:30 ` [PATCH v3 22/54] tests/unit: test-image-locking: " Bin Meng
@ 2022-09-26 13:22   ` Marc-André Lureau
  0 siblings, 0 replies; 89+ messages in thread
From: Marc-André Lureau @ 2022-09-26 13:22 UTC (permalink / raw)
  To: Bin Meng; +Cc: qemu-devel, Bin Meng

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

On Sun, Sep 25, 2022 at 3:49 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Bin Meng <bin.meng@windriver.com>
>
> This case was written to use hardcoded /tmp directory for temporary
> files. Update to use g_file_open_tmp() for a portable implementation.
>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
>

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


> ---
>
> Changes in v3:
> - Split to a separate patch
> - Ensure g_autofree variable is initialized
>
>  tests/unit/test-image-locking.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/tests/unit/test-image-locking.c
> b/tests/unit/test-image-locking.c
> index ba057bd66c..a47299c247 100644
> --- a/tests/unit/test-image-locking.c
> +++ b/tests/unit/test-image-locking.c
> @@ -76,10 +76,10 @@ 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";
> +    g_autofree char *img_path = NULL;
>      uint64_t perm, shared_perm;
>
> -    int fd = mkstemp(img_path);
> +    int fd = g_file_open_tmp("qtest.XXXXXX", &img_path, NULL);
>      assert(fd >= 0);
>
>      perm = BLK_PERM_WRITE | BLK_PERM_CONSISTENT_READ;
> @@ -117,10 +117,10 @@ static void test_image_locking_basic(void)
>  static void test_set_perm_abort(void)
>  {
>      BlockBackend *blk1, *blk2;
> -    char img_path[] = "/tmp/qtest.XXXXXX";
> +    g_autofree char *img_path = NULL;
>      uint64_t perm, shared_perm;
>      int r;
> -    int fd = mkstemp(img_path);
> +    int fd = g_file_open_tmp("qtest.XXXXXX", &img_path, NULL);
>      assert(fd >= 0);
>
>      perm = BLK_PERM_WRITE | BLK_PERM_CONSISTENT_READ;
> --
> 2.34.1
>
>
>

-- 
Marc-André Lureau

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

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

* Re: [PATCH v3 23/54] tests/unit: test-qga: Avoid using hardcoded /tmp
  2022-09-25 11:30 ` [PATCH v3 23/54] tests/unit: test-qga: " Bin Meng
@ 2022-09-26 13:23   ` Marc-André Lureau
  0 siblings, 0 replies; 89+ messages in thread
From: Marc-André Lureau @ 2022-09-26 13:23 UTC (permalink / raw)
  To: Bin Meng; +Cc: qemu-devel, Bin Meng, Konstantin Kostiuk, Michael Roth

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

On Sun, Sep 25, 2022 at 3:57 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Bin Meng <bin.meng@windriver.com>
>
> This case was written to use hardcoded /tmp directory for temporary
> files. Update to use g_get_tmp_dir() for a portable implementation.
>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
>

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


> ---
>
> Changes in v3:
> - Split to a separate patch
>
>  tests/unit/test-qga.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tests/unit/test-qga.c b/tests/unit/test-qga.c
> index b6ea7c7304..b4e0a14573 100644
> --- a/tests/unit/test-qga.c
> +++ b/tests/unit/test-qga.c
> @@ -60,7 +60,7 @@ fixture_setup(TestFixture *fixture, gconstpointer data,
> gchar **envp)
>
>      fixture->loop = g_main_loop_new(NULL, FALSE);
>
> -    fixture->test_dir = g_strdup("/tmp/qgatest.XXXXXX");
> +    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);
> --
> 2.34.1
>
>
>

-- 
Marc-André Lureau

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

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

* Re: [PATCH v3 24/54] tests: vhost-user-bridge: Avoid using hardcoded /tmp
  2022-09-25 11:30 ` [PATCH v3 24/54] tests: vhost-user-bridge: " Bin Meng
@ 2022-09-26 13:23   ` Marc-André Lureau
  0 siblings, 0 replies; 89+ messages in thread
From: Marc-André Lureau @ 2022-09-26 13:23 UTC (permalink / raw)
  To: Bin Meng; +Cc: qemu-devel, Bin Meng, Paolo Bonzini

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

On Sun, Sep 25, 2022 at 3:58 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Bin Meng <bin.meng@windriver.com>
>
> This case was written to use hardcoded /tmp directory for temporary
> files. Update to use g_file_open_tmp() for a portable implementation.
>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
>

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


> ---
>
> Changes in v3:
> - Split to a separate patch
>
>  tests/vhost-user-bridge.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/tests/vhost-user-bridge.c b/tests/vhost-user-bridge.c
> index 9b1dab2f28..fecdf915e7 100644
> --- a/tests/vhost-user-bridge.c
> +++ b/tests/vhost-user-bridge.c
> @@ -631,7 +631,6 @@ static void *notifier_thread(void *arg)
>  static void
>  vubr_host_notifier_setup(VubrDev *dev)
>  {
> -    char template[] = "/tmp/vubr-XXXXXX";
>      pthread_t thread;
>      size_t length;
>      void *addr;
> @@ -639,7 +638,7 @@ vubr_host_notifier_setup(VubrDev *dev)
>
>      length = qemu_real_host_page_size() * VHOST_USER_BRIDGE_MAX_QUEUES;
>
> -    fd = mkstemp(template);
> +    fd = g_file_open_tmp("vubr-XXXXXX", NULL, NULL);
>      if (fd < 0) {
>          vubr_die("mkstemp()");
>      }
> --
> 2.34.1
>
>
>

-- 
Marc-André Lureau

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

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

* Re: [PATCH v3 35/54] tests/qtest: libqtest: Install signal handler via signal()
  2022-09-25 11:30 ` [PATCH v3 35/54] tests/qtest: libqtest: Install signal handler via signal() Bin Meng
@ 2022-09-26 13:24   ` Marc-André Lureau
  0 siblings, 0 replies; 89+ messages in thread
From: Marc-André Lureau @ 2022-09-26 13:24 UTC (permalink / raw)
  To: Bin Meng; +Cc: qemu-devel, Bin Meng, Laurent Vivier, Paolo Bonzini, Thomas Huth

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

On Sun, Sep 25, 2022 at 4:03 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Bin Meng <bin.meng@windriver.com>
>
> At present the codes uses sigaction() to install signal handler with
> a flag SA_RESETHAND. Such usage can be covered by the signal() API
> that is a simplified interface to the general sigaction() facility.
>
> Update to use signal() to install the signal handler, as it is
> available on Windows which we are going to support.
>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
>

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


> ---
>
> (no changes since v1)
>
>  tests/qtest/libqtest.c | 14 +++-----------
>  1 file changed, 3 insertions(+), 11 deletions(-)
>
> diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
> index 269d622fe3..f0ac467903 100644
> --- a/tests/qtest/libqtest.c
> +++ b/tests/qtest/libqtest.c
> @@ -66,7 +66,7 @@ struct QTestState
>  };
>
>  static GHookList abrt_hooks;
> -static struct sigaction sigact_old;
> +static sighandler_t sighandler_old;
>
>  static int qtest_query_target_endianness(QTestState *s);
>
> @@ -179,20 +179,12 @@ static void sigabrt_handler(int signo)
>
>  static void setup_sigabrt_handler(void)
>  {
> -    struct sigaction sigact;
> -
> -    /* Catch SIGABRT to clean up on g_assert() failure */
> -    sigact = (struct sigaction){
> -        .sa_handler = sigabrt_handler,
> -        .sa_flags = SA_RESETHAND,
> -    };
> -    sigemptyset(&sigact.sa_mask);
> -    sigaction(SIGABRT, &sigact, &sigact_old);
> +    sighandler_old = signal(SIGABRT, sigabrt_handler);
>  }
>
>  static void cleanup_sigabrt_handler(void)
>  {
> -    sigaction(SIGABRT, &sigact_old, NULL);
> +    signal(SIGABRT, sighandler_old);
>  }
>
>  static bool hook_list_is_empty(GHookList *hook_list)
> --
> 2.34.1
>
>
>

-- 
Marc-André Lureau

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

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

* Re: [PATCH v3 42/54] chardev/char-file: Add FILE_SHARE_WRITE when opening the file for win32
  2022-09-25 11:30 ` [PATCH v3 42/54] chardev/char-file: Add FILE_SHARE_WRITE when opening the file " Bin Meng
@ 2022-09-26 13:27   ` Marc-André Lureau
  2022-09-26 15:05     ` Bin Meng
  0 siblings, 1 reply; 89+ messages in thread
From: Marc-André Lureau @ 2022-09-26 13:27 UTC (permalink / raw)
  To: Bin Meng; +Cc: qemu-devel, Xuzhou Cheng, Bin Meng, Paolo Bonzini

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

Hi

On Sun, Sep 25, 2022 at 4:35 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Xuzhou Cheng <xuzhou.cheng@windriver.com>
>
> The combination of GENERIC_WRITE and FILE_SHARE_READ options does not
> allow the same file to be opened again by CreateFile() from another
> QEMU process with the same options when the previous QEMU process
> still holds the file handle opened.
>
> 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 old one still holds the file handle that does
> not allow shared write permission then the new QEMU process will fail.
>
> There is another test case boot-serial-test that triggers the same
> issue. The qtest executable created a serial chardev file to be
> passed to the QEMU executable. The serial file was created by
> g_file_open_tmp(), which internally opens the file with
> FILE_SHARE_WRITE security attribute, and based on [1], there is
> only one case that allows the first call to CreateFile() with
> GENERIC_READ & FILE_SHARE_WRITE, and second call to CreateFile()
> with GENERIC_WRITE & FILE_SHARE_READ. All other combinations
> require FILE_SHARE_WRITE in the second call. But there is no way
> for the second call (in this case the QEMU executable) to know
> what combination was passed to the first call, so we will have to
> add FILE_SHARE_WRITE to the second call.
>
> For both scenarios we should add FILE_SHARE_WRITE in the chardev
> file backend driver. This change also makes the behavior to be
> consistent with the POSIX platforms.
>

It seems to me the tests should be fixed instead. I thought you fixed the
first case. For the second case, why not close the file before starting
qemu? If you have issues, I will take a deeper look.


>
> [1]
> https://docs.microsoft.com/en-us/windows/win32/fileio/creating-and-opening-files
>
> Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
>
> Changes in v3:
> - Add another case "boot-serial-test" to justify the change
>
> Changes in v2:
> - Update commit message to include the use case why we should set
>   FILE_SHARE_WRITE when opening the file for win32
>
>  chardev/char-file.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/chardev/char-file.c b/chardev/char-file.c
> index 2fd80707e5..66385211eb 100644
> --- a/chardev/char-file.c
> +++ b/chardev/char-file.c
> @@ -60,8 +60,8 @@ static void qmp_chardev_open_file(Chardev *chr,
>          flags = CREATE_ALWAYS;
>      }
>
> -    out = CreateFile(file->out, accessmode, FILE_SHARE_READ, NULL, flags,
> -                     FILE_ATTRIBUTE_NORMAL, NULL);
> +    out = CreateFile(file->out, accessmode, FILE_SHARE_READ |
> FILE_SHARE_WRITE,
> +                     NULL, flags, FILE_ATTRIBUTE_NORMAL, NULL);
>      if (out == INVALID_HANDLE_VALUE) {
>          error_setg(errp, "open %s failed", file->out);
>          return;
> --
> 2.34.1
>
>
>

-- 
Marc-André Lureau

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

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

* Re: [PATCH v3 42/54] chardev/char-file: Add FILE_SHARE_WRITE when opening the file for win32
  2022-09-26 13:27   ` Marc-André Lureau
@ 2022-09-26 15:05     ` Bin Meng
  2022-09-27  9:00       ` Marc-André Lureau
  0 siblings, 1 reply; 89+ messages in thread
From: Bin Meng @ 2022-09-26 15:05 UTC (permalink / raw)
  To: Marc-André Lureau
  Cc: qemu-devel@nongnu.org Developers, Xuzhou Cheng, Bin Meng, Paolo Bonzini

On Mon, Sep 26, 2022 at 9:27 PM Marc-André Lureau
<marcandre.lureau@gmail.com> wrote:
>
> Hi
>
> On Sun, Sep 25, 2022 at 4:35 PM Bin Meng <bmeng.cn@gmail.com> wrote:
>>
>> From: Xuzhou Cheng <xuzhou.cheng@windriver.com>
>>
>> The combination of GENERIC_WRITE and FILE_SHARE_READ options does not
>> allow the same file to be opened again by CreateFile() from another
>> QEMU process with the same options when the previous QEMU process
>> still holds the file handle opened.
>>
>> 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 old one still holds the file handle that does
>> not allow shared write permission then the new QEMU process will fail.
>>
>> There is another test case boot-serial-test that triggers the same
>> issue. The qtest executable created a serial chardev file to be
>> passed to the QEMU executable. The serial file was created by
>> g_file_open_tmp(), which internally opens the file with
>> FILE_SHARE_WRITE security attribute, and based on [1], there is
>> only one case that allows the first call to CreateFile() with
>> GENERIC_READ & FILE_SHARE_WRITE, and second call to CreateFile()
>> with GENERIC_WRITE & FILE_SHARE_READ. All other combinations
>> require FILE_SHARE_WRITE in the second call. But there is no way
>> for the second call (in this case the QEMU executable) to know
>> what combination was passed to the first call, so we will have to
>> add FILE_SHARE_WRITE to the second call.
>>
>> For both scenarios we should add FILE_SHARE_WRITE in the chardev
>> file backend driver. This change also makes the behavior to be
>> consistent with the POSIX platforms.
>
>
> It seems to me the tests should be fixed instead. I thought you fixed the first case. For the second case, why not close the file before starting qemu? If you have issues, I will take a deeper look.

Indeed, the following test case change can "fix" this issue:

diff --git a/tests/qtest/boot-serial-test.c b/tests/qtest/boot-serial-test.c
index 72310ba30e..f192fbc181 100644
--- a/tests/qtest/boot-serial-test.c
+++ b/tests/qtest/boot-serial-test.c
@@ -233,6 +233,7 @@ static void test_machine(const void *data)
ser_fd = g_file_open_tmp("qtest-boot-serial-sXXXXXX", &serialtmp, NULL);
g_assert(ser_fd != -1);
+ close(ser_fd);
if (test->kernel) {
code = test->kernel;
@@ -266,6 +267,7 @@ static void test_machine(const void *data)
unlink(codetmp);
}
+ ser_fd = open(serialtmp, O_RDONLY);
if (!check_guest_output(qts, test, ser_fd)) {
g_error("Failed to find expected string. Please check '%s'",
serialtmp);

But I think it just workarounds the problem. The original test case
looks reasonable to me. If we update the case like above, we cannot
guarantee users will do like the updated test case does.

>
>>
>>
>> [1] https://docs.microsoft.com/en-us/windows/win32/fileio/creating-and-opening-files
>>
>> Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
>> Signed-off-by: Bin Meng <bin.meng@windriver.com>
>> ---
>>
>> Changes in v3:
>> - Add another case "boot-serial-test" to justify the change
>>
>> Changes in v2:
>> - Update commit message to include the use case why we should set
>>   FILE_SHARE_WRITE when opening the file for win32
>>
>>  chardev/char-file.c | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>

Regards,
Bin


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

* Re: [PATCH v3 12/54] tests/qtest: hd-geo-test: Avoid using hardcoded /tmp
  2022-09-25 11:29 ` [PATCH v3 12/54] tests/qtest: hd-geo-test: " Bin Meng
  2022-09-26 13:11   ` Marc-André Lureau
@ 2022-09-26 15:38   ` Thomas Huth
  1 sibling, 0 replies; 89+ messages in thread
From: Thomas Huth @ 2022-09-26 15:38 UTC (permalink / raw)
  To: Bin Meng, qemu-devel
  Cc: Marc-André Lureau, Bin Meng, Laurent Vivier, Paolo Bonzini

On 25/09/2022 13.29, Bin Meng wrote:
> From: Bin Meng <bin.meng@windriver.com>
> 
> This case was written to use hardcoded /tmp directory for temporary
> files. Update to use g_file_open_tmp() for a portable implementation.
> 
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
> 
> Changes in v3:
> - Split to a separate patch
> - Ensure g_autofree variable is initialized
> - Use g_steal_pointer() in create_test_img()
> 
>   tests/qtest/hd-geo-test.c | 25 +++++++++++--------------
>   1 file changed, 11 insertions(+), 14 deletions(-)
> 
> diff --git a/tests/qtest/hd-geo-test.c b/tests/qtest/hd-geo-test.c
> index 413cf964c0..455bc5db5c 100644
> --- a/tests/qtest/hd-geo-test.c
> +++ b/tests/qtest/hd-geo-test.c
> @@ -27,20 +27,19 @@
>   
>   static char *create_test_img(int secs)
>   {
> -    char *template = strdup("/tmp/qtest.XXXXXX");
> +    g_autofree char *template = NULL;
>       int fd, ret;
>   
> -    fd = mkstemp(template);
> +    fd = g_file_open_tmp("qtest.XXXXXX", &template, NULL);
>       g_assert(fd >= 0);
>       ret = ftruncate(fd, (off_t)secs * 512);
>       close(fd);
>   
>       if (ret) {
> -        free(template);
>           template = NULL;
>       }
>   
> -    return template;
> +    return g_steal_pointer(&template);

Just a matter of taste, but in this case, I'd rather prefer to not use 
g_autofree + g_steal_pointer and simply replace the "free" with a "g_free" 
instead.

  Thomas



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

* Re: [PATCH v3 32/54] tests/qtest: libqtest: Adapt global_qtest declaration for win32
  2022-09-25 11:30 ` [PATCH v3 32/54] tests/qtest: libqtest: Adapt global_qtest declaration for win32 Bin Meng
@ 2022-09-26 16:07   ` Thomas Huth
  0 siblings, 0 replies; 89+ messages in thread
From: Thomas Huth @ 2022-09-26 16:07 UTC (permalink / raw)
  To: Bin Meng, qemu-devel
  Cc: Marc-André Lureau, Xuzhou Cheng, Bin Meng, Laurent Vivier,
	Paolo Bonzini

On 25/09/2022 13.30, Bin Meng wrote:
> From: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> 
> Commit dd2107497275 ("tests/libqtest: Use libqtest-single.h in tests that require global_qtest")
> moved global_qtest to libqtest-single.h, by declaring global_qtest
> attribute to be common and weak.
> 
> This trick unfortunately does not work on Windows, and building
> qtest test cases results in multiple definition errors of the weak
> symbol global_qtest, as Windows PE does not have the concept of
> the so-called weak symbol like ELF in the *nix world.
> 
> However Windows does provide a trick to declare a variable to be
> a common symbol, via __declspec(selectany) [1]. It does not provide
> the "strong override weak" effect but we don't need it in our use
> case anyway. So let's use it for win32.
> 
> [1] https://docs.microsoft.com/en-us/cpp/cpp/selectany
> 
> Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
> 
> (no changes since v2)
> 
> Changes in v2:
> - Use __declspec(selectany) for the common weak symbol on Windows
> 
>   tests/qtest/libqtest-single.h | 4 ++++
>   1 file changed, 4 insertions(+)
> 
> diff --git a/tests/qtest/libqtest-single.h b/tests/qtest/libqtest-single.h
> index 4e7d0ae1dc..851724cbcb 100644
> --- a/tests/qtest/libqtest-single.h
> +++ b/tests/qtest/libqtest-single.h
> @@ -13,7 +13,11 @@
>   
>   #include "libqtest.h"
>   
> +#ifndef _WIN32
>   QTestState *global_qtest __attribute__((common, weak));
> +#else
> +__declspec(selectany) QTestState *global_qtest;
> +#endif
>   
>   /**
>    * qtest_start:

Good to know that it works also on Windows somehow!

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



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

* Re: [PATCH v3 37/54] tests/qtest: {ahci, ide}-test: Use relative path for temporary files for win32
  2022-09-25 11:30 ` [PATCH v3 37/54] tests/qtest: {ahci, ide}-test: Use relative path for temporary files for win32 Bin Meng
@ 2022-09-26 16:20   ` Thomas Huth
  2022-09-27  0:17     ` Bin Meng
  0 siblings, 1 reply; 89+ messages in thread
From: Thomas Huth @ 2022-09-26 16:20 UTC (permalink / raw)
  To: Bin Meng, qemu-devel
  Cc: Marc-André Lureau, Bin Meng, John Snow, Laurent Vivier,
	Paolo Bonzini, qemu-block

On 25/09/2022 13.30, Bin Meng wrote:
> From: Bin Meng <bin.meng@windriver.com>
> 
> These test cases uses "blkdebug:path/to/config:path/to/image" for
> testing. On Windows, absolute file paths contain the delimiter ':'
> which causes the blkdebug filename parser fail to parse filenames.
> 
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
> 
> (no changes since v1)
> 
>   tests/qtest/ahci-test.c | 21 ++++++++++++++++++---
>   tests/qtest/ide-test.c  | 20 ++++++++++++++++++--
>   2 files changed, 36 insertions(+), 5 deletions(-)
> 
> diff --git a/tests/qtest/ahci-test.c b/tests/qtest/ahci-test.c
> index 1d5929d8c3..66652fed04 100644
> --- a/tests/qtest/ahci-test.c
> +++ b/tests/qtest/ahci-test.c
> @@ -1833,7 +1833,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;
> @@ -1871,8 +1871,22 @@ 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 */
> -    fd = g_file_open_tmp("qtest.XXXXXX", &tmp_path, NULL);
> +    tmp_path = g_strdup_printf("%s/qtest.XXXXXX", base);
> +    fd = g_mkstemp(tmp_path);
>       g_assert(fd >= 0);
>       if (have_qemu_img()) {
>           imgfmt = "qcow2";
> @@ -1889,7 +1903,8 @@ int main(int argc, char **argv)
>       close(fd);
>   
>       /* Create temporary blkdebug instructions */
> -    fd = g_file_open_tmp("qtest-blkdebug.XXXXXX", &debug_path, NULL);
> +    debug_path = g_strdup_printf("%s/qtest-blkdebug.XXXXXX", base);
> +    fd = g_mkstemp(debug_path);
>       g_assert(fd >= 0);
>       close(fd);

It would maybe make sense to merge this with patch 05 ("tests/qtest: 
ahci-test: Avoid using hardcoded /tmp") ? ... but if you want to keep it 
separate, that's fine for me, too.

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



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

* Re: [PATCH v3 52/54] .gitlab-ci.d/windows.yml: Display meson test logs
  2022-09-25 11:30 ` [PATCH v3 52/54] .gitlab-ci.d/windows.yml: Display meson test logs Bin Meng
@ 2022-09-26 16:46   ` Thomas Huth
  0 siblings, 0 replies; 89+ messages in thread
From: Thomas Huth @ 2022-09-26 16:46 UTC (permalink / raw)
  To: Bin Meng, qemu-devel
  Cc: Marc-André Lureau, Bin Meng, Alex Bennée, Beraldo Leal,
	Philippe Mathieu-Daudé,
	Wainer dos Santos Moschetta

On 25/09/2022 13.30, Bin Meng wrote:
> From: Bin Meng <bin.meng@windriver.com>
> 
> When CI fails we don't know what causes the failure. Displaying the
> meson test logs can be helpful.
> 
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
> 
> (no changes since v2)
> 
> Changes in v2:
> - new patch: Display meson test logs in the Windows CI
> 
>   .gitlab-ci.d/windows.yml | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/.gitlab-ci.d/windows.yml b/.gitlab-ci.d/windows.yml
> index 9ef4667317..29a3ba04a4 100644
> --- a/.gitlab-ci.d/windows.yml
> +++ b/.gitlab-ci.d/windows.yml
> @@ -61,7 +61,7 @@ msys2-64bit:
>     - .\msys64\usr\bin\bash -lc './configure --target-list=x86_64-softmmu
>         --enable-capstone'
>     - .\msys64\usr\bin\bash -lc 'make'
> -  - .\msys64\usr\bin\bash -lc 'make check'
> +  - .\msys64\usr\bin\bash -lc 'make check || { cat build/meson-logs/testlog.txt; exit 1; } ;'
>   
>   msys2-32bit:
>     extends: .shared_msys2_builder
> @@ -94,4 +94,4 @@ msys2-32bit:
>     - cd output
>     - ..\msys64\usr\bin\bash -lc "../configure --target-list=ppc64-softmmu"
>     - ..\msys64\usr\bin\bash -lc 'make'
> -  - ..\msys64\usr\bin\bash -lc 'make check'
> +  - ..\msys64\usr\bin\bash -lc 'make check || { cat meson-logs/testlog.txt; exit 1; } ;'

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



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

* Re: [PATCH v3 54/54] docs/devel: testing: Document writing portable test cases
  2022-09-25 11:30 ` [PATCH v3 54/54] docs/devel: testing: Document writing portable test cases Bin Meng
@ 2022-09-26 16:55   ` Thomas Huth
  0 siblings, 0 replies; 89+ messages in thread
From: Thomas Huth @ 2022-09-26 16:55 UTC (permalink / raw)
  To: Bin Meng, qemu-devel
  Cc: Marc-André Lureau, Bin Meng, Alex Bennée,
	Paolo Bonzini, Philippe Mathieu-Daudé,
	Willian Rampazzo

On 25/09/2022 13.30, Bin Meng wrote:
> From: Bin Meng <bin.meng@windriver.com>
> 
> Update the best practices of how to write portable test cases that
> can be built and run successfully on both Linux and Windows hosts.
> 
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
> 
> (no changes since v3)
> 
> Changes in v2:
> - Minor wording changes
> - Drop patches that were already applied in the mainline
> - Drop patch: "qga/commands-posix-ssh: Use g_mkdir_with_parents()"
> - Drop patch: "tests: Skip iotests and qtest when '--without-default-devices'"
> - Drop patch: "tests/qtest: Fix ERROR_SHARING_VIOLATION for win32"
> 
>   docs/devel/testing.rst | 30 ++++++++++++++++++++++++++++++
>   1 file changed, 30 insertions(+)
> 
> diff --git a/docs/devel/testing.rst b/docs/devel/testing.rst
> index aea5b42356..0eae9c4654 100644
> --- a/docs/devel/testing.rst
> +++ b/docs/devel/testing.rst
> @@ -115,6 +115,36 @@ check-block
>   are in the "auto" group).
>   See the "QEMU iotests" section below for more information.

Looks like you've added the new text after the "check-block" section ... 
could you please add it after the "QTest" section instead?

> +Writing portable test cases
> +~~~~~~~~~~~~~~~~~~~~~~~~~~~
> +Both unit tests and qtests can run on POSIX hosts as well as a Windows host.

Nit: better use plural in both cases: "on POSIX hosts as well as Windows hosts".

> +Care must be taken when writing portable test cases that can be built and run
> +successfully on various hosts. The following are some best practices:

Maybe better (but I'm not a native speaker either): "The following list 
shows some best practices"

> +* Use portable APIs from glib whenever necessary, e.g.: g_setenv(),
> +  g_mkdtemp(), g_mkdir().
> +* Avoid using hardcoded /tmp for temporary file directory.
> +  Use g_get_tmp_dir() instead.
> +* Bear in mind that Windows has different special string representation for
> +  stdin/stdout/stderr and null devices. For example if your test case uses
> +  "/dev/fd/2" and "/dev/null" on Linux, remember to use "2" and "nul" on
> +  Windows instead. Also IO redirection does not work on Windows, so avoid
> +  using "2>nul" whenever necessary.
> +* If your test cases uses the blkdebug feature, use relative path to pass
> +  the config and image file paths in the command line as Windows absolute
> +  path contains the delimeter ":" which will confuse the blkdebug parser.

s/delimeter/delimiter/

> +* Use double quotes in your extra QEMU commmand line in your test cases
> +  instead of single quotes, as Windows does not drop single quotes when
> +  passing the command line to QEMU.
> +* Windows opens a file in text mode by default, while a POSIX compliant
> +  implementation treats text files and binary files the same. So if your
> +  test cases opens a file to write some data and later wants to compare the
> +  written data with the original one, be sure to pass the letter 'b' as
> +  part of the mode string to fopen(), or O_BINARY flag for the open() call.
> +* If a certain test case can only run on POSIX or Linux hosts, use a proper
> +  #ifdef in the codes. If the whole test suite cannot run on Windows, disable
> +  the build in the meson.build file.
> +
>   QEMU iotests
>   ------------
>   

  Thomas



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

* Re: [PATCH v3 37/54] tests/qtest: {ahci, ide}-test: Use relative path for temporary files for win32
  2022-09-26 16:20   ` Thomas Huth
@ 2022-09-27  0:17     ` Bin Meng
  0 siblings, 0 replies; 89+ messages in thread
From: Bin Meng @ 2022-09-27  0:17 UTC (permalink / raw)
  To: Thomas Huth
  Cc: qemu-devel@nongnu.org Developers, Marc-André Lureau,
	Bin Meng, John Snow, Laurent Vivier, Paolo Bonzini, Qemu-block

Hi Thomas,

On Tue, Sep 27, 2022 at 12:20 AM Thomas Huth <thuth@redhat.com> wrote:
>
> On 25/09/2022 13.30, Bin Meng wrote:
> > From: Bin Meng <bin.meng@windriver.com>
> >
> > These test cases uses "blkdebug:path/to/config:path/to/image" for
> > testing. On Windows, absolute file paths contain the delimiter ':'
> > which causes the blkdebug filename parser fail to parse filenames.
> >
> > Signed-off-by: Bin Meng <bin.meng@windriver.com>
> > Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > ---
> >
> > (no changes since v1)
> >
> >   tests/qtest/ahci-test.c | 21 ++++++++++++++++++---
> >   tests/qtest/ide-test.c  | 20 ++++++++++++++++++--
> >   2 files changed, 36 insertions(+), 5 deletions(-)
> >
> > diff --git a/tests/qtest/ahci-test.c b/tests/qtest/ahci-test.c
> > index 1d5929d8c3..66652fed04 100644
> > --- a/tests/qtest/ahci-test.c
> > +++ b/tests/qtest/ahci-test.c
> > @@ -1833,7 +1833,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;
> > @@ -1871,8 +1871,22 @@ 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 */
> > -    fd = g_file_open_tmp("qtest.XXXXXX", &tmp_path, NULL);
> > +    tmp_path = g_strdup_printf("%s/qtest.XXXXXX", base);
> > +    fd = g_mkstemp(tmp_path);
> >       g_assert(fd >= 0);
> >       if (have_qemu_img()) {
> >           imgfmt = "qcow2";
> > @@ -1889,7 +1903,8 @@ int main(int argc, char **argv)
> >       close(fd);
> >
> >       /* Create temporary blkdebug instructions */
> > -    fd = g_file_open_tmp("qtest-blkdebug.XXXXXX", &debug_path, NULL);
> > +    debug_path = g_strdup_printf("%s/qtest-blkdebug.XXXXXX", base);
> > +    fd = g_mkstemp(debug_path);
> >       g_assert(fd >= 0);
> >       close(fd);
>
> It would maybe make sense to merge this with patch 05 ("tests/qtest:
> ahci-test: Avoid using hardcoded /tmp") ? ... but if you want to keep it
> separate, that's fine for me, too.

I'd prefer to keep these two patches separate as they are resolving
different issues.

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

Thanks for the review!

Regards,
Bin

Regards,
Bin


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

* Re: [PATCH v3 42/54] chardev/char-file: Add FILE_SHARE_WRITE when opening the file for win32
  2022-09-26 15:05     ` Bin Meng
@ 2022-09-27  9:00       ` Marc-André Lureau
  2022-09-27 10:44         ` Bin Meng
  0 siblings, 1 reply; 89+ messages in thread
From: Marc-André Lureau @ 2022-09-27  9:00 UTC (permalink / raw)
  To: Bin Meng
  Cc: qemu-devel@nongnu.org Developers, Xuzhou Cheng, Bin Meng, Paolo Bonzini

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

Hi

On Mon, Sep 26, 2022 at 7:05 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> On Mon, Sep 26, 2022 at 9:27 PM Marc-André Lureau
> <marcandre.lureau@gmail.com> wrote:
> >
> > Hi
> >
> > On Sun, Sep 25, 2022 at 4:35 PM Bin Meng <bmeng.cn@gmail.com> wrote:
> >>
> >> From: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> >>
> >> The combination of GENERIC_WRITE and FILE_SHARE_READ options does not
> >> allow the same file to be opened again by CreateFile() from another
> >> QEMU process with the same options when the previous QEMU process
> >> still holds the file handle opened.
> >>
> >> 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 old one still holds the file handle that does
> >> not allow shared write permission then the new QEMU process will fail.
> >>
> >> There is another test case boot-serial-test that triggers the same
> >> issue. The qtest executable created a serial chardev file to be
> >> passed to the QEMU executable. The serial file was created by
> >> g_file_open_tmp(), which internally opens the file with
> >> FILE_SHARE_WRITE security attribute, and based on [1], there is
> >> only one case that allows the first call to CreateFile() with
> >> GENERIC_READ & FILE_SHARE_WRITE, and second call to CreateFile()
> >> with GENERIC_WRITE & FILE_SHARE_READ. All other combinations
> >> require FILE_SHARE_WRITE in the second call. But there is no way
> >> for the second call (in this case the QEMU executable) to know
> >> what combination was passed to the first call, so we will have to
> >> add FILE_SHARE_WRITE to the second call.
> >>
> >> For both scenarios we should add FILE_SHARE_WRITE in the chardev
> >> file backend driver. This change also makes the behavior to be
> >> consistent with the POSIX platforms.
> >
> >
> > It seems to me the tests should be fixed instead. I thought you fixed
> the first case. For the second case, why not close the file before starting
> qemu? If you have issues, I will take a deeper look.
>
> Indeed, the following test case change can "fix" this issue:
>
> diff --git a/tests/qtest/boot-serial-test.c
> b/tests/qtest/boot-serial-test.c
> index 72310ba30e..f192fbc181 100644
> --- a/tests/qtest/boot-serial-test.c
> +++ b/tests/qtest/boot-serial-test.c
> @@ -233,6 +233,7 @@ static void test_machine(const void *data)
> ser_fd = g_file_open_tmp("qtest-boot-serial-sXXXXXX", &serialtmp, NULL);
> g_assert(ser_fd != -1);
> + close(ser_fd);
> if (test->kernel) {
> code = test->kernel;
> @@ -266,6 +267,7 @@ static void test_machine(const void *data)
> unlink(codetmp);
> }
> + ser_fd = open(serialtmp, O_RDONLY);
> if (!check_guest_output(qts, test, ser_fd)) {
> g_error("Failed to find expected string. Please check '%s'",
> serialtmp);
>
>
Please send this fix as a new patch in the series.


> But I think it just workarounds the problem. The original test case
> looks reasonable to me. If we update the case like above, we cannot
> guarantee users will do like the updated test case does.
>

If the test is enabled, it will fail, and the reasons are reasonably valid:
two processes shouldn't share the same file for writing with a chardev.

I still think the windows file chardev behavior is superior and we should
instead teach the posix implementation of exclusive write access, rather
than downgrading the windows implementation. I'd drop this patch from the
series for now.


>
> >
> >>
> >>
> >> [1]
> https://docs.microsoft.com/en-us/windows/win32/fileio/creating-and-opening-files
> >>
> >> Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> >> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> >> ---
> >>
> >> Changes in v3:
> >> - Add another case "boot-serial-test" to justify the change
> >>
> >> Changes in v2:
> >> - Update commit message to include the use case why we should set
> >>   FILE_SHARE_WRITE when opening the file for win32
> >>
> >>  chardev/char-file.c | 4 ++--
> >>  1 file changed, 2 insertions(+), 2 deletions(-)
> >>
>
> Regards,
> Bin
>


-- 
Marc-André Lureau

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

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

* Re: [PATCH v3 42/54] chardev/char-file: Add FILE_SHARE_WRITE when opening the file for win32
  2022-09-27  9:00       ` Marc-André Lureau
@ 2022-09-27 10:44         ` Bin Meng
  0 siblings, 0 replies; 89+ messages in thread
From: Bin Meng @ 2022-09-27 10:44 UTC (permalink / raw)
  To: Marc-André Lureau
  Cc: qemu-devel@nongnu.org Developers, Xuzhou Cheng, Bin Meng, Paolo Bonzini

On Tue, Sep 27, 2022 at 5:00 PM Marc-André Lureau
<marcandre.lureau@gmail.com> wrote:
>
> Hi
>
> On Mon, Sep 26, 2022 at 7:05 PM Bin Meng <bmeng.cn@gmail.com> wrote:
>>
>> On Mon, Sep 26, 2022 at 9:27 PM Marc-André Lureau
>> <marcandre.lureau@gmail.com> wrote:
>> >
>> > Hi
>> >
>> > On Sun, Sep 25, 2022 at 4:35 PM Bin Meng <bmeng.cn@gmail.com> wrote:
>> >>
>> >> From: Xuzhou Cheng <xuzhou.cheng@windriver.com>
>> >>
>> >> The combination of GENERIC_WRITE and FILE_SHARE_READ options does not
>> >> allow the same file to be opened again by CreateFile() from another
>> >> QEMU process with the same options when the previous QEMU process
>> >> still holds the file handle opened.
>> >>
>> >> 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 old one still holds the file handle that does
>> >> not allow shared write permission then the new QEMU process will fail.
>> >>
>> >> There is another test case boot-serial-test that triggers the same
>> >> issue. The qtest executable created a serial chardev file to be
>> >> passed to the QEMU executable. The serial file was created by
>> >> g_file_open_tmp(), which internally opens the file with
>> >> FILE_SHARE_WRITE security attribute, and based on [1], there is
>> >> only one case that allows the first call to CreateFile() with
>> >> GENERIC_READ & FILE_SHARE_WRITE, and second call to CreateFile()
>> >> with GENERIC_WRITE & FILE_SHARE_READ. All other combinations
>> >> require FILE_SHARE_WRITE in the second call. But there is no way
>> >> for the second call (in this case the QEMU executable) to know
>> >> what combination was passed to the first call, so we will have to
>> >> add FILE_SHARE_WRITE to the second call.
>> >>
>> >> For both scenarios we should add FILE_SHARE_WRITE in the chardev
>> >> file backend driver. This change also makes the behavior to be
>> >> consistent with the POSIX platforms.
>> >
>> >
>> > It seems to me the tests should be fixed instead. I thought you fixed the first case. For the second case, why not close the file before starting qemu? If you have issues, I will take a deeper look.
>>
>> Indeed, the following test case change can "fix" this issue:
>>
>> diff --git a/tests/qtest/boot-serial-test.c b/tests/qtest/boot-serial-test.c
>> index 72310ba30e..f192fbc181 100644
>> --- a/tests/qtest/boot-serial-test.c
>> +++ b/tests/qtest/boot-serial-test.c
>> @@ -233,6 +233,7 @@ static void test_machine(const void *data)
>> ser_fd = g_file_open_tmp("qtest-boot-serial-sXXXXXX", &serialtmp, NULL);
>> g_assert(ser_fd != -1);
>> + close(ser_fd);
>> if (test->kernel) {
>> code = test->kernel;
>> @@ -266,6 +267,7 @@ static void test_machine(const void *data)
>> unlink(codetmp);
>> }
>> + ser_fd = open(serialtmp, O_RDONLY);
>> if (!check_guest_output(qts, test, ser_fd)) {
>> g_error("Failed to find expected string. Please check '%s'",
>> serialtmp);
>>
>
> Please send this fix as a new patch in the series.
>
>>
>> But I think it just workarounds the problem. The original test case
>> looks reasonable to me. If we update the case like above, we cannot
>> guarantee users will do like the updated test case does.
>
>
> If the test is enabled, it will fail, and the reasons are reasonably valid: two processes shouldn't share the same file for writing with a chardev.
>
> I still think the windows file chardev behavior is superior and we should instead teach the posix implementation of exclusive write access, rather than downgrading the windows implementation. I'd drop this patch from the series for now.
>

Okay, will drop this patch, and add the test case fix as a new patch in v4.

Regards,
Bin


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

end of thread, other threads:[~2022-09-27 10:45 UTC | newest]

Thread overview: 89+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-25 11:29 [PATCH v3 00/54] tests/qtest: Enable running qtest on Windows Bin Meng
2022-09-25 11:29 ` [PATCH v3 01/54] tests/qtest: i440fx-test: Rewrite create_blob_file() to be portable Bin Meng
2022-09-26 12:10   ` Thomas Huth
2022-09-25 11:29 ` [PATCH v3 02/54] semihosting/arm-compat-semi: Avoid using hardcoded /tmp Bin Meng
2022-09-25 11:29 ` [PATCH v3 03/54] tcg: " Bin Meng
2022-09-25 11:29 ` [PATCH v3 04/54] util/qemu-sockets: Use g_get_tmp_dir() to get the directory for temporary files Bin Meng
2022-09-25 11:29 ` [PATCH v3 05/54] tests/qtest: ahci-test: Avoid using hardcoded /tmp Bin Meng
2022-09-26 12:17   ` Thomas Huth
2022-09-25 11:29 ` [PATCH v3 06/54] tests/qtest: aspeed_smc-test: " Bin Meng
2022-09-25 16:20   ` Cédric Le Goater
2022-09-26 12:18   ` Thomas Huth
2022-09-25 11:29 ` [PATCH v3 07/54] tests/qtest: boot-serial-test: " Bin Meng
2022-09-26 12:22   ` Thomas Huth
2022-09-25 11:29 ` [PATCH v3 08/54] tests/qtest: cxl-test: " Bin Meng
2022-09-26 13:07   ` Marc-André Lureau
2022-09-25 11:29 ` [PATCH v3 09/54] tests/qtest: fdc-test: " Bin Meng
2022-09-26 13:08   ` Marc-André Lureau
2022-09-25 11:29 ` [PATCH v3 10/54] tests/qtest: generic_fuzz: " Bin Meng
2022-09-26 13:09   ` Marc-André Lureau
2022-09-25 11:29 ` [PATCH v3 11/54] tests/qtest: virtio_blk_fuzz: " Bin Meng
2022-09-26 13:11   ` Marc-André Lureau
2022-09-25 11:29 ` [PATCH v3 12/54] tests/qtest: hd-geo-test: " Bin Meng
2022-09-26 13:11   ` Marc-André Lureau
2022-09-26 15:38   ` Thomas Huth
2022-09-25 11:29 ` [PATCH v3 13/54] tests/qtest: ide-test: " Bin Meng
2022-09-26 13:12   ` Marc-André Lureau
2022-09-25 11:29 ` [PATCH v3 14/54] tests/qtest: migration-test: " Bin Meng
2022-09-26 13:15   ` Marc-André Lureau
2022-09-25 11:29 ` [PATCH v3 15/54] tests/qtest: pflash-cfi02-test: " Bin Meng
2022-09-26 13:18   ` Marc-André Lureau
2022-09-25 11:29 ` [PATCH v3 16/54] tests/qtest: qmp-test: " Bin Meng
2022-09-26 13:19   ` Marc-André Lureau
2022-09-25 11:29 ` [PATCH v3 17/54] tests/qtest: vhost-user-blk-test: " Bin Meng
2022-09-26 13:20   ` Marc-André Lureau
2022-09-25 11:29 ` [PATCH v3 18/54] tests/qtest: vhost-user-test: " Bin Meng
2022-09-26 13:21   ` Marc-André Lureau
2022-09-25 11:29 ` [PATCH v3 19/54] tests/qtest: virtio-blk-test: " Bin Meng
2022-09-26 13:21   ` Marc-André Lureau
2022-09-25 11:29 ` [PATCH v3 20/54] tests/qtest: virtio-scsi-test: " Bin Meng
2022-09-26 13:21   ` Marc-André Lureau
2022-09-25 11:29 ` [PATCH v3 21/54] tests/qtest: libqtest: " Bin Meng
2022-09-26 13:22   ` Marc-André Lureau
2022-09-25 11:30 ` [PATCH v3 22/54] tests/unit: test-image-locking: " Bin Meng
2022-09-26 13:22   ` Marc-André Lureau
2022-09-25 11:30 ` [PATCH v3 23/54] tests/unit: test-qga: " Bin Meng
2022-09-26 13:23   ` Marc-André Lureau
2022-09-25 11:30 ` [PATCH v3 24/54] tests: vhost-user-bridge: " Bin Meng
2022-09-26 13:23   ` Marc-André Lureau
2022-09-25 11:30 ` [PATCH v3 25/54] block/vvfat: Unify the mkdir() call Bin Meng
2022-09-25 11:30 ` [PATCH v3 26/54] fsdev/virtfs-proxy-helper: Use g_mkdir() Bin Meng
2022-09-25 11:30 ` [PATCH v3 27/54] hw/usb: dev-mtp: " Bin Meng
2022-09-25 11:30 ` [PATCH v3 28/54] tests/qtest: Skip running virtio-net-test cases that require socketpair() for win32 Bin Meng
2022-09-25 11:30 ` [PATCH v3 29/54] tests/qtest: Build test-filter-{mirror, redirector} cases for posix only Bin Meng
2022-09-25 11:30 ` [PATCH v3 30/54] tests/qtest: qmp-test: Skip running test_qmp_oob for win32 Bin Meng
2022-09-25 11:30 ` [PATCH v3 31/54] accel/qtest: Implement a portable qtest accelerator Bin Meng
2022-09-25 11:30 ` [PATCH v3 32/54] tests/qtest: libqtest: Adapt global_qtest declaration for win32 Bin Meng
2022-09-26 16:07   ` Thomas Huth
2022-09-25 11:30 ` [PATCH v3 33/54] tests/qtest: Use send/recv for socket communication Bin Meng
2022-09-25 11:30 ` [PATCH v3 34/54] tests/qtest: libqtest: Exclude the *_fds APIs for win32 Bin Meng
2022-09-25 11:30 ` [PATCH v3 35/54] tests/qtest: libqtest: Install signal handler via signal() Bin Meng
2022-09-26 13:24   ` Marc-André Lureau
2022-09-25 11:30 ` [PATCH v3 36/54] tests/qtest: Support libqtest to build and run on Windows Bin Meng
2022-09-25 11:30 ` [PATCH v3 37/54] tests/qtest: {ahci, ide}-test: Use relative path for temporary files for win32 Bin Meng
2022-09-26 16:20   ` Thomas Huth
2022-09-27  0:17     ` Bin Meng
2022-09-25 11:30 ` [PATCH v3 38/54] tests/qtest: bios-tables-test: Adapt the case " Bin Meng
2022-09-25 12:41   ` Michael S. Tsirkin
2022-09-25 11:30 ` [PATCH v3 39/54] tests/qtest: migration-test: Disable IO redirection " Bin Meng
2022-09-25 11:30 ` [PATCH v3 40/54] tests/qtest: ide-test: Open file in binary mode Bin Meng
2022-09-25 11:30 ` [PATCH v3 41/54] tests/qtest: virtio-net-failover: Disable migration tests for win32 Bin Meng
2022-09-25 11:30 ` [PATCH v3 42/54] chardev/char-file: Add FILE_SHARE_WRITE when opening the file " Bin Meng
2022-09-26 13:27   ` Marc-André Lureau
2022-09-26 15:05     ` Bin Meng
2022-09-27  9:00       ` Marc-André Lureau
2022-09-27 10:44         ` Bin Meng
2022-09-25 11:30 ` [PATCH v3 43/54] tests/qtest: migration-test: Make sure QEMU process "to" exited after migration is canceled Bin Meng
2022-09-25 11:30 ` [PATCH v3 44/54] tests/qtest: microbit-test: Fix socket access for win32 Bin Meng
2022-09-25 11:30 ` [PATCH v3 45/54] tests/qtest: libqtest: Replace the call to close a socket with closesocket() Bin Meng
2022-09-25 11:30 ` [PATCH v3 46/54] tests/qtest: libqtest: Correct the timeout unit of blocking receive calls for win32 Bin Meng
2022-09-25 11:30 ` [PATCH v3 47/54] io/channel-watch: Drop a superfluous '#ifdef WIN32' Bin Meng
2022-09-25 11:30 ` [PATCH v3 48/54] io/channel-watch: Drop the unnecessary cast Bin Meng
2022-09-25 11:30 ` [PATCH v3 49/54] io/channel-watch: Fix socket watch on Windows Bin Meng
2022-09-25 11:30 ` [PATCH v3 50/54] tests/qtest: migration-test: Skip running some TLS cases for win32 Bin Meng
2022-09-25 11:30 ` [PATCH v3 51/54] .gitlab-ci.d/windows.yml: Increase the timeout to 90 minutes Bin Meng
2022-09-25 11:30 ` [PATCH v3 52/54] .gitlab-ci.d/windows.yml: Display meson test logs Bin Meng
2022-09-26 16:46   ` Thomas Huth
2022-09-25 11:30 ` [PATCH v3 53/54] tests/qtest: Enable qtest build on Windows Bin Meng
2022-09-25 11:30 ` [PATCH v3 54/54] docs/devel: testing: Document writing portable test cases Bin Meng
2022-09-26 16:55   ` Thomas Huth

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).