aboutsummaryrefslogtreecommitdiff
path: root/tests/qtest/libqtest.c
diff options
context:
space:
mode:
authorStefan Hajnoczi <stefanha@redhat.com>2022-09-28 17:04:11 -0400
committerStefan Hajnoczi <stefanha@redhat.com>2022-09-28 17:04:11 -0400
commitc8de6ec63d766ca1998c5af468483ce912fdc0c2 (patch)
treea52db66c3f796445b2923ac2d752d497baebab6b /tests/qtest/libqtest.c
parent36cd0aeac3337af06875e08683380389df48ccd0 (diff)
parent0b49bc1b713d6e3896179f9700c8c35e511075f6 (diff)
Merge tag 'pull-request-2022-09-28' of https://gitlab.com/thuth/qemu into staging
* Fixes for qtests and unit tests to be more portable to non-POSIX platforms # -----BEGIN PGP SIGNATURE----- # # iQJFBAABCAAvFiEEJ7iIR+7gJQEY8+q5LtnXdP5wLbUFAmMz9MQRHHRodXRoQHJl # ZGhhdC5jb20ACgkQLtnXdP5wLbVUKRAAnubo/wtHqjxg/yVO68odX2LFI2koligA # LcEAnhGkVJ/Pe/+Qo9yVbcOY6k6xfGQU3VIipqvLEwPAdSF0E43EJxlImBNm8/Zq # MggjNoepXRhdFGULONSmSNm7HJykLH/CHdmBjPLrbpkTCwWG1gg64xP9fI+b8mGf # vST0ADuYloLDA9J45UbC33AD+9dQsy2GeOs8X99O6ysKF3htEqMD3vBdqKiJSwgT # 2c7UqySGECn6kMHl7iAdipRNUghSgzpUe8LcH4jP7Y1XnoB3zwC/+VrOVwFESI6y # LVFsC8u7cEKKSYunoowfQTgHvYbCuSdrDqljy17NE5qRMziKMTnhXaQNR5wtBKNt # HZxvc082P/QDFdBYYY3MIjB27r/I6x0t6Xl4IVwLz7bK0xfHFF8Ba2Lr57/2RTc/ # SMPDxGrMicTPnPDU/Cw5VROMmw0OC/tVpJMGo1VjVnNESo581RAMApyzkWiUyfZj # ktKd+4ihmqrBXcZHVjKbIufa6eKNuktlkfv72dnJY4XoUlDHlbDYaVuknybZmxWK # 9/CDVDG72s5Cqm+M47Q56IagVVZwIGrUP0u3j3h/v0rnHZehY8Qzr3SLEfeqmUb6 # nP7MP+ItZFZtMITdvXb3OtyeVuM0ZSw8kt+/evpvC9zB6FjgYl/e5FppsO0HxB/O # PeeV43Bk270= # =n+FM # -----END PGP SIGNATURE----- # gpg: Signature made Wed 28 Sep 2022 03:16:20 EDT # gpg: using RSA key 27B88847EEE0250118F3EAB92ED9D774FE702DB5 # gpg: issuer "thuth@redhat.com" # gpg: Good signature from "Thomas Huth <th.huth@gmx.de>" [full] # gpg: aka "Thomas Huth <thuth@redhat.com>" [full] # gpg: aka "Thomas Huth <huth@tuxfamily.org>" [full] # gpg: aka "Thomas Huth <th.huth@posteo.de>" [unknown] # Primary key fingerprint: 27B8 8847 EEE0 2501 18F3 EAB9 2ED9 D774 FE70 2DB5 * tag 'pull-request-2022-09-28' of https://gitlab.com/thuth/qemu: (37 commits) docs/devel: testing: Document writing portable test cases tests/qtest: boot-serial-test: Close the serial file before starting QEMU tests/qtest: vhost-user-test: Avoid using hardcoded /tmp tests/qtest: qmp-test: Avoid using hardcoded /tmp tests/qtest: pflash-cfi02-test: Avoid using hardcoded /tmp tests/qtest: hd-geo-test: Avoid using hardcoded /tmp tests/x86: Move common code to function in device-plug-test .gitlab-ci.d/windows.yml: Display meson test logs tests/qtest: migration-test: Skip running some TLS cases for win32 tests/qtest: libqtest: Replace the call to close a socket with closesocket() tests/qtest: microbit-test: Fix socket access for win32 tests/qtest: virtio-net-failover: Disable migration tests for win32 tests/qtest: ide-test: Open file in binary mode tests/qtest: migration-test: Disable IO redirection for win32 tests/qtest: bios-tables-test: Adapt the case for win32 tests/qtest: {ahci, ide}-test: Use relative path for temporary files for win32 tests/qtest: libqtest: Exclude the *_fds APIs for win32 tests/qtest: libqtest: Adapt global_qtest declaration for win32 tests/qtest: qmp-test: Skip running test_qmp_oob for win32 tests/qtest: Build test-filter-{mirror, redirector} cases for posix only ... Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Diffstat (limited to 'tests/qtest/libqtest.c')
-rw-r--r--tests/qtest/libqtest.c30
1 files changed, 21 insertions, 9 deletions
diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
index 7c9fc07de4..4f4b2d6477 100644
--- a/tests/qtest/libqtest.c
+++ b/tests/qtest/libqtest.c
@@ -97,7 +97,7 @@ static int socket_accept(int sock)
(void *)&timeout, sizeof(timeout))) {
fprintf(stderr, "%s failed to set SO_RCVTIMEO: %s\n",
__func__, strerror(errno));
- close(sock);
+ closesocket(sock);
return -1;
}
@@ -108,7 +108,7 @@ static int socket_accept(int sock)
if (ret == -1) {
fprintf(stderr, "%s failed: %s\n", __func__, strerror(errno));
}
- close(sock);
+ closesocket(sock);
return ret;
}
@@ -265,8 +265,10 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args)
s = g_new(QTestState, 1);
- socket_path = g_strdup_printf("/tmp/qtest-%d.sock", getpid());
- qmp_socket_path = g_strdup_printf("/tmp/qtest-%d.qmp", getpid());
+ socket_path = g_strdup_printf("%s/qtest-%d.sock",
+ g_get_tmp_dir(), getpid());
+ qmp_socket_path = g_strdup_printf("%s/qtest-%d.qmp",
+ g_get_tmp_dir(), getpid());
/* It's possible that if an earlier test run crashed it might
* have left a stale unix socket lying around. Delete any
@@ -390,10 +392,12 @@ QTestState *qtest_initf(const char *fmt, ...)
QTestState *qtest_init_with_serial(const char *extra_args, int *sock_fd)
{
int sock_fd_init;
- char *sock_path, sock_dir[] = "/tmp/qtest-serial-XXXXXX";
+ g_autofree char *sock_dir = NULL;
+ char *sock_path;
QTestState *qts;
- g_assert_true(g_mkdtemp(sock_dir) != NULL);
+ sock_dir = g_dir_make_tmp("qtest-serial-XXXXXX", NULL);
+ g_assert_true(sock_dir != NULL);
sock_path = g_strdup_printf("%s/sock", sock_dir);
sock_fd_init = init_socket(sock_path);
@@ -417,8 +421,8 @@ void qtest_quit(QTestState *s)
qtest_remove_abrt_handler(s);
qtest_kill_qemu(s);
- close(s->fd);
- close(s->qmp_fd);
+ closesocket(s->fd);
+ closesocket(s->qmp_fd);
g_string_free(s->rx, true);
for (GList *it = s->pending_events; it != NULL; it = it->next) {
@@ -588,17 +592,20 @@ int qtest_socket_server(const char *socket_path)
return sock;
}
+#ifndef _WIN32
void qtest_qmp_vsend_fds(QTestState *s, int *fds, size_t fds_num,
const char *fmt, va_list ap)
{
qmp_fd_vsend_fds(s->qmp_fd, fds, fds_num, fmt, ap);
}
+#endif
void qtest_qmp_vsend(QTestState *s, const char *fmt, va_list ap)
{
- qmp_fd_vsend_fds(s->qmp_fd, NULL, 0, fmt, ap);
+ qmp_fd_vsend(s->qmp_fd, fmt, ap);
}
+#ifndef _WIN32
QDict *qtest_vqmp_fds(QTestState *s, int *fds, size_t fds_num,
const char *fmt, va_list ap)
{
@@ -607,6 +614,7 @@ QDict *qtest_vqmp_fds(QTestState *s, int *fds, size_t fds_num,
/* Receive reply */
return qtest_qmp_receive(s);
}
+#endif
QDict *qtest_vqmp(QTestState *s, const char *fmt, va_list ap)
{
@@ -616,6 +624,7 @@ QDict *qtest_vqmp(QTestState *s, const char *fmt, va_list ap)
return qtest_qmp_receive(s);
}
+#ifndef _WIN32
QDict *qtest_qmp_fds(QTestState *s, int *fds, size_t fds_num,
const char *fmt, ...)
{
@@ -627,6 +636,7 @@ QDict *qtest_qmp_fds(QTestState *s, int *fds, size_t fds_num,
va_end(ap);
return response;
}
+#endif
QDict *qtest_qmp(QTestState *s, const char *fmt, ...)
{
@@ -1323,6 +1333,7 @@ void qtest_qmp_device_add(QTestState *qts, const char *driver, const char *id,
qobject_unref(args);
}
+#ifndef _WIN32
void qtest_qmp_add_client(QTestState *qts, const char *protocol, int fd)
{
QDict *resp;
@@ -1342,6 +1353,7 @@ void qtest_qmp_add_client(QTestState *qts, const char *protocol, int fd)
g_assert(!qdict_haskey(resp, "error"));
qobject_unref(resp);
}
+#endif
/*
* Generic hot-unplugging test via the device_del QMP command.