On 03/01/2023 12.00, Laurent Vivier wrote:
Signed-off-by: Laurent Vivier <lviv...@redhat.com>
Acked-by: Michael S. Tsirkin <m...@redhat.com>
---
Notes:
v4:
- rework EXPECT_STATE()
- use g_dir_make_tmp()
v3:
- Add "-M none" to avoid error:
"No machine specified, and there is no default"
v2:
- Fix ipv6 free port allocation
- Check for IPv4, IPv6, AF_UNIX
- Use g_mkdtemp() rather than g_file_open_tmp()
- Use socketpair() in test_stream_fd()
v1: compared to v14 of "qapi: net: add unix socket type support to netdev backend":
- use IP addresses 127.0.0.1 and ::1 rather than localhost
tests/qtest/meson.build | 2 +
tests/qtest/netdev-socket.c | 434 ++++++++++++++++++++++++++++++++++++
2 files changed, 436 insertions(+)
create mode 100644 tests/qtest/netdev-socket.c
[...]
+int main(int argc, char **argv)
+{
+ int ret;
+ bool has_ipv4, has_ipv6, has_afunix;
+ g_autoptr(GError) err = NULL;
+
+ 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;
+ }
+
+ tmpdir = g_dir_make_tmp("netdev-socket.XXXXXX", &err);
+ if (tmpdir == NULL) {
+ g_error("Can't create temporary directory in %s: %s",
+ g_get_tmp_dir(), err->message);
Should there also be a "goto end" here?
Apart from that:
Acked-by: Thomas Huth <th...@redhat.com>
+ }
+
+ 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(tmpdir);
+ g_free(tmpdir);
+
+ return ret;
+}