|
| 1 | +/* |
| 2 | + * |
| 3 | + * Copyright 2021-2024 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 "lib/scheduler/slicing/slice_scheduler.h" |
| 12 | +#include "tests/unittests/scheduler/test_utils/config_generators.h" |
| 13 | +#include "srsran/srslog/srslog.h" |
| 14 | +#include <gtest/gtest.h> |
| 15 | + |
| 16 | +using namespace srsran; |
| 17 | + |
| 18 | +class slice_scheduler_test : public ::testing::Test |
| 19 | +{ |
| 20 | +protected: |
| 21 | + slice_scheduler_test(const std::vector<slice_rrm_policy_config>& rrm_policy_members = {}) : |
| 22 | + test_cfg( |
| 23 | + []() { |
| 24 | + cell_config_builder_params params{}; |
| 25 | + params.scs_common = subcarrier_spacing::kHz30; |
| 26 | + params.channel_bw_mhz = bs_channel_bandwidth_fr1::MHz100; |
| 27 | + params.dl_arfcn = 520000; |
| 28 | + params.band = nr_band::n41; |
| 29 | + return params; |
| 30 | + }(), |
| 31 | + scheduler_expert_config{}), |
| 32 | + cell_cfg([this, rrm_policy_members]() -> const cell_configuration& { |
| 33 | + auto req = test_cfg.get_default_cell_config_request(); |
| 34 | + req.rrm_policy_members = rrm_policy_members; |
| 35 | + return *test_cfg.add_cell(req); |
| 36 | + }()) |
| 37 | + { |
| 38 | + logger.set_level(srslog::basic_levels::debug); |
| 39 | + srslog::init(); |
| 40 | + } |
| 41 | + |
| 42 | + ~slice_scheduler_test() { srslog::flush(); } |
| 43 | + |
| 44 | + const ue_configuration* add_ue(du_ue_index_t ue_idx) |
| 45 | + { |
| 46 | + auto req = test_cfg.get_default_ue_config_request(); |
| 47 | + req.ue_index = ue_idx; |
| 48 | + req.crnti = to_rnti(0x4601 + ue_idx); |
| 49 | + req.starts_in_fallback = false; |
| 50 | + const ue_configuration* ue_cfg = test_cfg.add_ue(req); |
| 51 | + |
| 52 | + slice_sched.add_ue(*ue_cfg); |
| 53 | + |
| 54 | + return ue_cfg; |
| 55 | + } |
| 56 | + |
| 57 | + srslog::basic_logger& logger = srslog::fetch_basic_logger("TEST"); |
| 58 | + test_helpers::test_sched_config_manager test_cfg; |
| 59 | + const cell_configuration& cell_cfg; |
| 60 | + |
| 61 | + slice_scheduler slice_sched{cell_cfg}; |
| 62 | +}; |
| 63 | + |
| 64 | +class default_slice_scheduler_test : public slice_scheduler_test |
| 65 | +{}; |
| 66 | + |
| 67 | +TEST_F(default_slice_scheduler_test, if_no_rrm_policy_cfg_exists_then_only_default_slice_is_created) |
| 68 | +{ |
| 69 | + ASSERT_EQ(slice_sched.nof_slices(), 1); |
| 70 | + ASSERT_EQ(slice_sched.slice_config(ran_slice_id_t{0}).min_prb, 0); |
| 71 | + ASSERT_EQ(slice_sched.slice_config(ran_slice_id_t{0}).max_prb, MAX_NOF_PRBS); |
| 72 | +} |
| 73 | + |
| 74 | +TEST_F(default_slice_scheduler_test, when_no_lcid_exists_then_default_slice_is_not_a_candidate) |
| 75 | +{ |
| 76 | + slice_sched.slot_indication(); |
| 77 | + |
| 78 | + auto next_dl_slice = slice_sched.get_next_dl_candidate(); |
| 79 | + ASSERT_FALSE(next_dl_slice.has_value()); |
| 80 | + |
| 81 | + auto next_ul_slice = slice_sched.get_next_ul_candidate(); |
| 82 | + ASSERT_FALSE(next_ul_slice.has_value()); |
| 83 | +} |
| 84 | + |
| 85 | +TEST_F(default_slice_scheduler_test, when_lcid_is_part_of_default_slice_then_default_slice_is_valid_candidate) |
| 86 | +{ |
| 87 | + this->add_ue(to_du_ue_index(0)); |
| 88 | + slice_sched.slot_indication(); |
| 89 | + |
| 90 | + auto next_dl_slice = slice_sched.get_next_dl_candidate(); |
| 91 | + ASSERT_TRUE(next_dl_slice.has_value()); |
| 92 | + ASSERT_EQ(next_dl_slice->id(), ran_slice_id_t{0}); |
| 93 | + ASSERT_TRUE(next_dl_slice->is_candidate(to_du_ue_index(0))); |
| 94 | + ASSERT_TRUE(next_dl_slice->is_candidate(to_du_ue_index(0), lcid_t::LCID_SRB1)); |
| 95 | + |
| 96 | + auto next_ul_slice = slice_sched.get_next_ul_candidate(); |
| 97 | + ASSERT_TRUE(next_ul_slice.has_value()); |
| 98 | + ASSERT_EQ(next_ul_slice->id(), ran_slice_id_t{0}); |
| 99 | + ASSERT_TRUE(next_ul_slice->is_candidate(to_du_ue_index(0))); |
| 100 | + ASSERT_TRUE(next_ul_slice->is_candidate(to_du_ue_index(0), lcid_t::LCID_SRB1)); |
| 101 | +} |
| 102 | + |
| 103 | +TEST_F(default_slice_scheduler_test, |
| 104 | + when_candidate_instance_goes_out_of_scope_then_it_stops_being_a_candidate_for_the_same_slot) |
| 105 | +{ |
| 106 | + this->add_ue(to_du_ue_index(0)); |
| 107 | + slice_sched.slot_indication(); |
| 108 | + |
| 109 | + auto next_dl_slice = slice_sched.get_next_dl_candidate(); |
| 110 | + ASSERT_TRUE(next_dl_slice.has_value()); |
| 111 | + ASSERT_EQ(next_dl_slice->id(), ran_slice_id_t{0}); |
| 112 | + |
| 113 | + next_dl_slice = slice_sched.get_next_dl_candidate(); |
| 114 | + ASSERT_FALSE(next_dl_slice.has_value()); |
| 115 | +} |
| 116 | + |
| 117 | +TEST_F(default_slice_scheduler_test, when_candidate_instance_goes_out_of_scope_then_it_can_be_a_candidate_for_next_slot) |
| 118 | +{ |
| 119 | + this->add_ue(to_du_ue_index(0)); |
| 120 | + |
| 121 | + slice_sched.slot_indication(); |
| 122 | + auto next_dl_slice = slice_sched.get_next_dl_candidate(); |
| 123 | + ASSERT_TRUE(next_dl_slice.has_value()); |
| 124 | + |
| 125 | + slice_sched.slot_indication(); |
| 126 | + next_dl_slice = slice_sched.get_next_dl_candidate(); |
| 127 | + ASSERT_TRUE(next_dl_slice.has_value()); |
| 128 | + ASSERT_EQ(next_dl_slice->id(), ran_slice_id_t{0}); |
| 129 | +} |
0 commit comments