From e7be547920c631273d138a276f197caaebffc5c1 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Tue, 21 Dec 2021 16:52:29 +0100 Subject: [PATCH 1/2] tests/socket_zep: adapt test to API expectations --- tests/socket_zep/main.c | 15 +-------------- tests/socket_zep/tests/01-run.py | 3 --- 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/tests/socket_zep/main.c b/tests/socket_zep/main.c index 499d20f571..284979cec4 100644 --- a/tests/socket_zep/main.c +++ b/tests/socket_zep/main.c @@ -63,18 +63,6 @@ static void test_init(void) _print_info(netdev); } -static void test_send__iolist_NULL(void) -{ - netdev_t *netdev = &_socket_zep_netdev.dev.netdev; - - puts("Send zero-length packet"); - int res = netdev->driver->send(netdev, NULL); - expect((res < 0) || (res == 0)); - if ((res < 0) && (errno == ECONNREFUSED)) { - puts("No remote socket exists (use scripts in `tests/` to have proper tests)"); - } -} - static void test_send__iolist_not_NULL(void) { iolist_t iolist[] = { { .iol_base = "Hello", .iol_len = sizeof("Hello") }, @@ -116,7 +104,6 @@ int main(void) _main_pid = thread_getpid(); test_init(); - test_send__iolist_NULL(); test_send__iolist_not_NULL(); test_recv(); /* does not return */ puts("ALL TESTS SUCCESSFUL"); @@ -131,7 +118,7 @@ static void _recv(netdev_t *dev) expect(exp_len >= 0); expect(((unsigned)exp_len) <= sizeof(_recvbuf)); - data_len = dev->driver->recv(dev, _recvbuf, sizeof(_recvbuf), &rx_info); + data_len = dev->driver->recv(dev, _recvbuf, exp_len, &rx_info); if (data_len < 0) { puts("Received invalid packet"); } diff --git a/tests/socket_zep/tests/01-run.py b/tests/socket_zep/tests/01-run.py index 843f3421b7..400f0cd095 100755 --- a/tests/socket_zep/tests/01-run.py +++ b/tests/socket_zep/tests/01-run.py @@ -35,9 +35,6 @@ def testfunc(child): assert(child.match.group('remote_addr') == zep_params['remote_addr']) assert(int(child.match.group('remote_port')) == zep_params['remote_port']) child.expect(r"\(Hwaddrs: (?P[0-9a-f]{4}), (?P[0-9a-f]{16})\)") - child.expect_exact("Send zero-length packet") - data, addr = s.recvfrom(RCVBUF_LEN) - assert(len(data) == (ZEP_DATA_HEADER_SIZE + FCS_LEN)) child.expect_exact("Send 'Hello\\0World\\0'") data, addr = s.recvfrom(RCVBUF_LEN) assert(len(data) == (ZEP_DATA_HEADER_SIZE + len("Hello\0World\0") + FCS_LEN)) From 79891e93181dca6fc2f2086dce0e49fec2566499 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Tue, 21 Dec 2021 16:53:27 +0100 Subject: [PATCH 2/2] tests/socket_zep: enable test on Murdock Murdock does not support IPv6, so use IPv4 for the automated test. --- tests/socket_zep/Makefile | 4 ---- tests/socket_zep/tests/01-run.py | 16 ++++++++-------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/tests/socket_zep/Makefile b/tests/socket_zep/Makefile index 0073b01ed6..b3131fa859 100644 --- a/tests/socket_zep/Makefile +++ b/tests/socket_zep/Makefile @@ -2,10 +2,6 @@ include ../Makefile.tests_common BOARD_WHITELIST = native # socket_zep is only available on native -# Cannot run the test on `murdock` -# ZEP: Unable to connect socket: Cannot assign requested address -TEST_ON_CI_BLACKLIST += native - USEMODULE += od USEMODULE += socket_zep USEMODULE += netdev diff --git a/tests/socket_zep/tests/01-run.py b/tests/socket_zep/tests/01-run.py index 400f0cd095..b72f66137b 100755 --- a/tests/socket_zep/tests/01-run.py +++ b/tests/socket_zep/tests/01-run.py @@ -17,9 +17,9 @@ ZEP_DATA_HEADER_SIZE = 32 FCS_LEN = 2 RCVBUF_LEN = IEEE802154_FRAME_LEN_MAX + ZEP_DATA_HEADER_SIZE + FCS_LEN zep_params = { - "local_addr": "::", + "local_addr": "127.0.0.1", "local_port": 12345, - "remote_addr": "::1", + "remote_addr": "127.0.0.1", "remote_port": 17754, } s = None @@ -28,8 +28,8 @@ s = None def testfunc(child): child.expect_exact("Socket ZEP device driver test") child.expect(r"Initializing socket ZEP with " + - r"\(local: \[(?P[:0-9a-f]+)\]:(?P\d+), " + - r"remote: \[(?P[:0-9a-f]+)\]:(?P\d+)\)") + r"\(local: \[(?P[.0-9a-f]+)\]:(?P\d+), " + + r"remote: \[(?P[.0-9a-f]+)\]:(?P\d+)\)") assert(child.match.group('local_addr') == zep_params['local_addr']) assert(int(child.match.group('local_port')) == zep_params['local_port']) assert(child.match.group('remote_addr') == zep_params['remote_addr']) @@ -44,18 +44,18 @@ def testfunc(child): b"\xfd\xae\x60\xd3\x21\xf1\x00\x00\x00\x00\x00\x00\x00\x00\x00" + b"\x00\x22\x41\xdc\x02\x23\x00\x38\x30\x00\x0a\x50\x45\x5a\x00" + b"\x5b\x45\x00\x0a\x50\x45\x5a\x00Hello World\x3a\xf2", - ("::1", zep_params['local_port'])) + ("127.0.0.1", zep_params['local_port'])) child.expect(r"RSSI: \d+, LQI: \d+, Data:") child.expect_exact(r"00000000 41 DC 02 23 00 38 30 00 0A 50 45 5A 00 5B 45 00") child.expect_exact(r"00000010 0A 50 45 5A 00 48 65 6C 6C 6F 20 57 6F 72 6C 64") if __name__ == "__main__": - os.environ['TERMFLAGS'] = "-z [%s]:%d,[%s]:%d" % ( + os.environ['TERMFLAGS'] = "--eui64=00:5a:45:50:0a:00:30:38 -z [%s]:%d,[%s]:%d" % ( zep_params['local_addr'], zep_params['local_port'], zep_params['remote_addr'], zep_params['remote_port']) - s = socket.socket(family=socket.AF_INET6, type=socket.SOCK_DGRAM) - s.bind(("::", zep_params['remote_port'])) + s = socket.socket(family=socket.AF_INET, type=socket.SOCK_DGRAM) + s.bind(("127.0.0.1", zep_params['remote_port'])) res = run(testfunc, timeout=1, echo=True, traceback=True) s.close() if (res == 0):