From b67a61e2e482c0123d6726c90e351cb643bd1ba1 Mon Sep 17 00:00:00 2001 From: Damian Krolik Date: Tue, 10 Dec 2024 12:01:10 +0100 Subject: [PATCH] quarantine: fix RPC server tests without optimizations Fix unit tests using FFF fakes' arguments by pointer after releasing the underlying memory. Jira: NCSDK-30881 Signed-off-by: Damian Krolik --- scripts/quarantine_no_optimization.yaml | 7 -- .../openthread/rpc/server/src/coap_suite.c | 15 ++- .../openthread/rpc/server/src/dataset_suite.c | 114 +++++++++--------- tests/subsys/nfc/rpc/server/src/t2t_suite.c | 22 ++-- tests/subsys/nfc/rpc/server/src/t4t_suite.c | 22 ++-- 5 files changed, 101 insertions(+), 79 deletions(-) diff --git a/scripts/quarantine_no_optimization.yaml b/scripts/quarantine_no_optimization.yaml index deb831c90c53..c9b4970ed4ba 100644 --- a/scripts/quarantine_no_optimization.yaml +++ b/scripts/quarantine_no_optimization.yaml @@ -5,13 +5,6 @@ # - scenarios: # - None -- scenarios: - - net.openthread.rpc.server - - nfc.rpc.server - platforms: - - native_sim - comment: "https://nordicsemi.atlassian.net/browse/NCSDK-30881" - - scenarios: - nrf5340_audio.sd_card_test platforms: diff --git a/tests/subsys/net/openthread/rpc/server/src/coap_suite.c b/tests/subsys/net/openthread/rpc/server/src/coap_suite.c index 08f6002b4766..f0a54dbf811b 100644 --- a/tests/subsys/net/openthread/rpc/server/src/coap_suite.c +++ b/tests/subsys/net/openthread/rpc/server/src/coap_suite.c @@ -174,12 +174,21 @@ ZTEST(ot_rpc_coap, test_otCoapMessageInitResponse) * Test reception of otCoapMessageAppendUriPathOptions() command. * Test serialization of the result: OT_ERROR_INVALID_ARGS. */ +otError append_uri_path_options_fake(otMessage *message, const char *uri_path) +{ + char uri[] = {URI, '\0'}; + + zassert_equal(message, (otMessage *)MSG_ADDR); + zassert_str_equal(uri_path, uri); + + return OT_ERROR_INVALID_ARGS; +} + ZTEST(ot_rpc_coap, test_otCoapMessageAppendUriPathOptions) { ot_msg_key message_rep = ot_reg_msg_alloc((otMessage *)MSG_ADDR); - char uri[] = {URI, '\0'}; - otCoapMessageAppendUriPathOptions_fake.return_val = OT_ERROR_INVALID_ARGS; + otCoapMessageAppendUriPathOptions_fake.custom_fake = append_uri_path_options_fake; mock_nrf_rpc_tr_expect_add(RPC_RSP(OT_ERROR_INVALID_ARGS), NO_RSP); mock_nrf_rpc_tr_receive( @@ -187,8 +196,6 @@ ZTEST(ot_rpc_coap, test_otCoapMessageAppendUriPathOptions) mock_nrf_rpc_tr_expect_done(); zassert_equal(otCoapMessageAppendUriPathOptions_fake.call_count, 1); - zassert_equal(otCoapMessageAppendUriPathOptions_fake.arg0_val, (otMessage *)MSG_ADDR); - zassert_str_equal(otCoapMessageAppendUriPathOptions_fake.arg1_val, uri); } /* diff --git a/tests/subsys/net/openthread/rpc/server/src/dataset_suite.c b/tests/subsys/net/openthread/rpc/server/src/dataset_suite.c index d98ee4bface9..e7a29c20b3d2 100644 --- a/tests/subsys/net/openthread/rpc/server/src/dataset_suite.c +++ b/tests/subsys/net/openthread/rpc/server/src/dataset_suite.c @@ -65,26 +65,30 @@ ZTEST(ot_rpc_dataset, test_otDatasetIsCommissioned) zassert_equal(otDatasetIsCommissioned_fake.call_count, 2); } - /* * Test reception of otDatasetSetActiveTlvs command. * Test serialization of the result: OT_ERROR_NONE. */ -ZTEST(ot_rpc_dataset, test_otDatasetSetActiveTlvs) +otError dataset_tlvs_set_fake(otInstance *instance, const otOperationalDatasetTlvs *dataset) { const otOperationalDatasetTlvs expected_dataset = { {INT_SEQUENCE(OT_OPERATIONAL_DATASET_MAX_LENGTH)}, OT_OPERATIONAL_DATASET_MAX_LENGTH}; - otDatasetSetActiveTlvs_fake.return_val = OT_ERROR_NONE; + zassert_mem_equal(dataset, &expected_dataset, sizeof(otOperationalDatasetTlvs)); + + return OT_ERROR_NONE; +} + +ZTEST(ot_rpc_dataset, test_otDatasetSetActiveTlvs) +{ + otDatasetSetActiveTlvs_fake.custom_fake = dataset_tlvs_set_fake; mock_nrf_rpc_tr_expect_add(RPC_RSP(OT_ERROR_NONE), NO_RSP); mock_nrf_rpc_tr_receive(RPC_CMD(OT_RPC_CMD_DATASET_SET_ACTIVE_TLVS, TLVS)); mock_nrf_rpc_tr_expect_done(); zassert_equal(otDatasetSetActiveTlvs_fake.call_count, 1); - zassert_mem_equal(otDatasetSetActiveTlvs_fake.arg1_val, &expected_dataset, - sizeof(otOperationalDatasetTlvs)); } /* @@ -145,68 +149,70 @@ ZTEST(ot_rpc_dataset, test_otDatasetGetActiveTlvs_null) * Test reception of otDatasetSetActive command. * Test serialization of the result: OT_ERROR_NONE. */ -ZTEST(ot_rpc_dataset, test_otDatasetSetActive) +otError dataset_set_fake(otInstance *instance, const otOperationalDataset *dataset) { - const otOperationalDataset *expected_dataset; uint8_t net_key[] = {INT_SEQUENCE(OT_NETWORK_KEY_SIZE)}; uint8_t nwk_name[] = {INT_SEQUENCE(OT_NETWORK_NAME_MAX_SIZE), 0}; uint8_t ext_pan_id[] = {INT_SEQUENCE(OT_EXT_PAN_ID_SIZE)}; uint8_t local_prefix[] = {INT_SEQUENCE(OT_IP6_PREFIX_SIZE)}; uint8_t pskc[] = {INT_SEQUENCE(OT_PSKC_MAX_SIZE)}; - otDatasetSetActive_fake.return_val = OT_ERROR_NONE; + zassert_equal(dataset->mActiveTimestamp.mSeconds, 0x0123456789abcdefull); + zassert_equal(dataset->mActiveTimestamp.mTicks, 0x1234); + zassert_false(dataset->mActiveTimestamp.mAuthoritative); + + zassert_equal(dataset->mPendingTimestamp.mSeconds, 0x0123456789abcdefull); + zassert_equal(dataset->mPendingTimestamp.mTicks, 0x1234); + zassert_false(dataset->mPendingTimestamp.mAuthoritative); + + zassert_mem_equal(dataset->mNetworkKey.m8, net_key, OT_NETWORK_KEY_SIZE); + zassert_mem_equal(dataset->mNetworkName.m8, nwk_name, OT_NETWORK_NAME_MAX_SIZE + 1); + zassert_mem_equal(dataset->mExtendedPanId.m8, ext_pan_id, OT_EXT_PAN_ID_SIZE); + zassert_mem_equal(dataset->mMeshLocalPrefix.m8, local_prefix, OT_IP6_PREFIX_SIZE); + zassert_equal(dataset->mDelay, 0x12345678ul); + zassert_equal(dataset->mPanId, 0xabcd); + zassert_equal(dataset->mChannel, 0xef67); + zassert_mem_equal(dataset->mPskc.m8, pskc, OT_PSKC_MAX_SIZE); + + zassert_equal(dataset->mSecurityPolicy.mRotationTime, 0x9876); + zassert_true(!!dataset->mSecurityPolicy.mObtainNetworkKeyEnabled); + zassert_false(!!dataset->mSecurityPolicy.mNativeCommissioningEnabled); + zassert_true(!!dataset->mSecurityPolicy.mRoutersEnabled); + zassert_false(!!dataset->mSecurityPolicy.mExternalCommissioningEnabled); + zassert_true(!!dataset->mSecurityPolicy.mCommercialCommissioningEnabled); + zassert_false(!!dataset->mSecurityPolicy.mAutonomousEnrollmentEnabled); + zassert_true(!!dataset->mSecurityPolicy.mNetworkKeyProvisioningEnabled); + zassert_false(!!dataset->mSecurityPolicy.mTobleLinkEnabled); + zassert_true(!!dataset->mSecurityPolicy.mNonCcmRoutersEnabled); + zassert_equal(dataset->mSecurityPolicy.mVersionThresholdForRouting, 7); + + zassert_equal(dataset->mChannelMask, 0xfedcba98ul); + + zassert_false(dataset->mComponents.mIsActiveTimestampPresent); + zassert_true(dataset->mComponents.mIsPendingTimestampPresent); + zassert_false(dataset->mComponents.mIsNetworkKeyPresent); + zassert_true(dataset->mComponents.mIsNetworkNamePresent); + zassert_false(dataset->mComponents.mIsExtendedPanIdPresent); + zassert_true(dataset->mComponents.mIsMeshLocalPrefixPresent); + zassert_false(dataset->mComponents.mIsDelayPresent); + zassert_true(dataset->mComponents.mIsPanIdPresent); + zassert_false(dataset->mComponents.mIsChannelPresent); + zassert_true(dataset->mComponents.mIsPskcPresent); + zassert_false(dataset->mComponents.mIsSecurityPolicyPresent); + zassert_true(dataset->mComponents.mIsChannelMaskPresent); + + return OT_ERROR_NONE; +} + +ZTEST(ot_rpc_dataset, test_otDatasetSetActive) +{ + otDatasetSetActive_fake.custom_fake = dataset_set_fake; mock_nrf_rpc_tr_expect_add(RPC_RSP(OT_ERROR_NONE), NO_RSP); mock_nrf_rpc_tr_receive(RPC_CMD(OT_RPC_CMD_DATASET_SET_ACTIVE, DATASET)); mock_nrf_rpc_tr_expect_done(); - expected_dataset = otDatasetSetActive_fake.arg1_val; - zassert_equal(otDatasetSetActive_fake.call_count, 1); - zassert_equal(expected_dataset->mActiveTimestamp.mSeconds, 0x0123456789abcdefull); - zassert_equal(expected_dataset->mActiveTimestamp.mTicks, 0x1234); - zassert_false(expected_dataset->mActiveTimestamp.mAuthoritative); - - zassert_equal(expected_dataset->mPendingTimestamp.mSeconds, 0x0123456789abcdefull); - zassert_equal(expected_dataset->mPendingTimestamp.mTicks, 0x1234); - zassert_false(expected_dataset->mPendingTimestamp.mAuthoritative); - - zassert_mem_equal(expected_dataset->mNetworkKey.m8, net_key, OT_NETWORK_KEY_SIZE); - zassert_mem_equal(expected_dataset->mNetworkName.m8, nwk_name, - OT_NETWORK_NAME_MAX_SIZE + 1); - zassert_mem_equal(expected_dataset->mExtendedPanId.m8, ext_pan_id, OT_EXT_PAN_ID_SIZE); - zassert_mem_equal(expected_dataset->mMeshLocalPrefix.m8, local_prefix, OT_IP6_PREFIX_SIZE); - zassert_equal(expected_dataset->mDelay, 0x12345678ul); - zassert_equal(expected_dataset->mPanId, 0xabcd); - zassert_equal(expected_dataset->mChannel, 0xef67); - zassert_mem_equal(expected_dataset->mPskc.m8, pskc, OT_PSKC_MAX_SIZE); - - zassert_equal(expected_dataset->mSecurityPolicy.mRotationTime, 0x9876); - zassert_true(!!expected_dataset->mSecurityPolicy.mObtainNetworkKeyEnabled); - zassert_false(!!expected_dataset->mSecurityPolicy.mNativeCommissioningEnabled); - zassert_true(!!expected_dataset->mSecurityPolicy.mRoutersEnabled); - zassert_false(!!expected_dataset->mSecurityPolicy.mExternalCommissioningEnabled); - zassert_true(!!expected_dataset->mSecurityPolicy.mCommercialCommissioningEnabled); - zassert_false(!!expected_dataset->mSecurityPolicy.mAutonomousEnrollmentEnabled); - zassert_true(!!expected_dataset->mSecurityPolicy.mNetworkKeyProvisioningEnabled); - zassert_false(!!expected_dataset->mSecurityPolicy.mTobleLinkEnabled); - zassert_true(!!expected_dataset->mSecurityPolicy.mNonCcmRoutersEnabled); - zassert_equal(expected_dataset->mSecurityPolicy.mVersionThresholdForRouting, 7); - - zassert_equal(expected_dataset->mChannelMask, 0xfedcba98ul); - - zassert_false(expected_dataset->mComponents.mIsActiveTimestampPresent); - zassert_true(expected_dataset->mComponents.mIsPendingTimestampPresent); - zassert_false(expected_dataset->mComponents.mIsNetworkKeyPresent); - zassert_true(expected_dataset->mComponents.mIsNetworkNamePresent); - zassert_false(expected_dataset->mComponents.mIsExtendedPanIdPresent); - zassert_true(expected_dataset->mComponents.mIsMeshLocalPrefixPresent); - zassert_false(expected_dataset->mComponents.mIsDelayPresent); - zassert_true(expected_dataset->mComponents.mIsPanIdPresent); - zassert_false(expected_dataset->mComponents.mIsChannelPresent); - zassert_true(expected_dataset->mComponents.mIsPskcPresent); - zassert_false(expected_dataset->mComponents.mIsSecurityPolicyPresent); - zassert_true(expected_dataset->mComponents.mIsChannelMaskPresent); } /* diff --git a/tests/subsys/nfc/rpc/server/src/t2t_suite.c b/tests/subsys/nfc/rpc/server/src/t2t_suite.c index 786bd13e97bb..6602b18a3e6d 100644 --- a/tests/subsys/nfc/rpc/server/src/t2t_suite.c +++ b/tests/subsys/nfc/rpc/server/src/t2t_suite.c @@ -102,21 +102,21 @@ ZTEST(nfc_rpc_t2t_srv, test_nfc_t2t_parameter_set) zassert_equal(nfc_t2t_parameter_set_fake.call_count, 1); } +/* Test reception of nfc_t2t_parameter_get command. */ static int nfc_t2t_parameter_get_custom_fake(nfc_t2t_param_id_t id, void *data, size_t *max_data_length) { uint8_t expected_data[DATA_SIZE] = {INT_SEQUENCE(DATA_SIZE)}; + zassert_equal(id, NFC_T2T_PARAM_FDT_MIN); zassert_equal(*max_data_length, DATA_SIZE); memcpy(data, expected_data, *max_data_length); return 0; } -/* Test reception of nfc_t2t_parameter_get command. */ ZTEST(nfc_rpc_t2t_srv, test_nfc_t2t_parameter_get) { - nfc_t2t_parameter_get_fake.return_val = 0; nfc_t2t_parameter_get_fake.custom_fake = nfc_t2t_parameter_get_custom_fake; mock_nrf_rpc_tr_expect_add(RPC_RSP(NFC_DATA), NO_RSP); @@ -125,14 +125,24 @@ ZTEST(nfc_rpc_t2t_srv, test_nfc_t2t_parameter_get) mock_nrf_rpc_tr_expect_done(); zassert_equal(nfc_t2t_parameter_get_fake.call_count, 1); - zassert_equal(nfc_t2t_parameter_get_fake.arg0_val, NFC_T2T_PARAM_FDT_MIN); - zassert_equal(*nfc_t2t_parameter_get_fake.arg2_val, DATA_SIZE); } /* Test reception of nfc_t2t_parameter_get command with returned error. */ +static int nfc_t2t_parameter_get_custom_fake_err(nfc_t2t_param_id_t id, void *data, + size_t *max_data_length) +{ + uint8_t expected_data[DATA_SIZE] = {INT_SEQUENCE(DATA_SIZE)}; + + zassert_equal(id, NFC_T2T_PARAM_FDT_MIN); + zassert_equal(*max_data_length, DATA_SIZE); + memcpy(data, expected_data, *max_data_length); + + return -NRF_EINVAL; +} + ZTEST(nfc_rpc_t2t_srv, test_nfc_t2t_parameter_get_negative) { - nfc_t2t_parameter_get_fake.return_val = -NRF_EINVAL; + nfc_t2t_parameter_get_fake.custom_fake = nfc_t2t_parameter_get_custom_fake_err; mock_nrf_rpc_tr_expect_add(RPC_RSP(CBOR_NULL), NO_RSP); mock_nrf_rpc_tr_receive(RPC_CMD(NFC_RPC_CMD_T2T_PARAMETER_GET, NFC_T2T_PARAM_FDT_MIN, @@ -140,8 +150,6 @@ ZTEST(nfc_rpc_t2t_srv, test_nfc_t2t_parameter_get_negative) mock_nrf_rpc_tr_expect_done(); zassert_equal(nfc_t2t_parameter_get_fake.call_count, 1); - zassert_equal(nfc_t2t_parameter_get_fake.arg0_val, NFC_T2T_PARAM_FDT_MIN); - zassert_equal(*nfc_t2t_parameter_get_fake.arg2_val, DATA_SIZE); } /* Test reception of nfc_t2t_payload_set command. */ diff --git a/tests/subsys/nfc/rpc/server/src/t4t_suite.c b/tests/subsys/nfc/rpc/server/src/t4t_suite.c index 18bd5a33eed4..944f82d529aa 100644 --- a/tests/subsys/nfc/rpc/server/src/t4t_suite.c +++ b/tests/subsys/nfc/rpc/server/src/t4t_suite.c @@ -100,21 +100,21 @@ ZTEST(nfc_rpc_t4t_srv, test_nfc_t4t_parameter_set) zassert_equal(nfc_t4t_parameter_set_fake.call_count, 1); } +/* Test reception of nfc_t4t_parameter_get command. */ static int nfc_t4t_parameter_get_custom_fake(nfc_t4t_param_id_t id, void *data, size_t *max_data_length) { uint8_t expected_data[DATA_SIZE] = {INT_SEQUENCE(DATA_SIZE)}; + zassert_equal(id, NFC_T4T_PARAM_FWI); zassert_equal(*max_data_length, DATA_SIZE); memcpy(data, expected_data, *max_data_length); return 0; } -/* Test reception of nfc_t4t_parameter_get command. */ ZTEST(nfc_rpc_t4t_srv, test_nfc_t4t_parameter_get) { - nfc_t4t_parameter_get_fake.return_val = 0; nfc_t4t_parameter_get_fake.custom_fake = nfc_t4t_parameter_get_custom_fake; mock_nrf_rpc_tr_expect_add(RPC_RSP(NFC_DATA), NO_RSP); @@ -123,14 +123,24 @@ ZTEST(nfc_rpc_t4t_srv, test_nfc_t4t_parameter_get) mock_nrf_rpc_tr_expect_done(); zassert_equal(nfc_t4t_parameter_get_fake.call_count, 1); - zassert_equal(nfc_t4t_parameter_get_fake.arg0_val, NFC_T4T_PARAM_FWI); - zassert_equal(*nfc_t4t_parameter_get_fake.arg2_val, DATA_SIZE); } /* Test reception of nfc_t4t_parameter_get command with returned error. */ +static int nfc_t4t_parameter_get_custom_fake_err(nfc_t4t_param_id_t id, void *data, + size_t *max_data_length) +{ + uint8_t expected_data[DATA_SIZE] = {INT_SEQUENCE(DATA_SIZE)}; + + zassert_equal(id, NFC_T4T_PARAM_FDT_MIN); + zassert_equal(*max_data_length, DATA_SIZE); + memcpy(data, expected_data, *max_data_length); + + return -NRF_EINVAL; +} + ZTEST(nfc_rpc_t4t_srv, test_nfc_t4t_parameter_get_negative) { - nfc_t4t_parameter_get_fake.return_val = -NRF_EINVAL; + nfc_t4t_parameter_get_fake.custom_fake = nfc_t4t_parameter_get_custom_fake_err; mock_nrf_rpc_tr_expect_add(RPC_RSP(CBOR_NULL), NO_RSP); mock_nrf_rpc_tr_receive(RPC_CMD(NFC_RPC_CMD_T4T_PARAMETER_GET, NFC_T4T_PARAM_FDT_MIN, @@ -138,8 +148,6 @@ ZTEST(nfc_rpc_t4t_srv, test_nfc_t4t_parameter_get_negative) mock_nrf_rpc_tr_expect_done(); zassert_equal(nfc_t4t_parameter_get_fake.call_count, 1); - zassert_equal(nfc_t4t_parameter_get_fake.arg0_val, NFC_T4T_PARAM_FDT_MIN); - zassert_equal(*nfc_t4t_parameter_get_fake.arg2_val, DATA_SIZE); } /* Test reception of nfc_t4t_ndef_rwpayload_set command. */