From 35fd18a090b4fc8ee8f037029913216522d6549b Mon Sep 17 00:00:00 2001 From: Guido Casati Date: Fri, 15 Nov 2024 16:02:28 +0100 Subject: [PATCH] Add test for NAS Service Accept enc/dec library --- openair3/NAS/NR_UE/5GS/tests/nas_lib_test.c | 53 +++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/openair3/NAS/NR_UE/5GS/tests/nas_lib_test.c b/openair3/NAS/NR_UE/5GS/tests/nas_lib_test.c index 41865051cd..12e69c1581 100644 --- a/openair3/NAS/NR_UE/5GS/tests/nas_lib_test.c +++ b/openair3/NAS/NR_UE/5GS/tests/nas_lib_test.c @@ -2,7 +2,9 @@ #include #include #include +#include "common/utils/ds/byte_array.h" #include "fgs_service_request.h" +#include "fgmm_service_accept.h" #include "nr_nas_msg.h" void exit_function(const char *file, const char *function, const int line, const char *s, const int assert) @@ -75,8 +77,59 @@ static void test_service_request(void) "test_service_request() failed: original and decoded messages do not match\n"); } +/** + * @brief Test NAS Service Accept enc/dec + */ +static void test_service_accept(void) +{ + // Dummy NAS Service Accept message + fgs_service_accept_msg_t orig = { + .has_psi_status = true, + .has_psi_res = true, + .num_errors = 1, + .t3448 = malloc_or_fail(sizeof(*orig.t3448)), + }; + orig.psi_status[1] = PDU_SESSION_ACTIVE; + orig.psi_status[2] = PDU_SESSION_INACTIVE; + orig.psi_status[3] = PDU_SESSION_ACTIVE; + orig.psi_res[1] = REACTIVATION_FAILED; + orig.psi_res[2] = REACTIVATION_SUCCESS; + orig.cause[0].cause = Illegal_UE; + orig.cause[0].pdu_session_id = 1; + orig.t3448->value = 16; + orig.t3448->unit = TWO_SECONDS; + + // Expected encoded data + uint8_t expected_enc[] = {0x50, 0x02, 0x0a, 0x00, 0x26, 0x02, 0x02, 0x00, 0x72, 0x00, 0x00, 0x01, 0x03, 0x6B, 0x01, 0x10}; + uint16_t len_status = 2; + expected_enc[9] = (len_status >> 8) & 0xFF; + expected_enc[10] = len_status & 0xFF; + + // Buffer + uint8_t buf[64] = {0}; + byte_array_t buffer = {.buf = &buf[0], .len = sizeof(expected_enc)}; + + // Encode NAS Service Accept + int encoded_length = encode_fgs_service_accept(&buffer, &orig); + AssertFatal(encoded_length == sizeofArray(expected_enc), "encode_fgs_service_accept() failed\n"); + + // Compare the raw encoded buffer with expected encoded data + AssertFatal(memcmp(buffer.buf, expected_enc, buffer.len) == 0, "Encoding mismatch!\n"); + + // Decode NAS Service Accept + fgs_service_accept_msg_t dec = {0}; + int decoded_length = decode_fgs_service_accept(&dec, &buffer); + AssertFatal(decoded_length >= 0, "decode_fgs_service_accept() failed\n"); + + // Compare original and decoded messages + AssertFatal(eq_service_accept(&orig, &dec), "test_service_accept() failed: original and decoded messages do not match\n"); + free_fgs_service_accept(&dec); + free_fgs_service_accept(&orig); +} + int main() { test_service_request(); + test_service_accept(); return 0; }