mirror of
https://gitlab.eurecom.fr/oai/openairinterface5g.git
synced 2026-07-13 04:30:28 +00:00
Move functions for packing/unpacking START.request
Add unitary test for START.request ( test pack/unpack, free, copy and compare )
This commit is contained in:
committed by
Rúben Soares Silva
parent
442097e69a
commit
2c676865dc
@@ -1,5 +1,5 @@
|
||||
set(Test_Labels fapi p5)
|
||||
set(_fapi_p5_messages "param_request;param_response;config_request;config_response")
|
||||
set(_fapi_p5_messages "param_request;param_response;config_request;config_response;start_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)
|
||||
|
||||
86
nfapi/tests/p5/nr_fapi_start_request_test.c
Normal file
86
nfapi/tests/p5/nr_fapi_start_request_test.c
Normal file
@@ -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_start_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_start_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);
|
||||
// START.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_start_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(eq_start_request(&unpacked_req, req));
|
||||
free_start_request(&unpacked_req);
|
||||
}
|
||||
|
||||
void test_copy(const nfapi_nr_start_request_scf_t *msg)
|
||||
{
|
||||
// Test copy function
|
||||
nfapi_nr_start_request_scf_t copy = {0};
|
||||
copy_start_request(msg, ©);
|
||||
DevAssert(eq_start_request(msg, ©));
|
||||
free_start_request(©);
|
||||
}
|
||||
|
||||
int main(int n, char *v[])
|
||||
{
|
||||
fapi_test_init();
|
||||
|
||||
nfapi_nr_start_request_scf_t req = {.header.message_id = NFAPI_NR_PHY_MSG_TYPE_START_REQUEST};
|
||||
// Perform tests
|
||||
test_pack_unpack(&req);
|
||||
test_copy(&req);
|
||||
// All tests successful!
|
||||
free_start_request(&req);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user