sched,nr: fix sched RAR NR test; update test assert macros

master
Francisco Paisana 3 years ago
parent 8f00c9363c
commit da4b7e4f80

@ -157,7 +157,7 @@ struct formatter<srsran::slot_point> {
template <typename FormatContext>
auto format(srsran::slot_point slot, FormatContext& ctx) -> decltype(std::declval<FormatContext>().out())
{
return format_to(ctx.out(), "{}/{}", slot.sfn(), slot.slot_idx());
return format_to(ctx.out(), "{}:{}", slot.sfn(), slot.slot_idx());
}
};
} // namespace fmt

@ -17,31 +17,15 @@
#include "srsran_assert.h"
namespace srsran {
namespace detail {
template <typename T, typename U>
[[gnu::noinline, noreturn]] void assert_eq_failure(const T& expected_val, const U& actual_val)
{
std::string s = fmt::format("Actual value '{}' differs from expected '{}'", actual_val, expected_val);
srsran_assertion_failure("%s", s.c_str());
}
template <typename T>
[[gnu::noinline, noreturn]] void assert_neq_failure(const T& actual_val)
{
std::string s = fmt::format("Value should not be equal to '{}'", actual_val);
srsran_assertion_failure("%s", s.c_str());
}
} // namespace detail
} // namespace srsran
#define TESTASSERT_EQ(EXPECTED, ACTUAL) \
(void)((EXPECTED == ACTUAL) || (::srsran::detail::assert_eq_failure(EXPECTED, ACTUAL), 0))
(void)((EXPECTED == ACTUAL) || \
(srsran_assertion_failure( \
"%s", fmt::format("Actual value '{}' differs from expected '{}'", ACTUAL, EXPECTED).c_str()), \
0))
#define TESTASSERT_NEQ(EXPECTED, ACTUAL) \
(void)((EXPECTED != ACTUAL) || (::srsran::detail::assert_neq_failure(ACTUAL), 0))
(void)((EXPECTED != ACTUAL) || \
(srsran_assertion_failure("%s", fmt::format("Value should not be equal to '{}'", ACTUAL).c_str()), 0))
#define TESTASSERT(cond) srsran_assert((cond), "Fail at \"%s\"", (#cond))
@ -54,7 +38,7 @@ template <typename T>
#define TESTASSERT(cond) \
do { \
if (!(cond)) { \
printf("[%s][Line %d] Fail at \"%s\"\n", __FUNCTION__, __LINE__, (#cond)); \
fprintf(stderr, "%s:%d: Assertion Failure: \"%s\"\n", __FUNCTION__, __LINE__, (#cond)); \
return -1; \
} \
} while (0)

@ -100,6 +100,7 @@ public:
slot_point get_pdcch_tti() const { return pdcch_slot; }
slot_point get_tti_rx() const { return pdcch_slot - TX_ENB_DELAY; }
const bwp_res_grid& res_grid() const { return bwp_grid; }
void log_bwp_sched_result();
const bwp_params& cfg;

@ -14,12 +14,14 @@
#define SRSRAN_SCHED_NR_HELPERS_H
#include "sched_nr_cfg.h"
#include "sched_nr_ue.h"
namespace srsenb {
namespace sched_nr_impl {
class slot_ue;
class ul_harq_proc;
struct bwp_res_grid;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -41,6 +43,11 @@ void fill_ul_dci_ue_fields(const slot_ue& ue,
srsran_dci_location_t dci_pos,
srsran_dci_ul_nr_t& dci);
void log_sched_bwp_result(srslog::basic_logger& logger,
slot_point pdcch_slot,
const bwp_res_grid& res_grid,
const slot_ue_map_t& slot_ues);
} // namespace sched_nr_impl
} // namespace srsenb

@ -54,7 +54,7 @@ public:
srsran_pdcch_cfg_nr_t pdcch = {};
srsran_sch_hl_cfg_nr_t pdsch = {};
srsran_sch_hl_cfg_nr_t pusch = {};
uint32_t rar_window_size = 8;
uint32_t rar_window_size = 10; // See TS 38.331, ra-ResponseWindow: {1, 2, 4, 8, 10, 20, 40, 80}
uint32_t numerology_idx = 0;
};

@ -341,5 +341,10 @@ alloc_result bwp_slot_allocator::verify_pusch_space(bwp_slot_grid& pusch_grid, b
return alloc_result::success;
}
void bwp_slot_allocator::log_bwp_sched_result()
{
log_sched_bwp_result(logger, get_pdcch_tti(), bwp_grid, *slot_ues);
}
} // namespace sched_nr_impl
} // namespace srsenb
} // namespace srsenb

