Commit 32bbd64a authored by Rúben Soares da Silva's avatar Rúben Soares da Silva Committed by Rúben Soares Silva

Move functions for packing/unpacking ERROR.indication

Add unitary test for ERROR.indication ( test pack/unpack, free, copy and compare )
parent c95c12e8
......@@ -50,4 +50,6 @@ uint8_t pack_nr_stop_request(void *msg, uint8_t **ppWritePackedMsg, uint8_t *end
uint8_t unpack_nr_stop_request(uint8_t **ppReadPackedMsg, uint8_t *end, void *msg, nfapi_p4_p5_codec_config_t *config);
uint8_t pack_nr_stop_indication(void *msg, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p4_p5_codec_config_t *config);
uint8_t unpack_nr_stop_indication(uint8_t **ppReadPackedMsg, uint8_t *end, void *msg, nfapi_p4_p5_codec_config_t *config);
uint8_t pack_nr_error_indication(void *msg, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p4_p5_codec_config_t *config);
uint8_t unpack_nr_error_indication(uint8_t **ppReadPackedMsg, uint8_t *end, void *msg, nfapi_p4_p5_codec_config_t *config);
#endif // OPENAIRINTERFACE_NR_FAPI_P5_H
......@@ -1682,3 +1682,26 @@ uint8_t unpack_nr_stop_indication(uint8_t **ppReadPackedMsg, uint8_t *end, void
nfapi_nr_stop_indication_scf_t *pNfapiMsg = (nfapi_nr_stop_indication_scf_t *)msg;
return unpack_nr_tlv_list(NULL, 0, ppReadPackedMsg, end, config, &(pNfapiMsg->vendor_extension));
}
uint8_t pack_nr_error_indication(void *msg, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p4_p5_codec_config_t *config)
{
nfapi_nr_error_indication_scf_t *pNfapiMsg = (nfapi_nr_error_indication_scf_t *)msg;
uint8_t retval = push16(pNfapiMsg->sfn, ppWritePackedMsg, end);
retval &= push16(pNfapiMsg->slot, ppWritePackedMsg, end);
retval &= push8(pNfapiMsg->message_id, ppWritePackedMsg, end);
retval &= push8(pNfapiMsg->error_code, ppWritePackedMsg, end);
retval &= pack_vendor_extension_tlv(pNfapiMsg->vendor_extension, ppWritePackedMsg, end, config);
return retval;
}
uint8_t unpack_nr_error_indication(uint8_t **ppReadPackedMsg, uint8_t *end, void *msg, nfapi_p4_p5_codec_config_t *config)
{
nfapi_nr_error_indication_scf_t *pNfapiMsg = (nfapi_nr_error_indication_scf_t *)msg;
uint8_t retval = pull16(ppReadPackedMsg, &pNfapiMsg->sfn, end);
retval &= pull16(ppReadPackedMsg, &pNfapiMsg->slot, end);
retval &= pull8(ppReadPackedMsg, &pNfapiMsg->message_id, end);
retval &= pull8(ppReadPackedMsg, &pNfapiMsg->error_code, end);
retval &= unpack_nr_tlv_list(NULL, 0, ppReadPackedMsg, end, config, &(pNfapiMsg->vendor_extension));
return retval;
}
......@@ -4121,7 +4121,4 @@ int pack_nr_srs_beamforming_report(void *pMessageBuf, void *pPackedBuf, uint32_t
*/
int unpack_nr_srs_beamforming_report(void *pMessageBuf, uint32_t messageBufLen, void *pUnpackedBuf, uint32_t unpackedBufLen);
uint8_t pack_nr_error_indication(void *msg, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p4_p5_codec_config_t *config);
uint8_t unpack_nr_error_indication(uint8_t **ppReadPackedMsg, uint8_t *end, void *msg, nfapi_p4_p5_codec_config_t *config);
#endif /* _NFAPI_INTERFACE_H_ */
......@@ -1169,18 +1169,6 @@ static uint8_t pack_stop_request(void *msg, uint8_t **ppWritePackedMsg, uint8_t
return pack_vendor_extension_tlv(pNfapiMsg->vendor_extension, ppWritePackedMsg, end, config);
}
uint8_t pack_nr_error_indication(void *msg, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p4_p5_codec_config_t *config)
{
nfapi_nr_error_indication_scf_t *pNfapiMsg = (nfapi_nr_error_indication_scf_t *)msg;
uint8_t retval = push16(pNfapiMsg->sfn, ppWritePackedMsg, end);
retval &= push16(pNfapiMsg->slot, ppWritePackedMsg, end);
retval &= push8(pNfapiMsg->message_id, ppWritePackedMsg, end);
retval &= push8(pNfapiMsg->error_code, ppWritePackedMsg, end);
retval &= pack_vendor_extension_tlv(pNfapiMsg->vendor_extension, ppWritePackedMsg, end, config);
return retval;
}
static uint8_t pack_recevied_interference_power_measurement_value(void *tlv, uint8_t **ppWritePackedMsg, uint8_t *end) {
nfapi_received_interference_power_measurement_t *value = (nfapi_received_interference_power_measurement_t *)tlv;
return ( push16(value->number_of_resource_blocks, ppWritePackedMsg, end) &&
......@@ -2093,17 +2081,6 @@ static uint8_t unpack_stop_request(uint8_t **ppReadPackedMsg, uint8_t *end, void
return unpack_tlv_list(NULL, 0, ppReadPackedMsg, end, config, &(pNfapiMsg->vendor_extension));
}
uint8_t unpack_nr_error_indication(uint8_t **ppReadPackedMsg, uint8_t *end, void *msg, nfapi_p4_p5_codec_config_t *config)
{
nfapi_nr_error_indication_scf_t *pNfapiMsg = (nfapi_nr_error_indication_scf_t *)msg;
uint8_t retval = pull16(ppReadPackedMsg, &pNfapiMsg->sfn, end);
retval &= pull16(ppReadPackedMsg, &pNfapiMsg->slot, end);
retval &= pull8(ppReadPackedMsg, &pNfapiMsg->message_id, end);
retval &= pull8(ppReadPackedMsg, &pNfapiMsg->error_code, end);
retval &= unpack_nr_tlv_list(NULL, 0, ppReadPackedMsg, end, config, &(pNfapiMsg->vendor_extension));
return retval;
}
static uint8_t unpack_received_interference_power_measurement_value(void *tlv, uint8_t **ppReadPackedMsg, uint8_t *end) {
nfapi_received_interference_power_measurement_t *value = (nfapi_received_interference_power_measurement_t *)tlv;
return ( pull16(ppReadPackedMsg, &value->number_of_resource_blocks, end) &&
......
set(Test_Labels fapi p5)
set(_fapi_p5_messages "param_request;param_response;config_request;config_response;start_request;start_response;stop_request;stop_indication")
set(_fapi_p5_messages "param_request;param_response;config_request;config_response;start_request;start_response;stop_request;stop_indication;error_indication")
foreach (fapi_p5_message IN LISTS _fapi_p5_messages)
add_executable(nr_fapi_${fapi_p5_message}_test nr_fapi_${fapi_p5_message}_test.c)
......
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
/*! \file nfapi/tests/p5/nr_fapi_error_indication_test.c
* \brief
* \author Ruben S. Silva
* \date 2024
* \version 0.1
* \company OpenAirInterface Software Alliance
* \email: contact@openairinterface.org, rsilva@allbesmart.pt
* \note
* \warning
*/
#include "nfapi/tests/nr_fapi_test.h"
#include "nr_fapi_p5_utils.h"
void test_pack_unpack(nfapi_nr_error_indication_scf_t *req)
{
uint8_t msg_buf[65535];
uint16_t msg_len = sizeof(*req);
// first test the packing procedure
int pack_result = fapi_nr_p5_message_pack(req, msg_len, msg_buf, sizeof(msg_buf), NULL);
DevAssert(pack_result >= 0 + NFAPI_HEADER_LENGTH);
// update req message_length value with value calculated in message_pack procedure
req->header.message_length = pack_result - NFAPI_HEADER_LENGTH;
// test the unpacking of the header
// copy first NFAPI_HEADER_LENGTH bytes into a new buffer, to simulate SCTP PEEK
fapi_message_header_t header;
uint32_t header_buffer_size = NFAPI_HEADER_LENGTH;
uint8_t header_buffer[header_buffer_size];
for (int idx = 0; idx < header_buffer_size; idx++) {
header_buffer[idx] = msg_buf[idx];
}
uint8_t *pReadPackedMessage = header_buffer;
int unpack_header_result = fapi_nr_p5_message_header_unpack(&pReadPackedMessage, NFAPI_HEADER_LENGTH, &header, sizeof(header), 0);
DevAssert(unpack_header_result >= 0);
DevAssert(header.message_id == req->header.message_id);
DevAssert(header.message_length == req->header.message_length);
// test the unpacking and compare with initial message
nfapi_nr_error_indication_scf_t unpacked_req = {0};
int unpack_result =
fapi_nr_p5_message_unpack(msg_buf, header.message_length + NFAPI_HEADER_LENGTH, &unpacked_req, sizeof(unpacked_req), NULL);
DevAssert(unpack_result >= 0);
DevAssert(eq_error_indication(&unpacked_req, req));
free_error_indication(&unpacked_req);
}
void test_copy(const nfapi_nr_error_indication_scf_t *msg)
{
// Test copy function
nfapi_nr_error_indication_scf_t copy = {0};
copy_error_indication(msg, &copy);
DevAssert(eq_error_indication(msg, &copy));
free_error_indication(&copy);
}
int main(int n, char *v[])
{
fapi_test_init();
nfapi_nr_error_indication_scf_t req = {.header.message_id = NFAPI_NR_PHY_MSG_TYPE_ERROR_INDICATION};
// Fill the message with randomized data
req.sfn = rand16_range(0, 1023);
req.slot = rand16_range(0, 159);
req.message_id = rand8_range(0x00, 0xFF);
req.error_code = rand8_range(0x00, 0x08);
// Perform tests
test_pack_unpack(&req);
test_copy(&req);
// All tests successful!
free_error_indication(&req);
return 0;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment