@@ -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{
8181protected:
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
148156TEST_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+ }
0 commit comments