Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: build OT RPC tests with Address Sanitizer #21052

Merged
merged 1 commit into from
Mar 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions tests/subsys/net/openthread/rpc/client/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ CONFIG_MOCK_NRF_RPC_TRANSPORT=y

CONFIG_KERNEL_MEM_POOL=y
CONFIG_HEAP_MEM_POOL_SIZE=4096

CONFIG_ASAN=y
2 changes: 2 additions & 0 deletions tests/subsys/net/openthread/rpc/server/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ CONFIG_MOCK_NRF_RPC_TRANSPORT=y

CONFIG_KERNEL_MEM_POOL=y
CONFIG_HEAP_MEM_POOL_SIZE=4096

CONFIG_ASAN=y
59 changes: 43 additions & 16 deletions tests/subsys/net/openthread/rpc/server/src/ip6_suite.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

/*
Expand Down
27 changes: 23 additions & 4 deletions tests/subsys/net/openthread/rpc/server/src/message_suite.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand All @@ -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));
Expand Down
13 changes: 8 additions & 5 deletions tests/subsys/net/openthread/rpc/server/src/netdiag_suite.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down