@ -11,8 +11,10 @@
*/
#include "srsenb/hdr/stack/mac/nr/sched_nr_helpers.h"
#include "srsenb/hdr/stack/mac/nr/sched_nr_grant_allocator.h"
#include "srsenb/hdr/stack/mac/nr/sched_nr_harq.h"
#include "srsenb/hdr/stack/mac/nr/sched_nr_ue.h"
#include "srsran/common/string_helpers.h"
namespace srsenb {
namespace sched_nr_impl {
@ -110,5 +112,73 @@ void fill_ul_dci_ue_fields(const slot_ue& ue,
fill_dci_common(ue, bwp_cfg, dci);
}
void log_sched_bwp_result(srslog::basic_logger& logger,
slot_point pdcch_slot,
const bwp_res_grid& res_grid,
const slot_ue_map_t& slot_ues)
{
const bwp_slot_grid& bwp_slot = res_grid[pdcch_slot];
for (const pdcch_dl_t& pdcch : bwp_slot.dl_pdcchs) {
fmt::memory_buffer fmtbuf;
if (pdcch.dci.ctx.rnti_type == srsran_rnti_type_c) {
const slot_ue& ue = slot_ues[pdcch.dci.ctx.rnti];
fmt::format_to(
fmtbuf,
"SCHED: DL {}, cc={}, rnti=0x{:x}, pid={}, f={}, nrtx={}, dai={}, tbs={}, pdsch_slot={}, tti_ack={}",
ue.h_dl->nof_retx() == 0 ? "tx" : "retx",
res_grid.cfg->cc,
ue.rnti,
pdcch.dci.pid,
srsran_dci_format_nr_string(pdcch.dci.ctx.format),
ue.h_dl->nof_retx(),
pdcch.dci.dai,
ue.h_dl->tbs(),
ue.pdsch_slot,
ue.uci_slot);
} else if (pdcch.dci.ctx.rnti_type == srsran_rnti_type_ra) {
fmt::format_to(fmtbuf,
"SCHED: DL RAR, cc={}, ra-rnti=0x{:x}, pdsch_slot={}, msg3_slot={}",
res_grid.cfg->cc,
pdcch.dci.ctx.rnti,
pdcch_slot,
pdcch_slot + res_grid.cfg->pusch_ra_list[0].msg3_delay);
} else {
fmt::format_to(fmtbuf, "SCHED: unknown format");
}
logger.info("%s", srsran::to_c_str(fmtbuf));
}
for (const pdcch_ul_t& pdcch : bwp_slot.ul_pdcchs) {
fmt::memory_buffer fmtbuf;
if (pdcch.dci.ctx.rnti_type == srsran_rnti_type_c) {
const slot_ue& ue = slot_ues[pdcch.dci.ctx.rnti];
fmt::format_to(fmtbuf,
"SCHED: UL {}, cc={}, rnti=0x{:x}, pid={}, f={}, nrtx={}, tbs={}, tti_pusch={}",
ue.h_dl->nof_retx() == 0 ? "tx" : "retx",
res_grid.cfg->cc,
ue.rnti,
pdcch.dci.pid,
srsran_dci_format_nr_string(pdcch.dci.ctx.format),
ue.h_dl->nof_retx(),
ue.h_ul->tbs(),
ue.pusch_slot);
} else if (pdcch.dci.ctx.rnti_type == srsran_rnti_type_tc) {
const slot_ue& ue = slot_ues[pdcch.dci.ctx.rnti];
fmt::format_to(fmtbuf,
"SCHED: UL Msg3, cc={}, tc-rnti=0x{:x}, pid={}, nrtx={}, f={}, tti_pusch={}",
res_grid.cfg->cc,
ue.rnti,
pdcch.dci.pid,
ue.h_dl->nof_retx(),
srsran_dci_format_nr_string(pdcch.dci.ctx.format),
ue.pusch_slot);
} else {
fmt::format_to(fmtbuf, "SCHED: unknown rnti format");
}
logger.info("%s", srsran::to_c_str(fmtbuf));
}
}
} // namespace sched_nr_impl
} // namespace srsenb

