tests: mgmt: convert to ztest
- replaced test points with ztest APIs wherever possible - replaced CONFIG_MAIN_STACK_SIZE with CONFIG_ZTEST_STACKSIZE in config file, reduced size to 896 JIRA: ZEP-2249 Signed-off-by: Niranjhana N <niranjhana.n@intel.com>
This commit is contained in:
committed by
Anas Nashif
parent
7d1c9184a8
commit
be8a106cb3
@@ -1,7 +1,7 @@
|
||||
CONFIG_NETWORKING=y
|
||||
CONFIG_NET_TEST=y
|
||||
CONFIG_NET_BUF=y
|
||||
CONFIG_MAIN_STACK_SIZE=2048
|
||||
CONFIG_ZTEST_STACKSIZE=896
|
||||
CONFIG_NET_PKT_RX_COUNT=5
|
||||
CONFIG_NET_PKT_TX_COUNT=5
|
||||
CONFIG_NET_BUF_RX_COUNT=5
|
||||
@@ -14,3 +14,4 @@ CONFIG_NET_MGMT=y
|
||||
CONFIG_NET_MGMT_EVENT=y
|
||||
CONFIG_NET_IPV6=y
|
||||
CONFIG_NET_L2_DUMMY=y
|
||||
CONFIG_ZTEST=y
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
include ${ZEPHYR_BASE}/tests/Makefile.test
|
||||
ccflags-y += -I${ZEPHYR_BASE}/tests/include
|
||||
|
||||
obj-y = mgmt.o
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
#include <net/net_mgmt.h>
|
||||
#include <net/net_pkt.h>
|
||||
#include <ztest.h>
|
||||
|
||||
#define TEST_MGMT_REQUEST 0x17AB1234
|
||||
#define TEST_MGMT_EVENT 0x97AB1234
|
||||
@@ -81,17 +82,14 @@ NET_DEVICE_INIT(net_event_test, "net_event_test",
|
||||
fake_dev_init, NULL, NULL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT,
|
||||
&fake_iface_api, DUMMY_L2, NET_L2_GET_CTX_TYPE(DUMMY_L2), 127);
|
||||
|
||||
static inline int test_requesting_nm(void)
|
||||
void test_requesting_nm(void)
|
||||
{
|
||||
u32_t data = 0;
|
||||
|
||||
TC_PRINT("- Request Net MGMT\n");
|
||||
|
||||
if (net_mgmt(TEST_MGMT_REQUEST, NULL, &data, sizeof(data))) {
|
||||
return TC_FAIL;
|
||||
}
|
||||
|
||||
return TC_PASS;
|
||||
zassert_false(net_mgmt(TEST_MGMT_REQUEST, NULL, &data, sizeof(data)),
|
||||
"Requesting Net MGMT failed");
|
||||
}
|
||||
|
||||
static void thrower_thread(void)
|
||||
@@ -142,13 +140,10 @@ static inline int test_sending_event(u32_t times, bool receiver)
|
||||
TC_PRINT("\tReceived 0x%08X %u times\n",
|
||||
rx_event, rx_calls);
|
||||
|
||||
if (rx_event != event2throw) {
|
||||
ret = TC_FAIL;
|
||||
}
|
||||
/**TESTPOINTS: Check rx events*/
|
||||
zassert_equal(rx_event, event2throw, "rx_event check failed");
|
||||
|
||||
if (rx_calls != times) {
|
||||
ret = TC_FAIL;
|
||||
}
|
||||
zassert_equal(rx_calls, times, "rx_calls check failed");
|
||||
|
||||
net_mgmt_del_event_callback(&rx_cb);
|
||||
rx_event = rx_calls = 0;
|
||||
@@ -222,23 +217,15 @@ static int test_core_event(u32_t event, bool (*func)(void))
|
||||
|
||||
net_mgmt_add_event_callback(&rx_cb);
|
||||
|
||||
if (!func()) {
|
||||
ret = TC_FAIL;
|
||||
goto out;
|
||||
}
|
||||
zassert_true(func(), "func() check failed");
|
||||
|
||||
k_yield();
|
||||
|
||||
if (!rx_calls) {
|
||||
ret = TC_FAIL;
|
||||
goto out;
|
||||
}
|
||||
/**TESTPOINTS: Check rx events*/
|
||||
zassert_true(rx_calls, "rx_calls empty");
|
||||
|
||||
if (rx_event != event) {
|
||||
ret = TC_FAIL;
|
||||
}
|
||||
zassert_equal(rx_event, event, "rx_event check failed");
|
||||
|
||||
out:
|
||||
net_mgmt_del_event_callback(&rx_cb);
|
||||
rx_event = rx_calls = 0;
|
||||
|
||||
@@ -264,55 +251,43 @@ static bool _iface_ip6_del(void)
|
||||
return false;
|
||||
}
|
||||
|
||||
void main(void)
|
||||
void test_mgmt(void)
|
||||
{
|
||||
int status = TC_FAIL;
|
||||
|
||||
TC_PRINT("Starting Network Management API test\n");
|
||||
|
||||
if (test_requesting_nm() != TC_PASS) {
|
||||
goto end;
|
||||
}
|
||||
test_requesting_nm();
|
||||
|
||||
initialize_event_tests();
|
||||
|
||||
if (test_sending_event(1, false) != TC_PASS) {
|
||||
goto end;
|
||||
}
|
||||
/**TESTPOINTS: Check events results*/
|
||||
zassert_false(test_sending_event(1, false),
|
||||
"test_sending_event failed");
|
||||
|
||||
if (test_sending_event(2, false) != TC_PASS) {
|
||||
goto end;
|
||||
}
|
||||
zassert_false(test_sending_event(2, false),
|
||||
"test_sending_event failed");
|
||||
|
||||
if (test_sending_event(1, true) != TC_PASS) {
|
||||
goto end;
|
||||
}
|
||||
zassert_false(test_sending_event(1, true),
|
||||
"test_sending_event failed");
|
||||
|
||||
if (test_sending_event(2, true) != TC_PASS) {
|
||||
goto end;
|
||||
}
|
||||
zassert_false(test_sending_event(2, true),
|
||||
"test_sending_event failed");
|
||||
|
||||
if (test_core_event(NET_EVENT_IPV6_ADDR_ADD,
|
||||
_iface_ip6_add) != TC_PASS) {
|
||||
goto end;
|
||||
}
|
||||
zassert_false(test_core_event(NET_EVENT_IPV6_ADDR_ADD,
|
||||
_iface_ip6_add), "test_core_event failed");
|
||||
|
||||
if (test_core_event(NET_EVENT_IPV6_ADDR_DEL,
|
||||
_iface_ip6_del) != TC_PASS) {
|
||||
goto end;
|
||||
}
|
||||
zassert_false(test_core_event(NET_EVENT_IPV6_ADDR_DEL,
|
||||
_iface_ip6_del), "test_core_event failed");
|
||||
|
||||
if (test_synchronous_event_listener(2, false) != TC_PASS) {
|
||||
goto end;
|
||||
}
|
||||
zassert_false(test_synchronous_event_listener(2, false),
|
||||
"test_synchronous_event_listener failed");
|
||||
|
||||
if (test_synchronous_event_listener(2, true) != TC_PASS) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
status = TC_PASS;
|
||||
|
||||
end:
|
||||
TC_END_RESULT(status);
|
||||
TC_END_REPORT(status);
|
||||
zassert_false(test_synchronous_event_listener(2, true),
|
||||
"test_synchronous_event_listener failed");
|
||||
}
|
||||
|
||||
void test_main(void)
|
||||
{
|
||||
ztest_test_suite(test_mgmt_fn,
|
||||
ztest_unit_test(test_mgmt));
|
||||
ztest_run_test_suite(test_mgmt_fn);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user