Skip to content
Permalink
Browse files

tests: net: utils: Add userspace tests for net_addr_ntop/pton()

Add unit tests to net_addr_ntop() and net_addr_pton() in order to
verify that the functions can be called from userspace.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
  • Loading branch information...
jukkar authored and andrewboie committed Jun 12, 2019
1 parent 5d13df9 commit 8cf4d59180e3ff760179e65fc4a047672e9d5a93
Showing with 32 additions and 29 deletions.
  1. +1 −1 tests/net/utils/prj.conf
  2. +31 −28 tests/net/utils/src/main.c
@@ -16,4 +16,4 @@ CONFIG_NET_TCP=y
CONFIG_NET_UDP=y
CONFIG_ZTEST=y
CONFIG_MAIN_STACK_SIZE=1280

CONFIG_TEST_USERSPACE=y
@@ -9,6 +9,8 @@
#include <logging/log.h>
LOG_MODULE_REGISTER(net_test, CONFIG_NET_UTILS_LOG_LEVEL);

#include <kernel.h>
#include <ztest_assert.h>
#include <zephyr/types.h>
#include <stddef.h>
#include <string.h>
@@ -47,100 +49,100 @@ struct net_addr_test_data {
} ipv6;
};

static struct net_addr_test_data ipv4_pton_1 = {
static ZTEST_DMEM struct net_addr_test_data ipv4_pton_1 = {
.family = AF_INET,
.pton = true,
.ipv4.c_addr = "192.0.0.1",
.ipv4.verify.s4_addr = { 192, 0, 0, 1 },
};

static struct net_addr_test_data ipv4_pton_2 = {
static ZTEST_DMEM struct net_addr_test_data ipv4_pton_2 = {
.family = AF_INET,
.pton = true,
.ipv4.c_addr = "192.1.0.0",
.ipv4.verify.s4_addr = { 192, 1, 0, 0 },
};

static struct net_addr_test_data ipv4_pton_3 = {
static ZTEST_DMEM struct net_addr_test_data ipv4_pton_3 = {
.family = AF_INET,
.pton = true,
.ipv4.c_addr = "192.0.0.0",
.ipv4.verify.s4_addr = { 192, 0, 0, 0 },
};

static struct net_addr_test_data ipv4_pton_4 = {
static ZTEST_DMEM struct net_addr_test_data ipv4_pton_4 = {
.family = AF_INET,
.pton = true,
.ipv4.c_addr = "255.255.255.255",
.ipv4.verify.s4_addr = { 255, 255, 255, 255 },
};

static struct net_addr_test_data ipv4_pton_5 = {
static ZTEST_DMEM struct net_addr_test_data ipv4_pton_5 = {
.family = AF_INET,
.pton = true,
.ipv4.c_addr = "0.0.0.0",
.ipv4.verify.s4_addr = { 0, 0, 0, 0 },
};

static struct net_addr_test_data ipv4_pton_6 = {
static ZTEST_DMEM struct net_addr_test_data ipv4_pton_6 = {
.family = AF_INET,
.pton = true,
.ipv4.c_addr = "0.0.0.1",
.ipv4.verify.s4_addr = { 0, 0, 0, 1 },
};

static struct net_addr_test_data ipv4_pton_7 = {
static ZTEST_DMEM struct net_addr_test_data ipv4_pton_7 = {
.family = AF_INET,
.pton = true,
.ipv4.c_addr = "0.0.1.0",
.ipv4.verify.s4_addr = { 0, 0, 1, 0 },
};

static struct net_addr_test_data ipv4_pton_8 = {
static ZTEST_DMEM struct net_addr_test_data ipv4_pton_8 = {
.family = AF_INET,
.pton = true,
.ipv4.c_addr = "0.1.0.0",
.ipv4.verify.s4_addr = { 0, 1, 0, 0 },
};

static struct net_addr_test_data ipv6_pton_1 = {
static ZTEST_DMEM struct net_addr_test_data ipv6_pton_1 = {
.family = AF_INET6,
.pton = true,
.ipv6.c_addr = "ff08::",
.ipv6.verify.s6_addr32 = { htons(0xff08), 0, 0, 0 },
};

static struct net_addr_test_data ipv6_pton_2 = {
static ZTEST_DMEM struct net_addr_test_data ipv6_pton_2 = {
.family = AF_INET6,
.pton = true,
.ipv6.c_addr = "::",
.ipv6.verify.s6_addr32 = { 0, 0, 0, 0 },
};

static struct net_addr_test_data ipv6_pton_3 = {
static ZTEST_DMEM struct net_addr_test_data ipv6_pton_3 = {
.family = AF_INET6,
.pton = true,
.ipv6.c_addr = "ff08::1",
.ipv6.verify.s6_addr16 = { htons(0xff08), 0, 0, 0, 0, 0, 0, htons(1) },
};

static struct net_addr_test_data ipv6_pton_4 = {
static ZTEST_DMEM struct net_addr_test_data ipv6_pton_4 = {
.family = AF_INET6,
.pton = true,
.ipv6.c_addr = "2001:db8::1",
.ipv6.verify.s6_addr16 = { htons(0x2001), htons(0xdb8),
0, 0, 0, 0, 0, htons(1) },
};

static struct net_addr_test_data ipv6_pton_5 = {
static ZTEST_DMEM struct net_addr_test_data ipv6_pton_5 = {
.family = AF_INET6,
.pton = true,
.ipv6.c_addr = "2001:db8::2:1",
.ipv6.verify.s6_addr16 = { htons(0x2001), htons(0xdb8),
0, 0, 0, 0, htons(2), htons(1) },
};

static struct net_addr_test_data ipv6_pton_6 = {
static ZTEST_DMEM struct net_addr_test_data ipv6_pton_6 = {
.family = AF_INET6,
.pton = true,
.ipv6.c_addr = "ff08:1122:3344:5566:7788:9900:aabb:ccdd",
@@ -151,100 +153,100 @@ static struct net_addr_test_data ipv6_pton_6 = {
};

/* net_addr_ntop test cases */
static struct net_addr_test_data ipv4_ntop_1 = {
static ZTEST_DMEM struct net_addr_test_data ipv4_ntop_1 = {
.family = AF_INET,
.pton = false,
.ipv4.c_verify = "192.0.0.1",
.ipv4.addr.s4_addr = { 192, 0, 0, 1 },
};

static struct net_addr_test_data ipv4_ntop_2 = {
static ZTEST_DMEM struct net_addr_test_data ipv4_ntop_2 = {
.family = AF_INET,
.pton = false,
.ipv4.c_verify = "192.1.0.0",
.ipv4.addr.s4_addr = { 192, 1, 0, 0 },
};

static struct net_addr_test_data ipv4_ntop_3 = {
static ZTEST_DMEM struct net_addr_test_data ipv4_ntop_3 = {
.family = AF_INET,
.pton = false,
.ipv4.c_verify = "192.0.0.0",
.ipv4.addr.s4_addr = { 192, 0, 0, 0 },
};

static struct net_addr_test_data ipv4_ntop_4 = {
static ZTEST_DMEM struct net_addr_test_data ipv4_ntop_4 = {
.family = AF_INET,
.pton = false,
.ipv4.c_verify = "255.255.255.255",
.ipv4.addr.s4_addr = { 255, 255, 255, 255 },
};

static struct net_addr_test_data ipv4_ntop_5 = {
static ZTEST_DMEM struct net_addr_test_data ipv4_ntop_5 = {
.family = AF_INET,
.pton = false,
.ipv4.c_verify = "0.0.0.0",
.ipv4.addr.s4_addr = { 0, 0, 0, 0 },
};

static struct net_addr_test_data ipv4_ntop_6 = {
static ZTEST_DMEM struct net_addr_test_data ipv4_ntop_6 = {
.family = AF_INET,
.pton = false,
.ipv4.c_verify = "0.0.0.1",
.ipv4.addr.s4_addr = { 0, 0, 0, 1 },
};

static struct net_addr_test_data ipv4_ntop_7 = {
static ZTEST_DMEM struct net_addr_test_data ipv4_ntop_7 = {
.family = AF_INET,
.pton = false,
.ipv4.c_verify = "0.0.1.0",
.ipv4.addr.s4_addr = { 0, 0, 1, 0 },
};

static struct net_addr_test_data ipv4_ntop_8 = {
static ZTEST_DMEM struct net_addr_test_data ipv4_ntop_8 = {
.family = AF_INET,
.pton = false,
.ipv4.c_verify = "0.1.0.0",
.ipv4.addr.s4_addr = { 0, 1, 0, 0 },
};

static struct net_addr_test_data ipv6_ntop_1 = {
static ZTEST_DMEM struct net_addr_test_data ipv6_ntop_1 = {
.family = AF_INET6,
.pton = false,
.ipv6.c_verify = "ff08::",
.ipv6.addr.s6_addr32 = { htons(0xff08), 0, 0, 0 },
};

static struct net_addr_test_data ipv6_ntop_2 = {
static ZTEST_DMEM struct net_addr_test_data ipv6_ntop_2 = {
.family = AF_INET6,
.pton = false,
.ipv6.c_verify = "::",
.ipv6.addr.s6_addr32 = { 0, 0, 0, 0 },
};

static struct net_addr_test_data ipv6_ntop_3 = {
static ZTEST_DMEM struct net_addr_test_data ipv6_ntop_3 = {
.family = AF_INET6,
.pton = false,
.ipv6.c_verify = "ff08::1",
.ipv6.addr.s6_addr16 = { htons(0xff08), 0, 0, 0, 0, 0, 0, htons(1) },
};

static struct net_addr_test_data ipv6_ntop_4 = {
static ZTEST_DMEM struct net_addr_test_data ipv6_ntop_4 = {
.family = AF_INET6,
.pton = false,
.ipv6.c_verify = "2001:db8::1",
.ipv6.addr.s6_addr16 = { htons(0x2001), htons(0xdb8),
0, 0, 0, 0, 0, htons(1) },
};

static struct net_addr_test_data ipv6_ntop_5 = {
static ZTEST_DMEM struct net_addr_test_data ipv6_ntop_5 = {
.family = AF_INET6,
.pton = false,
.ipv6.c_verify = "2001:db8::2:1",
.ipv6.addr.s6_addr16 = { htons(0x2001), htons(0xdb8),
0, 0, 0, 0, htons(2), htons(1) },
};

static struct net_addr_test_data ipv6_ntop_6 = {
static ZTEST_DMEM struct net_addr_test_data ipv6_ntop_6 = {
.family = AF_INET6,
.pton = false,
.ipv6.c_verify = "ff08:1122:3344:5566:7788:9900:aabb:ccdd",
@@ -834,6 +836,7 @@ void test_main(void)
{
ztest_test_suite(test_utils_fn,
ztest_unit_test(test_net_addr),
ztest_user_unit_test(test_net_addr),
ztest_unit_test(test_addr_parse));

ztest_run_test_suite(test_utils_fn);

0 comments on commit 8cf4d59

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