qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PULL 00/37] qtests fixes
@ 2022-09-28  7:18 Thomas Huth
  2022-09-28  7:18 ` [PULL 01/37] tests/qtest: i440fx-test: Rewrite create_blob_file() to be portable Thomas Huth
                   ` (37 more replies)
  0 siblings, 38 replies; 39+ messages in thread
From: Thomas Huth @ 2022-09-28  7:18 UTC (permalink / raw)
  To: Stefan Hajnoczi, qemu-devel

The following changes since commit dbc4f48b5ab3e6d85f78aa4df6bd6ad561c3d152:

  Merge tag 'net-pull-request' of https://github.com/jasowang/qemu into staging (2022-09-27 11:08:36 -0400)

are available in the Git repository at:

  https://gitlab.com/thuth/qemu.git tags/pull-request-2022-09-28

for you to fetch changes up to 0b49bc1b713d6e3896179f9700c8c35e511075f6:

  docs/devel: testing: Document writing portable test cases (2022-09-27 20:51:21 +0200)

----------------------------------------------------------------
* Fixes for qtests and unit tests to be more portable to non-POSIX platforms

----------------------------------------------------------------
Bin Meng (33):
      tests/qtest: i440fx-test: Rewrite create_blob_file() to be portable
      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: ide-test: Avoid using hardcoded /tmp
      tests/qtest: vhost-user-blk-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
      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: {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: migration-test: Skip running some TLS cases for win32
      .gitlab-ci.d/windows.yml: Display meson test logs
      tests/qtest: hd-geo-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-test: Avoid using hardcoded /tmp
      tests/qtest: boot-serial-test: Close the serial file before starting QEMU
      docs/devel: testing: Document writing portable test cases

Michael Labiuk (1):
      tests/x86: Move common code to function in device-plug-test

Xuzhou Cheng (3):
      tests/qtest: libqtest: Adapt global_qtest declaration for win32
      tests/qtest: ide-test: Open file in binary mode
      tests/qtest: virtio-net-failover: Disable migration tests for win32

 docs/devel/testing.rst                  | 30 ++++++++++++++++++
 tests/qtest/fuzz/generic_fuzz_configs.h |  4 +--
 tests/qtest/libqtest-single.h           |  4 +++
 tests/qtest/libqtest.h                  |  8 +++++
 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          | 11 ++++---
 tests/qtest/cxl-test.c                  | 15 ++++-----
 tests/qtest/device-plug-test.c          | 42 +++++++++++--------------
 tests/qtest/fdc-test.c                  |  5 +--
 tests/qtest/fuzz/virtio_blk_fuzz.c      |  4 +--
 tests/qtest/hd-geo-test.c               | 24 +++++++--------
 tests/qtest/i440fx-test.c               | 54 +++++++++------------------------
 tests/qtest/ide-test.c                  | 30 ++++++++++++++----
 tests/qtest/libqtest.c                  | 30 ++++++++++++------
 tests/qtest/microbit-test.c             | 10 +++---
 tests/qtest/migration-test.c            | 23 ++++++++++++++
 tests/qtest/pflash-cfi02-test.c         | 15 +++++----
 tests/qtest/qmp-test.c                  | 17 ++++++++---
 tests/qtest/vhost-user-blk-test.c       |  3 +-
 tests/qtest/vhost-user-test.c           | 10 +++---
 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 +-
 .gitlab-ci.d/windows.yml                |  4 +--
 tests/qtest/meson.build                 | 36 ++++++++++------------
 31 files changed, 285 insertions(+), 190 deletions(-)



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

* [PULL 01/37] tests/qtest: i440fx-test: Rewrite create_blob_file() to be portable
  2022-09-28  7:18 [PULL 00/37] qtests fixes Thomas Huth
@ 2022-09-28  7:18 ` Thomas Huth
  2022-09-28  7:18 ` [PULL 02/37] tests/qtest: ahci-test: Avoid using hardcoded /tmp Thomas Huth
                   ` (36 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Thomas Huth @ 2022-09-28  7:18 UTC (permalink / raw)
  To: Stefan Hajnoczi, qemu-devel; +Cc: Bin Meng, Marc-André Lureau

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>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Message-Id: <20220925113032.1949844-2-bmeng.cn@gmail.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 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.31.1



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

* [PULL 02/37] tests/qtest: ahci-test: Avoid using hardcoded /tmp
  2022-09-28  7:18 [PULL 00/37] qtests fixes Thomas Huth
  2022-09-28  7:18 ` [PULL 01/37] tests/qtest: i440fx-test: Rewrite create_blob_file() to be portable Thomas Huth
@ 2022-09-28  7:18 ` Thomas Huth
  2022-09-28  7:18 ` [PULL 03/37] tests/qtest: aspeed_smc-test: " Thomas Huth
                   ` (35 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Thomas Huth @ 2022-09-28  7:18 UTC (permalink / raw)
  To: Stefan Hajnoczi, qemu-devel; +Cc: 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>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Message-Id: <20220925113032.1949844-6-bmeng.cn@gmail.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 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.31.1



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

* [PULL 03/37] tests/qtest: aspeed_smc-test: Avoid using hardcoded /tmp
  2022-09-28  7:18 [PULL 00/37] qtests fixes Thomas Huth
  2022-09-28  7:18 ` [PULL 01/37] tests/qtest: i440fx-test: Rewrite create_blob_file() to be portable Thomas Huth
  2022-09-28  7:18 ` [PULL 02/37] tests/qtest: ahci-test: Avoid using hardcoded /tmp Thomas Huth
@ 2022-09-28  7:18 ` Thomas Huth
  2022-09-28  7:18 ` [PULL 04/37] tests/qtest: boot-serial-test: " Thomas Huth
                   ` (34 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Thomas Huth @ 2022-09-28  7:18 UTC (permalink / raw)
  To: Stefan Hajnoczi, qemu-devel; +Cc: Bin Meng, Cédric Le Goater

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: Thomas Huth <thuth@redhat.com>
Reviewed-by: Cédric Le Goater <clg@kaod.org>
Message-Id: <20220925113032.1949844-7-bmeng.cn@gmail.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 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.31.1



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

* [PULL 04/37] tests/qtest: boot-serial-test: Avoid using hardcoded /tmp
  2022-09-28  7:18 [PULL 00/37] qtests fixes Thomas Huth
                   ` (2 preceding siblings ...)
  2022-09-28  7:18 ` [PULL 03/37] tests/qtest: aspeed_smc-test: " Thomas Huth
@ 2022-09-28  7:18 ` Thomas Huth
  2022-09-28  7:18 ` [PULL 05/37] tests/qtest: cxl-test: " Thomas Huth
                   ` (33 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Thomas Huth @ 2022-09-28  7:18 UTC (permalink / raw)
  To: Stefan Hajnoczi, qemu-devel; +Cc: 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>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Message-Id: <20220925113032.1949844-8-bmeng.cn@gmail.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 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.31.1



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

* [PULL 05/37] tests/qtest: cxl-test: Avoid using hardcoded /tmp
  2022-09-28  7:18 [PULL 00/37] qtests fixes Thomas Huth
                   ` (3 preceding siblings ...)
  2022-09-28  7:18 ` [PULL 04/37] tests/qtest: boot-serial-test: " Thomas Huth
@ 2022-09-28  7:18 ` Thomas Huth
  2022-09-28  7:18 ` [PULL 06/37] tests/qtest: fdc-test: " Thomas Huth
                   ` (32 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Thomas Huth @ 2022-09-28  7:18 UTC (permalink / raw)
  To: Stefan Hajnoczi, qemu-devel; +Cc: Bin Meng, Marc-André Lureau

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>
Message-Id: <20220925113032.1949844-9-bmeng.cn@gmail.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 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.31.1



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

* [PULL 06/37] tests/qtest: fdc-test: Avoid using hardcoded /tmp
  2022-09-28  7:18 [PULL 00/37] qtests fixes Thomas Huth
                   ` (4 preceding siblings ...)
  2022-09-28  7:18 ` [PULL 05/37] tests/qtest: cxl-test: " Thomas Huth
@ 2022-09-28  7:18 ` Thomas Huth
  2022-09-28  7:18 ` [PULL 07/37] tests/qtest: generic_fuzz: " Thomas Huth
                   ` (31 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Thomas Huth @ 2022-09-28  7:18 UTC (permalink / raw)
  To: Stefan Hajnoczi, qemu-devel; +Cc: Bin Meng, Marc-André Lureau

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>
Message-Id: <20220925113032.1949844-10-bmeng.cn@gmail.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 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.31.1



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

* [PULL 07/37] tests/qtest: generic_fuzz: Avoid using hardcoded /tmp
  2022-09-28  7:18 [PULL 00/37] qtests fixes Thomas Huth
                   ` (5 preceding siblings ...)
  2022-09-28  7:18 ` [PULL 06/37] tests/qtest: fdc-test: " Thomas Huth
@ 2022-09-28  7:18 ` Thomas Huth
  2022-09-28  7:18 ` [PULL 08/37] tests/qtest: virtio_blk_fuzz: " Thomas Huth
                   ` (30 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Thomas Huth @ 2022-09-28  7:18 UTC (permalink / raw)
  To: Stefan Hajnoczi, qemu-devel; +Cc: Bin Meng, Marc-André Lureau

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>
Message-Id: <20220925113032.1949844-11-bmeng.cn@gmail.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 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.31.1



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

* [PULL 08/37] tests/qtest: virtio_blk_fuzz: Avoid using hardcoded /tmp
  2022-09-28  7:18 [PULL 00/37] qtests fixes Thomas Huth
                   ` (6 preceding siblings ...)
  2022-09-28  7:18 ` [PULL 07/37] tests/qtest: generic_fuzz: " Thomas Huth
@ 2022-09-28  7:18 ` Thomas Huth
  2022-09-28  7:18 ` [PULL 09/37] tests/qtest: ide-test: " Thomas Huth
                   ` (29 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Thomas Huth @ 2022-09-28  7:18 UTC (permalink / raw)
  To: Stefan Hajnoczi, qemu-devel; +Cc: Bin Meng, Marc-André Lureau

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>
Message-Id: <20220925113032.1949844-12-bmeng.cn@gmail.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 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.31.1



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

* [PULL 09/37] tests/qtest: ide-test: Avoid using hardcoded /tmp
  2022-09-28  7:18 [PULL 00/37] qtests fixes Thomas Huth
                   ` (7 preceding siblings ...)
  2022-09-28  7:18 ` [PULL 08/37] tests/qtest: virtio_blk_fuzz: " Thomas Huth
@ 2022-09-28  7:18 ` Thomas Huth
  2022-09-28  7:18 ` [PULL 10/37] tests/qtest: vhost-user-blk-test: " Thomas Huth
                   ` (28 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Thomas Huth @ 2022-09-28  7:18 UTC (permalink / raw)
  To: Stefan Hajnoczi, qemu-devel; +Cc: Bin Meng, Marc-André Lureau

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>
Message-Id: <20220925113032.1949844-14-bmeng.cn@gmail.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 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.31.1



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

* [PULL 10/37] tests/qtest: vhost-user-blk-test: Avoid using hardcoded /tmp
  2022-09-28  7:18 [PULL 00/37] qtests fixes Thomas Huth
                   ` (8 preceding siblings ...)
  2022-09-28  7:18 ` [PULL 09/37] tests/qtest: ide-test: " Thomas Huth
@ 2022-09-28  7:18 ` Thomas Huth
  2022-09-28  7:18 ` [PULL 11/37] tests/qtest: virtio-blk-test: " Thomas Huth
                   ` (27 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Thomas Huth @ 2022-09-28  7:18 UTC (permalink / raw)
  To: Stefan Hajnoczi, qemu-devel; +Cc: Bin Meng, Marc-André Lureau

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>
Message-Id: <20220925113032.1949844-18-bmeng.cn@gmail.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 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.31.1



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

* [PULL 11/37] tests/qtest: virtio-blk-test: Avoid using hardcoded /tmp
  2022-09-28  7:18 [PULL 00/37] qtests fixes Thomas Huth
                   ` (9 preceding siblings ...)
  2022-09-28  7:18 ` [PULL 10/37] tests/qtest: vhost-user-blk-test: " Thomas Huth
@ 2022-09-28  7:18 ` Thomas Huth
  2022-09-28  7:18 ` [PULL 12/37] tests/qtest: virtio-scsi-test: " Thomas Huth
                   ` (26 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Thomas Huth @ 2022-09-28  7:18 UTC (permalink / raw)
  To: Stefan Hajnoczi, qemu-devel; +Cc: Bin Meng, Marc-André Lureau

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>
Message-Id: <20220925113032.1949844-20-bmeng.cn@gmail.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 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.31.1



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

* [PULL 12/37] tests/qtest: virtio-scsi-test: Avoid using hardcoded /tmp
  2022-09-28  7:18 [PULL 00/37] qtests fixes Thomas Huth
                   ` (10 preceding siblings ...)
  2022-09-28  7:18 ` [PULL 11/37] tests/qtest: virtio-blk-test: " Thomas Huth
@ 2022-09-28  7:18 ` Thomas Huth
  2022-09-28  7:18 ` [PULL 13/37] tests/qtest: libqtest: " Thomas Huth
                   ` (25 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Thomas Huth @ 2022-09-28  7:18 UTC (permalink / raw)
  To: Stefan Hajnoczi, qemu-devel; +Cc: Bin Meng, Marc-André Lureau

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>
Message-Id: <20220925113032.1949844-21-bmeng.cn@gmail.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 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.31.1



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

* [PULL 13/37] tests/qtest: libqtest: Avoid using hardcoded /tmp
  2022-09-28  7:18 [PULL 00/37] qtests fixes Thomas Huth
                   ` (11 preceding siblings ...)
  2022-09-28  7:18 ` [PULL 12/37] tests/qtest: virtio-scsi-test: " Thomas Huth
@ 2022-09-28  7:18 ` Thomas Huth
  2022-09-28  7:18 ` [PULL 14/37] tests/unit: test-image-locking: " Thomas Huth
                   ` (24 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Thomas Huth @ 2022-09-28  7:18 UTC (permalink / raw)
  To: Stefan Hajnoczi, qemu-devel; +Cc: Bin Meng, Marc-André Lureau

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>
Message-Id: <20220925113032.1949844-22-bmeng.cn@gmail.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 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.31.1



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

* [PULL 14/37] tests/unit: test-image-locking: Avoid using hardcoded /tmp
  2022-09-28  7:18 [PULL 00/37] qtests fixes Thomas Huth
                   ` (12 preceding siblings ...)
  2022-09-28  7:18 ` [PULL 13/37] tests/qtest: libqtest: " Thomas Huth
@ 2022-09-28  7:18 ` Thomas Huth
  2022-09-28  7:18 ` [PULL 15/37] tests/unit: test-qga: " Thomas Huth
                   ` (23 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Thomas Huth @ 2022-09-28  7:18 UTC (permalink / raw)
  To: Stefan Hajnoczi, qemu-devel; +Cc: Bin Meng, Marc-André Lureau

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>
Message-Id: <20220925113032.1949844-23-bmeng.cn@gmail.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 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.31.1



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

* [PULL 15/37] tests/unit: test-qga: Avoid using hardcoded /tmp
  2022-09-28  7:18 [PULL 00/37] qtests fixes Thomas Huth
                   ` (13 preceding siblings ...)
  2022-09-28  7:18 ` [PULL 14/37] tests/unit: test-image-locking: " Thomas Huth
@ 2022-09-28  7:18 ` Thomas Huth
  2022-09-28  7:18 ` [PULL 16/37] tests: vhost-user-bridge: " Thomas Huth
                   ` (22 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Thomas Huth @ 2022-09-28  7:18 UTC (permalink / raw)
  To: Stefan Hajnoczi, qemu-devel; +Cc: Bin Meng, Marc-André Lureau

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>
Message-Id: <20220925113032.1949844-24-bmeng.cn@gmail.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 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.31.1



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

* [PULL 16/37] tests: vhost-user-bridge: Avoid using hardcoded /tmp
  2022-09-28  7:18 [PULL 00/37] qtests fixes Thomas Huth
                   ` (14 preceding siblings ...)
  2022-09-28  7:18 ` [PULL 15/37] tests/unit: test-qga: " Thomas Huth
@ 2022-09-28  7:18 ` Thomas Huth
  2022-09-28  7:18 ` [PULL 17/37] tests/qtest: Skip running virtio-net-test cases that require socketpair() for win32 Thomas Huth
                   ` (21 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Thomas Huth @ 2022-09-28  7:18 UTC (permalink / raw)
  To: Stefan Hajnoczi, qemu-devel; +Cc: Bin Meng, Marc-André Lureau

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>
Message-Id: <20220925113032.1949844-25-bmeng.cn@gmail.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 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.31.1



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

* [PULL 17/37] tests/qtest: Skip running virtio-net-test cases that require socketpair() for win32
  2022-09-28  7:18 [PULL 00/37] qtests fixes Thomas Huth
                   ` (15 preceding siblings ...)
  2022-09-28  7:18 ` [PULL 16/37] tests: vhost-user-bridge: " Thomas Huth
@ 2022-09-28  7:18 ` Thomas Huth
  2022-09-28  7:18 ` [PULL 18/37] tests/qtest: Build test-filter-{mirror, redirector} cases for posix only Thomas Huth
                   ` (20 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Thomas Huth @ 2022-09-28  7:18 UTC (permalink / raw)
  To: Stefan Hajnoczi, qemu-devel; +Cc: Bin Meng, Marc-André Lureau

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>
Message-Id: <20220925113032.1949844-29-bmeng.cn@gmail.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 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.31.1



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

* [PULL 18/37] tests/qtest: Build test-filter-{mirror, redirector} cases for posix only
  2022-09-28  7:18 [PULL 00/37] qtests fixes Thomas Huth
                   ` (16 preceding siblings ...)
  2022-09-28  7:18 ` [PULL 17/37] tests/qtest: Skip running virtio-net-test cases that require socketpair() for win32 Thomas Huth
@ 2022-09-28  7:18 ` Thomas Huth
  2022-09-28  7:18 ` [PULL 19/37] tests/qtest: qmp-test: Skip running test_qmp_oob for win32 Thomas Huth
                   ` (19 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Thomas Huth @ 2022-09-28  7:18 UTC (permalink / raw)
  To: Stefan Hajnoczi, qemu-devel; +Cc: Bin Meng, Marc-André Lureau

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>
Message-Id: <20220925113032.1949844-30-bmeng.cn@gmail.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 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.31.1



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

* [PULL 19/37] tests/qtest: qmp-test: Skip running test_qmp_oob for win32
  2022-09-28  7:18 [PULL 00/37] qtests fixes Thomas Huth
                   ` (17 preceding siblings ...)
  2022-09-28  7:18 ` [PULL 18/37] tests/qtest: Build test-filter-{mirror, redirector} cases for posix only Thomas Huth
@ 2022-09-28  7:18 ` Thomas Huth
  2022-09-28  7:18 ` [PULL 20/37] tests/qtest: libqtest: Adapt global_qtest declaration " Thomas Huth
                   ` (18 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Thomas Huth @ 2022-09-28  7:18 UTC (permalink / raw)
  To: Stefan Hajnoczi, qemu-devel; +Cc: Bin Meng

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>
Message-Id: <20220925113032.1949844-31-bmeng.cn@gmail.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 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 bf7304c7dc..23b2a37942 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[] = "/tmp/qmp-test-XXXXXX";
@@ -277,6 +279,8 @@ static void test_qmp_oob(void)
     qtest_quit(qts);
 }
 
+#endif /* _WIN32 */
+
 /* Preconfig tests */
 
 static void test_qmp_preconfig(void)
@@ -336,7 +340,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.31.1



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

* [PULL 20/37] tests/qtest: libqtest: Adapt global_qtest declaration for win32
  2022-09-28  7:18 [PULL 00/37] qtests fixes Thomas Huth
                   ` (18 preceding siblings ...)
  2022-09-28  7:18 ` [PULL 19/37] tests/qtest: qmp-test: Skip running test_qmp_oob for win32 Thomas Huth
@ 2022-09-28  7:18 ` Thomas Huth
  2022-09-28  7:18 ` [PULL 21/37] tests/qtest: libqtest: Exclude the *_fds APIs " Thomas Huth
                   ` (17 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Thomas Huth @ 2022-09-28  7:18 UTC (permalink / raw)
  To: Stefan Hajnoczi, qemu-devel; +Cc: Xuzhou Cheng, Bin Meng

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>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Message-Id: <20220925113032.1949844-33-bmeng.cn@gmail.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 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.31.1



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

* [PULL 21/37] tests/qtest: libqtest: Exclude the *_fds APIs for win32
  2022-09-28  7:18 [PULL 00/37] qtests fixes Thomas Huth
                   ` (19 preceding siblings ...)
  2022-09-28  7:18 ` [PULL 20/37] tests/qtest: libqtest: Adapt global_qtest declaration " Thomas Huth
@ 2022-09-28  7:18 ` Thomas Huth
  2022-09-28  7:18 ` [PULL 22/37] tests/qtest: {ahci, ide}-test: Use relative path for temporary files " Thomas Huth
                   ` (16 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Thomas Huth @ 2022-09-28  7:18 UTC (permalink / raw)
  To: Stefan Hajnoczi, qemu-devel; +Cc: Bin Meng, Marc-André Lureau

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>
Message-Id: <20220925113032.1949844-35-bmeng.cn@gmail.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 tests/qtest/libqtest.h |  8 ++++++++
 tests/qtest/libqtest.c | 10 +++++++++-
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/tests/qtest/libqtest.h b/tests/qtest/libqtest.h
index 94b187837d..3abc75964d 100644
--- a/tests/qtest/libqtest.h
+++ b/tests/qtest/libqtest.h
@@ -94,6 +94,7 @@ void qtest_kill_qemu(QTestState *s);
  */
 void qtest_quit(QTestState *s);
 
+#ifndef _WIN32
 /**
  * qtest_qmp_fds:
  * @s: #QTestState instance to operate on.
@@ -108,6 +109,7 @@ void qtest_quit(QTestState *s);
 QDict *qtest_qmp_fds(QTestState *s, int *fds, size_t fds_num,
                      const char *fmt, ...)
     G_GNUC_PRINTF(4, 5);
+#endif /* _WIN32 */
 
 /**
  * qtest_qmp:
@@ -152,6 +154,7 @@ void qtest_qmp_send_raw(QTestState *s, const char *fmt, ...)
  */
 int qtest_socket_server(const char *socket_path);
 
+#ifndef _WIN32
 /**
  * qtest_vqmp_fds:
  * @s: #QTestState instance to operate on.
@@ -167,6 +170,7 @@ int qtest_socket_server(const char *socket_path);
 QDict *qtest_vqmp_fds(QTestState *s, int *fds, size_t fds_num,
                       const char *fmt, va_list ap)
     G_GNUC_PRINTF(4, 0);
+#endif /* _WIN32 */
 
 /**
  * qtest_vqmp:
@@ -181,6 +185,7 @@ QDict *qtest_vqmp_fds(QTestState *s, int *fds, size_t fds_num,
 QDict *qtest_vqmp(QTestState *s, const char *fmt, va_list ap)
     G_GNUC_PRINTF(2, 0);
 
+#ifndef _WIN32
 /**
  * qtest_qmp_vsend_fds:
  * @s: #QTestState instance to operate on.
@@ -196,6 +201,7 @@ QDict *qtest_vqmp(QTestState *s, const char *fmt, va_list ap)
 void qtest_qmp_vsend_fds(QTestState *s, int *fds, size_t fds_num,
                          const char *fmt, va_list ap)
     G_GNUC_PRINTF(4, 0);
+#endif /* _WIN32 */
 
 /**
  * qtest_qmp_vsend:
@@ -743,6 +749,7 @@ void qtest_qmp_device_add_qdict(QTestState *qts, const char *drv,
 void qtest_qmp_device_add(QTestState *qts, const char *driver, const char *id,
                           const char *fmt, ...) G_GNUC_PRINTF(4, 5);
 
+#ifndef _WIN32
 /**
  * qtest_qmp_add_client:
  * @qts: QTestState instance to operate on
@@ -752,6 +759,7 @@ void qtest_qmp_device_add(QTestState *qts, const char *driver, const char *id,
  * Call QMP ``getfd`` followed by ``add_client`` with the given @fd.
  */
 void qtest_qmp_add_client(QTestState *qts, const char *protocol, int fd);
+#endif /* _WIN32 */
 
 /**
  * qtest_qmp_device_del:
diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
index d8ffa0e7b1..5c4a509c58 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.31.1



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

* [PULL 22/37] tests/qtest: {ahci, ide}-test: Use relative path for temporary files for win32
  2022-09-28  7:18 [PULL 00/37] qtests fixes Thomas Huth
                   ` (20 preceding siblings ...)
  2022-09-28  7:18 ` [PULL 21/37] tests/qtest: libqtest: Exclude the *_fds APIs " Thomas Huth
@ 2022-09-28  7:18 ` Thomas Huth
  2022-09-28  7:18 ` [PULL 23/37] tests/qtest: bios-tables-test: Adapt the case " Thomas Huth
                   ` (15 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Thomas Huth @ 2022-09-28  7:18 UTC (permalink / raw)
  To: Stefan Hajnoczi, qemu-devel; +Cc: Bin Meng, Marc-André Lureau

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>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Message-Id: <20220925113032.1949844-38-bmeng.cn@gmail.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 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.31.1



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

* [PULL 23/37] tests/qtest: bios-tables-test: Adapt the case for win32
  2022-09-28  7:18 [PULL 00/37] qtests fixes Thomas Huth
                   ` (21 preceding siblings ...)
  2022-09-28  7:18 ` [PULL 22/37] tests/qtest: {ahci, ide}-test: Use relative path for temporary files " Thomas Huth
@ 2022-09-28  7:18 ` Thomas Huth
  2022-09-28  7:18 ` [PULL 24/37] tests/qtest: migration-test: Disable IO redirection " Thomas Huth
                   ` (14 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Thomas Huth @ 2022-09-28  7:18 UTC (permalink / raw)
  To: Stefan Hajnoczi, qemu-devel
  Cc: Bin Meng, Marc-André Lureau, 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>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Message-Id: <20220925113032.1949844-39-bmeng.cn@gmail.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 tests/qtest/bios-tables-test.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/tests/qtest/bios-tables-test.c b/tests/qtest/bios-tables-test.c
index 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.31.1



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

* [PULL 24/37] tests/qtest: migration-test: Disable IO redirection for win32
  2022-09-28  7:18 [PULL 00/37] qtests fixes Thomas Huth
                   ` (22 preceding siblings ...)
  2022-09-28  7:18 ` [PULL 23/37] tests/qtest: bios-tables-test: Adapt the case " Thomas Huth
@ 2022-09-28  7:18 ` Thomas Huth
  2022-09-28  7:18 ` [PULL 25/37] tests/qtest: ide-test: Open file in binary mode Thomas Huth
                   ` (13 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Thomas Huth @ 2022-09-28  7:18 UTC (permalink / raw)
  To: Stefan Hajnoczi, qemu-devel; +Cc: Bin Meng, Marc-André Lureau

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>
Message-Id: <20220925113032.1949844-40-bmeng.cn@gmail.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 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 4728d528bb..3db1177377 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.31.1



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

* [PULL 25/37] tests/qtest: ide-test: Open file in binary mode
  2022-09-28  7:18 [PULL 00/37] qtests fixes Thomas Huth
                   ` (23 preceding siblings ...)
  2022-09-28  7:18 ` [PULL 24/37] tests/qtest: migration-test: Disable IO redirection " Thomas Huth
@ 2022-09-28  7:18 ` Thomas Huth
  2022-09-28  7:18 ` [PULL 26/37] tests/qtest: virtio-net-failover: Disable migration tests for win32 Thomas Huth
                   ` (12 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Thomas Huth @ 2022-09-28  7:18 UTC (permalink / raw)
  To: Stefan Hajnoczi, qemu-devel
  Cc: Xuzhou Cheng, Bin Meng, Marc-André Lureau

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>
Message-Id: <20220925113032.1949844-41-bmeng.cn@gmail.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 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.31.1



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

* [PULL 26/37] tests/qtest: virtio-net-failover: Disable migration tests for win32
  2022-09-28  7:18 [PULL 00/37] qtests fixes Thomas Huth
                   ` (24 preceding siblings ...)
  2022-09-28  7:18 ` [PULL 25/37] tests/qtest: ide-test: Open file in binary mode Thomas Huth
@ 2022-09-28  7:18 ` Thomas Huth
  2022-09-28  7:18 ` [PULL 27/37] tests/qtest: microbit-test: Fix socket access " Thomas Huth
                   ` (11 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Thomas Huth @ 2022-09-28  7:18 UTC (permalink / raw)
  To: Stefan Hajnoczi, qemu-devel
  Cc: Xuzhou Cheng, Bin Meng, Marc-André Lureau

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>
Message-Id: <20220925113032.1949844-42-bmeng.cn@gmail.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 tests/qtest/virtio-net-failover.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

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



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

* [PULL 27/37] tests/qtest: microbit-test: Fix socket access for win32
  2022-09-28  7:18 [PULL 00/37] qtests fixes Thomas Huth
                   ` (25 preceding siblings ...)
  2022-09-28  7:18 ` [PULL 26/37] tests/qtest: virtio-net-failover: Disable migration tests for win32 Thomas Huth
@ 2022-09-28  7:18 ` Thomas Huth
  2022-09-28  7:18 ` [PULL 28/37] tests/qtest: libqtest: Replace the call to close a socket with closesocket() Thomas Huth
                   ` (10 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Thomas Huth @ 2022-09-28  7:18 UTC (permalink / raw)
  To: Stefan Hajnoczi, qemu-devel; +Cc: Bin Meng, Marc-André Lureau

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>
Message-Id: <20220925113032.1949844-45-bmeng.cn@gmail.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 tests/qtest/microbit-test.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

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



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

* [PULL 28/37] tests/qtest: libqtest: Replace the call to close a socket with closesocket()
  2022-09-28  7:18 [PULL 00/37] qtests fixes Thomas Huth
                   ` (26 preceding siblings ...)
  2022-09-28  7:18 ` [PULL 27/37] tests/qtest: microbit-test: Fix socket access " Thomas Huth
@ 2022-09-28  7:18 ` Thomas Huth
  2022-09-28  7:18 ` [PULL 29/37] tests/qtest: migration-test: Skip running some TLS cases for win32 Thomas Huth
                   ` (9 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Thomas Huth @ 2022-09-28  7:18 UTC (permalink / raw)
  To: Stefan Hajnoczi, qemu-devel; +Cc: Bin Meng, Marc-André Lureau

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>
Message-Id: <20220925113032.1949844-46-bmeng.cn@gmail.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 tests/qtest/libqtest.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
index 5c4a509c58..4f4b2d6477 100644
--- a/tests/qtest/libqtest.c
+++ b/tests/qtest/libqtest.c
@@ -97,7 +97,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;
     }
 
@@ -108,7 +108,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;
 }
@@ -421,8 +421,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.31.1



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

* [PULL 29/37] tests/qtest: migration-test: Skip running some TLS cases for win32
  2022-09-28  7:18 [PULL 00/37] qtests fixes Thomas Huth
                   ` (27 preceding siblings ...)
  2022-09-28  7:18 ` [PULL 28/37] tests/qtest: libqtest: Replace the call to close a socket with closesocket() Thomas Huth
@ 2022-09-28  7:18 ` Thomas Huth
  2022-09-28  7:18 ` [PULL 30/37] .gitlab-ci.d/windows.yml: Display meson test logs Thomas Huth
                   ` (8 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Thomas Huth @ 2022-09-28  7:18 UTC (permalink / raw)
  To: Stefan Hajnoczi, qemu-devel; +Cc: Bin Meng

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>
Message-Id: <20220925113032.1949844-51-bmeng.cn@gmail.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 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 3db1177377..0d153d6b5e 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)
 {
@@ -2492,8 +2500,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) {
         /*
@@ -2519,8 +2529,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
@@ -2564,8 +2576,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.31.1



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

* [PULL 30/37] .gitlab-ci.d/windows.yml: Display meson test logs
  2022-09-28  7:18 [PULL 00/37] qtests fixes Thomas Huth
                   ` (28 preceding siblings ...)
  2022-09-28  7:18 ` [PULL 29/37] tests/qtest: migration-test: Skip running some TLS cases for win32 Thomas Huth
@ 2022-09-28  7:18 ` Thomas Huth
  2022-09-28  7:18 ` [PULL 31/37] tests/x86: Move common code to function in device-plug-test Thomas Huth
                   ` (7 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Thomas Huth @ 2022-09-28  7:18 UTC (permalink / raw)
  To: Stefan Hajnoczi, qemu-devel; +Cc: Bin Meng

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>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Message-Id: <20220925113032.1949844-53-bmeng.cn@gmail.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 .gitlab-ci.d/windows.yml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/.gitlab-ci.d/windows.yml b/.gitlab-ci.d/windows.yml
index 86a4339c48..ba59844d12 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 --without-default-devices'
   - .\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.31.1



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

* [PULL 31/37] tests/x86: Move common code to function in device-plug-test
  2022-09-28  7:18 [PULL 00/37] qtests fixes Thomas Huth
                   ` (29 preceding siblings ...)
  2022-09-28  7:18 ` [PULL 30/37] .gitlab-ci.d/windows.yml: Display meson test logs Thomas Huth
@ 2022-09-28  7:18 ` Thomas Huth
  2022-09-28  7:18 ` [PULL 32/37] tests/qtest: hd-geo-test: Avoid using hardcoded /tmp Thomas Huth
                   ` (6 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Thomas Huth @ 2022-09-28  7:18 UTC (permalink / raw)
  To: Stefan Hajnoczi, qemu-devel; +Cc: Michael Labiuk

From: Michael Labiuk <michael.labiuk@virtuozzo.com>

Move common code for device removing to function.

Signed-off-by: Michael Labiuk <michael.labiuk@virtuozzo.com>
Message-Id: <20220920104842.605530-2-michael.labiuk@virtuozzo.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 tests/qtest/device-plug-test.c | 42 ++++++++++++++--------------------
 1 file changed, 17 insertions(+), 25 deletions(-)

diff --git a/tests/qtest/device-plug-test.c b/tests/qtest/device-plug-test.c
index a1fb99c8ff..e595b45b66 100644
--- a/tests/qtest/device-plug-test.c
+++ b/tests/qtest/device-plug-test.c
@@ -61,6 +61,18 @@ static void wait_device_deleted_event(QTestState *qtest, const char *id)
     }
 }
 
+static void process_device_remove(QTestState *qtest, const char *id)
+{
+    /*
+     * Request device removal. As the guest is not running, the request won't
+     * be processed. However during system reset, the removal will be
+     * handled, removing the device.
+     */
+    device_del(qtest, id);
+    system_reset(qtest);
+    wait_device_deleted_event(qtest, id);
+}
+
 static void test_pci_unplug_request(void)
 {
     const char *arch = qtest_get_arch();
@@ -73,14 +85,7 @@ static void test_pci_unplug_request(void)
     QTestState *qtest = qtest_initf("%s -device virtio-mouse-pci,id=dev0",
                                     machine_addition);
 
-    /*
-     * Request device removal. As the guest is not running, the request won't
-     * be processed. However during system reset, the removal will be
-     * handled, removing the device.
-     */
-    device_del(qtest, "dev0");
-    system_reset(qtest);
-    wait_device_deleted_event(qtest, "dev0");
+    process_device_remove(qtest, "dev0");
 
     qtest_quit(qtest);
 }
@@ -98,14 +103,7 @@ static void test_pci_unplug_json_request(void)
         "%s -device \"{'driver': 'virtio-mouse-pci', 'id': 'dev0'}\"",
         machine_addition);
 
-    /*
-     * Request device removal. As the guest is not running, the request won't
-     * be processed. However during system reset, the removal will be
-     * handled, removing the device.
-     */
-    device_del(qtest, "dev0");
-    system_reset(qtest);
-    wait_device_deleted_event(qtest, "dev0");
+    process_device_remove(qtest, "dev0");
 
     qtest_quit(qtest);
 }
@@ -128,9 +126,7 @@ static void test_spapr_cpu_unplug_request(void)
                         "-device power9_v2.0-spapr-cpu-core,core-id=1,id=dev0");
 
     /* similar to test_pci_unplug_request */
-    device_del(qtest, "dev0");
-    system_reset(qtest);
-    wait_device_deleted_event(qtest, "dev0");
+    process_device_remove(qtest, "dev0");
 
     qtest_quit(qtest);
 }
@@ -144,9 +140,7 @@ static void test_spapr_memory_unplug_request(void)
                         "-device pc-dimm,id=dev0,memdev=mem0");
 
     /* similar to test_pci_unplug_request */
-    device_del(qtest, "dev0");
-    system_reset(qtest);
-    wait_device_deleted_event(qtest, "dev0");
+    process_device_remove(qtest, "dev0");
 
     qtest_quit(qtest);
 }
@@ -158,9 +152,7 @@ static void test_spapr_phb_unplug_request(void)
     qtest = qtest_initf("-device spapr-pci-host-bridge,index=1,id=dev0");
 
     /* similar to test_pci_unplug_request */
-    device_del(qtest, "dev0");
-    system_reset(qtest);
-    wait_device_deleted_event(qtest, "dev0");
+    process_device_remove(qtest, "dev0");
 
     qtest_quit(qtest);
 }
-- 
2.31.1



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

* [PULL 32/37] tests/qtest: hd-geo-test: Avoid using hardcoded /tmp
  2022-09-28  7:18 [PULL 00/37] qtests fixes Thomas Huth
                   ` (30 preceding siblings ...)
  2022-09-28  7:18 ` [PULL 31/37] tests/x86: Move common code to function in device-plug-test Thomas Huth
@ 2022-09-28  7:18 ` Thomas Huth
  2022-09-28  7:18 ` [PULL 33/37] tests/qtest: pflash-cfi02-test: " Thomas Huth
                   ` (5 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Thomas Huth @ 2022-09-28  7:18 UTC (permalink / raw)
  To: Stefan Hajnoczi, qemu-devel; +Cc: 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>
Message-Id: <20220927110632.1973965-13-bmeng.cn@gmail.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 tests/qtest/hd-geo-test.c | 24 +++++++++++-------------
 1 file changed, 11 insertions(+), 13 deletions(-)

diff --git a/tests/qtest/hd-geo-test.c b/tests/qtest/hd-geo-test.c
index 413cf964c0..ba772f4d7a 100644
--- a/tests/qtest/hd-geo-test.c
+++ b/tests/qtest/hd-geo-test.c
@@ -27,16 +27,16 @@
 
 static char *create_test_img(int secs)
 {
-    char *template = strdup("/tmp/qtest.XXXXXX");
+    char *template;
     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);
+        g_free(template);
         template = NULL;
     }
 
@@ -422,9 +422,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 +467,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 +477,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 +505,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 +712,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 +865,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 +925,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 +985,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.31.1



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

* [PULL 33/37] tests/qtest: pflash-cfi02-test: Avoid using hardcoded /tmp
  2022-09-28  7:18 [PULL 00/37] qtests fixes Thomas Huth
                   ` (31 preceding siblings ...)
  2022-09-28  7:18 ` [PULL 32/37] tests/qtest: hd-geo-test: Avoid using hardcoded /tmp Thomas Huth
@ 2022-09-28  7:18 ` Thomas Huth
  2022-09-28  7:18 ` [PULL 34/37] tests/qtest: qmp-test: " Thomas Huth
                   ` (4 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Thomas Huth @ 2022-09-28  7:18 UTC (permalink / raw)
  To: Stefan Hajnoczi, qemu-devel; +Cc: Bin Meng, Marc-André Lureau

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>
Message-Id: <20220927110632.1973965-16-bmeng.cn@gmail.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 tests/qtest/pflash-cfi02-test.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/tests/qtest/pflash-cfi02-test.c b/tests/qtest/pflash-cfi02-test.c
index 7fce614b64..0b52c2ca5c 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,14 @@ static const FlashConfig configuration[] = {
 
 int main(int argc, char **argv)
 {
-    int fd = mkstemp(image_path);
-    if (fd == -1) {
-        g_printerr("Failed to create temporary file %s: %s\n", image_path,
-                   strerror(errno));
-        exit(EXIT_FAILURE);
-    }
+    GError *err = NULL;
+    int fd = g_file_open_tmp("qtest.XXXXXX", &image_path, &err);
+    g_assert_no_error(err);
+
     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.31.1



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

* [PULL 34/37] tests/qtest: qmp-test: Avoid using hardcoded /tmp
  2022-09-28  7:18 [PULL 00/37] qtests fixes Thomas Huth
                   ` (32 preceding siblings ...)
  2022-09-28  7:18 ` [PULL 33/37] tests/qtest: pflash-cfi02-test: " Thomas Huth
@ 2022-09-28  7:18 ` Thomas Huth
  2022-09-28  7:18 ` [PULL 35/37] tests/qtest: vhost-user-test: " Thomas Huth
                   ` (3 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Thomas Huth @ 2022-09-28  7:18 UTC (permalink / raw)
  To: Stefan Hajnoczi, qemu-devel; +Cc: Bin Meng, Marc-André Lureau

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>
Message-Id: <20220927110632.1973965-17-bmeng.cn@gmail.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 tests/qtest/qmp-test.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/tests/qtest/qmp-test.c b/tests/qtest/qmp-test.c
index 23b2a37942..22957fa49c 100644
--- a/tests/qtest/qmp-test.c
+++ b/tests/qtest/qmp-test.c
@@ -163,14 +163,15 @@ 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)) {
-        g_error("g_mkdtemp: %s", strerror(errno));
-    }
+    GError *err = NULL;
+    tmpdir = g_dir_make_tmp("qmp-test-XXXXXX", &err);
+    g_assert_no_error(err);
+
     fifo_name = g_strdup_printf("%s/fifo", tmpdir);
     if (mkfifo(fifo_name, 0666)) {
         g_error("mkfifo: %s", strerror(errno));
@@ -181,6 +182,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.31.1



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

* [PULL 35/37] tests/qtest: vhost-user-test: Avoid using hardcoded /tmp
  2022-09-28  7:18 [PULL 00/37] qtests fixes Thomas Huth
                   ` (33 preceding siblings ...)
  2022-09-28  7:18 ` [PULL 34/37] tests/qtest: qmp-test: " Thomas Huth
@ 2022-09-28  7:18 ` Thomas Huth
  2022-09-28  7:18 ` [PULL 36/37] tests/qtest: boot-serial-test: Close the serial file before starting QEMU Thomas Huth
                   ` (2 subsequent siblings)
  37 siblings, 0 replies; 39+ messages in thread
From: Thomas Huth @ 2022-09-28  7:18 UTC (permalink / raw)
  To: Stefan Hajnoczi, qemu-devel; +Cc: Bin Meng, Marc-André Lureau

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>
Message-Id: <20220927110632.1973965-19-bmeng.cn@gmail.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 tests/qtest/vhost-user-test.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/tests/qtest/vhost-user-test.c b/tests/qtest/vhost-user-test.c
index d7d6cfc9bd..84498941a6 100644
--- a/tests/qtest/vhost-user-test.c
+++ b/tests/qtest/vhost-user-test.c
@@ -482,8 +482,8 @@ 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;
+    GError *err = NULL;
 
     server->context = g_main_context_new();
     server->loop = g_main_loop_new(server->context, FALSE);
@@ -491,9 +491,11 @@ 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", &err);
     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,
+                       err->message);
+        g_error_free(err);
     }
     g_assert(tmpfs);
 
-- 
2.31.1



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

* [PULL 36/37] tests/qtest: boot-serial-test: Close the serial file before starting QEMU
  2022-09-28  7:18 [PULL 00/37] qtests fixes Thomas Huth
                   ` (34 preceding siblings ...)
  2022-09-28  7:18 ` [PULL 35/37] tests/qtest: vhost-user-test: " Thomas Huth
@ 2022-09-28  7:18 ` Thomas Huth
  2022-09-28  7:18 ` [PULL 37/37] docs/devel: testing: Document writing portable test cases Thomas Huth
  2022-09-29 14:49 ` [PULL 00/37] qtests fixes Stefan Hajnoczi
  37 siblings, 0 replies; 39+ messages in thread
From: Thomas Huth @ 2022-09-28  7:18 UTC (permalink / raw)
  To: Stefan Hajnoczi, qemu-devel; +Cc: Bin Meng, Marc-André Lureau

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

This 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
on Windows. 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, unless FILE_SHARE_WRITE
is passed to the second call.

Two processes shouldn't share the same file for writing with a chardev.
Let's close the serial file before starting QEMU.

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

Signed-off-by: Bin Meng <bin.meng@windriver.com>
Message-Id: <20220927110632.1973965-40-bmeng.cn@gmail.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 tests/qtest/boot-serial-test.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/tests/qtest/boot-serial-test.c b/tests/qtest/boot-serial-test.c
index 72310ba30e..b216519b62 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,8 @@ static void test_machine(const void *data)
         unlink(codetmp);
     }
 
+    ser_fd = open(serialtmp, O_RDONLY);
+    g_assert(ser_fd != -1);
     if (!check_guest_output(qts, test, ser_fd)) {
         g_error("Failed to find expected string. Please check '%s'",
                 serialtmp);
-- 
2.31.1



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

* [PULL 37/37] docs/devel: testing: Document writing portable test cases
  2022-09-28  7:18 [PULL 00/37] qtests fixes Thomas Huth
                   ` (35 preceding siblings ...)
  2022-09-28  7:18 ` [PULL 36/37] tests/qtest: boot-serial-test: Close the serial file before starting QEMU Thomas Huth
@ 2022-09-28  7:18 ` Thomas Huth
  2022-09-29 14:49 ` [PULL 00/37] qtests fixes Stefan Hajnoczi
  37 siblings, 0 replies; 39+ messages in thread
From: Thomas Huth @ 2022-09-28  7:18 UTC (permalink / raw)
  To: Stefan Hajnoczi, qemu-devel; +Cc: Bin Meng, Marc-André Lureau

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>
Message-Id: <20220927110632.1973965-55-bmeng.cn@gmail.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 docs/devel/testing.rst | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/docs/devel/testing.rst b/docs/devel/testing.rst
index aea5b42356..fbb98faabe 100644
--- a/docs/devel/testing.rst
+++ b/docs/devel/testing.rst
@@ -81,6 +81,36 @@ QTest cases can be executed with
 
    make check-qtest
 
+Writing portable test cases
+~~~~~~~~~~~~~~~~~~~~~~~~~~~
+Both unit tests and qtests can run 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 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 delimiter ":" 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.
+
 QAPI schema tests
 ~~~~~~~~~~~~~~~~~
 
-- 
2.31.1



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

* Re: [PULL 00/37] qtests fixes
  2022-09-28  7:18 [PULL 00/37] qtests fixes Thomas Huth
                   ` (36 preceding siblings ...)
  2022-09-28  7:18 ` [PULL 37/37] docs/devel: testing: Document writing portable test cases Thomas Huth
@ 2022-09-29 14:49 ` Stefan Hajnoczi
  37 siblings, 0 replies; 39+ messages in thread
From: Stefan Hajnoczi @ 2022-09-29 14:49 UTC (permalink / raw)
  To: Thomas Huth; +Cc: Stefan Hajnoczi, qemu-devel

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

Applied, thanks.

Please update the changelog at https://wiki.qemu.org/ChangeLog/7.2 for any user-visible changes.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

end of thread, other threads:[~2022-09-29 17:54 UTC | newest]

Thread overview: 39+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-28  7:18 [PULL 00/37] qtests fixes Thomas Huth
2022-09-28  7:18 ` [PULL 01/37] tests/qtest: i440fx-test: Rewrite create_blob_file() to be portable Thomas Huth
2022-09-28  7:18 ` [PULL 02/37] tests/qtest: ahci-test: Avoid using hardcoded /tmp Thomas Huth
2022-09-28  7:18 ` [PULL 03/37] tests/qtest: aspeed_smc-test: " Thomas Huth
2022-09-28  7:18 ` [PULL 04/37] tests/qtest: boot-serial-test: " Thomas Huth
2022-09-28  7:18 ` [PULL 05/37] tests/qtest: cxl-test: " Thomas Huth
2022-09-28  7:18 ` [PULL 06/37] tests/qtest: fdc-test: " Thomas Huth
2022-09-28  7:18 ` [PULL 07/37] tests/qtest: generic_fuzz: " Thomas Huth
2022-09-28  7:18 ` [PULL 08/37] tests/qtest: virtio_blk_fuzz: " Thomas Huth
2022-09-28  7:18 ` [PULL 09/37] tests/qtest: ide-test: " Thomas Huth
2022-09-28  7:18 ` [PULL 10/37] tests/qtest: vhost-user-blk-test: " Thomas Huth
2022-09-28  7:18 ` [PULL 11/37] tests/qtest: virtio-blk-test: " Thomas Huth
2022-09-28  7:18 ` [PULL 12/37] tests/qtest: virtio-scsi-test: " Thomas Huth
2022-09-28  7:18 ` [PULL 13/37] tests/qtest: libqtest: " Thomas Huth
2022-09-28  7:18 ` [PULL 14/37] tests/unit: test-image-locking: " Thomas Huth
2022-09-28  7:18 ` [PULL 15/37] tests/unit: test-qga: " Thomas Huth
2022-09-28  7:18 ` [PULL 16/37] tests: vhost-user-bridge: " Thomas Huth
2022-09-28  7:18 ` [PULL 17/37] tests/qtest: Skip running virtio-net-test cases that require socketpair() for win32 Thomas Huth
2022-09-28  7:18 ` [PULL 18/37] tests/qtest: Build test-filter-{mirror, redirector} cases for posix only Thomas Huth
2022-09-28  7:18 ` [PULL 19/37] tests/qtest: qmp-test: Skip running test_qmp_oob for win32 Thomas Huth
2022-09-28  7:18 ` [PULL 20/37] tests/qtest: libqtest: Adapt global_qtest declaration " Thomas Huth
2022-09-28  7:18 ` [PULL 21/37] tests/qtest: libqtest: Exclude the *_fds APIs " Thomas Huth
2022-09-28  7:18 ` [PULL 22/37] tests/qtest: {ahci, ide}-test: Use relative path for temporary files " Thomas Huth
2022-09-28  7:18 ` [PULL 23/37] tests/qtest: bios-tables-test: Adapt the case " Thomas Huth
2022-09-28  7:18 ` [PULL 24/37] tests/qtest: migration-test: Disable IO redirection " Thomas Huth
2022-09-28  7:18 ` [PULL 25/37] tests/qtest: ide-test: Open file in binary mode Thomas Huth
2022-09-28  7:18 ` [PULL 26/37] tests/qtest: virtio-net-failover: Disable migration tests for win32 Thomas Huth
2022-09-28  7:18 ` [PULL 27/37] tests/qtest: microbit-test: Fix socket access " Thomas Huth
2022-09-28  7:18 ` [PULL 28/37] tests/qtest: libqtest: Replace the call to close a socket with closesocket() Thomas Huth
2022-09-28  7:18 ` [PULL 29/37] tests/qtest: migration-test: Skip running some TLS cases for win32 Thomas Huth
2022-09-28  7:18 ` [PULL 30/37] .gitlab-ci.d/windows.yml: Display meson test logs Thomas Huth
2022-09-28  7:18 ` [PULL 31/37] tests/x86: Move common code to function in device-plug-test Thomas Huth
2022-09-28  7:18 ` [PULL 32/37] tests/qtest: hd-geo-test: Avoid using hardcoded /tmp Thomas Huth
2022-09-28  7:18 ` [PULL 33/37] tests/qtest: pflash-cfi02-test: " Thomas Huth
2022-09-28  7:18 ` [PULL 34/37] tests/qtest: qmp-test: " Thomas Huth
2022-09-28  7:18 ` [PULL 35/37] tests/qtest: vhost-user-test: " Thomas Huth
2022-09-28  7:18 ` [PULL 36/37] tests/qtest: boot-serial-test: Close the serial file before starting QEMU Thomas Huth
2022-09-28  7:18 ` [PULL 37/37] docs/devel: testing: Document writing portable test cases Thomas Huth
2022-09-29 14:49 ` [PULL 00/37] qtests fixes Stefan Hajnoczi

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