Skip to content

Commit

Permalink
m4
Browse files Browse the repository at this point in the history
  • Loading branch information
thom311 committed May 9, 2022
1 parent d241f42 commit b92b84e
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 15 deletions.
40 changes: 40 additions & 0 deletions tests/cksuite-all-attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,45 @@ END_TEST

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

START_TEST(test_nltst_expected_routes_parse)
{
/* This is a unit test for testing the unit-test helper function
* _nltst_expected_routes_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_expected_routes_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); \
} 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 @@ -151,6 +190,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_expected_routes_parse);
suite_add_tcase(suite, tc);

return suite;
Expand Down
59 changes: 44 additions & 15 deletions tests/cksuite-all-netns.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,22 @@

#include "netlink-private/utils.h"
#include "netlink/route/link.h"
#include "netlink/route/link/bonding.h"
#include "netlink/route/link/bridge.h"
#include "netlink/route/link/ip6tnl.h"
#include "netlink/route/link/ipgre.h"
#include "netlink/route/link/ipip.h"
#include "netlink/route/link/ipvlan.h"
#include "netlink/route/link/ipvti.h"
#include "netlink/route/link/macsec.h"
#include "netlink/route/link/macvlan.h"
#include "netlink/route/link/macvtap.h"
#include "netlink/route/link/sit.h"
#include <netlink/route/link/bonding.h>
#include <netlink/route/link/bridge.h>
#include <netlink/route/link/ip6tnl.h>
#include <netlink/route/link/ipgre.h>
#include <netlink/route/link/ipip.h>
#include <netlink/route/link/ipvlan.h>
#include <netlink/route/link/ipvti.h>
#include <netlink/route/link/macsec.h>
#include <netlink/route/link/macvlan.h>
#include <netlink/route/link/macvtap.h>
#include <netlink/route/link/veth.h>
#include <netlink/route/link/vlan.h>
#include <netlink/route/link/vrf.h>
#include <netlink/route/link/vxlan.h>
#include "netlink/route/link/veth.h"
#include "netlink/route/link/vlan.h"
#include "netlink/route/link/vrf.h"
#include "netlink/route/link/vxlan.h"
#include "netlink/route/route.h"

#include "cksuite-all.h"

Expand Down Expand Up @@ -303,6 +304,34 @@ 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");
//system("ip -d link set v1 up");
//system("ip -d link");
//system("ip -d route show table all");

_route_init(AF_INET6, &sk, &cache);

//_nltst_assert_route_cache(cache, "0.0.0.0/0", "", "");
}
END_TEST

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

Suite *make_nl_netns_suite(void)
{
Suite *suite = suite_create("netns");
Expand All @@ -312,7 +341,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

0 comments on commit b92b84e

Please sign in to comment.