tests/qtest: Enable running qtest on Windows
Subsystems (2)
v5 cover tests/qtest: Enable running qtest on Windows
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 v5:
- Rebase on qemu/master
- Drop patches that are already merged
- Use g_autoptr(GError)
- Restore to v1 version which does not touch the posix implementation
- Replace sighandler_t with its actual definition, since it is not available on BSD hosts
Changes in v4:
- Update the error reporting by using the GError "error" argument of g_dir_make_tmp()
- Remove the const from tmpfs declaration
Changes in v3:
- Split to a separate patch
- Add a usleep(1) in the busy wait loop
- Drop the host test
Changes in v2:
- Use g_autofree to declare the variable
- Change to use g_mkdir()
- Change to use g_mkdir()
- Change to use g_mkdir()
- 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 to a busy wait after migration is canceled
- new patch: "io/channel-watch: Drop the unnecessary cast"
- Change the timeout limit to 90 minutes
- new patch: "tests/qtest: Enable qtest build on Windows"
Bin Meng (15):
semihosting/arm-compat-semi: Avoid using hardcoded /tmp
tcg: Avoid using hardcoded /tmp
util/qemu-sockets: Use g_get_tmp_dir() to get the directory for
temporary files
tests/qtest: migration-test: Avoid using hardcoded /tmp block/vvfat: Unify the mkdir() call fsdev/virtfs-proxy-helper: Use g_mkdir()
hw/usb: dev-mtp: Use g_mkdir()
tests/qtest: libqtest: Install signal handler via signal() tests/qtest: Support libqtest to build and run on Windows 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 .gitlab-ci.d/windows.yml: Increase the timeout to 90 minutes tests/qtest: Enable qtest build on Windows
Xuzhou Cheng (3):
accel/qtest: Support qtest accelerator for Windows tests/qtest: Use send/recv for socket communication tests/qtest: migration-test: Make sure QEMU process "to" exited after
migration is canceled
include/hw/core/cpu.h | 1 + include/qemu/sockets.h | 2 + accel/dummy-cpus.c | 14 +++- block/vvfat.c | 9 +-- fsdev/virtfs-proxy-helper.c | 3 +- hw/usb/dev-mtp.c | 4 +- io/channel-watch.c | 12 +--- semihosting/arm-compat-semi.c | 3 +- softmmu/cpus.c | 9 +-- tcg/tcg.c | 3 +- tests/qtest/libqmp.c | 5 +- tests/qtest/libqtest.c | 124 +++++++++++++++++++++++++++++----- tests/qtest/migration-test.c | 14 ++-- util/osdep.c | 33 +++++++++ util/qemu-sockets.c | 5 +- .gitlab-ci.d/windows.yml | 4 +- accel/meson.build | 1 + accel/qtest/meson.build | 1 + tests/qtest/meson.build | 6 -- 19 files changed, 194 insertions(+), 59 deletions(-)
Signature · 1 line
2.34.1
PATCH v5 2/18 tcg: Avoid using hardcoded /tmp
From: Bin Meng <[email protected]>
Use g_get_tmp_dir() to get the directory to use for temporary files.
---
(no changes since v2)
Changes in v2:
- Use g_autofree to declare the variable
tcg/tcg.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tcg/tcg.c +2 -1
@@ -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. */
Signature · 1 line
2.34.1
PATCH v5 5/18 block/vvfat: Unify the mkdir() call
In reply to Bin MengFrom: Bin Meng <[email protected]>
There is a difference in the mkdir() call for win32 and non-win32 platforms, and currently is handled in the codes with #ifdefs.
glib provides a portable g_mkdir() API and we can use it to unify the codes without #ifdefs.
---
(no changes since v2)
Changes in v2:
- Change to use g_mkdir()
block/vvfat.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
block/vvfat.c +3 -6
@@ -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 );
Signature · 1 line
2.34.1
PATCH v5 1/18 semihosting/arm-compat-semi: Avoid using hardcoded /tmp
In reply to Bin MengFrom: Bin Meng <[email protected]>
Use g_get_tmp_dir() to get the directory to use for temporary files.
---
(no changes since v1)
semihosting/arm-compat-semi.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
semihosting/arm-compat-semi.c +2 -1
@@ -503,7 +503,8 @@ void do_common_semihosting(CPUState *cs)GET_ARG (0 );GET_ARG (1 );GET_ARG (2 ); - len =asprintf (&s,"/tmp/qemu-%x%02x" ,getpid (), (int )arg1 &0xff ); + len =asprintf (&s,"%s/qemu-%x%02x" ,g_get_tmp_dir (), +getpid (), (int )arg1 &0xff );if (len <0 ) {common_semi_set_ret (cs,-1 );break ;
Signature · 1 line
2.34.1
PATCH v5 6/18 fsdev/virtfs-proxy-helper: Use g_mkdir()
In reply to Bin MengFrom: Bin Meng <[email protected]>
Use g_mkdir() to create a directory on all platforms.
---
(no changes since v2)
Changes in v2:
- Change to use g_mkdir()
fsdev/virtfs-proxy-helper.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fsdev/virtfs-proxy-helper.c +2 -1
@@ -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);
Signature · 1 line
2.34.1
PATCH v5 4/18 tests/qtest: migration-test: Avoid using hardcoded /tmp
In reply to Bin MengFrom: Bin Meng <[email protected]>
This case was written to use hardcoded /tmp directory for temporary files. Update to use g_dir_make_tmp() for a portable implementation.
---
Changes in v5:
- Use g_autoptr(GError)
Changes in v4:
- Update the error reporting by using the GError "error" argument of g_dir_make_tmp()
- Remove the const from tmpfs declaration
Changes in v3:
- Split to a separate patch
tests/qtest/migration-test.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
tests/qtest/migration-test.c +6 -4
@@ -102,7 +102,7 @@ static bool ufd_version_check(void)#endif -static const char *tmpfs; +static char *tmpfs;/* The boot file modifies memory area in [start_address, end_address) * repeatedly. It outputs a 'B' at a fixed rate while it's still running.
@@ -2451,10 +2451,10 @@ 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 (); +g_autoptr (GError) err =NULL ;int ret;g_test_init (&argc, &argv,NULL );
@@ -2479,9 +2479,10 @@ int main(int argc, char **argv)return g_test_run (); } - tmpfs =g_mkdtemp (template); + tmpfs =g_dir_make_tmp ("migration-test-XXXXXX" , &err);if (!tmpfs) { -g_test_message ("g_mkdtemp on path (%s): %s" , template,strerror (errno)); +g_test_message ("g_dir_make_tmp on path (%s): %s" , tmpfs, + err->message); }g_assert (tmpfs);
@@ -2612,6 +2613,7 @@ int main(int argc, char **argv)g_test_message ("unable to rmdir: path (%s): %s" , tmpfs,strerror (errno)); } +g_free (tmpfs);return ret; }
Signature · 1 line
2.34.1
PATCH v5 8/18 accel/qtest: Support qtest accelerator for Windows
In reply to Bin MengFrom: Xuzhou Cheng <[email protected]>
Currently signal SIGIPI [=SIGUSR1] is used to kick the dummy CPU when qtest accelerator is used. However SIGUSR1 is unsupported on Windows. To support Windows, we add a QemuSemaphore CPUState::sem to kick the dummy CPU instead for Windows.
---
Changes in v5:
- restore to v1 version which does not touch the posix implementation
include/hw/core/cpu.h | 1 + accel/dummy-cpus.c | 14 ++++++++++++-- softmmu/cpus.c | 9 +++++---- accel/meson.build | 1 + accel/qtest/meson.build | 1 + 5 files changed, 20 insertions(+), 6 deletions(-)
include/hw/core/cpu.h +1 -0
@@ -333,6 +333,7 @@ struct CPUState {struct QemuThread *thread;#ifdef _WIN32HANDLE hThread; +QemuSemaphore sem;#endif int thread_id;bool running, has_waiter;
accel/dummy-cpus.c +12 -2
@@ -21,8 +21,6 @@static void *dummy_cpu_thread_fn (void *arg) {CPUState *cpu = arg; -sigset_t waitset; -int r;rcu_register_thread ();
@@ -32,8 +30,13 @@ static void *dummy_cpu_thread_fn(void *arg) cpu->can_do_io =1 ; current_cpu = cpu; +#ifndef _WIN32 +sigset_t waitset; +int r; +sigemptyset (&waitset);sigaddset (&waitset,SIG_IPI ); +#endif /* signal CPU creation */ cpu_thread_signal_created (cpu);
@@ -41,6 +44,7 @@ static void *dummy_cpu_thread_fn(void *arg) do { qemu_mutex_unlock_iothread(); +#ifndef _WIN32 do { int sig; r = sigwait(&waitset, &sig);
@@ -49,6 +53,9 @@ static void *dummy_cpu_thread_fn(void *arg)perror ("sigwait" ); exit(1); } +#else +qemu_sem_wait (&cpu->sem); +#endif qemu_mutex_lock_iothread ();qemu_wait_io_event (cpu); }while (!cpu->unplug);
@@ -69,4 +76,7 @@ void dummy_start_vcpu_thread(CPUState *cpu) cpu->cpu_index);qemu_thread_create (cpu->thread, thread_name, dummy_cpu_thread_fn, cpu,QEMU_THREAD_JOINABLE ); +#ifdef _WIN32 +qemu_sem_init (&cpu->sem,0 ); +#endif }
softmmu/cpus.c +5 -4
@@ -437,18 +437,19 @@ void qemu_wait_io_event(CPUState *cpu)void cpus_kick_thread (CPUState *cpu) { -#ifndef _WIN32 -int err; -if (cpu->thread_kicked) {return ; } cpu->thread_kicked = true; - err =pthread_kill (cpu->thread->thread,SIG_IPI ); + +#ifndef _WIN32 +int err =pthread_kill (cpu->thread->thread,SIG_IPI );if (err && err !=ESRCH ) {fprintf (stderr,"qemu:%s: %s" , __func__,strerror (err));exit (1 ); } +#else +qemu_sem_post (&cpu->sem);#endif }
accel/meson.build +1 -0
@@ -17,4 +17,5 @@ dummy_ss.add(files( )) specific_ss.add_all(when: ['CONFIG_SOFTMMU', 'CONFIG_POSIX'], if_true: dummy_ss) +specific_ss.add_all(when: ['CONFIG_WIN32'], if_true: dummy_ss) specific_ss.add_all(when: ['CONFIG_XEN'], if_true: dummy_ss)
accel/qtest/meson.build +1 -0
@@ -1,2 +1,3 @@ qtest_module_ss.add(when: ['CONFIG_SOFTMMU', 'CONFIG_POSIX'], if_true: files('qtest.c')) +qtest_module_ss.add(when: ['CONFIG_WIN32'], if_true: files('qtest.c'))
Signature · 1 line
2.34.1
PATCH v5 3/18 util/qemu-sockets: Use g_get_tmp_dir() to get the directory for temporary files
In reply to Bin MengFrom: Bin Meng <[email protected]>
Replace the existing logic to get the directory for temporary files with g_get_tmp_dir(), which works for win32 too.
---
(no changes since v1)
util/qemu-sockets.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
util/qemu-sockets.c +2 -3
@@ -919,9 +919,8 @@ static int unix_listen_saddr(UnixSocketAddress *saddr,if (saddr->path[0 ] || abstract) { path = saddr->path; }else { -const char *tmpdir =getenv ("TMPDIR" ); - tmpdir = tmpdir ? tmpdir :"/tmp" ; - path = pathbuf =g_strdup_printf ("%s/qemu-socket-XXXXXX" , tmpdir); + path = pathbuf =g_strdup_printf ("%s/qemu-socket-XXXXXX" , +g_get_tmp_dir ()); } pathlen =strlen (path);
Signature · 1 line
2.34.1
PATCH v5 12/18 tests/qtest: migration-test: Make sure QEMU process "to" exited after migration is canceled
In reply to Bin MengFrom: Xuzhou Cheng <[email protected]>
Make sure QEMU process "to" exited before launching another target for migration in the test_multifd_tcp_cancel case.
---
(no changes since v3)
Changes in v3:
- Add a usleep(1) in the busy wait loop
Changes in v2:
- Change to a busy wait after migration is canceled
tests/qtest/migration-test.c | 4 ++++ 1 file changed, 4 insertions(+)
tests/qtest/migration-test.c +4 -0
@@ -2140,6 +2140,10 @@ static void test_multifd_tcp_cancel(void)wait_for_migration_pass (from);migrate_cancel (from); +/* Make sure QEMU process "to" exited */ +while (qtest_probe_child (to)) { +usleep (1 ); + } args = (MigrateStart ){ .only_target = true,
Signature · 1 line
2.34.1
PATCH v5 7/18 hw/usb: dev-mtp: Use g_mkdir()
In reply to Bin MengFrom: Bin Meng <[email protected]>
Use g_mkdir() to create a directory on all platforms.
---
(no changes since v2)
Changes in v2:
- Change to use g_mkdir()
hw/usb/dev-mtp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
hw/usb/dev-mtp.c +2 -2
@@ -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,
Signature · 1 line
2.34.1
PATCH v5 11/18 tests/qtest: Support libqtest to build and run on Windows
In reply to Bin MengFrom: Bin Meng <[email protected]>
At present the libqtest codes were written to depend on several POSIX APIs, including fork(), kill() and waitpid(). Unfortunately these APIs are not available on Windows.
This commit implements the corresponding functionalities using win32 native APIs. With this change, all qtest cases can build successfully on a Windows host, and we can start qtest testing on Windows now.
---
(no changes since v2)
Changes in v2:
- Move the enabling of building qtests on Windows to a separate patch to keep bisectablity
- Call socket_init() unconditionally
- Add a missing CloseHandle() call
tests/qtest/libqtest.c | 95 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 93 insertions(+), 2 deletions(-)
tests/qtest/libqtest.c +93 -2
@@ -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 *);
@@ -118,10 +131,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 +157,23 @@ void qtest_set_expected_status(QTestState *s, int status)void qtest_kill_qemu (QTestState *s) {pid_t pid = s->qemu_pid; +#ifndef _WIN32int wstatus; +#else +DWORD ret, exit_code; +#endif /* Skip wait if qtest_probe_child already reaped. */ if (pid !=-1 ) { +#ifndef _WIN32kill (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 +181,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 +198,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 +286,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 +345,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 +354,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 +363,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 +372,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 +395,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 +416,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 _WIN32if (getenv ("QTEST_STOP" )) {kill (s->qemu_pid,SIGSTOP ); } +#endif /* ask endianness of the target */
@@ -392,6 +482,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",
Signature · 1 line
2.34.1
PATCH v5 9/18 tests/qtest: Use send/recv for socket communication
In reply to Bin MengFrom: Xuzhou Cheng <[email protected]>
Socket communication in the libqtest and libqmp codes uses read() and write() which work on any file descriptor on *nix, and sockets in *nix are an example of a file descriptor.
However sockets on Windows do not use *nix-style file descriptors, so read() and write() cannot be used on sockets on Windows. Switch over to use send() and recv() instead which work on both Windows and *nix.
---
(no changes since v2)
Changes in v2:
- Introduce qemu_send_full() and use it
include/qemu/sockets.h | 2 ++ tests/qtest/libqmp.c | 5 +++-- tests/qtest/libqtest.c | 4 ++-- util/osdep.c | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 40 insertions(+), 4 deletions(-)
include/qemu/sockets.h +2 -0
@@ -33,6 +33,8 @@ int qemu_socketpair(int domain, int type, int protocol, int sv[2]);#endif 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);
tests/qtest/libqmp.c +3 -2
@@ -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 ; }
tests/qtest/libqtest.c +2 -2
@@ -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 ; }
util/osdep.c +33 -0
@@ -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;
Signature · 1 line
2.34.1
PATCH v5 17/18 .gitlab-ci.d/windows.yml: Increase the timeout to 90 minutes
In reply to Bin MengFrom: Bin Meng <[email protected]>
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.
---
(no changes since v2)
Changes in v2:
- Change the timeout limit to 90 minutes
.gitlab-ci.d/windows.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
.gitlab-ci.d/windows.yml +2 -2
@@ -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
@@ -60,7 +60,7 @@ msys2-64bit: - $env:MSYSTEM = 'MINGW64' # Start a 64 bit Mingw environment - $env:MSYS = 'winsymlinks:native' # Enable native Windows symlink - .\msys64\usr\bin\bash -lc './configure --target-list=x86_64-softmmu - --enable-capstone --without-default-devices' + --enable-capstone' - .\msys64\usr\bin\bash -lc 'make' - .\msys64\usr\bin\bash -lc 'make check || { cat build/meson-logs/testlog.txt; exit 1; } ;'
Signature · 1 line
2.34.1
PATCH v5 10/18 tests/qtest: libqtest: Install signal handler via signal()
In reply to Bin MengFrom: Bin Meng <[email protected]>
At present the codes uses sigaction() to install signal handler with a flag SA_RESETHAND. Such usage can be covered by the signal() API that is a simplified interface to the general sigaction() facility.
Update to use signal() to install the signal handler, as it is available on Windows which we are going to support.
---
Changes in v5:
- Replace sighandler_t with its actual definition, since it is not available on BSD hosts
tests/qtest/libqtest.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-)
tests/qtest/libqtest.c +3 -11
@@ -66,7 +66,7 @@ struct QTestState };static GHookList abrt_hooks; -static struct sigaction sigact_old; +static void (*sighandler_old)(int );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)
Signature · 1 line
2.34.1
PATCH v5 16/18 io/channel-watch: Fix socket watch on Windows
In reply to Bin MengFrom: Bin Meng <[email protected]>
Random failure was observed when running qtests on Windows due to "Broken pipe" detected by qmp_fd_receive(). What happened is that the qtest executable sends testing data over a socket to the QEMU under test but no response is received. The errno of the recv() call from the qtest executable indicates ETIMEOUT, due to the qmp chardev's tcp_chr_read() is never called to receive testing data hence no response is sent to the other side.
tcp_chr_read() is registered as the callback of the socket watch GSource. The reason of the callback not being called by glib, is that the source check fails to indicate the source is ready. There are two socket watch sources created to monitor the same socket event object from the char-socket backend in update_ioc_handlers(). During the source check phase, qio_channel_socket_source_check() calls WSAEnumNetworkEvents() to 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.
---
(no changes since v1)
io/channel-watch.c | 4 ---- 1 file changed, 4 deletions(-)
io/channel-watch.c +0 -4
@@ -115,17 +115,13 @@ static gboolean qio_channel_socket_source_check(GSource *source) {static struct timeval tv0; -QIOChannelSocketSource *ssource = (QIOChannelSocketSource *)source; -WSANETWORKEVENTS ev;fd_set rfds, wfds, xfds;if (!ssource->condition) {return 0 ; } -WSAEnumNetworkEvents (ssource->socket, ssource->ioc->event, &ev); -FD_ZERO (&rfds);FD_ZERO (&wfds);FD_ZERO (&xfds);
Signature · 1 line
2.34.1
PATCH v5 18/18 tests/qtest: Enable qtest build on Windows
In reply to Bin MengFrom: Bin Meng <[email protected]>
Now that we have fixed various test case issues as seen when running on Windows, let's enable the qtest build on Windows.
---
(no changes since v3)
Changes in v3:
- Drop the host test
Changes in v2:
- new patch: "tests/qtest: Enable qtest build on Windows"
tests/qtest/meson.build | 6 ------ 1 file changed, 6 deletions(-)
tests/qtest/meson.build +0 -6
@@ -1,9 +1,3 @@ -# All QTests for now are POSIX-only, but the dependencies are -# really in libqtest, not in the testcases themselves. -if not config_host.has_key('CONFIG_POSIX') - subdir_done() -endif - slow_qtests = { 'ahci-test' : 60, 'bios-tables-test' : 120,
Signature · 1 line
2.34.1
PATCH v5 13/18 tests/qtest: libqtest: Correct the timeout unit of blocking receive calls for win32
In reply to Bin MengFrom: Bin Meng <[email protected]>
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.
---
(no changes since v1)
tests/qtest/libqtest.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
tests/qtest/libqtest.c +10 -1
@@ -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"
@@ -103,8 +104,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 _WIN32struct timeval timeout = { .tv_sec =SOCKET_TIMEOUT , .tv_usec =0 }; +#else +DWORD timeout =SOCKET_TIMEOUT ; +#endif if (setsockopt (sock,SOL_SOCKET ,SO_RCVTIMEO , (void *)&timeout,sizeof (timeout))) {
Signature · 1 line
2.34.1
PATCH v5 14/18 io/channel-watch: Drop a superfluous '#ifdef WIN32'
In reply to Bin MengFrom: Bin Meng <[email protected]>
In the win32 version qio_channel_create_socket_watch() body there is no need to do a '#ifdef WIN32'.
---
(no changes since v1)
io/channel-watch.c | 2 -- 1 file changed, 2 deletions(-)
io/channel-watch.c +0 -2
@@ -285,11 +285,9 @@ GSource *qio_channel_create_socket_watch(QIOChannel *ioc,GSource *source;QIOChannelSocketSource *ssource; -#ifdef WIN32 WSAEventSelect (socket, ioc->event,FD_READ |FD_ACCEPT |FD_CLOSE |FD_CONNECT |FD_WRITE |FD_OOB ); -#endif source =g_source_new (&qio_channel_socket_source_funcs,sizeof (QIOChannelSocketSource));
Signature · 1 line
2.34.1
PATCH v5 15/18 io/channel-watch: Drop the unnecessary cast
In reply to Bin MengFrom: Bin Meng <[email protected]>
There is no need to do a type cast on ssource->socket as it is already declared as a SOCKET.
---
(no changes since v2)
Changes in v2:
- new patch: "io/channel-watch: Drop the unnecessary cast"
io/channel-watch.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
io/channel-watch.c +3 -3
@@ -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 ) {
Signature · 1 line
2.34.1
Quoted 3 lines · Bin Meng
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.
I'm happy to take this whole series through my testing/next however I don't have working CI for the month so need to wait for my minutes to reset. Have you done a full CI run* with this?
(*make sure any CI run is only on a repo forked from
https://gitlab.com/qemu-project as you won't get the discount cost factor otherwise)
Quoted 79 lines
Changes in v5:
- Rebase on qemu/master
- Drop patches that are already merged
- Useg_autoptr(GError)
- Restore to v1 version which does not touch the posix implementation
- Replacesighandler_twith its actual definition, since it is not available on BSD hostsChanges in v4:
- Update the error reporting by using the GError "error" argument ofg_dir_make_tmp()
- Remove the const from tmpfs declarationChanges in v3:
- Split to a separate patch
- Add a usleep(1) in the busy wait loop
- Drop the host testChanges in v2:
- Useg_autofreeto declare the variable
- Change to useg_mkdir()
- Change to useg_mkdir()
- Change to useg_mkdir()
- Introduceqemu_send_full()and use it
- Move the enabling of building qtests on Windows to a separate patch to keep bisectablity
- Callsocket_init()unconditionally
- Add a missingCloseHandle()call
- Change to a busy wait after migration is canceled
- new patch: "io/channel-watch: Drop the unnecessary cast"
- Change the timeout limit to 90 minutes
- new patch: "tests/qtest: Enable qtest build on Windows"Bin Meng (15):
semihosting/arm-compat-semi: Avoid using hardcoded /tmp
tcg: Avoid using hardcoded /tmp
util/qemu-sockets: Useg_get_tmp_dir()to get the directory for
temporary files
tests/qtest: migration-test: Avoid using hardcoded /tmp block/vvfat: Unify themkdir()call fsdev/virtfs-proxy-helper: Useg_mkdir()
hw/usb: dev-mtp: Useg_mkdir()
tests/qtest: libqtest: Install signal handler viasignal()tests/qtest: Support libqtest to build and run on Windows 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.gitlab-ci.d/windows.yml: Increase the timeout to 90 minutes tests/qtest: Enable qtest build on WindowsXuzhou Cheng (3):
accel/qtest: Support qtest accelerator for Windows tests/qtest: Use send/recv for socket communication tests/qtest: migration-test: Make sure QEMU process "to" exited after
migration is canceledinclude/hw/core/cpu.h | 1 + include/qemu/sockets.h | 2 + accel/dummy-cpus.c | 14 +++- block/vvfat.c | 9 +-- fsdev/virtfs-proxy-helper.c | 3 +- hw/usb/dev-mtp.c | 4 +- io/channel-watch.c | 12 +--- semihosting/arm-compat-semi.c | 3 +- softmmu/cpus.c | 9 +-- tcg/tcg.c | 3 +- tests/qtest/libqmp.c | 5 +- tests/qtest/libqtest.c | 124 +++++++++++++++++++++++++++++----- tests/qtest/migration-test.c | 14 ++-- util/osdep.c | 33 +++++++++ util/qemu-sockets.c | 5 +- .gitlab-ci.d/windows.yml | 4 +- accel/meson.build | 1 + accel/qtest/meson.build | 1 + tests/qtest/meson.build | 6 -- 19 files changed, 194 insertions(+), 59 deletions(-)
Signature · 1 line
Alex Bennée
Quoted 4 lines · Alex Bennée
Bin Meng <[email protected]> writes:
Quoted 8 lines
Quoted 3 lines
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.
I'm happy to take this whole series through my testing/next however I don't have working CI for the month so need to wait for my minutes to reset. Have you done a full CI run* with this?
Yes, gitlab CI passed.
Quoted 4 lines
(*make sure any CI run is only on a repo forked from
https://gitlab.com/qemu-project as you won't get the discount cost factor otherwise)
Regards,
Bin
Re: [PATCH v5 17/18] .gitlab-ci.d/windows.yml: Increase the timeout to 90 minutes
In reply to Bin MengHi
Quoted 9 lines · Bin Meng
From: Bin Meng <[email protected]>
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.
Quoted 7 lines
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 <[email protected]>
Given the discussion in "[PATCH v2 36/39] .gitlab-ci.d/windows.yml:
Increase the timeout to 90 minutes", maybe we should drop this patch for now?
---
Quoted 37 lines
(no changes since v2)
Changes in v2:
- Change the timeout limit to 90 minutes.gitlab-ci.d/windows.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-).gitlab-ci.d/windows.yml +2
-2@@ -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@@ -60,7 +60,7 @@ msys2-64bit: - $env:MSYSTEM = 'MINGW64' # Start a 64 bit Mingw environment - $env:MSYS = 'winsymlinks:native' # Enable native Windows symlink - .\msys64\usr\bin\bash -lc './configure --target-list=x86_64-softmmu - --enable-capstone --without-default-devices' + --enable-capstone' - .\msys64\usr\bin\bash -lc 'make' - .\msys64\usr\bin\bash -lc 'make check || { cat
build/meson-logs/testlog.txt; exit 1; } ;'--
2.34.1
Signature · 1 line
Marc-André Lureau
Re: [PATCH v5 17/18] .gitlab-ci.d/windows.yml: Increase the timeout to 90 minutes
Quoted 18 lines · Marc-André Lureau
Hi
Quoted 14 lines · Bin Meng
From: Bin Meng <[email protected]>
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.
Quoted 5 lines
Quoted 1 line
Signed-off-by Bin Meng <[email protected]>Given the discussion in "[PATCH v2 36/39]
.gitlab-ci.d/windows.yml: Increase the timeout to 90 minutes", maybe we should drop this patch for now?
Unfortunately there is not a good solution to make the CI complete within 90 minutes to finish the Windows qTtest CI without "--without-default-devices"
Regards,
Bin
Re: [PATCH v5 08/18] accel/qtest: Support qtest accelerator for Windows
In reply to Thomas HuthQuoted 31 lines · Thomas Huth
Quoted 21 lines · Bin Meng
From: Xuzhou Cheng <[email protected]>
Currently signal SIGIPI [=SIGUSR1] is used to kick the dummy CPU when qtest accelerator is used. However SIGUSR1 is unsupported on Windows. To support Windows, we add a QemuSemaphore
CPUState::semto kick the dummy CPU instead for Windows.Signed-off-by Xuzhou Cheng <[email protected]>Signed-off-by Bin Meng <[email protected]>Reviewed-by Marc-André Lureau <[email protected]>---
Changes in v5:
- restore to v1 version which does not touch the posix implementationinclude/hw/core/cpu.h | 1 + accel/dummy-cpus.c | 14 ++++++++++++-- softmmu/cpus.c | 9 +++++---- accel/meson.build | 1 + accel/qtest/meson.build | 1 + 5 files changed, 20 insertions(+), 6 deletions(-)...
Quoted 7 lines
accel/meson.build +0
-0@@ -17,4 +17,5 @@ dummy_ss.add(files( ))
Quoted 8 lines
accel/meson.build dummy_ss.add(files( · line 20
Quoted 2 lines
accel/meson.build +1
-0specific_ss.add_all(when: ['CONFIG_SOFTMMU', 'CONFIG_POSIX'], if_true: dummy_ss) +specific_ss.add_all(when: ['CONFIG_WIN32'], if_true: dummy_ss)Sorry for not noticing it earlier, but I just noticed that this likely should also only be added for softmmu builds on Windows?
So instead of adding a new line, I'd rather simply remove the
CONFIG_POSIXfrom the previous line?
Yes, I think that should work.
Quoted 13 lines
accel/qtest/meson.build line 3
Quoted 10 lines
accel/meson.build +0
-0specific_ss.add_all(when: ['CONFIG_XEN'], if_true: dummy_ss)accel/qtest/meson.build +1
-0@@ -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'))Dito, rather remove the
CONFIG_POSIXin the previous line?
Regards,
Bin
Re: [PATCH v5 08/18] accel/qtest: Support qtest accelerator for Windows
In reply to Bin MengQuoted 21 lines · Bin Meng
From: Xuzhou Cheng <[email protected]>
Currently signal SIGIPI [=SIGUSR1] is used to kick the dummy CPU when qtest accelerator is used. However SIGUSR1 is unsupported on Windows. To support Windows, we add a QemuSemaphore
CPUState::semto kick the dummy CPU instead for Windows.Signed-off-by Xuzhou Cheng <[email protected]>Signed-off-by Bin Meng <[email protected]>Reviewed-by Marc-André Lureau <[email protected]>---
Changes in v5:
- restore to v1 version which does not touch the posix implementationinclude/hw/core/cpu.h | 1 + accel/dummy-cpus.c | 14 ++++++++++++-- softmmu/cpus.c | 9 +++++---- accel/meson.build | 1 + accel/qtest/meson.build | 1 + 5 files changed, 20 insertions(+), 6 deletions(-)
...
accel/meson.build dummy_ss.add(files( · line 20
Quoted 9 lines
accel/meson.build +1
-0@@ -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)
Sorry for not noticing it earlier, but I just noticed that this likely should also only be added for softmmu builds on Windows?
So instead of adding a new line, I'd rather simply remove the CONFIG_POSIX from the previous line?
accel/qtest/meson.build line 3
Quoted 9 lines
accel/meson.build +0
-0specific_ss.add_all(when: ['CONFIG_XEN'], if_true: dummy_ss)accel/qtest/meson.build +1
-0@@ -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'))
Dito, rather remove the CONFIG_POSIX in the previous line?
Thomas
Re: [PATCH v5 10/18] tests/qtest: libqtest: Install signal handler via signal()
In reply to Bin MengQuoted 46 lines · Bin Meng
From: Bin Meng <[email protected]>
At present the codes uses
sigaction()to install signal handler with a flagSA_RESETHAND. Such usage can be covered by thesignal()API that is a simplified interface to the generalsigaction()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 <[email protected]>Reviewed-by Marc-André Lureau <[email protected]>---
Changes in v5:
- Replacesighandler_twith its actual definition, since it is not available on BSD hoststests/qtest/libqtest.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-)tests/qtest/libqtest.c +1
-10@@ -66,7 +66,7 @@ struct QTestState };static GHookList abrt_hooks; -static struct sigaction sigact_old; +static void (*sighandler_old)(int );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);
tests/qtest/libqtest.c static void sigabrt_handler(int signo) · line 190
Quoted 10 lines
tests/qtest/libqtest.c +2
-1+ 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)
Hmm, did you notice the error from checkpatch.pl ?
ERROR: use sigaction to establish signal handlers; signal is not portable
... rationale is given in the commit description here:
https://gitlab.com/qemu-project/qemu/-/commit/e8c2091d4c4dd
... but since we likely don't care about continuing running after the first signal has been delivered, I guess it's ok here to use signal() instead of sigaction?
Thomas
Re: [PATCH v5 17/18] .gitlab-ci.d/windows.yml: Increase the timeout to 90 minutes
In reply to Bin MengQuoted 38 lines · Bin Meng
From: Bin Meng <[email protected]>
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 <[email protected]>---
(no changes since v2)
Changes in v2:
- Change the timeout limit to 90 minutes.gitlab-ci.d/windows.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-).gitlab-ci.d/windows.yml +1
-1@@ -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
.gitlab-ci.d/windows.yml msys2-64bit: · line 66
Quoted 8 lines
.gitlab-ci.d/windows.yml +1
-1@@ -60,7 +60,7 @@ msys2-64bit: - $env:MSYSTEM = 'MINGW64' # Start a 64 bit Mingw environment - $env:MSYS = 'winsymlinks:native' # Enable native Windows symlink - .\msys64\usr\bin\bash -lc './configure --target-list=x86_64-softmmu - --enable-capstone --without-default-devices' + --enable-capstone' - .\msys64\usr\bin\bash -lc 'make' - .\msys64\usr\bin\bash -lc 'make check || { cat build/meson-logs/testlog.txt; exit 1; } ;'
I just gave your patch set a try in the gitlab-CI, and for me it even did not finish within 90 minutes:
https://gitlab.com/thuth/qemu/-/jobs/3156107033
I think we have to do something different if we want to run the qtests in this CI pipeline ... e.g. disable some subsystems? Try if compiling with "-O1" is faster than compiling with "-O2" ? Use a different target-list ? (well, the latter would be a pity since we would lose compile-testing the HAX and WHPX support) ... Sorry, I've got no really good clue here :-/
Additionally, there was also this error in line 2792:
ERROR:../tests/unit/test-aio.c:501:test_timer_schedule: assertion failed: (aio_poll(ctx, true))
Is that something new?
Thomas
Re: [PATCH v5 10/18] tests/qtest: libqtest: Install signal handler via signal()
In reply to Thomas HuthQuoted 61 lines · Thomas Huth
Quoted 46 lines · Bin Meng
From: Bin Meng <[email protected]>
At present the codes uses
sigaction()to install signal handler with a flagSA_RESETHAND. Such usage can be covered by thesignal()API that is a simplified interface to the generalsigaction()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 <[email protected]>Reviewed-by Marc-André Lureau <[email protected]>---
Changes in v5:
- Replacesighandler_twith its actual definition, since it is not available on BSD hoststests/qtest/libqtest.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-)tests/qtest/libqtest.c +1
-10@@ -66,7 +66,7 @@ struct QTestState };static GHookList abrt_hooks; -static struct sigaction sigact_old; +static void (*sighandler_old)(int );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);tests/qtest/libqtest.c static void sigabrt_handler(int signo) · line 190
Quoted 10 lines
tests/qtest/libqtest.c +2
-1+ 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)Hmm, did you notice the error from checkpatch.pl ?
Quoted 5 lines
ERROR: use sigaction to establish signal handlers; signal is not portable
... rationale is given in the commit description here:
Yes, I noticed this checkpatch warning.
Quoted 5 lines
... but since we likely don't care about continuing running after the first signal has been delivered, I guess it's ok here to use
signal()instead of sigaction?
I think so. I mentioned in the commit message that the code is using SA_RESETHAND for sigaction, and such usage can be replaced with signal().
Regards,
Bin
Re: [PATCH v5 17/18] .gitlab-ci.d/windows.yml: Increase the timeout to 90 minutes
In reply to Thomas HuthQuoted 52 lines · Thomas Huth
Quoted 38 lines · Bin Meng
From: Bin Meng <[email protected]>
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 <[email protected]>---
(no changes since v2)
Changes in v2:
- Change the timeout limit to 90 minutes.gitlab-ci.d/windows.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-).gitlab-ci.d/windows.yml +1
-1@@ -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.gitlab-ci.d/windows.yml msys2-64bit: · line 66
Quoted 8 lines
.gitlab-ci.d/windows.yml +1
-1@@ -60,7 +60,7 @@ msys2-64bit: - $env:MSYSTEM = 'MINGW64' # Start a 64 bit Mingw environment - $env:MSYS = 'winsymlinks:native' # Enable native Windows symlink - .\msys64\usr\bin\bash -lc './configure --target-list=x86_64-softmmu - --enable-capstone --without-default-devices' + --enable-capstone' - .\msys64\usr\bin\bash -lc 'make' - .\msys64\usr\bin\bash -lc 'make check || { cat build/meson-logs/testlog.txt; exit 1; } ;'I just gave your patch set a try in the gitlab-CI, and for me it even did not finish within 90 minutes:
Quoted 1 line
That's longer than mine. My test took about 80 minutes.
https://gitlab.com/lbmeng/qemu/-/jobs/3137520040
Not sure if it relates to the MSYS2 required tools installation before the build starts? Or the shared runner was too overloaded?
Quoted 6 lines
I think we have to do something different if we want to run the qtests in this CI pipeline ... e.g. disable some subsystems? Try if compiling with "-O1" is faster than compiling with "-O2" ? Use a different target-list ? (well, the latter would be a pity since we would lose compile-testing the HAX and WHPX support) ... Sorry, I've got no really good clue here :-/
The gitlab shared Windows runners are too slow. Is there any alternatives for this (e.g.: github, azure)?
Quoted 8 lines
Additionally, there was also this error in line 2792:
ERROR:../tests/unit/test-aio.c:501:test_timer_schedule: assertion failed:
(aio_poll(ctx, true))Is that something new?
I never saw this error before. I guess it's unrelated as this series did not touch unit tests but qtests.
Regards,
Bin
Re: [PATCH v5 11/18] tests/qtest: Support libqtest to build and run on Windows
In reply to Bin MengHi Bin
Quoted 124 lines · Bin Meng
From: Bin Meng <[email protected]>
At present the libqtest codes were written to depend on several POSIX APIs, including
fork(),kill()andwaitpid(). 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 <[email protected]>Signed-off-by Bin Meng <[email protected]>Reviewed-by Marc-André Lureau <[email protected]>---
(no changes since v2)
Changes in v2:
- Move the enabling of building qtests on Windows to a separate patch to keep bisectablity
- Callsocket_init()unconditionally
- Add a missingCloseHandle()calltests/qtest/libqtest.c | 95 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 93 insertions(+), 2 deletions(-)tests/qtest/libqtest.c +32
-0@@ -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 *);@@ -118,10 +131,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 +157,23 @@ void qtest_set_expected_status(QTestState *s, int status)void qtest_kill_qemu (QTestState *s) {pid_t pid = s->qemu_pid; +#ifndef _WIN32int wstatus; +#else +DWORD ret, exit_code; +#endif /* Skip wait if qtest_probe_child already reaped. */ if (pid !=-1 ) { +#ifndef _WIN32kill (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 +181,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_WIN32wstatus = s->wstatus; if (WIFEXITED(wstatus) && WEXITSTATUS(wstatus) != s->expected_status){
fprintf(stderr, "%s:%d:kill_qemu()tried to terminate QEMU "
tests/qtest/libqtest.c void qtest_kill_qemu(QTestState *s) · line 203
Quoted 6 lines
tests/qtest/libqtest.c +2
-0@@ -165,6 +198,16 @@ void qtest_kill_qemu(QTestState *s) __FILE__, __LINE__, sig, signame, dump); abort(); } +#else +GetExitCodeProcess ((HANDLE )pid, &exit_code);
That doesn't fulfill the doc expectations: "It is safe to call this function multiple times". pid will be -1 after the first call. I think it should save the "exit_code", similar to how "wstatus" is saved in posix.
please update the patch
+ CloseHandle((HANDLE)pid);
Quoted 136 lines
tests/qtest/libqtest.c +28
-0+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 +286,38 @@ static const char *qtest_qemu_binary(void)return qemu_bin; } +#ifdef _WIN32 +static pid_t qtest_create_process (char *cmd) +{ +STARTUPINFO si; +PROCESS_INFORMATION pi; +BOOL ret; + +ZeroMemory (&si,sizeof (si)); + si.cb =sizeof (si); +ZeroMemory (&pi,sizeof (pi)); + + ret =CreateProcess (NULL ,/* module name */ + cmd,/* command line */ +NULL ,/* process handle not inheritable */ +NULL ,/* thread handle not inheritable */ + FALSE,/* set handle inheritance to FALSE */ +0 ,/* No creation flags */ +NULL ,/* use parent's environment block */ +NULL ,/* use parent's starting directory */ + &si,/* pointer to STARTUPINFO structure */ + &pi/* pointer to PROCESS_INFORMATION structure */
tests/qtest/libqtest.c +13
-1+ ); +if (ret ==0 ) { +fprintf (stderr,"%s:%d: unable to create a new process (%s)\n" , + __FILE__, __LINE__,strerror (GetLastError ())); +abort (); + } + + return (pid_t)pi.hProcess; +} +#endif /* _WIN32 */ +QTestState *qtest_init_without_qmp_handshake (const char *extra_args) {QTestState *s;@@ -270,6 +345,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 +354,7 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args)qtest_add_abrt_handler (kill_qemu_hook_func ,s ); - command =g_strdup_printf ("exec %s %s" + command =g_strdup_printf (CMD_EXEC "%s %s" "-qtest unix:%s " "-qtest-log %s ""-chardev socket,path=%s,id=char0 "tests/qtest/libqtest.c +1
-1@@ -287,7 +363,7 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args)"%s" " -accel qtest" , qemu_binary, tracearg, socket_path, -getenv ("QTEST_LOG" ) ?"/dev/fd/2" :"/dev/null" , +getenv ("QTEST_LOG" ) ?DEV_STDERR :DEV_NULL , qmp_socket_path,extra_args ?: "");tests/qtest/libqtest.c +1
-0@@ -296,6 +372,7 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args) s->pending_events = NULL; s->wstatus =0 ; s->expected_status =0 ; +#ifndef _WIN32 s->qemu_pid =fork ();if (s->qemu_pid ==0 ) {#ifdef
__linux__tests/qtest/libqtest.c +3
-0@@ -318,6 +395,9 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args) execlp("/bin/sh", "sh", "-c", command, NULL); exit(1); } +#else + s->qemu_pid =qtest_create_process (command); +#endif /* _WIN32 */ g_free (command);s->fd = socket_accept(sock);tests/qtest/libqtest.c +11
-0@@ -336,9 +416,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 _WIN32if (getenv ("QTEST_STOP" )) {kill (s->qemu_pid,SIGSTOP ); } +#endif /* ask endianness of the target */ @@ -392,6 +482,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
Signature · 1 line
Marc-André Lureau
Re: [PATCH v5 12/18] tests/qtest: migration-test: Make sure QEMU process "to" exited after migration is canceled
In reply to Bin MengHi
Quoted 25 lines · Bin Meng
From: Xuzhou Cheng <[email protected]>
Make sure QEMU process "to" exited before launching another target for migration in the
test_multifd_tcp_cancelcase.Signed-off-by Xuzhou Cheng <[email protected]>Signed-off-by Bin Meng <[email protected]>---
(no changes since v3)
Changes in v3:
- Add a usleep(1) in the busy wait loopChanges in v2:
- Change to a busy wait after migration is canceledtests/qtest/migration-test.c | 4 ++++ 1 file changed, 4 insertions(+)tests/qtest/migration-test.c +0
-0
tests/qtest/migration-test.c static void test_multifd_tcp_cancel(void) · line 2148
Quoted 9 lines
tests/qtest/migration-test.c +4
-0@@ -2140,6 +2140,10 @@ static void test_multifd_tcp_cancel(void)wait_for_migration_pass (from);migrate_cancel (from); +/* Make sure QEMU process "to" exited */ +while (qtest_probe_child (to)) { +usleep (1 ); + }
As discussed earlier, I think we can introduce a qtest_wait_qemu() instead, something like that should work:
-void qtest_kill_qemu(QTestState *s)
+static void qtest_check_status(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;
- }
-
/*
* 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;
+ int wstatus = s->wstatus;
if (WIFEXITED(wstatus) && WEXITSTATUS(wstatus) != s->expected_status) {
fprintf(stderr, "%s:%d: kill_qemu() tried to terminate QEMU "
"process but encountered exit status %d (expected %d)\n",
@@ -208,17 +191,50 @@ void qtest_kill_qemu(QTestState *s)
abort();
}
#else
- GetExitCodeProcess((HANDLE)pid, &exit_code);
- CloseHandle((HANDLE)pid);
- if (exit_code != s->expected_status) {
+ if (s->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);
+ __FILE__, __LINE__, s->exit_code, s->expected_status);
abort();
} #endif
}
+void qtest_kill_qemu(QTestState *s)
+{
+ /* Skip wait if qtest_probe_child already reaped. */
+ if (s->qemu_pid != -1) {
+#ifndef _WIN32
+ kill(s->qemu_pid, SIGTERM);
+#else
+ TerminateProcess((HANDLE)s->qemu_pid, s->expected_status);
+#endif
+ qtest_wait_qemu(s);
+ s->qemu_pid = -1;
+ }
+
+ qtest_check_status(s);
+}
+
+void qtest_wait_qemu(QTestState *s)
+{
+#ifndef _WIN32
+ pid_t pid;
+
+ TFR(pid = waitpid(s->qemu_pid, &s->wstatus, 0));
+ assert(pid == s->qemu_pid);
+#else
+ DWORD ret;
+
+ ret = WaitForSingleObject((HANDLE)s->qemu_pid, INFINITE); + assert(ret == WAIT_OBJECT_0); + GetExitCodeProcess((HANDLE)s->qemu_pid, &s->exit_code); + CloseHandle((HANDLE)s->qemu_pid);
+#endif
+
+ qtest_check_status(s);
+}
+
static void kill_qemu_hook_func(void *s)
{
qtest_kill_qemu(s);Signature · 1 line
Marc-André Lureau
Hi Alex,
Quoted 10 lines · Bin Meng
Quoted 8 lines · Alex Bennée
Quoted 3 lines · Bin Meng
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.
Quoted 11 lines
Quoted 4 lines
I'm happy to take this whole series through my testing/next however I don't have working CI for the month so need to wait for my minutes to reset. Have you done a full CI run* with this?
Yes, gitlab CI passed.
Quoted 4 lines
(*make sure any CI run is only on a repo forked from
https://gitlab.com/qemu-project as you won't get the discount cost factor otherwise)
Patch 4 and 10 are already applied in the mainline by Thomas.
Daniel will queue patch 14, 15, 16.
Could you please help queue patch 1, 2, 3, 5, 6, 7, 9, 13 from this series?
I will rework the rest of the patches.
Regards,
Bin
Quoted 19 lines · CEST Bin Meng
Hi Alex,
Quoted 6 lines · Bin Meng
Quoted 5 lines · Alex Bennée
Quoted 3 lines · Bin Meng
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.
Quoted 9 lines
Quoted 3 lines
I'm happy to take this whole series through my testing/next however I don't have working CI for the month so need to wait for my minutes to reset. Have you done a full CI run* with this?
Yes, gitlab CI passed.
Quoted 3 lines
(*make sure any CI run is only on a repo forked from
https://gitlab.com/qemu-project as you won't get the discount cost factor otherwise)
Quoted 5 lines
Patch 4 and 10 are already applied in the mainline by Thomas.
Daniel will queue patch 14, 15, 16.
Could you please help queue patch 1, 2, 3, 5, 6, 7, 9, 13 from this series?
I already had patch 6 queued on my end:
https://github.com/cschoenebeck/qemu/commits/9p.next
Next 9p PR end of this week. But if somebody else is faster then I'll just drop it later on.
Best regards,
Christian Schoenebeck
Quoted 25 lines · Bin Meng
Hi Alex,
Quoted 10 lines · Bin Meng
Quoted 8 lines · Alex Bennée
Quoted 3 lines · Bin Meng
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.
Quoted 11 lines
Quoted 4 lines
I'm happy to take this whole series through my testing/next however I don't have working CI for the month so need to wait for my minutes to reset. Have you done a full CI run* with this?
Yes, gitlab CI passed.
Quoted 4 lines
(*make sure any CI run is only on a repo forked from
https://gitlab.com/qemu-project as you won't get the discount cost factor otherwise)
Quoted 6 lines
Patch 4 and 10 are already applied in the mainline by Thomas.
Daniel will queue patch 14, 15, 16.
Could you please help queue patch 1, 2, 3, 5, 6, 7, 9, 13 from this series?
I've queued those except 13 into my testing/next. There was a merge failure so I guess a dependency on another patch?
Quoted 5 lines
I will rework the rest of the patches.
Regards,
Bin
Signature · 1 line
Alex Bennée
Re: [PATCH v5 09/18] tests/qtest: Use send/recv for socket communication
In reply to Bin MengQuoted 126 lines · Bin Meng
From: Xuzhou Cheng <[email protected]>
Socket communication in the libqtest and libqmp codes uses
read()andwrite()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()andwrite()cannot be used on sockets on Windows. Switch over to usesend()andrecv()instead which work on both Windows and *nix.Signed-off-by Xuzhou Cheng <[email protected]>Signed-off-by Bin Meng <[email protected]>Reviewed-by Marc-André Lureau <[email protected]>---
(no changes since v2)
Changes in v2:
- Introduceqemu_send_full()and use itinclude/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(-)include/qemu/sockets.h +2
-0@@ -33,6 +33,8 @@ int qemu_socketpair(int domain, int type, int protocol, int sv[2]);#endif 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);tests/qtest/libqmp.c +3
-2@@ -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 ; }tests/qtest/libqtest.c +2
-2@@ -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 ; }util/osdep.c +26
-0@@ -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;
util/osdep.c int qemu_accept(int s, struct sockaddr *addr, socklen_t *addrlen) · line 540
Quoted 10 lines
util/osdep.c +7
-0+ buf += ret; + total += ret; + } + +return total; +} +void qemu_set_hw_version (const char *version) { hw_version = version;
Hmm something goes wrong here:
FAILED: tests/qtest/libqos/libqos.fa.p/.._libqtest.c.o
cc -m64 -mcx16 -Itests/qtest/libqos/libqos.fa.p -Itests/qtest/libqos -I../../tests/qtest/libqos -I. -Iqapi -Itrace -Iui -Iui/shader -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -fdiagnostics-color=auto -Wall -Winvalid-pch -Werror -std=gnu11 -O2 -g -isystem /home/alex/lsrc/qemu.git/linux-headers -isystem linux-headers -iquote . -iquote /home/alex/lsrc/qemu.git -iquote /home/alex/lsrc/qemu.git/include -iquote /home/alex/lsrc/qemu.git/tcg/i386 -pthread -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wundef -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -fno-common -fwrapv -Wold-style-declaration -Wold-style-definition -Wtype-limits -Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers -Wempty-body -Wnested-externs -Wendif-labels -Wexpansion-to-defined -Wimplicit-fallthrough=2 -Wno-missing-include-dirs -Wno-shift-negative-value -Wno-psabi -fstack-protector-strong -fPIE -MD -MQ tests/qtest/libqos/libqos.fa.p/.._libqtest.c.o -MF tests/qtest/libqos/libqos.fa.p/.._libqtest.c.o.d -o tests/qtest/libqos/libqos.fa.p/.._libqtest.c.o -c ../../tests/qtest/libqtest.c ../../tests/qtest/libqtest.c: In function ‘socket_send’:../../tests/qtest/libqtest.c:431:19: error: implicit declaration of function ‘qemu_send_full’; did you mean ‘qemu_write_full’? [-Werror=implicit-function-declaration]
431 | ssize_t res = qemu_send_full(fd, buf, size);
| ^~~~~~~~~~~~~~
| qemu_write_full../../tests/qtest/libqtest.c:431:19: error: nested extern declaration of ‘qemu_send_full’ [-Werror=nested-externs]
cc1: all warnings being treated as errors
dropping this patch.
Signature · 1 line
Alex Bennée
Re: [PATCH v5 09/18] tests/qtest: Use send/recv for socket communication
In reply to Bin MengQuoted 33 lines · Bin Meng
From: Xuzhou Cheng <[email protected]>
Socket communication in the libqtest and libqmp codes uses
read()andwrite()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()andwrite()cannot be used on sockets on Windows. Switch over to usesend()andrecv()instead which work on both Windows and *nix.Signed-off-by Xuzhou Cheng <[email protected]>Signed-off-by Bin Meng <[email protected]>Reviewed-by Marc-André Lureau <[email protected]>---
(no changes since v2)
Changes in v2:
- Introduceqemu_send_full()and use itinclude/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(-)include/qemu/sockets.h +0
-0
include/qemu/sockets.h int qemu_socketpair(int domain, int type, int protocol, int sv[2]); · line 37
Quoted 5 lines
include/qemu/sockets.h +2
-0@@ -33,6 +33,8 @@ int qemu_socketpair(int domain, int type, int protocol, int sv[2]);#endif 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;
New global function prototypes in headers need documentation comments, please.
thanks
-- PMM
Re: [PATCH v5 09/18] tests/qtest: Use send/recv for socket communication
Quoted 36 lines · Peter Maydell
Quoted 35 lines · Bin Meng
From: Xuzhou Cheng <[email protected]>
Socket communication in the libqtest and libqmp codes uses
read()andwrite()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()andwrite()cannot be used on sockets on Windows. Switch over to usesend()andrecv()instead which work on both Windows and *nix.Signed-off-by Xuzhou Cheng <[email protected]>Signed-off-by Bin Meng <[email protected]>Reviewed-by Marc-André Lureau <[email protected]>---
(no changes since v2)
Changes in v2:
- Introduceqemu_send_full()and use itinclude/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(-)include/qemu/sockets.h +0
-0@@ -33,6 +33,8 @@ int qemu_socketpair(int domain, int type, int protocol, int sv[2]);#endif
Quoted 6 lines
include/qemu/sockets.h int qemu_socketpair(int domain, int type, int protocol, int sv[2]); · line 37
Quoted 3 lines
include/qemu/sockets.h +2
-0int 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;New global function prototypes in headers need documentation comments, please.
In previous versions of this series I suggested we should be making libqmp/libqtest use the QIOChannelSocket API, instead of raw sockets code. The latter gives us portability already, and is what almost all of the rest of the codebase uses for sockets I/O.
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Quoted 31 lines · Alex Bennée
Quoted 27 lines · Bin Meng
Hi Alex,
Quoted 10 lines · Bin Meng
Quoted 8 lines · Alex Bennée
Quoted 3 lines · Bin Meng
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.
Quoted 11 lines
Quoted 4 lines
I'm happy to take this whole series through my testing/next however I don't have working CI for the month so need to wait for my minutes to reset. Have you done a full CI run* with this?
Yes, gitlab CI passed.
Quoted 4 lines
(*make sure any CI run is only on a repo forked from
https://gitlab.com/qemu-project as you won't get the discount cost factor otherwise)Patch 4 and 10 are already applied in the mainline by Thomas.
Quoted 8 lines
Quoted 4 lines
Daniel will queue patch 14, 15, 16.
Could you please help queue patch 1, 2, 3, 5, 6, 7, 9, 13 from this series?
I've queued those except 13 into my testing/next. There was a merge failure so I guess a dependency on another patch?
Thank you Alex.
Indeed patch 13 depends on a previous patch. Please ignore. I will rebase in the next version.
Regards,
Bin
Re: [PATCH v5 09/18] tests/qtest: Use send/recv for socket communication
In reply to Alex BennéeQuoted 147 lines · Alex Bennée
Quoted 126 lines · Bin Meng
From: Xuzhou Cheng <[email protected]>
Socket communication in the libqtest and libqmp codes uses
read()andwrite()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()andwrite()cannot be used on sockets on Windows. Switch over to usesend()andrecv()instead which work on both Windows and *nix.Signed-off-by Xuzhou Cheng <[email protected]>Signed-off-by Bin Meng <[email protected]>Reviewed-by Marc-André Lureau <[email protected]>---
(no changes since v2)
Changes in v2:
- Introduceqemu_send_full()and use itinclude/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(-)include/qemu/sockets.h +2
-0@@ -33,6 +33,8 @@ int qemu_socketpair(int domain, int type, int protocol, int sv[2]);#endif 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);tests/qtest/libqmp.c +3
-2@@ -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 ; }tests/qtest/libqtest.c +2
-2@@ -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 ; }util/osdep.c +26
-0@@ -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;util/osdep.c int qemu_accept(int s, struct sockaddr *addr, socklen_t *addrlen) · line 540
Quoted 10 lines
util/osdep.c +7
-0+ buf += ret; + total += ret; + } + +return total; +} +void qemu_set_hw_version (const char *version) { hw_version = version;Hmm something goes wrong here:
FAILED:
tests/qtest/libqos/libqos.fa.p/.._libqtest.c.o
cc -m64 -mcx16 -Itests/qtest/libqos/libqos.fa.p -Itests/qtest/libqos -I../../tests/qtest/libqos -I. -Iqapi -Itrace -Iui -Iui/shader -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -fdiagnostics-color=auto -Wall -Winvalid-pch -Werror -std=gnu11 -O2 -g -isystem/home/alex/lsrc/qemu.git/linux-headers-isystem linux-headers -iquote . -iquote/home/alex/lsrc/qemu.git-iquote/home/alex/lsrc/qemu.git/include-iquote/home/alex/lsrc/qemu.git/tcg/i386-pthread -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wundef -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -fno-common -fwrapv -Wold-style-declaration -Wold-style-definition -Wtype-limits -Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers -Wempty-body -Wnested-externs -Wendif-labels -Wexpansion-to-defined -Wimplicit-fallthrough=2 -Wno-missing-include-dirs -Wno-shift-negative-value -Wno-psabi -fstack-protector-strong -fPIE -MD -MQtests/qtest/libqos/libqos.fa.p/.._libqtest.c.o-MF tests/qtest/libqos/libqos.fa.p/.._libqtest.c.o.d -otests/qtest/libqos/libqos.fa.p/.._libqtest.c.o-c../../tests/qtest/libqtest.c../../tests/qtest/libqtest.c: In function ‘socket_send’:../../tests/qtest/libqtest.c:431:19: error: implicit declaration of function ‘qemu_send_full’; did you mean ‘qemu_write_full’? [-Werror=implicit-function-declaration]
Quoted 9 lines
431 | ssize_t res = qemu_send_full(fd, buf, size); | ^~~~~~~~~~~~~~ | qemu_write_full
../../tests/qtest/libqtest.c:431:19: error: nested extern declaration of ‘qemu_send_full’ [-Werror=nested-externs]
cc1: all warnings being treated as errorsdropping this patch.
This is weird. It does not reproduce on my side, neither did the QEMU CI.
Regards,
Bin
Re: [PATCH v5 09/18] tests/qtest: Use send/recv for socket communication
Quoted 155 lines · Bin Meng
Quoted 154 lines · Alex Bennée
Quoted 126 lines · Bin Meng
From: Xuzhou Cheng <[email protected]>
Socket communication in the libqtest and libqmp codes uses
read()andwrite()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()andwrite()cannot be used on sockets on Windows. Switch over to usesend()andrecv()instead which work on both Windows and *nix.Signed-off-by Xuzhou Cheng <[email protected]>Signed-off-by Bin Meng <[email protected]>Reviewed-by Marc-André Lureau <[email protected]>---
(no changes since v2)
Changes in v2:
- Introduceqemu_send_full()and use itinclude/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(-)include/qemu/sockets.h +2
-0@@ -33,6 +33,8 @@ int qemu_socketpair(int domain, int type, int protocol, int sv[2]);#endif 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);tests/qtest/libqmp.c +3
-2@@ -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 ; }tests/qtest/libqtest.c +2
-2@@ -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 ; }util/osdep.c +26
-0@@ -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;util/osdep.c int qemu_accept(int s, struct sockaddr *addr, socklen_t *addrlen) · line 540
Quoted 10 lines
util/osdep.c +7
-0+ buf += ret; + total += ret; + } + +return total; +} +void qemu_set_hw_version (const char *version) { hw_version = version;Hmm something goes wrong here:
FAILED:
tests/qtest/libqos/libqos.fa.p/.._libqtest.c.o
cc -m64 -mcx16 -Itests/qtest/libqos/libqos.fa.p -Itests/qtest/libqos -I../../tests/qtest/libqos -I. -Iqapi -Itrace -Iui -Iui/shader -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -fdiagnostics-color=auto -Wall -Winvalid-pch -Werror -std=gnu11 -O2 -g -isystem/home/alex/lsrc/qemu.git/linux-headers-isystem linux-headers -iquote . -iquote/home/alex/lsrc/qemu.git-iquote/home/alex/lsrc/qemu.git/include-iquote/home/alex/lsrc/qemu.git/tcg/i386-pthread -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wundef -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -fno-common -fwrapv -Wold-style-declaration -Wold-style-definition -Wtype-limits -Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers -Wempty-body -Wnested-externs -Wendif-labels -Wexpansion-to-defined -Wimplicit-fallthrough=2 -Wno-missing-include-dirs -Wno-shift-negative-value -Wno-psabi -fstack-protector-strong -fPIE -MD -MQtests/qtest/libqos/libqos.fa.p/.._libqtest.c.o-MF tests/qtest/libqos/libqos.fa.p/.._libqtest.c.o.d -otests/qtest/libqos/libqos.fa.p/.._libqtest.c.o-c../../tests/qtest/libqtest.c../../tests/qtest/libqtest.c: In function ‘socket_send’:../../tests/qtest/libqtest.c:431:19: error: implicit declaration of function ‘qemu_send_full’; did you mean ‘qemu_write_full’? [-Werror=implicit-function-declaration]431 | ssize_t res = qemu_send_full(fd, buf, size); | ^~~~~~~~~~~~~~ | qemu_write_full
../../tests/qtest/libqtest.c:431:19: error: nested extern declaration of ‘qemu_send_full’ [-Werror=nested-externs]
cc1: all warnings being treated as errors
Quoted 4 lines
Quoted 2 lines
dropping this patch.
This is weird. It does not reproduce on my side, neither did the QEMU CI.
I think it needs an #include statement from an earlier patch?
Thomas
Re: [PATCH v5 04/18] tests/qtest: migration-test: Avoid using hardcoded /tmp
In reply to Bin MengQuoted 12 lines · Bin Meng
From: Bin Meng <[email protected]>
This case was written to use hardcoded /tmp directory for temporary files. Update to use
g_dir_make_tmp()for a portable implementation.Signed-off-by Bin Meng <[email protected]>Reviewed-by Marc-André Lureau <[email protected]>---
Changes in v5:
- Useg_autoptr(GError)
Quoted 7 lines
Changes in v4:
- Update the error reporting by using the GError "error" argument ofg_dir_make_tmp()
- Remove the const from tmpfs declarationChanges in v3:
- Split to a separate patch
This patch breaks with gcc 12:
tests/qtest/migration-test.c int main(int argc, char **argv) · line 2488
Quoted 13 lines
tests/qtest/migration-test.c +3
-2@@ -2479,9 +2479,10 @@ int main(int argc, char **argv)return g_test_run (); } - tmpfs =g_mkdtemp (template); + tmpfs =g_dir_make_tmp ("migration-test-XXXXXX" , &err);if (!tmpfs) { -g_test_message ("g_mkdtemp on path (%s): %s" , template,strerror (errno)); +g_test_message ("g_dir_make_tmp on path (%s): %s" , tmpfs, + err->message); }g_assert (tmpfs);
../src/tests/qtest/migration-test.c: In function ‘main’:../src/tests/qtest/migration-test.c:2484:49: error: ‘%s’ directive argument is null [-Werror=format-overflow=]
2484 | g_test_message("g_dir_make_tmp on path (%s): %s", tmpfs,
| ^~
The compiler correctly notices that tmpfs was tested and found to be null, but tried to print it anyway.
r~
Re: [PATCH v5 04/18] tests/qtest: migration-test: Avoid using hardcoded /tmp
Quoted 19 lines · Richard Henderson
Quoted 17 lines · Bin Meng
From: Bin Meng <[email protected]>
This case was written to use hardcoded /tmp directory for temporary files. Update to use
g_dir_make_tmp()for a portable implementation.Signed-off-by Bin Meng <[email protected]>Reviewed-by Marc-André Lureau <[email protected]>---
Changes in v5:
- Useg_autoptr(GError)Changes in v4:
- Update the error reporting by using the GError "error" argument ofg_dir_make_tmp()
- Remove the const from tmpfs declaration
Quoted 4 lines
Quoted 2 lines
Changes in v3:
- Split to a separate patchThis patch breaks with gcc 12:
Weird GCC ...
GCC 9 reported [1], but not GCC 11, and now GCC 12 reported again.
Quoted 22 lines
Quoted 5 lines
tests/qtest/migration-test.c +0
-0@@ -2479,9 +2479,10 @@ int main(int argc, char **argv)return g_test_run (); }tests/qtest/migration-test.c int main(int argc, char **argv) · line 2488
Quoted 10 lines
tests/qtest/migration-test.c +3
-2- tmpfs =g_mkdtemp (template); + tmpfs =g_dir_make_tmp ("migration-test-XXXXXX" , &err);if (!tmpfs) { -g_test_message ("g_mkdtemp on path (%s): %s" , template,strerror (errno)); +g_test_message ("g_dir_make_tmp on path (%s): %s" , tmpfs, + err->message); }g_assert (tmpfs);
../src/tests/qtest/migration-test.c: In function ‘main’:../src/tests/qtest/migration-test.c:2484:49: error: ‘%s’ directive argument is null [-Werror=format-overflow=]
2484 | g_test_message("g_dir_make_tmp on path (%s): %s", tmpfs,
| ^~
Quoted 3 lines
The compiler correctly notices that tmpfs was tested and found to be null, but tried to print it anyway.
Patch [1] already queued in qemu-trivial
[1] http://patchwork.ozlabs.org/project/qemu-devel/patch/[email protected]/
Regards,
Bin
Re: [PATCH v5 04/18] tests/qtest: migration-test: Avoid using hardcoded /tmp
Quoted 6 lines · Bin Meng
Quoted 6 lines
../src/tests/qtest/migration-test.c: In function ‘main’:../src/tests/qtest/migration-test.c:2484:49: error: ‘%s’ directive argument is null [-Werror=format-overflow=]
2484 | g_test_message("g_dir_make_tmp on path (%s): %s", tmpfs,
| ^~
Quoted 7 lines
Quoted 3 lines
The compiler correctly notices that tmpfs was tested and found to be null, but tried to print it anyway.
Patch [1] already queued in qemu-trivial
[1] http://patchwork.ozlabs.org/project/qemu-devel/patch/[email protected]/
Oh, excellent, thanks.
r~