aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2023-03-13 13:44:17 +0000
committerPeter Maydell <peter.maydell@linaro.org>2023-03-13 13:44:17 +0000
commit284c52eec2d0a1b9c47f06c3eee46762c5fc0915 (patch)
tree2020afbc1d980f53767c061e01e23ee98e722c83 /tests
parent29c8a9e31a982874ce4e2c15f2bf82d5f8dc3517 (diff)
parent4bf21c7f748bee42b6f4692f8c37a11d1033b2d1 (diff)
downloadqemu-284c52eec2d0a1b9c47f06c3eee46762c5fc0915.zip
qemu-284c52eec2d0a1b9c47f06c3eee46762c5fc0915.tar.gz
qemu-284c52eec2d0a1b9c47f06c3eee46762c5fc0915.tar.bz2
Merge tag 'win-socket-pull-request' of https://gitlab.com/marcandre.lureau/qemu into staging
QMP command to import win32 sockets # -----BEGIN PGP SIGNATURE----- # # iQJQBAABCAA6FiEEh6m9kz+HxgbSdvYt2ujhCXWWnOUFAmQPDQ0cHG1hcmNhbmRy # ZS5sdXJlYXVAcmVkaGF0LmNvbQAKCRDa6OEJdZac5eTUD/41+bodkctP9wtNQT5g # 4P2XQysa9dhxIaQuPT48J5bN0velOAv+p+e9jNMojVPHogACRGkjJUGrh2AhaWJO # bpqB5teNz3pbTLAHNrqiJdUrJDI0WSqBN2q7WgfbzvHMugBqul13n6UG/cVWH8D3 # pDX3miBl9Cv3zUDFzPjHH3eR/MHz+6wXmuzUGQdWqyGBoLwqgWA3Bqh39BDVOeJf # 03Kq3TbJSP096EjGGrq1pTYDIIv9AKzUWgn8tT8S73sD3J0BN28Gl5HirXDx8e/4 # 2WtW/XLYKjqoUl7RmXOjfOarCV+kxzdoYCAUYfyH6DLWrkXc41L5ugFdyxxQ66Sh # +on7hKCBzPEOPEXmlm6HlMj3bK4C/GI6mIoaZgCrsvj9xlehhQNtwpndAwAR8esH # perQ6q+jPdoQnBvOBgC3amckS1kYdbQivTILkoopumw/q4waG5reyA4rshbhm/bs # U33ZRzob0XyRWqvWAcq9hnWB5gvQCcppeJlu60gocnX5wdZOjbnsBXw3l+r2osIh # izJbxwM6xmz9oHh50nhDCn42JrNdSnZJdJ/XA/lrOkTHQ6kbZO7v86Y/mKQz+Vyx # Uyhb8/y8gKrUkZlGCEMvQVcyvOA8vneX8WhfZUm6w5MWWCNKfCrEl6UGmFkPAL0m # +sUYIhN5PSxWSQU5MWogXtQEPA== # =/Y/7 # -----END PGP SIGNATURE----- # gpg: Signature made Mon 13 Mar 2023 11:46:21 GMT # gpg: using RSA key 87A9BD933F87C606D276F62DDAE8E10975969CE5 # gpg: issuer "marcandre.lureau@redhat.com" # gpg: Good signature from "Marc-André Lureau <marcandre.lureau@redhat.com>" [full] # gpg: aka "Marc-André Lureau <marcandre.lureau@gmail.com>" [full] # Primary key fingerprint: 87A9 BD93 3F87 C606 D276 F62D DAE8 E109 7596 9CE5 * tag 'win-socket-pull-request' of https://gitlab.com/marcandre.lureau/qemu: (25 commits) monitor: restrict command getfd to POSIX hosts qtest: enable vnc-display test on win32 libqtest: make qtest_qmp_add_client work on win32 qmp: add 'get-win32-socket' monitor: release the lock before calling close() qmp: 'add_client' actually expects sockets osdep: implement qemu_socketpair() for win32 tests/docker: fix a win32 error due to portability char: do not double-close fd when failing to add client tests: fix path separator, use g_build_filename() win32: replace closesocket() with close() wrapper os-posix: remove useless ioctlsocket() define win32: avoid mixing SOCKET and file descriptor space slirp: open-code qemu_socket_(un)select() slirp: unregister the win32 SOCKET main-loop: remove qemu_fd_register(), win32/slirp/socket specific aio/win32: aio_set_fd_handler() only supports SOCKET aio: make aio_set_fd_poll() static to aio-posix.c win32/socket: introduce qemu_socket_unselect() helper win32/socket: introduce qemu_socket_select() helper ... Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'tests')
-rwxr-xr-xtests/docker/docker.py6
-rw-r--r--tests/qtest/libqtest.c26
-rw-r--r--tests/qtest/libqtest.h5
-rw-r--r--tests/qtest/microbit-test.c2
-rw-r--r--tests/qtest/netdev-socket.c10
-rw-r--r--tests/qtest/vnc-display-test.c12
-rw-r--r--tests/unit/meson.build1
-rw-r--r--tests/unit/socket-helpers.c2
-rw-r--r--tests/unit/test-error-report.c139
-rw-r--r--tests/unit/test-io-channel-command.c2
10 files changed, 180 insertions, 25 deletions
diff --git a/tests/docker/docker.py b/tests/docker/docker.py
index 3a1ed7c..688ef62 100755
--- a/tests/docker/docker.py
+++ b/tests/docker/docker.py
@@ -23,10 +23,10 @@ import enum
import tempfile
import re
import signal
+import getpass
from tarfile import TarFile, TarInfo
from io import StringIO, BytesIO
from shutil import copy, rmtree
-from pwd import getpwuid
from datetime import datetime, timedelta
@@ -316,7 +316,7 @@ class Docker(object):
if user:
uid = os.getuid()
- uname = getpwuid(uid).pw_name
+ uname = getpass.getuser()
tmp_df.write("\n")
tmp_df.write("RUN id %s 2>/dev/null || useradd -u %d -U %s" %
(uname, uid, uname))
@@ -570,7 +570,7 @@ class UpdateCommand(SubCommand):
if args.user:
uid = os.getuid()
- uname = getpwuid(uid).pw_name
+ uname = getpass.getuser()
df.write("\n")
df.write("RUN id %s 2>/dev/null || useradd -u %d -U %s" %
(uname, uid, uname))
diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
index 2bfd460..c3a0ef5 100644
--- a/tests/qtest/libqtest.c
+++ b/tests/qtest/libqtest.c
@@ -124,7 +124,7 @@ static int socket_accept(int sock)
(void *)&timeout, sizeof(timeout))) {
fprintf(stderr, "%s failed to set SO_RCVTIMEO: %s\n",
__func__, strerror(errno));
- closesocket(sock);
+ close(sock);
return -1;
}
@@ -135,7 +135,7 @@ static int socket_accept(int sock)
if (ret == -1) {
fprintf(stderr, "%s failed: %s\n", __func__, strerror(errno));
}
- closesocket(sock);
+ close(sock);
return ret;
}
@@ -564,8 +564,8 @@ void qtest_quit(QTestState *s)
qtest_remove_abrt_handler(s);
qtest_kill_qemu(s);
- closesocket(s->fd);
- closesocket(s->qmp_fd);
+ close(s->fd);
+ close(s->qmp_fd);
g_string_free(s->rx, true);
for (GList *it = s->pending_events; it != NULL; it = it->next) {
@@ -1478,13 +1478,28 @@ void qtest_qmp_device_add(QTestState *qts, const char *driver, const char *id,
qobject_unref(args);
}
-#ifndef _WIN32
void qtest_qmp_add_client(QTestState *qts, const char *protocol, int fd)
{
QDict *resp;
+#ifdef WIN32
+ WSAPROTOCOL_INFOW info;
+ g_autofree char *info64 = NULL;
+ SOCKET s;
+
+ assert(fd_is_socket(fd));
+ s = _get_osfhandle(fd);
+ if (WSADuplicateSocketW(s, GetProcessId((HANDLE)qts->qemu_pid), &info) == SOCKET_ERROR) {
+ g_autofree char *emsg = g_win32_error_message(WSAGetLastError());
+ g_error("WSADuplicateSocketW failed: %s", emsg);
+ }
+ info64 = g_base64_encode((guchar *)&info, sizeof(info));
+ resp = qtest_qmp(qts, "{'execute': 'get-win32-socket',"
+ "'arguments': {'fdname': 'fdname', 'info': %s}}", info64);
+#else
resp = qtest_qmp_fds(qts, &fd, 1, "{'execute': 'getfd',"
"'arguments': {'fdname': 'fdname'}}");
+#endif
g_assert(resp);
g_assert(!qdict_haskey(resp, "event")); /* We don't expect any events */
g_assert(!qdict_haskey(resp, "error"));
@@ -1498,7 +1513,6 @@ void qtest_qmp_add_client(QTestState *qts, const char *protocol, int fd)
g_assert(!qdict_haskey(resp, "error"));
qobject_unref(resp);
}
-#endif
/*
* Generic hot-unplugging test via the device_del QMP command.
diff --git a/tests/qtest/libqtest.h b/tests/qtest/libqtest.h
index fcf1c3c..8d7d450 100644
--- a/tests/qtest/libqtest.h
+++ b/tests/qtest/libqtest.h
@@ -758,17 +758,16 @@ void qtest_qmp_device_add_qdict(QTestState *qts, const char *drv,
void qtest_qmp_device_add(QTestState *qts, const char *driver, const char *id,
const char *fmt, ...) G_GNUC_PRINTF(4, 5);
-#ifndef _WIN32
/**
* qtest_qmp_add_client:
* @qts: QTestState instance to operate on
* @protocol: the protocol to add to
* @fd: the client file-descriptor
*
- * Call QMP ``getfd`` followed by ``add_client`` with the given @fd.
+ * Call QMP ``getfd`` (on Windows ``get-win32-socket``) followed by
+ * ``add_client`` with the given @fd.
*/
void qtest_qmp_add_client(QTestState *qts, const char *protocol, int fd);
-#endif /* _WIN32 */
/**
* qtest_qmp_device_del_send:
diff --git a/tests/qtest/microbit-test.c b/tests/qtest/microbit-test.c
index 4bc2670..6022a92 100644
--- a/tests/qtest/microbit-test.c
+++ b/tests/qtest/microbit-test.c
@@ -107,7 +107,7 @@ static void test_nrf51_uart(void)
g_assert_true(recv(sock_fd, s, 10, 0) == 5);
g_assert_true(memcmp(s, "world", 5) == 0);
- closesocket(sock_fd);
+ close(sock_fd);
qtest_quit(qts);
}
diff --git a/tests/qtest/netdev-socket.c b/tests/qtest/netdev-socket.c
index 270e424..9cf1b06 100644
--- a/tests/qtest/netdev-socket.c
+++ b/tests/qtest/netdev-socket.c
@@ -99,7 +99,7 @@ static int inet_get_free_port_multiple(int nb, int *port, bool ipv6)
nb = i;
for (i = 0; i < nb; i++) {
- closesocket(sock[i]);
+ close(sock[i]);
}
return nb;
@@ -361,8 +361,8 @@ static void test_stream_fd(void)
qtest_quit(qts1);
qtest_quit(qts0);
- closesocket(sock[0]);
- closesocket(sock[1]);
+ close(sock[0]);
+ close(sock[1]);
}
#endif
@@ -487,8 +487,8 @@ static void test_dgram_fd(void)
qtest_quit(qts1);
qtest_quit(qts0);
- closesocket(sv[0]);
- closesocket(sv[1]);
+ close(sv[0]);
+ close(sv[1]);
}
#endif
diff --git a/tests/qtest/vnc-display-test.c b/tests/qtest/vnc-display-test.c
index e52a432..f8933b0 100644
--- a/tests/qtest/vnc-display-test.c
+++ b/tests/qtest/vnc-display-test.c
@@ -19,7 +19,7 @@ typedef struct Test {
GMainLoop *loop;
} Test;
-#if !defined(WIN32) && !defined(CONFIG_DARWIN)
+#if !defined(CONFIG_DARWIN)
static void on_vnc_error(VncConnection* self,
const char* msg)
@@ -38,10 +38,7 @@ static void on_vnc_auth_failure(VncConnection *self,
static bool
test_setup(Test *test)
{
-#ifdef WIN32
- g_test_skip("Not supported on Windows yet");
- return false;
-#elif defined(CONFIG_DARWIN)
+#if defined(CONFIG_DARWIN)
g_test_skip("Broken on Darwin");
return false;
#else
@@ -59,7 +56,12 @@ test_setup(Test *test)
g_signal_connect(test->conn, "vnc-auth-failure",
G_CALLBACK(on_vnc_auth_failure), NULL);
vnc_connection_set_auth_type(test->conn, VNC_CONNECTION_AUTH_NONE);
+
+#ifdef WIN32
+ vnc_connection_open_fd(test->conn, _get_osfhandle(pair[0]));
+#else
vnc_connection_open_fd(test->conn, pair[0]);
+#endif
test->loop = g_main_loop_new(NULL, FALSE);
return true;
diff --git a/tests/unit/meson.build b/tests/unit/meson.build
index d9c0a7e..fa63cfe 100644
--- a/tests/unit/meson.build
+++ b/tests/unit/meson.build
@@ -11,6 +11,7 @@ tests = {
'check-qobject': [],
'check-qjson': [],
'check-qlit': [],
+ 'test-error-report': [],
'test-qobject-output-visitor': [testqapi],
'test-clone-visitor': [testqapi],
'test-qobject-input-visitor': [testqapi],
diff --git a/tests/unit/socket-helpers.c b/tests/unit/socket-helpers.c
index eecadf3..6de27ba 100644
--- a/tests/unit/socket-helpers.c
+++ b/tests/unit/socket-helpers.c
@@ -160,7 +160,7 @@ void socket_check_afunix_support(bool *has_afunix)
int fd;
fd = socket(PF_UNIX, SOCK_STREAM, 0);
- closesocket(fd);
+ close(fd);
#ifdef _WIN32
*has_afunix = (fd != (int)INVALID_SOCKET);
diff --git a/tests/unit/test-error-report.c b/tests/unit/test-error-report.c
new file mode 100644
index 0000000..54319c8
--- /dev/null
+++ b/tests/unit/test-error-report.c
@@ -0,0 +1,139 @@
+/*
+ * Error reporting test
+ *
+ * Copyright (C) 2022 Red Hat Inc.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#include "qemu/osdep.h"
+#include "glib-compat.h"
+#include <locale.h>
+
+#include "qemu/error-report.h"
+#include "qapi/error.h"
+
+static void
+test_error_report_simple(void)
+{
+ if (g_test_subprocess()) {
+ error_report("%s", "test error");
+ warn_report("%s", "test warn");
+ info_report("%s", "test info");
+ return;
+ }
+
+ g_test_trap_subprocess(NULL, 0, 0);
+ g_test_trap_assert_passed();
+ g_test_trap_assert_stderr("\
+test-error-report: test error*\
+test-error-report: warning: test warn*\
+test-error-report: info: test info*\
+");
+}
+
+static void
+test_error_report_loc(void)
+{
+ if (g_test_subprocess()) {
+ loc_set_file("some-file.c", 7717);
+ error_report("%s", "test error1");
+ loc_set_none();
+ error_report("%s", "test error2");
+ return;
+ }
+
+ g_test_trap_subprocess(NULL, 0, 0);
+ g_test_trap_assert_passed();
+ g_test_trap_assert_stderr("\
+test-error-report:some-file.c:7717: test error1*\
+test-error-report: test error2*\
+");
+}
+
+static void
+test_error_report_glog(void)
+{
+ if (g_test_subprocess()) {
+ g_message("gmessage");
+ return;
+ }
+
+ g_test_trap_subprocess(NULL, 0, 0);
+ g_test_trap_assert_passed();
+ g_test_trap_assert_stderr("test-error-report: info: gmessage*");
+}
+
+static void
+test_error_report_once(void)
+{
+ int i;
+
+ if (g_test_subprocess()) {
+ for (i = 0; i < 3; i++) {
+ warn_report_once("warn");
+ error_report_once("err");
+ }
+ return;
+ }
+
+ g_test_trap_subprocess(NULL, 0, 0);
+ g_test_trap_assert_passed();
+ g_test_trap_assert_stderr("\
+test-error-report: warning: warn*\
+test-error-report: err*\
+");
+}
+
+static void
+test_error_report_timestamp(void)
+{
+ if (g_test_subprocess()) {
+ message_with_timestamp = true;
+ warn_report("warn");
+ error_report("err");
+ return;
+ }
+
+ g_test_trap_subprocess(NULL, 0, 0);
+ g_test_trap_assert_passed();
+ g_test_trap_assert_stderr("\
+*-*-*:*:* test-error-report: warning: warn*\
+*-*-*:*:* test-error-report: err*\
+");
+}
+
+static void
+test_error_warn(void)
+{
+ if (g_test_subprocess()) {
+ error_setg(&error_warn, "Testing &error_warn");
+ return;
+ }
+
+ g_test_trap_subprocess(NULL, 0, 0);
+ g_test_trap_assert_passed();
+ g_test_trap_assert_stderr("\
+test-error-report: warning: Testing &error_warn*\
+");
+}
+
+
+int
+main(int argc, char *argv[])
+{
+ setlocale(LC_ALL, "");
+
+ g_test_init(&argc, &argv, NULL);
+ error_init("test-error-report");
+
+ g_test_add_func("/error-report/simple", test_error_report_simple);
+ g_test_add_func("/error-report/loc", test_error_report_loc);
+ g_test_add_func("/error-report/glog", test_error_report_glog);
+ g_test_add_func("/error-report/once", test_error_report_once);
+ g_test_add_func("/error-report/timestamp", test_error_report_timestamp);
+ g_test_add_func("/error-report/warn", test_error_warn);
+
+ return g_test_run();
+}
diff --git a/tests/unit/test-io-channel-command.c b/tests/unit/test-io-channel-command.c
index c6e66a8..4f02261 100644
--- a/tests/unit/test-io-channel-command.c
+++ b/tests/unit/test-io-channel-command.c
@@ -35,7 +35,7 @@ static char *socat = NULL;
static void test_io_channel_command_fifo(bool async)
{
g_autofree gchar *tmpdir = g_dir_make_tmp("qemu-test-io-channel.XXXXXX", NULL);
- g_autofree gchar *fifo = g_strdup_printf("%s/%s", tmpdir, TEST_FIFO);
+ g_autofree gchar *fifo = g_build_filename(tmpdir, TEST_FIFO, NULL);
g_autofree gchar *srcargs = g_strdup_printf("%s - PIPE:%s,wronly", socat, fifo);
g_autofree gchar *dstargs = g_strdup_printf("%s PIPE:%s,rdonly -", socat, fifo);
g_auto(GStrv) srcargv = g_strsplit(srcargs, " ", -1);