[PATCH v2 03/15] tests: make libqmp buildable for win32

marcandre.lureau@redhat.com posted 15 patches 3 years, 7 months ago
Maintainers: Kevin Wolf <kwolf@redhat.com>, Hanna Reitz <hreitz@redhat.com>, Michael Roth <michael.roth@amd.com>, Konstantin Kostiuk <kkostiuk@redhat.com>, Alexander Bulekov <alxndr@bu.edu>, Paolo Bonzini <pbonzini@redhat.com>, Bandan Das <bsd@redhat.com>, Stefan Hajnoczi <stefanha@redhat.com>, Thomas Huth <thuth@redhat.com>, Darren Kenny <darren.kenny@oracle.com>, Qiuhao Li <Qiuhao.Li@outlook.com>, Laurent Vivier <lvivier@redhat.com>, Stefan Weil <sw@weilnetz.de>
There is a newer version of this series
[PATCH v2 03/15] tests: make libqmp buildable for win32
Posted by marcandre.lureau@redhat.com 3 years, 7 months ago
From: Marc-André Lureau <marcandre.lureau@redhat.com>

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
---
 tests/qtest/libqmp.h |  2 ++
 tests/qtest/libqmp.c | 35 +++++++++++++++++++++++++++++------
 2 files changed, 31 insertions(+), 6 deletions(-)

diff --git a/tests/qtest/libqmp.h b/tests/qtest/libqmp.h
index 94aa97328a17..772f18b73ba3 100644
--- a/tests/qtest/libqmp.h
+++ b/tests/qtest/libqmp.h
@@ -20,8 +20,10 @@
 #include "qapi/qmp/qdict.h"
 
 QDict *qmp_fd_receive(int fd);
+#ifndef G_OS_WIN32
 void qmp_fd_vsend_fds(int fd, int *fds, size_t fds_num,
                       const char *fmt, va_list ap) G_GNUC_PRINTF(4, 0);
+#endif
 void qmp_fd_vsend(int fd, const char *fmt, va_list ap) G_GNUC_PRINTF(2, 0);
 void qmp_fd_send(int fd, const char *fmt, ...) G_GNUC_PRINTF(2, 3);
 void qmp_fd_send_raw(int fd, const char *fmt, ...) G_GNUC_PRINTF(2, 3);
diff --git a/tests/qtest/libqmp.c b/tests/qtest/libqmp.c
index 0358b8313dc4..93c9b31cd4ca 100644
--- a/tests/qtest/libqmp.c
+++ b/tests/qtest/libqmp.c
@@ -15,9 +15,13 @@
  */
 
 #include "qemu/osdep.h"
-
 #include "libqmp.h"
 
+#ifndef G_OS_WIN32
+#include <sys/socket.h>
+#endif
+
+#include "qemu/cutils.h"
 #include "qapi/error.h"
 #include "qapi/qmp/json-parser.h"
 #include "qapi/qmp/qjson.h"
@@ -87,6 +91,7 @@ QDict *qmp_fd_receive(int fd)
     return qmp.response;
 }
 
+#ifndef G_OS_WIN32
 /* Sends a message and file descriptors to the socket.
  * It's needed for qmp-commands like getfd/add-fd */
 static void socket_send_fds(int socket_fd, int *fds, size_t fds_num,
@@ -120,17 +125,23 @@ static void socket_send_fds(int socket_fd, int *fds, size_t fds_num,
     } while (ret < 0 && errno == EINTR);
     g_assert_cmpint(ret, >, 0);
 }
+#endif
 
 /**
  * Allow users to send a message without waiting for the reply,
  * in the case that they choose to discard all replies up until
  * a particular EVENT is received.
  */
