Skip to content

Commit b943c9a

Browse files
FabianEckermanncodebot
authored andcommitted
cu_cp,f1ap: Add unittest for cu f1ap ue context
1 parent e3e7594 commit b943c9a

File tree

2 files changed

+102
-0
lines changed

2 files changed

+102
-0
lines changed

tests/unittests/f1ap/cu_cp/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ target_include_directories(f1ap_cu_test_helpers PRIVATE ${CMAKE_SOURCE_DIR})
1111
target_link_libraries(f1ap_cu_test_helpers f1ap_test_helpers srsran_f1ap_du srsran_f1ap_cu f1ap_asn1 srsran_support srslog)
1212

1313
set(SOURCES
14+
f1ap_cu_ue_context_test.cpp
1415
f1ap_cu_ue_context_setup_procedure_test.cpp
1516
f1ap_cu_ue_context_modification_procedure_test.cpp
1617
f1ap_cu_ue_context_release_procedure_test.cpp
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/*
2+
*
3+
* Copyright 2021-2023 Software Radio Systems Limited
4+
*
5+
* By using this file, you agree to the terms and conditions set
6+
* forth in the LICENSE file which can be found at the top level of
7+
* the distribution.
8+
*
9+
*/
10+
11+
#include "../common/test_helpers.h"
12+
#include "lib/f1ap/cu_cp/ue_context/f1ap_cu_ue_context.h"
13+
#include "srsran/support/executors/manual_task_worker.h"
14+
#include "srsran/support/test_utils.h"
15+
16+
#include <gtest/gtest.h>
17+
18+
using namespace srsran;
19+
using namespace srs_cu_cp;
20+
21+
/// Fixture class for F1AP UE context
22+
class f1ap_cu_ue_context_test : public ::testing::Test
23+
{
24+
protected:
25+
f1ap_cu_ue_context_test() { srslog::init(); };
26+
~f1ap_cu_ue_context_test()
27+
{
28+
// flush logger after each test
29+
srslog::flush();
30+
};
31+
32+
ue_index_t generate_random_ue_index()
33+
{
34+
return uint_to_ue_index(
35+
test_rgen::uniform_int<uint64_t>(ue_index_to_uint(ue_index_t::min), ue_index_to_uint(ue_index_t::max) - 1));
36+
};
37+
38+
timer_manager timer_mng;
39+
manual_task_worker ctrl_worker{128};
40+
timer_factory timers{timer_mng, ctrl_worker};
41+
f1ap_ue_context_list ue_ctxt_list{timers};
42+
};
43+
44+
TEST_F(f1ap_cu_ue_context_test, when_ue_added_then_ue_exists)
45+
{
46+
ue_index_t ue_index = generate_random_ue_index();
47+
gnb_cu_ue_f1ap_id_t cu_ue_f1ap_id = generate_random_gnb_cu_ue_f1ap_id();
48+
49+
ue_ctxt_list.add_ue(ue_index, cu_ue_f1ap_id);
50+
51+
ASSERT_TRUE(ue_ctxt_list.contains(cu_ue_f1ap_id));
52+
ASSERT_TRUE(ue_ctxt_list.contains(ue_index));
53+
54+
ASSERT_EQ(ue_ctxt_list[cu_ue_f1ap_id].cu_ue_f1ap_id, cu_ue_f1ap_id);
55+
ASSERT_EQ(ue_ctxt_list[cu_ue_f1ap_id].ue_index, ue_index);
56+
ASSERT_EQ(ue_ctxt_list[ue_index].cu_ue_f1ap_id, cu_ue_f1ap_id);
57+
ASSERT_EQ(ue_ctxt_list[ue_index].ue_index, ue_index);
58+
}
59+
60+
TEST_F(f1ap_cu_ue_context_test, when_ue_not_added_then_ue_doesnt_exist)
61+
{
62+
ue_index_t ue_index = generate_random_ue_index();
63+
gnb_cu_ue_f1ap_id_t cu_ue_f1ap_id = generate_random_gnb_cu_ue_f1ap_id();
64+
65+
ASSERT_FALSE(ue_ctxt_list.contains(cu_ue_f1ap_id));
66+
ASSERT_FALSE(ue_ctxt_list.contains(ue_index));
67+
}
68+
69+
TEST_F(f1ap_cu_ue_context_test, when_unsupported_number_of_ues_addeded_then_ue_not_added)
70+
{
71+
// Add maximum number of supported UEs
72+
for (unsigned it = 0; it < MAX_NOF_UES_PER_DU; ++it) {
73+
gnb_cu_ue_f1ap_id_t cu_ue_f1ap_id = ue_ctxt_list.next_gnb_cu_ue_f1ap_id();
74+
ASSERT_NE(cu_ue_f1ap_id, gnb_cu_ue_f1ap_id_t::invalid);
75+
ue_index_t ue_index = uint_to_ue_index(it);
76+
77+
ue_ctxt_list.add_ue(ue_index, cu_ue_f1ap_id);
78+
79+
ASSERT_TRUE(ue_ctxt_list.contains(cu_ue_f1ap_id));
80+
ASSERT_TRUE(ue_ctxt_list.contains(ue_index));
81+
}
82+
83+
// Try to get another cu_ue_f1ap_id (should fail)
84+
ASSERT_EQ(ue_ctxt_list.next_gnb_cu_ue_f1ap_id(), gnb_cu_ue_f1ap_id_t::invalid);
85+
}
86+
87+
TEST_F(f1ap_cu_ue_context_test, when_ue_exists_then_removal_succeeds)
88+
{
89+
ue_index_t ue_index = generate_random_ue_index();
90+
gnb_cu_ue_f1ap_id_t cu_ue_f1ap_id = generate_random_gnb_cu_ue_f1ap_id();
91+
92+
ue_ctxt_list.add_ue(ue_index, cu_ue_f1ap_id);
93+
94+
// test removal
95+
ue_ctxt_list.remove_ue(cu_ue_f1ap_id);
96+
97+
ASSERT_FALSE(ue_ctxt_list.contains(cu_ue_f1ap_id));
98+
ASSERT_FALSE(ue_ctxt_list.contains(ue_index));
99+
100+
ue_ctxt_list.add_ue(ue_index, cu_ue_f1ap_id);
101+
}

0 commit comments

Comments
 (0)