From 4117b459afde436edaab4df7b2c40e463b655681 Mon Sep 17 00:00:00 2001 From: Francisco Molina Date: Tue, 3 Dec 2019 19:19:07 +0100 Subject: [PATCH 1/4] tests/shell: fix reset dependency --- tests/shell/tests/01-run.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/shell/tests/01-run.py b/tests/shell/tests/01-run.py index be99c9bbab..1afd19533e 100755 --- a/tests/shell/tests/01-run.py +++ b/tests/shell/tests/01-run.py @@ -63,9 +63,6 @@ def check_cmd(child, cmd, expected): def testfunc(child): - # check startup message - child.expect('test_shell.') - # loop other defined commands and expected output for cmd, expected in CMDS: check_cmd(child, cmd, expected) From 5bf1a2247219eaa652790452125bb5cf7b5deacc Mon Sep 17 00:00:00 2001 From: Francisco Molina Date: Tue, 3 Dec 2019 20:08:19 +0100 Subject: [PATCH 2/4] tests/gnrc_ipv6_ext_frag: refactor to not depend on reset Using the shell to run unittests allows not needing to wait for a string at the start of the test which makes the test independent having the application reset after the terminal is open. The same goes for triggering sending UDP test pkts. --- tests/gnrc_ipv6_ext_frag/main.c | 43 +++++++++++++++++------- tests/gnrc_ipv6_ext_frag/tests/01-run.py | 2 ++ 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/tests/gnrc_ipv6_ext_frag/main.c b/tests/gnrc_ipv6_ext_frag/main.c index 60e130f9a5..c1fe8ac956 100644 --- a/tests/gnrc_ipv6_ext_frag/main.c +++ b/tests/gnrc_ipv6_ext_frag/main.c @@ -84,11 +84,6 @@ static gnrc_netif_t *eth_netif, *mock_netif; static ipv6_addr_t *local_addr; static char mock_netif_stack[THREAD_STACKSIZE_DEFAULT]; static char line_buf[SHELL_DEFAULT_BUFSIZE]; -static const shell_command_t shell_commands[] = { - { "udp", "send data over UDP and listen on UDP ports", udp_cmd }, - { "test", "sends data according to a specified numeric test", shell_test_cmd }, - { NULL, NULL, NULL } -}; static const ipv6_addr_t _src = { .u8 = TEST_SRC }; static const ipv6_addr_t _dst = { .u8 = TEST_DST }; @@ -617,6 +612,29 @@ static int shell_test_cmd(int argc, char **argv) return 0; } +static int send_test_pkt(int argc, char **argv) +{ + (void) argc; + (void) argv; + + printf("Sending UDP test packets to port %u\n", TEST_PORT); + for (unsigned i = 0; i < GNRC_NETIF_IPV6_ADDRS_NUMOF; i++) { + if (ipv6_addr_is_link_local(ð_netif->ipv6.addrs[i])) { + local_addr = ð_netif->ipv6.addrs[i]; + } + } + return 0; +} + +static int unittests(int argc, char** argv) +{ + (void) argc; + (void) argv; + + run_unittests(); + return 0; +} + /* TODO: test if forwarded packet is not fragmented */ static int mock_get_device_type(netdev_t *dev, void *value, size_t max_len) @@ -649,6 +667,14 @@ static int mock_send(netdev_t *dev, const iolist_t *iolist) return res; } +static const shell_command_t shell_commands[] = { + { "udp", "send data over UDP and listen on UDP ports", udp_cmd }, + { "unittests", "Runs unitest", unittests}, + { "test", "sends data according to a specified numeric test", shell_test_cmd }, + { "send-test-pkt", "start sendig UDP test packets to TEST_PORT", send_test_pkt }, + { NULL, NULL, NULL } +}; + int main(void) { eth_netif = gnrc_netif_iter(NULL); @@ -663,13 +689,6 @@ int main(void) sizeof(mock_netif_stack), GNRC_NETIF_PRIO, "mock_netif", (netdev_t *)&mock_netdev); - run_unittests(); - printf("Sending UDP test packets to port %u\n", TEST_PORT); - for (unsigned i = 0; i < GNRC_NETIF_IPV6_ADDRS_NUMOF; i++) { - if (ipv6_addr_is_link_local(ð_netif->ipv6.addrs[i])) { - local_addr = ð_netif->ipv6.addrs[i]; - } - } shell_run(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE); return 0; } diff --git a/tests/gnrc_ipv6_ext_frag/tests/01-run.py b/tests/gnrc_ipv6_ext_frag/tests/01-run.py index b99f261224..3308737686 100755 --- a/tests/gnrc_ipv6_ext_frag/tests/01-run.py +++ b/tests/gnrc_ipv6_ext_frag/tests/01-run.py @@ -318,6 +318,7 @@ def test_ipv6_ext_frag_fwd_too_big(child, s, iface, ll_dst): def testfunc(child): tap = get_bridge(os.environ["TAP"]) + child.sendline("unittests") child.expect(r"OK \((\d+) tests\)") # wait for and check result of unittests print("." * int(child.match.group(1)), end="", flush=True) @@ -337,6 +338,7 @@ def testfunc(child): print("FAILED") raise e + child.sendline("send-test-pkt") child.expect(r"Sending UDP test packets to port (\d+)\r\n") port = int(child.match.group(1)) From eb9d27db6960c2ec1c650950a020af6d3d967346 Mon Sep 17 00:00:00 2001 From: Francisco Molina Date: Tue, 3 Dec 2019 20:05:32 +0100 Subject: [PATCH 3/4] tests/gnrc_rpl_srh: run unittests through shell Using the shell to run unittests allows not needing to wait for a string at the start of the test which makes the test independent having the application reset after the terminal is open. --- tests/gnrc_rpl_srh/main.c | 21 +++++++++++++++------ tests/gnrc_rpl_srh/tests/01-run.py | 2 +- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/tests/gnrc_rpl_srh/main.c b/tests/gnrc_rpl_srh/main.c index 63a6aca249..bdddca5956 100644 --- a/tests/gnrc_rpl_srh/main.c +++ b/tests/gnrc_rpl_srh/main.c @@ -234,11 +234,6 @@ static int _ipreg(int argc, char **argv) return 0; } -static const shell_command_t shell_commands[] = { - { "ip", "Registers pktdump to protocol number 59 (no next header)", _ipreg }, - { NULL, NULL, NULL } -}; - static void run_unittests(void) { EMB_UNIT_TESTFIXTURES(fixtures) { @@ -255,9 +250,23 @@ static void run_unittests(void) TESTS_END(); } +static int _unittests(int argc, char** argv) +{ + (void) argc; + (void) argv; + + run_unittests(); + return 0; +} + +static const shell_command_t shell_commands[] = { + { "ip", "Registers pktdump to protocol number 59 (no next header)", _ipreg }, + { "unittests", "Runs unitest", _unittests}, + { NULL, NULL, NULL } +}; + int main(void) { - run_unittests(); shell_run(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE); return 0; } diff --git a/tests/gnrc_rpl_srh/tests/01-run.py b/tests/gnrc_rpl_srh/tests/01-run.py index ef8a889141..eb566e8053 100755 --- a/tests/gnrc_rpl_srh/tests/01-run.py +++ b/tests/gnrc_rpl_srh/tests/01-run.py @@ -337,7 +337,7 @@ def test_time_exc(child, iface, hw_dst, ll_dst, ll_src): def testfunc(child): global sniffer tap = get_bridge(os.environ["TAP"]) - + child.sendline("unittests") child.expect(r"OK \((\d+) tests\)") # wait for and check result of unittests print("." * int(child.match.group(1)), end="", flush=True) lladdr_src = get_host_lladdr(tap) From 341a4b5bfdef099e2e829141e5266aa146c14e74 Mon Sep 17 00:00:00 2001 From: Francisco Molina Date: Tue, 3 Dec 2019 20:03:49 +0100 Subject: [PATCH 4/4] tests/gnrc_%: use tests_utils_interactive_sync --- tests/gnrc_ipv6_ext/Makefile | 2 -- tests/gnrc_ipv6_ext_frag/Makefile | 2 -- tests/gnrc_rpl_srh/Makefile | 2 -- tests/gnrc_sock_dns/Makefile | 2 -- tests/gnrc_tcp/Makefile | 2 -- 5 files changed, 10 deletions(-) diff --git a/tests/gnrc_ipv6_ext/Makefile b/tests/gnrc_ipv6_ext/Makefile index 79bc3382a1..d51860e533 100644 --- a/tests/gnrc_ipv6_ext/Makefile +++ b/tests/gnrc_ipv6_ext/Makefile @@ -35,8 +35,6 @@ USEMODULE += shell USEMODULE += shell_commands USEMODULE += ps -DISABLE_MODULE += test_utils_interactive_sync - # The test requires some setup and to be run as root # So it cannot currently be run TEST_ON_CI_BLACKLIST += all diff --git a/tests/gnrc_ipv6_ext_frag/Makefile b/tests/gnrc_ipv6_ext_frag/Makefile index 19fe733bde..80884344db 100644 --- a/tests/gnrc_ipv6_ext_frag/Makefile +++ b/tests/gnrc_ipv6_ext_frag/Makefile @@ -44,8 +44,6 @@ USEMODULE += shell USEMODULE += shell_commands USEMODULE += ps -DISABLE_MODULE += test_utils_interactive_sync - # The test requires some setup and to be run as root # So it cannot currently be run TEST_ON_CI_BLACKLIST += all diff --git a/tests/gnrc_rpl_srh/Makefile b/tests/gnrc_rpl_srh/Makefile index 4be5e28b19..79d4cd74b9 100644 --- a/tests/gnrc_rpl_srh/Makefile +++ b/tests/gnrc_rpl_srh/Makefile @@ -39,8 +39,6 @@ USEMODULE += shell USEMODULE += shell_commands USEMODULE += ps -DISABLE_MODULE += test_utils_interactive_sync - # The test requires some setup and to be run as root # So it cannot currently be run TEST_ON_CI_BLACKLIST += all diff --git a/tests/gnrc_sock_dns/Makefile b/tests/gnrc_sock_dns/Makefile index ef2d5bf380..5837b7bec5 100644 --- a/tests/gnrc_sock_dns/Makefile +++ b/tests/gnrc_sock_dns/Makefile @@ -32,8 +32,6 @@ USEMODULE += shell_commands USEMODULE += posix_inet -DISABLE_MODULE += test_utils_interactive_sync - LOW_MEMORY_BOARDS := nucleo-f334r8 msb-430 msb-430h ifeq ($(BOARD),$(filter $(BOARD),$(LOW_MEMORY_BOARDS))) diff --git a/tests/gnrc_tcp/Makefile b/tests/gnrc_tcp/Makefile index ea2f5faefd..88abd3bd5e 100644 --- a/tests/gnrc_tcp/Makefile +++ b/tests/gnrc_tcp/Makefile @@ -39,8 +39,6 @@ USEMODULE += shell USEMODULE += shell_commands USEMODULE += od -DISABLE_MODULE += test_utils_interactive_sync - # Export used tap device to environment export TAPDEV = $(TAP)