|
| 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 | +/// \file |
| 12 | +/// \brief Unit test for scheduler using different TDD patterns. |
| 13 | + |
| 14 | +#include "test_utils/config_generators.h" |
| 15 | +#include "test_utils/indication_generators.h" |
| 16 | +#include "test_utils/result_test_helpers.h" |
| 17 | +#include "test_utils/scheduler_test_bench.h" |
| 18 | +#include <gtest/gtest.h> |
| 19 | + |
| 20 | +using namespace srsran; |
| 21 | + |
| 22 | +class base_scheduler_tdd_tester : public scheduler_test_bench |
| 23 | +{ |
| 24 | +protected: |
| 25 | + base_scheduler_tdd_tester( |
| 26 | + const tdd_ul_dl_config_common& tdd_cfg = config_helpers::make_default_tdd_ul_dl_config_common()) : |
| 27 | + scheduler_test_bench(4, tdd_cfg.ref_scs) |
| 28 | + { |
| 29 | + // Add Cell. |
| 30 | + this->add_cell([this, &tdd_cfg]() { |
| 31 | + params.scs_common = tdd_cfg.ref_scs; |
| 32 | + params.dl_arfcn = 520002; |
| 33 | + params.band = nr_band::n41; |
| 34 | + params.channel_bw_mhz = bs_channel_bandwidth_fr1::MHz20; |
| 35 | + const unsigned nof_crbs = band_helper::get_n_rbs_from_bw( |
| 36 | + params.channel_bw_mhz, params.scs_common, band_helper::get_freq_range(*params.band)); |
| 37 | + static const uint8_t ss0_idx = 0; |
| 38 | + optional<band_helper::ssb_coreset0_freq_location> ssb_freq_loc = band_helper::get_ssb_coreset0_freq_location( |
| 39 | + params.dl_arfcn, *params.band, nof_crbs, params.scs_common, params.scs_common, ss0_idx); |
| 40 | + if (!ssb_freq_loc.has_value()) { |
| 41 | + report_error("Unable to derive a valid SSB pointA and k_SSB for cell id ({}).\n", params.pci); |
| 42 | + } |
| 43 | + params.offset_to_point_a = (*ssb_freq_loc).offset_to_point_A; |
| 44 | + params.k_ssb = (*ssb_freq_loc).k_ssb; |
| 45 | + params.coreset0_index = (*ssb_freq_loc).coreset0_idx; |
| 46 | + |
| 47 | + sched_cell_configuration_request_message sched_cfg = |
| 48 | + test_helpers::make_default_sched_cell_configuration_request(params); |
| 49 | + // TDD params. |
| 50 | + sched_cfg.tdd_ul_dl_cfg_common = tdd_cfg; |
| 51 | + |
| 52 | + return sched_cfg; |
| 53 | + }()); |
| 54 | + |
| 55 | + // Add UE |
| 56 | + auto ue_cfg = test_helpers::create_default_sched_ue_creation_request(params, {ue_drb_lcid}); |
| 57 | + ue_cfg.ue_index = ue_idx; |
| 58 | + ue_cfg.crnti = ue_rnti; |
| 59 | + this->add_ue(ue_cfg); |
| 60 | + } |
| 61 | + |
| 62 | + const du_ue_index_t ue_idx = to_du_ue_index(0); |
| 63 | + const rnti_t ue_rnti = to_rnti(0x4601); |
| 64 | + const lcid_t ue_drb_lcid = LCID_MIN_DRB; |
| 65 | + |
| 66 | + cell_config_builder_params params; |
| 67 | +}; |
| 68 | + |
| 69 | +using test_params = tdd_ul_dl_config_common; |
| 70 | + |
| 71 | +class scheduler_tdd_tester : public base_scheduler_tdd_tester, public ::testing::TestWithParam<test_params> |
| 72 | +{ |
| 73 | +public: |
| 74 | + scheduler_tdd_tester() : base_scheduler_tdd_tester(GetParam()) {} |
| 75 | +}; |
| 76 | + |
| 77 | +TEST_P(scheduler_tdd_tester, all_dl_slots_are_scheduled) |
| 78 | +{ |
| 79 | + // Enqueue enough bytes for continuous DL tx. |
| 80 | + dl_buffer_state_indication_message dl_buf_st{ue_idx, ue_drb_lcid, 10000000}; |
| 81 | + this->push_dl_buffer_state(dl_buf_st); |
| 82 | + |
| 83 | + const unsigned MAX_COUNT = 1000; |
| 84 | + for (unsigned count = 0; count != MAX_COUNT; ++count) { |
| 85 | + this->run_slot(); |
| 86 | + ASSERT_TRUE(this->last_sched_res->success); |
| 87 | + |
| 88 | + // For every DL slot. |
| 89 | + // Note: Skip special slots in test for now. |
| 90 | + if (cell_cfg_list[0].is_fully_dl_enabled(this->last_result_slot())) { |
| 91 | + // Ensure UE PDSCH allocations are made. |
| 92 | + ASSERT_FALSE(this->last_sched_res->dl.ue_grants.empty()) |
| 93 | + << "The UE configuration is leading to some DL slots staying empty"; |
| 94 | + } |
| 95 | + |
| 96 | + for (const pucch_info& pucch : this->last_sched_res->ul.pucchs) { |
| 97 | + if (pucch.format == pucch_format::FORMAT_1 and pucch.format_1.sr_bits != sr_nof_bits::no_sr) { |
| 98 | + // Skip SRs for this test. |
| 99 | + continue; |
| 100 | + } |
| 101 | + |
| 102 | + uci_indication uci_ind = create_uci_indication(this->last_result_slot(), ue_idx, pucch); |
| 103 | + this->sched->handle_uci_indication(uci_ind); |
| 104 | + } |
| 105 | + } |
| 106 | +} |
| 107 | + |
| 108 | +TEST_P(scheduler_tdd_tester, all_ul_slots_are_scheduled) |
| 109 | +{ |
| 110 | + // Enqueue enough bytes for continuous UL tx. |
| 111 | + ul_bsr_indication_message bsr{ |
| 112 | + to_du_cell_index(0), ue_idx, ue_rnti, bsr_format::SHORT_BSR, {ul_bsr_lcg_report{uint_to_lcg_id(0), 10000000}}}; |
| 113 | + this->push_bsr(bsr); |
| 114 | + |
| 115 | + // Run some slots to ensure PDCCH can be scheduled. |
| 116 | + for (unsigned i = 0; i != cell_cfg_list[0].tdd_cfg_common->pattern1.nof_ul_symbols; ++i) { |
| 117 | + run_slot(); |
| 118 | + } |
| 119 | + |
| 120 | + const unsigned MAX_COUNT = 1000; |
| 121 | + for (unsigned count = 0; count != MAX_COUNT; ++count) { |
| 122 | + this->run_slot(); |
| 123 | + ASSERT_TRUE(this->last_sched_res->success); |
| 124 | + |
| 125 | + // For every UL slot. |
| 126 | + // Note: Skip special slots in test for now. |
| 127 | + if (cell_cfg_list[0].is_fully_ul_enabled(this->last_result_slot())) { |
| 128 | + // Ensure UE PUSCH allocations are made. |
| 129 | + ASSERT_FALSE(this->last_sched_res->ul.puschs.empty()) |
| 130 | + << "The UE configuration is leading to some UL slots staying empty"; |
| 131 | + } |
| 132 | + |
| 133 | + for (const ul_sched_info& pusch : this->last_sched_res->ul.puschs) { |
| 134 | + ul_crc_indication crc{}; |
| 135 | + crc.cell_index = to_du_cell_index(0); |
| 136 | + crc.sl_rx = this->last_result_slot(); |
| 137 | + crc.crcs.resize(1); |
| 138 | + crc.crcs[0].ue_index = ue_idx; |
| 139 | + crc.crcs[0].rnti = ue_rnti; |
| 140 | + crc.crcs[0].harq_id = to_harq_id(pusch.pusch_cfg.harq_id); |
| 141 | + crc.crcs[0].tb_crc_success = true; |
| 142 | + this->sched->handle_crc_indication(crc); |
| 143 | + } |
| 144 | + } |
| 145 | +} |
| 146 | + |
| 147 | +INSTANTIATE_TEST_SUITE_P( |
| 148 | + scheduler_tdd_test, |
| 149 | + scheduler_tdd_tester, |
| 150 | + testing::Values( |
| 151 | + // clang-format off |
| 152 | + // test_params{ref_scs, pattern1={slot_period, DL_slots, DL_symbols, UL_slots, UL_symbols}, pattern2={...}} |
| 153 | + test_params{subcarrier_spacing::kHz30, {10, 6, 4, 3, 4}, nullopt})); |
| 154 | + // Note: Not working because some PDSCHs fail due to insufficient PUCCH resources. |
| 155 | + //test_params{subcarrier_spacing::kHz30, {10, 7, 4, 2, 4}, nullopt}, |
| 156 | + // Note: Not working because PRACH configuration needs to be adjusted. |
| 157 | + //test_params{subcarrier_spacing::kHz30, {6, 3, 4, 2, 4}, tdd_ul_dl_pattern{4, 4, 0, 0, 0}})); |
| 158 | +// clang-format on |
0 commit comments