tests/contrib/test_net: Don't assert on net_stream_recv() failure
This commit removes the assert() in _sync() and propagates the error to the caller. It was possible for the test_dns_tcp() test to set up an invalid socket descriptor and not notice that the socket was not usable, which would cause socket reads to fail, which would trigger the assert. This can occur in some CI environments where IPv6 networking is not available. These tests should probably just fail instead of crashing the build. Here is what the strace output looked like when this test asserted: write(1, "# DNS messages over TCP\n", 24) = 24 socket(PF_INET6, SOCK_STREAM|SOCK_NONBLOCK, IPPROTO_IP) = 3 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0 setsockopt(3, SOL_IPV6, IPV6_V6ONLY, [1], 4) = 0 bind(3, {sa_family=AF_INET6, sin6_port=htons(0), inet_pton(AF_INET6, "::1", &sin6_addr), sin6_flowinfo=0, sin6_scope_id=0}, 28) = -1 EADDRNOTAVAIL (Cannot assign requested address) close(3) = 0 write(1, "not ok 1 - single DNS, server, create socket\n", 45) = 45 listen(-99, 5) = -1 EBADF (Bad file descriptor) write(1, "not ok 2 - single DNS, server, start listening\n", 47) = 47 mmap(NULL, 8392704, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_STACK, -1, 0) = 0x7f340dc41000 mprotect(0x7f340dc41000, 4096, PROT_NONE) = 0 clone(child_stack=0x7f340e440ff0, flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID, parent_tidptr=0x7f340e4419d0, tls=0x7f340e441700, child_tidptr=0x7f340e4419d0) = 80049 write(1, "ok 3 - single DNS, server, start handler\n", 41) = 41 getsockname(-99, 0x7fffc7378760, 0x7fffc737867c) = -1 EBADF (Bad file descriptor) write(1, "not ok 4 - check getsockname return\n", 36) = 36 socket(PF_UNSPEC, SOCK_STREAM|SOCK_NONBLOCK, 0) = -1 EAFNOSUPPORT (Address family not supported by protocol) write(1, "not ok 5 - single DNS, client, create connected socket\n", 55) = 55 write(2, "test_net: contrib/test_net.c:410: _sync: Assertion `r == sizeof(buf)' failed.\n", 78) = 78 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f340ec4d000 rt_sigprocmask(SIG_UNBLOCK, [ABRT], NULL, 8) = 0 tgkill(80048, 80048, SIGABRT) = 0 --- SIGABRT {si_signo=SIGABRT, si_code=SI_TKILL, si_pid=80048, si_uid=0} --- +++ killed by SIGABRT (core dumped) +++ (I commented out all of the test_*() calls in main() except the call to test_dns_tcp(), so the test numbering on stdout is off.) This keeps the test_net program from assert()'ing on IPv4-only and IPv4/IPv6 machines, but perhaps a better solution would be to have the loop in test_dns_tcp() skip to the next test case if required socket operations fail.
Loading