-void qmp_fd_vsend_fds(int fd, int *fds, size_t fds_num,
-                      const char *fmt, va_list ap)
+static void
+_qmp_fd_vsend_fds(int fd, int *fds, size_t fds_num,
+                  const char *fmt, va_list ap)
 {
     QObject *qobj;
 
+#ifdef G_OS_WIN32
+    assert(fds_num == 0);
+#endif
+
     /* Going through qobject ensures we escape strings properly */
     qobj = qobject_from_vjsonf_nofail(fmt, ap);
 
@@ -148,10 +159,14 @@ void qmp_fd_vsend_fds(int fd, int *fds, size_t fds_num,
         if (log) {
             fprintf(stderr, "%s", str->str);
         }
+
+#ifndef G_OS_WIN32
         /* Send QMP request */
         if (fds && fds_num > 0) {
             socket_send_fds(fd, fds, fds_num, str->str, str->len);
-        } else {
+        } else
+#endif
+        {
             socket_send(fd, str->str, str->len);
         }
 
@@ -160,15 +175,23 @@ void qmp_fd_vsend_fds(int fd, int *fds, size_t fds_num,
     }
 }
 
+#ifndef G_OS_WIN32
+void qmp_fd_vsend_fds(int fd, int *fds, size_t fds_num,
+                      const char *fmt, va_list ap)
+{
+    _qmp_fd_vsend_fds(fd, fds, fds_num, fmt, ap);
+}
+#endif
+
 void qmp_fd_vsend(int fd, const char *fmt, va_list ap)
 {
-    qmp_fd_vsend_fds(fd, NULL, 0, fmt, ap);
+    _qmp_fd_vsend_fds(fd, NULL, 0, fmt, ap);
 }
 
 
 QDict *qmp_fdv(int fd, const char *fmt, va_list ap)
 {
-    qmp_fd_vsend_fds(fd, NULL, 0, fmt, ap);
+    _qmp_fd_vsend_fds(fd, NULL, 0, fmt, ap);
 
     return qmp_fd_receive(fd);
 }
-- 
2.36.0.44.g0f828332d5ac


Re: [PATCH v2 03/15] tests: make libqmp buildable for win32
Posted by Markus Armbruster 3 years, 7 months ago
marcandre.lureau@redhat.com writes:

> From: Marc-André Lureau <marcandre.lureau@redhat.com>
>
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> Reviewed-by: Thomas Huth <thuth@redhat.com>
> ---
>  tests/qtest/libqmp.h |  2 ++
>  tests/qtest/libqmp.c | 35 +++++++++++++++++++++++++++++------
>  2 files changed, 31 insertions(+), 6 deletions(-)
>
> diff --git a/tests/qtest/libqmp.h b/tests/qtest/libqmp.h
> index 94aa97328a17..772f18b73ba3 100644
> --- a/tests/qtest/libqmp.h
> +++ b/tests/qtest/libqmp.h
> @@ -20,8 +20,10 @@
>  #include "qapi/qmp/qdict.h"
>  
>  QDict *qmp_fd_receive(int fd);
> +#ifndef G_OS_WIN32

What's the difference between G_OS_WIN32 and _WIN32?

We have 10 of the former, but >250 of the latter.  If they are
effectively the same, we should pick one and stick to it.

[...]
Re: [PATCH v2 03/15] tests: make libqmp buildable for win32
Posted by Marc-André Lureau 3 years, 7 months ago
Hi

On Thu, May 5, 2022 at 2:52 PM Markus Armbruster <armbru@redhat.com> wrote:
>
> marcandre.lureau@redhat.com writes:
>
> > From: Marc-André Lureau <marcandre.lureau@redhat.com>
> >
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > Reviewed-by: Thomas Huth <thuth@redhat.com>
> > ---
> >  tests/qtest/libqmp.h |  2 ++
> >  tests/qtest/libqmp.c | 35 +++++++++++++++++++++++++++++------
> >  2 files changed, 31 insertions(+), 6 deletions(-)
> >
> > diff --git a/tests/qtest/libqmp.h b/tests/qtest/libqmp.h
> > index 94aa97328a17..772f18b73ba3 100644
> > --- a/tests/qtest/libqmp.h
> > +++ b/tests/qtest/libqmp.h
> > @@ -20,8 +20,10 @@
> >  #include "qapi/qmp/qdict.h"
> >
> >  QDict *qmp_fd_receive(int fd);
> > +#ifndef G_OS_WIN32
>
> What's the difference between G_OS_WIN32 and _WIN32?
>
> We have 10 of the former, but >250 of the latter.  If they are
> effectively the same, we should pick one and stick to it.

There are some subtle differences when compiling for cygwin, in which
case G_OS_WIN32 is not defined.

I usually pick G_OS_{UNIX,WIN32} defines, mostly for consistency, but
in many situation _WIN32/WIN32 is fine.

(and we also have CONFIG_WIN32)
Re: [PATCH v2 03/15] tests: make libqmp buildable for win32
Posted by Markus Armbruster 3 years, 7 months ago
Marc-André Lureau <marcandre.lureau@redhat.com> writes:

> Hi
>
> On Thu, May 5, 2022 at 2:52 PM Markus Armbruster <armbru@redhat.com> wrote:
>>
>> marcandre.lureau@redhat.com writes:
>>
>> > From: Marc-André Lureau <marcandre.lureau@redhat.com>
>> >
>> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
>> > Reviewed-by: Thomas Huth <thuth@redhat.com>
>> > ---
>> >  tests/qtest/libqmp.h |  2 ++
>> >  tests/qtest/libqmp.c | 35 +++++++++++++++++++++++++++++------
>> >  2 files changed, 31 insertions(+), 6 deletions(-)
>> >
>> > diff --git a/tests/qtest/libqmp.h b/tests/qtest/libqmp.h
>> > index 94aa97328a17..772f18b73ba3 100644
>> > --- a/tests/qtest/libqmp.h
>> > +++ b/tests/qtest/libqmp.h
>> > @@ -20,8 +20,10 @@
>> >  #include "qapi/qmp/qdict.h"
>> >
>> >  QDict *qmp_fd_receive(int fd);
>> > +#ifndef G_OS_WIN32
>>
>> What's the difference between G_OS_WIN32 and _WIN32?
>>
>> We have 10 of the former, but >250 of the latter.  If they are
>> effectively the same, we should pick one and stick to it.
>
> There are some subtle differences when compiling for cygwin, in which
> case G_OS_WIN32 is not defined.
>
> I usually pick G_OS_{UNIX,WIN32} defines, mostly for consistency, but
> in many situation _WIN32/WIN32 is fine.
>
> (and we also have CONFIG_WIN32)

I really think we should use one and only one unless there are
differences that *require* more.

Of the three, _WIN32 predominates (numbers appended).  Please use _WIN32
unless you can show a need for something else.



$ git-grep -cw G_OS_WIN32
qga/commands.c:5
ui/gtk.c:5

$ git-grep -cw CONFIG_WIN32 master
master:Makefile:1
master:block/meson.build:1
master:chardev/meson.build:1
master:configure:1
master:hw/usb/host-libusb.c:9
master:io/channel-watch.c:5
master:meson.build:1
master:net/meson.build:1
master:qga/meson.build:1
master:scripts/checkpatch.pl:1
master:target/i386/hax/hax-i386.h:2
master:target/i386/hax/meson.build:1
master:ui/gtk.c:1
master:ui/meson.build:2
master:ui/sdl2.c:1
master:util/meson.build:5
master:util/sys_membarrier.c:1

$ git-grep -cw CONFIG_WIN32 master
master:Makefile:1
master:block/meson.build:1
master:chardev/meson.build:1
master:configure:1
master:hw/usb/host-libusb.c:9
master:io/channel-watch.c:5
master:meson.build:1
master:net/meson.build:1
master:qga/meson.build:1
master:scripts/checkpatch.pl:1
master:target/i386/hax/hax-i386.h:2
master:target/i386/hax/meson.build:1
master:ui/gtk.c:1
master:ui/meson.build:2
master:ui/sdl2.c:1
master:util/meson.build:5
master:util/sys_membarrier.c:1
$ git-grep -cw _WIN32 master
master:accel/tcg/cpu-exec.c:1
master:accel/tcg/tcg-accel-ops-mttcg.c:1
master:accel/tcg/tcg-accel-ops-rr.c:1
master:audio/sdlaudio.c:3
master:block.c:6
master:block/nfs.c:5
master:block/vvfat.c:1
master:chardev/char-file.c:3
master:chardev/char-pipe.c:4
master:chardev/char-serial.c:4
master:chardev/char-socket.c:1
master:chardev/char-stdio.c:5
master:configure:1
master:contrib/elf2dmp/kdbg.h:1
master:contrib/elf2dmp/pdb.h:1
master:contrib/elf2dmp/pe.h:1
master:crypto/pbkdf.c:2
master:crypto/random-platform.c:3
master:gdbstub.c:2
master:include/block/block_int-common.h:1
master:include/block/raw-aio.h:1
master:include/exec/ram_addr.h:2
master:include/hw/core/cpu.h:1
master:include/io/channel.h:1
master:include/qapi/error.h:1
master:include/qemu/compiler.h:2
master:include/qemu/event_notifier.h:2
master:include/qemu/main-loop.h:1
master:include/qemu/osdep.h:6
master:include/qemu/qemu-plugin.h:1
master:include/qemu/sockets.h:2
master:include/qemu/thread.h:1
master:include/qemu/timer.h:1
master:io/channel.c:1
master:monitor/misc.c:1
master:nbd/nbd-internal.h:1
master:net/net.c:1
master:qemu-io.c:2
master:qemu-options.hx:6
master:qga/guest-agent-core.h:1
master:qga/main.c:21
master:scripts/cocci-macro-file.h:1
master:scripts/codeconverter/codeconverter/test_regexps.py:1
master:softmmu/cpus.c:2
master:softmmu/physmem.c:4
master:softmmu/vl.c:3
master:stubs/is-daemonized.c:1
master:subprojects/libvhost-user/libvhost-user.h:1
master:target/i386/hax/hax-accel-ops.c:1
master:target/i386/whpx/whpx-accel-ops.c:1
master:target/m68k/m68k-semi.c:1
master:target/mips/tcg/sysemu/mips-semi.c:4
master:target/nios2/nios2-semi.c:1
master:tcg/region.c:1
master:tests/qtest/virtio-net-test.c:2
master:tests/unit/test-char.c:6
master:tests/unit/test-crypto-block.c:2
master:tests/unit/test-crypto-pbkdf.c:2
master:tests/unit/test-io-channel-file.c:4
master:tests/unit/test-io-channel-socket.c:4
master:tests/unit/test-iov.c:1
master:tests/unit/test-replication.c:3
master:tests/unit/test-util-sockets.c:2
master:trace/simple.c:3
master:ui/curses.c:3
master:util/cacheinfo.c:1
master:util/error.c:1
master:util/main-loop.c:4
master:util/osdep.c:8
master:util/qemu-sockets.c:2
master:util/qemu-timer-common.c:1
master:util/systemd.c:2