From 6e3c12a820be57d964775b475351043095e54307 Mon Sep 17 00:00:00 2001 From: Jukka Rissanen Date: Mon, 23 May 2016 17:31:58 +0300 Subject: [PATCH] net: tests: Add tests for IPv4 netmask, gateway and subnet compare Unit tests added for checking network interface netmask, gateway and IPv4 subnet compare utility functions. Change-Id: I5b4a07d6a064097ab41ad6552d14181b1631eb53 Signed-off-by: Jukka Rissanen --- tests/net/ip-addr/src/main.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/net/ip-addr/src/main.c b/tests/net/ip-addr/src/main.c index 006bf219369..a0a5e92a25e 100644 --- a/tests/net/ip-addr/src/main.c +++ b/tests/net/ip-addr/src/main.c @@ -179,6 +179,10 @@ void main(void) struct net_if_addr *ifaddr1, *ifaddr2; struct net_if_mcast_addr *ifmaddr1; struct in_addr addr4 = { { { 192, 168, 0, 1 } } }; + struct in_addr match_addr = { { { 192, 168, 0, 2 } } }; + struct in_addr fail_addr = { { { 10, 1, 0, 2 } } }; + struct in_addr netmask = { { { 255, 255, 255, 0 } } }; + struct in_addr gw = { { { 192, 168, 0, 42 } } }; struct in_addr loopback4 = { { { 127, 0, 0, 1 } } }; struct net_if *iface; int i; @@ -410,5 +414,20 @@ void main(void) } } + iface = net_if_get_default(); + + net_if_set_gw(iface, &gw); + net_if_set_netmask(iface, &netmask); + + if (net_ipv4_addr_mask_cmp(iface, &fail_addr)) { + printk("IPv4 wrong match failed\n"); + return; + } + + if (!net_ipv4_addr_mask_cmp(iface, &match_addr)) { + printk("IPv4 match failed\n"); + return; + } + printk("IP address checks passed\n"); }