Skip to content
Permalink
Browse files

tests: net: if: Test userspace support in net_if

Add more tests to test userspace enabled APIs.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
  • Loading branch information...
jukkar committed May 29, 2019
1 parent 041cd5f commit 01fa8a6fe2e6e5f0e02eba703e810244b3918519
Showing with 189 additions and 6 deletions.
  1. +5 −0 tests/net/iface/prj.conf
  2. +175 −1 tests/net/iface/src/main.c
  3. +9 −5 tests/net/iface/testcase.yaml
@@ -19,7 +19,12 @@ CONFIG_NET_BUF_RX_COUNT=10
CONFIG_NET_BUF_TX_COUNT=10
CONFIG_NET_IF_MAX_IPV6_COUNT=3
CONFIG_NET_IF_UNICAST_IPV6_ADDR_COUNT=6
CONFIG_NET_IF_UNICAST_IPV4_ADDR_COUNT=2
CONFIG_NET_MAX_NEXTHOPS=8
CONFIG_NET_IPV6_MAX_NEIGHBORS=8
CONFIG_NET_IPV6_ND=n
CONFIG_ZTEST=y
CONFIG_NET_IF_MAX_IPV4_COUNT=4
CONFIG_NET_IF_MAX_IPV6_COUNT=4
CONFIG_TEST_USERSPACE=y
CONFIG_NET_IF_USERSPACE_ACCESS=y
@@ -618,6 +618,167 @@ static void set_promisc_mode_off(void)
net_if_unset_promisc(iface4);
}

static struct in_addr my_ipv4_addr_test = { { { 10, 0, 0, 1 } } };
static struct in_addr my_ipv4_addr_not_found = { { { 1, 2, 3, 4 } } };

static void v4_addr_add(void)
{
bool ret;

ret = net_if_ipv4_addr_add_by_index(1, &my_ipv4_addr_test,
NET_ADDR_MANUAL, 0);
zassert_true(ret, "Cannot add IPv4 address");
}

static void v4_addr_lookup(void)
{
int ret;

ret = net_if_ipv4_addr_lookup_by_index(&my_ipv4_addr_test);
zassert_equal(ret, 1, "IPv4 address not found");

ret = net_if_ipv4_addr_lookup_by_index(&my_ipv4_addr_not_found);
zassert_not_equal(ret, 1, "IPv4 address found");
}

static void v4_addr_rm(void)
{
bool ret;

ret = net_if_ipv4_addr_rm_by_index(1, &my_ipv4_addr_test);
zassert_true(ret, "Cannot remove IPv4 address");
}

#define MY_ADDR_V4_USER { { { 10, 0, 0, 2 } } }
#define UNKNOWN_ADDR_V4_USER { { { 5, 6, 7, 8 } } }

static void v4_addr_add_user(void)
{
struct in_addr my_addr = MY_ADDR_V4_USER;
bool ret;

ret = net_if_ipv4_addr_add_by_index(1, &my_addr, NET_ADDR_MANUAL, 0);
if (IS_ENABLED(CONFIG_NET_IF_USERSPACE_ACCESS)) {
zassert_true(ret, "Cannot add IPv4 address");
} else if (IS_ENABLED(CONFIG_USERSPACE)) {
zassert_false(ret, "Could add IPv4 address");
} else {
zassert_true(ret, "Cannot add IPv4 address");
}
}

static void v4_addr_lookup_user(void)
{
struct in_addr my_addr = MY_ADDR_V4_USER;
struct in_addr unknown_addr = UNKNOWN_ADDR_V4_USER;
int ret;

if (IS_ENABLED(CONFIG_NET_IF_USERSPACE_ACCESS)) {
ret = net_if_ipv4_addr_lookup_by_index(&my_addr);
zassert_equal(ret, 1, "IPv4 address not found (%d)", ret);
}

ret = net_if_ipv4_addr_lookup_by_index(&unknown_addr);
zassert_equal(ret, 0, "IPv4 address found");
}

static void v4_addr_rm_user(void)
{
struct in_addr my_addr = MY_ADDR_V4_USER;
bool ret;

if (IS_ENABLED(CONFIG_NET_IF_USERSPACE_ACCESS)) {
ret = net_if_ipv4_addr_rm_by_index(1, &my_addr);
zassert_true(ret, "Cannot remove IPv4 address");
}
}

static
struct in6_addr my_ipv6_addr_test = { { { 0x20, 0x01, 0x0d, 0xb8, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0x1 } } };

