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

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

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

Bin Meng (30):
  tests: Change to use g_mkdir()
  tests/qtest: i440fx-test: Rewrite create_blob_file() to be portable
  block: Unify the get_tmp_filename() implementation
  semihosting/arm-compat-semi: Avoid using hardcoded /tmp
  tcg: Avoid using hardcoded /tmp
  util/qemu-sockets: Use g_get_tmp_dir() to get the directory for
    temporary files
  tests: Avoid using hardcoded /tmp in test cases
  block/vvfat: Unify the mkdir() call
  fsdev/virtfs-proxy-helper: Use g_mkdir()
  hw/usb: dev-mtp: Use g_mkdir()
  tests/qtest: Skip running virtio-net-test cases that require
    socketpair() for win32
  tests/qtest: Build test-filter-{mirror,redirector} cases for posix
    only
  tests/qtest: qmp-test: Skip running test_qmp_oob for win32
  tests/qtest: libqtest: Exclude the *_fds APIs for win32
  tests/qtest: libqtest: Install signal handler via signal()
  tests/qtest: Support libqtest to build and run on Windows
  tests/qtest: {ahci,ide}-test: Use relative path for temporary files
    for win32
  tests/qtest: bios-tables-test: Adapt the case for win32
  tests/qtest: migration-test: Disable IO redirection for win32
  tests/qtest: microbit-test: Fix socket access for win32
  tests/qtest: libqtest: Replace the call to close a socket with
    closesocket()
  tests/qtest: libqtest: Correct the timeout unit of blocking receive
    calls for win32
  io/channel-watch: Drop a superfluous '#ifdef WIN32'
  io/channel-watch: Drop the unnecessary cast
  io/channel-watch: Fix socket watch on Windows
  tests/qtest: migration-test: Skip running some TLS cases for win32
  .gitlab-ci.d/windows.yml: Increase the timeout to 90 minutes
  .gitlab-ci.d/windows.yml: Display meson test logs
  tests/qtest: Enable qtest build on Windows
  docs/devel: testing: Document writing portable test cases

Xuzhou Cheng (9):
  accel/qtest: Implement a portable qtest accelerator
  tests/qtest: libqtest: Adapt global_qtest declaration for win32
  tests/qtest: Use send/recv for socket communication
  tests/qtest: ide-test: Open file in binary mode
  tests/qtest: virtio-net-failover: Disable migration tests for win32
  chardev/char-file: Add FILE_SHARE_WRITE when openning the file for
    win32
  tests/qtest: migration-test: Make sure QEMU process "to" exited after
    migration is canceled
  hw/ppc: spapr: Use qemu_vfree() to free spapr->htab
  hw/pci-host: pnv_phb{3,4}: Fix heap out-of-bound access failure

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

-- 
2.34.1



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

* [PATCH v2 01/39] tests: Change to use g_mkdir()
  2022-09-20 10:31 [PATCH v2 00/39] tests/qtest: Enable running qtest on Windows Bin Meng
@ 2022-09-20 10:31 ` Bin Meng
  2022-09-22 19:32   ` Marc-André Lureau
  2022-09-20 10:31 ` [PATCH v2 02/39] tests/qtest: i440fx-test: Rewrite create_blob_file() to be portable Bin Meng
                   ` (37 subsequent siblings)
  38 siblings, 1 reply; 87+ messages in thread
From: Bin Meng @ 2022-09-20 10:31 UTC (permalink / raw)
  To: qemu-devel
  Cc: Bin Meng, Daniel P. Berrangé,
	Dr. David Alan Gilbert, Juan Quintela, Laurent Vivier,
	Paolo Bonzini, Thomas Huth

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

Commit 413bebc04603 ("tests: Use g_mkdir_with_parents()") replaces
the mkdir() call in the test codes with glib's g_mkdir_with_parents(),
but the exact portable replacement for mkdir() should be g_mkdir().

I probably was misled by the GTK glib doc [1] before, thinking that
g_mkdir() is not a supported API from glib. But the glib sources do
not support this statement. It is probably that the GTK documentation
was not built to include all APIs.

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

Fixes: 413bebc04603 ("tests: Use g_mkdir_with_parents()")
Signed-off-by: Bin Meng <bin.meng@windriver.com>
---

Changes in v2:
- new patch: "tests: Change to use g_mkdir()"

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

diff --git a/tests/migration/stress.c b/tests/migration/stress.c
index 88acf8dc25..76b91851ad 100644
--- a/tests/migration/stress.c
+++ b/tests/migration/stress.c
@@ -19,6 +19,7 @@
 
 #include "qemu/osdep.h"
 #include <getopt.h>
+#include <glib/gstdio.h>
 #include <sys/reboot.h>
 #include <sys/syscall.h>
 #include <linux/random.h>
@@ -232,7 +233,7 @@ static void stress(unsigned long long ramsizeGB, int ncpus)
 
 static int mount_misc(const char *fstype, const char *dir)
 {
-    if (g_mkdir_with_parents(dir, 0755) < 0 && errno != EEXIST) {
+    if (g_mkdir(dir, 0755) < 0 && errno != EEXIST) {
         fprintf(stderr, "%s (%05d): ERROR: cannot create %s: %s\n",
                 argv0, gettid(), dir, strerror(errno));
         return -1;
diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index 4728d528bb..55892b3798 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -11,6 +11,7 @@
  */
 
 #include "qemu/osdep.h"
+#include <glib/gstdio.h>
 
 #include "libqtest.h"
 #include "qapi/error.h"
@@ -761,14 +762,14 @@ test_migrate_tls_psk_start_common(QTestState *from,
     data->workdir = g_strdup_printf("%s/tlscredspsk0", tmpfs);
     data->pskfile = g_strdup_printf("%s/%s", data->workdir,
                                     QCRYPTO_TLS_CREDS_PSKFILE);
-    g_mkdir_with_parents(data->workdir, 0700);
+    g_mkdir(data->workdir, 0700);
     test_tls_psk_init(data->pskfile);
 
     if (mismatch) {
         data->workdiralt = g_strdup_printf("%s/tlscredspskalt0", tmpfs);
         data->pskfilealt = g_strdup_printf("%s/%s", data->workdiralt,
                                            QCRYPTO_TLS_CREDS_PSKFILE);
-        g_mkdir_with_parents(data->workdiralt, 0700);
+        g_mkdir(data->workdiralt, 0700);
         test_tls_psk_init_alt(data->pskfilealt);
     }
 
@@ -873,7 +874,7 @@ test_migrate_tls_x509_start_common(QTestState *from,
         data->clientcert = g_strdup_printf("%s/client-cert.pem", data->workdir);
     }
 
-    g_mkdir_with_parents(data->workdir, 0700);
+    g_mkdir(data->workdir, 0700);
 
     test_tls_init(data->keyfile);
 #ifndef _WIN32
diff --git a/tests/unit/test-crypto-tlscredsx509.c b/tests/unit/test-crypto-tlscredsx509.c
index 3c25d75ca1..03fa48a3c5 100644
--- a/tests/unit/test-crypto-tlscredsx509.c
+++ b/tests/unit/test-crypto-tlscredsx509.c
@@ -19,6 +19,7 @@
  */
 
 #include "qemu/osdep.h"
+#include <glib/gstdio.h>
 
 #include "crypto-tls-x509-helpers.h"
 #include "crypto/tlscredsx509.h"
@@ -75,7 +76,7 @@ static void test_tls_creds(const void *opaque)
     QCryptoTLSCreds *creds;
 
 #define CERT_DIR "tests/test-crypto-tlscredsx509-certs/"
-    g_mkdir_with_parents(CERT_DIR, 0700);
+    g_mkdir(CERT_DIR, 0700);
 
     unlink(CERT_DIR QCRYPTO_TLS_CREDS_X509_CA_CERT);
     if (data->isServer) {
@@ -141,7 +142,7 @@ int main(int argc, char **argv)
     g_test_init(&argc, &argv, NULL);
     g_setenv("GNUTLS_FORCE_FIPS_MODE", "2", 1);
 
-    g_mkdir_with_parents(WORKDIR, 0700);
+    g_mkdir(WORKDIR, 0700);
 
     test_tls_init(KEYFILE);
 
diff --git a/tests/unit/test-crypto-tlssession.c b/tests/unit/test-crypto-tlssession.c
index 615a1344b4..356afbadfb 100644
--- a/tests/unit/test-crypto-tlssession.c
+++ b/tests/unit/test-crypto-tlssession.c
@@ -19,6 +19,7 @@
  */
 
 #include "qemu/osdep.h"
+#include <glib/gstdio.h>
 
 #include "crypto-tls-x509-helpers.h"
 #include "crypto-tls-psk-helpers.h"
@@ -249,8 +250,8 @@ static void test_crypto_tls_session_x509(const void *opaque)
 
 #define CLIENT_CERT_DIR "tests/test-crypto-tlssession-client/"
 #define SERVER_CERT_DIR "tests/test-crypto-tlssession-server/"
-    g_mkdir_with_parents(CLIENT_CERT_DIR, 0700);
-    g_mkdir_with_parents(SERVER_CERT_DIR, 0700);
+    g_mkdir(CLIENT_CERT_DIR, 0700);
+    g_mkdir(SERVER_CERT_DIR, 0700);
 
     unlink(SERVER_CERT_DIR QCRYPTO_TLS_CREDS_X509_CA_CERT);
     unlink(SERVER_CERT_DIR QCRYPTO_TLS_CREDS_X509_SERVER_CERT);
@@ -398,7 +399,7 @@ int main(int argc, char **argv)
     g_test_init(&argc, &argv, NULL);
     g_setenv("GNUTLS_FORCE_FIPS_MODE", "2", 1);
 
-    g_mkdir_with_parents(WORKDIR, 0700);
+    g_mkdir(WORKDIR, 0700);
 
     test_tls_init(KEYFILE);
     test_tls_psk_init(PSKFILE);
diff --git a/tests/unit/test-io-channel-tls.c b/tests/unit/test-io-channel-tls.c
index cc39247556..1d95c9f61d 100644
--- a/tests/unit/test-io-channel-tls.c
+++ b/tests/unit/test-io-channel-tls.c
@@ -22,6 +22,7 @@
 
 
 #include "qemu/osdep.h"
+#include <glib/gstdio.h>
 
 #include "crypto-tls-x509-helpers.h"
 #include "io/channel-tls.h"
@@ -125,8 +126,8 @@ static void test_io_channel_tls(const void *opaque)
 
 #define CLIENT_CERT_DIR "tests/test-io-channel-tls-client/"
 #define SERVER_CERT_DIR "tests/test-io-channel-tls-server/"
-    g_mkdir_with_parents(CLIENT_CERT_DIR, 0700);
-    g_mkdir_with_parents(SERVER_CERT_DIR, 0700);
+    g_mkdir(CLIENT_CERT_DIR, 0700);
+    g_mkdir(SERVER_CERT_DIR, 0700);
 
     unlink(SERVER_CERT_DIR QCRYPTO_TLS_CREDS_X509_CA_CERT);
     unlink(SERVER_CERT_DIR QCRYPTO_TLS_CREDS_X509_SERVER_CERT);
@@ -273,7 +274,7 @@ int main(int argc, char **argv)
     g_test_init(&argc, &argv, NULL);
     g_setenv("GNUTLS_FORCE_FIPS_MODE", "2", 1);
 
-    g_mkdir_with_parents(WORKDIR, 0700);
+    g_mkdir(WORKDIR, 0700);
 
     test_tls_init(KEYFILE);
 
-- 
2.34.1



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

* [PATCH v2 02/39] tests/qtest: i440fx-test: Rewrite create_blob_file() to be portable
  2022-09-20 10:31 [PATCH v2 00/39] tests/qtest: Enable running qtest on Windows Bin Meng
  2022-09-20 10:31 ` [PATCH v2 01/39] tests: Change to use g_mkdir() Bin Meng
@ 2022-09-20 10:31 ` Bin Meng
  2022-09-22 19:34   ` Marc-André Lureau
  2022-09-20 10:31 ` [PATCH v2 03/39] block: Unify the get_tmp_filename() implementation Bin Meng
                   ` (36 subsequent siblings)
  38 siblings, 1 reply; 87+ messages in thread
From: Bin Meng @ 2022-09-20 10:31 UTC (permalink / raw)
  To: qemu-devel
  Cc: Bin Meng, Marc-André Lureau, Laurent Vivier, Paolo Bonzini,
	Thomas Huth

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

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

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

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

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

diff --git a/tests/qtest/i440fx-test.c b/tests/qtest/i440fx-test.c
index 3890f1237c..202bc6022c 100644
--- a/tests/qtest/i440fx-test.c
+++ b/tests/qtest/i440fx-test.c
@@ -278,8 +278,6 @@ 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))
 
@@ -290,44 +288,25 @@ static void test_i440fx_pam(gconstpointer opaque)
  */
 static char *create_blob_file(void)
 {
-    int ret, fd;
+    int i, fd;
     char *pathname;
-    GError *error = NULL;
+    GError *error;
+    g_autofree uint8_t *buf = g_malloc(BLOB_SIZE);
 
-    ret = -1;
+    error = NULL;
     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;
+    error = NULL;
+    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 +377,6 @@ static void request_pflash(FirmwareTestFixture *fixture,
     fixture->is_bios = false;
 }
 
-#endif /* _WIN32 */
-
 int main(int argc, char **argv)
 {
     TestData data;
@@ -410,10 +387,8 @@ int main(int argc, char **argv)
 
     qtest_add_data_func("i440fx/defaults", &data, test_i440fx_defaults);
     qtest_add_data_func("i440fx/pam", &data, test_i440fx_pam);
-#ifndef _WIN32
     add_firmware_test("i440fx/firmware/bios", request_bios);
     add_firmware_test("i440fx/firmware/pflash", request_pflash);
-#endif
 
     return g_test_run();
 }
-- 
2.34.1



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

* [PATCH v2 03/39] block: Unify the get_tmp_filename() implementation
  2022-09-20 10:31 [PATCH v2 00/39] tests/qtest: Enable running qtest on Windows Bin Meng
  2022-09-20 10:31 ` [PATCH v2 01/39] tests: Change to use g_mkdir() Bin Meng
  2022-09-20 10:31 ` [PATCH v2 02/39] tests/qtest: i440fx-test: Rewrite create_blob_file() to be portable Bin Meng
@ 2022-09-20 10:31 ` Bin Meng
  2022-09-22 19:38   ` Marc-André Lureau
  2022-09-20 10:31 ` [PATCH v2 04/39] semihosting/arm-compat-semi: Avoid using hardcoded /tmp Bin Meng
                   ` (35 subsequent siblings)
  38 siblings, 1 reply; 87+ messages in thread
From: Bin Meng @ 2022-09-20 10:31 UTC (permalink / raw)
  To: qemu-devel; +Cc: Bin Meng, Hanna Reitz, Kevin Wolf, qemu-block

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

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

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

(no changes since v1)

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

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



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

* [PATCH v2 04/39] semihosting/arm-compat-semi: Avoid using hardcoded /tmp
  2022-09-20 10:31 [PATCH v2 00/39] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (2 preceding siblings ...)
  2022-09-20 10:31 ` [PATCH v2 03/39] block: Unify the get_tmp_filename() implementation Bin Meng
@ 2022-09-20 10:31 ` Bin Meng
  2022-09-23 16:20   ` Alex Bennée
  2022-09-20 10:31 ` [PATCH v2 05/39] tcg: " Bin Meng
                   ` (34 subsequent siblings)
  38 siblings, 1 reply; 87+ messages in thread
From: Bin Meng @ 2022-09-20 10:31 UTC (permalink / raw)
  To: qemu-devel; +Cc: Bin Meng, Alex Bennée

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

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

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

(no changes since v1)

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

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



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

* [PATCH v2 05/39] tcg: Avoid using hardcoded /tmp
  2022-09-20 10:31 [PATCH v2 00/39] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (3 preceding siblings ...)
  2022-09-20 10:31 ` [PATCH v2 04/39] semihosting/arm-compat-semi: Avoid using hardcoded /tmp Bin Meng
@ 2022-09-20 10:31 ` Bin Meng
  2022-09-23 16:20   ` Alex Bennée
  2022-09-20 10:31 ` [PATCH v2 06/39] util/qemu-sockets: Use g_get_tmp_dir() to get the directory for temporary files Bin Meng
                   ` (33 subsequent siblings)
  38 siblings, 1 reply; 87+ messages in thread
From: Bin Meng @ 2022-09-20 10:31 UTC (permalink / raw)
  To: qemu-devel; +Cc: Bin Meng, Marc-André Lureau, Richard Henderson

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

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

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

Changes in v2:
- Use g_autofree to declare the variable

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

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



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

* [PATCH v2 06/39] util/qemu-sockets: Use g_get_tmp_dir() to get the directory for temporary files
  2022-09-20 10:31 [PATCH v2 00/39] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (4 preceding siblings ...)
  2022-09-20 10:31 ` [PATCH v2 05/39] tcg: " Bin Meng
@ 2022-09-20 10:31 ` Bin Meng
  2022-09-20 10:31 ` [PATCH v2 07/39] tests: Avoid using hardcoded /tmp in test cases Bin Meng
                   ` (32 subsequent siblings)
  38 siblings, 0 replies; 87+ messages in thread
From: Bin Meng @ 2022-09-20 10:31 UTC (permalink / raw)
  To: qemu-devel; +Cc: Bin Meng, Marc-André Lureau, Daniel P. Berrangé

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

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

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

(no changes since v1)

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

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



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

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

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

Lots of test cases were written to use hardcoded /tmp directory for
temporary files. To avoid this, we update them to use g_dir_make_tmp()
or g_file_open_tmp() when appropriate.

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

Changes in v2:
- Use g_dir_make_tmp(), g_file_open_tmp() when appropriate

 tests/qtest/fuzz/generic_fuzz_configs.h |  4 ++--
 tests/qtest/ahci-test.c                 | 19 +++++++++++--------
 tests/qtest/aspeed_smc-test.c           |  5 ++---
 tests/qtest/boot-serial-test.c          |  9 +++++----
 tests/qtest/cxl-test.c                  | 15 ++++++---------
 tests/qtest/fdc-test.c                  |  5 +++--
 tests/qtest/fuzz/virtio_blk_fuzz.c      |  4 ++--
 tests/qtest/hd-geo-test.c               | 24 +++++++++++-------------
 tests/qtest/ide-test.c                  | 10 ++++++----
 tests/qtest/libqtest.c                  | 12 ++++++++----
 tests/qtest/migration-test.c            |  7 ++++---
 tests/qtest/pflash-cfi02-test.c         |  8 +++++---
 tests/qtest/qmp-test.c                  |  6 ++++--
 tests/qtest/vhost-user-blk-test.c       |  3 ++-
 tests/qtest/vhost-user-test.c           |  8 ++++----
 tests/qtest/virtio-blk-test.c           |  4 ++--
 tests/qtest/virtio-scsi-test.c          |  4 ++--
 tests/unit/test-image-locking.c         |  8 ++++----
 tests/unit/test-qga.c                   |  2 +-
 tests/vhost-user-bridge.c               |  3 +--
 20 files changed, 85 insertions(+), 75 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 "
diff --git a/tests/qtest/ahci-test.c b/tests/qtest/ahci-test.c
index f1e510b0ac..00524f14c6 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;
     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;
 }
diff --git a/tests/qtest/aspeed_smc-test.c b/tests/qtest/aspeed_smc-test.c
index 05ce941566..5e16b5c9a5 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;
     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);
diff --git a/tests/qtest/boot-serial-test.c b/tests/qtest/boot-serial-test.c
index 2f99d71cab..ce6e3d3eb8 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;
+    char *codetmp;
     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);
@@ -264,6 +264,7 @@ static void test_machine(const void *data)
                       serialtmp, test->extra);
     if (code) {
         unlink(codetmp);
+        g_free(codetmp);
     }
 
     if (!check_guest_output(qts, test, ser_fd)) {
diff --git a/tests/qtest/cxl-test.c b/tests/qtest/cxl-test.c
index 2e14da7dee..4f3ea76fa3 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;
 
-    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;
 
-    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;
 
-    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,
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;
 }
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);
diff --git a/tests/qtest/hd-geo-test.c b/tests/qtest/hd-geo-test.c
index 413cf964c0..4793954c19 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;
+    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]);
         }
     }
 
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;
 }
diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
index 7c9fc07de4..a0f28ddf8e 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;
+    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);
diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index 55892b3798..9925691ead 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -2435,7 +2435,6 @@ static bool kvm_dirty_ring_supported(void)
 
 int main(int argc, char **argv)
 {
-    char template[] = "/tmp/migration-test-XXXXXX";
     const bool has_kvm = qtest_has_accel("kvm");
     const bool has_uffd = ufd_version_check();
     const char *arch = qtest_get_arch();
@@ -2463,9 +2462,10 @@ int main(int argc, char **argv)
         return g_test_run();
     }
 
-    tmpfs = g_mkdtemp(template);
+    tmpfs = g_dir_make_tmp("migration-test-XXXXXX", NULL);
     if (!tmpfs) {
-        g_test_message("g_mkdtemp on path (%s): %s", template, strerror(errno));
+        g_test_message("g_dir_make_tmp on path (%s): %s", tmpfs,
+                       strerror(errno));
     }
     g_assert(tmpfs);
 
@@ -2590,6 +2590,7 @@ int main(int argc, char **argv)
         g_test_message("unable to rmdir: path (%s): %s",
                        tmpfs, strerror(errno));
     }
+    g_free((gpointer)tmpfs);
 
     return ret;
 }
diff --git a/tests/qtest/pflash-cfi02-test.c b/tests/qtest/pflash-cfi02-test.c
index 7fce614b64..55890b7d95 100644
--- a/tests/qtest/pflash-cfi02-test.c
+++ b/tests/qtest/pflash-cfi02-test.c
@@ -56,7 +56,7 @@ typedef struct {
     QTestState *qtest;
 } FlashConfig;
 
-static char image_path[] = "/tmp/qtest.XXXXXX";
+static char *image_path;
 
 /*
  * The pflash implementation allows some parameters to be unspecified. We want
@@ -608,6 +608,7 @@ static void test_cfi_in_autoselect(const void *opaque)
 static void cleanup(void *opaque)
 {
     unlink(image_path);
+    g_free(image_path);
 }
 
 /*
@@ -635,16 +636,17 @@ static const FlashConfig configuration[] = {
 
 int main(int argc, char **argv)
 {
-    int fd = mkstemp(image_path);
+    int fd = g_file_open_tmp("qtest.XXXXXX", &image_path, NULL);
     if (fd == -1) {
         g_printerr("Failed to create temporary file %s: %s\n", image_path,
                    strerror(errno));
+        g_free(image_path);
         exit(EXIT_FAILURE);
     }
     if (ftruncate(fd, UNIFORM_FLASH_SIZE) < 0) {
         int error_code = errno;
         close(fd);
-        unlink(image_path);
+        cleanup(NULL);
         g_printerr("Failed to truncate file %s to %u MB: %s\n", image_path,
                    UNIFORM_FLASH_SIZE, strerror(error_code));
         exit(EXIT_FAILURE);
diff --git a/tests/qtest/qmp-test.c b/tests/qtest/qmp-test.c
index bf7304c7dc..0fa00c12dc 100644
--- a/tests/qtest/qmp-test.c
+++ b/tests/qtest/qmp-test.c
@@ -161,12 +161,13 @@ static void test_qmp_protocol(void)
 
 /* Out-of-band tests */
 
-char tmpdir[] = "/tmp/qmp-test-XXXXXX";
+char *tmpdir;
 char *fifo_name;
 
 static void setup_blocking_cmd(void)
 {
-    if (!g_mkdtemp(tmpdir)) {
+    tmpdir = g_dir_make_tmp("qmp-test-XXXXXX", NULL);
+    if (!tmpdir) {
         g_error("g_mkdtemp: %s", strerror(errno));
     }
     fifo_name = g_strdup_printf("%s/fifo", tmpdir);
@@ -179,6 +180,7 @@ static void cleanup_blocking_cmd(void)
 {
     unlink(fifo_name);
     rmdir(tmpdir);
+    g_free(tmpdir);
 }
 
 static void send_cmd_that_blocks(QTestState *s, const char *id)
diff --git a/tests/qtest/vhost-user-blk-test.c b/tests/qtest/vhost-user-blk-test.c
index a81c2a2715..07a4c2d500 100644
--- a/tests/qtest/vhost-user-blk-test.c
+++ b/tests/qtest/vhost-user-blk-test.c
@@ -841,7 +841,8 @@ static char *create_listen_socket(int *fd)
     char *path;
 
     /* No race because our pid makes the path unique */
-    path = g_strdup_printf("/tmp/qtest-%d-sock.XXXXXX", getpid());
+    path = g_strdup_printf("%s/qtest-%d-sock.XXXXXX",
+                           g_get_tmp_dir(), getpid());
     tmp_fd = mkstemp(path);
     g_assert_cmpint(tmp_fd, >=, 0);
     close(tmp_fd);
diff --git a/tests/qtest/vhost-user-test.c b/tests/qtest/vhost-user-test.c
index d7d6cfc9bd..4e1aae1794 100644
--- a/tests/qtest/vhost-user-test.c
+++ b/tests/qtest/vhost-user-test.c
@@ -482,8 +482,7 @@ static TestServer *test_server_new(const gchar *name,
         struct vhost_user_ops *ops)
 {
     TestServer *server = g_new0(TestServer, 1);
-    char template[] = "/tmp/vhost-test-XXXXXX";
-    const char *tmpfs;
+    g_autofree const char *tmpfs;
 
     server->context = g_main_context_new();
     server->loop = g_main_loop_new(server->context, FALSE);
@@ -491,9 +490,10 @@ static TestServer *test_server_new(const gchar *name,
     /* run the main loop thread so the chardev may operate */
     server->thread = g_thread_new(NULL, thread_function, server->loop);
 
-    tmpfs = g_mkdtemp(template);
+    tmpfs = g_dir_make_tmp("vhost-test-XXXXXX", NULL);
     if (!tmpfs) {
-        g_test_message("g_mkdtemp on path (%s): %s", template, strerror(errno));
+        g_test_message("g_dir_make_tmp on path (%s): %s", tmpfs,
+                       strerror(errno));
     }
     g_assert(tmpfs);
 
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);
diff --git a/tests/qtest/virtio-scsi-test.c b/tests/qtest/virtio-scsi-test.c
index 8ceb12aacd..073a89d535 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;
     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);
 
diff --git a/tests/unit/test-image-locking.c b/tests/unit/test-image-locking.c
index ba057bd66c..d09ff43fcb 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;
     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;
     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;
diff --git a/tests/unit/test-qga.c b/tests/unit/test-qga.c
index a05a4628ed..b73d231cd5 100644
--- a/tests/unit/test-qga.c
+++ b/tests/unit/test-qga.c
@@ -59,7 +59,7 @@ fixture_setup(TestFixture *fixture, gconstpointer data, gchar **envp)
 
     fixture->loop = g_main_loop_new(NULL, FALSE);
 
-    fixture->test_dir = g_strdup("/tmp/qgatest.XXXXXX");
+    fixture->test_dir = g_strdup_printf("%s/qgatest.XXXXXX", g_get_tmp_dir());
     g_assert_nonnull(g_mkdtemp(fixture->test_dir));
 
     path = g_build_filename(fixture->test_dir, "sock", NULL);
diff --git a/tests/vhost-user-bridge.c b/tests/vhost-user-bridge.c
index 9b1dab2f28..fecdf915e7 100644
--- a/tests/vhost-user-bridge.c
+++ b/tests/vhost-user-bridge.c
@@ -631,7 +631,6 @@ static void *notifier_thread(void *arg)
 static void
 vubr_host_notifier_setup(VubrDev *dev)
 {
-    char template[] = "/tmp/vubr-XXXXXX";
     pthread_t thread;
     size_t length;
     void *addr;
@@ -639,7 +638,7 @@ vubr_host_notifier_setup(VubrDev *dev)
 
     length = qemu_real_host_page_size() * VHOST_USER_BRIDGE_MAX_QUEUES;
 
-    fd = mkstemp(template);
+    fd = g_file_open_tmp("vubr-XXXXXX", NULL, NULL);
     if (fd < 0) {
         vubr_die("mkstemp()");
     }
-- 
2.34.1



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

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

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

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

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

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

Changes in v2:
- Change to use g_mkdir()

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

diff --git a/block/vvfat.c b/block/vvfat.c
index d6dd919683..723beef025 100644
--- a/block/vvfat.c
+++ b/block/vvfat.c
@@ -25,6 +25,7 @@
 
 #include "qemu/osdep.h"
 #include <dirent.h>
+#include <glib/gstdio.h>
 #include "qapi/error.h"
 #include "block/block_int.h"
 #include "block/qdict.h"
@@ -2726,13 +2727,9 @@ static int handle_renames_and_mkdirs(BDRVVVFATState* s)
             mapping_t* mapping;
             int j, parent_path_len;
 
-#ifdef __MINGW32__
-            if (mkdir(commit->path))
+            if (g_mkdir(commit->path, 0755)) {
                 return -5;
-#else
-            if (mkdir(commit->path, 0755))
-                return -5;
-#endif
+            }
 
             mapping = insert_mapping(s, commit->param.mkdir.cluster,
                     commit->param.mkdir.cluster + 1);
-- 
2.34.1



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

* [PATCH v2 09/39] fsdev/virtfs-proxy-helper: Use g_mkdir()
  2022-09-20 10:31 [PATCH v2 00/39] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (7 preceding siblings ...)
  2022-09-20 10:31 ` [PATCH v2 08/39] block/vvfat: Unify the mkdir() call Bin Meng
@ 2022-09-20 10:31 ` Bin Meng
  2022-09-20 13:42   ` Christian Schoenebeck
  2022-09-20 10:31 ` [PATCH v2 10/39] hw/usb: dev-mtp: " Bin Meng
                   ` (29 subsequent siblings)
  38 siblings, 1 reply; 87+ messages in thread
From: Bin Meng @ 2022-09-20 10:31 UTC (permalink / raw)
  To: qemu-devel; +Cc: Bin Meng, Christian Schoenebeck, Greg Kurz

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

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

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

Changes in v2:
- Change to use g_mkdir()

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

diff --git a/fsdev/virtfs-proxy-helper.c b/fsdev/virtfs-proxy-helper.c
index 2dde27922f..5cafcd7703 100644
--- a/fsdev/virtfs-proxy-helper.c
+++ b/fsdev/virtfs-proxy-helper.c
@@ -10,6 +10,7 @@
  */
 
 #include "qemu/osdep.h"
+#include <glib/gstdio.h>
 #include <sys/resource.h>
 #include <getopt.h>
 #include <syslog.h>
@@ -639,7 +640,7 @@ static int do_create_others(int type, struct iovec *iovec)
         if (retval < 0) {
             goto err_out;
         }
-        retval = mkdir(path.data, mode);
+        retval = g_mkdir(path.data, mode);
         break;
     case T_SYMLINK:
         retval = proxy_unmarshal(iovec, offset, "ss", &oldpath, &path);
-- 
2.34.1



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

* [PATCH v2 10/39] hw/usb: dev-mtp: Use g_mkdir()
  2022-09-20 10:31 [PATCH v2 00/39] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (8 preceding siblings ...)
  2022-09-20 10:31 ` [PATCH v2 09/39] fsdev/virtfs-proxy-helper: Use g_mkdir() Bin Meng
@ 2022-09-20 10:31 ` Bin Meng
  2022-09-20 11:20   ` Gerd Hoffmann
  2022-09-20 10:31 ` [PATCH v2 11/39] tests/qtest: Skip running virtio-net-test cases that require socketpair() for win32 Bin Meng
                   ` (28 subsequent siblings)
  38 siblings, 1 reply; 87+ messages in thread
From: Bin Meng @ 2022-09-20 10:31 UTC (permalink / raw)
  To: qemu-devel; +Cc: Bin Meng, Gerd Hoffmann

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

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

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

Changes in v2:
- Change to use g_mkdir()

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

diff --git a/hw/usb/dev-mtp.c b/hw/usb/dev-mtp.c
index 5831395cef..1cac1cd435 100644
--- a/hw/usb/dev-mtp.c
+++ b/hw/usb/dev-mtp.c
@@ -14,7 +14,7 @@
 #include "qemu/error-report.h"
 #include <wchar.h>
 #include <dirent.h>
-
+#include <glib/gstdio.h>
 #include <sys/statvfs.h>
 
 
@@ -1622,7 +1622,7 @@ static void usb_mtp_write_data(MTPState *s, uint32_t handle)
         if (s->dataset.filename) {
             path = g_strdup_printf("%s/%s", parent->path, s->dataset.filename);
             if (s->dataset.format == FMT_ASSOCIATION) {
-                ret = mkdir(path, mask);
+                ret = g_mkdir(path, mask);
                 if (!ret) {
                     usb_mtp_queue_result(s, RES_OK, d->trans, 3,
                                          QEMU_STORAGE_ID,
-- 
2.34.1



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

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

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

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

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

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

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

diff --git a/tests/qtest/virtio-net-test.c b/tests/qtest/virtio-net-test.c
index 6ded252901..dff43f0f60 100644
--- a/tests/qtest/virtio-net-test.c
+++ b/tests/qtest/virtio-net-test.c
@@ -165,8 +165,6 @@ static void stop_cont_test(void *obj, void *data, QGuestAllocator *t_alloc)
     rx_stop_cont_test(dev, t_alloc, rx, sv[0]);
 }
 
-#endif
-
 static void hotplug(void *obj, void *data, QGuestAllocator *t_alloc)
 {
     QVirtioPCIDevice *dev = obj;
@@ -286,6 +284,8 @@ static void *virtio_net_test_setup(GString *cmd_line, void *arg)
     return sv;
 }
 
+#endif /* _WIN32 */
+
 static void large_tx(void *obj, void *data, QGuestAllocator *t_alloc)
 {
     QVirtioNet *dev = obj;
@@ -319,16 +319,15 @@ static void *virtio_net_test_setup_nosocket(GString *cmd_line, void *arg)
 
 static void register_virtio_net_test(void)
 {
-    QOSGraphTestOptions opts = {
-        .before = virtio_net_test_setup,
-    };
+    QOSGraphTestOptions opts = { 0 };
 
-    qos_add_test("hotplug", "virtio-net-pci", hotplug, &opts);
 #ifndef _WIN32
+    opts.before = virtio_net_test_setup;
+    qos_add_test("hotplug", "virtio-net-pci", hotplug, &opts);
     qos_add_test("basic", "virtio-net", send_recv_test, &opts);
     qos_add_test("rx_stop_cont", "virtio-net", stop_cont_test, &opts);
-#endif
     qos_add_test("announce-self", "virtio-net", announce_self, &opts);
+#endif
 
     /* These tests do not need a loopback backend.  */
     opts.before = virtio_net_test_setup_nosocket;
-- 
2.34.1



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

* [PATCH v2 12/39] tests/qtest: Build test-filter-{mirror, redirector} cases for posix only
  2022-09-20 10:31 [PATCH v2 00/39] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (10 preceding siblings ...)
  2022-09-20 10:31 ` [PATCH v2 11/39] tests/qtest: Skip running virtio-net-test cases that require socketpair() for win32 Bin Meng
@ 2022-09-20 10:31 ` Bin Meng
  2022-09-20 10:31 ` [PATCH v2 13/39] tests/qtest: qmp-test: Skip running test_qmp_oob for win32 Bin Meng
                   ` (26 subsequent siblings)
  38 siblings, 0 replies; 87+ messages in thread
From: Bin Meng @ 2022-09-20 10:31 UTC (permalink / raw)
  To: qemu-devel
  Cc: Bin Meng, Marc-André Lureau, Laurent Vivier, Paolo Bonzini,
	Thomas Huth

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

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

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

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

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

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



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

* [PATCH v2 13/39] tests/qtest: qmp-test: Skip running test_qmp_oob for win32
  2022-09-20 10:31 [PATCH v2 00/39] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (11 preceding siblings ...)
  2022-09-20 10:31 ` [PATCH v2 12/39] tests/qtest: Build test-filter-{mirror, redirector} cases for posix only Bin Meng
@ 2022-09-20 10:31 ` Bin Meng
  2022-09-20 10:31 ` [PATCH v2 14/39] accel/qtest: Implement a portable qtest accelerator Bin Meng
                   ` (25 subsequent siblings)
  38 siblings, 0 replies; 87+ messages in thread
From: Bin Meng @ 2022-09-20 10:31 UTC (permalink / raw)
  To: qemu-devel
  Cc: Bin Meng, Thomas Huth, Laurent Vivier, Markus Armbruster, Paolo Bonzini

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

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

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

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

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

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



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

* [PATCH v2 14/39] accel/qtest: Implement a portable qtest accelerator
  2022-09-20 10:31 [PATCH v2 00/39] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (12 preceding siblings ...)
  2022-09-20 10:31 ` [PATCH v2 13/39] tests/qtest: qmp-test: Skip running test_qmp_oob for win32 Bin Meng
@ 2022-09-20 10:31 ` Bin Meng
  2022-09-20 10:31 ` [PATCH v2 15/39] tests/qtest: libqtest: Adapt global_qtest declaration for win32 Bin Meng
                   ` (24 subsequent siblings)
  38 siblings, 0 replies; 87+ messages in thread
From: Bin Meng @ 2022-09-20 10:31 UTC (permalink / raw)
  To: qemu-devel
  Cc: Xuzhou Cheng, Bin Meng, Marc-André Lureau, Eduardo Habkost,
	Laurent Vivier, Marcel Apfelbaum, Paolo Bonzini,
	Philippe Mathieu-Daudé,
	Richard Henderson, Thomas Huth, Yanan Wang

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

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

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

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

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

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

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



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

* [PATCH v2 15/39] tests/qtest: libqtest: Adapt global_qtest declaration for win32
  2022-09-20 10:31 [PATCH v2 00/39] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (13 preceding siblings ...)
  2022-09-20 10:31 ` [PATCH v2 14/39] accel/qtest: Implement a portable qtest accelerator Bin Meng
@ 2022-09-20 10:31 ` Bin Meng
  2022-09-20 10:31 ` [PATCH v2 16/39] tests/qtest: Use send/recv for socket communication Bin Meng
                   ` (23 subsequent siblings)
  38 siblings, 0 replies; 87+ messages in thread
From: Bin Meng @ 2022-09-20 10:31 UTC (permalink / raw)
  To: qemu-devel
  Cc: Xuzhou Cheng, Bin Meng, Laurent Vivier, Paolo Bonzini, Thomas Huth

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

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

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

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

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

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

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



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

* [PATCH v2 16/39] tests/qtest: Use send/recv for socket communication
  2022-09-20 10:31 [PATCH v2 00/39] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (14 preceding siblings ...)
  2022-09-20 10:31 ` [PATCH v2 15/39] tests/qtest: libqtest: Adapt global_qtest declaration for win32 Bin Meng
@ 2022-09-20 10:31 ` Bin Meng
  2022-09-22 19:52   ` Marc-André Lureau
  2022-09-20 10:31 ` [PATCH v2 17/39] tests/qtest: libqtest: Exclude the *_fds APIs for win32 Bin Meng
                   ` (22 subsequent siblings)
  38 siblings, 1 reply; 87+ messages in thread
From: Bin Meng @ 2022-09-20 10:31 UTC (permalink / raw)
  To: qemu-devel
  Cc: Xuzhou Cheng, Bin Meng, Daniel P. Berrangé,
	Laurent Vivier, Paolo Bonzini, Thomas Huth

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

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

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

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

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

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

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



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

* [PATCH v2 17/39] tests/qtest: libqtest: Exclude the *_fds APIs for win32
  2022-09-20 10:31 [PATCH v2 00/39] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (15 preceding siblings ...)
  2022-09-20 10:31 ` [PATCH v2 16/39] tests/qtest: Use send/recv for socket communication Bin Meng
@ 2022-09-20 10:31 ` Bin Meng
  2022-09-20 10:31 ` [PATCH v2 18/39] tests/qtest: libqtest: Install signal handler via signal() Bin Meng
                   ` (21 subsequent siblings)
  38 siblings, 0 replies; 87+ messages in thread
From: Bin Meng @ 2022-09-20 10:31 UTC (permalink / raw)
  To: qemu-devel
  Cc: Bin Meng, Marc-André Lureau, Laurent Vivier, Paolo Bonzini,
	Thomas Huth

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

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

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

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

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

(no changes since v1)

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

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



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

* [PATCH v2 18/39] tests/qtest: libqtest: Install signal handler via signal()
  2022-09-20 10:31 [PATCH v2 00/39] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (16 preceding siblings ...)
  2022-09-20 10:31 ` [PATCH v2 17/39] tests/qtest: libqtest: Exclude the *_fds APIs for win32 Bin Meng
@ 2022-09-20 10:31 ` Bin Meng
  2022-09-22 19:55   ` Marc-André Lureau
  2022-09-20 10:31 ` [PATCH v2 19/39] tests/qtest: Support libqtest to build and run on Windows Bin Meng
                   ` (20 subsequent siblings)
  38 siblings, 1 reply; 87+ messages in thread
From: Bin Meng @ 2022-09-20 10:31 UTC (permalink / raw)
  To: qemu-devel; +Cc: Bin Meng, Laurent Vivier, Paolo Bonzini, Thomas Huth

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

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

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

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

(no changes since v1)

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

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



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

* [PATCH v2 19/39] tests/qtest: Support libqtest to build and run on Windows
  2022-09-20 10:31 [PATCH v2 00/39] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (17 preceding siblings ...)
  2022-09-20 10:31 ` [PATCH v2 18/39] tests/qtest: libqtest: Install signal handler via signal() Bin Meng
@ 2022-09-20 10:31 ` Bin Meng
  2022-09-22 19:59   ` Marc-André Lureau
  2022-09-20 10:31 ` [PATCH v2 20/39] tests/qtest: {ahci, ide}-test: Use relative path for temporary files for win32 Bin Meng
                   ` (19 subsequent siblings)
  38 siblings, 1 reply; 87+ messages in thread
From: Bin Meng @ 2022-09-20 10:31 UTC (permalink / raw)
  To: qemu-devel
  Cc: Bin Meng, Xuzhou Cheng, Laurent Vivier, Paolo Bonzini, Thomas Huth

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

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

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

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

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

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

diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
index f46a21fa45..5d15e39289 100644
--- a/tests/qtest/libqtest.c
+++ b/tests/qtest/libqtest.c
@@ -16,9 +16,11 @@
 
 #include "qemu/osdep.h"
 
+#ifndef _WIN32
 #include <sys/socket.h>
 #include <sys/wait.h>
 #include <sys/un.h>
+#endif /* _WIN32 */
 #ifdef __linux__
 #include <sys/prctl.h>
 #endif /* __linux__ */
@@ -27,6 +29,7 @@
 #include "libqmp.h"
 #include "qemu/ctype.h"
 #include "qemu/cutils.h"
+#include "qemu/sockets.h"
 #include "qapi/qmp/qdict.h"
 #include "qapi/qmp/qjson.h"
 #include "qapi/qmp/qlist.h"
@@ -35,6 +38,16 @@
 #define MAX_IRQ 256
 #define SOCKET_TIMEOUT 50
 
+#ifndef _WIN32
+# define CMD_EXEC   "exec "
+# define DEV_STDERR "/dev/fd/2"
+# define DEV_NULL   "/dev/null"
+#else
+# define CMD_EXEC   ""
+# define DEV_STDERR "2"
+# define DEV_NULL   "nul"
+#endif
+
 typedef void (*QTestSendFn)(QTestState *s, const char *buf);
 typedef void (*ExternalSendFn)(void *s, const char *buf);
 typedef GString* (*QTestRecvFn)(QTestState *);
@@ -66,6 +79,9 @@ struct QTestState
 };
 
 static GHookList abrt_hooks;
+#ifdef _WIN32
+typedef void (*sighandler_t)(int);
+#endif
 static sighandler_t sighandler_old;
 
 static int qtest_query_target_endianness(QTestState *s);
@@ -118,10 +134,19 @@ bool qtest_probe_child(QTestState *s)
     pid_t pid = s->qemu_pid;
 
     if (pid != -1) {
+#ifndef _WIN32
         pid = waitpid(pid, &s->wstatus, WNOHANG);
         if (pid == 0) {
             return true;
         }
+#else
+        DWORD exit_code;
+        GetExitCodeProcess((HANDLE)pid, &exit_code);
+        if (exit_code == STILL_ACTIVE) {
+            return true;
+        }
+        CloseHandle((HANDLE)pid);
+#endif
         s->qemu_pid = -1;
     }
     return false;
@@ -135,13 +160,23 @@ void qtest_set_expected_status(QTestState *s, int status)
 void qtest_kill_qemu(QTestState *s)
 {
     pid_t pid = s->qemu_pid;
+#ifndef _WIN32
     int wstatus;
+#else
+    DWORD ret, exit_code;
+#endif
 
     /* Skip wait if qtest_probe_child already reaped.  */
     if (pid != -1) {
+#ifndef _WIN32
         kill(pid, SIGTERM);
         TFR(pid = waitpid(s->qemu_pid, &s->wstatus, 0));
         assert(pid == s->qemu_pid);
+#else
+        TerminateProcess((HANDLE)pid, s->expected_status);
+        ret = WaitForSingleObject((HANDLE)pid, INFINITE);
+        assert(ret == WAIT_OBJECT_0);
+#endif
         s->qemu_pid = -1;
     }
 
@@ -149,6 +184,7 @@ void qtest_kill_qemu(QTestState *s)
      * Check whether qemu exited with expected exit status; anything else is
      * fishy and should be logged with as much detail as possible.
      */
+#ifndef _WIN32
     wstatus = s->wstatus;
     if (WIFEXITED(wstatus) && WEXITSTATUS(wstatus) != s->expected_status) {
         fprintf(stderr, "%s:%d: kill_qemu() tried to terminate QEMU "
@@ -165,6 +201,16 @@ void qtest_kill_qemu(QTestState *s)
                 __FILE__, __LINE__, sig, signame, dump);
         abort();
     }
+#else
+    GetExitCodeProcess((HANDLE)pid, &exit_code);
+    CloseHandle((HANDLE)pid);
+    if (exit_code != s->expected_status) {
+        fprintf(stderr, "%s:%d: kill_qemu() tried to terminate QEMU "
+                "process but encountered exit status %ld (expected %d)\n",
+                __FILE__, __LINE__, exit_code, s->expected_status);
+        abort();
+    }
+#endif
 }
 
 static void kill_qemu_hook_func(void *s)
@@ -243,6 +289,38 @@ static const char *qtest_qemu_binary(void)
     return qemu_bin;
 }
 
+#ifdef _WIN32
+static pid_t qtest_create_process(char *cmd)
+{
+    STARTUPINFO si;
+    PROCESS_INFORMATION pi;
+    BOOL ret;
+
+    ZeroMemory(&si, sizeof(si));
+    si.cb = sizeof(si);
+    ZeroMemory(&pi, sizeof(pi));
+
+    ret = CreateProcess(NULL,   /* module name */
+                        cmd,    /* command line */
+                        NULL,   /* process handle not inheritable */
+                        NULL,   /* thread handle not inheritable */
+                        FALSE,  /* set handle inheritance to FALSE */
+                        0,      /* No creation flags */
+                        NULL,   /* use parent's environment block */
+                        NULL,   /* use parent's starting directory */
+                        &si,    /* pointer to STARTUPINFO structure */
+                        &pi     /* pointer to PROCESS_INFORMATION structure */
+                        );
+    if (ret == 0) {
+        fprintf(stderr, "%s:%d: unable to create a new process (%s)\n",
+                __FILE__, __LINE__, strerror(GetLastError()));
+        abort();
+    }
+
+    return (pid_t)pi.hProcess;
+}
+#endif /* _WIN32 */
+
 QTestState *qtest_init_without_qmp_handshake(const char *extra_args)
 {
     QTestState *s;
@@ -270,6 +348,7 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args)
     unlink(socket_path);
     unlink(qmp_socket_path);
 
+    socket_init();
     sock = init_socket(socket_path);
     qmpsock = init_socket(qmp_socket_path);
 
@@ -278,7 +357,7 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args)
 
     qtest_add_abrt_handler(kill_qemu_hook_func, s);
 
-    command = g_strdup_printf("exec %s %s"
+    command = g_strdup_printf(CMD_EXEC "%s %s"
                               "-qtest unix:%s "
                               "-qtest-log %s "
                               "-chardev socket,path=%s,id=char0 "
@@ -287,7 +366,7 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args)
                               "%s"
                               " -accel qtest",
                               qemu_binary, tracearg, socket_path,
-                              getenv("QTEST_LOG") ? "/dev/fd/2" : "/dev/null",
+                              getenv("QTEST_LOG") ? DEV_STDERR : DEV_NULL,
                               qmp_socket_path,
                               extra_args ?: "");
 
@@ -296,6 +375,7 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args)
     s->pending_events = NULL;
     s->wstatus = 0;
     s->expected_status = 0;
+#ifndef _WIN32
     s->qemu_pid = fork();
     if (s->qemu_pid == 0) {
 #ifdef __linux__
@@ -318,6 +398,9 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args)
         execlp("/bin/sh", "sh", "-c", command, NULL);
         exit(1);
     }
