Skip to content
Permalink
Browse files

tests: net: mgmt: Verify that info_length is correct

If info is sent by net_mgmt, make sure it contains correct data.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
  • Loading branch information...
jukkar authored and andrewboie committed Jun 12, 2019
1 parent 2da132e commit eb018f8109b66c6f4c949300bce1fa8a75f810d3
Showing with 22 additions and 6 deletions.
  1. +22 −6 tests/net/mgmt/src/mgmt.c
@@ -18,10 +18,13 @@ LOG_MODULE_REGISTER(net_test, CONFIG_NET_MGMT_EVENT_LOG_LEVEL);
#include <net/net_pkt.h>
#include <ztest.h>

#define TEST_INFO_STRING "mgmt event info"

#define TEST_MGMT_REQUEST 0x17AB1234
#define TEST_MGMT_EVENT 0x97AB1234
#define TEST_MGMT_EVENT_UNHANDLED 0x97AB4321
#define TEST_MGMT_EVENT_INFO_SIZE sizeof("mgmt event info")
#define TEST_MGMT_EVENT_INFO_SIZE \
MAX(sizeof(TEST_INFO_STRING), sizeof(struct in6_addr))

/* Notifier infra */
static u32_t event2throw;
@@ -35,12 +38,14 @@ static struct k_sem thrower_lock;
/* Receiver infra */
static u32_t rx_event;
static u32_t rx_calls;
static size_t info_length_in_test;
static struct net_mgmt_event_callback rx_cb;
static char *info_string = TEST_INFO_STRING;

static struct in6_addr addr6 = { { { 0xfe, 0x80, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0x1 } } };

static char info_data[TEST_MGMT_EVENT_INFO_SIZE] = "mgmt event info";
static char info_data[TEST_MGMT_EVENT_INFO_SIZE];

static int test_mgmt_request(u32_t mgmt_request,
struct net_if *iface, void *data, u32_t len)
@@ -129,8 +134,12 @@ static void receiver_cb(struct net_mgmt_event_callback *cb,
TC_PRINT("\t\tReceived event 0x%08X\n", nm_event);

if (with_info && cb->info) {
if (memcmp(info_data, cb->info,
TEST_MGMT_EVENT_INFO_SIZE)) {
if (cb->info_length != info_length_in_test) {
rx_calls = (u32_t) -1;
return;
}

if (memcmp(info_data, cb->info, info_length_in_test)) {
rx_calls = (u32_t) -1;
return;
}
@@ -230,6 +239,9 @@ static void initialize_event_tests(void)

k_sem_init(&thrower_lock, 0, UINT_MAX);

info_length_in_test = TEST_MGMT_EVENT_INFO_SIZE;
memcpy(info_data, info_string, strlen(info_string) + 1);

net_mgmt_init_event_callback(&rx_cb, receiver_cb, TEST_MGMT_EVENT);

k_thread_create(&thrower_thread_data, thrower_stack,
@@ -242,6 +254,9 @@ static int test_core_event(u32_t event, bool (*func)(void))
{
TC_PRINT("- Triggering core event: 0x%08X\n", event);

info_length_in_test = sizeof(struct in6_addr);
memcpy(info_data, &addr6, sizeof(addr6));

net_mgmt_init_event_callback(&rx_cb, receiver_cb, event);

net_mgmt_add_event_callback(&rx_cb);
@@ -250,8 +265,9 @@ static int test_core_event(u32_t event, bool (*func)(void))

k_yield();

zassert_true(rx_calls, "rx_calls empty");
zassert_equal(rx_event, event, "rx_event check failed");
zassert_true(rx_calls > 0 && rx_calls != -1, "rx_calls empty");
zassert_equal(rx_event, event, "rx_event check failed, "
"0x%08x vs 0x%08x", rx_event, event);

net_mgmt_del_event_callback(&rx_cb);
rx_event = rx_calls = 0U;

0 comments on commit eb018f8

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