diff --git a/nfapi/CMakeLists.txt b/nfapi/CMakeLists.txt index 1362e33b06ab84cf4ddca32322224e5c28fe89b0..d6c5b0e92a39acf1489578a9c3e8d0e7b92594ff 100644 --- a/nfapi/CMakeLists.txt +++ b/nfapi/CMakeLists.txt @@ -1,2 +1,3 @@ add_subdirectory(oai_integration/aerial) add_subdirectory(open-nFAPI) +add_subdirectory(tests) diff --git a/nfapi/open-nFAPI/fapi/inc/nr_fapi_p5.h b/nfapi/open-nFAPI/fapi/inc/nr_fapi_p5.h index 197f23d06d5d76336b1adf0000c1671f5ccc3d89..983fe153026135c1108262ff4e5ae028535faacb 100644 --- a/nfapi/open-nFAPI/fapi/inc/nr_fapi_p5.h +++ b/nfapi/open-nFAPI/fapi/inc/nr_fapi_p5.h @@ -34,4 +34,6 @@ #include "stdint.h" #include "nfapi_interface.h" +uint8_t pack_nr_param_request(void *msg, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p4_p5_codec_config_t *config); +uint8_t unpack_nr_param_request(uint8_t **ppReadPackedMsg, uint8_t *end, void *msg, nfapi_p4_p5_codec_config_t *config); #endif // OPENAIRINTERFACE_NR_FAPI_P5_H diff --git a/nfapi/open-nFAPI/fapi/src/nr_fapi_p5.c b/nfapi/open-nFAPI/fapi/src/nr_fapi_p5.c index 7cfe261f9c496cbdabd6ea399610450d26687844..bc1f0d932b4f0e9790fad06574bbffd231a2264a 100644 --- a/nfapi/open-nFAPI/fapi/src/nr_fapi_p5.c +++ b/nfapi/open-nFAPI/fapi/src/nr_fapi_p5.c @@ -338,3 +338,15 @@ int check_nr_fapi_unpack_length(nfapi_nr_phy_msg_type_e msgId, uint32_t unpacked return retLen; } + + +uint8_t pack_nr_param_request(void *msg, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p4_p5_codec_config_t *config) { + nfapi_nr_param_request_scf_t *pNfapiMsg = (nfapi_nr_param_request_scf_t *)msg; + return (pack_vendor_extension_tlv(pNfapiMsg->vendor_extension, ppWritePackedMsg, end, config)); +} + +uint8_t unpack_nr_param_request(uint8_t **ppReadPackedMsg, uint8_t *end, void *msg, nfapi_p4_p5_codec_config_t *config) +{ + nfapi_nr_param_request_scf_t *pNfapiMsg = (nfapi_nr_param_request_scf_t *)msg; + return unpack_nr_tlv_list(NULL, 0, ppReadPackedMsg, end, config, &(pNfapiMsg->vendor_extension)); +} diff --git a/nfapi/open-nFAPI/nfapi/public_inc/nfapi_interface.h b/nfapi/open-nFAPI/nfapi/public_inc/nfapi_interface.h index 46d85e08e8824404cb58af402d751d916b104d98..7fcb42bedc833e1b1ca4ea62aa0fad6a1628ae7e 100644 --- a/nfapi/open-nFAPI/nfapi/public_inc/nfapi_interface.h +++ b/nfapi/open-nFAPI/nfapi/public_inc/nfapi_interface.h @@ -4118,10 +4118,6 @@ 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_param_request(void *msg, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p4_p5_codec_config_t *config); - -uint8_t unpack_nr_param_request(uint8_t **ppReadPackedMsg, uint8_t *end, void *msg, nfapi_p4_p5_codec_config_t *config); - uint8_t pack_nr_param_response(void *msg, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p4_p5_codec_config_t *config); uint8_t unpack_nr_param_response(uint8_t **ppReadPackedMsg, uint8_t *end, void *msg, nfapi_p4_p5_codec_config_t *config); diff --git a/nfapi/open-nFAPI/nfapi/src/nfapi_p5.c b/nfapi/open-nFAPI/nfapi/src/nfapi_p5.c index cda4fb173d9bbd19c88b6e189e50e263398375b7..a7cab371b45726140ba704b4dc9b1bdee9ba25c9 100644 --- a/nfapi/open-nFAPI/nfapi/src/nfapi_p5.c +++ b/nfapi/open-nFAPI/nfapi/src/nfapi_p5.c @@ -273,11 +273,6 @@ static uint8_t pack_pnf_stop_response(void *msg, uint8_t **ppWritePackedMsg, uin pack_vendor_extension_tlv(pNfapiMsg->vendor_extension, ppWritePackedMsg, end, config)); } -uint8_t pack_nr_param_request(void *msg, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p4_p5_codec_config_t *config) { - nfapi_nr_param_request_scf_t *pNfapiMsg = (nfapi_nr_param_request_scf_t *)msg; - return (pack_vendor_extension_tlv(pNfapiMsg->vendor_extension, ppWritePackedMsg, end, config)); -} - static uint8_t pack_param_request(void *msg, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p4_p5_codec_config_t *config) { nfapi_param_request_t *pNfapiMsg = (nfapi_param_request_t *)msg; return (pack_vendor_extension_tlv(pNfapiMsg->vendor_extension, ppWritePackedMsg, end, config)); @@ -2450,11 +2445,6 @@ static uint8_t unpack_param_request(uint8_t **ppReadPackedMsg, uint8_t *end, voi return unpack_tlv_list(NULL, 0, ppReadPackedMsg, end, config, &(pNfapiMsg->vendor_extension)); } -uint8_t unpack_nr_param_request(uint8_t **ppReadPackedMsg, uint8_t *end, void *msg, nfapi_p4_p5_codec_config_t *config) -{ - nfapi_nr_param_request_scf_t *pNfapiMsg = (nfapi_nr_param_request_scf_t *)msg; - return unpack_nr_tlv_list(NULL, 0, ppReadPackedMsg, end, config, &(pNfapiMsg->vendor_extension)); -} static uint8_t unpack_param_response(uint8_t **ppReadPackedMsg, uint8_t *end, void *msg, nfapi_p4_p5_codec_config_t *config) { diff --git a/nfapi/tests/CMakeLists.txt b/nfapi/tests/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..64f26743da678b32d1ad92dacb967baf1f5fc8cb --- /dev/null +++ b/nfapi/tests/CMakeLists.txt @@ -0,0 +1,3 @@ +if(ENABLE_TESTS) + add_subdirectory(p5) +endif() diff --git a/nfapi/tests/nr_fapi_test.h b/nfapi/tests/nr_fapi_test.h new file mode 100644 index 0000000000000000000000000000000000000000..5e2ef2fbfc630a0f50bc3ef9e1d2e72938486eee --- /dev/null +++ b/nfapi/tests/nr_fapi_test.h @@ -0,0 +1,90 @@ +/* + * 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_test.h + * \brief + * \author Ruben S. Silva + * \date 2024 + * \version 0.1 + * \company OpenAirInterface Software Alliance + * \email: contact@openairinterface.org, rsilva@allbesmart.pt + * \note + * \warning + */ + +#ifndef OPENAIRINTERFACE_NR_FAPI_TEST_H +#define OPENAIRINTERFACE_NR_FAPI_TEST_H +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <inttypes.h> +#include <sys/wait.h> +#include <unistd.h> + +#ifndef _STANDALONE_TESTING_ +#include "common/utils/LOG/log.h" +#endif +#include "nfapi_nr_interface.h" +#include "nfapi_nr_interface_scf.h" + +#define CMP_TLV(_a,_b) do{ if(_a != _b){ return -1; } }while(0) + +uint8_t rand8() +{ + return (rand() & 0xff); +} +uint16_t rand16() +{ + return rand8() << 8 | rand8(); +} +uint32_t rand24() +{ + return rand16() << 8 | rand8(); +} +uint32_t rand32() +{ + return rand24() << 8 | rand8(); +} +uint64_t rand64() +{ + return (uint64_t)rand32() << 32 | rand32(); +} + +uint8_t rand8_range(uint8_t lower, uint8_t upper) +{ + return (rand() % (upper - lower + 1)) + lower; +} + +uint16_t rand16_range(uint16_t lower, uint16_t upper) +{ + return (rand() % (upper - lower + 1)) + lower; +} + +int main(int n, char *v[]); + +static inline void fapi_test_init() +{ + time_t now = time(NULL); + srand(now); + printf("srand seed is %ld\n", now); + logInit(); + set_glog(OAILOG_DISABLE); +} +#endif // OPENAIRINTERFACE_NR_FAPI_TEST_H diff --git a/nfapi/tests/p5/CMakeLists.txt b/nfapi/tests/p5/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..4feef1a5fc28f7a0623c6d0878662176ff63d417 --- /dev/null +++ b/nfapi/tests/p5/CMakeLists.txt @@ -0,0 +1,15 @@ +set(Test_Labels fapi p5) +set (_fapi_p5_messages "param_request") + +foreach (fapi_p5_message IN LISTS _fapi_p5_messages) + add_executable(nr_fapi_${fapi_p5_message}_test nr_fapi_${fapi_p5_message}_test.c) + target_link_libraries(nr_fapi_${fapi_p5_message}_test PUBLIC nr_fapi_p5) + target_link_libraries(nr_fapi_${fapi_p5_message}_test PRIVATE pthread UTIL ${T_LIB} minimal_lib) + target_compile_definitions(nr_fapi_${fapi_p5_message}_test PRIVATE TEST="nr_fapi_test.h") + add_dependencies(tests nr_fapi_${fapi_p5_message}_test) + + add_test(NAME nr_fapi_${fapi_p5_message}_test + COMMAND nr_fapi_${fapi_p5_message}_test ${CMAKE_CURRENT_BINARY_DIR} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) + set_tests_properties(nr_fapi_${fapi_p5_message}_test PROPERTIES LABELS "${Test_Labels}") +endforeach () diff --git a/nfapi/tests/p5/nr_fapi_param_request_test.c b/nfapi/tests/p5/nr_fapi_param_request_test.c new file mode 100644 index 0000000000000000000000000000000000000000..faf56dc3c99cf09740d196f84690542e3ff782e8 --- /dev/null +++ b/nfapi/tests/p5/nr_fapi_param_request_test.c @@ -0,0 +1,86 @@ +/* + * 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_param_request_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_param_request_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); + // PARAM.request message body length is 0 + 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_param_request_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(compare_param_request(&unpacked_req, req)); + free_param_request(&unpacked_req); +} + +void test_copy(const nfapi_nr_param_request_scf_t *msg) +{ + // Test copy function + nfapi_nr_param_request_scf_t copy = {0}; + copy_param_request(msg, ©); + DevAssert(compare_param_request(msg, ©)); + free_param_request(©); +} + +int main(int n, char *v[]) +{ + fapi_test_init(); + + nfapi_nr_param_request_scf_t req = {.header.message_id = NFAPI_NR_PHY_MSG_TYPE_PARAM_REQUEST}; + // Perform tests + test_pack_unpack(&req); + test_copy(&req); + // All tests successful! + free_param_request(&req); + return 0; +}