Skip to content

Commit

Permalink
m3
Browse files Browse the repository at this point in the history
  • Loading branch information
thom311 committed May 16, 2024
1 parent 8539b7d commit f1dcf95
Show file tree
Hide file tree
Showing 4 changed files with 483 additions and 4 deletions.
53 changes: 53 additions & 0 deletions tests/cksuite-all-attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,58 @@ END_TEST

/*****************************************************************************/

START_TEST(test_nltst_select_route_parse)
{
/* This is a unit test for testing the unit-test helper function
* _nltst_select_route_parse(). */

#define _check_erp(str, exp_addr_family, exp_addr_pattern, exp_plen) \
do { \
const char *_str = (str); \
const int _exp_addr_family = (exp_addr_family); \
const char *const _exp_addr_pattern = (exp_addr_pattern); \
const int _exp_plen = (exp_plen); \
_nltst_auto_clear_select_route NLTstSelectRoute \
_select_route = { 0 }; \
_nltst_auto_clear_select_route NLTstSelectRoute \
_select_route2 = { 0 }; \
_nl_auto_free char *_str2 = NULL; \
\
_nltst_select_route_parse(_str, &_select_route); \
ck_assert_int_eq(_exp_addr_family, _select_route.addr_family); \
if (_nltst_inet_valid(AF_UNSPEC, _exp_addr_pattern)) { \
ck_assert_str_eq(_exp_addr_pattern, \
_select_route.addr); \
ck_assert_ptr_null(_select_route.addr_pattern); \
} else { \
ck_assert_str_eq(_exp_addr_pattern, \
_select_route.addr_pattern); \
ck_assert_ptr_null(_select_route.addr); \
} \
ck_assert_int_eq(_exp_plen, _select_route.plen); \
\
_nltst_assert_select_route(&_select_route); \
\
_str2 = _nltst_select_route_to_string(&_select_route); \
ck_assert_ptr_nonnull(_str2); \
\
_nltst_select_route_parse(_str2, &_select_route2); \
\
ck_assert(_nltst_select_route_equal(&_select_route, \
&_select_route2)); \
} while (0)

_check_erp("0.0.0.0", AF_INET, "0.0.0.0", -1);
_check_erp("4 0.0.0.0/0", AF_INET, "0.0.0.0", 0);
_check_erp(" 6\n 0:0::/0", AF_INET6, "::", 0);
_check_erp(" \n 0:0::/100", AF_INET6, "::", 100);
_check_erp("6 0:0::*/0 ", AF_INET6, "0:0::*", 0);
_check_erp("6 0:0::*/128 ", AF_INET6, "0:0::*", 128);
_check_erp("6 0:0::* ", AF_INET6, "0:0::*", -1);
}

/*****************************************************************************/

Suite *make_nl_attr_suite(void)
{
Suite *suite = suite_create("Netlink attributes");
Expand All @@ -153,6 +205,7 @@ Suite *make_nl_attr_suite(void)
tcase_add_test(tc, msg_construct);
tcase_add_test(tc, clone_cls_u32);
tcase_add_test(tc, test_nltst_strtok);
tcase_add_test(tc, test_nltst_select_route_parse);
suite_add_tcase(suite, tc);

return suite;
Expand Down
28 changes: 27 additions & 1 deletion tests/cksuite-all-netns.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,32 @@ END_TEST

/*****************************************************************************/

static void _route_init(int addr_family, struct nl_sock **sk,
struct nl_cache **cache)
{
ck_assert(sk && !*sk);
ck_assert(cache && !*cache);

*sk = _nltst_socket(NETLINK_ROUTE);
*cache = _nltst_rtnl_route_alloc_cache(*sk, addr_family);
}

START_TEST(route_1)
{
_nl_auto_nl_socket struct nl_sock *sk = NULL;
_nl_auto_nl_cache struct nl_cache *cache = NULL;

_nltst_add_link(NULL, "v1", "dummy", NULL);
_nltst_system("ip -d link set v1 up");

_route_init(AF_INET6, &sk, &cache);

_nltst_assert_route_cache(cache, "fe80::/64", "::", "::");
}
END_TEST

/*****************************************************************************/

Suite *make_nl_netns_suite(void)
{
Suite *suite = suite_create("netns");
Expand All @@ -311,7 +337,7 @@ Suite *make_nl_netns_suite(void)
nltst_netns_fixture_teardown);
tcase_add_test(tc, cache_and_clone);
tcase_add_loop_test(tc, test_create_iface, 0, 17);

tcase_add_test(tc, route_1);
suite_add_tcase(suite, tc);

return suite;
Expand Down
Loading

0 comments on commit f1dcf95

Please sign in to comment.