From 7851aecc1c6209f5a3b332a38b26b9c53fc499cf Mon Sep 17 00:00:00 2001 From: Jukka Rissanen Date: Tue, 17 May 2016 14:16:01 +0300 Subject: [PATCH] net: tests: Add IPv4 address unit tests These tests will check that caller is able to set IPv4 address to a network interface and check if an address is one of the assigned to a network interface. Change-Id: I8aa748c40fbc02eef50ccf76d10a0057ef29021b Signed-off-by: Jukka Rissanen --- tests/net/ip-addr/src/main.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/net/ip-addr/src/main.c b/tests/net/ip-addr/src/main.c index 82b0d9fdb5d..930589d30f8 100644 --- a/tests/net/ip-addr/src/main.c +++ b/tests/net/ip-addr/src/main.c @@ -178,6 +178,8 @@ void main(void) 0, 0, 0, 0, 0, 0, 0, 0, 0x2 } } }; struct net_if_addr *ifaddr1, *ifaddr2; struct net_if_mcast_addr *ifmaddr1; + struct in_addr addr4 = { { { 192, 168, 0, 1 } } }; + struct in_addr loopback4 = { { { 127, 0, 0, 1 } } }; TEST_BYTE_1(0xde, "DE"); TEST_BYTE_1(0x09, "09"); @@ -291,5 +293,24 @@ void main(void) return; } + ifaddr1 = net_if_ipv4_addr_add(__net_if_start, + &addr4, + NET_ADDR_MANUAL, + 0); + if (!ifaddr1) { + printk("IPv4 interface address add failed\n"); + return; + } + + if (!net_is_my_ipv4_addr(&addr4)) { + printk("My IPv4 address check failed\n"); + return; + } + + if (net_is_my_ipv4_addr(&loopback4)) { + printk("My IPv4 loopback address check failed\n"); + return; + } + printk("IP address checks passed\n"); }