Skip to content

Commit

Permalink
quarantine: fix RPC server tests without optimizations
Browse files Browse the repository at this point in the history
Fix unit tests using FFF fakes' arguments by pointer after
releasing the underlying memory.

Jira: NCSDK-30881

Signed-off-by: Damian Krolik <[email protected]>
  • Loading branch information
Damian-Nordic committed Dec 10, 2024
1 parent 81d8a9e commit b67a61e
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 79 deletions.
7 changes: 0 additions & 7 deletions scripts/quarantine_no_optimization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
15 changes: 11 additions & 4 deletions tests/subsys/net/openthread/rpc/server/src/coap_suite.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,21 +174,28 @@ 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(
RPC_CMD(OT_RPC_CMD_COAP_MESSAGE_APPEND_URI_PATH_OPTIONS, message_rep, CBOR_URI));
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);
}

/*
Expand Down
114 changes: 60 additions & 54 deletions tests/subsys/net/openthread/rpc/server/src/dataset_suite.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

/*
Expand Down Expand Up @@ -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);
}

/*
Expand Down
22 changes: 15 additions & 7 deletions tests/subsys/nfc/rpc/server/src/t2t_suite.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -125,23 +125,31 @@ 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,
CBOR_UINT8(DATA_SIZE)));
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. */
Expand Down
22 changes: 15 additions & 7 deletions tests/subsys/nfc/rpc/server/src/t4t_suite.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -123,23 +123,31 @@ 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,
CBOR_UINT8(DATA_SIZE)));
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. */
Expand Down

0 comments on commit b67a61e

Please sign in to comment.