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.
This commit is contained in:
Francisco Molina 2019-12-03 20:08:19 +01:00
parent 4117b459af
commit 5bf1a22472
2 changed files with 33 additions and 12 deletions

View File

@ -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(&eth_netif->ipv6.addrs[i])) {
local_addr = &eth_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(&eth_netif->ipv6.addrs[i])) {
local_addr = &eth_netif->ipv6.addrs[i];
}
}
shell_run(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE);
return 0;
}

View File

@ -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))