+#else
+    s->qemu_pid = qtest_create_process(command);
+#endif /* _WIN32 */
 
     g_free(command);
     s->fd = socket_accept(sock);
@@ -336,9 +419,19 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args)
         s->irq_level[i] = false;
     }
 
+    /*
+     * Stopping QEMU for debugging is not supported on Windows.
+     *
+     * Using DebugActiveProcess() API can suspend the QEMU process,
+     * but gdb cannot attach to the process. Using the undocumented
+     * NtSuspendProcess() can suspend the QEMU process and gdb can
+     * attach to the process, but gdb cannot resume it.
+     */
+#ifndef _WIN32
     if (getenv("QTEST_STOP")) {
         kill(s->qemu_pid, SIGSTOP);
     }
+#endif
 
     /* ask endianness of the target */
 
@@ -392,6 +485,7 @@ QTestState *qtest_init_with_serial(const char *extra_args, int *sock_fd)
     g_assert_true(sock_dir != NULL);
     sock_path = g_strdup_printf("%s/sock", sock_dir);
 
+    socket_init();
     sock_fd_init = init_socket(sock_path);
 
     qts = qtest_initf("-chardev socket,id=s0,path=%s -serial chardev:s0 %s",
-- 
2.34.1



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

* [PATCH v2 20/39] tests/qtest: {ahci, ide}-test: Use relative path for temporary files for win32
  2022-09-20 10:31 [PATCH v2 00/39] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (18 preceding siblings ...)
  2022-09-20 10:31 ` [PATCH v2 19/39] tests/qtest: Support libqtest to build and run on Windows Bin Meng
@ 2022-09-20 10:31 ` Bin Meng
  2022-09-22 20:02   ` Marc-André Lureau
  2022-09-20 10:31 ` [PATCH v2 21/39] tests/qtest: bios-tables-test: Adapt the case " Bin Meng
                   ` (18 subsequent siblings)
  38 siblings, 1 reply; 87+ messages in thread
From: Bin Meng @ 2022-09-20 10:31 UTC (permalink / raw)
  To: qemu-devel
  Cc: Bin Meng, John Snow, Laurent Vivier, Paolo Bonzini, Thomas Huth,
	qemu-block

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

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

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

(no changes since v1)

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

diff --git a/tests/qtest/ahci-test.c b/tests/qtest/ahci-test.c
index 00524f14c6..c57576b08c 100644
--- a/tests/qtest/ahci-test.c
+++ b/tests/qtest/ahci-test.c
@@ -1833,7 +1833,7 @@ static void create_ahci_io_test(enum IOMode type, enum AddrMode addr,
 
 int main(int argc, char **argv)
 {
-    const char *arch;
+    const char *arch, *base;
     int ret;
     int fd;
     int c;
@@ -1871,8 +1871,22 @@ int main(int argc, char **argv)
         return 0;
     }
 
+    /*
+     * "base" stores the starting point where we create temporary files.
+     *
+     * On Windows, this is set to the relative path of current working
+     * directory, because the absolute path causes the blkdebug filename
+     * parser fail to parse "blkdebug:path/to/config:path/to/image".
+     */
+#ifndef _WIN32
+    base = g_get_tmp_dir();
+#else
+    base = ".";
+#endif
+
     /* Create a temporary image */
-    fd = g_file_open_tmp("qtest.XXXXXX", &tmp_path, NULL);
+    tmp_path = g_strdup_printf("%s/qtest.XXXXXX", base);
+    fd = g_mkstemp(tmp_path);
     g_assert(fd >= 0);
     if (have_qemu_img()) {
         imgfmt = "qcow2";
@@ -1889,7 +1903,8 @@ int main(int argc, char **argv)
     close(fd);
 
     /* Create temporary blkdebug instructions */
-    fd = g_file_open_tmp("qtest-blkdebug.XXXXXX", &debug_path, NULL);
+    debug_path = g_strdup_printf("%s/qtest-blkdebug.XXXXXX", base);
+    fd = g_mkstemp(debug_path);
     g_assert(fd >= 0);
     close(fd);
 
diff --git a/tests/qtest/ide-test.c b/tests/qtest/ide-test.c
index 25302be6dc..5e3e28aea2 100644
--- a/tests/qtest/ide-test.c
+++ b/tests/qtest/ide-test.c
@@ -1011,16 +1011,32 @@ static void test_cdrom_dma(void)
 
 int main(int argc, char **argv)
 {
+    const char *base;
     int fd;
     int ret;
 
+    /*
+     * "base" stores the starting point where we create temporary files.
+     *
+     * On Windows, this is set to the relative path of current working
+     * directory, because the absolute path causes the blkdebug filename
+     * parser fail to parse "blkdebug:path/to/config:path/to/image".
+     */
+#ifndef _WIN32
+    base = g_get_tmp_dir();
+#else
+    base = ".";
+#endif
+
     /* Create temporary blkdebug instructions */
-    fd = g_file_open_tmp("qtest-blkdebug.XXXXXX", &debug_path, NULL);
+    debug_path = g_strdup_printf("%s/qtest-blkdebug.XXXXXX", base);
+    fd = g_mkstemp(debug_path);
     g_assert(fd >= 0);
     close(fd);
 
     /* Create a temporary raw image */
-    fd = g_file_open_tmp("qtest.XXXXXX", &tmp_path, NULL);
+    tmp_path = g_strdup_printf("%s/qtest.XXXXXX", base);
+    fd = g_mkstemp(tmp_path);
     g_assert(fd >= 0);
     ret = ftruncate(fd, TEST_IMAGE_SIZE);
     g_assert(ret == 0);
-- 
2.34.1



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

* [PATCH v2 21/39] tests/qtest: bios-tables-test: Adapt the case for win32
  2022-09-20 10:31 [PATCH v2 00/39] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (19 preceding siblings ...)
  2022-09-20 10:31 ` [PATCH v2 20/39] tests/qtest: {ahci, ide}-test: Use relative path for temporary files for win32 Bin Meng
@ 2022-09-20 10:31 ` Bin Meng
  2022-09-20 10:31 ` [PATCH v2 22/39] tests/qtest: migration-test: Disable IO redirection " Bin Meng
                   ` (17 subsequent siblings)
  38 siblings, 0 replies; 87+ messages in thread
From: Bin Meng @ 2022-09-20 10:31 UTC (permalink / raw)
  To: qemu-devel
  Cc: Bin Meng, Marc-André Lureau, Ani Sinha, Igor Mammedov,
	Michael S. Tsirkin

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

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

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

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

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

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

(no changes since v1)

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

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



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

* [PATCH v2 22/39] tests/qtest: migration-test: Disable IO redirection for win32
  2022-09-20 10:31 [PATCH v2 00/39] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (20 preceding siblings ...)
  2022-09-20 10:31 ` [PATCH v2 21/39] tests/qtest: bios-tables-test: Adapt the case " Bin Meng
@ 2022-09-20 10:31 ` Bin Meng
  2022-09-22 20:04   ` Marc-André Lureau
  2022-09-20 10:31 ` [PATCH v2 23/39] tests/qtest: ide-test: Open file in binary mode Bin Meng
                   ` (16 subsequent siblings)
  38 siblings, 1 reply; 87+ messages in thread
From: Bin Meng @ 2022-09-20 10:31 UTC (permalink / raw)
  To: qemu-devel
  Cc: Bin Meng, Dr. David Alan Gilbert, Juan Quintela, Laurent Vivier,
	Paolo Bonzini, Thomas Huth

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

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

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

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

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

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



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

* [PATCH v2 23/39] tests/qtest: ide-test: Open file in binary mode
  2022-09-20 10:31 [PATCH v2 00/39] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (21 preceding siblings ...)
  2022-09-20 10:31 ` [PATCH v2 22/39] tests/qtest: migration-test: Disable IO redirection " Bin Meng
@ 2022-09-20 10:31 ` Bin Meng
  2022-09-20 10:31 ` [PATCH v2 24/39] tests/qtest: virtio-net-failover: Disable migration tests for win32 Bin Meng
                   ` (15 subsequent siblings)
  38 siblings, 0 replies; 87+ messages in thread
From: Bin Meng @ 2022-09-20 10:31 UTC (permalink / raw)
  To: qemu-devel
  Cc: Xuzhou Cheng, Bin Meng, Marc-André Lureau, John Snow,
	Laurent Vivier, Paolo Bonzini, Thomas Huth, qemu-block

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

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

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

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

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

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

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



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

* [PATCH v2 24/39] tests/qtest: virtio-net-failover: Disable migration tests for win32
  2022-09-20 10:31 [PATCH v2 00/39] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (22 preceding siblings ...)
  2022-09-20 10:31 ` [PATCH v2 23/39] tests/qtest: ide-test: Open file in binary mode Bin Meng
@ 2022-09-20 10:31 ` Bin Meng
  2022-09-22 20:05   ` Marc-André Lureau
  2022-09-20 10:31 ` [PATCH v2 25/39] chardev/char-file: Add FILE_SHARE_WRITE when openning the file " Bin Meng
                   ` (14 subsequent siblings)
  38 siblings, 1 reply; 87+ messages in thread
From: Bin Meng @ 2022-09-20 10:31 UTC (permalink / raw)
  To: qemu-devel
  Cc: Xuzhou Cheng, Bin Meng, Laurent Vivier, Paolo Bonzini, Thomas Huth

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

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

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

(no changes since v1)

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

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



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

* [PATCH v2 25/39] chardev/char-file: Add FILE_SHARE_WRITE when openning the file for win32
  2022-09-20 10:31 [PATCH v2 00/39] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (23 preceding siblings ...)
  2022-09-20 10:31 ` [PATCH v2 24/39] tests/qtest: virtio-net-failover: Disable migration tests for win32 Bin Meng
@ 2022-09-20 10:31 ` Bin Meng
  2022-09-22 20:09   ` Marc-André Lureau
  2022-09-20 10:31 ` [PATCH v2 26/39] tests/qtest: migration-test: Make sure QEMU process "to" exited after migration is canceled Bin Meng
                   ` (13 subsequent siblings)
  38 siblings, 1 reply; 87+ messages in thread
From: Bin Meng @ 2022-09-20 10:31 UTC (permalink / raw)
  To: qemu-devel; +Cc: Xuzhou Cheng, Bin Meng, Marc-André Lureau, Paolo Bonzini

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

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

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

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

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

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

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

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

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



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

* [PATCH v2 26/39] tests/qtest: migration-test: Make sure QEMU process "to" exited after migration is canceled
  2022-09-20 10:31 [PATCH v2 00/39] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (24 preceding siblings ...)
  2022-09-20 10:31 ` [PATCH v2 25/39] chardev/char-file: Add FILE_SHARE_WRITE when openning the file " Bin Meng
@ 2022-09-20 10:31 ` Bin Meng
  2022-09-21 16:29   ` Dr. David Alan Gilbert
  2022-09-21 21:54   ` Marc-André Lureau
  2022-09-20 10:31 ` [PATCH v2 27/39] hw/ppc: spapr: Use qemu_vfree() to free spapr->htab Bin Meng
                   ` (12 subsequent siblings)
  38 siblings, 2 replies; 87+ messages in thread
From: Bin Meng @ 2022-09-20 10:31 UTC (permalink / raw)
  To: qemu-devel
  Cc: Xuzhou Cheng, Bin Meng, Marc-André Lureau,
	Dr. David Alan Gilbert, Juan Quintela, Laurent Vivier,
	Paolo Bonzini, Thomas Huth

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

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

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

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

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

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



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

* [PATCH v2 27/39] hw/ppc: spapr: Use qemu_vfree() to free spapr->htab
  2022-09-20 10:31 [PATCH v2 00/39] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (25 preceding siblings ...)
  2022-09-20 10:31 ` [PATCH v2 26/39] tests/qtest: migration-test: Make sure QEMU process "to" exited after migration is canceled Bin Meng
@ 2022-09-20 10:31 ` Bin Meng
  2022-09-20 10:31 ` [PATCH v2 28/39] hw/pci-host: pnv_phb{3, 4}: Fix heap out-of-bound access failure Bin Meng
                   ` (11 subsequent siblings)
  38 siblings, 0 replies; 87+ messages in thread
From: Bin Meng @ 2022-09-20 10:31 UTC (permalink / raw)
  To: qemu-devel
  Cc: Xuzhou Cheng, Bin Meng, Daniel Henrique Barboza,
	Marc-André Lureau, Cédric Le Goater, David Gibson,
	Greg Kurz, qemu-ppc

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

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

Fixes: c5f54f3e31bf ("pseries: Move hash page table allocation to reset time")
Fixes: b4db54132ffe ("target/ppc: Implement H_REGISTER_PROCESS_TABLE H_CALL"")
Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
Signed-off-by: Bin Meng <bin.meng@windriver.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---

(no changes since v1)

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

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



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

* [PATCH v2 28/39] hw/pci-host: pnv_phb{3, 4}: Fix heap out-of-bound access failure
  2022-09-20 10:31 [PATCH v2 00/39] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (26 preceding siblings ...)
  2022-09-20 10:31 ` [PATCH v2 27/39] hw/ppc: spapr: Use qemu_vfree() to free spapr->htab Bin Meng
@ 2022-09-20 10:31 ` Bin Meng
  2022-09-20 11:17   ` Cédric Le Goater
  2022-09-20 15:40   ` Daniel Henrique Barboza
  2022-09-20 10:31 ` [PATCH v2 29/39] tests/qtest: microbit-test: Fix socket access for win32 Bin Meng
                   ` (10 subsequent siblings)
  38 siblings, 2 replies; 87+ messages in thread
From: Bin Meng @ 2022-09-20 10:31 UTC (permalink / raw)
  To: qemu-devel; +Cc: Xuzhou Cheng, Bin Meng, Cédric Le Goater, qemu-ppc

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

pnv_phb3_root_bus_info and pnv_phb4_root_bus_info are missing the
instance_size initialization. This results in accessing out-of-bound
memory when setting 'chip-id' and 'phb-id', and eventually crashes
glib's malloc functionality with the following message:

  "qemu-system-ppc64: GLib: ../glib-2.72.3/glib/gmem.c:131: failed to allocate 3232 bytes"

This issue was noticed only when running qtests with QEMU Windows
32-bit executable. Windows 64-bit, Linux 32/64-bit do not expose
this bug though.

Fixes: 9ae1329ee2fe ("ppc/pnv: Add models for POWER8 PHB3 PCIe Host bridge")
Fixes: 4f9924c4d4cf ("ppc/pnv: Add models for POWER9 PHB4 PCIe Host bridge")
Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
Signed-off-by: Bin Meng <bin.meng@windriver.com>
---

Changes in v2:
- new patch: "hw/pci-host: pnv_phb{3,4}: Fix heap out-of-bound access failure"

 hw/pci-host/pnv_phb3.c | 1 +
 hw/pci-host/pnv_phb4.c | 1 +
 2 files changed, 2 insertions(+)

diff --git a/hw/pci-host/pnv_phb3.c b/hw/pci-host/pnv_phb3.c
index af8575c007..9054c393a2 100644
--- a/hw/pci-host/pnv_phb3.c
+++ b/hw/pci-host/pnv_phb3.c
@@ -1169,6 +1169,7 @@ static void pnv_phb3_root_bus_class_init(ObjectClass *klass, void *data)
 static const TypeInfo pnv_phb3_root_bus_info = {
     .name = TYPE_PNV_PHB3_ROOT_BUS,
     .parent = TYPE_PCIE_BUS,
+    .instance_size = sizeof(PnvPHB3RootBus),
     .class_init = pnv_phb3_root_bus_class_init,
 };
 
diff --git a/hw/pci-host/pnv_phb4.c b/hw/pci-host/pnv_phb4.c
index 824e1a73fb..ccbde841fc 100644
--- a/hw/pci-host/pnv_phb4.c
+++ b/hw/pci-host/pnv_phb4.c
@@ -1773,6 +1773,7 @@ static void pnv_phb4_root_bus_class_init(ObjectClass *klass, void *data)
 static const TypeInfo pnv_phb4_root_bus_info = {
     .name = TYPE_PNV_PHB4_ROOT_BUS,
     .parent = TYPE_PCIE_BUS,
+    .instance_size = sizeof(PnvPHB4RootBus),
     .class_init = pnv_phb4_root_bus_class_init,
 };
 
-- 
2.34.1



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

* [PATCH v2 29/39] tests/qtest: microbit-test: Fix socket access for win32
  2022-09-20 10:31 [PATCH v2 00/39] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (27 preceding siblings ...)
  2022-09-20 10:31 ` [PATCH v2 28/39] hw/pci-host: pnv_phb{3, 4}: Fix heap out-of-bound access failure Bin Meng
@ 2022-09-20 10:31 ` Bin Meng
  2022-09-20 10:31 ` [PATCH v2 30/39] tests/qtest: libqtest: Replace the call to close a socket with closesocket() Bin Meng
                   ` (9 subsequent siblings)
  38 siblings, 0 replies; 87+ messages in thread
From: Bin Meng @ 2022-09-20 10:31 UTC (permalink / raw)
  To: qemu-devel
  Cc: Bin Meng, Marc-André Lureau, Joel Stanley, Laurent Vivier,
	Paolo Bonzini, Peter Maydell, Thomas Huth, qemu-arm

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

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

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

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

(no changes since v1)

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

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



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

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

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

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

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

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

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

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

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

(no changes since v1)

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

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



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

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

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

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

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

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

(no changes since v1)

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

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



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

* [PATCH v2 32/39] io/channel-watch: Drop a superfluous '#ifdef WIN32'
  2022-09-20 10:31 [PATCH v2 00/39] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (30 preceding siblings ...)
  2022-09-20 10:31 ` [PATCH v2 31/39] tests/qtest: libqtest: Correct the timeout unit of blocking receive calls for win32 Bin Meng
@ 2022-09-20 10:31 ` Bin Meng
  2022-09-20 10:31 ` [PATCH v2 33/39] io/channel-watch: Drop the unnecessary cast Bin Meng
                   ` (6 subsequent siblings)
  38 siblings, 0 replies; 87+ messages in thread
From: Bin Meng @ 2022-09-20 10:31 UTC (permalink / raw)
  To: qemu-devel; +Cc: Bin Meng, Marc-André Lureau, Daniel P. Berrangé

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

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

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

(no changes since v1)

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

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



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

* [PATCH v2 33/39] io/channel-watch: Drop the unnecessary cast
  2022-09-20 10:31 [PATCH v2 00/39] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (31 preceding siblings ...)
  2022-09-20 10:31 ` [PATCH v2 32/39] io/channel-watch: Drop a superfluous '#ifdef WIN32' Bin Meng
@ 2022-09-20 10:31 ` Bin Meng
  2022-09-22 20:13   ` Marc-André Lureau
  2022-09-20 10:31 ` [PATCH v2 34/39] io/channel-watch: Fix socket watch on Windows Bin Meng
                   ` (5 subsequent siblings)
  38 siblings, 1 reply; 87+ messages in thread
From: Bin Meng @ 2022-09-20 10:31 UTC (permalink / raw)
  To: qemu-devel; +Cc: Bin Meng, Marc-André Lureau, Daniel P. Berrangé

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

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

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

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

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

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



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

* [PATCH v2 34/39] io/channel-watch: Fix socket watch on Windows
  2022-09-20 10:31 [PATCH v2 00/39] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (32 preceding siblings ...)
  2022-09-20 10:31 ` [PATCH v2 33/39] io/channel-watch: Drop the unnecessary cast Bin Meng
@ 2022-09-20 10:31 ` Bin Meng
  2022-09-20 10:31 ` [PATCH v2 35/39] tests/qtest: migration-test: Skip running some TLS cases for win32 Bin Meng
                   ` (4 subsequent siblings)
  38 siblings, 0 replies; 87+ messages in thread
From: Bin Meng @ 2022-09-20 10:31 UTC (permalink / raw)
  To: qemu-devel; +Cc: Bin Meng, Daniel P. Berrangé

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

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

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

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

Some side notes:

During the testing, I removed the following codes in update_ioc_handlers():

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

and such change also makes the symptom go away.

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

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

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

(no changes since v1)

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

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



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

* [PATCH v2 35/39] tests/qtest: migration-test: Skip running some TLS cases for win32
  2022-09-20 10:31 [PATCH v2 00/39] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (33 preceding siblings ...)
  2022-09-20 10:31 ` [PATCH v2 34/39] io/channel-watch: Fix socket watch on Windows Bin Meng
@ 2022-09-20 10:31 ` Bin Meng
  2022-09-21 16:51   ` Dr. David Alan Gilbert
  2022-09-22 20:16   ` Marc-André Lureau
  2022-09-20 10:31 ` [PATCH v2 36/39] .gitlab-ci.d/windows.yml: Increase the timeout to 90 minutes Bin Meng
                   ` (3 subsequent siblings)
  38 siblings, 2 replies; 87+ messages in thread
From: Bin Meng @ 2022-09-20 10:31 UTC (permalink / raw)
  To: qemu-devel
  Cc: Bin Meng, Dr. David Alan Gilbert, Juan Quintela, Laurent Vivier,
	Paolo Bonzini, Thomas Huth

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

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

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

Disable them temporarily.

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

(no changes since v1)

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

diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index aedd9ddb72..dbee9b528a 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -1403,6 +1403,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);
@@ -1415,6 +1416,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)
@@ -1523,6 +1525,7 @@ static void test_precopy_tcp_plain(void)
 }
 
 #ifdef CONFIG_GNUTLS
+#ifndef _WIN32
 static void test_precopy_tcp_tls_psk_match(void)
 {
     MigrateCommon args = {
@@ -1533,6 +1536,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)
 {
@@ -1930,6 +1934,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)
@@ -1937,6 +1942,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,
@@ -1988,6 +1994,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 = {
@@ -1997,6 +2004,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)
 {
@@ -2497,8 +2505,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) {
         /*
@@ -2524,8 +2534,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
@@ -2569,8 +2581,10 @@ int main(int argc, char **argv)
                    test_multifd_tcp_zstd);
 #endif
 #ifdef CONFIG_GNUTLS
+#ifndef _WIN32
     qtest_add_func("/migration/multifd/tcp/tls/psk/match",
                    test_multifd_tcp_tls_psk_match);
+#endif
     qtest_add_func("/migration/multifd/tcp/tls/psk/mismatch",
                    test_multifd_tcp_tls_psk_mismatch);
 #ifdef CONFIG_TASN1
-- 
2.34.1



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

* [PATCH v2 36/39] .gitlab-ci.d/windows.yml: Increase the timeout to 90 minutes
  2022-09-20 10:31 [PATCH v2 00/39] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (34 preceding siblings ...)
  2022-09-20 10:31 ` [PATCH v2 35/39] tests/qtest: migration-test: Skip running some TLS cases for win32 Bin Meng
@ 2022-09-20 10:31 ` Bin Meng
  2022-09-23 16:22   ` Alex Bennée
  2022-09-20 10:31 ` [PATCH v2 37/39] .gitlab-ci.d/windows.yml: Display meson test logs Bin Meng
                   ` (2 subsequent siblings)
  38 siblings, 1 reply; 87+ messages in thread
From: Bin Meng @ 2022-09-20 10:31 UTC (permalink / raw)
  To: qemu-devel
  Cc: Bin Meng, Alex Bennée, Beraldo Leal,
	Philippe Mathieu-Daudé,
	Thomas Huth, Wainer dos Santos Moschetta

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

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

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

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

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

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

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



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

* [PATCH v2 37/39] .gitlab-ci.d/windows.yml: Display meson test logs
  2022-09-20 10:31 [PATCH v2 00/39] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (35 preceding siblings ...)
  2022-09-20 10:31 ` [PATCH v2 36/39] .gitlab-ci.d/windows.yml: Increase the timeout to 90 minutes Bin Meng
@ 2022-09-20 10:31 ` Bin Meng
  2022-09-20 10:31 ` [PATCH v2 38/39] tests/qtest: Enable qtest build on Windows Bin Meng
  2022-09-20 10:31 ` [PATCH v2 39/39] docs/devel: testing: Document writing portable test cases Bin Meng
  38 siblings, 0 replies; 87+ messages in thread
From: Bin Meng @ 2022-09-20 10:31 UTC (permalink / raw)
  To: qemu-devel
  Cc: Bin Meng, Alex Bennée, Beraldo Leal,
	Philippe Mathieu-Daudé,
	Thomas Huth, Wainer dos Santos Moschetta

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

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

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

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

diff --git a/.gitlab-ci.d/windows.yml b/.gitlab-ci.d/windows.yml
index 818676662a..dcd553a081 100644
--- a/.gitlab-ci.d/windows.yml
+++ b/.gitlab-ci.d/windows.yml
@@ -62,7 +62,7 @@ msys2-64bit:
       --enable-capstone'
   - .\msys64\usr\bin\bash -lc "sed -i '/^ROMS=/d' build/config-host.mak"
   - .\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
@@ -95,4 +95,4 @@ msys2-32bit:
   - cd output
   - ..\msys64\usr\bin\bash -lc "../configure --target-list=ppc64-softmmu"
   - ..\msys64\usr\bin\bash -lc 'make'
-  - ..\msys64\usr\bin\bash -lc 'make check'
+  - ..\msys64\usr\bin\bash -lc 'make check || { cat meson-logs/testlog.txt; exit 1; } ;'
-- 
2.34.1



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

* [PATCH v2 38/39] tests/qtest: Enable qtest build on Windows
  2022-09-20 10:31 [PATCH v2 00/39] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (36 preceding siblings ...)
  2022-09-20 10:31 ` [PATCH v2 37/39] .gitlab-ci.d/windows.yml: Display meson test logs Bin Meng
@ 2022-09-20 10:31 ` Bin Meng
  2022-09-22 20:18   ` Marc-André Lureau
  2022-09-20 10:31 ` [PATCH v2 39/39] docs/devel: testing: Document writing portable test cases Bin Meng
  38 siblings, 1 reply; 87+ messages in thread
From: Bin Meng @ 2022-09-20 10:31 UTC (permalink / raw)
  To: qemu-devel; +Cc: Bin Meng, Laurent Vivier, Paolo Bonzini, Thomas Huth

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

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

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

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

 tests/qtest/meson.build | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
index 455f1bbb7e..ceab141824 100644
--- a/tests/qtest/meson.build
+++ b/tests/qtest/meson.build
@@ -1,6 +1,5 @@
-# All QTests for now are POSIX-only, but the dependencies are
-# really in libqtest, not in the testcases themselves.
-if not config_host.has_key('CONFIG_POSIX')
+# Build all QTests for POSIX and Windows
+if not config_host.has_key('CONFIG_POSIX') and not config_host.has_key('CONFIG_WIN32')
   subdir_done()
 endif
 
-- 
2.34.1



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

* [PATCH v2 39/39] docs/devel: testing: Document writing portable test cases
  2022-09-20 10:31 [PATCH v2 00/39] tests/qtest: Enable running qtest on Windows Bin Meng
                   ` (37 preceding siblings ...)
  2022-09-20 10:31 ` [PATCH v2 38/39] tests/qtest: Enable qtest build on Windows Bin Meng
@ 2022-09-20 10:31 ` Bin Meng
  38 siblings, 0 replies; 87+ messages in thread
From: Bin Meng @ 2022-09-20 10:31 UTC (permalink / raw)
  To: qemu-devel
  Cc: Bin Meng, Marc-André Lureau, Alex Bennée,
	Paolo Bonzini, Philippe Mathieu-Daudé,
	Thomas Huth, Willian Rampazzo

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

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

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

Changes in v2:
- Minor wording changes

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

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



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

* Re: [PATCH v2 28/39] hw/pci-host: pnv_phb{3, 4}: Fix heap out-of-bound access failure
  2022-09-20 10:31 ` [PATCH v2 28/39] hw/pci-host: pnv_phb{3, 4}: Fix heap out-of-bound access failure Bin Meng
@ 2022-09-20 11:17   ` Cédric Le Goater
  2022-09-20 15:40   ` Daniel Henrique Barboza
  1 sibling, 0 replies; 87+ messages in thread
From: Cédric Le Goater @ 2022-09-20 11:17 UTC (permalink / raw)
  To: Bin Meng, qemu-devel; +Cc: Xuzhou Cheng, Bin Meng, qemu-ppc

On 9/20/22 12:31, Bin Meng wrote:
> From: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> 
> pnv_phb3_root_bus_info and pnv_phb4_root_bus_info are missing the
> instance_size initialization. This results in accessing out-of-bound
> memory when setting 'chip-id' and 'phb-id', and eventually crashes
> glib's malloc functionality with the following message:
> 
>    "qemu-system-ppc64: GLib: ../glib-2.72.3/glib/gmem.c:131: failed to allocate 3232 bytes"
> 
> This issue was noticed only when running qtests with QEMU Windows
> 32-bit executable. Windows 64-bit, Linux 32/64-bit do not expose
> this bug though.
> 
> Fixes: 9ae1329ee2fe ("ppc/pnv: Add models for POWER8 PHB3 PCIe Host bridge")
> Fixes: 4f9924c4d4cf ("ppc/pnv: Add models for POWER9 PHB4 PCIe Host bridge")
> Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>

Nice !

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

Thanks,

C.

> ---
> 
> Changes in v2:
> - new patch: "hw/pci-host: pnv_phb{3,4}: Fix heap out-of-bound access failure"
> 
>   hw/pci-host/pnv_phb3.c | 1 +
>   hw/pci-host/pnv_phb4.c | 1 +
>   2 files changed, 2 insertions(+)
> 
> diff --git a/hw/pci-host/pnv_phb3.c b/hw/pci-host/pnv_phb3.c
> index af8575c007..9054c393a2 100644
> --- a/hw/pci-host/pnv_phb3.c
> +++ b/hw/pci-host/pnv_phb3.c
> @@ -1169,6 +1169,7 @@ static void pnv_phb3_root_bus_class_init(ObjectClass *klass, void *data)
>   static const TypeInfo pnv_phb3_root_bus_info = {
>       .name = TYPE_PNV_PHB3_ROOT_BUS,
>       .parent = TYPE_PCIE_BUS,
> +    .instance_size = sizeof(PnvPHB3RootBus),
>       .class_init = pnv_phb3_root_bus_class_init,
>   };
>   
> diff --git a/hw/pci-host/pnv_phb4.c b/hw/pci-host/pnv_phb4.c
> index 824e1a73fb..ccbde841fc 100644
> --- a/hw/pci-host/pnv_phb4.c
> +++ b/hw/pci-host/pnv_phb4.c
> @@ -1773,6 +1773,7 @@ static void pnv_phb4_root_bus_class_init(ObjectClass *klass, void *data)
>   static const TypeInfo pnv_phb4_root_bus_info = {
>       .name = TYPE_PNV_PHB4_ROOT_BUS,
>       .parent = TYPE_PCIE_BUS,
> +    .instance_size = sizeof(PnvPHB4RootBus),
>       .class_init = pnv_phb4_root_bus_class_init,
>   };
>   



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

* Re: [PATCH v2 10/39] hw/usb: dev-mtp: Use g_mkdir()
  2022-09-20 10:31 ` [PATCH v2 10/39] hw/usb: dev-mtp: " Bin Meng
@ 2022-09-20 11:20   ` Gerd Hoffmann
  0 siblings, 0 replies; 87+ messages in thread
From: Gerd Hoffmann @ 2022-09-20 11:20 UTC (permalink / raw)
  To: Bin Meng; +Cc: qemu-devel, Bin Meng

On Tue, Sep 20, 2022 at 06:31:30PM +0800, Bin Meng wrote:
> From: Bin Meng <bin.meng@windriver.com>
> 
> Use g_mkdir() to create a directory on all platforms.
> 
> Signed-off-by: Bin Meng <bin.meng@windriver.com>

Acked-by: Gerd Hoffmann <kraxel@redhat.com>



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

* Re: [PATCH v2 09/39] fsdev/virtfs-proxy-helper: Use g_mkdir()
  2022-09-20 10:31 ` [PATCH v2 09/39] fsdev/virtfs-proxy-helper: Use g_mkdir() Bin Meng
@ 2022-09-20 13:42   ` Christian Schoenebeck
  0 siblings, 0 replies; 87+ messages in thread
From: Christian Schoenebeck @ 2022-09-20 13:42 UTC (permalink / raw)
  To: qemu-devel; +Cc: Bin Meng, Greg Kurz, Bin Meng

On Dienstag, 20. September 2022 12:31:29 CEST Bin Meng wrote:
> From: Bin Meng <bin.meng@windriver.com>
> 
> Use g_mkdir() to create a directory on all platforms.
> 
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---

Reviewed-by: Christian Schoenebeck <qemu_oss@crudebyte.com>

> 
> Changes in v2:
> - Change to use g_mkdir()
> 
>  fsdev/virtfs-proxy-helper.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/fsdev/virtfs-proxy-helper.c b/fsdev/virtfs-proxy-helper.c
> index 2dde27922f..5cafcd7703 100644
> --- a/fsdev/virtfs-proxy-helper.c
> +++ b/fsdev/virtfs-proxy-helper.c
> @@ -10,6 +10,7 @@
>   */
> 
>  #include "qemu/osdep.h"
> +#include <glib/gstdio.h>
>  #include <sys/resource.h>
>  #include <getopt.h>
>  #include <syslog.h>
> @@ -639,7 +640,7 @@ static int do_create_others(int type, struct iovec
> *iovec) if (retval < 0) {
>              goto err_out;
>          }
> -        retval = mkdir(path.data, mode);
> +        retval = g_mkdir(path.data, mode);
>          break;
>      case T_SYMLINK:
>          retval = proxy_unmarshal(iovec, offset, "ss", &oldpath, &path);





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

* Re: [PATCH v2 28/39] hw/pci-host: pnv_phb{3, 4}: Fix heap out-of-bound access failure
  2022-09-20 10:31 ` [PATCH v2 28/39] hw/pci-host: pnv_phb{3, 4}: Fix heap out-of-bound access failure Bin Meng
  2022-09-20 11:17   ` Cédric Le Goater
@ 2022-09-20 15:40   ` Daniel Henrique Barboza
  2022-09-21  0:14     ` Bin Meng
  1 sibling, 1 reply; 87+ messages in thread
From: Daniel Henrique Barboza @ 2022-09-20 15:40 UTC (permalink / raw)
  To: Bin Meng, qemu-devel
  Cc: Xuzhou Cheng, Bin Meng, Cédric Le Goater, qemu-ppc

Bin,

Since I'll send a ppc pull request shortly, I'll queue up both this and patch 27 via
the ppc tree. These are good fixes that are independent of what happens with the
'tests/qtest: Enable running qtest on Windows​' series.


Thanks,


Daniel

On 9/20/22 07:31, Bin Meng wrote:
> From: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> 
> pnv_phb3_root_bus_info and pnv_phb4_root_bus_info are missing the
> instance_size initialization. This results in accessing out-of-bound
> memory when setting 'chip-id' and 'phb-id', and eventually crashes
> glib's malloc functionality with the following message:
> 
>    "qemu-system-ppc64: GLib: ../glib-2.72.3/glib/gmem.c:131: failed to allocate 3232 bytes"
> 
> This issue was noticed only when running qtests with QEMU Windows
> 32-bit executable. Windows 64-bit, Linux 32/64-bit do not expose
> this bug though.
> 
> Fixes: 9ae1329ee2fe ("ppc/pnv: Add models for POWER8 PHB3 PCIe Host bridge")
> Fixes: 4f9924c4d4cf ("ppc/pnv: Add models for POWER9 PHB4 PCIe Host bridge")
> Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
> 
> Changes in v2:
> - new patch: "hw/pci-host: pnv_phb{3,4}: Fix heap out-of-bound access failure"
> 
>   hw/pci-host/pnv_phb3.c | 1 +
>   hw/pci-host/pnv_phb4.c | 1 +
>   2 files changed, 2 insertions(+)
> 
> diff --git a/hw/pci-host/pnv_phb3.c b/hw/pci-host/pnv_phb3.c
> index af8575c007..9054c393a2 100644
> --- a/hw/pci-host/pnv_phb3.c
> +++ b/hw/pci-host/pnv_phb3.c
> @@ -1169,6 +1169,7 @@ static void pnv_phb3_root_bus_class_init(ObjectClass *klass, void *data)
>   static const TypeInfo pnv_phb3_root_bus_info = {
>       .name = TYPE_PNV_PHB3_ROOT_BUS,
>       .parent = TYPE_PCIE_BUS,
> +    .instance_size = sizeof(PnvPHB3RootBus),
>       .class_init = pnv_phb3_root_bus_class_init,
>   };
>   
> diff --git a/hw/pci-host/pnv_phb4.c b/hw/pci-host/pnv_phb4.c
> index 824e1a73fb..ccbde841fc 100644
> --- a/hw/pci-host/pnv_phb4.c
> +++ b/hw/pci-host/pnv_phb4.c
> @@ -1773,6 +1773,7 @@ static void pnv_phb4_root_bus_class_init(ObjectClass *klass, void *data)
>   static const TypeInfo pnv_phb4_root_bus_info = {
>       .name = TYPE_PNV_PHB4_ROOT_BUS,
>       .parent = TYPE_PCIE_BUS,
> +    .instance_size = sizeof(PnvPHB4RootBus),
>       .class_init = pnv_phb4_root_bus_class_init,
>   };
>   


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

* Re: [PATCH v2 28/39] hw/pci-host: pnv_phb{3, 4}: Fix heap out-of-bound access failure
  2022-09-20 15:40   ` Daniel Henrique Barboza
@ 2022-09-21  0:14     ` Bin Meng
  0 siblings, 0 replies; 87+ messages in thread
From: Bin Meng @ 2022-09-21  0:14 UTC (permalink / raw)
  To: Daniel Henrique Barboza
  Cc: qemu-devel@nongnu.org Developers, Xuzhou Cheng, Bin Meng,
	Cédric Le Goater, qemu-ppc

On Tue, Sep 20, 2022 at 11:40 PM Daniel Henrique Barboza
<danielhb413@gmail.com> wrote:
>
> Bin,
>
> Since I'll send a ppc pull request shortly, I'll queue up both this and patch 27 via
> the ppc tree. These are good fixes that are independent of what happens with the
> 'tests/qtest: Enable running qtest on Windows' series.
>

Thank you Daniel.

Regards,
Bin


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

* Re: [PATCH v2 26/39] tests/qtest: migration-test: Make sure QEMU process "to" exited after migration is canceled
  2022-09-20 10:31 ` [PATCH v2 26/39] tests/qtest: migration-test: Make sure QEMU process "to" exited after migration is canceled Bin Meng
@ 2022-09-21 16:29   ` Dr. David Alan Gilbert
  2022-09-21 16:50     ` Daniel P. Berrangé
  2022-09-21 21:54   ` Marc-André Lureau
  1 sibling, 1 reply; 87+ messages in thread
From: Dr. David Alan Gilbert @ 2022-09-21 16:29 UTC (permalink / raw)
  To: Bin Meng
  Cc: qemu-devel, Xuzhou Cheng, Bin Meng, Marc-André Lureau,
	Juan Quintela, Laurent Vivier, Paolo Bonzini, Thomas Huth

* Bin Meng (bmeng.cn@gmail.com) wrote:
> From: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> 
> Make sure QEMU process "to" exited before launching another target
> for migration in the test_multifd_tcp_cancel case.
> 
> Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>

Hmm you might want to put a small usleep in that loop; otherwise
it'll burn CPU.

There is a slim risk with this that another, entirely unrelated, process 
will start up with the same PID between the end of migrate_cancel
and then you'll be spinning on it rather than the 'to' qemu.

I wonder if there's a better way to check for it dieing; e.g. an error
on it's qmp interface or something?

Dave

> ---
> 
> Changes in v2:
> - Change to a busy wait after migration is canceled
> 
>  tests/qtest/migration-test.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
> index c87afad9e8..aedd9ddb72 100644
> --- a/tests/qtest/migration-test.c
> +++ b/tests/qtest/migration-test.c
> @@ -2133,6 +2133,10 @@ static void test_multifd_tcp_cancel(void)
>      wait_for_migration_pass(from);
>  
>      migrate_cancel(from);
> +    /* Make sure QEMU process "to" exited */
> +    while (qtest_probe_child(to)) {
> +        ;
> +    }
>  
>      args = (MigrateStart){
>          .only_target = true,
> -- 
> 2.34.1
> 
-- 
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK



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

* Re: [PATCH v2 26/39] tests/qtest: migration-test: Make sure QEMU process "to" exited after migration is canceled
  2022-09-21 16:29   ` Dr. David Alan Gilbert
@ 2022-09-21 16:50     ` Daniel P. Berrangé
  0 siblings, 0 replies; 87+ messages in thread
From: Daniel P. Berrangé @ 2022-09-21 16:50 UTC (permalink / raw)
  To: Dr. David Alan Gilbert
  Cc: Bin Meng, qemu-devel, Xuzhou Cheng, Bin Meng,
	Marc-André Lureau, Juan Quintela, Laurent Vivier,
	Paolo Bonzini, Thomas Huth

On Wed, Sep 21, 2022 at 05:29:55PM +0100, Dr. David Alan Gilbert wrote:
> * Bin Meng (bmeng.cn@gmail.com) wrote:
> > From: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> > 
> > Make sure QEMU process "to" exited before launching another target
> > for migration in the test_multifd_tcp_cancel case.
> > 
> > Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> > Signed-off-by: Bin Meng <bin.meng@windriver.com>
> > Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> 
> Hmm you might want to put a small usleep in that loop; otherwise
> it'll burn CPU.
> 
> There is a slim risk with this that another, entirely unrelated, process 
> will start up with the same PID between the end of migrate_cancel
> and then you'll be spinning on it rather than the 'to' qemu.
> 
> I wonder if there's a better way to check for it dieing; e.g. an error
> on it's qmp interface or something?

Both the qtest and qmp sockets should give EOF. So if there's an API
that can call g_poll() on the FD with POLL_HUP event, it would be the
reliable way to detect it, without busy-looping.

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



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

* Re: [PATCH v2 35/39] tests/qtest: migration-test: Skip running some TLS cases for win32
  2022-09-20 10:31 ` [PATCH v2 35/39] tests/qtest: migration-test: Skip running some TLS cases for win32 Bin Meng
@ 2022-09-21 16:51   ` Dr. David Alan Gilbert
  2022-09-21 17:23     ` Daniel P. Berrangé
  2022-09-22 20:16   ` Marc-André Lureau
  1 sibling, 1 reply; 87+ messages in thread
From: Dr. David Alan Gilbert @ 2022-09-21 16:51 UTC (permalink / raw)
  To: Bin Meng, berrange
  Cc: qemu-devel, Bin Meng, Juan Quintela, Laurent Vivier,
	Paolo Bonzini, Thomas Huth

* Bin Meng (bmeng.cn@gmail.com) wrote:
> From: Bin Meng <bin.meng@windriver.com>
> 
> Some migration test cases use TLS to communicate, but they fail on
> Windows with the following error messages:
> 
>   qemu-system-x86_64: TLS handshake failed: Insufficient credentials for that request.
>   qemu-system-x86_64: TLS handshake failed: Error in the pull function.
>   query-migrate shows failed migration: TLS handshake failed: Error in the pull function.
> 
> Disable them temporarily.
> 
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
> I am not familar with the gnutls and simply enabling the gnutls debug
> output does not give me an immedidate hint on why it's failing on
> Windows. Disable these cases for now until someone or maintainers
> who may want to test this on Windows.

Copying in Dan Berrange, he's our expert on weird TLS failures.

Dave

> 
> (no changes since v1)
> 
>  tests/qtest/migration-test.c | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
> 
> diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
> index aedd9ddb72..dbee9b528a 100644
> --- a/tests/qtest/migration-test.c
> +++ b/tests/qtest/migration-test.c
> @@ -1403,6 +1403,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);
> @@ -1415,6 +1416,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)
> @@ -1523,6 +1525,7 @@ static void test_precopy_tcp_plain(void)
>  }
>  
>  #ifdef CONFIG_GNUTLS
> +#ifndef _WIN32
>  static void test_precopy_tcp_tls_psk_match(void)
>  {
>      MigrateCommon args = {
> @@ -1533,6 +1536,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)
>  {
> @@ -1930,6 +1934,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)
> @@ -1937,6 +1942,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,
> @@ -1988,6 +1994,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 = {
> @@ -1997,6 +2004,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)
>  {
> @@ -2497,8 +2505,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) {
>          /*
> @@ -2524,8 +2534,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
> @@ -2569,8 +2581,10 @@ int main(int argc, char **argv)
>                     test_multifd_tcp_zstd);
>  #endif
>  #ifdef CONFIG_GNUTLS
> +#ifndef _WIN32
>      qtest_add_func("/migration/multifd/tcp/tls/psk/match",
>                     test_multifd_tcp_tls_psk_match);
> +#endif
>      qtest_add_func("/migration/multifd/tcp/tls/psk/mismatch",
>                     test_multifd_tcp_tls_psk_mismatch);
>  #ifdef CONFIG_TASN1
> -- 
> 2.34.1
> 
-- 
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK



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

* Re: [PATCH v2 35/39] tests/qtest: migration-test: Skip running some TLS cases for win32
  2022-09-21 16:51   ` Dr. David Alan Gilbert
@ 2022-09-21 17:23     ` Daniel P. Berrangé
  2022-09-22  2:47       ` Bin Meng
  0 siblings, 1 reply; 87+ messages in thread
From: Daniel P. Berrangé @ 2022-09-21 17:23 UTC (permalink / raw)
  To: Dr. David Alan Gilbert
  Cc: Bin Meng, qemu-devel, Bin Meng, Juan Quintela, Laurent Vivier,
	Paolo Bonzini, Thomas Huth

On Wed, Sep 21, 2022 at 05:51:33PM +0100, Dr. David Alan Gilbert wrote:
> * Bin Meng (bmeng.cn@gmail.com) wrote:
> > From: Bin Meng <bin.meng@windriver.com>
> > 
> > Some migration test cases use TLS to communicate, but they fail on
> > Windows with the following error messages:
> > 
> >   qemu-system-x86_64: TLS handshake failed: Insufficient credentials for that request.
> >   qemu-system-x86_64: TLS handshake failed: Error in the pull function.
> >   query-migrate shows failed migration: TLS handshake failed: Error in the pull function.
> > 
> > Disable them temporarily.
> > 
> > Signed-off-by: Bin Meng <bin.meng@windriver.com>
> > ---
> > I am not familar with the gnutls and simply enabling the gnutls debug
> > output does not give me an immedidate hint on why it's failing on
> > Windows. Disable these cases for now until someone or maintainers
> > who may want to test this on Windows.
> 
> Copying in Dan Berrange, he's our expert on weird TLS failures.

Seems to match this:

   https://gnutls.org/faq.html#key-usage-violation2

which suggests we have a configuration mis-match.

I'm surprised to see you are only needing to disable the TLS PSK tests,
not the TLS x509 tests.

I'd like to know if tests/unit/test-crypto-tlssession passes.

If so, it might suggest we are missing 'priority: NORMAL' property
when configuring TLS creds for the migration test.

> > (no changes since v1)
> > 
> >  tests/qtest/migration-test.c | 14 ++++++++++++++
> >  1 file changed, 14 insertions(+)
> > 
> > diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
> > index aedd9ddb72..dbee9b528a 100644
> > --- a/tests/qtest/migration-test.c
> > +++ b/tests/qtest/migration-test.c
> > @@ -1403,6 +1403,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);
> > @@ -1415,6 +1416,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)
> > @@ -1523,6 +1525,7 @@ static void test_precopy_tcp_plain(void)
> >  }
> >  
> >  #ifdef CONFIG_GNUTLS
> > +#ifndef _WIN32
> >  static void test_precopy_tcp_tls_psk_match(void)
> >  {
> >      MigrateCommon args = {
> > @@ -1533,6 +1536,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)
> >  {
> > @@ -1930,6 +1934,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)
> > @@ -1937,6 +1942,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,
> > @@ -1988,6 +1994,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 = {
> > @@ -1997,6 +2004,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)
> >  {
> > @@ -2497,8 +2505,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) {
> >          /*
> > @@ -2524,8 +2534,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
> > @@ -2569,8 +2581,10 @@ int main(int argc, char **argv)
> >                     test_multifd_tcp_zstd);
> >  #endif
> >  #ifdef CONFIG_GNUTLS
> > +#ifndef _WIN32
> >      qtest_add_func("/migration/multifd/tcp/tls/psk/match",
> >                     test_multifd_tcp_tls_psk_match);
> > +#endif
> >      qtest_add_func("/migration/multifd/tcp/tls/psk/mismatch",
> >                     test_multifd_tcp_tls_psk_mismatch);
> >  #ifdef CONFIG_TASN1
> > -- 
> > 2.34.1
> > 
> -- 
> Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
> 

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



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

* Re: [PATCH v2 26/39] tests/qtest: migration-test: Make sure QEMU process "to" exited after migration is canceled
  2022-09-20 10:31 ` [PATCH v2 26/39] tests/qtest: migration-test: Make sure QEMU process "to" exited after migration is canceled Bin Meng
  2022-09-21 16:29   ` Dr. David Alan Gilbert
@ 2022-09-21 21:54   ` Marc-André Lureau
  2022-09-22  3:29     ` Bin Meng
  1 sibling, 1 reply; 87+ messages in thread
From: Marc-André Lureau @ 2022-09-21 21:54 UTC (permalink / raw)
  To: Bin Meng
  Cc: qemu-devel, Xuzhou Cheng, Bin Meng, Dr. David Alan Gilbert,
	Juan Quintela, Laurent Vivier, Paolo Bonzini, Thomas Huth

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

Hi

On Tue, Sep 20, 2022 at 3:18 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Xuzhou Cheng <xuzhou.cheng@windriver.com>
>
> Make sure QEMU process "to" exited before launching another target
> for migration in the test_multifd_tcp_cancel case.
>
> Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
>

fwiw, I didn't r-b the version with a busy wait
(
https://patchew.org/QEMU/20220824094029.1634519-1-bmeng.cn@gmail.com/20220824094029.1634519-42-bmeng.cn@gmail.com/
)

---
>
> Changes in v2:
> - Change to a busy wait after migration is canceled
>
>  tests/qtest/migration-test.c | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
> index c87afad9e8..aedd9ddb72 100644
> --- a/tests/qtest/migration-test.c
> +++ b/tests/qtest/migration-test.c
> @@ -2133,6 +2133,10 @@ static void test_multifd_tcp_cancel(void)
>      wait_for_migration_pass(from);
>
>      migrate_cancel(from);
> +    /* Make sure QEMU process "to" exited */
> +    while (qtest_probe_child(to)) {
> +        ;
> +    }
>
>      args = (MigrateStart){
>          .only_target = true,
> --
> 2.34.1
>
>
>

-- 
Marc-André Lureau

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

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

* Re: [PATCH v2 35/39] tests/qtest: migration-test: Skip running some TLS cases for win32
  2022-09-21 17:23     ` Daniel P. Berrangé
@ 2022-09-22  2:47       ` Bin Meng
  2022-09-22 10:39         ` Daniel P. Berrangé
  0 siblings, 1 reply; 87+ messages in thread
From: Bin Meng @ 2022-09-22  2:47 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: Dr. David Alan Gilbert, qemu-devel@nongnu.org Developers,
	Bin Meng, Juan Quintela, Laurent Vivier, Paolo Bonzini,
	Thomas Huth

On Thu, Sep 22, 2022 at 1:23 AM Daniel P. Berrangé <berrange@redhat.com> wrote:
>
> On Wed, Sep 21, 2022 at 05:51:33PM +0100, Dr. David Alan Gilbert wrote:
> > * Bin Meng (bmeng.cn@gmail.com) wrote:
> > > From: Bin Meng <bin.meng@windriver.com>
> > >
> > > Some migration test cases use TLS to communicate, but they fail on
> > > Windows with the following error messages:
> > >
> > >   qemu-system-x86_64: TLS handshake failed: Insufficient credentials for that request.
> > >   qemu-system-x86_64: TLS handshake failed: Error in the pull function.
> > >   query-migrate shows failed migration: TLS handshake failed: Error in the pull function.
> > >
> > > Disable them temporarily.
> > >
> > > Signed-off-by: Bin Meng <bin.meng@windriver.com>
> > > ---
> > > I am not familar with the gnutls and simply enabling the gnutls debug
> > > output does not give me an immedidate hint on why it's failing on
> > > Windows. Disable these cases for now until someone or maintainers
> > > who may want to test this on Windows.
> >
> > Copying in Dan Berrange, he's our expert on weird TLS failures.
>
> Seems to match this:
>
>    https://gnutls.org/faq.html#key-usage-violation2
>
> which suggests we have a configuration mis-match.
>
> I'm surprised to see you are only needing to disable the TLS PSK tests,
> not the TLS x509 tests.

The TLS x509 qtests all passed.

>
> I'd like to know if tests/unit/test-crypto-tlssession passes.

These unit tests currently are not built on Windows as they simply
don't build due to usage of socketpair().

>
> If so, it might suggest we are missing 'priority: NORMAL' property
> when configuring TLS creds for the migration test.

I did the following changes but the error is still the same:

diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index dbee9b528a..c1e3f11873 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -788,7 +788,8 @@ test_migrate_tls_psk_start_common(QTestState *from,
" 'id': 'tlscredspsk0',"
" 'endpoint': 'client',"
" 'dir': %s,"
- " 'username': 'qemu'} }",
+ " 'username': 'qemu',"
+ " 'priority': 'NORMAL'} }",
data->workdir);
qobject_unref(rsp);
@@ -797,7 +798,8 @@ test_migrate_tls_psk_start_common(QTestState *from,
" 'arguments': { 'qom-type': 'tls-creds-psk',"
" 'id': 'tlscredspsk0',"
" 'endpoint': 'server',"
- " 'dir': %s } }",
+ " 'dir': %s,"
+ " 'priority': 'NORMAL'} }",
mismatch ? data->workdiralt : data->workdir);
qobject_unref(rsp);

I am not sure whether I did the right changes.

>
> > > (no changes since v1)
> > >
> > >  tests/qtest/migration-test.c | 14 ++++++++++++++
> > >  1 file changed, 14 insertions(+)
> > >
> > > diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
> > > index aedd9ddb72..dbee9b528a 100644
> > > --- a/tests/qtest/migration-test.c
> > > +++ b/tests/qtest/migration-test.c
> > > @@ -1403,6 +1403,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);
> > > @@ -1415,6 +1416,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)
> > > @@ -1523,6 +1525,7 @@ static void test_precopy_tcp_plain(void)
> > >  }
> > >
> > >  #ifdef CONFIG_GNUTLS
> > > +#ifndef _WIN32
> > >  static void test_precopy_tcp_tls_psk_match(void)
> > >  {
> > >      MigrateCommon args = {
> > > @@ -1533,6 +1536,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)
> > >  {
> > > @@ -1930,6 +1934,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)
> > > @@ -1937,6 +1942,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,
> > > @@ -1988,6 +1994,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 = {
> > > @@ -1997,6 +2004,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)
> > >  {
> > > @@ -2497,8 +2505,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) {
> > >          /*
> > > @@ -2524,8 +2534,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
> > > @@ -2569,8 +2581,10 @@ int main(int argc, char **argv)
> > >                     test_multifd_tcp_zstd);
> > >  #endif
> > >  #ifdef CONFIG_GNUTLS
> > > +#ifndef _WIN32
> > >      qtest_add_func("/migration/multifd/tcp/tls/psk/match",
> > >                     test_multifd_tcp_tls_psk_match);
> > > +#endif
> > >      qtest_add_func("/migration/multifd/tcp/tls/psk/mismatch",
> > >                     test_multifd_tcp_tls_psk_mismatch);
> > >  #ifdef CONFIG_TASN1
> > > --
> > > 2.34.1
> > >

Regards,
Bin


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

* Re: [PATCH v2 26/39] tests/qtest: migration-test: Make sure QEMU process "to" exited after migration is canceled
  2022-09-21 21:54   ` Marc-André Lureau
@ 2022-09-22  3:29     ` Bin Meng
  0 siblings, 0 replies; 87+ messages in thread
From: Bin Meng @ 2022-09-22  3:29 UTC (permalink / raw)
  To: Marc-André Lureau
  Cc: qemu-devel@nongnu.org Developers, Xuzhou Cheng, Bin Meng,
	Dr. David Alan Gilbert, Juan Quintela, Laurent Vivier,
	Paolo Bonzini, Thomas Huth

On Thu, Sep 22, 2022 at 5:54 AM Marc-André Lureau
<marcandre.lureau@gmail.com> wrote:
>
> Hi
>
> On Tue, Sep 20, 2022 at 3:18 PM Bin Meng <bmeng.cn@gmail.com> wrote:
>>
>> From: Xuzhou Cheng <xuzhou.cheng@windriver.com>
>>
>> Make sure QEMU process "to" exited before launching another target
>> for migration in the test_multifd_tcp_cancel case.
>>
>> Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
>> Signed-off-by: Bin Meng <bin.meng@windriver.com>
>> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
>
>
> fwiw, I didn't r-b the version with a busy wait
> (https://patchew.org/QEMU/20220824094029.1634519-1-bmeng.cn@gmail.com/20220824094029.1634519-42-bmeng.cn@gmail.com/)
>

My mistake. The R-B tag was added before I changed the implementation
and I forgot to remove the tag.

Regards,
Bin


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

* Re: [PATCH v2 35/39] tests/qtest: migration-test: Skip running some TLS cases for win32
  2022-09-22  2:47       ` Bin Meng
@ 2022-09-22 10:39         ` Daniel P. Berrangé
  2022-09-22 11:54           ` Bin Meng
  0 siblings, 1 reply; 87+ messages in thread
From: Daniel P. Berrangé @ 2022-09-22 10:39 UTC (permalink / raw)
  To: Bin Meng
  Cc: Dr. David Alan Gilbert, qemu-devel@nongnu.org Developers,
	Bin Meng, Juan Quintela, Laurent Vivier, Paolo Bonzini,
	Thomas Huth

On Thu, Sep 22, 2022 at 10:47:26AM +0800, Bin Meng wrote:
> On Thu, Sep 22, 2022 at 1:23 AM Daniel P. Berrangé <berrange@redhat.com> wrote:
> >
> > On Wed, Sep 21, 2022 at 05:51:33PM +0100, Dr. David Alan Gilbert wrote:
> > > * Bin Meng (bmeng.cn@gmail.com) wrote:
> > > > From: Bin Meng <bin.meng@windriver.com>
> > > >
> > > > Some migration test cases use TLS to communicate, but they fail on
> > > > Windows with the following error messages:
> > > >
> > > >   qemu-system-x86_64: TLS handshake failed: Insufficient credentials for that request.
> > > >   qemu-system-x86_64: TLS handshake failed: Error in the pull function.
> > > >   query-migrate shows failed migration: TLS handshake failed: Error in the pull function.
> > > >
> > > > Disable them temporarily.
> > > >
> > > > Signed-off-by: Bin Meng <bin.meng@windriver.com>
> > > > ---
> > > > I am not familar with the gnutls and simply enabling the gnutls debug
> > > > output does not give me an immedidate hint on why it's failing on
> > > > Windows. Disable these cases for now until someone or maintainers
> > > > who may want to test this on Windows.
> > >
> > > Copying in Dan Berrange, he's our expert on weird TLS failures.
> >
> > Seems to match this:
> >
> >    https://gnutls.org/faq.html#key-usage-violation2
> >
> > which suggests we have a configuration mis-match.
> >
> > I'm surprised to see you are only needing to disable the TLS PSK tests,
> > not the TLS x509 tests.
> 
> The TLS x509 qtests all passed.
> 
> >
> > I'd like to know if tests/unit/test-crypto-tlssession passes.
> 
> These unit tests currently are not built on Windows as they simply
> don't build due to usage of socketpair().

Doh, yes, that's rather annoying, as debugging this problem in the
unit tests would be easier than in qtests.

> > If so, it might suggest we are missing 'priority: NORMAL' property
> > when configuring TLS creds for the migration test.
> 
> I did the following changes but the error is still the same:

> 
> diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
> index dbee9b528a..c1e3f11873 100644
> --- a/tests/qtest/migration-test.c
> +++ b/tests/qtest/migration-test.c
> @@ -788,7 +788,8 @@ test_migrate_tls_psk_start_common(QTestState *from,
> " 'id': 'tlscredspsk0',"
> " 'endpoint': 'client',"
> " 'dir': %s,"
> - " 'username': 'qemu'} }",
> + " 'username': 'qemu',"
> + " 'priority': 'NORMAL'} }",
> data->workdir);
> qobject_unref(rsp);
> @@ -797,7 +798,8 @@ test_migrate_tls_psk_start_common(QTestState *from,
> " 'arguments': { 'qom-type': 'tls-creds-psk',"
> " 'id': 'tlscredspsk0',"
> " 'endpoint': 'server',"
> - " 'dir': %s } }",
> + " 'dir': %s,"
> + " 'priority': 'NORMAL'} }",
> mismatch ? data->workdiralt : data->workdir);
> qobject_unref(rsp);
> 
> I am not sure whether I did the right changes.


That ought to have been sufficient, if priority strings were the
problem.


I think we'd need the debug output from gnutls - could you edit crypto/init.c
and uncomment the '#define DEBUG_GNUTLS' line near the top.

If you can post the output you get from a single migration-test test case
involving PSK, it might be enough to diagnose why gnutls is failing.

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



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

* Re: [PATCH v2 35/39] tests/qtest: migration-test: Skip running some TLS cases for win32
  2022-09-22 10:39         ` Daniel P. Berrangé
@ 2022-09-22 11:54           ` Bin Meng
  2022-09-27 15:40             ` Daniel P. Berrangé
  0 siblings, 1 reply; 87+ messages in thread
From: Bin Meng @ 2022-09-22 11:54 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: Dr. David Alan Gilbert, qemu-devel@nongnu.org Developers,
	Bin Meng, Juan Quintela, Laurent Vivier, Paolo Bonzini,
	Thomas Huth

On Thu, Sep 22, 2022 at 6:39 PM Daniel P. Berrangé <berrange@redhat.com> wrote:
>
> On Thu, Sep 22, 2022 at 10:47:26AM +0800, Bin Meng wrote:
> > On Thu, Sep 22, 2022 at 1:23 AM Daniel P. Berrangé <berrange@redhat.com> wrote:
> > >
> > > On Wed, Sep 21, 2022 at 05:51:33PM +0100, Dr. David Alan Gilbert wrote:
> > > > * Bin Meng (bmeng.cn@gmail.com) wrote:
> > > > > From: Bin Meng <bin.meng@windriver.com>
> > > > >
> > > > > Some migration test cases use TLS to communicate, but they fail on
> > > > > Windows with the following error messages:
> > > > >
> > > > >   qemu-system-x86_64: TLS handshake failed: Insufficient credentials for that request.
> > > > >   qemu-system-x86_64: TLS handshake failed: Error in the pull function.
> > > > >   query-migrate shows failed migration: TLS handshake failed: Error in the pull function.
> > > > >
> > > > > Disable them temporarily.
> > > > >
> > > > > Signed-off-by: Bin Meng <bin.meng@windriver.com>
> > > > > ---
> > > > > I am not familar with the gnutls and simply enabling the gnutls debug
> > > > > output does not give me an immedidate hint on why it's failing on
> > > > > Windows. Disable these cases for now until someone or maintainers
> > > > > who may want to test this on Windows.
> > > >
> > > > Copying in Dan Berrange, he's our expert on weird TLS failures.
> > >
> > > Seems to match this:
> > >
> > >    https://gnutls.org/faq.html#key-usage-violation2
> > >
> > > which suggests we have a configuration mis-match.
> > >
> > > I'm surprised to see you are only needing to disable the TLS PSK tests,
> > > not the TLS x509 tests.
> >
> > The TLS x509 qtests all passed.
> >
> > >
> > > I'd like to know if tests/unit/test-crypto-tlssession passes.
> >
> > These unit tests currently are not built on Windows as they simply
> > don't build due to usage of socketpair().
>
> Doh, yes, that's rather annoying, as debugging this problem in the
> unit tests would be easier than in qtests.
>
> > > If so, it might suggest we are missing 'priority: NORMAL' property
> > > when configuring TLS creds for the migration test.
> >
> > I did the following changes but the error is still the same:
>
> >
> > diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
> > index dbee9b528a..c1e3f11873 100644
> > --- a/tests/qtest/migration-test.c
> > +++ b/tests/qtest/migration-test.c
> > @@ -788,7 +788,8 @@ test_migrate_tls_psk_start_common(QTestState *from,
> > " 'id': 'tlscredspsk0',"
> > " 'endpoint': 'client',"
> > " 'dir': %s,"
> > - " 'username': 'qemu'} }",
> > + " 'username': 'qemu',"
> > + " 'priority': 'NORMAL'} }",
> > data->workdir);
> > qobject_unref(rsp);
> > @@ -797,7 +798,8 @@ test_migrate_tls_psk_start_common(QTestState *from,
> > " 'arguments': { 'qom-type': 'tls-creds-psk',"
> > " 'id': 'tlscredspsk0',"
> > " 'endpoint': 'server',"
> > - " 'dir': %s } }",
> > + " 'dir': %s,"
> > + " 'priority': 'NORMAL'} }",
> > mismatch ? data->workdiralt : data->workdir);
> > qobject_unref(rsp);
> >
> > I am not sure whether I did the right changes.
>
>
> That ought to have been sufficient, if priority strings were the
> problem.
>
>
> I think we'd need the debug output from gnutls - could you edit crypto/init.c
> and uncomment the '#define DEBUG_GNUTLS' line near the top.
>
> If you can post the output you get from a single migration-test test case
> involving PSK, it might be enough to diagnose why gnutls is failing.
>

Here is the output:

# Start of tls tests
# starting QEMU: ./qemu-system-x86_64 -qtest
unix:D:\msys64\tmp/qtest-18480.sock -qtest-log nul -chardev
socket,path=D:\msys64\tmp/qtest-18480.qmp,id=char0 -mon
chardev=char0,mode=control -display none -accel kvm -accel t
cg -name source,debug-threads=on -m 150M -serial
file:D:\msys64\tmp\migration-test-A5WJS1/src_serial -drive
file=D:\msys64\tmp\migration-test-A5WJS1/bootsect,format=raw -accel
qtest
qemu: thread naming not supported on this host
# starting QEMU: ./qemu-system-x86_64 -qtest
unix:D:\msys64\tmp/qtest-18480.sock -qtest-log nul -chardev
socket,path=D:\msys64\tmp/qtest-18480.qmp,id=char0 -mon
chardev=char0,mode=control -display none -accel kvm -accel t
cg -name target,debug-threads=on -m 150M -serial
file:D:\msys64\tmp\migration-test-A5WJS1/dest_serial -incoming
unix:D:\msys64\tmp\migration-test-A5WJS1/migsocket -drive
file=D:\msys64\tmp\migration-test-A5WJS1/bootsect,f
ormat=raw -accel qtest
qemu: thread naming not supported on this host
3: ASSERT: ../../gnutls-3.7.7/lib/str.c[gnutls_hex_decode]:605
3: ASSERT: ../../gnutls-3.7.7/lib/psk.c[gnutls_psk_set_client_credentials2]:164
55:: RREECC[[000000000011651b6bd15dfd420c2500]]:: AAllllooccaattiinngg
eeppoocchh ##00
2: a2d:de da d6d epdr o6t opcrooltso,c o4l6s ,c i4p6h
ecrispuhietressu,i t1e9s ,s i1g9 asliggo sa lagnods 1a0 ngdr o1u0ps i
ngtroo upprsi oirnitto yp rliiosrti
ty5 :l iRsEtC
[50:0 0REC0[0010601060d155fb4b012d0d]2:c 5A0l]l:o cAalltocatiinngg
eeppoocchh ##11
3:4: AHSSSKE[R0T0:0 0.0.1/5.b.b/1gdndu2tcl5s0-]3:. 7A.d7v/.l
ivbe/rbsuifofne:r s3..c3[
ge2t:_ lKaesetp_ipnagc kceitp]h:e1r1s8u5i
t10: eR E1A3D.:0 2- 1( GrNeUtTuLrSn_eAdE Sf_r2o5m6 _0G0C0M0_0S1H6A1368349)b
d21:7 0K,e ererpnion=g1 1c igpehrerrnsou=i0t
e3 :1 3A.S0S3E R(TG:N
U.T.L/S._.C/HgAnCuHtAl2s0-_3P.O7L.Y71/3l0i5b_/SbHuAf2f5e6r)s
.2c:[ _Kgeneuptilnsg_ icoi_prheeards_ubiutfef e1r3e.d0]1: 5(8G9N
UTLS_AES_128_GCM_SHA256)
2: Keeping ciphersuite 13.04 (GNUTLS_AES_128_CCM_SHA256)
2: Keeping ciphersuite cc.ac (GNUTLS_ECDHE_PSK_CHACHA20_POLY1305)
2: Keeping ciphersuite c0.36 (GNUTLS_ECDHE_PSK_AES_256_CBC_SHA1)
2: Keeping ciphersuite c0.35 (GNUTLS_ECDHE_PSK_AES_128_CBC_SHA1)
2: Keeping ciphersuite 00.ab (GNUTLS_DHE_PSK_AES_256_GCM_SHA384)
2: Keeping ciphersuite cc.ad (GNUTLS_DHE_PSK_CHACHA20_POLY1305)
2: Keeping ciphersuite c0.a7 (GNUTLS_DHE_PSK_AES_256_CCM)
2: Keeping ciphersuite 00.91 (GNUTLS_DHE_PSK_AES_256_CBC_SHA1)
2: Keeping ciphersuite 00.aa (GNUTLS_DHE_PSK_AES_128_GCM_SHA256)
2: Keeping ciphersuite c0.a6 (GNUTLS_DHE_PSK_AES_128_CCM)
2: Keeping ciphersuite 00.90 (GNUTLS_DHE_PSK_AES_128_CBC_SHA1)
2: Keeping ciphersuite 00.a9 (GNUTLS_PSK_AES_256_GCM_SHA384)
2: Keeping ciphersuite cc.ab (GNUTLS_PSK_CHACHA20_POLY1305)
2: Keeping ciphersuite c0.a5 (GNUTLS_PSK_AES_256_CCM)
2: Keeping ciphersuite 00.8d (GNUTLS_PSK_AES_256_CBC_SHA1)
2: Keeping ciphersuite 00.a8 (GNUTLS_PSK_AES_128_GCM_SHA256)
2: Keeping ciphersuite c0.a4 (GNUTLS_PSK_AES_128_CCM)
2: Keeping ciphersuite 00.8c (GNUTLS_PSK_AES_128_CBC_SHA1)
4: EXT[0000015bb1dd2c50]: Preparing extension (OCSP Status Request/5)
for 'client hello'
4: EXT[0000015bb1dd2c50]: Preparing extension (Client Certificate
Type/19) for 'client hello'
4: EXT[0000015bb1dd2c50]: Preparing extension (Server Certificate
Type/20) for 'client hello'
4: EXT[0000015bb1dd2c50]: Preparing extension (Supported Groups/10)
for 'client hello'
4: EXT[0000015bb1dd2c50]: Sent group SECP256R1 (0x17)
4: EXT[0000015bb1dd2c50]: Sent group SECP384R1 (0x18)
4: EXT[0000015bb1dd2c50]: Sent group SECP521R1 (0x19)
4: EXT[0000015bb1dd2c50]: Sent group X25519 (0x1d)
4: EXT[0000015bb1dd2c50]: Sent group X448 (0x1e)
4: EXT[0000015bb1dd2c50]: Sent group FFDHE2048 (0x100)
4: EXT[0000015bb1dd2c50]: Sent group FFDHE3072 (0x101)
4: EXT[0000015bb1dd2c50]: Sent group FFDHE4096 (0x102)
4: EXT[0000015bb1dd2c50]: Sent group FFDHE6144 (0x103)
4: EXT[0000015bb1dd2c50]: Sent group FFDHE8192 (0x104)
4: EXT[0000015bb1dd2c50]: Sending extension Supported Groups/10 (22 bytes)
4: EXT[0000015bb1dd2c50]: Preparing extension (Supported EC Point
Formats/11) for 'client hello'
4: EXT[0000015bb1dd2c50]: Sending extension Supported EC Point
Formats/11 (2 bytes)
4: EXT[0000015bb1dd2c50]: Preparing extension (SRP/12) for 'client hello'
4: EXT[0000015bb1dd2c50]: Preparing extension (Signature
Algorithms/13) for 'client hello'
4: EXT[0000015bb1dd2c50]: sent signature algo (4.1) RSA-SHA256
4: EXT[0000015bb1dd2c50]: sent signature algo (8.9) RSA-PSS-SHA256
4: EXT[0000015bb1dd2c50]: sent signature algo (8.4) RSA-PSS-RSAE-SHA256
4: EXT[0000015bb1dd2c50]: sent signature algo (4.3) ECDSA-SHA256
4: EXT[0000015bb1dd2c50]: sent signature algo (8.7) EdDSA-Ed25519
4: EXT[0000015bb1dd2c50]: sent signature algo (5.1) RSA-SHA384
4: EXT[0000015bb1dd2c50]: sent signature algo (8.10) RSA-PSS-SHA384
4: EXT[0000015bb1dd2c50]: sent signature algo (8.5) RSA-PSS-RSAE-SHA384
4: EXT[0000015bb1dd2c50]: sent signature algo (5.3) ECDSA-SHA384
4: EXT[0000015bb1dd2c50]: sent signature algo (8.8) EdDSA-Ed448
4: EXT[0000015bb1dd2c50]: sent signature algo (6.1) RSA-SHA512
4: EXT[0000015bb1dd2c50]: sent signature algo (8.11) RSA-PSS-SHA512
4: EXT[0000015bb1dd2c50]: sent signature algo (8.6) RSA-PSS-RSAE-SHA512
4: EXT[0000015bb1dd2c50]: sent signature algo (6.3) ECDSA-SHA512
4: EXT[0000015bb1dd2c50]: sent signature algo (2.1) RSA-SHA1
4: EXT[0000015bb1dd2c50]: sent signature algo (2.3) ECDSA-SHA1
4: EXT[0000015bb1dd2c50]: Sending extension Signature Algorithms/13 (34 bytes)
4: EXT[0000015bb1dd2c50]: Preparing extension (SRTP/14) for 'client hello'
4: EXT[0000015bb1dd2c50]: Preparing extension (Heartbeat/15) for 'client hello'
4: EXT[0000015bb1dd2c50]: Preparing extension (ALPN/16) for 'client hello'
4: EXT[0000015bb1dd2c50]: Preparing extension (Encrypt-then-MAC/22)
for 'client hello'
4: EXT[0000015bb1dd2c50]: Sending extension Encrypt-then-MAC/22 (0 bytes)
4: EXT[0000015bb1dd2c50]: Preparing extension (Extended Master
Secret/23) for 'client hello'
4: EXT[0000015bb1dd2c50]: Sending extension Extended Master Secret/23 (0 bytes)
4: EXT[0000015bb1dd2c50]: Preparing extension (Session Ticket/35) for
'client hello'
4: EXT[0000015bb1dd2c50]: Sending extension Session Ticket/35 (0 bytes)
4: EXT[0000015bb1dd2c50]: Preparing extension (Key Share/51) for 'client hello'
4: EXT[0000015bb1dd2c50]: sending key share for SECP256R1
4: EXT[0000015bb1dd2c50]: sending key share for X25519
4: EXT[0000015bb1dd2c50]: Sending extension Key Share/51 (107 bytes)
4: EXT[0000015bb1dd2c50]: Preparing extension (Supported Versions/43)
for 'client hello'
2: Advertizing version 3.4
2: Advertizing version 3.3
2: Advertizing version 3.2
2: Advertizing version 3.1
4: EXT[0000015bb1dd2c50]: Sending extension Supported Versions/43 (9 bytes)
4: EXT[0000015bb1dd2c50]: Preparing extension (Post Handshake Auth/49)
for 'client hello'
4: EXT[0000015bb1dd2c50]: Preparing extension (Safe
Renegotiation/65281) for 'client hello'
4: EXT[0000015bb1dd2c50]: Sending extension Safe Renegotiation/65281 (1 bytes)
4: EXT[0000015bb1dd2c50]: Preparing extension (Server Name
Indication/0) for 'client hello'
4: EXT[0000015bb1dd2c50]: Preparing extension (Cookie/44) for 'client hello'
4: EXT[0000015bb1dd2c50]: Preparing extension (Early Data/42) for 'client hello'
4: EXT[0000015bb1dd2c50]: Preparing extension (PSK Key Exchange
Modes/45) for 'client hello'
4: EXT[0000015bb1dd2c50]: Sending extension PSK Key Exchange Modes/45 (3 bytes)
4: EXT[0000015bb1dd2c50]: Preparing extension (Record Size Limit/28)
for 'client hello'
4: EXT[0000015bb1dd2c50]: Sending extension Record Size Limit/28 (2 bytes)
4: EXT[0000015bb1dd2c50]: Preparing extension (Maximum Record Size/1)
for 'client hello'
4: EXT[0000015bb1dd2c50]: Preparing extension (Compress
Certificate/27) for 'client hello'
4: EXT[0000015bb1dd2c50]: Preparing extension (ClientHello Padding/21)
for 'client hello'
4: EXT[0000015bb1dd2c50]: Preparing extension (Pre Shared Key/41) for
'client hello'
4: HSK[0000015bb1dd2c50]: CLIENT HELLO was queued [343 bytes]
5: REC[0000015bb1dd2c50]: Preparing Packet Handshake(22) with length:
343 and min pad: 0
9: ENC[0000015bb1dd2c50]: cipher: NULL, MAC: MAC-NULL, Epoch: 0
5: REC[0000015bb1dd2c50]: Sent Packet[1] Handshake(22) in epoch 0 and
length: 348
3: A3S:S EARSTS:E R.T.:/
....//g.n.u/tglnsu-t3l.s7-.37./7l.i7b//lbiubf/fbeurfsf.ecr[sg.ect[_gleats_tl_apsatc_kpeatc]k:e1t1]8:51
185
10: READ: Got 5 bytes from 00000161639bd170
10: READ: read 5 bytes from 00000161639bd170
10: RB: Have 0 bytes into buffer. Adding 5 bytes.
10: RB: Requested 5 bytes
5: REC[000001616d5f4020]: SSL 3.1 Handshake packet received. Epoch 0,
length: 343
5: REC[000001616d5f4020]: Expected Packet Handshake(22)
5: REC[000001616d5f4020]: Received Packet Handshake(22) with length: 343
10: READ: Got 343 bytes from 00000161639bd170
10: READ: read 343 bytes from 00000161639bd170
10: RB: Have 5 bytes into buffer. Adding 343 bytes.
10: RB: Requested 348 bytes
5: REC[000001616d5f4020]: Decrypted Packet[0] Handshake(22) with length: 343
4: HSK[000001616d5f4020]: CLIENT HELLO (1) was received. Length
339[339], frag offset 0, frag length: 339, sequence: 0
4: HSK[000001616d5f4020]: Client's version: 3.3
4: EXT[000001616d5f4020]: Parsing extension 'Supported Versions/43' (9 bytes)
4: EXT[000001616d5f4020]: Found version: 3.4
4: EXT[000001616d5f4020]: Found version: 3.3
4: EXT[000001616d5f4020]: Found version: 3.2
4: EXT[000001616d5f4020]: Found version: 3.1
4: EXT[000001616d5f4020]: Negotiated version: 3.4
4: EXT[000001616d5f4020]: Parsing extension 'Encrypt-then-MAC/22' (0 bytes)
4: EXT[000001616d5f4020]: Parsing extension 'Extended Master
Secret/23' (0 bytes)
4: EXT[000001616d5f4020]: Parsing extension 'Safe Renegotiation/65281' (1 bytes)
4: EXT[000001616d5f4020]: Parsing extension 'Record Size Limit/28' (2 bytes)
4: EXT[000001616d5f4020]: record_size_limit 16385 negotiated
4: EXT[000001616d5f4020]: Parsing extension 'Supported Groups/10' (22 bytes)
4: EXT[000001616d5f4020]: Received group SECP256R1 (0x17)
4: EXT[000001616d5f4020]: Received group SECP384R1 (0x18)
4: EXT[000001616d5f4020]: Received group SECP521R1 (0x19)
4: EXT[000001616d5f4020]: Received group X25519 (0x1d)
4: EXT[000001616d5f4020]: Received group X448 (0x1e)
4: EXT[000001616d5f4020]: Received group FFDHE2048 (0x100)
4: EXT[000001616d5f4020]: Received group FFDHE3072 (0x101)
4: EXT[000001616d5f4020]: Received group FFDHE4096 (0x102)
4: EXT[000001616d5f4020]: Received group FFDHE6144 (0x103)
4: EXT[000001616d5f4020]: Received group FFDHE8192 (0x104)
4: EXT[000001616d5f4020]: Selected group SECP256R1
4: EXT[000001616d5f4020]: Parsing extension 'Supported EC Point
Formats/11' (2 bytes)
4: EXT[000001616d5f4020]: Parsing extension 'Signature Algorithms/13' (34 bytes)
4: EXT[000001616d5f4020]: rcvd signature algo (4.1) RSA-SHA256
4: EXT[000001616d5f4020]: rcvd signature algo (8.9) RSA-PSS-SHA256
4: EXT[000001616d5f4020]: rcvd signature algo (8.4) RSA-PSS-RSAE-SHA256
4: EXT[000001616d5f4020]: rcvd signature algo (4.3) ECDSA-SECP256R1-SHA256
4: EXT[000001616d5f4020]: rcvd signature algo (8.7) EdDSA-Ed25519
4: EXT[000001616d5f4020]: rcvd signature algo (5.1) RSA-SHA384
4: EXT[000001616d5f4020]: rcvd signature algo (8.10) RSA-PSS-SHA384
4: EXT[000001616d5f4020]: rcvd signature algo (8.5) RSA-PSS-RSAE-SHA384
4: EXT[000001616d5f4020]: rcvd signature algo (5.3) ECDSA-SECP384R1-SHA384
4: EXT[000001616d5f4020]: rcvd signature algo (8.8) EdDSA-Ed448
4: EXT[000001616d5f4020]: rcvd signature algo (6.1) RSA-SHA512
4: EXT[000001616d5f4020]: rcvd signature algo (8.11) RSA-PSS-SHA512
4: EXT[000001616d5f4020]: rcvd signature algo (8.6) RSA-PSS-RSAE-SHA512
4: EXT[000001616d5f4020]: rcvd signature algo (6.3) ECDSA-SECP521R1-SHA512
4: EXT[000001616d5f4020]: rcvd signature algo (2.1) RSA-SHA1
4: EXT[000001616d5f4020]: rcvd signature algo (2.3) ECDSA-SHA1
4: EXT[000001616d5f4020]: Parsing extension 'Session Ticket/35' (0 bytes)
4: EXT[000001616d5f4020]: Parsing extension 'PSK Key Exchange
Modes/45' (3 bytes)
4: EXT[000001616d5f4020]: PSK KE mode 01 received
4: EXT[000001616d5f4020]: PSK KE mode 00 received
2: checking 13.02 (GNUTLS_AES_256_GCM_SHA384) for compatibility
3: ASSERT: ../../../gnutls-3.7.7/lib/auth/cert.c[_gnutls_select_server_cert]:1622
4: HSK[000001616d5f4020]: Selected cipher suite: GNUTLS_AES_256_GCM_SHA384
4: HSK[000001616d5f4020]: Selected version TLS1.3
4: EXT[000001616d5f4020]: Parsing extension 'Key Share/51' (107 bytes)
4: EXT[000001616d5f4020]: Received key share for SECP256R1
4: HSK[000001616d5f4020]: Selected group SECP256R1 (2)
2: EXT[000001616d5f4020]: server generated SECP256R1 shared key
4: HSK[000001616d5f4020]: Safe renegotiation succeeded
4: HSK[000001616d5f4020]: SessionID:
746d784844566d638ffa314a9b00c72d2d0ad0cfdd83ae6623c36fa21e3dfc94
4: EXT[000001616d5f4020]: Not sending extension (OCSP Status
Request/5) for 'TLS 1.3 server hello'
4: EXT[000001616d5f4020]: Not sending extension (Client Certificate
Type/19) for 'TLS 1.3 server hello'
4: EXT[000001616d5f4020]: Not sending extension (Server Certificate
Type/20) for 'TLS 1.3 server hello'
4: EXT[000001616d5f4020]: Not sending extension (Supported Groups/10)
for 'TLS 1.3 server hello'
4: EXT[000001616d5f4020]: Not sending extension (Supported EC Point
Formats/11) for 'TLS 1.3 server hello'
4: EXT[000001616d5f4020]: Not sending extension (SRP/12) for 'TLS 1.3
server hello'
4: EXT[000001616d5f4020]: Not sending extension (Signature
Algorithms/13) for 'TLS 1.3 server hello'
4: EXT[000001616d5f4020]: Not sending extension (SRTP/14) for 'TLS 1.3
server hello'
4: EXT[000001616d5f4020]: Not sending extension (Heartbeat/15) for
'TLS 1.3 server hello'
4: EXT[000001616d5f4020]: Not sending extension (ALPN/16) for 'TLS 1.3
server hello'
4: EXT[000001616d5f4020]: Not sending extension (Encrypt-then-MAC/22)
for 'TLS 1.3 server hello'
4: EXT[000001616d5f4020]: Not sending extension (Extended Master
Secret/23) for 'TLS 1.3 server hello'
4: EXT[000001616d5f4020]: Not sending extension (Session Ticket/35)
for 'TLS 1.3 server hello'
4: EXT[000001616d5f4020]: Preparing extension (Key Share/51) for 'TLS
1.3 server hello'
4: EXT[000001616d5f4020]: sending key share for SECP256R1
4: EXT[000001616d5f4020]: Sending extension Key Share/51 (69 bytes)
4: EXT[000001616d5f4020]: Preparing extension (Supported Versions/43)
for 'TLS 1.3 server hello'
4: EXT[000001616d5f4020]: Sending extension Supported Versions/43 (2 bytes)
4: EXT[000001616d5f4020]: Not sending extension (Post Handshake
Auth/49) for 'TLS 1.3 server hello'
4: EXT[000001616d5f4020]: Not sending extension (Safe
Renegotiation/65281) for 'TLS 1.3 server hello'
4: EXT[000001616d5f4020]: Not sending extension (Server Name
Indication/0) for 'TLS 1.3 server hello'
4: EXT[000001616d5f4020]: Not sending extension (Cookie/44) for 'TLS
1.3 server hello'
4: EXT[000001616d5f4020]: Not sending extension (Early Data/42) for
'TLS 1.3 server hello'
4: EXT[000001616d5f4020]: Preparing extension (PSK Key Exchange
Modes/45) for 'TLS 1.3 server hello'
4: EXT[000001616d5f4020]: Not sending extension (Record Size Limit/28)
for 'TLS 1.3 server hello'
4: EXT[000001616d5f4020]: Not sending extension (Maximum Record
Size/1) for 'TLS 1.3 server hello'
4: EXT[000001616d5f4020]: Preparing extension (Compress
Certificate/27) for 'TLS 1.3 server hello'
4: EXT[000001616d5f4020]: Not sending extension (ClientHello
Padding/21) for 'TLS 1.3 server hello'
4: EXT[000001616d5f4020]: Preparing extension (Pre Shared Key/41) for
'TLS 1.3 server hello'
4: HSK[000001616d5f4020]: SERVER HELLO was queued [155 bytes]
5: REC[000001616d5f4020]: Preparing Packet Handshake(22) with length:
155 and min pad: 0
9: ENC[000001616d5f4020]: cipher: NULL, MAC: MAC-NULL, Epoch: 0
5: REC[000001616d5f4020]: Sent Packet[1] Handshake(22) in epoch 0 and
length: 160
5: REC[000001616d5f4020]: Preparing Packet ChangeCipherSpec(20) with
length: 1 and min pad: 0
9: ENC[000001616d5f4020]: cipher: NULL, MAC: MAC-NULL, Epoch: 0
5: REC[000001616d5f4020]: Sent Packet[2] ChangeCipherSpec(20) in epoch
0 and length: 6
41:0 :R ERCE[A0D00:0 0G1o6t1 65d 5bfy4t0e2s0 ]f:r oSme n0t0
0C0h0a1n5gbefCdi2pah3eeraS0p
e1c0
: RE5:A DR:E Cr[e0a0d0 050 1b6y1t6eds5 ff4r0o2m0 ]0:0
0I0n0i1t5ibafldi2zai3nega 0e
p10o:c hR B#:1
Have 09 :b yItNeTs: iCnLtIoE NbTu fWfReIrT.E AKdEdYi n[g3 25] :b y7tbe4s4.8
d1b05:0 R3Be:4 5Rbedq7u7ebsbt6e4d0 053 8b7y1t1e1s0
df51:0 6R2EcC0[50a010c050e1959b6b211dfdd20c2520d]3:8 5S2S0L7 232.c3
9H:a nIdNsTh:a kSeE RpVaEcRk eWtR IrTeEc eKiEvYe d[.3 2E]p:o cdh7
d0c,b7 0lce7ncgft1hb:2 7165e52
ef50:d cR8E9C8[a0e06040a061e53bfb510d2d225c15402]8:7 7E3x1pbeec5tbefd0
dP1a5c7kee9t5 5H9aan
d9:s hIaNkTe:( 2C2L)I
EN5T: WRREICT[E0 0I0V0 0[1152b]b:1 d6dd2fc55004]6:7 cR0e5c9edi0v3e1d3
5Pca7cck8eft4
H9a:n dIsNhTa:k eS(E2R2V)E Rw iWtRhI TlEe nIgVt h[:1 21]5:5
e8d1e0a:7 8R1E0A9De:d 6Geobt4 a135c58 0b7yat1e
s 5f:r oRm E0C0[0000001050b1f6d126ad35efa400
2100]:: REEpAoDc:h r#e1a dr e1a5d5y
byt4e:s HfSrKo[m0 000000001061156bdf5df24a032e0a]0:
1T0L:S R1B.:3 Hraev-ek e5y bwyittehs ciinpthoe rb usfufietre.:
AGdNdUiTnLgS _1A5E5S _b2y5t6e_GsC.M
_1S0H:A 3R8B4:
R4e:q uEeXsTt[e0d0 0106001 6b1y6tde5sf
4052:0 ]R:E CN[o0t0 0s0e0n1d5ibnbg1 dedx2tce5n0s]i:o nD e(cOrCySpPt
eSdt aPtaucsk eRte[q0u]e sHta/n5d)s hfaokre ('2e2n)c rwyiptthe dl
eenxgttehn:s i1o5n5s
'
44:: HESXKT[[00000000001156b1b61dd5df24c05200]]:: SPErReVpEaRr iHnEgL
LeOx t(e2n)s iwoans (rCelcieeinvte dC.e rLteinfgitcha t1e5
1T[y1p5e1/]1,9 )f rfaogr o'fefnscerty p0t,e df reaxgt elnesnigotnhs:'
145:1 ,E XsTe[q0u0e0n0c0e1:6 106
d35:f 4A0S2S0E]R:T :P r.e.p/a.r.i/nggn uetxltse-n3s.i7o.n7
/(lSiebr/vbeurf fCeerrst.icf[igceatt_el aTsytp_ep/a2c0k)e tf]o:r
1'1e7n6c
r3y:p tAeSdS EeRxTt:e n.s.i/o.n.s/'g
nu4t:l sE-X3T.[70.070/0l0i1b6/1b6udf5ffe4r0s2.0c][:_
gPnruetplasr_ihnagn desxhtaeknes_iioon_ r(eScuvp_pionrtt]e:d1 4G2r8o
u4p:s /H1S0K)[ 0f0o0r0 0'1e5nbcbr1ydpdt2ecd5 0e]x:t eSnesrivoenrs''s
4v:e rEsXiTo[n0:0 030.031
6146:d 5EfX4T0[2000]0:0 0N1o5tb bs1edndd2icn5g0 ]e:x tPeanrssiionng
(eSxutpepnosritoend 'ESCu pPpooirntte dF oVremrastiso/n1s1/)4 3f'o r(
2' ebnyctreysp)t
e4d: eExXtTe[n0s0i0o0n0s1'5
bb41:d dE2XcT5[00]0:0 0N0e1g6o1t6ida5tfe4d0 2v0e]r:s iNoont: s3e.n4d
i4:n gH SeKx[t0e0n0s0i0o1n5 b(bS1RdPd/21c25)0 ]f:o rS e'leencctreydp
tceidp heexrt esnusiitoen:s 'G
N4U:T LESX_TA[E0S0_0205061_6G1C6Md_5SfH4A032804]
:4 :No tE XsTe[n0d0i0n0g0 1e5xbtbe1ndsdi2ocn5 0(]S:i gPnaartsuirneg
Aelxgtoernistihomns /'1K3e)y fSohra r'ee/n5c1r'y p(t6e9d beyxtteesn)s
i4o:n sH'S
K4[:0 0E0X0T0[1050b0b010d1d621c65d05]f:4 0S2e0l]e:c tPerd egpraoruipn
gS EeCxPt2e5n6sRi1o n( 2()S
RTP/14)2 :f oErX T'[e0n0c0r0y0p1t5ebdb 1edxdt2ecn5s0i]o:n sc'l
i4e:n tE XgTe[n0e0r0a0t0e1d6 1S6EdC5Pf245062R01] :s hParreepda rkienyg
ext5e:n sRiEoCn[ 0(0H0e0a0r1t5bbeba1td/d125c)5 0f]o:r
P'reenpcarryipntge dP aecxkteetn sCihoannsg'e
Ci4p:h eErXSTp[e0c0(02000)1 6w1i6tdh5 fl4e0n2g0t]h:: P1r eapnadr
imnign epxatde:n s0i
on 9(:A LEPNNC/[1060)0 0f0o1r5 b'be1ndcdr2ycp5t0e]d: ecxitpehnesri:o nNsU'L
L4,: MEAXTC[:0 0M0A0C0-1N6U1L6Ld,5 fE4p0o2c0h]:: 0N
ot5 :s eRnEdCi[n0g0 0e0x0t1e5nbsbi1odnd 2(cE5n0c]r:y pSte-ntth
ePna-cMkAeCt/[222]) Cfhoarn g'eeCnicprhyeprtSepde ce(x2t0e)n siino
nesp'o
ch4 :0 EaXnTd[ 0l0e0n0g0t1h6:1 66d
5f4042:0 ]R:E CN[o0t0 0s0e0n1d5ibnbg1 dedx2tce5n0s]i:o nS e(nEtx
tCehnadnegde CMiapshteerrS pSeecc
ret/52:3 )R EfCo[r0 0'0e0n0c1r5ybpbt1eddd 2ecx5t0e]n:s iIonnist'i
a4l:i zEiXnTg[ 0e0p0o0c0h1 6#116
d59f:4 0I2N0T]:: CNLoItE NsTe nWdRiInTgE eKxEtYe n[s3i2o]n:
(7Sbe4s4s8idobn5 0T3iec4k5ebd7t7/b3b56)4 0f0o3r8 7'1e1n1c0rdyfp1t0e6d2
ce0x5tae1ncs5ieo9n9s6'2
1fd40:2 2EdX3T8[502000702021c6
169d:5f 4I0N2T0:] :S ENRoVtE Rs eWnRdIiTnEg KeExYt e[n3s2i]o:n
d(7Kdecyb 7S0hca7rcef/15b12)7 6feo2re f'0edncc8r9y8patee6d4
ae6xet3efn5s0i2o2n5s1'4
248:7 7E3X1Tb[e050b0f000d115671e69d555f94a0
209:] :I Not NsTe:n dCiLnIgE NeTx tWeRnIsTiEo nI V( S[u1p2p]o:r t6eddf
5V0e4r6s7ico0n5s9/d4033)1 3f5ocr7 c'8efn4c
ry9p:t eIdN Te:x tSeEnsioRnVsE'R
W4R:I TEEX TI[V0 0[01020]1:6 1e68dd5efa47082100]9:e dN6oetb 4sae3ncd8i0n7ga 1e
x5t:e nRsEiCo[n0 0(0P0o0s1t5 bHba1nddds2hca5k0e] :A uEtpho/c4h9 )# 1f
orre a'deyn
c4r:y pHtSeKd[ 0e0x0t0e0n1s5ibobn1sd'd
24c:5 0]E:X TT[L0S0 010.031 6r1e6-dk5efy4 0w2i0t]h: cNiopth esre
nsduiintge :e xGtNeUnTsLiSo_nA E(SS_a2f5e6 _RGeCnMe_gSoHtAi3a8t4i
o3n:/ 6A5S2S8E1R)T :f o.r. /'.e.n/cgrnyupttlesd- 3e.x7t.e7n/sliiobn/sb'u
f4f:e rEsX.Tc[[0g0e0t0_0l1a6s1t6_pda5cfk4e0t2]0:]1:1 8P5r
ep1a0r:i nRgE AeDx:t eGnosti o5n b(ySteersv efrr oNma m0e0
0I0n0d1i5cbaftdi2oan3/e0a)0
f1o0r: 'ReEnAcDr:y prteeadd e5x tbeyntseiso nfsr'o
m4 :0 0E0X0T0[1050b0f0d021a631e6ad05
f1400:2 0R]B:: NHoatv es e0n dbiyntge se xitnetnos ibounf f(eCro.o
kAided/i4n4g) 5f obry t'eesn.c
r1y0p:t eRdB :e xRteeqnuseisotnesd'
54 :b yEtXeTs[
050:0 0R0E1C6[1060d050f041052b0]b:1 dPdr2ecp5a0r]i:n gS SeLx t3e.n3s
iCohna n(gEeaCrilpyh eDraStpae/c4 2p)a cfkoert 'reencceriyvpetde.d
Eepxotcehn s1i,o nlse'n
g4t:h :E X1T
[50:0 0R0E0C1[601060d050f1450b2b01]d:d 2Nco5t0 ]s:e nEdxipnegc teexdt
ePnascikoent (HPaSnKd sKheayk eE(x2c2h)a
n5g:e RMEoCd[e0s0/04050)1 5fbobr1 d'de2ncc5r0y]p:t eRde ceexitveends iPoancsk'e
t4 :C hEaXnTg[e0C0i0p0h0e1r6S1p6edc5(f2400)2 0w]i:t hP rleepnagrtihn:g 1e
xt1e0n:s iRoEnA D(:R eGcootr d1 Sbiyztee sL ifmriotm/ 2080)0 0f0o1r5
b'fedn2car3yepat0e
d1 0e:x tReEnAsDi:o nrse'a
d4 :1 EbXyTt[e0s0 0f0r0o1m6 1060d050f041052b0f]d:2 aS3eenad0i
n1g0 :e xRtBe:n sHiaovne R5e cboyrtde sS iiznet oL ibmuiftf/e2r8. (A2d
dbiyntge s1)
byt4e:s .E
XT1[00:0 0R0B0:1 6R1e6qdu5efs4t0e2d0 ]6: bPyrteepsa
ri1n0g: edxitsecnasridoinn g( Mcahxainmguem cRiepchoerrd sSpiezce
/i1n) TfLoSr1 .'3e
ncrypted extensions'
4: EXT[000001616d5f4020]: Not sending extension (Compress
Certificate/27) for 'encrypted extensions'
4: EXT[000001616d5f4020]: Not sending extension (ClientHello
Padding/21) for 'encrypted extensions'
4: EXT[000001616d5f4020]: Not sending extension (Pre Shared Key/41)
for 'encrypted extensions'
4: HSK[000001616d5f4020]: ENCRYPTED EXTENSIONS was queued [12 bytes]
3: ASSERT: ../../gnutls-3.7.7/lib/tls13/certificate.c[_gnutls13_send_certificate]:250
3: ASSERT: ../../gnutls-3.7.7/lib/handshake-tls13.c[_gnutls13_handshake_server]:440
qemu-system-x86_64: TLS handshake failed: Insufficient credentials for
that request.
5: REC[000001616d5f4020]: Start of epoch cleanup
5: REC[000001616d5f4020]: Epoch #0 freed
5: REC[000001616d5f4020]: End of epoch cleanup
5: REC[000001616d5f4020]: Epoch #1 freed
10: READ: -1 returned from 0000015bfd2a3ea0, errno=5 gerrno=0
3: ASSERT: ../../gnutls-3.7.7/lib/buffers.c[_gnutls_stream_read]:369
3: ASSERT: ../../gnutls-3.7.7/lib/buffers.c[_gnutls_io_read_buffered]:589
3: ASSERT: ../../gnutls-3.7.7/lib/record.c[recv_headers]:1195
3: ASSERT: ../../gnutls-3.7.7/lib/record.c[_gnutls_recv_in_buffers]:1321
3: ASSERT: ../../gnutls-3.7.7/lib/buffers.c[_gnutls_handshake_io_recv_int]:1467
3: ASSERT: ../../gnutls-3.7.7/lib/handshake.c[_gnutls_recv_handshake]:1600
3: ASSERT: ../../gnutls-3.7.7/lib/tls13/encrypted_extensions.c[_gnutls13_recv_encrypted_extensions]:37
3: ASSERT: ../../gnutls-3.7.7/lib/handshake-tls13.c[_gnutls13_handshake_client]:114
qemu-system-x86_64: TLS handshake failed: Error in the pull function.
5: REC[0000015bb1dd2c50]: Start of epoch cleanup
5: REC[0000015bb1dd2c50]: Epoch #0 freed
5: REC[0000015bb1dd2c50]: End of epoch cleanup
5: REC[0000015bb1dd2c50]: Epoch #1 freed
query-migrate shows failed migration: TLS handshake failed: Error in
the pull function.
**
ERROR:../tests/qtest/migration-helpers.c:151:migrate_query_not_failed:
assertion failed: (!g_str_equal(status, "failed"))
Bail out! ERROR:../tests/qtest/migration-helpers.c:151:migrate_query_not_failed:
assertion failed: (!g_str_equal(status, "failed"))

Regards,
Bin


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

* Re: [PATCH v2 01/39] tests: Change to use g_mkdir()
  2022-09-20 10:31 ` [PATCH v2 01/39] tests: Change to use g_mkdir() Bin Meng
@ 2022-09-22 19:32   ` Marc-André Lureau
  2022-09-23  1:09     ` Bin Meng
  0 siblings, 1 reply; 87+ messages in thread
From: Marc-André Lureau @ 2022-09-22 19:32 UTC (permalink / raw)
  To: Bin Meng
  Cc: qemu-devel, Bin Meng, Daniel P. Berrangé,
	Dr. David Alan Gilbert, Juan Quintela, Laurent Vivier,
	Paolo Bonzini, Thomas Huth

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

Hi

On Tue, Sep 20, 2022 at 1:48 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Bin Meng <bin.meng@windriver.com>
>
> Commit 413bebc04603 ("tests: Use g_mkdir_with_parents()") replaces
> the mkdir() call in the test codes with glib's g_mkdir_with_parents(),
> but the exact portable replacement for mkdir() should be g_mkdir().
>
> I probably was misled by the GTK glib doc [1] before, thinking that
> g_mkdir() is not a supported API from glib. But the glib sources do
> not support this statement. It is probably that the GTK documentation
> was not built to include all APIs.
>
> [1] https://docs.gtk.org/glib/?q=mkdir
>
> Fixes: 413bebc04603 ("tests: Use g_mkdir_with_parents()")
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
>

I wouldn't bother anymore, I'd keep mkdir_with_parents for now. YMMV

---
>
> Changes in v2:
> - new patch: "tests: Change to use g_mkdir()"
>
>  tests/migration/stress.c              | 3 ++-
>  tests/qtest/migration-test.c          | 7 ++++---
>  tests/unit/test-crypto-tlscredsx509.c | 5 +++--
>  tests/unit/test-crypto-tlssession.c   | 7 ++++---
>  tests/unit/test-io-channel-tls.c      | 7 ++++---
>  5 files changed, 17 insertions(+), 12 deletions(-)
>
> diff --git a/tests/migration/stress.c b/tests/migration/stress.c
> index 88acf8dc25..76b91851ad 100644
> --- a/tests/migration/stress.c
> +++ b/tests/migration/stress.c
> @@ -19,6 +19,7 @@
>
>  #include "qemu/osdep.h"
>  #include <getopt.h>
> +#include <glib/gstdio.h>
>  #include <sys/reboot.h>
>  #include <sys/syscall.h>
>  #include <linux/random.h>
> @@ -232,7 +233,7 @@ static void stress(unsigned long long ramsizeGB, int
> ncpus)
>
>  static int mount_misc(const char *fstype, const char *dir)
>  {
> -    if (g_mkdir_with_parents(dir, 0755) < 0 && errno != EEXIST) {
> +    if (g_mkdir(dir, 0755) < 0 && errno != EEXIST) {
>          fprintf(stderr, "%s (%05d): ERROR: cannot create %s: %s\n",
>                  argv0, gettid(), dir, strerror(errno));
>          return -1;
> diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
> index 4728d528bb..55892b3798 100644
> --- a/tests/qtest/migration-test.c
> +++ b/tests/qtest/migration-test.c
> @@ -11,6 +11,7 @@
>   */
>
>  #include "qemu/osdep.h"
> +#include <glib/gstdio.h>
>
>  #include "libqtest.h"
>  #include "qapi/error.h"
> @@ -761,14 +762,14 @@ test_migrate_tls_psk_start_common(QTestState *from,
>      data->workdir = g_strdup_printf("%s/tlscredspsk0", tmpfs);
>      data->pskfile = g_strdup_printf("%s/%s", data->workdir,
>                                      QCRYPTO_TLS_CREDS_PSKFILE);
> -    g_mkdir_with_parents(data->workdir, 0700);
> +    g_mkdir(data->workdir, 0700);
>      test_tls_psk_init(data->pskfile);
>
>      if (mismatch) {
>          data->workdiralt = g_strdup_printf("%s/tlscredspskalt0", tmpfs);
>          data->pskfilealt = g_strdup_printf("%s/%s", data->workdiralt,
>                                             QCRYPTO_TLS_CREDS_PSKFILE);
> -        g_mkdir_with_parents(data->workdiralt, 0700);
> +        g_mkdir(data->workdiralt, 0700);
>          test_tls_psk_init_alt(data->pskfilealt);
>      }
>
> @@ -873,7 +874,7 @@ test_migrate_tls_x509_start_common(QTestState *from,
>          data->clientcert = g_strdup_printf("%s/client-cert.pem",
> data->workdir);
>      }
>
> -    g_mkdir_with_parents(data->workdir, 0700);
> +    g_mkdir(data->workdir, 0700);
>
>      test_tls_init(data->keyfile);
>  #ifndef _WIN32
> diff --git a/tests/unit/test-crypto-tlscredsx509.c
> b/tests/unit/test-crypto-tlscredsx509.c
> index 3c25d75ca1..03fa48a3c5 100644
> --- a/tests/unit/test-crypto-tlscredsx509.c
> +++ b/tests/unit/test-crypto-tlscredsx509.c
> @@ -19,6 +19,7 @@
>   */
>
>  #include "qemu/osdep.h"
> +#include <glib/gstdio.h>
>
>  #include "crypto-tls-x509-helpers.h"
>  #include "crypto/tlscredsx509.h"
> @@ -75,7 +76,7 @@ static void test_tls_creds(const void *opaque)
>      QCryptoTLSCreds *creds;
>
>  #define CERT_DIR "tests/test-crypto-tlscredsx509-certs/"
> -    g_mkdir_with_parents(CERT_DIR, 0700);
> +    g_mkdir(CERT_DIR, 0700);
>
>      unlink(CERT_DIR QCRYPTO_TLS_CREDS_X509_CA_CERT);
>      if (data->isServer) {
> @@ -141,7 +142,7 @@ int main(int argc, char **argv)
>      g_test_init(&argc, &argv, NULL);
>      g_setenv("GNUTLS_FORCE_FIPS_MODE", "2", 1);
>
> -    g_mkdir_with_parents(WORKDIR, 0700);
> +    g_mkdir(WORKDIR, 0700);
>
>      test_tls_init(KEYFILE);
>
> diff --git a/tests/unit/test-crypto-tlssession.c
> b/tests/unit/test-crypto-tlssession.c
> index 615a1344b4..356afbadfb 100644
> --- a/tests/unit/test-crypto-tlssession.c
> +++ b/tests/unit/test-crypto-tlssession.c
> @@ -19,6 +19,7 @@
>   */
>
>  #include "qemu/osdep.h"
> +#include <glib/gstdio.h>
>
>  #include "crypto-tls-x509-helpers.h"
>  #include "crypto-tls-psk-helpers.h"
> @@ -249,8 +250,8 @@ static void test_crypto_tls_session_x509(const void
> *opaque)
>
>  #define CLIENT_CERT_DIR "tests/test-crypto-tlssession-client/"
>  #define SERVER_CERT_DIR "tests/test-crypto-tlssession-server/"
> -    g_mkdir_with_parents(CLIENT_CERT_DIR, 0700);
> -    g_mkdir_with_parents(SERVER_CERT_DIR, 0700);
> +    g_mkdir(CLIENT_CERT_DIR, 0700);
> +    g_mkdir(SERVER_CERT_DIR, 0700);
>
>      unlink(SERVER_CERT_DIR QCRYPTO_TLS_CREDS_X509_CA_CERT);
>      unlink(SERVER_CERT_DIR QCRYPTO_TLS_CREDS_X509_SERVER_CERT);
> @@ -398,7 +399,7 @@ int main(int argc, char **argv)
>      g_test_init(&argc, &argv, NULL);
>      g_setenv("GNUTLS_FORCE_FIPS_MODE", "2", 1);
>
> -    g_mkdir_with_parents(WORKDIR, 0700);
> +    g_mkdir(WORKDIR, 0700);
>
>      test_tls_init(KEYFILE);
>      test_tls_psk_init(PSKFILE);
> diff --git a/tests/unit/test-io-channel-tls.c
> b/tests/unit/test-io-channel-tls.c
> index cc39247556..1d95c9f61d 100644
> --- a/tests/unit/test-io-channel-tls.c
> +++ b/tests/unit/test-io-channel-tls.c
> @@ -22,6 +22,7 @@
>
>
>  #include "qemu/osdep.h"
> +#include <glib/gstdio.h>
>
>  #include "crypto-tls-x509-helpers.h"
>  #include "io/channel-tls.h"
> @@ -125,8 +126,8 @@ static void test_io_channel_tls(const void *opaque)
>
>  #define CLIENT_CERT_DIR "tests/test-io-channel-tls-client/"
>  #define SERVER_CERT_DIR "tests/test-io-channel-tls-server/"
> -    g_mkdir_with_parents(CLIENT_CERT_DIR, 0700);
> -    g_mkdir_with_parents(SERVER_CERT_DIR, 0700);
> +    g_mkdir(CLIENT_CERT_DIR, 0700);
> +    g_mkdir(SERVER_CERT_DIR, 0700);
>
>      unlink(SERVER_CERT_DIR QCRYPTO_TLS_CREDS_X509_CA_CERT);
>      unlink(SERVER_CERT_DIR QCRYPTO_TLS_CREDS_X509_SERVER_CERT);
> @@ -273,7 +274,7 @@ int main(int argc, char **argv)
>      g_test_init(&argc, &argv, NULL);
>      g_setenv("GNUTLS_FORCE_FIPS_MODE", "2", 1);
>
> -    g_mkdir_with_parents(WORKDIR, 0700);
> +    g_mkdir(WORKDIR, 0700);
>
>      test_tls_init(KEYFILE);
>
> --
> 2.34.1
>
>
>

-- 
Marc-André Lureau

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

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

* Re: [PATCH v2 02/39] tests/qtest: i440fx-test: Rewrite create_blob_file() to be portable
  2022-09-20 10:31 ` [PATCH v2 02/39] tests/qtest: i440fx-test: Rewrite create_blob_file() to be portable Bin Meng
@ 2022-09-22 19:34   ` Marc-André Lureau
  0 siblings, 0 replies; 87+ messages in thread
From: Marc-André Lureau @ 2022-09-22 19:34 UTC (permalink / raw)
  To: Bin Meng; +Cc: qemu-devel, Bin Meng, Laurent Vivier, Paolo Bonzini, Thomas Huth

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

Hi

On Tue, Sep 20, 2022 at 12:56 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Bin Meng <bin.meng@windriver.com>
>
> Previously request_{bios, pflash} cases were skipped on win32, mainly
> due to create_blob_file() calling mmap() which does not exist on win32.
> This rewirtes create_blob_file() to be portable, so that we can enable
> these cases on Windows.
>
> Suggested-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
>
> Changes in v2:
> - new patch: "tests/qtest: i440fx-test: Rewrite create_blob_file() to be
> portable"
>
>  tests/qtest/i440fx-test.c | 53 +++++++++++----------------------------
>  1 file changed, 14 insertions(+), 39 deletions(-)
>
> diff --git a/tests/qtest/i440fx-test.c b/tests/qtest/i440fx-test.c
> index 3890f1237c..202bc6022c 100644
> --- a/tests/qtest/i440fx-test.c
> +++ b/tests/qtest/i440fx-test.c
> @@ -278,8 +278,6 @@ 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))
>
> @@ -290,44 +288,25 @@ static void test_i440fx_pam(gconstpointer opaque)
>   */
>  static char *create_blob_file(void)
>  {
> -    int ret, fd;
> +    int i, fd;
>      char *pathname;
> -    GError *error = NULL;
> +    GError *error;
>

Bad change, please keep "error = NULL".

+    g_autofree uint8_t *buf = g_malloc(BLOB_SIZE);
>
> -    ret = -1;
> +    error = NULL;
>

Not necessary then


>      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;
> +    error = NULL;
>

Not necessary either.


> +    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 +377,6 @@ static void request_pflash(FirmwareTestFixture
> *fixture,
>      fixture->is_bios = false;
>  }
>
> -#endif /* _WIN32 */
> -
>  int main(int argc, char **argv)
>  {
>      TestData data;
> @@ -410,10 +387,8 @@ int main(int argc, char **argv)
>
>      qtest_add_data_func("i440fx/defaults", &data, test_i440fx_defaults);
>      qtest_add_data_func("i440fx/pam", &data, test_i440fx_pam);
> -#ifndef _WIN32
>      add_firmware_test("i440fx/firmware/bios", request_bios);
>      add_firmware_test("i440fx/firmware/pflash", request_pflash);
> -#endif
>
>      return g_test_run();
>  }
> --
> 2.34.1
>
>
>

-- 
Marc-André Lureau

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

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

* Re: [PATCH v2 03/39] block: Unify the get_tmp_filename() implementation
  2022-09-20 10:31 ` [PATCH v2 03/39] block: Unify the get_tmp_filename() implementation Bin Meng
@ 2022-09-22 19:38   ` Marc-André Lureau
  2022-09-24  8:09     ` Bin Meng
  0 siblings, 1 reply; 87+ messages in thread
From: Marc-André Lureau @ 2022-09-22 19:38 UTC (permalink / raw)
  To: Bin Meng; +Cc: qemu-devel, Bin Meng, Hanna Reitz, Kevin Wolf, qemu-block

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

Hi

On Tue, Sep 20, 2022 at 2:17 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Bin Meng <bin.meng@windriver.com>
>
> At present get_tmp_filename() has platform specific implementations
> to get the directory to use for temporary files. Switch over to use
> g_get_tmp_dir() which works on all supported platforms.
>
>
As discussed in v1, there are other things to do while touching this code.
And since it is optional for the series goal, please send this as a
different patch/series.



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

-- 
Marc-André Lureau

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

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

* Re: [PATCH v2 07/39] tests: Avoid using hardcoded /tmp in test cases
  2022-09-20 10:31 ` [PATCH v2 07/39] tests: Avoid using hardcoded /tmp in test cases Bin Meng
@ 2022-09-22 19:46   ` Marc-André Lureau
  2022-09-23  4:43     ` Markus Armbruster
  0 siblings, 1 reply; 87+ messages in thread
From: Marc-André Lureau @ 2022-09-22 19:46 UTC (permalink / raw)
  To: Bin Meng
  Cc: qemu-devel, Bin Meng, Alexander Bulekov, Andrew Jeffery,
	Bandan Das, Coiby Xu, Cédric Le Goater, Darren Kenny,
	Dr. David Alan Gilbert, Fam Zheng, Joel Stanley, John Snow,
	Juan Quintela, Konstantin Kostiuk, Laurent Vivier,
	Markus Armbruster, Michael Roth, Paolo Bonzini, Peter Maydell,
	Qiuhao Li, Stefan Hajnoczi, Thomas Huth, qemu-arm, qemu-block

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

Hi

On Tue, Sep 20, 2022 at 2:47 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Bin Meng <bin.meng@windriver.com>
>
> Lots of test cases were written to use hardcoded /tmp directory for
> temporary files. To avoid this, we update them to use g_dir_make_tmp()
> or g_file_open_tmp() when appropriate.
>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
>
> Changes in v2:
> - Use g_dir_make_tmp(), g_file_open_tmp() when appropriate
>
>  tests/qtest/fuzz/generic_fuzz_configs.h |  4 ++--
>  tests/qtest/ahci-test.c                 | 19 +++++++++++--------
>  tests/qtest/aspeed_smc-test.c           |  5 ++---
>  tests/qtest/boot-serial-test.c          |  9 +++++----
>  tests/qtest/cxl-test.c                  | 15 ++++++---------
>  tests/qtest/fdc-test.c                  |  5 +++--
>  tests/qtest/fuzz/virtio_blk_fuzz.c      |  4 ++--
>  tests/qtest/hd-geo-test.c               | 24 +++++++++++-------------
>  tests/qtest/ide-test.c                  | 10 ++++++----
>  tests/qtest/libqtest.c                  | 12 ++++++++----
>  tests/qtest/migration-test.c            |  7 ++++---
>  tests/qtest/pflash-cfi02-test.c         |  8 +++++---
>  tests/qtest/qmp-test.c                  |  6 ++++--
>  tests/qtest/vhost-user-blk-test.c       |  3 ++-
>  tests/qtest/vhost-user-test.c           |  8 ++++----
>  tests/qtest/virtio-blk-test.c           |  4 ++--
>  tests/qtest/virtio-scsi-test.c          |  4 ++--
>  tests/unit/test-image-locking.c         |  8 ++++----
>  tests/unit/test-qga.c                   |  2 +-
>  tests/vhost-user-bridge.c               |  3 +--
>  20 files changed, 85 insertions(+), 75 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 "
> diff --git a/tests/qtest/ahci-test.c b/tests/qtest/ahci-test.c
> index f1e510b0ac..00524f14c6 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;
>

Whenever introducing g_auto* usage, please make sure to initialize the
variable to NULL or a correct value.

     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;
>  }
> diff --git a/tests/qtest/aspeed_smc-test.c b/tests/qtest/aspeed_smc-test.c
> index 05ce941566..5e16b5c9a5 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;
>      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);
> diff --git a/tests/qtest/boot-serial-test.c
> b/tests/qtest/boot-serial-test.c
> index 2f99d71cab..ce6e3d3eb8 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;
> +    char *codetmp;
>      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);
> @@ -264,6 +264,7 @@ static void test_machine(const void *data)
>                        serialtmp, test->extra);
>      if (code) {
>          unlink(codetmp);
> +        g_free(codetmp);
>      }
>
>      if (!check_guest_output(qts, test, ser_fd)) {
> diff --git a/tests/qtest/cxl-test.c b/tests/qtest/cxl-test.c
> index 2e14da7dee..4f3ea76fa3 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;
>
> -    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;
>
> -    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;
>
> -    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,
> 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;
>  }
> 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);
> diff --git a/tests/qtest/hd-geo-test.c b/tests/qtest/hd-geo-test.c
> index 413cf964c0..4793954c19 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;
>

Why not use g_auto here?

You'll need to replace "return template" with "return
g_steal_pointer(&template)")

I suggest splitting this patch for the various tests.


>      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;
> +    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]);
>          }
>      }
>
> 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;
>  }
> diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
> index 7c9fc07de4..a0f28ddf8e 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;
> +    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);
> diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
> index 55892b3798..9925691ead 100644
> --- a/tests/qtest/migration-test.c
> +++ b/tests/qtest/migration-test.c
> @@ -2435,7 +2435,6 @@ static bool kvm_dirty_ring_supported(void)
>
>  int main(int argc, char **argv)
>  {
> -    char template[] = "/tmp/migration-test-XXXXXX";
>      const bool has_kvm = qtest_has_accel("kvm");
>      const bool has_uffd = ufd_version_check();
>      const char *arch = qtest_get_arch();
> @@ -2463,9 +2462,10 @@ int main(int argc, char **argv)
>          return g_test_run();
>      }
>
> -    tmpfs = g_mkdtemp(template);
> +    tmpfs = g_dir_make_tmp("migration-test-XXXXXX", NULL);
>      if (!tmpfs) {
> -        g_test_message("g_mkdtemp on path (%s): %s", template,
> strerror(errno));
> +        g_test_message("g_dir_make_tmp on path (%s): %s", tmpfs,
> +                       strerror(errno));
>      }
>      g_assert(tmpfs);
>
> @@ -2590,6 +2590,7 @@ int main(int argc, char **argv)
>          g_test_message("unable to rmdir: path (%s): %s",
>                         tmpfs, strerror(errno));
>      }
> +    g_free((gpointer)tmpfs);
>
>      return ret;
>  }
> diff --git a/tests/qtest/pflash-cfi02-test.c
> b/tests/qtest/pflash-cfi02-test.c
> index 7fce614b64..55890b7d95 100644
> --- a/tests/qtest/pflash-cfi02-test.c
> +++ b/tests/qtest/pflash-cfi02-test.c
> @@ -56,7 +56,7 @@ typedef struct {
>      QTestState *qtest;
>  } FlashConfig;
>
> -static char image_path[] = "/tmp/qtest.XXXXXX";
> +static char *image_path;
>
>  /*
>   * The pflash implementation allows some parameters to be unspecified. We
> want
> @@ -608,6 +608,7 @@ static void test_cfi_in_autoselect(const void *opaque)
>  static void cleanup(void *opaque)
>  {
>      unlink(image_path);
> +    g_free(image_path);
>  }
>
>  /*
> @@ -635,16 +636,17 @@ static const FlashConfig configuration[] = {
>
>  int main(int argc, char **argv)
>  {
> -    int fd = mkstemp(image_path);
> +    int fd = g_file_open_tmp("qtest.XXXXXX", &image_path, NULL);
>      if (fd == -1) {
>          g_printerr("Failed to create temporary file %s: %s\n", image_path,
>                     strerror(errno));
> +        g_free(image_path);
>          exit(EXIT_FAILURE);
>      }
>      if (ftruncate(fd, UNIFORM_FLASH_SIZE) < 0) {
>          int error_code = errno;
>          close(fd);
> -        unlink(image_path);
> +        cleanup(NULL);
>          g_printerr("Failed to truncate file %s to %u MB: %s\n",
> image_path,
>                     UNIFORM_FLASH_SIZE, strerror(error_code));
>          exit(EXIT_FAILURE);
> diff --git a/tests/qtest/qmp-test.c b/tests/qtest/qmp-test.c
> index bf7304c7dc..0fa00c12dc 100644
> --- a/tests/qtest/qmp-test.c
> +++ b/tests/qtest/qmp-test.c
> @@ -161,12 +161,13 @@ static void test_qmp_protocol(void)
>
>  /* Out-of-band tests */
>
> -char tmpdir[] = "/tmp/qmp-test-XXXXXX";
> +char *tmpdir;
>  char *fifo_name;
>
>  static void setup_blocking_cmd(void)
>  {
> -    if (!g_mkdtemp(tmpdir)) {
> +    tmpdir = g_dir_make_tmp("qmp-test-XXXXXX", NULL);
> +    if (!tmpdir) {
>          g_error("g_mkdtemp: %s", strerror(errno));
>      }
>      fifo_name = g_strdup_printf("%s/fifo", tmpdir);
> @@ -179,6 +180,7 @@ static void cleanup_blocking_cmd(void)
>  {
>      unlink(fifo_name);
>      rmdir(tmpdir);
> +    g_free(tmpdir);
>  }
>
>  static void send_cmd_that_blocks(QTestState *s, const char *id)
> diff --git a/tests/qtest/vhost-user-blk-test.c
> b/tests/qtest/vhost-user-blk-test.c
> index a81c2a2715..07a4c2d500 100644
> --- a/tests/qtest/vhost-user-blk-test.c
> +++ b/tests/qtest/vhost-user-blk-test.c
> @@ -841,7 +841,8 @@ static char *create_listen_socket(int *fd)
>      char *path;
>
>      /* No race because our pid makes the path unique */
> -    path = g_strdup_printf("/tmp/qtest-%d-sock.XXXXXX", getpid());
> +    path = g_strdup_printf("%s/qtest-%d-sock.XXXXXX",
> +                           g_get_tmp_dir(), getpid());
>      tmp_fd = mkstemp(path);
>      g_assert_cmpint(tmp_fd, >=, 0);
>      close(tmp_fd);
> diff --git a/tests/qtest/vhost-user-test.c b/tests/qtest/vhost-user-test.c
> index d7d6cfc9bd..4e1aae1794 100644
> --- a/tests/qtest/vhost-user-test.c
> +++ b/tests/qtest/vhost-user-test.c
> @@ -482,8 +482,7 @@ static TestServer *test_server_new(const gchar *name,
>          struct vhost_user_ops *ops)
>  {
>      TestServer *server = g_new0(TestServer, 1);
> -    char template[] = "/tmp/vhost-test-XXXXXX";
> -    const char *tmpfs;
> +    g_autofree const char *tmpfs;
>
>      server->context = g_main_context_new();
>      server->loop = g_main_loop_new(server->context, FALSE);
> @@ -491,9 +490,10 @@ static TestServer *test_server_new(const gchar *name,
>      /* run the main loop thread so the chardev may operate */
>      server->thread = g_thread_new(NULL, thread_function, server->loop);
>
> -    tmpfs = g_mkdtemp(template);
> +    tmpfs = g_dir_make_tmp("vhost-test-XXXXXX", NULL);
>      if (!tmpfs) {
> -        g_test_message("g_mkdtemp on path (%s): %s", template,
> strerror(errno));
> +        g_test_message("g_dir_make_tmp on path (%s): %s", tmpfs,
> +                       strerror(errno));
>      }
>      g_assert(tmpfs);
>
> 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);
> diff --git a/tests/qtest/virtio-scsi-test.c
> b/tests/qtest/virtio-scsi-test.c
> index 8ceb12aacd..073a89d535 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;
>      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);
>
> diff --git a/tests/unit/test-image-locking.c
> b/tests/unit/test-image-locking.c
> index ba057bd66c..d09ff43fcb 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;
>      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;
>      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;
> diff --git a/tests/unit/test-qga.c b/tests/unit/test-qga.c
> index a05a4628ed..b73d231cd5 100644
> --- a/tests/unit/test-qga.c
> +++ b/tests/unit/test-qga.c
> @@ -59,7 +59,7 @@ fixture_setup(TestFixture *fixture, gconstpointer data,
> gchar **envp)
>
>      fixture->loop = g_main_loop_new(NULL, FALSE);
>
> -    fixture->test_dir = g_strdup("/tmp/qgatest.XXXXXX");
> +    fixture->test_dir = g_strdup_printf("%s/qgatest.XXXXXX",
> g_get_tmp_dir());
>      g_assert_nonnull(g_mkdtemp(fixture->test_dir));
>
>      path = g_build_filename(fixture->test_dir, "sock", NULL);
> diff --git a/tests/vhost-user-bridge.c b/tests/vhost-user-bridge.c
> index 9b1dab2f28..fecdf915e7 100644
> --- a/tests/vhost-user-bridge.c
> +++ b/tests/vhost-user-bridge.c
> @@ -631,7 +631,6 @@ static void *notifier_thread(void *arg)
>  static void
>  vubr_host_notifier_setup(VubrDev *dev)
>  {
> -    char template[] = "/tmp/vubr-XXXXXX";
>      pthread_t thread;
>      size_t length;
>      void *addr;
> @@ -639,7 +638,7 @@ vubr_host_notifier_setup(VubrDev *dev)
>
>      length = qemu_real_host_page_size() * VHOST_USER_BRIDGE_MAX_QUEUES;
>
> -    fd = mkstemp(template);
> +    fd = g_file_open_tmp("vubr-XXXXXX", NULL, NULL);
>      if (fd < 0) {
>          vubr_die("mkstemp()");
>      }
> --
> 2.34.1
>
>
>

-- 
Marc-André Lureau

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

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

* Re: [PATCH v2 08/39] block/vvfat: Unify the mkdir() call
  2022-09-20 10:31 ` [PATCH v2 08/39] block/vvfat: Unify the mkdir() call Bin Meng
@ 2022-09-22 19:47   ` Marc-André Lureau
  0 siblings, 0 replies; 87+ messages in thread
From: Marc-André Lureau @ 2022-09-22 19:47 UTC (permalink / raw)
  To: Bin Meng; +Cc: qemu-devel, Bin Meng, Hanna Reitz, Kevin Wolf, qemu-block

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

On Tue, Sep 20, 2022 at 2:58 PM Bin Meng <bmeng.cn@gmail.com> wrote:

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

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


> ---
>
> Changes in v2:
> - Change to use g_mkdir()
>
>  block/vvfat.c | 9 +++------
>  1 file changed, 3 insertions(+), 6 deletions(-)
>
> diff --git a/block/vvfat.c b/block/vvfat.c
> index d6dd919683..723beef025 100644
> --- a/block/vvfat.c
> +++ b/block/vvfat.c
> @@ -25,6 +25,7 @@
>
>  #include "qemu/osdep.h"
>  #include <dirent.h>
> +#include <glib/gstdio.h>
>  #include "qapi/error.h"
>  #include "block/block_int.h"
>  #include "block/qdict.h"
> @@ -2726,13 +2727,9 @@ static int
> handle_renames_and_mkdirs(BDRVVVFATState* s)
>              mapping_t* mapping;
>              int j, parent_path_len;
>
> -#ifdef __MINGW32__
> -            if (mkdir(commit->path))
> +            if (g_mkdir(commit->path, 0755)) {
>                  return -5;
> -#else
> -            if (mkdir(commit->path, 0755))
> -                return -5;
> -#endif
> +            }
>
>              mapping = insert_mapping(s, commit->param.mkdir.cluster,
>                      commit->param.mkdir.cluster + 1);
> --
> 2.34.1
>
>
>

-- 
Marc-André Lureau

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

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

* Re: [PATCH v2 16/39] tests/qtest: Use send/recv for socket communication
  2022-09-20 10:31 ` [PATCH v2 16/39] tests/qtest: Use send/recv for socket communication Bin Meng
@ 2022-09-22 19:52   ` Marc-André Lureau
  0 siblings, 0 replies; 87+ messages in thread
From: Marc-André Lureau @ 2022-09-22 19:52 UTC (permalink / raw)
  To: Bin Meng
  Cc: qemu-devel, Xuzhou Cheng, Bin Meng, Daniel P. Berrangé,
	Laurent Vivier, Paolo Bonzini, Thomas Huth

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

On Tue, Sep 20, 2022 at 2:23 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Xuzhou Cheng <xuzhou.cheng@windriver.com>
>
> Socket communication in the libqtest and libqmp codes uses read()
> and write() which work on any file descriptor on *nix, and sockets
> in *nix are an example of a file descriptor.
>
> However sockets on Windows do not use *nix-style file descriptors,
> so read() and write() cannot be used on sockets on Windows.
> Switch over to use send() and recv() instead which work on both
> Windows and *nix.
>
> Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
>

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


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

-- 
Marc-André Lureau

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

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

* Re: [PATCH v2 18/39] tests/qtest: libqtest: Install signal handler via signal()
  2022-09-20 10:31 ` [PATCH v2 18/39] tests/qtest: libqtest: Install signal handler via signal() Bin Meng
@ 2022-09-22 19:55   ` Marc-André Lureau
  2022-09-23 17:54     ` Thomas Huth
  0 siblings, 1 reply; 87+ messages in thread
From: Marc-André Lureau @ 2022-09-22 19:55 UTC (permalink / raw)
  To: Bin Meng; +Cc: qemu-devel, Bin Meng, Laurent Vivier, Paolo Bonzini, Thomas Huth

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

Hi

On Tue, Sep 20, 2022 at 2:32 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Bin Meng <bin.meng@windriver.com>
>
> At present the codes uses sigaction() to install signal handler with
> a flag SA_RESETHAND. Such usage can be covered by the signal() API
> that is a simplified interface to the general sigaction() facility.
>
> Update to use signal() to install the signal handler, as it is
> available on Windows which we are going to support.
>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
>
> (no changes since v1)
>
>  tests/qtest/libqtest.c | 14 +++-----------
>  1 file changed, 3 insertions(+), 11 deletions(-)
>
> diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
> index 8b804faade..f46a21fa45 100644
> --- a/tests/qtest/libqtest.c
> +++ b/tests/qtest/libqtest.c
> @@ -66,7 +66,7 @@ struct QTestState
>  };
>
>  static GHookList abrt_hooks;
> -static struct sigaction sigact_old;
> +static sighandler_t sighandler_old;
>
>  static int qtest_query_target_endianness(QTestState *s);
>
> @@ -179,20 +179,12 @@ static void sigabrt_handler(int signo)
>
>  static void setup_sigabrt_handler(void)
>  {
> -    struct sigaction sigact;
> -
> -    /* Catch SIGABRT to clean up on g_assert() failure */
> -    sigact = (struct sigaction){
> -        .sa_handler = sigabrt_handler,
> -        .sa_flags = SA_RESETHAND,
> -    };
> -    sigemptyset(&sigact.sa_mask);
> -    sigaction(SIGABRT, &sigact, &sigact_old);
> +    sighandler_old = signal(SIGABRT, sigabrt_handler);
>  }
>
>  static void cleanup_sigabrt_handler(void)
>  {
> -    sigaction(SIGABRT, &sigact_old, NULL);
> +    signal(SIGABRT, sighandler_old);
>

I would rather make the usage of signal() specific to WIN32, but it's up to
the maintainers to decide what's best.

Thomas, Laurent, opinions?


-- 
Marc-André Lureau

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

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

* Re: [PATCH v2 19/39] tests/qtest: Support libqtest to build and run on Windows
  2022-09-20 10:31 ` [PATCH v2 19/39] tests/qtest: Support libqtest to build and run on Windows Bin Meng
@ 2022-09-22 19:59   ` Marc-André Lureau
  0 siblings, 0 replies; 87+ messages in thread
From: Marc-André Lureau @ 2022-09-22 19:59 UTC (permalink / raw)
  To: Bin Meng
  Cc: qemu-devel, Bin Meng, Xuzhou Cheng, Laurent Vivier,
	Paolo Bonzini, Thomas Huth

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

Hi

On Tue, Sep 20, 2022 at 1:36 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Bin Meng <bin.meng@windriver.com>
>
> At present the libqtest codes were written to depend on several
> POSIX APIs, including fork(), kill() and waitpid(). Unfortunately
> these APIs are not available on Windows.
>
> This commit implements the corresponding functionalities using
> win32 native APIs. With this change, all qtest cases can build
> successfully on a Windows host, and we can start qtest testing
> on Windows now.
>
> Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
>

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


> ---
>
> Changes in v2:
> - Move the enabling of building qtests on Windows to a separate
>   patch to keep bisectablity
> - Call socket_init() unconditionally
> - Add a missing CloseHandle() call
>
>  tests/qtest/libqtest.c | 98 +++++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 96 insertions(+), 2 deletions(-)
>
> diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
> index f46a21fa45..5d15e39289 100644
> --- a/tests/qtest/libqtest.c
> +++ b/tests/qtest/libqtest.c
> @@ -16,9 +16,11 @@
>
>  #include "qemu/osdep.h"
>
> +#ifndef _WIN32
>  #include <sys/socket.h>
>  #include <sys/wait.h>
>  #include <sys/un.h>
> +#endif /* _WIN32 */
>  #ifdef __linux__
>  #include <sys/prctl.h>
>  #endif /* __linux__ */
> @@ -27,6 +29,7 @@
>  #include "libqmp.h"
>  #include "qemu/ctype.h"
>  #include "qemu/cutils.h"
> +#include "qemu/sockets.h"
>  #include "qapi/qmp/qdict.h"
>  #include "qapi/qmp/qjson.h"
>  #include "qapi/qmp/qlist.h"
> @@ -35,6 +38,16 @@
>  #define MAX_IRQ 256
>  #define SOCKET_TIMEOUT 50
>
> +#ifndef _WIN32
> +# define CMD_EXEC   "exec "
> +# define DEV_STDERR "/dev/fd/2"
> +# define DEV_NULL   "/dev/null"
> +#else
> +# define CMD_EXEC   ""
> +# define DEV_STDERR "2"
> +# define DEV_NULL   "nul"
> +#endif
> +
>  typedef void (*QTestSendFn)(QTestState *s, const char *buf);
>  typedef void (*ExternalSendFn)(void *s, const char *buf);
>  typedef GString* (*QTestRecvFn)(QTestState *);
> @@ -66,6 +79,9 @@ struct QTestState
>  };
>
>  static GHookList abrt_hooks;
> +#ifdef _WIN32
> +typedef void (*sighandler_t)(int);
> +#endif
>  static sighandler_t sighandler_old;
>
>  static int qtest_query_target_endianness(QTestState *s);
> @@ -118,10 +134,19 @@ bool qtest_probe_child(QTestState *s)
>      pid_t pid = s->qemu_pid;
>
>      if (pid != -1) {
> +#ifndef _WIN32
>          pid = waitpid(pid, &s->wstatus, WNOHANG);
>          if (pid == 0) {
>              return true;
>          }
> +#else
> +        DWORD exit_code;
> +        GetExitCodeProcess((HANDLE)pid, &exit_code);
> +        if (exit_code == STILL_ACTIVE) {
> +            return true;
> +        }
> +        CloseHandle((HANDLE)pid);
> +#endif
>          s->qemu_pid = -1;
>      }
>      return false;
> @@ -135,13 +160,23 @@ void qtest_set_expected_status(QTestState *s, int
> status)
>  void qtest_kill_qemu(QTestState *s)
>  {
>      pid_t pid = s->qemu_pid;
> +#ifndef _WIN32
>      int wstatus;
> +#else
> +    DWORD ret, exit_code;
> +#endif
>
>      /* Skip wait if qtest_probe_child already reaped.  */
>      if (pid != -1) {
> +#ifndef _WIN32
>          kill(pid, SIGTERM);
>          TFR(pid = waitpid(s->qemu_pid, &s->wstatus, 0));
>          assert(pid == s->qemu_pid);
> +#else
> +        TerminateProcess((HANDLE)pid, s->expected_status);
> +        ret = WaitForSingleObject((HANDLE)pid, INFINITE);
> +        assert(ret == WAIT_OBJECT_0);
> +#endif
>          s->qemu_pid = -1;
>      }
>
> @@ -149,6 +184,7 @@ void qtest_kill_qemu(QTestState *s)
>       * Check whether qemu exited with expected exit status; anything else
> is
>       * fishy and should be logged with as much detail as possible.
>       */
> +#ifndef _WIN32
>      wstatus = s->wstatus;
>      if (WIFEXITED(wstatus) && WEXITSTATUS(wstatus) != s->expected_status)
> {
>          fprintf(stderr, "%s:%d: kill_qemu() tried to terminate QEMU "
> @@ -165,6 +201,16 @@ void qtest_kill_qemu(QTestState *s)
>                  __FILE__, __LINE__, sig, signame, dump);
>          abort();
>      }
> +#else
> +    GetExitCodeProcess((HANDLE)pid, &exit_code);
> +    CloseHandle((HANDLE)pid);
> +    if (exit_code != s->expected_status) {
> +        fprintf(stderr, "%s:%d: kill_qemu() tried to terminate QEMU "
> +                "process but encountered exit status %ld (expected %d)\n",
> +                __FILE__, __LINE__, exit_code, s->expected_status);
> +        abort();
> +    }
> +#endif
>  }
>
>  static void kill_qemu_hook_func(void *s)
> @@ -243,6 +289,38 @@ static const char *qtest_qemu_binary(void)
>      return qemu_bin;
>  }
>
> +#ifdef _WIN32
> +static pid_t qtest_create_process(char *cmd)
> +{
> +    STARTUPINFO si;
> +    PROCESS_INFORMATION pi;
> +    BOOL ret;
> +
> +    ZeroMemory(&si, sizeof(si));
> +    si.cb = sizeof(si);
> +    ZeroMemory(&pi, sizeof(pi));
> +
> +    ret = CreateProcess(NULL,   /* module name */
> +                        cmd,    /* command line */
> +                        NULL,   /* process handle not inheritable */
> +                        NULL,   /* thread handle not inheritable */
> +                        FALSE,  /* set handle inheritance to FALSE */
> +                        0,      /* No creation flags */
> +                        NULL,   /* use parent's environment block */
> +                        NULL,   /* use parent's starting directory */
> +                        &si,    /* pointer to STARTUPINFO structure */
> +                        &pi     /* pointer to PROCESS_INFORMATION
> structure */
> +                        );
> +    if (ret == 0) {
> +        fprintf(stderr, "%s:%d: unable to create a new process (%s)\n",
> +                __FILE__, __LINE__, strerror(GetLastError()));
> +        abort();
> +    }
> +
> +    return (pid_t)pi.hProcess;
> +}
> +#endif /* _WIN32 */
> +
>  QTestState *qtest_init_without_qmp_handshake(const char *extra_args)
>  {
>      QTestState *s;
> @@ -270,6 +348,7 @@ QTestState *qtest_init_without_qmp_handshake(const
> char *extra_args)
>      unlink(socket_path);
>      unlink(qmp_socket_path);
>
> +    socket_init();
>      sock = init_socket(socket_path);
>      qmpsock = init_socket(qmp_socket_path);
>
> @@ -278,7 +357,7 @@ QTestState *qtest_init_without_qmp_handshake(const
> char *extra_args)
>
>      qtest_add_abrt_handler(kill_qemu_hook_func, s);
>
> -    command = g_strdup_printf("exec %s %s"
> +    command = g_strdup_printf(CMD_EXEC "%s %s"
>                                "-qtest unix:%s "
>                                "-qtest-log %s "
>                                "-chardev socket,path=%s,id=char0 "
> @@ -287,7 +366,7 @@ QTestState *qtest_init_without_qmp_handshake(const
> char *extra_args)
>                                "%s"
>                                " -accel qtest",
>                                qemu_binary, tracearg, socket_path,
> -                              getenv("QTEST_LOG") ? "/dev/fd/2" :
> "/dev/null",
> +                              getenv("QTEST_LOG") ? DEV_STDERR : DEV_NULL,
>                                qmp_socket_path,
>                                extra_args ?: "");
>
> @@ -296,6 +375,7 @@ QTestState *qtest_init_without_qmp_handshake(const
> char *extra_args)
>      s->pending_events = NULL;
>      s->wstatus = 0;
>      s->expected_status = 0;
> +#ifndef _WIN32
>      s->qemu_pid = fork();
>      if (s->qemu_pid == 0) {
>  #ifdef __linux__
> @@ -318,6 +398,9 @@ QTestState *qtest_init_without_qmp_handshake(const
> char *extra_args)
>          execlp("/bin/sh", "sh", "-c", command, NULL);
>          exit(1);
>      }
> +#else
> +    s->qemu_pid = qtest_create_process(command);
> +#endif /* _WIN32 */
>
>      g_free(command);
>      s->fd = socket_accept(sock);
> @@ -336,9 +419,19 @@ QTestState *qtest_init_without_qmp_handshake(const
> char *extra_args)
>          s->irq_level[i] = false;
>      }
>
> +    /*
> +     * Stopping QEMU for debugging is not supported on Windows.
> +     *
> +     * Using DebugActiveProcess() API can suspend the QEMU process,
> +     * but gdb cannot attach to the process. Using the undocumented
> +     * NtSuspendProcess() can suspend the QEMU process and gdb can
> +     * attach to the process, but gdb cannot resume it.
> +     */
> +#ifndef _WIN32
>      if (getenv("QTEST_STOP")) {
>          kill(s->qemu_pid, SIGSTOP);
>      }
> +#endif
>
>      /* ask endianness of the target */
>
> @@ -392,6 +485,7 @@ QTestState *qtest_init_with_serial(const char
> *extra_args, int *sock_fd)
>      g_assert_true(sock_dir != NULL);
>      sock_path = g_strdup_printf("%s/sock", sock_dir);
>
> +    socket_init();
>      sock_fd_init = init_socket(sock_path);
>
>      qts = qtest_initf("-chardev socket,id=s0,path=%s -serial chardev:s0
> %s",
> --
> 2.34.1
>
>
>

-- 
Marc-André Lureau

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

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

* Re: [PATCH v2 20/39] tests/qtest: {ahci, ide}-test: Use relative path for temporary files for win32
  2022-09-20 10:31 ` [PATCH v2 20/39] tests/qtest: {ahci, ide}-test: Use relative path for temporary files for win32 Bin Meng
@ 2022-09-22 20:02   ` Marc-André Lureau
  2022-09-23 20:00     ` John Snow
  0 siblings, 1 reply; 87+ messages in thread
From: Marc-André Lureau @ 2022-09-22 20:02 UTC (permalink / raw)
  To: Bin Meng
  Cc: qemu-devel, Bin Meng, John Snow, Laurent Vivier, Paolo Bonzini,
	Thomas Huth, qemu-block

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

Hi

On Tue, Sep 20, 2022 at 1:50 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Bin Meng <bin.meng@windriver.com>
>
> These test cases uses "blkdebug:path/to/config:path/to/image" for
> testing. On Windows, absolute file paths contain the delimiter ':'
> which causes the blkdebug filename parser fail to parse filenames.
>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
>

I don't have a much better solution to propose at this point (to actually
use a temp directory), so:
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>


> ---
>
> (no changes since v1)
>
>  tests/qtest/ahci-test.c | 21 ++++++++++++++++++---
>  tests/qtest/ide-test.c  | 20 ++++++++++++++++++--
>  2 files changed, 36 insertions(+), 5 deletions(-)
>
> diff --git a/tests/qtest/ahci-test.c b/tests/qtest/ahci-test.c
> index 00524f14c6..c57576b08c 100644
> --- a/tests/qtest/ahci-test.c
> +++ b/tests/qtest/ahci-test.c
> @@ -1833,7 +1833,7 @@ static void create_ahci_io_test(enum IOMode type,
> enum AddrMode addr,
>
>  int main(int argc, char **argv)
>  {
> -    const char *arch;
> +    const char *arch, *base;
>      int ret;
>      int fd;
>      int c;
> @@ -1871,8 +1871,22 @@ int main(int argc, char **argv)
>          return 0;
>      }
>
> +    /*
> +     * "base" stores the starting point where we create temporary files.
> +     *
> +     * On Windows, this is set to the relative path of current working
> +     * directory, because the absolute path causes the blkdebug filename
> +     * parser fail to parse "blkdebug:path/to/config:path/to/image".
> +     */
> +#ifndef _WIN32
> +    base = g_get_tmp_dir();
> +#else
> +    base = ".";
> +#endif
> +
>      /* Create a temporary image */
> -    fd = g_file_open_tmp("qtest.XXXXXX", &tmp_path, NULL);
> +    tmp_path = g_strdup_printf("%s/qtest.XXXXXX", base);
> +    fd = g_mkstemp(tmp_path);
>      g_assert(fd >= 0);
>      if (have_qemu_img()) {
>          imgfmt = "qcow2";
> @@ -1889,7 +1903,8 @@ int main(int argc, char **argv)
>      close(fd);
>
>      /* Create temporary blkdebug instructions */
> -    fd = g_file_open_tmp("qtest-blkdebug.XXXXXX", &debug_path, NULL);
> +    debug_path = g_strdup_printf("%s/qtest-blkdebug.XXXXXX", base);
> +    fd = g_mkstemp(debug_path);
>      g_assert(fd >= 0);
>      close(fd);
>
> diff --git a/tests/qtest/ide-test.c b/tests/qtest/ide-test.c
> index 25302be6dc..5e3e28aea2 100644
> --- a/tests/qtest/ide-test.c
> +++ b/tests/qtest/ide-test.c
> @@ -1011,16 +1011,32 @@ static void test_cdrom_dma(void)
>
>  int main(int argc, char **argv)
>  {
> +    const char *base;
>      int fd;
>      int ret;
>
> +    /*
> +     * "base" stores the starting point where we create temporary files.
> +     *
> +     * On Windows, this is set to the relative path of current working
> +     * directory, because the absolute path causes the blkdebug filename
> +     * parser fail to parse "blkdebug:path/to/config:path/to/image".
> +     */
> +#ifndef _WIN32
> +    base = g_get_tmp_dir();
> +#else
> +    base = ".";
> +#endif
> +
>      /* Create temporary blkdebug instructions */
> -    fd = g_file_open_tmp("qtest-blkdebug.XXXXXX", &debug_path, NULL);
> +    debug_path = g_strdup_printf("%s/qtest-blkdebug.XXXXXX", base);
> +    fd = g_mkstemp(debug_path);
>      g_assert(fd >= 0);
>      close(fd);
>
>      /* Create a temporary raw image */
> -    fd = g_file_open_tmp("qtest.XXXXXX", &tmp_path, NULL);
> +    tmp_path = g_strdup_printf("%s/qtest.XXXXXX", base);
> +    fd = g_mkstemp(tmp_path);
>      g_assert(fd >= 0);
>      ret = ftruncate(fd, TEST_IMAGE_SIZE);
>      g_assert(ret == 0);
> --
> 2.34.1
>
>
>

-- 
Marc-André Lureau

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

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

* Re: [PATCH v2 22/39] tests/qtest: migration-test: Disable IO redirection for win32
  2022-09-20 10:31 ` [PATCH v2 22/39] tests/qtest: migration-test: Disable IO redirection " Bin Meng
@ 2022-09-22 20:04   ` Marc-André Lureau
  0 siblings, 0 replies; 87+ messages in thread
From: Marc-André Lureau @ 2022-09-22 20:04 UTC (permalink / raw)
  To: Bin Meng
  Cc: qemu-devel, Bin Meng, Dr. David Alan Gilbert, Juan Quintela,
	Laurent Vivier, Paolo Bonzini, Thomas Huth

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

On Tue, Sep 20, 2022 at 3:04 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Bin Meng <bin.meng@windriver.com>
>
> On Windows the QEMU executable is created via CreateProcess() and
> IO redirection does not work, so don't bother adding IO redirection
> to the command line.
>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
>
> Changes in v2:
> - Change the place that sets IO redirection in the command line
>

hmm ok,
Reviewed-by: Marc-André Lureau <marcandre.lureau@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 9925691ead..c87afad9e8 100644
> --- a/tests/qtest/migration-test.c
> +++ b/tests/qtest/migration-test.c
> @@ -648,7 +648,16 @@ static int test_migrate_start(QTestState **from,
> QTestState **to,
>      }
>
>      if (!getenv("QTEST_LOG") && args->hide_stderr) {
> +#ifndef _WIN32
>          ignore_stderr = "2>/dev/null";
> +#else
> +        /*
> +         * On Windows the QEMU executable is created via CreateProcess()
> and
> +         * IO redirection does not work, so don't bother adding IO
> redirection
> +         * to the command line.
> +         */
> +        ignore_stderr = "";
> +#endif
>      } else {
>          ignore_stderr = "";
>      }
> --
> 2.34.1
>
>
>

-- 
Marc-André Lureau

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

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

* Re: [PATCH v2 24/39] tests/qtest: virtio-net-failover: Disable migration tests for win32
  2022-09-20 10:31 ` [PATCH v2 24/39] tests/qtest: virtio-net-failover: Disable migration tests for win32 Bin Meng
@ 2022-09-22 20:05   ` Marc-André Lureau
  0 siblings, 0 replies; 87+ messages in thread
From: Marc-André Lureau @ 2022-09-22 20:05 UTC (permalink / raw)
  To: Bin Meng
  Cc: qemu-devel, Xuzhou Cheng, Bin Meng, Laurent Vivier,
	Paolo Bonzini, Thomas Huth

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

On Tue, Sep 20, 2022 at 3:28 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Xuzhou Cheng <xuzhou.cheng@windriver.com>
>
> These tests use the exec migration protocol, which is unsupported
> on Windows as of today. Disable these tests for now.
>
> Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
>

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


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

-- 
Marc-André Lureau

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

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

* Re: [PATCH v2 25/39] chardev/char-file: Add FILE_SHARE_WRITE when openning the file for win32
  2022-09-20 10:31 ` [PATCH v2 25/39] chardev/char-file: Add FILE_SHARE_WRITE when openning the file " Bin Meng
@ 2022-09-22 20:09   ` Marc-André Lureau
  2022-09-24  8:10     ` Bin Meng
  0 siblings, 1 reply; 87+ messages in thread
From: Marc-André Lureau @ 2022-09-22 20:09 UTC (permalink / raw)
  To: Bin Meng; +Cc: qemu-devel, Xuzhou Cheng, Bin Meng, Paolo Bonzini

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

Hi

On Tue, Sep 20, 2022 at 2:33 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Xuzhou Cheng <xuzhou.cheng@windriver.com>
>
> The combination of GENERIC_WRITE and FILE_SHARE_READ options does
> not allow the same file to be opened again by CreateFile() from
> another QEMU process with the same options when the previous QEMU
> process still holds the file handle opened.
>
> This was triggered by running the test_multifd_tcp_cancel() case on
> Windows, which cancels the migration, and launches another QEMU
> process to migrate with the same file opened for write. Chances are
> that the previous QEMU process does not quit before the new QEMU
> process runs hence the old one still holds the file handle that does
> not allow shared write permission then the new QEMU process will fail.
>
> As per [1] we should add FILE_SHARE_WRITE to the share mode to allow
> such use case. This change makes the behavior be consistent with the
> POSIX platforms.
>
> [1]
> https://docs.microsoft.com/en-us/windows/win32/fileio/creating-and-opening-files
>
> Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
>
> Changes in v2:
> - Update commit message to include the use case why we should set
>   FILE_SHARE_WRITE when openning the file for win32
>

As discussed in v1, I would rather leave that patch out of this series,
since the visible issue is solved differently elsewhere.

Also, I disagree with the approach to make windows behaviour consistent
with posix here, since I consider the windows behaviour (exclusive write
access) superior. I would rather teach the posix implementation about
exclusive write access.


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

-- 
Marc-André Lureau

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

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

* Re: [PATCH v2 33/39] io/channel-watch: Drop the unnecessary cast
  2022-09-20 10:31 ` [PATCH v2 33/39] io/channel-watch: Drop the unnecessary cast Bin Meng
@ 2022-09-22 20:13   ` Marc-André Lureau
  0 siblings, 0 replies; 87+ messages in thread
From: Marc-André Lureau @ 2022-09-22 20:13 UTC (permalink / raw)
  To: Bin Meng; +Cc: qemu-devel, Bin Meng, Daniel P. Berrangé

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

On Tue, Sep 20, 2022 at 2:56 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> From: Bin Meng <bin.meng@windriver.com>
>
> There is no need to do a type cast on ssource->socket as it is
> already declared as a SOCKET.
>
> Suggested-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
>

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

---
>
> Changes in v2:
> - new patch: "io/channel-watch: Drop the unnecessary cast"
>
>  io/channel-watch.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/io/channel-watch.c b/io/channel-watch.c
> index 89f3c8a88a..43d38494f7 100644
> --- a/io/channel-watch.c
> +++ b/io/channel-watch.c
> @@ -130,13 +130,13 @@ qio_channel_socket_source_check(GSource *source)
>      FD_ZERO(&wfds);
>      FD_ZERO(&xfds);
>      if (ssource->condition & G_IO_IN) {
> -        FD_SET((SOCKET)ssource->socket, &rfds);
> +        FD_SET(ssource->socket, &rfds);
>      }
>      if (ssource->condition & G_IO_OUT) {
> -        FD_SET((SOCKET)ssource->socket, &wfds);
> +        FD_SET(ssource->socket, &wfds);
>      }
>      if (ssource->condition & G_IO_PRI) {
> -        FD_SET((SOCKET)ssource->socket, &xfds);
> +        FD_SET(ssource->socket, &xfds);
>      }
>      ssource->revents = 0;
>      if (select(0, &rfds, &wfds, &xfds, &tv0) == 0) {
> --
> 2.34.1
>
>
>

-- 
Marc-André Lureau

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

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

* Re: [PATCH v2 35/39] tests/qtest: migration-test: Skip running some TLS cases for win32
  2022-09-20 10:31 ` [PATCH v2 35/39] tests/qtest: migration-test: Skip running some TLS cases for win32 Bin Meng
  2022-09-21 16:51   ` Dr. David Alan Gilbert
@ 2022-09-22 20:16   ` Marc-André Lureau
  1 sibling, 0 replies; 87+ messages in thread
From: Marc-André Lureau @ 2022-09-22 20:16 UTC (permalink / raw)
  To: Bin Meng
  Cc: qemu-devel, Bin Meng, Dr. David Alan Gilbert, Juan Quintela,
	Laurent Vivier, Paolo Bonzini, Thomas Huth

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

Hi

On Tue, Sep 20, 2022 at 3:11 PM Bin Meng <bmeng.cn@gmail.com> wrote:

> 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.
>
>
You might find a better solution for this issue with Daniel help,
nevertheless when disabling a test that can compile on the platform, please
prefer g_test_skip() usage instead. That way, we make sure the code still
compiles and we get some log in the tests :) thanks


> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
> I am not familar with the gnutls and simply enabling the gnutls debug
> output does not give me an immedidate hint on why it's failing on
> Windows. Disable these cases for now until someone or maintainers
> who may want to test this on Windows.
>
> (no changes since v1)
>
>  tests/qtest/migration-test.c | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
>
> diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
> index aedd9ddb72..dbee9b528a 100644
> --- a/tests/qtest/migration-test.c
> +++ b/tests/qtest/migration-test.c
> @@ -1403,6 +1403,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);
> @@ -1415,6 +1416,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)
> @@ -1523,6 +1525,7 @@ static void test_precopy_tcp_plain(void)
>  }
>
>  #ifdef CONFIG_GNUTLS
> +#ifndef _WIN32
>  static void test_precopy_tcp_tls_psk_match(void)
>  {
>      MigrateCommon args = {
> @@ -1533,6 +1536,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)
>  {
> @@ -1930,6 +1934,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)
> @@ -1937,6 +1942,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,
> @@ -1988,6 +1994,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 = {
> @@ -1997,6 +2004,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)
>  {
> @@ -2497,8 +2505,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) {
>          /*
> @@ -2524,8 +2534,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
> @@ -2569,8 +2581,10 @@ int main(int argc, char **argv)
>                     test_multifd_tcp_zstd);
>  #endif
>  #ifdef CONFIG_GNUTLS
> +#ifndef _WIN32
>      qtest_add_func("/migration/multifd/tcp/tls/psk/match",
>                     test_multifd_tcp_tls_psk_match);
> +#endif
>      qtest_add_func("/migration/multifd/tcp/tls/psk/mismatch",
>                     test_multifd_tcp_tls_psk_mismatch);
>  #ifdef CONFIG_TASN1
> --
> 2.34.1
>
>
>

-- 
Marc-André Lureau

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

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

* Re: [PATCH v2 38/39] tests/qtest: Enable qtest build on Windows
  2022-09-20 10:31 ` [PATCH v2 38/39] tests/qtest: Enable qtest build on Windows Bin Meng
@ 2022-09-22 20:18   ` Marc-André Lureau
  2022-09-24  8:13     ` Bin Meng
  0 siblings, 1 reply; 87+ messages in thread
From: Marc-André Lureau @ 2022-09-22 20:18 UTC (permalink / raw)
  To: Bin Meng; +Cc: qemu-devel, Bin Meng, Laurent Vivier, Paolo Bonzini, Thomas Huth

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

Hi

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

> From: Bin Meng <bin.meng@windriver.com>
>
> Now that we have fixed various test case issues as seen when running
> on Windows, let's enable the qtest build on Windows.
>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
>
> Changes in v2:
> - new patch: "tests/qtest: Enable qtest build on Windows"
>
>  tests/qtest/meson.build | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
> index 455f1bbb7e..ceab141824 100644
> --- a/tests/qtest/meson.build
> +++ b/tests/qtest/meson.build
> @@ -1,6 +1,5 @@
> -# All QTests for now are POSIX-only, but the dependencies are
> -# really in libqtest, not in the testcases themselves.
> -if not config_host.has_key('CONFIG_POSIX')
> +# Build all QTests for POSIX and Windows
> +if not config_host.has_key('CONFIG_POSIX') and not
> config_host.has_key('CONFIG_WIN32')
>    subdir_done()
>  endif
>

I wonder, but I suppose we can just remove the conditions. No?


-- 
Marc-André Lureau

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

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

* Re: [PATCH v2 01/39] tests: Change to use g_mkdir()
  2022-09-22 19:32   ` Marc-André Lureau
@ 2022-09-23  1:09     ` Bin Meng
  2022-09-23 18:02       ` Thomas Huth
  0 siblings, 1 reply; 87+ messages in thread
From: Bin Meng @ 2022-09-23  1:09 UTC (permalink / raw)
  To: Marc-André Lureau
  Cc: qemu-devel@nongnu.org Developers, Bin Meng,
	Daniel P. Berrangé,
	Dr. David Alan Gilbert, Juan Quintela, Laurent Vivier,
	Paolo Bonzini, Thomas Huth

On Fri, Sep 23, 2022 at 3:32 AM Marc-André Lureau
<marcandre.lureau@gmail.com> wrote:
>
> Hi
>
> On Tue, Sep 20, 2022 at 1:48 PM Bin Meng <bmeng.cn@gmail.com> wrote:
>>
>> From: Bin Meng <bin.meng@windriver.com>
>>
>> Commit 413bebc04603 ("tests: Use g_mkdir_with_parents()") replaces
>> the mkdir() call in the test codes with glib's g_mkdir_with_parents(),
>> but the exact portable replacement for mkdir() should be g_mkdir().
>>
>> I probably was misled by the GTK glib doc [1] before, thinking that
>> g_mkdir() is not a supported API from glib. But the glib sources do
>> not support this statement. It is probably that the GTK documentation
>> was not built to include all APIs.
>>
>> [1] https://docs.gtk.org/glib/?q=mkdir
>>
>> Fixes: 413bebc04603 ("tests: Use g_mkdir_with_parents()")
>> Signed-off-by: Bin Meng <bin.meng@windriver.com>
>
>
> I wouldn't bother anymore, I'd keep mkdir_with_parents for now. YMMV
>

Yep but some maintainers pointed out in other patches in v1 that
g_mkdir() is the strict replacement for mkdir() :)

@Thomas Huth Would you share your thoughts?

Regards,
Bin


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

* Re: [PATCH v2 07/39] tests: Avoid using hardcoded /tmp in test cases
  2022-09-22 19:46   ` Marc-André Lureau
@ 2022-09-23  4:43     ` Markus Armbruster
  0 siblings, 0 replies; 87+ messages in thread
From: Markus Armbruster @ 2022-09-23  4:43 UTC (permalink / raw)
  To: Marc-André Lureau
  Cc: Bin Meng, qemu-devel, Bin Meng, Alexander Bulekov,
	Andrew Jeffery, Bandan Das, Coiby Xu, Cédric Le Goater,
	Darren Kenny, Dr. David Alan Gilbert, Fam Zheng, Joel Stanley,
	John Snow, Juan Quintela, Konstantin Kostiuk, Laurent Vivier,
	Michael Roth, Paolo Bonzini, Peter Maydell, Qiuhao Li,
	Stefan Hajnoczi, Thomas Huth, qemu-arm, qemu-block

Marc-André Lureau <marcandre.lureau@gmail.com> writes:

> Hi
>
> On Tue, Sep 20, 2022 at 2:47 PM Bin Meng <bmeng.cn@gmail.com> wrote:
>
>> From: Bin Meng <bin.meng@windriver.com>
>>
>> Lots of test cases were written to use hardcoded /tmp directory for
>> temporary files. To avoid this, we update them to use g_dir_make_tmp()
>> or g_file_open_tmp() when appropriate.
>>
>> Signed-off-by: Bin Meng <bin.meng@windriver.com>
>> ---
>>
>> Changes in v2:
>> - Use g_dir_make_tmp(), g_file_open_tmp() when appropriate
>>
>>  tests/qtest/fuzz/generic_fuzz_configs.h |  4 ++--
>>  tests/qtest/ahci-test.c                 | 19 +++++++++++--------
>>  tests/qtest/aspeed_smc-test.c           |  5 ++---
>>  tests/qtest/boot-serial-test.c          |  9 +++++----
>>  tests/qtest/cxl-test.c                  | 15 ++++++---------
>>  tests/qtest/fdc-test.c                  |  5 +++--
>>  tests/qtest/fuzz/virtio_blk_fuzz.c      |  4 ++--
>>  tests/qtest/hd-geo-test.c               | 24 +++++++++++-------------
>>  tests/qtest/ide-test.c                  | 10 ++++++----
>>  tests/qtest/libqtest.c                  | 12 ++++++++----
>>  tests/qtest/migration-test.c            |  7 ++++---
>>  tests/qtest/pflash-cfi02-test.c         |  8 +++++---
>>  tests/qtest/qmp-test.c                  |  6 ++++--
>>  tests/qtest/vhost-user-blk-test.c       |  3 ++-
>>  tests/qtest/vhost-user-test.c           |  8 ++++----
>>  tests/qtest/virtio-blk-test.c           |  4 ++--
>>  tests/qtest/virtio-scsi-test.c          |  4 ++--
>>  tests/unit/test-image-locking.c         |  8 ++++----
>>  tests/unit/test-qga.c                   |  2 +-
>>  tests/vhost-user-bridge.c               |  3 +--
>>  20 files changed, 85 insertions(+), 75 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 "
>> diff --git a/tests/qtest/ahci-test.c b/tests/qtest/ahci-test.c
>> index f1e510b0ac..00524f14c6 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;
>>
>
> Whenever introducing g_auto* usage, please make sure to initialize the
> variable to NULL or a correct value.

Potential food for checkpatch.pl.

[...]



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

* Re: [PATCH v2 04/39] semihosting/arm-compat-semi: Avoid using hardcoded /tmp
  2022-09-20 10:31 ` [PATCH v2 04/39] semihosting/arm-compat-semi: Avoid using hardcoded /tmp Bin Meng
@ 2022-09-23 16:20   ` Alex Bennée
  0 siblings, 0 replies; 87+ messages in thread
From: Alex Bennée @ 2022-09-23 16:20 UTC (permalink / raw)
  To: Bin Meng; +Cc: qemu-devel, Bin Meng


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

> From: Bin Meng <bin.meng@windriver.com>
>
> Use g_get_tmp_dir() to get the directory to use for temporary files.
>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>

Reviewed-by: Alex Bennée <alex.bennee@linaro.org>

-- 
Alex Bennée


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

* Re: [PATCH v2 05/39] tcg: Avoid using hardcoded /tmp
  2022-09-20 10:31 ` [PATCH v2 05/39] tcg: " Bin Meng
@ 2022-09-23 16:20   ` Alex Bennée
  0 siblings, 0 replies; 87+ messages in thread
From: Alex Bennée @ 2022-09-23 16:20 UTC (permalink / raw)
  To: Bin Meng; +Cc: Bin Meng, Marc-André Lureau, Richard Henderson, qemu-devel


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

> From: Bin Meng <bin.meng@windriver.com>
>
> Use g_get_tmp_dir() to get the directory to use for temporary files.
>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>

Reviewed-by: Alex Bennée <alex.bennee@linaro.org>

-- 
Alex Bennée


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

* Re: [PATCH v2 36/39] .gitlab-ci.d/windows.yml: Increase the timeout to 90 minutes
  2022-09-20 10:31 ` [PATCH v2 36/39] .gitlab-ci.d/windows.yml: Increase the timeout to 90 minutes Bin Meng
@ 2022-09-23 16:22   ` Alex Bennée
  2022-09-23 17:50     ` Thomas Huth
  2022-09-24  1:13     ` Bin Meng
  0 siblings, 2 replies; 87+ messages in thread
From: Alex Bennée @ 2022-09-23 16:22 UTC (permalink / raw)
  To: Bin Meng
  Cc: qemu-devel, Bin Meng, Beraldo Leal, Philippe Mathieu-Daudé,
	Thomas Huth, Wainer dos Santos Moschetta


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

> From: Bin Meng <bin.meng@windriver.com>
>
> commit 9f8e6cad65a6 ("gitlab-ci: Speed up the msys2-64bit job by using --without-default-devices"
> changed to compile QEMU with the --without-default-devices switch for
> the msys2-64bit job, due to the build could not complete within the
> project timeout (1h), and also mentioned that a bigger timeout was
> getting ignored on the shared Gitlab-CI Windows runners.
>
> However as of today it seems the shared Gitlab-CI Windows runners does
> honor the job timeout, and the runner has the timeout limit of 2h, so
> let's increase the timeout to 90 minutes and drop the configure switch
> "--without-default-devices" to get a larger build coverage.

I'd like to push back lightly against increasing the time because it
lengthens the total run time before we can merge a branch. Ideally we
could come up with a combination of build and tests that exercises all
the Windows code without exhaustively testing code paths that are tested
elsewhere. For device emulation are there any host specific things we
are testing?


>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
>
> Changes in v2:
> - Change the timeout limit to 90 minutes
>
>  .gitlab-ci.d/windows.yml | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/.gitlab-ci.d/windows.yml b/.gitlab-ci.d/windows.yml
> index da6013904a..818676662a 100644
> --- a/.gitlab-ci.d/windows.yml
> +++ b/.gitlab-ci.d/windows.yml
> @@ -10,7 +10,7 @@
>        - ${CI_PROJECT_DIR}/msys64/var/cache
>    needs: []
>    stage: build
> -  timeout: 70m
> +  timeout: 90m
>    before_script:
>    - If ( !(Test-Path -Path msys64\var\cache ) ) {
>        mkdir msys64\var\cache
> @@ -59,7 +59,7 @@ msys2-64bit:
>    - $env:MSYSTEM = 'MINGW64'     # Start a 64 bit Mingw environment
>    - $env:MSYS = 'winsymlinks:native' # Enable native Windows symlink
>    - .\msys64\usr\bin\bash -lc './configure --target-list=x86_64-softmmu
> -      --enable-capstone --without-default-devices'
> +      --enable-capstone'
>    - .\msys64\usr\bin\bash -lc "sed -i '/^ROMS=/d' build/config-host.mak"
>    - .\msys64\usr\bin\bash -lc 'make'
>    - .\msys64\usr\bin\bash -lc 'make check'


-- 
Alex Bennée


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

* Re: [PATCH v2 36/39] .gitlab-ci.d/windows.yml: Increase the timeout to 90 minutes
  2022-09-23 16:22   ` Alex Bennée
@ 2022-09-23 17:50     ` Thomas Huth
  2022-09-24  1:13     ` Bin Meng
  1 sibling, 0 replies; 87+ messages in thread
From: Thomas Huth @ 2022-09-23 17:50 UTC (permalink / raw)
  To: Alex Bennée, Bin Meng
  Cc: qemu-devel, Bin Meng, Beraldo Leal, Philippe Mathieu-Daudé,
	Wainer dos Santos Moschetta

On 23/09/2022 18.22, Alex Bennée wrote:
> 
> Bin Meng <bmeng.cn@gmail.com> writes:
> 
>> From: Bin Meng <bin.meng@windriver.com>
>>
>> commit 9f8e6cad65a6 ("gitlab-ci: Speed up the msys2-64bit job by using --without-default-devices"
>> changed to compile QEMU with the --without-default-devices switch for
>> the msys2-64bit job, due to the build could not complete within the
>> project timeout (1h), and also mentioned that a bigger timeout was
>> getting ignored on the shared Gitlab-CI Windows runners.
>>
>> However as of today it seems the shared Gitlab-CI Windows runners does
>> honor the job timeout, and the runner has the timeout limit of 2h, so
>> let's increase the timeout to 90 minutes and drop the configure switch
>> "--without-default-devices" to get a larger build coverage.
> 
> I'd like to push back lightly against increasing the time because it
> lengthens the total run time before we can merge a branch. Ideally we
> could come up with a combination of build and tests that exercises all
> the Windows code without exhaustively testing code paths that are tested
> elsewhere. For device emulation are there any host specific things we
> are testing?

The problem is rather: With "--without-default-devices", make check is not 
working anymore since a lot of qtests expect certain devices to be around...

  Thomas



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

* Re: [PATCH v2 18/39] tests/qtest: libqtest: Install signal handler via signal()
  2022-09-22 19:55   ` Marc-André Lureau
@ 2022-09-23 17:54     ` Thomas Huth
  0 siblings, 0 replies; 87+ messages in thread
From: Thomas Huth @ 2022-09-23 17:54 UTC (permalink / raw)
  To: Marc-André Lureau, Bin Meng
  Cc: qemu-devel, Bin Meng, Laurent Vivier, Paolo Bonzini

On 22/09/2022 21.55, Marc-André Lureau wrote:
> Hi
> 
> On Tue, Sep 20, 2022 at 2:32 PM Bin Meng <bmeng.cn@gmail.com 
> <mailto:bmeng.cn@gmail.com>> wrote:
> 
>     From: Bin Meng <bin.meng@windriver.com <mailto:bin.meng@windriver.com>>
> 
>     At present the codes uses sigaction() to install signal handler with
>     a flag SA_RESETHAND. Such usage can be covered by the signal() API
>     that is a simplified interface to the general sigaction() facility.
> 
>     Update to use signal() to install the signal handler, as it is
>     available on Windows which we are going to support.
> 
>     Signed-off-by: Bin Meng <bin.meng@windriver.com
>     <mailto:bin.meng@windriver.com>>
>     ---
> 
>     (no changes since v1)
> 
>       tests/qtest/libqtest.c | 14 +++-----------
>       1 file changed, 3 insertions(+), 11 deletions(-)
> 
>     diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
>     index 8b804faade..f46a21fa45 100644
>     --- a/tests/qtest/libqtest.c
>     +++ b/tests/qtest/libqtest.c
>     @@ -66,7 +66,7 @@ struct QTestState
>       };
> 
>       static GHookList abrt_hooks;
>     -static struct sigaction sigact_old;
>     +static sighandler_t sighandler_old;
> 
>       static int qtest_query_target_endianness(QTestState *s);
> 
>     @@ -179,20 +179,12 @@ static void sigabrt_handler(int signo)
> 
>       static void setup_sigabrt_handler(void)
>       {
>     -    struct sigaction sigact;
>     -
>     -    /* Catch SIGABRT to clean up on g_assert() failure */
>     -    sigact = (struct sigaction){
>     -        .sa_handler = sigabrt_handler,
>     -        .sa_flags = SA_RESETHAND,
>     -    };
>     -    sigemptyset(&sigact.sa_mask);
>     -    sigaction(SIGABRT, &sigact, &sigact_old);
>     +    sighandler_old = signal(SIGABRT, sigabrt_handler);
>       }
> 
>       static void cleanup_sigabrt_handler(void)
>       {
>     -    sigaction(SIGABRT, &sigact_old, NULL);
>     +    signal(SIGABRT, sighandler_old);
> 
> 
> I would rather make the usage of signal() specific to WIN32, but it's up to 
> the maintainers to decide what's best.
> 
> Thomas, Laurent, opinions?

I don't mind much either way ... I'd say let's take this patch since it's 
already done and it avoids some #ifdefs in the code.

  Thomas




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

* Re: [PATCH v2 01/39] tests: Change to use g_mkdir()
  2022-09-23  1:09     ` Bin Meng
@ 2022-09-23 18:02       ` Thomas Huth
  2022-09-26  8:21         ` Daniel P. Berrangé
  0 siblings, 1 reply; 87+ messages in thread
From: Thomas Huth @ 2022-09-23 18:02 UTC (permalink / raw)
  To: Bin Meng, Marc-André Lureau
  Cc: qemu-devel@nongnu.org Developers, Bin Meng,
	Daniel P. Berrangé,
	Dr. David Alan Gilbert, Juan Quintela, Laurent Vivier,
	Paolo Bonzini

On 23/09/2022 03.09, Bin Meng wrote:
> On Fri, Sep 23, 2022 at 3:32 AM Marc-André Lureau
> <marcandre.lureau@gmail.com> wrote:
>>
>> Hi
>>
>> On Tue, Sep 20, 2022 at 1:48 PM Bin Meng <bmeng.cn@gmail.com> wrote:
>>>
>>> From: Bin Meng <bin.meng@windriver.com>
>>>
>>> Commit 413bebc04603 ("tests: Use g_mkdir_with_parents()") replaces
>>> the mkdir() call in the test codes with glib's g_mkdir_with_parents(),
>>> but the exact portable replacement for mkdir() should be g_mkdir().
>>>
>>> I probably was misled by the GTK glib doc [1] before, thinking that
>>> g_mkdir() is not a supported API from glib. But the glib sources do
>>> not support this statement. It is probably that the GTK documentation
>>> was not built to include all APIs.
>>>
>>> [1] https://docs.gtk.org/glib/?q=mkdir
>>>
>>> Fixes: 413bebc04603 ("tests: Use g_mkdir_with_parents()")
>>> Signed-off-by: Bin Meng <bin.meng@windriver.com>
>>
>>
>> I wouldn't bother anymore, I'd keep mkdir_with_parents for now. YMMV
>>
> 
> Yep but some maintainers pointed out in other patches in v1 that
> g_mkdir() is the strict replacement for mkdir() :)
> 
> @Thomas Huth Would you share your thoughts?

It's a little bit weird that g_mkdir() does not show up in the glib docs ... 
let's keep g_mkdir_with_parents(), that sounds like the better choice to me.

  Thomas



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

* Re: [PATCH v2 20/39] tests/qtest: {ahci, ide}-test: Use relative path for temporary files for win32
  2022-09-22 20:02   ` Marc-André Lureau
@ 2022-09-23 20:00     ` John Snow
  0 siblings, 0 replies; 87+ messages in thread
From: John Snow @ 2022-09-23 20:00 UTC (permalink / raw)
  To: Marc-André Lureau
  Cc: Bin Meng, qemu-devel, Bin Meng, Laurent Vivier, Paolo Bonzini,
	Thomas Huth, qemu-block

On Thu, Sep 22, 2022 at 4:03 PM Marc-André Lureau
<marcandre.lureau@gmail.com> wrote:
>
> Hi
>
> On Tue, Sep 20, 2022 at 1:50 PM Bin Meng <bmeng.cn@gmail.com> wrote:
>>
>> From: Bin Meng <bin.meng@windriver.com>
>>
>> These test cases uses "blkdebug:path/to/config:path/to/image" for
>> testing. On Windows, absolute file paths contain the delimiter ':'
>> which causes the blkdebug filename parser fail to parse filenames.
>>
>> Signed-off-by: Bin Meng <bin.meng@windriver.com>
>
>
> I don't have a much better solution to propose at this point (to actually use a temp directory), so:
> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>

I assume we can switch to using the node-based specifications instead
of -file=blkdebug:%s and just spell out the tree more meticulously,
either on the CLI or by switching to using QMP for the test. These
tests were written a long time ago.

--js



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

* Re: [PATCH v2 36/39] .gitlab-ci.d/windows.yml: Increase the timeout to 90 minutes
  2022-09-23 16:22   ` Alex Bennée
  2022-09-23 17:50     ` Thomas Huth
@ 2022-09-24  1:13     ` Bin Meng
  1 sibling, 0 replies; 87+ messages in thread
From: Bin Meng @ 2022-09-24  1:13 UTC (permalink / raw)
  To: Alex Bennée
  Cc: qemu-devel@nongnu.org Developers, Bin Meng, Beraldo Leal,
	Philippe Mathieu-Daudé,
	Thomas Huth, Wainer dos Santos Moschetta

On Sat, Sep 24, 2022 at 12:24 AM Alex Bennée <alex.bennee@linaro.org> wrote:
>
>
> Bin Meng <bmeng.cn@gmail.com> writes:
>
> > From: Bin Meng <bin.meng@windriver.com>
> >
> > commit 9f8e6cad65a6 ("gitlab-ci: Speed up the msys2-64bit job by using --without-default-devices"
> > changed to compile QEMU with the --without-default-devices switch for
> > the msys2-64bit job, due to the build could not complete within the
> > project timeout (1h), and also mentioned that a bigger timeout was
> > getting ignored on the shared Gitlab-CI Windows runners.
> >
> > However as of today it seems the shared Gitlab-CI Windows runners does
> > honor the job timeout, and the runner has the timeout limit of 2h, so
> > let's increase the timeout to 90 minutes and drop the configure switch
> > "--without-default-devices" to get a larger build coverage.
>
> I'd like to push back lightly against increasing the time because it
> lengthens the total run time before we can merge a branch. Ideally we
> could come up with a combination of build and tests that exercises all
> the Windows code without exhaustively testing code paths that are tested
> elsewhere. For device emulation are there any host specific things we
> are testing?
>

Yes, the upcoming virtio-9p Windows support will update the qtests to
test the Windows specific 9p implementation.

Besides that, during the development of this patch series, several
QEMU code bugs were exposed only when we run qtests on Windows, or
even Windows 32-bit. I still see benefits of running qtests on
Windows.

The thing is that we need to find a more powerful machine to do the
CI. Current GitLab shared Windows runners are just too slow.

Regards,
Bin


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

* Re: [PATCH v2 03/39] block: Unify the get_tmp_filename() implementation
  2022-09-22 19:38   ` Marc-André Lureau
@ 2022-09-24  8:09     ` Bin Meng
  0 siblings, 0 replies; 87+ messages in thread
From: Bin Meng @ 2022-09-24  8:09 UTC (permalink / raw)
  To: Marc-André Lureau
  Cc: qemu-devel@nongnu.org Developers, Bin Meng, Hanna Reitz,
	Kevin Wolf, Qemu-block

On Fri, Sep 23, 2022 at 3:39 AM Marc-André Lureau
<marcandre.lureau@gmail.com> wrote:
>
> Hi
>
> On Tue, Sep 20, 2022 at 2:17 PM Bin Meng <bmeng.cn@gmail.com> wrote:
>>
>> From: Bin Meng <bin.meng@windriver.com>
>>
>> At present get_tmp_filename() has platform specific implementations
>> to get the directory to use for temporary files. Switch over to use
>> g_get_tmp_dir() which works on all supported platforms.
>>
>
> As discussed in v1, there are other things to do while touching this code. And since it is optional for the series goal, please send this as a different patch/series.
>

Okay, a separate patch has just been sent.

Regards,
Bin


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

* Re: [PATCH v2 25/39] chardev/char-file: Add FILE_SHARE_WRITE when openning the file for win32
  2022-09-22 20:09   ` Marc-André Lureau
@ 2022-09-24  8:10     ` Bin Meng
  2022-09-25  5:19       ` Bin Meng
  0 siblings, 1 reply; 87+ messages in thread
From: Bin Meng @ 2022-09-24  8:10 UTC (permalink / raw)
  To: Marc-André Lureau
  Cc: qemu-devel@nongnu.org Developers, Xuzhou Cheng, Bin Meng, Paolo Bonzini

On Fri, Sep 23, 2022 at 4:09 AM Marc-André Lureau
<marcandre.lureau@gmail.com> wrote:
>
> Hi
>
> On Tue, Sep 20, 2022 at 2:33 PM Bin Meng <bmeng.cn@gmail.com> wrote:
>>
>> From: Xuzhou Cheng <xuzhou.cheng@windriver.com>
>>
>> The combination of GENERIC_WRITE and FILE_SHARE_READ options does
>> not allow the same file to be opened again by CreateFile() from
>> another QEMU process with the same options when the previous QEMU
>> process still holds the file handle opened.
>>
>> This was triggered by running the test_multifd_tcp_cancel() case on
>> Windows, which cancels the migration, and launches another QEMU
>> process to migrate with the same file opened for write. Chances are
>> that the previous QEMU process does not quit before the new QEMU
>> process runs hence the old one still holds the file handle that does
>> not allow shared write permission then the new QEMU process will fail.
>>
>> As per [1] we should add FILE_SHARE_WRITE to the share mode to allow
>> such use case. This change makes the behavior be consistent with the
>> POSIX platforms.
>>
>> [1] https://docs.microsoft.com/en-us/windows/win32/fileio/creating-and-opening-files
>>
>> Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
>> Signed-off-by: Bin Meng <bin.meng@windriver.com>
>> ---
>>
>> Changes in v2:
>> - Update commit message to include the use case why we should set
>>   FILE_SHARE_WRITE when openning the file for win32
>
>
> As discussed in v1, I would rather leave that patch out of this series, since the visible issue is solved differently elsewhere.
>
> Also, I disagree with the approach to make windows behaviour consistent with posix here, since I consider the windows behaviour (exclusive write access) superior. I would rather teach the posix implementation about exclusive write access.
>

Okay, will drop this patch in v3.

Regards,
Bin


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

* Re: [PATCH v2 38/39] tests/qtest: Enable qtest build on Windows
  2022-09-22 20:18   ` Marc-André Lureau
@ 2022-09-24  8:13     ` Bin Meng
  0 siblings, 0 replies; 87+ messages in thread
From: Bin Meng @ 2022-09-24  8:13 UTC (permalink / raw)
  To: Marc-André Lureau
  Cc: qemu-devel@nongnu.org Developers, Bin Meng, Laurent Vivier,
	Paolo Bonzini, Thomas Huth

On Fri, Sep 23, 2022 at 4:18 AM Marc-André Lureau
<marcandre.lureau@gmail.com> wrote:
>
> Hi
>
> On Tue, Sep 20, 2022 at 3:37 PM Bin Meng <bmeng.cn@gmail.com> wrote:
>>
>> From: Bin Meng <bin.meng@windriver.com>
>>
>> Now that we have fixed various test case issues as seen when running
>> on Windows, let's enable the qtest build on Windows.
>>
>> Signed-off-by: Bin Meng <bin.meng@windriver.com>
>> ---
>>
>> Changes in v2:
>> - new patch: "tests/qtest: Enable qtest build on Windows"
>>
>>  tests/qtest/meson.build | 5 ++---
>>  1 file changed, 2 insertions(+), 3 deletions(-)
>>
>> diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
>> index 455f1bbb7e..ceab141824 100644
>> --- a/tests/qtest/meson.build
>> +++ b/tests/qtest/meson.build
>> @@ -1,6 +1,5 @@
>> -# All QTests for now are POSIX-only, but the dependencies are
>> -# really in libqtest, not in the testcases themselves.
>> -if not config_host.has_key('CONFIG_POSIX')
>> +# Build all QTests for POSIX and Windows
>> +if not config_host.has_key('CONFIG_POSIX') and not config_host.has_key('CONFIG_WIN32')
>>    subdir_done()
>>  endif
>
>
> I wonder, but I suppose we can just remove the conditions. No?

Yes, I think so.

Regards,
Bin


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

* Re: [PATCH v2 25/39] chardev/char-file: Add FILE_SHARE_WRITE when openning the file for win32
  2022-09-24  8:10     ` Bin Meng
@ 2022-09-25  5:19       ` Bin Meng
  0 siblings, 0 replies; 87+ messages in thread
From: Bin Meng @ 2022-09-25  5:19 UTC (permalink / raw)
  To: Marc-André Lureau
  Cc: qemu-devel@nongnu.org Developers, Xuzhou Cheng, Bin Meng, Paolo Bonzini

On Sat, Sep 24, 2022 at 4:10 PM Bin Meng <bmeng.cn@gmail.com> wrote:
>
> On Fri, Sep 23, 2022 at 4:09 AM Marc-André Lureau
> <marcandre.lureau@gmail.com> wrote:
> >
> > Hi
> >
> > On Tue, Sep 20, 2022 at 2:33 PM Bin Meng <bmeng.cn@gmail.com> wrote:
> >>
> >> From: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> >>
> >> The combination of GENERIC_WRITE and FILE_SHARE_READ options does
> >> not allow the same file to be opened again by CreateFile() from
> >> another QEMU process with the same options when the previous QEMU
> >> process still holds the file handle opened.
> >>
> >> This was triggered by running the test_multifd_tcp_cancel() case on
> >> Windows, which cancels the migration, and launches another QEMU
> >> process to migrate with the same file opened for write. Chances are
> >> that the previous QEMU process does not quit before the new QEMU
> >> process runs hence the old one still holds the file handle that does
> >> not allow shared write permission then the new QEMU process will fail.
> >>
> >> As per [1] we should add FILE_SHARE_WRITE to the share mode to allow
> >> such use case. This change makes the behavior be consistent with the
> >> POSIX platforms.
> >>
> >> [1] https://docs.microsoft.com/en-us/windows/win32/fileio/creating-and-opening-files
> >>
> >> Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> >> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> >> ---
> >>
> >> Changes in v2:
> >> - Update commit message to include the use case why we should set
> >>   FILE_SHARE_WRITE when openning the file for win32
> >
> >
> > As discussed in v1, I would rather leave that patch out of this series, since the visible issue is solved differently elsewhere.
> >
> > Also, I disagree with the approach to make windows behaviour consistent with posix here, since I consider the windows behaviour (exclusive write access) superior. I would rather teach the posix implementation about exclusive write access.
> >
>
> Okay, will drop this patch in v3.
>

Oops, I drew the conclusion too early.

Actually there is another test case that needs this patch, which is
boot-serial-test. Log below:

# starting QEMU: ./qemu-system-x86_64 -qtest
unix:G:\msys64\tmp/qtest-37112.sock -qtest-log nul -chardev
socket,path=G:\msys64\tmp/qtest-37112.qmp,id=char0 -mon
chardev=char0,mode=control -display none -M isapc -no-shutdown
-chardev file,id=serial0,
path=G:\msys64\tmp\qtest-boot-serial-sHH9FS1 -serial chardev:serial0
-accel tcg -accel kvm -cpu qemu32 -M graphics=off -accel qtest
qemu-system-x86_64: -chardev
file,id=serial0,path=G:\msys64\tmp\qtest-boot-serial-sHH9FS1: open
G:\msys64\tmp\qtest-boot-serial-sHH9FS1 failed

The serial chardev file was created by the qtest executable with
g_file_open_tmp(), and later opened by the QEMU executable.
g_file_open_tmp() opens the file with FILE_SHARE_WRITE, see g_open()
for the details.

Then based on https://learn.microsoft.com/en-us/windows/win32/fileio/creating-and-opening-files,
there is only one case that first call to CreateFile with
GENERIC_READ, FILE_SHARE_WRITE, and second call to CreateFile with
GENERIC_WRITE, FILE_SHARE_READ is allowed. Other combinations all
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 flags were passed to the first call, so we will have to
add FILE_SHARE_WRITE to the second call.

I will add more details in the commit message in v3.

Regards,
Bin


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

* Re: [PATCH v2 01/39] tests: Change to use g_mkdir()
  2022-09-23 18:02       ` Thomas Huth
@ 2022-09-26  8:21         ` Daniel P. Berrangé
  0 siblings, 0 replies; 87+ messages in thread
From: Daniel P. Berrangé @ 2022-09-26  8:21 UTC (permalink / raw)
  To: Thomas Huth
  Cc: Bin Meng, Marc-André Lureau,
	qemu-devel@nongnu.org Developers, Bin Meng,
	Dr. David Alan Gilbert, Juan Quintela, Laurent Vivier,
	Paolo Bonzini

On Fri, Sep 23, 2022 at 08:02:46PM +0200, Thomas Huth wrote:
> On 23/09/2022 03.09, Bin Meng wrote:
> > On Fri, Sep 23, 2022 at 3:32 AM Marc-André Lureau
> > <marcandre.lureau@gmail.com> wrote:
> > > 
> > > Hi
> > > 
> > > On Tue, Sep 20, 2022 at 1:48 PM Bin Meng <bmeng.cn@gmail.com> wrote:
> > > > 
> > > > From: Bin Meng <bin.meng@windriver.com>
> > > > 
> > > > Commit 413bebc04603 ("tests: Use g_mkdir_with_parents()") replaces
> > > > the mkdir() call in the test codes with glib's g_mkdir_with_parents(),
> > > > but the exact portable replacement for mkdir() should be g_mkdir().
> > > > 
> > > > I probably was misled by the GTK glib doc [1] before, thinking that
> > > > g_mkdir() is not a supported API from glib. But the glib sources do
> > > > not support this statement. It is probably that the GTK documentation
> > > > was not built to include all APIs.
> > > > 
> > > > [1] https://docs.gtk.org/glib/?q=mkdir
> > > > 
> > > > Fixes: 413bebc04603 ("tests: Use g_mkdir_with_parents()")
> > > > Signed-off-by: Bin Meng <bin.meng@windriver.com>
> > > 
> > > 
> > > I wouldn't bother anymore, I'd keep mkdir_with_parents for now. YMMV
> > > 
> > 
> > Yep but some maintainers pointed out in other patches in v1 that
> > g_mkdir() is the strict replacement for mkdir() :)
> > 
> > @Thomas Huth Would you share your thoughts?
> 
> It's a little bit weird that g_mkdir() does not show up in the glib docs ...
> let's keep g_mkdir_with_parents(), that sounds like the better choice to me.

That is a bug in the new docs generator for GTK. It appears to have
missed out a whole bunch of APIs.  It is certainly present in the old
docs from gtk-doc output

https://developer-old.gnome.org/glib/2.64/glib-File-Utilities.html#g-mkdir

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



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

* Re: [PATCH v2 35/39] tests/qtest: migration-test: Skip running some TLS cases for win32
  2022-09-22 11:54           ` Bin Meng
@ 2022-09-27 15:40             ` Daniel P. Berrangé
  2022-09-28  6:03               ` Bin Meng
  0 siblings, 1 reply; 87+ messages in thread
From: Daniel P. Berrangé @ 2022-09-27 15:40 UTC (permalink / raw)
  To: Bin Meng
  Cc: Dr. David Alan Gilbert, qemu-devel@nongnu.org Developers,
	Bin Meng, Juan Quintela, Laurent Vivier, Paolo Bonzini,
	Thomas Huth

On Thu, Sep 22, 2022 at 07:54:05PM +0800, Bin Meng wrote:
> On Thu, Sep 22, 2022 at 6:39 PM Daniel P. Berrangé <berrange@redhat.com> wrote:
> >
> > On Thu, Sep 22, 2022 at 10:47:26AM +0800, Bin Meng wrote:
> > > On Thu, Sep 22, 2022 at 1:23 AM Daniel P. Berrangé <berrange@redhat.com> wrote:
> > > >
> > > > On Wed, Sep 21, 2022 at 05:51:33PM +0100, Dr. David Alan Gilbert wrote:
> > > > > * Bin Meng (bmeng.cn@gmail.com) wrote:
> > > > > > From: Bin Meng <bin.meng@windriver.com>
> > > > > >
> > > > > > Some migration test cases use TLS to communicate, but they fail on
> > > > > > Windows with the following error messages:
> > > > > >
> > > > > >   qemu-system-x86_64: TLS handshake failed: Insufficient credentials for that request.
> > > > > >   qemu-system-x86_64: TLS handshake failed: Error in the pull function.
> > > > > >   query-migrate shows failed migration: TLS handshake failed: Error in the pull function.
> > > > > >
> > > > > > Disable them temporarily.
> > > > > >
> > > > > > Signed-off-by: Bin Meng <bin.meng@windriver.com>
> > > > > > ---
> > > > > > I am not familar with the gnutls and simply enabling the gnutls debug
> > > > > > output does not give me an immedidate hint on why it's failing on
> > > > > > Windows. Disable these cases for now until someone or maintainers
> > > > > > who may want to test this on Windows.
> > > > >
> > > > > Copying in Dan Berrange, he's our expert on weird TLS failures.
> > > >
> > > > Seems to match this:
> > > >
> > > >    https://gnutls.org/faq.html#key-usage-violation2
> > > >
> > > > which suggests we have a configuration mis-match.
> > > >
> > > > I'm surprised to see you are only needing to disable the TLS PSK tests,
> > > > not the TLS x509 tests.
> > >
> > > The TLS x509 qtests all passed.
> > >
> > > >
> > > > I'd like to know if tests/unit/test-crypto-tlssession passes.
> > >
> > > These unit tests currently are not built on Windows as they simply
> > > don't build due to usage of socketpair().
> >
> > Doh, yes, that's rather annoying, as debugging this problem in the
> > unit tests would be easier than in qtests.
> >
> > > > If so, it might suggest we are missing 'priority: NORMAL' property
> > > > when configuring TLS creds for the migration test.
> > >
> > > I did the following changes but the error is still the same:
> >
> > >
> > > diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
> > > index dbee9b528a..c1e3f11873 100644
> > > --- a/tests/qtest/migration-test.c
> > > +++ b/tests/qtest/migration-test.c
> > > @@ -788,7 +788,8 @@ test_migrate_tls_psk_start_common(QTestState *from,
> > > " 'id': 'tlscredspsk0',"
> > > " 'endpoint': 'client',"
> > > " 'dir': %s,"
> > > - " 'username': 'qemu'} }",
> > > + " 'username': 'qemu',"
> > > + " 'priority': 'NORMAL'} }",
> > > data->workdir);
> > > qobject_unref(rsp);
> > > @@ -797,7 +798,8 @@ test_migrate_tls_psk_start_common(QTestState *from,
> > > " 'arguments': { 'qom-type': 'tls-creds-psk',"
> > > " 'id': 'tlscredspsk0',"
> > > " 'endpoint': 'server',"
> > > - " 'dir': %s } }",
> > > + " 'dir': %s,"
> > > + " 'priority': 'NORMAL'} }",
> > > mismatch ? data->workdiralt : data->workdir);
> > > qobject_unref(rsp);
> > >
> > > I am not sure whether I did the right changes.
> >
> >
> > That ought to have been sufficient, if priority strings were the
> > problem.
> >
> >
> > I think we'd need the debug output from gnutls - could you edit crypto/init.c
> > and uncomment the '#define DEBUG_GNUTLS' line near the top.
> >
> > If you can post the output you get from a single migration-test test case
> > involving PSK, it might be enough to diagnose why gnutls is failing.
> >
> 
> Here is the output:
> 
> # Start of tls tests
> # starting QEMU: ./qemu-system-x86_64 -qtest
> unix:D:\msys64\tmp/qtest-18480.sock -qtest-log nul -chardev
> socket,path=D:\msys64\tmp/qtest-18480.qmp,id=char0 -mon
> chardev=char0,mode=control -display none -accel kvm -accel t
> cg -name source,debug-threads=on -m 150M -serial
> file:D:\msys64\tmp\migration-test-A5WJS1/src_serial -drive
> file=D:\msys64\tmp\migration-test-A5WJS1/bootsect,format=raw -accel
> qtest
> qemu: thread naming not supported on this host
> # starting QEMU: ./qemu-system-x86_64 -qtest
> unix:D:\msys64\tmp/qtest-18480.sock -qtest-log nul -chardev
> socket,path=D:\msys64\tmp/qtest-18480.qmp,id=char0 -mon
> chardev=char0,mode=control -display none -accel kvm -accel t
> cg -name target,debug-threads=on -m 150M -serial
> file:D:\msys64\tmp\migration-test-A5WJS1/dest_serial -incoming
> unix:D:\msys64\tmp\migration-test-A5WJS1/migsocket -drive
> file=D:\msys64\tmp\migration-test-A5WJS1/bootsect,f
> ormat=raw -accel qtest

Comparing to running the same test on my machine.....

> 4: EXT[0000015bb1dd2c50]: Sending extension Supported Versions/43 (9 bytes)
> 4: EXT[0000015bb1dd2c50]: Preparing extension (Post Handshake Auth/49)
> for 'client hello'
> 4: EXT[0000015bb1dd2c50]: Preparing extension (Safe
> Renegotiation/65281) for 'client hello'
> 4: EXT[0000015bb1dd2c50]: Sending extension Safe Renegotiation/65281 (1 bytes)
> 4: EXT[0000015bb1dd2c50]: Preparing extension (Server Name
> Indication/0) for 'client hello'
> 4: EXT[0000015bb1dd2c50]: Preparing extension (Cookie/44) for 'client hello'
> 4: EXT[0000015bb1dd2c50]: Preparing extension (Early Data/42) for 'client hello'
> 4: EXT[0000015bb1dd2c50]: Preparing extension (PSK Key Exchange
> Modes/45) for 'client hello'
> 4: EXT[0000015bb1dd2c50]: Sending extension PSK Key Exchange Modes/45 (3 bytes)
> 4: EXT[0000015bb1dd2c50]: Preparing extension (Record Size Limit/28)
> for 'client hello'
> 4: EXT[0000015bb1dd2c50]: Sending extension Record Size Limit/28 (2 bytes)
> 4: EXT[0000015bb1dd2c50]: Preparing extension (Maximum Record Size/1)
> for 'client hello'
> 4: EXT[0000015bb1dd2c50]: Preparing extension (Compress
> Certificate/27) for 'client hello'
> 4: EXT[0000015bb1dd2c50]: Preparing extension (ClientHello Padding/21)
> for 'client hello'
> 4: EXT[0000015bb1dd2c50]: Preparing extension (Pre Shared Key/41) for
> 'client hello'

Right here is missing two items:

  4: EXT[0x55bd0c660d30]: sent PSK identity 'qemu' (0)
  4: EXT[0x55bd0c660d30]: Sending extension Pre Shared Key/41 (47 bytes)

So it appears the client is not sendnig the PSK credentials

> 4: HSK[0000015bb1dd2c50]: CLIENT HELLO was queued [343 bytes]
> 5: REC[0000015bb1dd2c50]: Preparing Packet Handshake(22) with length:
> 343 and min pad: 0
> 9: ENC[0000015bb1dd2c50]: cipher: NULL, MAC: MAC-NULL, Epoch: 0
> 5: REC[0000015bb1dd2c50]: Sent Packet[1] Handshake(22) in epoch 0 and
> length: 348

I believe there are probably two issues - first we're igonring the
return value of gnutls_psk_set_client_credentials() and I have a feeling
that is reporting an error. Second, when we write the PSK credentials out
to disk, we're not using binary mode, so I think UNIX line endings are
getting turned into  DOS line endings, and when we later load the PSK
credentials there's a stray \r present  that probably breaks
gnutls_psk_set_client_credentials.

Could you try this patch and see if it makes the PSK tests work for
migration-test:

diff --git a/crypto/tlscredspsk.c b/crypto/tlscredspsk.c
index a4f9891274..546cad1c5a 100644
--- a/crypto/tlscredspsk.c
+++ b/crypto/tlscredspsk.c
@@ -109,7 +109,12 @@ qcrypto_tls_creds_psk_load(QCryptoTLSCredsPSK *creds,
             goto cleanup;
         }
 
-        gnutls_psk_set_server_credentials_file(creds->data.server, pskfile);
+        ret = gnutls_psk_set_server_credentials_file(creds->data.server, pskfile);
+        if (ret < 0) {
+            error_setg(errp, "Cannot set PSK server credentials: %s",
+                       gnutls_strerror(ret));
+            goto cleanup;
+        }
         gnutls_psk_set_server_dh_params(creds->data.server,
                                         creds->parent_obj.dh_params);
     } else {
@@ -135,8 +140,13 @@ qcrypto_tls_creds_psk_load(QCryptoTLSCredsPSK *creds,
             goto cleanup;
         }
 
-        gnutls_psk_set_client_credentials(creds->data.client,
-                                          username, &key, GNUTLS_PSK_KEY_HEX);
+        ret = gnutls_psk_set_client_credentials(creds->data.client,
+                                                username, &key, GNUTLS_PSK_KEY_HEX);
+        if (ret < 0) {
+            error_setg(errp, "Cannot set PSK client credentials: %s",
+                       gnutls_strerror(ret));
+            goto cleanup;
+        }
     }
 
     rv = 0;
diff --git a/tests/unit/crypto-tls-psk-helpers.c b/tests/unit/crypto-tls-psk-helpers.c
index 511e08cc9c..c6cc740772 100644
--- a/tests/unit/crypto-tls-psk-helpers.c
+++ b/tests/unit/crypto-tls-psk-helpers.c
@@ -27,15 +27,14 @@
 static void
 test_tls_psk_init_common(const char *pskfile, const char *user, const char *key)
 {
-    FILE *fp;
+    g_autoptr(GError) gerr = NULL;
+    g_autofree char *line = g_strdup_printf("%s:%s\n", user, key);
 
-    fp = fopen(pskfile, "w");
-    if (fp == NULL) {
-        g_critical("Failed to create pskfile %s: %s", pskfile, strerror(errno));
+    g_file_set_contents(pskfile, line, strlen(line), &gerr);
+    if (gerr != NULL) {
+        g_critical("Failed to create pskfile %s: %s", pskfile, gerr->message);
         abort();
     }
-    fprintf(fp, "%s:%s\n", user, key);
-    fclose(fp);
 }
 
 void test_tls_psk_init(const char *pskfile)



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



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

* Re: [PATCH v2 35/39] tests/qtest: migration-test: Skip running some TLS cases for win32
  2022-09-27 15:40             ` Daniel P. Berrangé
@ 2022-09-28  6:03               ` Bin Meng
  2022-09-28  7:07                 ` Daniel P. Berrangé
  0 siblings, 1 reply; 87+ messages in thread
From: Bin Meng @ 2022-09-28  6:03 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: Dr. David Alan Gilbert, qemu-devel@nongnu.org Developers,
	Bin Meng, Juan Quintela, Laurent Vivier, Paolo Bonzini,
	Thomas Huth

Hi Daniel,

On Tue, Sep 27, 2022 at 11:40 PM Daniel P. Berrangé <berrange@redhat.com> wrote:
>
> On Thu, Sep 22, 2022 at 07:54:05PM +0800, Bin Meng wrote:
> > On Thu, Sep 22, 2022 at 6:39 PM Daniel P. Berrangé <berrange@redhat.com> wrote:
> > >
> > > On Thu, Sep 22, 2022 at 10:47:26AM +0800, Bin Meng wrote:
> > > > On Thu, Sep 22, 2022 at 1:23 AM Daniel P. Berrangé <berrange@redhat.com> wrote:
> > > > >
> > > > > On Wed, Sep 21, 2022 at 05:51:33PM +0100, Dr. David Alan Gilbert wrote:
> > > > > > * Bin Meng (bmeng.cn@gmail.com) wrote:
> > > > > > > From: Bin Meng <bin.meng@windriver.com>
> > > > > > >
> > > > > > > Some migration test cases use TLS to communicate, but they fail on
> > > > > > > Windows with the following error messages:
> > > > > > >
> > > > > > >   qemu-system-x86_64: TLS handshake failed: Insufficient credentials for that request.
> > > > > > >   qemu-system-x86_64: TLS handshake failed: Error in the pull function.
> > > > > > >   query-migrate shows failed migration: TLS handshake failed: Error in the pull function.
> > > > > > >
> > > > > > > Disable them temporarily.
> > > > > > >
> > > > > > > Signed-off-by: Bin Meng <bin.meng@windriver.com>
> > > > > > > ---
> > > > > > > I am not familar with the gnutls and simply enabling the gnutls debug
> > > > > > > output does not give me an immedidate hint on why it's failing on
> > > > > > > Windows. Disable these cases for now until someone or maintainers
> > > > > > > who may want to test this on Windows.
> > > > > >
> > > > > > Copying in Dan Berrange, he's our expert on weird TLS failures.
> > > > >
> > > > > Seems to match this:
> > > > >
> > > > >    https://gnutls.org/faq.html#key-usage-violation2
> > > > >
> > > > > which suggests we have a configuration mis-match.
> > > > >
> > > > > I'm surprised to see you are only needing to disable the TLS PSK tests,
> > > > > not the TLS x509 tests.
> > > >
> > > > The TLS x509 qtests all passed.
> > > >
> > > > >
> > > > > I'd like to know if tests/unit/test-crypto-tlssession passes.
> > > >
> > > > These unit tests currently are not built on Windows as they simply
> > > > don't build due to usage of socketpair().
> > >
> > > Doh, yes, that's rather annoying, as debugging this problem in the
> > > unit tests would be easier than in qtests.
> > >
> > > > > If so, it might suggest we are missing 'priority: NORMAL' property
> > > > > when configuring TLS creds for the migration test.
> > > >
> > > > I did the following changes but the error is still the same:
> > >
> > > >
> > > > diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
> > > > index dbee9b528a..c1e3f11873 100644
> > > > --- a/tests/qtest/migration-test.c
> > > > +++ b/tests/qtest/migration-test.c
> > > > @@ -788,7 +788,8 @@ test_migrate_tls_psk_start_common(QTestState *from,
> > > > " 'id': 'tlscredspsk0',"
> > > > " 'endpoint': 'client',"
> > > > " 'dir': %s,"
> > > > - " 'username': 'qemu'} }",
> > > > + " 'username': 'qemu',"
> > > > + " 'priority': 'NORMAL'} }",
> > > > data->workdir);
> > > > qobject_unref(rsp);
> > > > @@ -797,7 +798,8 @@ test_migrate_tls_psk_start_common(QTestState *from,
> > > > " 'arguments': { 'qom-type': 'tls-creds-psk',"
> > > > " 'id': 'tlscredspsk0',"
> > > > " 'endpoint': 'server',"
> > > > - " 'dir': %s } }",
> > > > + " 'dir': %s,"
> > > > + " 'priority': 'NORMAL'} }",
> > > > mismatch ? data->workdiralt : data->workdir);
> > > > qobject_unref(rsp);
> > > >
> > > > I am not sure whether I did the right changes.
> > >
> > >
> > > That ought to have been sufficient, if priority strings were the
> > > problem.
> > >
> > >
> > > I think we'd need the debug output from gnutls - could you edit crypto/init.c
> > > and uncomment the '#define DEBUG_GNUTLS' line near the top.
> > >
> > > If you can post the output you get from a single migration-test test case
> > > involving PSK, it might be enough to diagnose why gnutls is failing.
> > >
> >
> > Here is the output:
> >
> > # Start of tls tests
> > # starting QEMU: ./qemu-system-x86_64 -qtest
> > unix:D:\msys64\tmp/qtest-18480.sock -qtest-log nul -chardev
> > socket,path=D:\msys64\tmp/qtest-18480.qmp,id=char0 -mon
> > chardev=char0,mode=control -display none -accel kvm -accel t
> > cg -name source,debug-threads=on -m 150M -serial
> > file:D:\msys64\tmp\migration-test-A5WJS1/src_serial -drive
> > file=D:\msys64\tmp\migration-test-A5WJS1/bootsect,format=raw -accel
> > qtest
> > qemu: thread naming not supported on this host
> > # starting QEMU: ./qemu-system-x86_64 -qtest
> > unix:D:\msys64\tmp/qtest-18480.sock -qtest-log nul -chardev
> > socket,path=D:\msys64\tmp/qtest-18480.qmp,id=char0 -mon
> > chardev=char0,mode=control -display none -accel kvm -accel t
> > cg -name target,debug-threads=on -m 150M -serial
> > file:D:\msys64\tmp\migration-test-A5WJS1/dest_serial -incoming
> > unix:D:\msys64\tmp\migration-test-A5WJS1/migsocket -drive
> > file=D:\msys64\tmp\migration-test-A5WJS1/bootsect,f
> > ormat=raw -accel qtest
>
> Comparing to running the same test on my machine.....
>
> > 4: EXT[0000015bb1dd2c50]: Sending extension Supported Versions/43 (9 bytes)
> > 4: EXT[0000015bb1dd2c50]: Preparing extension (Post Handshake Auth/49)
> > for 'client hello'
> > 4: EXT[0000015bb1dd2c50]: Preparing extension (Safe
> > Renegotiation/65281) for 'client hello'
> > 4: EXT[0000015bb1dd2c50]: Sending extension Safe Renegotiation/65281 (1 bytes)
> > 4: EXT[0000015bb1dd2c50]: Preparing extension (Server Name
> > Indication/0) for 'client hello'
> > 4: EXT[0000015bb1dd2c50]: Preparing extension (Cookie/44) for 'client hello'
> > 4: EXT[0000015bb1dd2c50]: Preparing extension (Early Data/42) for 'client hello'
> > 4: EXT[0000015bb1dd2c50]: Preparing extension (PSK Key Exchange
> > Modes/45) for 'client hello'
> > 4: EXT[0000015bb1dd2c50]: Sending extension PSK Key Exchange Modes/45 (3 bytes)
> > 4: EXT[0000015bb1dd2c50]: Preparing extension (Record Size Limit/28)
> > for 'client hello'
> > 4: EXT[0000015bb1dd2c50]: Sending extension Record Size Limit/28 (2 bytes)
> > 4: EXT[0000015bb1dd2c50]: Preparing extension (Maximum Record Size/1)
> > for 'client hello'
> > 4: EXT[0000015bb1dd2c50]: Preparing extension (Compress
> > Certificate/27) for 'client hello'
> > 4: EXT[0000015bb1dd2c50]: Preparing extension (ClientHello Padding/21)
> > for 'client hello'
> > 4: EXT[0000015bb1dd2c50]: Preparing extension (Pre Shared Key/41) for
> > 'client hello'
>
> Right here is missing two items:
>
>   4: EXT[0x55bd0c660d30]: sent PSK identity 'qemu' (0)
>   4: EXT[0x55bd0c660d30]: Sending extension Pre Shared Key/41 (47 bytes)
>
> So it appears the client is not sendnig the PSK credentials
>
> > 4: HSK[0000015bb1dd2c50]: CLIENT HELLO was queued [343 bytes]
> > 5: REC[0000015bb1dd2c50]: Preparing Packet Handshake(22) with length:
> > 343 and min pad: 0
> > 9: ENC[0000015bb1dd2c50]: cipher: NULL, MAC: MAC-NULL, Epoch: 0
> > 5: REC[0000015bb1dd2c50]: Sent Packet[1] Handshake(22) in epoch 0 and
> > length: 348
>
> I believe there are probably two issues - first we're igonring the
> return value of gnutls_psk_set_client_credentials() and I have a feeling
> that is reporting an error.

Indeed gnutls_psk_set_client_credentials() fails with "Error in
parsing." message.

> Second, when we write the PSK credentials out
> to disk, we're not using binary mode, so I think UNIX line endings are
> getting turned into  DOS line endings, and when we later load the PSK
> credentials there's a stray \r present  that probably breaks
> gnutls_psk_set_client_credentials.

I think that's what happened.

>
> Could you try this patch and see if it makes the PSK tests work for
> migration-test:

Yes, this patch fixed the TLS test cases in the migration-test on Windows!

Thank you very much for the help!

Would you mind sending the patches on your own, or you want me to
include them in the next version of this series?

>
> diff --git a/crypto/tlscredspsk.c b/crypto/tlscredspsk.c
> index a4f9891274..546cad1c5a 100644
> --- a/crypto/tlscredspsk.c
> +++ b/crypto/tlscredspsk.c
> @@ -109,7 +109,12 @@ qcrypto_tls_creds_psk_load(QCryptoTLSCredsPSK *creds,
>              goto cleanup;
>          }
>
> -        gnutls_psk_set_server_credentials_file(creds->data.server, pskfile);
> +        ret = gnutls_psk_set_server_credentials_file(creds->data.server, pskfile);
> +        if (ret < 0) {
> +            error_setg(errp, "Cannot set PSK server credentials: %s",
> +                       gnutls_strerror(ret));
> +            goto cleanup;
> +        }
>          gnutls_psk_set_server_dh_params(creds->data.server,
>                                          creds->parent_obj.dh_params);
>      } else {
> @@ -135,8 +140,13 @@ qcrypto_tls_creds_psk_load(QCryptoTLSCredsPSK *creds,
>              goto cleanup;
>          }
>
> -        gnutls_psk_set_client_credentials(creds->data.client,
> -                                          username, &key, GNUTLS_PSK_KEY_HEX);
> +        ret = gnutls_psk_set_client_credentials(creds->data.client,
> +                                                username, &key, GNUTLS_PSK_KEY_HEX);
> +        if (ret < 0) {
> +            error_setg(errp, "Cannot set PSK client credentials: %s",
> +                       gnutls_strerror(ret));
> +            goto cleanup;
> +        }
>      }
>
>      rv = 0;
> diff --git a/tests/unit/crypto-tls-psk-helpers.c b/tests/unit/crypto-tls-psk-helpers.c
> index 511e08cc9c..c6cc740772 100644
> --- a/tests/unit/crypto-tls-psk-helpers.c
> +++ b/tests/unit/crypto-tls-psk-helpers.c
> @@ -27,15 +27,14 @@
>  static void
>  test_tls_psk_init_common(const char *pskfile, const char *user, const char *key)
>  {
> -    FILE *fp;
> +    g_autoptr(GError) gerr = NULL;
> +    g_autofree char *line = g_strdup_printf("%s:%s\n", user, key);
>
> -    fp = fopen(pskfile, "w");
> -    if (fp == NULL) {
> -        g_critical("Failed to create pskfile %s: %s", pskfile, strerror(errno));
> +    g_file_set_contents(pskfile, line, strlen(line), &gerr);
> +    if (gerr != NULL) {
> +        g_critical("Failed to create pskfile %s: %s", pskfile, gerr->message);
>          abort();
>      }
> -    fprintf(fp, "%s:%s\n", user, key);
> -    fclose(fp);
>  }
>
>  void test_tls_psk_init(const char *pskfile)
>

Regards,
Bin


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

* Re: [PATCH v2 35/39] tests/qtest: migration-test: Skip running some TLS cases for win32
  2022-09-28  6:03               ` Bin Meng
@ 2022-09-28  7:07                 ` Daniel P. Berrangé
  0 siblings, 0 replies; 87+ messages in thread
From: Daniel P. Berrangé @ 2022-09-28  7:07 UTC (permalink / raw)
  To: Bin Meng
  Cc: Dr. David Alan Gilbert, qemu-devel@nongnu.org Developers,
	Bin Meng, Juan Quintela, Laurent Vivier, Paolo Bonzini,
	Thomas Huth

On Wed, Sep 28, 2022 at 02:03:28PM +0800, Bin Meng wrote:
> Hi Daniel,
> 
> On Tue, Sep 27, 2022 at 11:40 PM Daniel P. Berrangé <berrange@redhat.com> wrote:
> >
> > On Thu, Sep 22, 2022 at 07:54:05PM +0800, Bin Meng wrote:
> > > On Thu, Sep 22, 2022 at 6:39 PM Daniel P. Berrangé <berrange@redhat.com> wrote:
> > > >
> > > > On Thu, Sep 22, 2022 at 10:47:26AM +0800, Bin Meng wrote:
> > > > > On Thu, Sep 22, 2022 at 1:23 AM Daniel P. Berrangé <berrange@redhat.com> wrote:
> > > > > >
> > > > > > On Wed, Sep 21, 2022 at 05:51:33PM +0100, Dr. David Alan Gilbert wrote:
> > > > > > > * Bin Meng (bmeng.cn@gmail.com) wrote:
> > > > > > > > From: Bin Meng <bin.meng@windriver.com>
> > > > > > > >
> > > > > > > > Some migration test cases use TLS to communicate, but they fail on
> > > > > > > > Windows with the following error messages:
> > > > > > > >
> > > > > > > >   qemu-system-x86_64: TLS handshake failed: Insufficient credentials for that request.
> > > > > > > >   qemu-system-x86_64: TLS handshake failed: Error in the pull function.
> > > > > > > >   query-migrate shows failed migration: TLS handshake failed: Error in the pull function.
> > > > > > > >
> > > > > > > > Disable them temporarily.
> > > > > > > >
> > > > > > > > Signed-off-by: Bin Meng <bin.meng@windriver.com>
> > > > > > > > ---
> > > > > > > > I am not familar with the gnutls and simply enabling the gnutls debug
> > > > > > > > output does not give me an immedidate hint on why it's failing on
> > > > > > > > Windows. Disable these cases for now until someone or maintainers
> > > > > > > > who may want to test this on Windows.
> > > > > > >
> > > > > > > Copying in Dan Berrange, he's our expert on weird TLS failures.
> > > > > >
> > > > > > Seems to match this:
> > > > > >
> > > > > >    https://gnutls.org/faq.html#key-usage-violation2
> > > > > >
> > > > > > which suggests we have a configuration mis-match.
> > > > > >
> > > > > > I'm surprised to see you are only needing to disable the TLS PSK tests,
> > > > > > not the TLS x509 tests.
> > > > >
> > > > > The TLS x509 qtests all passed.
> > > > >
> > > > > >
> > > > > > I'd like to know if tests/unit/test-crypto-tlssession passes.
> > > > >
> > > > > These unit tests currently are not built on Windows as they simply
> > > > > don't build due to usage of socketpair().
> > > >
> > > > Doh, yes, that's rather annoying, as debugging this problem in the
> > > > unit tests would be easier than in qtests.
> > > >
> > > > > > If so, it might suggest we are missing 'priority: NORMAL' property
> > > > > > when configuring TLS creds for the migration test.
> > > > >
> > > > > I did the following changes but the error is still the same:
> > > >
> > > > >
> > > > > diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
> > > > > index dbee9b528a..c1e3f11873 100644
> > > > > --- a/tests/qtest/migration-test.c
> > > > > +++ b/tests/qtest/migration-test.c
> > > > > @@ -788,7 +788,8 @@ test_migrate_tls_psk_start_common(QTestState *from,
> > > > > " 'id': 'tlscredspsk0',"
> > > > > " 'endpoint': 'client',"
> > > > > " 'dir': %s,"
> > > > > - " 'username': 'qemu'} }",
> > > > > + " 'username': 'qemu',"
> > > > > + " 'priority': 'NORMAL'} }",
> > > > > data->workdir);
> > > > > qobject_unref(rsp);
> > > > > @@ -797,7 +798,8 @@ test_migrate_tls_psk_start_common(QTestState *from,
> > > > > " 'arguments': { 'qom-type': 'tls-creds-psk',"
> > > > > " 'id': 'tlscredspsk0',"
> > > > > " 'endpoint': 'server',"
> > > > > - " 'dir': %s } }",
> > > > > + " 'dir': %s,"
> > > > > + " 'priority': 'NORMAL'} }",
> > > > > mismatch ? data->workdiralt : data->workdir);
> > > > > qobject_unref(rsp);
> > > > >
> > > > > I am not sure whether I did the right changes.
> > > >
> > > >
> > > > That ought to have been sufficient, if priority strings were the
> > > > problem.
> > > >
> > > >
> > > > I think we'd need the debug output from gnutls - could you edit crypto/init.c
> > > > and uncomment the '#define DEBUG_GNUTLS' line near the top.
> > > >
> > > > If you can post the output you get from a single migration-test test case
> > > > involving PSK, it might be enough to diagnose why gnutls is failing.
> > > >
> > >
> > > Here is the output:
> > >
> > > # Start of tls tests
> > > # starting QEMU: ./qemu-system-x86_64 -qtest
> > > unix:D:\msys64\tmp/qtest-18480.sock -qtest-log nul -chardev
> > > socket,path=D:\msys64\tmp/qtest-18480.qmp,id=char0 -mon
> > > chardev=char0,mode=control -display none -accel kvm -accel t
> > > cg -name source,debug-threads=on -m 150M -serial
> > > file:D:\msys64\tmp\migration-test-A5WJS1/src_serial -drive
> > > file=D:\msys64\tmp\migration-test-A5WJS1/bootsect,format=raw -accel
> > > qtest
> > > qemu: thread naming not supported on this host
> > > # starting QEMU: ./qemu-system-x86_64 -qtest
> > > unix:D:\msys64\tmp/qtest-18480.sock -qtest-log nul -chardev
> > > socket,path=D:\msys64\tmp/qtest-18480.qmp,id=char0 -mon
> > > chardev=char0,mode=control -display none -accel kvm -accel t
> > > cg -name target,debug-threads=on -m 150M -serial
> > > file:D:\msys64\tmp\migration-test-A5WJS1/dest_serial -incoming
> > > unix:D:\msys64\tmp\migration-test-A5WJS1/migsocket -drive
> > > file=D:\msys64\tmp\migration-test-A5WJS1/bootsect,f
> > > ormat=raw -accel qtest
> >
> > Comparing to running the same test on my machine.....
> >
> > > 4: EXT[0000015bb1dd2c50]: Sending extension Supported Versions/43 (9 bytes)
> > > 4: EXT[0000015bb1dd2c50]: Preparing extension (Post Handshake Auth/49)
> > > for 'client hello'
> > > 4: EXT[0000015bb1dd2c50]: Preparing extension (Safe
> > > Renegotiation/65281) for 'client hello'
> > > 4: EXT[0000015bb1dd2c50]: Sending extension Safe Renegotiation/65281 (1 bytes)
> > > 4: EXT[0000015bb1dd2c50]: Preparing extension (Server Name
> > > Indication/0) for 'client hello'
> > > 4: EXT[0000015bb1dd2c50]: Preparing extension (Cookie/44) for 'client hello'
> > > 4: EXT[0000015bb1dd2c50]: Preparing extension (Early Data/42) for 'client hello'
> > > 4: EXT[0000015bb1dd2c50]: Preparing extension (PSK Key Exchange
> > > Modes/45) for 'client hello'
> > > 4: EXT[0000015bb1dd2c50]: Sending extension PSK Key Exchange Modes/45 (3 bytes)
> > > 4: EXT[0000015bb1dd2c50]: Preparing extension (Record Size Limit/28)
> > > for 'client hello'
> > > 4: EXT[0000015bb1dd2c50]: Sending extension Record Size Limit/28 (2 bytes)
> > > 4: EXT[0000015bb1dd2c50]: Preparing extension (Maximum Record Size/1)
> > > for 'client hello'
> > > 4: EXT[0000015bb1dd2c50]: Preparing extension (Compress
> > > Certificate/27) for 'client hello'
> > > 4: EXT[0000015bb1dd2c50]: Preparing extension (ClientHello Padding/21)
> > > for 'client hello'
> > > 4: EXT[0000015bb1dd2c50]: Preparing extension (Pre Shared Key/41) for
> > > 'client hello'
> >
> > Right here is missing two items:
> >
> >   4: EXT[0x55bd0c660d30]: sent PSK identity 'qemu' (0)
> >   4: EXT[0x55bd0c660d30]: Sending extension Pre Shared Key/41 (47 bytes)
> >
> > So it appears the client is not sendnig the PSK credentials
> >
> > > 4: HSK[0000015bb1dd2c50]: CLIENT HELLO was queued [343 bytes]
> > > 5: REC[0000015bb1dd2c50]: Preparing Packet Handshake(22) with length:
> > > 343 and min pad: 0
> > > 9: ENC[0000015bb1dd2c50]: cipher: NULL, MAC: MAC-NULL, Epoch: 0
> > > 5: REC[0000015bb1dd2c50]: Sent Packet[1] Handshake(22) in epoch 0 and
> > > length: 348
> >
> > I believe there are probably two issues - first we're igonring the
> > return value of gnutls_psk_set_client_credentials() and I have a feeling
> > that is reporting an error.
> 
> Indeed gnutls_psk_set_client_credentials() fails with "Error in
> parsing." message.
> 
> > Second, when we write the PSK credentials out
> > to disk, we're not using binary mode, so I think UNIX line endings are
> > getting turned into  DOS line endings, and when we later load the PSK
> > credentials there's a stray \r present  that probably breaks
> > gnutls_psk_set_client_credentials.
> 
> I think that's what happened.
> 
> >
> > Could you try this patch and see if it makes the PSK tests work for
> > migration-test:
> 
> Yes, this patch fixed the TLS test cases in the migration-test on Windows!
> 
> Thank you very much for the help!
> 
> Would you mind sending the patches on your own, or you want me to
> include them in the next version of this series?

I'll send my patch formally and CC you.

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



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

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

Thread overview: 87+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-20 10:31 [PATCH v2 00/39] tests/qtest: Enable running qtest on Windows Bin Meng
2022-09-20 10:31 ` [PATCH v2 01/39] tests: Change to use g_mkdir() Bin Meng
2022-09-22 19:32   ` Marc-André Lureau
2022-09-23  1:09     ` Bin Meng
2022-09-23 18:02       ` Thomas Huth
2022-09-26  8:21         ` Daniel P. Berrangé
2022-09-20 10:31 ` [PATCH v2 02/39] tests/qtest: i440fx-test: Rewrite create_blob_file() to be portable Bin Meng
2022-09-22 19:34   ` Marc-André Lureau
2022-09-20 10:31 ` [PATCH v2 03/39] block: Unify the get_tmp_filename() implementation Bin Meng
2022-09-22 19:38   ` Marc-André Lureau
2022-09-24  8:09     ` Bin Meng
2022-09-20 10:31 ` [PATCH v2 04/39] semihosting/arm-compat-semi: Avoid using hardcoded /tmp Bin Meng
2022-09-23 16:20   ` Alex Bennée
2022-09-20 10:31 ` [PATCH v2 05/39] tcg: " Bin Meng
2022-09-23 16:20   ` Alex Bennée
2022-09-20 10:31 ` [PATCH v2 06/39] util/qemu-sockets: Use g_get_tmp_dir() to get the directory for temporary files Bin Meng
2022-09-20 10:31 ` [PATCH v2 07/39] tests: Avoid using hardcoded /tmp in test cases Bin Meng
2022-09-22 19:46   ` Marc-André Lureau
2022-09-23  4:43     ` Markus Armbruster
2022-09-20 10:31 ` [PATCH v2 08/39] block/vvfat: Unify the mkdir() call Bin Meng
2022-09-22 19:47   ` Marc-André Lureau
2022-09-20 10:31 ` [PATCH v2 09/39] fsdev/virtfs-proxy-helper: Use g_mkdir() Bin Meng
2022-09-20 13:42   ` Christian Schoenebeck
2022-09-20 10:31 ` [PATCH v2 10/39] hw/usb: dev-mtp: " Bin Meng
2022-09-20 11:20   ` Gerd Hoffmann
2022-09-20 10:31 ` [PATCH v2 11/39] tests/qtest: Skip running virtio-net-test cases that require socketpair() for win32 Bin Meng
2022-09-20 10:31 ` [PATCH v2 12/39] tests/qtest: Build test-filter-{mirror, redirector} cases for posix only Bin Meng
2022-09-20 10:31 ` [PATCH v2 13/39] tests/qtest: qmp-test: Skip running test_qmp_oob for win32 Bin Meng
2022-09-20 10:31 ` [PATCH v2 14/39] accel/qtest: Implement a portable qtest accelerator Bin Meng
2022-09-20 10:31 ` [PATCH v2 15/39] tests/qtest: libqtest: Adapt global_qtest declaration for win32 Bin Meng
2022-09-20 10:31 ` [PATCH v2 16/39] tests/qtest: Use send/recv for socket communication Bin Meng
2022-09-22 19:52   ` Marc-André Lureau
2022-09-20 10:31 ` [PATCH v2 17/39] tests/qtest: libqtest: Exclude the *_fds APIs for win32 Bin Meng
2022-09-20 10:31 ` [PATCH v2 18/39] tests/qtest: libqtest: Install signal handler via signal() Bin Meng
2022-09-22 19:55   ` Marc-André Lureau
2022-09-23 17:54     ` Thomas Huth
2022-09-20 10:31 ` [PATCH v2 19/39] tests/qtest: Support libqtest to build and run on Windows Bin Meng
2022-09-22 19:59   ` Marc-André Lureau
2022-09-20 10:31 ` [PATCH v2 20/39] tests/qtest: {ahci, ide}-test: Use relative path for temporary files for win32 Bin Meng
2022-09-22 20:02   ` Marc-André Lureau
2022-09-23 20:00     ` John Snow
2022-09-20 10:31 ` [PATCH v2 21/39] tests/qtest: bios-tables-test: Adapt the case " Bin Meng
2022-09-20 10:31 ` [PATCH v2 22/39] tests/qtest: migration-test: Disable IO redirection " Bin Meng
2022-09-22 20:04   ` Marc-André Lureau
2022-09-20 10:31 ` [PATCH v2 23/39] tests/qtest: ide-test: Open file in binary mode Bin Meng
2022-09-20 10:31 ` [PATCH v2 24/39] tests/qtest: virtio-net-failover: Disable migration tests for win32 Bin Meng
2022-09-22 20:05   ` Marc-André Lureau
2022-09-20 10:31 ` [PATCH v2 25/39] chardev/char-file: Add FILE_SHARE_WRITE when openning the file " Bin Meng
2022-09-22 20:09   ` Marc-André Lureau
2022-09-24  8:10     ` Bin Meng
2022-09-25  5:19       ` Bin Meng
2022-09-20 10:31 ` [PATCH v2 26/39] tests/qtest: migration-test: Make sure QEMU process "to" exited after migration is canceled Bin Meng
2022-09-21 16:29   ` Dr. David Alan Gilbert
2022-09-21 16:50     ` Daniel P. Berrangé
2022-09-21 21:54   ` Marc-André Lureau
2022-09-22  3:29     ` Bin Meng
2022-09-20 10:31 ` [PATCH v2 27/39] hw/ppc: spapr: Use qemu_vfree() to free spapr->htab Bin Meng
2022-09-20 10:31 ` [PATCH v2 28/39] hw/pci-host: pnv_phb{3, 4}: Fix heap out-of-bound access failure Bin Meng
2022-09-20 11:17   ` Cédric Le Goater
2022-09-20 15:40   ` Daniel Henrique Barboza
2022-09-21  0:14     ` Bin Meng
2022-09-20 10:31 ` [PATCH v2 29/39] tests/qtest: microbit-test: Fix socket access for win32 Bin Meng
2022-09-20 10:31 ` [PATCH v2 30/39] tests/qtest: libqtest: Replace the call to close a socket with closesocket() Bin Meng
2022-09-20 10:31 ` [PATCH v2 31/39] tests/qtest: libqtest: Correct the timeout unit of blocking receive calls for win32 Bin Meng
2022-09-20 10:31 ` [PATCH v2 32/39] io/channel-watch: Drop a superfluous '#ifdef WIN32' Bin Meng
2022-09-20 10:31 ` [PATCH v2 33/39] io/channel-watch: Drop the unnecessary cast Bin Meng
2022-09-22 20:13   ` Marc-André Lureau
2022-09-20 10:31 ` [PATCH v2 34/39] io/channel-watch: Fix socket watch on Windows Bin Meng
2022-09-20 10:31 ` [PATCH v2 35/39] tests/qtest: migration-test: Skip running some TLS cases for win32 Bin Meng
2022-09-21 16:51   ` Dr. David Alan Gilbert
2022-09-21 17:23     ` Daniel P. Berrangé
2022-09-22  2:47       ` Bin Meng
2022-09-22 10:39         ` Daniel P. Berrangé
2022-09-22 11:54           ` Bin Meng
2022-09-27 15:40             ` Daniel P. Berrangé
2022-09-28  6:03               ` Bin Meng
2022-09-28  7:07                 ` Daniel P. Berrangé
2022-09-22 20:16   ` Marc-André Lureau
2022-09-20 10:31 ` [PATCH v2 36/39] .gitlab-ci.d/windows.yml: Increase the timeout to 90 minutes Bin Meng
2022-09-23 16:22   ` Alex Bennée
2022-09-23 17:50     ` Thomas Huth
2022-09-24  1:13     ` Bin Meng
2022-09-20 10:31 ` [PATCH v2 37/39] .gitlab-ci.d/windows.yml: Display meson test logs Bin Meng
2022-09-20 10:31 ` [PATCH v2 38/39] tests/qtest: Enable qtest build on Windows Bin Meng
2022-09-22 20:18   ` Marc-André Lureau
2022-09-24  8:13     ` Bin Meng
2022-09-20 10:31 ` [PATCH v2 39/39] docs/devel: testing: Document writing portable test cases Bin Meng

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.