static
struct in6_addr my_ipv6_addr_not_found = { { { 0x20, 0x01, 0x0d, 0xb8, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0x64 } } };

static void v6_addr_add(void)
{
bool ret;

ret = net_if_ipv6_addr_add_by_index(1, &my_ipv6_addr_test,
NET_ADDR_MANUAL, 0);
zassert_true(ret, "Cannot add IPv6 address");
}

static void v6_addr_lookup(void)
{
int ret;

ret = net_if_ipv6_addr_lookup_by_index(&my_ipv6_addr_test);
zassert_equal(ret, 1, "IPv6 address not found");

ret = net_if_ipv6_addr_lookup_by_index(&my_ipv6_addr_not_found);
zassert_not_equal(ret, 1, "IPv6 address found");
}

static void v6_addr_rm(void)
{
bool ret;

ret = net_if_ipv6_addr_rm_by_index(1, &my_ipv6_addr_test);
zassert_true(ret, "Cannot remove IPv6 address");
}

#define MY_ADDR_V6_USER { { { 0x20, 0x01, 0x0d, 0xb8, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0x65 } } }

#define UNKNOWN_ADDR_V6_USER { { { 0x20, 0x01, 0x0d, 0xb8, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0x66 } } }

static void v6_addr_add_user(void)
{
struct in6_addr my_addr = MY_ADDR_V6_USER;
bool ret;

ret = net_if_ipv6_addr_add_by_index(1, &my_addr, NET_ADDR_MANUAL, 0);
if (IS_ENABLED(CONFIG_NET_IF_USERSPACE_ACCESS)) {
zassert_true(ret, "Cannot add IPv6 address");
} else if (IS_ENABLED(CONFIG_USERSPACE)) {
zassert_false(ret, "Could add IPv6 address");
} else {
zassert_true(ret, "Cannot add IPv6 address");
}
}

static void v6_addr_lookup_user(void)
{
struct in6_addr my_addr = MY_ADDR_V6_USER;
struct in6_addr unknown_addr = UNKNOWN_ADDR_V6_USER;
int ret;

if (IS_ENABLED(CONFIG_NET_IF_USERSPACE_ACCESS)) {
ret = net_if_ipv6_addr_lookup_by_index(&my_addr);
zassert_equal(ret, 1, "IPv6 address not found (%d)", ret);

ret = net_if_ipv6_addr_lookup_by_index(&unknown_addr);
zassert_equal(ret, 0, "IPv6 address found");
}
}

static void v6_addr_rm_user(void)
{
struct in6_addr my_addr = MY_ADDR_V6_USER;
bool ret;

/* Check also that add is enabled so that we can remove something
* that was already added.
*/
if (IS_ENABLED(CONFIG_NET_IF_USERSPACE_ACCESS)) {
ret = net_if_ipv6_addr_rm_by_index(1, &my_addr);
zassert_true(ret, "Cannot remove IPv6 address");
}
}

void test_main(void)
{
ztest_test_suite(net_iface_test,
@@ -633,7 +794,20 @@ void test_main(void)
ztest_unit_test(check_promisc_mode_on),
ztest_unit_test(set_promisc_mode_on_again),
ztest_unit_test(set_promisc_mode_off),
ztest_unit_test(check_promisc_mode_off));
ztest_unit_test(check_promisc_mode_off),
ztest_unit_test(v4_addr_add),
ztest_unit_test(v4_addr_lookup),
ztest_unit_test(v4_addr_rm),
ztest_user_unit_test(v4_addr_add_user),
ztest_user_unit_test(v4_addr_lookup_user),
ztest_user_unit_test(v4_addr_rm_user),
ztest_unit_test(v6_addr_add),
ztest_unit_test(v6_addr_lookup),
ztest_unit_test(v6_addr_rm),
ztest_user_unit_test(v6_addr_add_user),
ztest_user_unit_test(v6_addr_lookup_user),
ztest_user_unit_test(v6_addr_rm_user)
);

ztest_run_test_suite(net_iface_test);
}
@@ -1,7 +1,11 @@
common:
platform_whitelist: native_posix qemu_x86 qemu_cortex_m3
min_ram: 16
tags: net iface
depends_on: netif
tests:
net.iface:
min_ram: 16
tags: net iface
depends_on: netif
net.iface.with_userspace:
extra_configs:
- CONFIG_NET_IF_USERSPACE_ACCESS=y
net.iface.no_userspace_allowed:
extra_configs:
- CONFIG_NET_IF_USERSPACE_ACCESS=n

0 comments on commit 01fa8a6

Please sign in to comment.
You can’t perform that action at this time.