Skip to content
Permalink
Browse files

tests: net: dhcpv4: Make sure we get DNS add/del events

Verify that DNS server add/del event is received properly.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
  • Loading branch information...
jukkar committed Jun 21, 2019
1 parent 8f92dc4 commit 0d8b0c67141072e3e9b6201d8dbfd6f98192fe57
Showing with 20 additions and 3 deletions.
  1. +3 −0 tests/net/dhcpv4/prj.conf
  2. +17 −3 tests/net/dhcpv4/src/main.c
@@ -17,6 +17,9 @@ CONFIG_NET_IPV6=n

CONFIG_NET_MGMT=y
CONFIG_NET_MGMT_EVENT=y
CONFIG_NET_MGMT_EVENT_INFO=y

CONFIG_DNS_RESOLVER=y

# Turn off UDP checksum checking as the test fails otherwise.
CONFIG_NET_UDP_CHECKSUM=n
@@ -386,15 +386,21 @@ NET_DEVICE_INIT(net_dhcpv4_test, "net_dhcpv4_test",
NET_L2_GET_CTX_TYPE(DUMMY_L2), 127);

static struct net_mgmt_event_callback rx_cb;
static struct net_mgmt_event_callback dns_cb;
static int event_count;

static void receiver_cb(struct net_mgmt_event_callback *cb,
u32_t nm_event, struct net_if *iface)
{
if (nm_event != NET_EVENT_IPV4_ADDR_ADD) {
if (nm_event != NET_EVENT_IPV4_ADDR_ADD &&
nm_event != NET_EVENT_DNS_SERVER_ADD &&
nm_event != NET_EVENT_DNS_SERVER_DEL) {
/* Spurious callback. */
return;
}

event_count++;

k_sem_give(&test_lock);
}

@@ -409,15 +415,23 @@ void test_dhcp(void)

net_mgmt_add_event_callback(&rx_cb);

net_mgmt_init_event_callback(&dns_cb, receiver_cb,
NET_EVENT_DNS_SERVER_ADD |
NET_EVENT_DNS_SERVER_DEL);

net_mgmt_add_event_callback(&dns_cb);

iface = net_if_get_default();
if (!iface) {
zassert_true(false, "Interface not available");
}

net_dhcpv4_start(iface);

if (k_sem_take(&test_lock, WAIT_TIME)) {
zassert_true(false, "Timeout while waiting");
while (event_count < 3) {
if (k_sem_take(&test_lock, WAIT_TIME)) {
zassert_true(false, "Timeout while waiting");
}
}
}

0 comments on commit 0d8b0c6

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