From e3b95de5e0d8ffc427afd9a84a950fa89c8a7157 Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Thu, 27 Jan 2022 11:43:43 +0100 Subject: [PATCH] ue,metrics_test: add testcases for EUTRA,NSA, and SA mode --- srsue/src/test/metrics_test.cc | 124 +++++++++++++++++++++++++++------ 1 file changed, 104 insertions(+), 20 deletions(-) diff --git a/srsue/src/test/metrics_test.cc b/srsue/src/test/metrics_test.cc index d1d9bc1be..b68b4d341 100644 --- a/srsue/src/test/metrics_test.cc +++ b/srsue/src/test/metrics_test.cc @@ -11,7 +11,7 @@ */ #include "srsran/common/metrics_hub.h" -#include "srsran/srsran.h" +#include "srsran/common/test_common.h" #include "srsue/hdr/metrics_csv.h" #include "srsue/hdr/metrics_stdout.h" #include "srsue/hdr/ue_metrics_interface.h" @@ -25,10 +25,12 @@ using namespace srsue; namespace srsue { -char* csv_file_name = NULL; +static char* csv_file_name = NULL; +static float period = 1.0; +static int duration_s = 5; // fake classes -class ue_dummy : public ue_metrics_interface +class eutra_ue_dummy : public ue_metrics_interface { public: bool get_metrics(ue_metrics_t* m) @@ -63,6 +65,51 @@ public: m->phy.nof_active_cc = 1; m->phy.ch[0].rsrp = -10.0f; m->phy.ch[0].pathloss = 32; + + m->stack.rrc.state = (rand() % 2 == 0) ? RRC_STATE_CONNECTED : RRC_STATE_IDLE; + + return true; + } +}; + +class nsa_ue_dummy : public ue_metrics_interface +{ +public: + bool get_metrics(ue_metrics_t* m) + { + *m = {}; + + // fill dummy values + m->rf.rf_o = 10; + m->phy.nof_active_cc = 1; + m->phy.ch[0].rsrp = -10.0f; + m->phy.ch[0].pathloss = 74; + m->stack.mac[0].rx_pkts = 100; + m->stack.mac[0].rx_errors = 0; + m->stack.mac[0].rx_brate = 200; + m->stack.mac[0].nof_tti = 1; + + m->phy.info[1].pci = UINT32_MAX; + m->stack.mac[1].rx_pkts = 100; + m->stack.mac[1].rx_errors = 100; + m->stack.mac[1].rx_brate = 150; + m->stack.mac[1].nof_tti = 1; + + // random neighbour cells + if (rand() % 2 == 0) { + phy_meas_t neighbor = {}; + neighbor.pci = 8; + neighbor.rsrp = -33; + m->stack.rrc.neighbour_cells.push_back(neighbor); + m->stack.rrc.neighbour_cells.push_back(neighbor); // need to add twice since we use CA + } + + m->phy.nof_active_cc = 1; + m->phy.ch[0].rsrp = -10.0f; + m->phy.ch[0].pathloss = 32; + + // NR + m->phy_nr.nof_active_cc = 1; m->stack.mac_nr[0].rx_pkts = 100; m->stack.mac_nr[0].rx_errors = 2; m->stack.mac_nr[0].rx_brate = 223; @@ -74,6 +121,31 @@ public: } }; +class sa_ue_dummy : public ue_metrics_interface +{ +public: + bool get_metrics(ue_metrics_t* m) + { + *m = {}; + + // fill dummy values + m->rf.rf_o = 10; + m->phy.nof_active_cc = 0; + + // NR + m->phy_nr.nof_active_cc = 1; + m->phy_nr.info[0].pci = 501; + m->stack.mac_nr[0].rx_pkts = 100; + m->stack.mac_nr[0].rx_errors = 2; + m->stack.mac_nr[0].rx_brate = 223; + m->stack.mac_nr[0].nof_tti = 1; + + m->stack.rrc_nr.state = (rand() % 2 == 0) ? RRC_NR_STATE_CONNECTED : RRC_NR_STATE_IDLE; + + return true; + } +}; + } // namespace srsue void usage(char* prog) @@ -101,38 +173,50 @@ void parse_args(int argc, char** argv) } } -int main(int argc, char** argv) +int ue_test(std::string name, ue_metrics_interface* ue) { - float period = 1.0; - ue_dummy ue; - - if (argc < 3) { - usage(argv[0]); - exit(-1); - } - - parse_args(argc, argv); - // the default metrics type for stdout output metrics_stdout metrics_screen; - metrics_screen.set_ue_handle(&ue); + metrics_screen.set_ue_handle(ue); // the CSV file writer metrics_csv metrics_file(csv_file_name); - metrics_file.set_ue_handle(&ue); + metrics_file.set_ue_handle(ue); // create metrics hub and register metrics for stdout srsran::metrics_hub metricshub; - metricshub.init(&ue, period); + metricshub.init(ue, period); metricshub.add_listener(&metrics_screen); metricshub.add_listener(&metrics_file); // enable printing metrics_screen.toggle_print(true); - std::cout << "Running for 5 seconds .." << std::endl; - usleep(5e6); + std::cout << "Running " << name << " UE test for " << duration_s << " seconds .." << std::endl; + usleep(duration_s * 1e6); metricshub.stop(); - return 0; + + return SRSRAN_SUCCESS; +} + +int main(int argc, char** argv) +{ + if (argc < 3) { + usage(argv[0]); + exit(-1); + } + + parse_args(argc, argv); + + eutra_ue_dummy eutra_ue; + TESTASSERT_SUCCESS(ue_test("EUTRA", &eutra_ue)); + + nsa_ue_dummy nsa_ue; + TESTASSERT_SUCCESS(ue_test("NSA", &nsa_ue)); + + sa_ue_dummy sa_ue; + TESTASSERT_SUCCESS(ue_test("SA", &sa_ue)); + + return SRSRAN_SUCCESS; }