From: Thomas Huth <thuth@redhat.com>
To: Laurent Vivier <lvivier@redhat.com>, qemu-devel@nongnu.org
Cc: "Daniel P . Berrangé" <berrange@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Jason Wang" <jasowang@redhat.com>,
"Michael S . Tsirkin" <mst@redhat.com>
Subject: Re: [PATCH v3] tests/qtest: netdev: test stream and dgram backends
Date: Mon, 12 Dec 2022 14:20:08 +0100 [thread overview]
Message-ID: <1ef14f94-92f2-17ee-1517-517c7acbd512@redhat.com> (raw)
In-Reply-To: <20221109130301.790679-1-lvivier@redhat.com>
On 09/11/2022 14.03, Laurent Vivier wrote:
[...]
> diff --git a/tests/qtest/netdev-socket.c b/tests/qtest/netdev-socket.c
> new file mode 100644
> index 000000000000..b6b59244a282
> --- /dev/null
> +++ b/tests/qtest/netdev-socket.c
> @@ -0,0 +1,435 @@
> +/*
> + * QTest testcase for netdev stream and dgram
> + *
> + * Copyright (c) 2022 Red Hat, Inc.
> + *
> + * SPDX-License-Identifier: GPL-2.0-or-later
> + */
> +
> +#include "qemu/osdep.h"
> +#include <glib/gstdio.h>
> +#include "../unit/socket-helpers.h"
> +#include "libqtest.h"
> +
> +#define CONNECTION_TIMEOUT 5
> +
> +#define EXPECT_STATE(q, e, t) \
> +do { \
> + char *resp = qtest_hmp(q, "info network"); \
> + if (t) { \
> + strrchr(resp, t)[0] = 0; \
> + } \
> + g_test_timer_start(); \
> + while (g_test_timer_elapsed() < CONNECTION_TIMEOUT) { \
> + if (strcmp(resp, e) == 0) { \
> + break; \
> + } \
> + g_free(resp); \
> + resp = qtest_hmp(q, "info network"); \
> + if (t) { \
> + strrchr(resp, t)[0] = 0; \
> + } \
> + } \
> + g_assert_cmpstr(resp, ==, e); \
> + g_free(resp); \
> +} while (0)
Wouldn't it be possible to write this without the duplicated qtest_hmp() ?
Something like this:
#define EXPECT_STATE(q, e, t) \
do { \
char *resp = NULL; \
g_test_timer_start(); \
do { \
g_free(resp); \
resp = qtest_hmp(q, "info network"); \
if (t) { \
strrchr(resp, t)[0] = 0; \
} \
if (g_strequal(resp, e)) { \
break; \
} \
} while (g_test_timer_elapsed() < CONNECTION_TIMEOUT); \
g_assert_cmpstr(resp, ==, e); \
g_free(resp); \
} while (0)
?
Also matching strings against the output of a HMP command sound very fragile
- isn't there a way to do this with QMP instead?
[...]
> +int main(int argc, char **argv)
> +{
> + int ret;
> + bool has_ipv4, has_ipv6, has_afunix;
> + gchar dir[] = "/tmp/netdev-socket.XXXXXX";
No more hard-coded /tmp/ paths, please. We're currently in progress of
enabling the qtests on Windows, too. Please use g_dir_make_tmp() or
something similar instead.
> + g_test_init(&argc, &argv, NULL);
> +
> + if (socket_check_protocol_support(&has_ipv4, &has_ipv6) < 0) {
> + g_printerr("socket_check_protocol_support() failed\n");
> + goto end;
> + }
> +
> + if (g_mkdtemp(dir) == NULL) {
> + g_error("g_mkdtemp: %s", g_strerror(errno));
> + }
> + tmpdir = dir;
> +
> + if (has_ipv4) {
> + qtest_add_func("/netdev/stream/inet/ipv4", test_stream_inet_ipv4);
> + qtest_add_func("/netdev/dgram/inet", test_dgram_inet);
> + qtest_add_func("/netdev/dgram/mcast", test_dgram_mcast);
> + }
> + if (has_ipv6) {
> + qtest_add_func("/netdev/stream/inet/ipv6", test_stream_inet_ipv6);
> + }
> +
> + socket_check_afunix_support(&has_afunix);
> + if (has_afunix) {
> + qtest_add_func("/netdev/dgram/unix", test_dgram_unix);
> + qtest_add_func("/netdev/stream/unix", test_stream_unix);
> + qtest_add_func("/netdev/stream/unix/abstract",
> + test_stream_unix_abstract);
> + qtest_add_func("/netdev/stream/fd", test_stream_fd);
> + qtest_add_func("/netdev/dgram/fd", test_dgram_fd);
> + }
> +
> +end:
> + ret = g_test_run();
> +
> + g_rmdir(dir);
Maybe check the return code of g_rmdir(), to make sure that all temporary
files in the directory have indeed been cleaned up successfully?
> + return ret;
> +}
Thomas
next prev parent reply other threads:[~2022-12-12 13:30 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-09 13:03 [PATCH v3] tests/qtest: netdev: test stream and dgram backends Laurent Vivier
2022-12-12 13:20 ` Thomas Huth [this message]
2023-01-02 21:45 ` Laurent Vivier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1ef14f94-92f2-17ee-1517-517c7acbd512@redhat.com \
--to=thuth@redhat.com \
--cc=berrange@redhat.com \
--cc=jasowang@redhat.com \
--cc=lvivier@redhat.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=philmd@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).