Skip to content

Commit b4fe35b

Browse files
committed
mac: unit test for MAC metric aggregator testing HFN wrap-around
1 parent 39bf2e3 commit b4fe35b

File tree

2 files changed

+56
-4
lines changed

2 files changed

+56
-4
lines changed

tests/unittests/mac/mac_metrics_test.cpp

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ struct dummy_sched_metric_handler {
7676
zero_copy_notifier<scheduler_cell_metrics>::builder builder;
7777
};
7878

79-
class mac_metric_handler_test : public ::testing::Test
79+
class base_mac_metrics_test
8080
{
8181
protected:
8282
struct cell_context {
@@ -95,7 +95,12 @@ class mac_metric_handler_test : public ::testing::Test
9595
}
9696
};
9797

98-
const std::chrono::milliseconds period{10};
98+
base_mac_metrics_test(std::chrono::milliseconds period_ = std::chrono::milliseconds{10}, unsigned start_hfn = 0) :
99+
period(period_), timer_ctrl(timers, start_hfn)
100+
{
101+
}
102+
103+
const std::chrono::milliseconds period;
99104
const subcarrier_spacing scs = subcarrier_spacing::kHz15;
100105
const unsigned period_slots{static_cast<unsigned>(period.count() * get_nof_slots_per_subframe(scs))};
101106
unsigned aggr_timeout_slots = mac_metrics_aggregator::aggregation_timeout.count() * get_nof_slots_per_subframe(scs);
@@ -143,6 +148,9 @@ class mac_metric_handler_test : public ::testing::Test
143148
}
144149
};
145150

151+
class mac_metric_handler_test : public base_mac_metrics_test, public ::testing::Test
152+
{};
153+
146154
} // namespace
147155

148156
TEST_F(mac_metric_handler_test, cell_created_successfully)
@@ -290,3 +298,44 @@ TEST_F(mac_metric_handler_test, when_one_cell_gets_removed_then_last_report_stil
290298
ASSERT_EQ(rep_cells[0].nof_slots, count_until_cell_rem);
291299
ASSERT_EQ(rep_cells[1].nof_slots, period_slots);
292300
}
301+
302+
class mac_metric_handler_hfn_wrap_around_test : public base_mac_metrics_test, public ::testing::Test
303+
{
304+
protected:
305+
mac_metric_handler_hfn_wrap_around_test() : base_mac_metrics_test(std::chrono::milliseconds{100}, 1021) {}
306+
};
307+
308+
TEST_F(mac_metric_handler_hfn_wrap_around_test, when_hfn_is_wrapped_around_metrics_are_still_reported_correctly)
309+
{
310+
add_cell(to_du_cell_index(0));
311+
312+
// Retrieve first report.
313+
unsigned wait_slots = period_slots + aggr_timeout_slots;
314+
for (unsigned i = 0; i != wait_slots; ++i) {
315+
run_slot();
316+
if (metric_notifier.last_report.has_value()) {
317+
break;
318+
}
319+
}
320+
ASSERT_TRUE(metric_notifier.last_report.has_value());
321+
slot_point next_report_slot = metric_notifier.last_report.value().sched.cells[0].slot +
322+
metric_notifier.last_report.value().sched.cells[0].nof_slots;
323+
metric_notifier.last_report.reset();
324+
325+
// Check if report is generated at the right slot even after HFN wrap-around.
326+
const unsigned max_slots = next_report_slot.nof_slots_per_hyper_system_frame() * 3;
327+
unsigned nof_reports = 0;
328+
for (unsigned i = 0; i != max_slots; ++i) {
329+
run_slot();
330+
if (metric_notifier.last_report.has_value()) {
331+
auto report_slot = metric_notifier.last_report.value().sched.cells[0].slot;
332+
ASSERT_EQ(report_slot, next_report_slot)
333+
<< fmt::format("Expected slot={} but got {}", next_report_slot, report_slot);
334+
next_report_slot += period_slots;
335+
metric_notifier.last_report.reset();
336+
nof_reports++;
337+
}
338+
}
339+
// Just a simple assurance that the reports never stopped flowing.
340+
ASSERT_GE(nof_reports, max_slots / period_slots);
341+
}

tests/unittests/mac/mac_test_helpers.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ class dummy_mac_clock_controller : public mac_clock_controller
209209
if (not parent.active_cells[cell_index]) {
210210
parent.active_cells[cell_index] = true;
211211
if (parent.nof_active_cells == 0) {
212-
parent.master_slot = slot_point_extended{sl_tx - 1, 0};
212+
parent.master_slot = slot_point_extended{sl_tx - 1, parent.start_hfn};
213213
}
214214
parent.nof_active_cells++;
215215
}
@@ -246,7 +246,9 @@ class dummy_mac_clock_controller : public mac_clock_controller
246246
du_cell_index_t cell_index;
247247
};
248248

249-
dummy_mac_clock_controller(timer_manager& timers_) : timers(timers_) {}
249+
dummy_mac_clock_controller(timer_manager& timers_, unsigned start_hfn_ = 0) : timers(timers_), start_hfn(start_hfn_)
250+
{
251+
}
250252

251253
std::unique_ptr<mac_cell_clock_controller> add_cell(du_cell_index_t cell_index) override
252254
{
@@ -257,6 +259,7 @@ class dummy_mac_clock_controller : public mac_clock_controller
257259

258260
private:
259261
timer_manager& timers;
262+
const unsigned start_hfn;
260263

261264
unsigned nof_active_cells = 0;
262265
slot_point_extended master_slot;

0 commit comments

Comments
 (0)