1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-25 06:23:53 +01:00

tests: unittests: extend gnrc_ipv6_nib unittests for holey NIB

When there are holes in the NIB (e.g. when entries were removed)
currently the NIB crashes the system due to a failed assertion.
This commit tests this behavior (`DEVELHELP` needs to be activated to
test this behavior). A fix will follow.
This commit is contained in:
Martine Lenders 2017-11-01 19:33:56 +01:00
parent fb7fcfdd10
commit fa81932a8f
2 changed files with 118 additions and 2 deletions

View File

@ -617,6 +617,79 @@ static void test_nib_ft_del__success(void)
TEST_ASSERT(!gnrc_ipv6_nib_ft_iter(NULL ,0, &iter_state, &fte));
}
/**
* Creates three default routes and removes the first one.
* The prefix list is then iterated.
* Expected result: there should be two default routes returned, the last
* two added.
*/
static void test_nib_ft_iter__empty_def_route_at_beginning(void)
{
gnrc_ipv6_nib_ft_t fte;
void *iter_state = NULL;
ipv6_addr_t next_hop = { .u64 = { { .u8 = LINK_LOCAL_PREFIX },
{ .u64 = TEST_UINT64 } } };
int count = 0;
TEST_ASSERT_EQUAL_INT(0, gnrc_ipv6_nib_ft_add(NULL, 0,
&next_hop, IFACE));
next_hop.u16[0].u16++;
TEST_ASSERT_EQUAL_INT(0, gnrc_ipv6_nib_ft_add(NULL, 0,
&next_hop, IFACE));
next_hop.u16[0].u16++;
TEST_ASSERT_EQUAL_INT(0, gnrc_ipv6_nib_ft_add(NULL, 0,
&next_hop, IFACE));
gnrc_ipv6_nib_ft_del(NULL, 0);
next_hop.u16[0].u16--;
while (gnrc_ipv6_nib_ft_iter(NULL, 0, &iter_state, &fte)) {
TEST_ASSERT(ipv6_addr_is_unspecified(&fte.dst));
TEST_ASSERT(ipv6_addr_equal(&fte.next_hop, &next_hop));
TEST_ASSERT_EQUAL_INT(0, fte.dst_len);
TEST_ASSERT_EQUAL_INT(IFACE, fte.iface);
count++;
next_hop.u16[0].u16++;
}
TEST_ASSERT_EQUAL_INT(2, count);
}
/**
* Creates three prefix based routes and removes the second one.
* The prefix list is then iterated.
* Expected result: there should be two prefix based routes returned, the first
* and the third one.
*/
static void test_nib_ft_iter__empty_pref_route_in_the_middle(void)
{
gnrc_ipv6_nib_ft_t fte;
void *iter_state = NULL;
ipv6_addr_t route = { .u64 = { { .u8 = GLOBAL_PREFIX },
{ .u64 = TEST_UINT64 } } };
const ipv6_addr_t next_hop = { .u64 = { { .u8 = LINK_LOCAL_PREFIX },
{ .u64 = TEST_UINT64 } } };
int count = 0;
TEST_ASSERT_EQUAL_INT(0, gnrc_ipv6_nib_ft_add(&route, GLOBAL_PREFIX_LEN,
&next_hop, IFACE));
route.u16[0].u16++;
TEST_ASSERT_EQUAL_INT(0, gnrc_ipv6_nib_ft_add(&route, GLOBAL_PREFIX_LEN,
&next_hop, IFACE));
route.u16[0].u16++;
TEST_ASSERT_EQUAL_INT(0, gnrc_ipv6_nib_ft_add(&route, GLOBAL_PREFIX_LEN,
&next_hop, IFACE));
route.u16[0].u16--;
gnrc_ipv6_nib_ft_del(&route, GLOBAL_PREFIX_LEN);
route.u16[0].u16--;
while (gnrc_ipv6_nib_ft_iter(NULL, 0, &iter_state, &fte)) {
TEST_ASSERT(ipv6_addr_match_prefix(&fte.dst, &route) >= GLOBAL_PREFIX_LEN);
TEST_ASSERT(ipv6_addr_equal(&fte.next_hop, &next_hop));
TEST_ASSERT_EQUAL_INT(GLOBAL_PREFIX_LEN, fte.dst_len);
TEST_ASSERT_EQUAL_INT(IFACE, fte.iface);
count++;
route.u16[0].u16 += 2; /* we skip the second address */
}
TEST_ASSERT_EQUAL_INT(2, count);
}
Test *tests_gnrc_ipv6_nib_ft_tests(void)
{
EMB_UNIT_TESTFIXTURES(fixtures) {
@ -646,7 +719,9 @@ Test *tests_gnrc_ipv6_nib_ft_tests(void)
new_TestFixture(test_nib_ft_add__success),
new_TestFixture(test_nib_ft_del__unknown),
new_TestFixture(test_nib_ft_del__success),
/* gnrc_ipv6_nib_ft_iter() is tested during all the tests above */
/* most of gnrc_ipv6_nib_ft_iter() is tested during all the tests above */
new_TestFixture(test_nib_ft_iter__empty_def_route_at_beginning),
new_TestFixture(test_nib_ft_iter__empty_pref_route_in_the_middle),
};
EMB_UNIT_TESTCALLER(tests, set_up, NULL,

View File

@ -377,6 +377,46 @@ static void test_nib_pl_del__success(void)
TEST_ASSERT(!gnrc_ipv6_nib_pl_iter(0, &iter_state, &ple));
}
/**
* Creates three prefix list entries and removes the second one.
* The prefix list is then iterated.
* Expected result: there should be two prefix list entries returned, the first
* and the third one
*/
static void test_nib_pl_iter__empty_in_the_middle(void)
{
gnrc_ipv6_nib_pl_t ple;
void *iter_state = NULL;
ipv6_addr_t pfx = { .u64 = { { .u8 = GLOBAL_PREFIX },
{ .u64 = TEST_UINT64 } } };
int count = 0;
TEST_ASSERT_EQUAL_INT(0, gnrc_ipv6_nib_pl_set(IFACE, &pfx,
GLOBAL_PREFIX_LEN,
UINT32_MAX, UINT32_MAX));
pfx.u16[0].u16++;
TEST_ASSERT_EQUAL_INT(0, gnrc_ipv6_nib_pl_set(IFACE, &pfx,
GLOBAL_PREFIX_LEN,
UINT32_MAX, UINT32_MAX));
pfx.u16[0].u16++;
TEST_ASSERT_EQUAL_INT(0, gnrc_ipv6_nib_pl_set(IFACE, &pfx,
GLOBAL_PREFIX_LEN,
UINT32_MAX, UINT32_MAX));
pfx.u16[0].u16--;
gnrc_ipv6_nib_pl_del(IFACE, &pfx, GLOBAL_PREFIX_LEN);
pfx.u16[0].u16--;
while (gnrc_ipv6_nib_pl_iter(0, &iter_state, &ple)) {
TEST_ASSERT(ipv6_addr_match_prefix(&ple.pfx, &pfx) >= GLOBAL_PREFIX_LEN);
TEST_ASSERT_EQUAL_INT(GLOBAL_PREFIX_LEN, ple.pfx_len);
TEST_ASSERT_EQUAL_INT(IFACE, ple.iface);
TEST_ASSERT_EQUAL_INT(UINT32_MAX, ple.valid_until);
TEST_ASSERT_EQUAL_INT(UINT32_MAX, ple.pref_until);
count++;
pfx.u16[0].u16 += 2; /* we skip the second address */
}
TEST_ASSERT_EQUAL_INT(2, count);
}
Test *tests_gnrc_ipv6_nib_pl_tests(void)
{
EMB_UNIT_TESTFIXTURES(fixtures) {
@ -396,7 +436,8 @@ Test *tests_gnrc_ipv6_nib_pl_tests(void)
new_TestFixture(test_nib_pl_set__success),
new_TestFixture(test_nib_pl_del__unknown),
new_TestFixture(test_nib_pl_del__success),
/* gnrc_ipv6_nib_pl_iter() is tested during all the tests above */
/* most of gnrc_ipv6_nib_pl_iter() is tested during all the tests above */
new_TestFixture(test_nib_pl_iter__empty_in_the_middle),
};
EMB_UNIT_TESTCALLER(tests, set_up, NULL,