tests/qtest: netdev: test stream and dgram backends
PATCH v4 1/1 tests/qtest: netdev: test stream and dgram backends
---
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
tests/qtest/meson.build +2 -0
@@ -21,6 +21,7 @@ qtests_generic = [ 'test-hmp', 'qos-test', 'readconfig-test', + 'netdev-socket', ] if config_host.has_key('CONFIG_MODULES') qtests_generic += [ 'modules-test' ]
@@ -298,6 +299,7 @@ qtests = { 'tpm-tis-device-swtpm-test': [io, tpmemu_files, 'tpm-tis-util.c'], 'tpm-tis-device-test': [io, tpmemu_files, 'tpm-tis-util.c'], 'vmgenid-test': files('boot-sector.c', 'acpi-utils.c'), + 'netdev-socket': files('netdev-socket.c', '../unit/socket-helpers.c'), } gvnc = dependency('gvnc-1.0', required: false)
tests/qtest/netdev-socket.c new file +434 -0
434 lines not on this page · raw message
Signature · 1 line
2.39.0
Quoted 26 lines · Laurent Vivier
Signed-off-by Laurent Vivier <[email protected]>---
Notes:
v4:
- reworkEXPECT_STATE()
- useg_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
- Useg_mkdtemp()rather thang_file_open_tmp()
- Usesocketpair()intest_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 localhosttests/qtest/meson.build | 2 + tests/qtest/netdev-socket.c | 434 ++++++++++++++++++++++++++++++++++++ 2 files changed, 436 insertions(+)create mode 100644
tests/qtest/netdev-socket.c
[...]
Quoted 7 lines
tests/qtest/netdev-socket.c new file +7
-0+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 );
tests/qtest/netdev-socket.c line 405
Quoted 10 lines
tests/qtest/netdev-socket.c new file +10
-0+ +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:
Quoted 29 lines
tests/qtest/netdev-socket.c new file +29
-0+ } + +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; +}
Quoted 36 lines · Thomas Huth
Quoted 23 lines · Laurent Vivier
Signed-off-by Laurent Vivier <[email protected]>---
Notes:
v4:
- reworkEXPECT_STATE()
- useg_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
- Useg_mkdtemp()rather thang_file_open_tmp()
- Usesocketpair()intest_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 localhosttests/qtest/meson.build | 2 +
tests/qtest/netdev-socket.c| 434 ++++++++++++++++++++++++++++++++++++2 files changed, 436 insertions(+)create mode 100644
tests/qtest/netdev-socket.c[...]
Quoted 11 lines
tests/qtest/netdev-socket.c new file +11
-0+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;
Quoted 8 lines
Quoted 6 lines
+ }
+
+ 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?
No, g_error() is fatal.
https://docs.gtk.org/glib/func.error.html
Quoted 4 lines
Apart from that:
Acked-by Thomas Huth <[email protected]>
Thanks,
Laurent
Quoted 30 lines
Quoted 29 lines
+ }
tests/qtest/netdev-socket.c new file +28
-0+ + 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; +}
Quoted 46 lines · Laurent Vivier
Quoted 36 lines · Thomas Huth
Quoted 23 lines · Laurent Vivier
Signed-off-by Laurent Vivier <[email protected]>---
Notes:
v4:
- reworkEXPECT_STATE()
- useg_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
- Useg_mkdtemp()rather thang_file_open_tmp()
- Usesocketpair()intest_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 localhosttests/qtest/meson.build | 2 +
tests/qtest/netdev-socket.c| 434 ++++++++++++++++++++++++++++++++++++2 files changed, 436 insertions(+)create mode 100644
tests/qtest/netdev-socket.c[...]
Quoted 11 lines
tests/qtest/netdev-socket.c new file +11
-0+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;Quoted 8 lines
Quoted 6 lines
+ }
+
+ 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?
Quoted 3 lines
No,
g_error()is fatal.
Ah, alright, then this is fine, thanks for the clarification!
Thomas
Quoted 26 lines · Laurent Vivier
Signed-off-by Laurent Vivier <[email protected]>---
Notes:
v4:
- reworkEXPECT_STATE()
- useg_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
- Useg_mkdtemp()rather thang_file_open_tmp()
- Usesocketpair()intest_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 localhosttests/qtest/meson.build | 2 + tests/qtest/netdev-socket.c | 434 ++++++++++++++++++++++++++++++++++++ 2 files changed, 436 insertions(+)create mode 100644
tests/qtest/netdev-socket.c
[...]
tests/qtest/netdev-socket.c line 242
Quoted 7 lines
tests/qtest/netdev-socket.c new file +7
-0+static void test_stream_fd (void ) +{ +QTestState *qts0, *qts1; +int sock[2 ]; +int ret; + + ret =socketpair (AF_LOCAL ,SOCK_STREAM ,0 , sock);
I've put your patch into my queue, but this seems to fail on Windows:
https://cirrus-ci.com/task/4869069434781696?logs=main#L6562
Seems like socketpair() does not exist there?
Thomas
Quoted 35 lines · Thomas Huth
Quoted 23 lines · Laurent Vivier
Signed-off-by Laurent Vivier <[email protected]>---
Notes:
v4:
- reworkEXPECT_STATE()
- useg_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
- Useg_mkdtemp()rather thang_file_open_tmp()
- Usesocketpair()intest_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 localhosttests/qtest/meson.build | 2 +
tests/qtest/netdev-socket.c| 434 ++++++++++++++++++++++++++++++++++++2 files changed, 436 insertions(+)create mode 100644
tests/qtest/netdev-socket.c[...]
tests/qtest/netdev-socket.c line 242
Quoted 7 lines
tests/qtest/netdev-socket.c new file +7
-0+static void test_stream_fd (void ) +{ + QTestState *qts0, *qts1; + int sock[2]; + int ret; + + ret = socketpair(AF_LOCAL, SOCK_STREAM, 0, sock);I've put your patch into my queue, but this seems to fail on Windows:
Quoted 3 lines
https://cirrus-ci.com/task/4869069434781696?logs=main#L6562
Seems like
socketpair()does not exist there?
There is qemu_socketpair() and since yesterday available on win32:
https://lore.kernel.org/qemu-devel/[email protected]/
Quoted 19 lines · Laurent Vivier
Signed-off-by Laurent Vivier <[email protected]>---
Notes:
v4:
- reworkEXPECT_STATE()
- useg_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
- Useg_mkdtemp()rather thang_file_open_tmp()
- Usesocketpair()intest_stream_fd()
Quoted 7 lines
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 localhosttests/qtest/meson.build | 2 + tests/qtest/netdev-socket.c | 434 ++++++++++++++++++++++++++++++++++++ 2 files changed, 436 insertions(+)create mode 100644
tests/qtest/netdev-socket.c
FYI, the test also does not work on FreeBSD. It hangs on both, FreeBSD 12 and 13:
https://cirrus-ci.com/task/5024964768694272?logs=build#L6937
https://cirrus-ci.com/task/5379344567107584?logs=build#L6938
Thomas
Quoted 25 lines · Thomas Huth
Quoted 19 lines · Laurent Vivier
Signed-off-by Laurent Vivier <[email protected]>---
Notes:
v4:
- reworkEXPECT_STATE()
- useg_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
- Useg_mkdtemp()rather thang_file_open_tmp()
- Usesocketpair()intest_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 localhostQuoted 4 lines
tests/qtest/meson.build | 2 +
tests/qtest/netdev-socket.c| 434 ++++++++++++++++++++++++++++++++++++2 files changed, 436 insertions(+)create mode 100644
tests/qtest/netdev-socket.c
Quoted 5 lines
FYI, the test also does not work on FreeBSD. It hangs on both, FreeBSD 12 and 13:
https://cirrus-ci.com/task/5024964768694272?logs=build#L6937
https://cirrus-ci.com/task/5379344567107584?logs=build#L6938
Thanks.
Are you sure it's this test?
The "/netdev/stream/inet/ipv6" seems to be the last one of the series (if I compare with previous machines) and it is OK in the logs.
I don't understand where it can hang as we have an internal 5 seconds timeout (in EXPECT_STATE()).
And I don't understand why we have only /netdev/stream tests and no /netdev/dgram tests.
Is it possible to have more details?
Laurent
Quoted 28 lines · Laurent Vivier
Quoted 27 lines · Thomas Huth
Quoted 19 lines · Laurent Vivier
Signed-off-by Laurent Vivier <[email protected]>---
Notes:
v4:
- reworkEXPECT_STATE()
- useg_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
- Useg_mkdtemp()rather thang_file_open_tmp()
- Usesocketpair()intest_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 localhostQuoted 4 lines
tests/qtest/meson.build | 2 +
tests/qtest/netdev-socket.c| 434 ++++++++++++++++++++++++++++++++++++2 files changed, 436 insertions(+)create mode 100644
tests/qtest/netdev-socket.cFYI, the test also does not work on FreeBSD. It hangs on both, FreeBSD 12 and 13:
Quoted 7 lines
Quoted 3 lines
https://cirrus-ci.com/task/5024964768694272?logs=build#L6937
https://cirrus-ci.com/task/5379344567107584?logs=build#L6938
Thanks.
Are you sure it's this test?
Since it's hanging at the same spot in both jobs, I'm pretty sure, yes.
Quoted 7 lines
The "/netdev/stream/inet/ipv6" seems to be the last one of the series (if I compare with previous machines) and it is OK in the logs.
I don't understand where it can hang as we have an internal 5 seconds timeout (in
EXPECT_STATE()).And I don't understand why we have only /netdev/stream tests and no /netdev/dgram tests.
Is it possible to have more details?
You can reproduce the issue locally on a KVM-enabled Linux box by running:
make vm-build-freebsd J=4 TARGET_LIST=loongarch64-softmmu \
BUILD_TARGET=check-qtest EXTRA_CONFIGURE_OPTS=--enable-werror \
DEBUG=1
And if I'm running the test manually there, I get this error message:
qemu-system-loongarch64: -netdev stream,id=st0,server=true,addr.type=unix,addr.path=/tmp/netdev-socket.8JXDY1/stream_unix_abstract,addr.abstract=on: Parameter 'addr.abstract' is unexpected
Looking at qapi/sockets.json, the "abstract" parameter is only available with CONFIG_LINUX, so this cannot work on FreeBSD, indeed. Maybe it should be switched to CONFIG_POSIX? Otherwise you need to check for Linux in your qtest, I think.
HTH,
Thomas