From aaaa8a21ed1a4d482c75c51554161454b0276d86 Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Mon, 15 Apr 2019 17:54:37 +0200 Subject: [PATCH] tests: provide testcase for issue 11398 --- tests/gnrc_netif_ieee802154/Makefile | 15 ++++++ tests/gnrc_netif_ieee802154/README.md | 11 ++++ tests/gnrc_netif_ieee802154/main.c | 38 +++++++++++++ tests/gnrc_netif_ieee802154/tests/01-run.py | 60 +++++++++++++++++++++ 4 files changed, 124 insertions(+) create mode 100644 tests/gnrc_netif_ieee802154/Makefile create mode 100644 tests/gnrc_netif_ieee802154/README.md create mode 100644 tests/gnrc_netif_ieee802154/main.c create mode 100755 tests/gnrc_netif_ieee802154/tests/01-run.py diff --git a/tests/gnrc_netif_ieee802154/Makefile b/tests/gnrc_netif_ieee802154/Makefile new file mode 100644 index 0000000000..874bf8c861 --- /dev/null +++ b/tests/gnrc_netif_ieee802154/Makefile @@ -0,0 +1,15 @@ +BOARD_WHITELIST = native + +include ../Makefile.tests_common + +TERMFLAGS ?= -z "0.0.0.0:17755,localhost:17754" + +USEMODULE += socket_zep +USEMODULE += auto_init_gnrc_netif +USEMODULE += gnrc +USEMODULE += gnrc_netif_ieee802154 +USEMODULE += gnrc_pktdump + +TEST_ON_CI_WHITELIST += native + +include $(RIOTBASE)/Makefile.include diff --git a/tests/gnrc_netif_ieee802154/README.md b/tests/gnrc_netif_ieee802154/README.md new file mode 100644 index 0000000000..48f3d23dd6 --- /dev/null +++ b/tests/gnrc_netif_ieee802154/README.md @@ -0,0 +1,11 @@ +Tests for `gnrc_netif_ieee802154` +================================= + +Motivation for this test was a reproducible test case for issue [#11398]. +Just run `make all test` for `native` to do run it. + +The test may be extended with other test cases for the `gnrc_netif_ieee802154` +module in the future. + + +[#11398]: https://github.com/RIOT-OS/RIOT/issues/11398 diff --git a/tests/gnrc_netif_ieee802154/main.c b/tests/gnrc_netif_ieee802154/main.c new file mode 100644 index 0000000000..a4078a7287 --- /dev/null +++ b/tests/gnrc_netif_ieee802154/main.c @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2019 Freie Universität Berlin + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @{ + * + * @file + * @author Martine Lenders + */ + +#include "net/gnrc.h" +#include "net/gnrc/netif.h" +#include "net/gnrc/pktdump.h" + + +int main(void) +{ + char addr_str[GNRC_NETIF_L2ADDR_MAXLEN * 3]; + gnrc_netif_t *netif = gnrc_netif_iter(NULL); + + printf("l2_addr: %s\n", gnrc_netif_addr_to_str(netif->l2addr, + netif->l2addr_len, + addr_str)); + + gnrc_netreg_entry_t dump = GNRC_NETREG_ENTRY_INIT_PID( + GNRC_NETREG_DEMUX_CTX_ALL, + gnrc_pktdump_pid + ); + gnrc_netreg_register(GNRC_NETTYPE_UNDEF, &dump); + return 0; +} + +/** @} */ diff --git a/tests/gnrc_netif_ieee802154/tests/01-run.py b/tests/gnrc_netif_ieee802154/tests/01-run.py new file mode 100755 index 0000000000..74b6ae5676 --- /dev/null +++ b/tests/gnrc_netif_ieee802154/tests/01-run.py @@ -0,0 +1,60 @@ +#!/usr/bin/env python3 + +# Copyright (C) 2019 Freie Universität Berlin +# +# This file is subject to the terms and conditions of the GNU Lesser +# General Public License v2.1. See the file LICENSE in the top level +# directory for more details. + +import sys +import socket +from testrunner import run +from pexpect import EOF, TIMEOUT +from scapy.all import ZEP2, Dot15d4Data, Dot15d4FCS, raw + +ZEP_V2_VERSION = 2 +ZEP_V2_TYPE_DATA = 1 + + +def testfunc(child): + with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s: + s.bind(("", 17754)) + child.expect("l2_addr: ([0-9A-F:]+)") + dst = int(child.match.group(1).replace(':', ''), base=16) + + # first send valid packet to check if communication is set up correctly + # generated with udp send 61616 0 in tests/gnrc_udp + payload = b"\x7e\x33\xf3\x00" + payload = ( + Dot15d4FCS(fcf_srcaddrmode=2, fcf_panidcompress=True, + fcf_frametype="Data") / + Dot15d4Data(dest_addr=dst, dest_panid=0x23, src_addr=dst-1) / + payload + ) + packet = raw( + ZEP2(ver=ZEP_V2_VERSION, type=ZEP_V2_TYPE_DATA, channel=26, + length=len(payload)) / payload + ) + s.sendto(packet, ("localhost", 17755)) + child.expect("PKTDUMP: data received:") + child.expect("00000000 7E 33 F3 00") + child.expect("~~ PKT - 2 snips, total size: 16 byte") + payload = ( + Dot15d4FCS(fcf_srcaddrmode=2, fcf_panidcompress=True, + fcf_frametype="Data") / + # just append destination PAN ID and address + bytes([0x23, 0x00, dst & 0xff, dst >> 8]) + ) + packet = raw( + ZEP2(ver=ZEP_V2_VERSION, type=ZEP_V2_TYPE_DATA, channel=26, + length=len(payload)) / payload + ) + s.sendto(packet, ("localhost", 17755)) + res = child.expect([TIMEOUT, EOF, "PKTDUMP: data received:"]) + # we actually want the timeout here. The application either + # receives a bogus packet or crashes in an error case case + assert res == 0 + + +if __name__ == "__main__": + sys.exit(run(testfunc, timeout=1))