summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorSimon Goldschmidt <[email protected]>2018-06-08 22:18:50 +0200
committerSimon Goldschmidt <[email protected]>2018-06-08 22:18:50 +0200
commitfd050b8a97521651016e8b830b15d1be123358dc (patch)
tree452e2ecac26c78fd76159f5a1cf8bf297cf99d37 /test
parentd4845abac64c746d781e2c90bebddfe3bfe9d679 (diff)
fix bug #53971 Lwip sends Router Solicitation on address changes
... and add a unit test for it. Moved resetting netif->rs_count from all reports to link-up and netif-up only. While at it, clean up the interface a bit so that netif->rs_count is touched from nd6.c only. Signed-off-by: Simon Goldschmidt <[email protected]>
Diffstat (limited to 'test')
-rw-r--r--test/unit/ip6/test_ip6.c172
-rw-r--r--test/unit/ip6/test_ip6.h8
-rw-r--r--test/unit/lwip_unittests.c2
3 files changed, 182 insertions, 0 deletions
diff --git a/test/unit/ip6/test_ip6.c b/test/unit/ip6/test_ip6.c
new file mode 100644
index 00000000..cf55d5b7
--- /dev/null
+++ b/test/unit/ip6/test_ip6.c
@@ -0,0 +1,172 @@
+#include "test_ip6.h"
+
+#include "lwip/ethip6.h"
+#include "lwip/ip6.h"
+#include "lwip/inet_chksum.h"
+#include "lwip/nd6.h"
+#include "lwip/stats.h"
+#include "lwip/prot/ethernet.h"
+#include "lwip/prot/ip.h"
+#include "lwip/prot/ip6.h"
+
+#include "lwip/tcpip.h"
+
+#if LWIP_IPV6 /* allow to build the unit tests without IPv6 support */
+
+static struct netif test_netif6;
+static int linkoutput_ctr;
+
+static err_t
+default_netif_linkoutput(struct netif *netif, struct pbuf *p)
+{
+ fail_unless(netif == &test_netif6);
+ fail_unless(p != NULL);
+ linkoutput_ctr++;
+ return ERR_OK;
+}
+
+static err_t
+default_netif_init(struct netif *netif)
+{
+ fail_unless(netif != NULL);
+ netif->linkoutput = default_netif_linkoutput;
+ netif->output_ip6 = ethip6_output;
+ netif->mtu = 1500;
+ netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHERNET | NETIF_FLAG_MLD6;
+ netif->hwaddr_len = ETH_HWADDR_LEN;
+ return ERR_OK;
+}
+
+static void
+default_netif_add(void)
+{
+ struct netif *n;
+ fail_unless(netif_default == NULL);
+ n = netif_add_noaddr(&test_netif6, NULL, default_netif_init, NULL);
+ fail_unless(n == &test_netif6);
+ netif_set_default(&test_netif6);
+}
+
+static void
+default_netif_remove(void)
+{
+ fail_unless(netif_default == &test_netif6);
+ netif_remove(&test_netif6);
+}
+
+static void
+ip6_test_handle_timers(int count)
+{
+ int i;
+ for (i = 0; i < count; i++) {
+ nd6_tmr();
+ }
+}
+
+/* Setups/teardown functions */
+
+static void
+ip6_setup(void)
+{
+ default_netif_add();
+ lwip_check_ensure_no_alloc(SKIP_POOL(MEMP_SYS_TIMEOUT));
+}
+
+static void
+ip6_teardown(void)
+{
+ if (netif_list->loop_first != NULL) {
+ pbuf_free(netif_list->loop_first);
+ netif_list->loop_first = NULL;
+ }
+ netif_list->loop_last = NULL;
+ /* poll until all memory is released... */
+ tcpip_thread_poll_one();
+ default_netif_remove();
+ lwip_check_ensure_no_alloc(SKIP_POOL(MEMP_SYS_TIMEOUT));
+}
+
+
+/* Test functions */
+
+static void
+test_ip6_ll_addr_iter(int expected_ctr1, int expected_ctr2)
+{
+ fail_unless(linkoutput_ctr == 0);
+
+ /* test that nothing is sent with link uo but netif down */
+ netif_set_link_up(&test_netif6);
+ ip6_test_handle_timers(500);
+ fail_unless(linkoutput_ctr == 0);
+ netif_set_link_down(&test_netif6);
+ fail_unless(linkoutput_ctr == 0);
+
+ /* test that nothing is sent with link down but netif up */
+ netif_set_up(&test_netif6);
+ ip6_test_handle_timers(500);
+ fail_unless(linkoutput_ctr == 0);
+ netif_set_down(&test_netif6);
+ fail_unless(linkoutput_ctr == 0);
+
+ /* test what is sent with link up + netif up */
+ netif_set_link_up(&test_netif6);
+ netif_set_up(&test_netif6);
+ ip6_test_handle_timers(500);
+ fail_unless(linkoutput_ctr == expected_ctr1);
+ netif_set_down(&test_netif6);
+ netif_set_link_down(&test_netif6);
+ fail_unless(linkoutput_ctr == expected_ctr1);
+ linkoutput_ctr = 0;
+
+ netif_set_up(&test_netif6);
+ netif_set_link_up(&test_netif6);
+ ip6_test_handle_timers(500);
+ fail_unless(linkoutput_ctr == expected_ctr2);
+ netif_set_link_down(&test_netif6);
+ netif_set_down(&test_netif6);
+ fail_unless(linkoutput_ctr == expected_ctr2);
+ linkoutput_ctr = 0;
+}
+
+START_TEST(test_ip6_ll_addr)
+{
+ LWIP_UNUSED_ARG(_i);
+
+ /* test without link-local address */
+ test_ip6_ll_addr_iter(0, 0);
+
+ /* test with link-local address */
+ netif_create_ip6_linklocal_address(&test_netif6, 1);
+ test_ip6_ll_addr_iter(3 + LWIP_IPV6_DUP_DETECT_ATTEMPTS + LWIP_IPV6_MLD, 3);
+}
+END_TEST
+
+
+/** Create the suite including all tests for this module */
+Suite *
+ip6_suite(void)
+{
+ testfunc tests[] = {
+ TESTFUNC(test_ip6_ll_addr),
+ };
+ return create_suite("IPv6", tests, sizeof(tests)/sizeof(testfunc), ip6_setup, ip6_teardown);
+}
+
+#else /* LWIP_IPV6 */
+
+/* allow to build the unit tests without IPv6 support */
+START_TEST(test_ip6_dummy)
+{
+ LWIP_UNUSED_ARG(_i);
+}
+END_TEST
+
+Suite *
+ip6_suite(void)
+{
+ testfunc tests[] = {
+ TESTFUNC(test_ip6_dummy),
+ };
+ return create_suite("IPv6", tests, sizeof(tests)/sizeof(testfunc), NULL, NULL);
+}
+#endif /* LWIP_IPV6 */
diff --git a/test/unit/ip6/test_ip6.h b/test/unit/ip6/test_ip6.h
new file mode 100644
index 00000000..a09345b3
--- /dev/null
+++ b/test/unit/ip6/test_ip6.h
@@ -0,0 +1,8 @@
+#ifndef LWIP_HDR_TEST_IP6_H
+#define LWIP_HDR_TEST_IP6_H
+
+#include "../lwip_check.h"
+
+Suite* ip6_suite(void);
+
+#endif
diff --git a/test/unit/lwip_unittests.c b/test/unit/lwip_unittests.c
index c33e9d61..497a44b2 100644
--- a/test/unit/lwip_unittests.c
+++ b/test/unit/lwip_unittests.c
@@ -1,6 +1,7 @@
#include "lwip_check.h"
#include "ip4/test_ip4.h"
+#include "ip6/test_ip6.h"
#include "udp/test_udp.h"
#include "tcp/test_tcp.h"
#include "tcp/test_tcp_oos.h"
@@ -62,6 +63,7 @@ int main(void)
size_t i;
suite_getter_fn* suites[] = {
ip4_suite,
+ ip6_suite,
udp_suite,
tcp_suite,
tcp_oos_suite,