@ -101,7 +101,7 @@ void slot_cc_worker::run()
alloc_ul_ues();
// Log CC scheduler result
log_result();
bwp_alloc.log_bwp_sched_result();
// releases UE resources
slot_ues.clear();

@ -17,6 +17,9 @@
#include "srsran/support/srsran_test.h"
#include <random>
uint32_t seed = 155556739;
// std::chrono::system_clock::now().time_since_epoch().count();
namespace srsenb {
void test_single_prach()
@ -24,20 +27,20 @@ void test_single_prach()
using namespace sched_nr_impl;
const uint16_t rnti = 0x1234;
static srslog::basic_logger& mac_logger = srslog::fetch_basic_logger("MAC");
std::random_device r;
std::default_random_engine rgen(r());
std::default_random_engine rand_gen(seed);
std::default_random_engine rgen(rand_gen());
sched_nr_interface::sched_cfg_t sched_cfg{};
std::vector<sched_nr_interface::cell_cfg_t> cells_cfg = get_default_cells_cfg(1);
sched_params schedparams{sched_cfg};
schedparams.cells.emplace_back(0, cells_cfg[0], sched_cfg);
bwp_params bwp_cfg(cells_cfg[0], sched_cfg, 0, 0);
slot_ue_map_t slot_ues;
const bwp_params& bwpparams = schedparams.cells[0].bwps[0];
slot_ue_map_t slot_ues;
ra_sched rasched(bwp_cfg);
ra_sched rasched(bwpparams);
TESTASSERT(rasched.empty());
std::unique_ptr<bwp_res_grid> res_grid(new bwp_res_grid{bwp_cfg});
std::unique_ptr<bwp_res_grid> res_grid(new bwp_res_grid{bwpparams});
bwp_slot_allocator alloc(*res_grid);
// Create UE
@ -54,6 +57,8 @@ void test_single_prach()
slot_ues.insert(rnti, u.try_reserve(pdcch_slot, 0));
alloc.new_slot(pdcch_slot, slot_ues);
rasched.run_slot(alloc);
alloc.log_bwp_sched_result();
const bwp_slot_grid* result = &alloc.res_grid()[alloc.get_pdcch_tti()];
test_pdcch_consistency(result->dl_pdcchs);
++pdcch_slot;
@ -77,14 +82,17 @@ void test_single_prach()
uint16_t ra_rnti = 1 + rainfo.ofdm_symbol_idx + 14 * rainfo.prach_slot.slot_idx() + 14 * 80 * rainfo.freq_idx;
// RAR is scheduled
const uint32_t prach_duration = 1;
while (true) {
result = run_slot();
if (result->is_dl()) {
TESTASSERT(result->dl_pdcchs.size() == 1);
slot_point current_slot = pdcch_slot;
result = run_slot();
if (bwpparams.slots[current_slot.slot_idx()].is_dl and
bwpparams.slots[(current_slot + bwpparams.pusch_ra_list[0].msg3_delay).slot_idx()].is_ul) {
TESTASSERT_EQ(result->dl_pdcchs.size(), 1);
const auto& pdcch = result->dl_pdcchs[0];
TESTASSERT_EQ(pdcch.dci.ctx.rnti, ra_rnti);
TESTASSERT_EQ(pdcch.dci.ctx.rnti_type, srsran_rnti_type_ra);
TESTASSERT(pdcch_slot < prach_slot + bwp_cfg.cell_cfg.bwps[0].rar_window_size);
TESTASSERT(current_slot < prach_slot + prach_duration + bwpparams.cfg.rar_window_size);
break;
} else {
TESTASSERT(result->dl_pdcchs.empty());
@ -103,5 +111,7 @@ int main(int argc, char** argv)
srsran::test_init(argc, argv);
printf("Test seed=%u\n", seed);
srsenb::test_single_prach();
}

Loading…
Cancel
Save