mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
Merge pull request #17432 from benpicco/tests/socket_zep-fix
tests/socket_zep: fix automatic test
This commit is contained in:
commit
27f3261792
@ -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
|
||||
|
@ -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");
|
||||
}
|
||||
|
@ -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,16 +28,13 @@ s = None
|
||||
def testfunc(child):
|
||||
child.expect_exact("Socket ZEP device driver test")
|
||||
child.expect(r"Initializing socket ZEP with " +
|
||||
r"\(local: \[(?P<local_addr>[:0-9a-f]+)\]:(?P<local_port>\d+), " +
|
||||
r"remote: \[(?P<remote_addr>[:0-9a-f]+)\]:(?P<remote_port>\d+)\)")
|
||||
r"\(local: \[(?P<local_addr>[.0-9a-f]+)\]:(?P<local_port>\d+), " +
|
||||
r"remote: \[(?P<remote_addr>[.0-9a-f]+)\]:(?P<remote_port>\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'])
|
||||
assert(int(child.match.group('remote_port')) == zep_params['remote_port'])
|
||||
child.expect(r"\(Hwaddrs: (?P<short_addr>[0-9a-f]{4}), (?P<long_addr>[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))
|
||||
@ -47,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):
|
||||
|
Loading…
Reference in New Issue
Block a user