diff --git a/tests/subsys/net/openthread/rpc/client/prj.conf b/tests/subsys/net/openthread/rpc/client/prj.conf index d8dcaae7a2f6..0a0b1b621830 100644 --- a/tests/subsys/net/openthread/rpc/client/prj.conf +++ b/tests/subsys/net/openthread/rpc/client/prj.conf @@ -19,3 +19,5 @@ CONFIG_MOCK_NRF_RPC_TRANSPORT=y CONFIG_KERNEL_MEM_POOL=y CONFIG_HEAP_MEM_POOL_SIZE=4096 + +CONFIG_ASAN=y diff --git a/tests/subsys/net/openthread/rpc/server/prj.conf b/tests/subsys/net/openthread/rpc/server/prj.conf index 6f9184baa8fc..22a1be9c75c1 100644 --- a/tests/subsys/net/openthread/rpc/server/prj.conf +++ b/tests/subsys/net/openthread/rpc/server/prj.conf @@ -18,3 +18,5 @@ CONFIG_MOCK_NRF_RPC_TRANSPORT=y CONFIG_KERNEL_MEM_POOL=y CONFIG_HEAP_MEM_POOL_SIZE=4096 + +CONFIG_ASAN=y diff --git a/tests/subsys/net/openthread/rpc/server/src/ip6_suite.c b/tests/subsys/net/openthread/rpc/server/src/ip6_suite.c index c5d88d48bc5b..d4108aee065f 100644 --- a/tests/subsys/net/openthread/rpc/server/src/ip6_suite.c +++ b/tests/subsys/net/openthread/rpc/server/src/ip6_suite.c @@ -136,72 +136,99 @@ ZTEST(ot_rpc_ip6, test_otIp6IsEnabled_true) * Test reception of otIp6SubscribeMulticastAddress(ff02::1) command. * Test serialization of the result: OT_ERROR_NONE. */ -ZTEST(ot_rpc_ip6, test_otIp6SubscribeMulticastAddress) +static otError subscribe_multicast_ff02_1_fake(otInstance *instance, const otIp6Address *addr) { - const otIp6Address addr = {.mFields.m8 = {MADDR_FF02_1}}; + const otIp6Address exp_addr = {.mFields.m8 = {MADDR_FF02_1}}; + + zassert_mem_equal(addr, &exp_addr, sizeof(exp_addr)); + + return OT_ERROR_NONE; +} - otIp6SubscribeMulticastAddress_fake.return_val = OT_ERROR_NONE; +ZTEST(ot_rpc_ip6, test_otIp6SubscribeMulticastAddress) +{ + otIp6SubscribeMulticastAddress_fake.custom_fake = subscribe_multicast_ff02_1_fake; mock_nrf_rpc_tr_expect_add(RPC_RSP(0x00), NO_RSP); mock_nrf_rpc_tr_receive(RPC_CMD(OT_RPC_CMD_IP6_SUBSCRIBE_MADDR, 0x50, MADDR_FF02_1)); mock_nrf_rpc_tr_expect_done(); zassert_equal(otIp6SubscribeMulticastAddress_fake.call_count, 1); - zassert_mem_equal(otIp6SubscribeMulticastAddress_fake.arg1_val, &addr, sizeof(addr)); } /* * Test reception of otIp6SubscribeMulticastAddress(ff02::1) command. * Test serialization of the result: OT_ERROR_FAILED. */ -ZTEST(ot_rpc_ip6, test_otIp6SubscribeMulticastAddress_failed) +static otError subscribe_multicast_ff02_1_failed_fake(otInstance *instance, + const otIp6Address *addr) { - const otIp6Address addr = {.mFields.m8 = {MADDR_FF02_1}}; + const otIp6Address exp_addr = {.mFields.m8 = {MADDR_FF02_1}}; + + zassert_mem_equal(addr, &exp_addr, sizeof(exp_addr)); + + return OT_ERROR_FAILED; +} - otIp6SubscribeMulticastAddress_fake.return_val = OT_ERROR_FAILED; +ZTEST(ot_rpc_ip6, test_otIp6SubscribeMulticastAddress_failed) +{ + otIp6SubscribeMulticastAddress_fake.custom_fake = subscribe_multicast_ff02_1_failed_fake; mock_nrf_rpc_tr_expect_add(RPC_RSP(0x01), NO_RSP); mock_nrf_rpc_tr_receive(RPC_CMD(OT_RPC_CMD_IP6_SUBSCRIBE_MADDR, 0x50, MADDR_FF02_1)); mock_nrf_rpc_tr_expect_done(); zassert_equal(otIp6SubscribeMulticastAddress_fake.call_count, 1); - zassert_mem_equal(otIp6SubscribeMulticastAddress_fake.arg1_val, &addr, sizeof(addr)); } /* * Test reception of otIp6UnubscribeMulticastAddress(ff02::1) command. * Test serialization of the result: OT_ERROR_NONE. */ -ZTEST(ot_rpc_ip6, test_otIp6UnsubscribeMulticastAddress) +static otError unsubscribe_multicast_ff02_1_fake(otInstance *instance, const otIp6Address *addr) { - const otIp6Address addr = {.mFields.m8 = {MADDR_FF02_1}}; + const otIp6Address exp_addr = {.mFields.m8 = {MADDR_FF02_1}}; + + zassert_mem_equal(addr, &exp_addr, sizeof(exp_addr)); + + return OT_ERROR_NONE; +} - otIp6UnsubscribeMulticastAddress_fake.return_val = OT_ERROR_NONE; +ZTEST(ot_rpc_ip6, test_otIp6UnsubscribeMulticastAddress) +{ + otIp6UnsubscribeMulticastAddress_fake.custom_fake = unsubscribe_multicast_ff02_1_fake; mock_nrf_rpc_tr_expect_add(RPC_RSP(0x00), NO_RSP); mock_nrf_rpc_tr_receive(RPC_CMD(OT_RPC_CMD_IP6_UNSUBSCRIBE_MADDR, 0x50, MADDR_FF02_1)); mock_nrf_rpc_tr_expect_done(); zassert_equal(otIp6UnsubscribeMulticastAddress_fake.call_count, 1); - zassert_mem_equal(otIp6UnsubscribeMulticastAddress_fake.arg1_val, &addr, sizeof(addr)); } /* * Test reception of otIp6UnubscribeMulticastAddress(ff02::1) command. * Test serialization of the result: OT_ERROR_FAILED. */ -ZTEST(ot_rpc_ip6, test_otIp6UnsubscribeMulticastAddress_failed) +static otError unsubscribe_multicast_ff02_1_failed_fake(otInstance *instance, + const otIp6Address *addr) { - const otIp6Address addr = {.mFields.m8 = {MADDR_FF02_1}}; + const otIp6Address exp_addr = {.mFields.m8 = {MADDR_FF02_1}}; + + zassert_mem_equal(addr, &exp_addr, sizeof(exp_addr)); + + return OT_ERROR_FAILED; +} - otIp6UnsubscribeMulticastAddress_fake.return_val = OT_ERROR_FAILED; +ZTEST(ot_rpc_ip6, test_otIp6UnsubscribeMulticastAddress_failed) +{ + otIp6UnsubscribeMulticastAddress_fake.custom_fake = + unsubscribe_multicast_ff02_1_failed_fake; mock_nrf_rpc_tr_expect_add(RPC_RSP(0x01), NO_RSP); mock_nrf_rpc_tr_receive(RPC_CMD(OT_RPC_CMD_IP6_UNSUBSCRIBE_MADDR, 0x50, MADDR_FF02_1)); mock_nrf_rpc_tr_expect_done(); zassert_equal(otIp6UnsubscribeMulticastAddress_fake.call_count, 1); - zassert_mem_equal(otIp6UnsubscribeMulticastAddress_fake.arg1_val, &addr, sizeof(addr)); } /* diff --git a/tests/subsys/net/openthread/rpc/server/src/message_suite.c b/tests/subsys/net/openthread/rpc/server/src/message_suite.c index da838767393f..12567cee4730 100644 --- a/tests/subsys/net/openthread/rpc/server/src/message_suite.c +++ b/tests/subsys/net/openthread/rpc/server/src/message_suite.c @@ -43,6 +43,15 @@ static void tc_setup(void *f) FFF_RESET_HISTORY(); } +static otMessage *udp_new_message_failed_fake(otInstance *instance, + const otMessageSettings *settings) +{ + zassert_true(settings->mLinkSecurityEnabled); + zassert_equal(settings->mPriority, 40); + + return NULL; +} + ZTEST(ot_rpc_message, test_otUdpNewMessage_failing) { const uint8_t prio = 40; @@ -52,15 +61,24 @@ ZTEST(ot_rpc_message, test_otUdpNewMessage_failing) mock_nrf_rpc_tr_expect_add(RPC_RSP(0), NO_RSP); mock_nrf_rpc_tr_receive(RPC_CMD(OT_RPC_CMD_UDP_NEW_MESSAGE, CBOR_NULL)); + zassert_equal(otUdpNewMessage_fake.call_count, 1); zassert_is_null(otUdpNewMessage_fake.arg1_val); + otUdpNewMessage_fake.custom_fake = udp_new_message_failed_fake; + mock_nrf_rpc_tr_expect_add(RPC_RSP(0), NO_RSP); mock_nrf_rpc_tr_receive(RPC_CMD(OT_RPC_CMD_UDP_NEW_MESSAGE, CBOR_TRUE, CBOR_UINT8(prio))); mock_nrf_rpc_tr_expect_done(); zassert_equal(otUdpNewMessage_fake.call_count, 2); - zassert_true(otUdpNewMessage_fake.arg1_val->mLinkSecurityEnabled); - zassert_equal(otUdpNewMessage_fake.arg1_val->mPriority, prio); +} + +static otMessage *udp_new_message_free_fake(otInstance *instance, const otMessageSettings *settings) +{ + zassert_true(settings->mLinkSecurityEnabled); + zassert_equal(settings->mPriority, 40); + + return (otMessage *)1; } ZTEST(ot_rpc_message, test_otUdpNewMessage_free_working) @@ -72,14 +90,15 @@ ZTEST(ot_rpc_message, test_otUdpNewMessage_free_working) mock_nrf_rpc_tr_expect_add(RPC_RSP(1), NO_RSP); mock_nrf_rpc_tr_receive(RPC_CMD(OT_RPC_CMD_UDP_NEW_MESSAGE, CBOR_NULL)); + zassert_equal(otUdpNewMessage_fake.call_count, 1); zassert_is_null(otUdpNewMessage_fake.arg1_val); + otUdpNewMessage_fake.custom_fake = udp_new_message_free_fake; + mock_nrf_rpc_tr_expect_add(RPC_RSP(2), NO_RSP); mock_nrf_rpc_tr_receive(RPC_CMD(OT_RPC_CMD_UDP_NEW_MESSAGE, CBOR_TRUE, CBOR_UINT8(prio))); zassert_equal(otUdpNewMessage_fake.call_count, 2); - zassert_true(otUdpNewMessage_fake.arg1_val->mLinkSecurityEnabled); - zassert_equal(otUdpNewMessage_fake.arg1_val->mPriority, prio); mock_nrf_rpc_tr_expect_add(RPC_RSP(), NO_RSP); mock_nrf_rpc_tr_receive(RPC_CMD(OT_RPC_CMD_MESSAGE_FREE, 1)); diff --git a/tests/subsys/net/openthread/rpc/server/src/netdiag_suite.c b/tests/subsys/net/openthread/rpc/server/src/netdiag_suite.c index 87e8d676d0db..1509bd7637cf 100644 --- a/tests/subsys/net/openthread/rpc/server/src/netdiag_suite.c +++ b/tests/subsys/net/openthread/rpc/server/src/netdiag_suite.c @@ -50,25 +50,28 @@ static void tc_setup(void *f) #define TEST_STRING_SETTER(test_name, cmd, data, data_cbor, func_to_call, max_length, result_exp) \ static otError fake_##test_name(otInstance *instance, const char *arg) \ { \ + char data_exp[] = data; \ + \ ARG_UNUSED(instance); \ + \ if (strlen(arg) > max_length) { \ return OT_ERROR_INVALID_ARGS; \ } \ \ + zassert_str_equal(func_to_call##_fake.arg1_val, data_exp); \ + \ return OT_ERROR_NONE; \ } \ - \ + \ ZTEST(ot_rpc_netdiag, test_name) \ { \ - char data_exp[] = data; \ func_to_call##_fake.custom_fake = fake_##test_name; \ - \ + \ mock_nrf_rpc_tr_expect_add(RPC_RSP(result_exp), NO_RSP); \ mock_nrf_rpc_tr_receive(RPC_CMD(cmd, data_cbor)); \ mock_nrf_rpc_tr_expect_done(); \ - \ + \ zassert_equal(func_to_call##_fake.call_count, 1); \ - zassert_str_equal(func_to_call##_fake.arg1_val, data_exp); \ } #define TEST_STRING_GETTER(test_name, cmd, data, data_cbor, func_to_call) \