diff --git a/lib/include/srslte/common/logmap.h b/lib/include/srslte/common/logmap.h index 7aaa6d2b3..601ed9f5b 100644 --- a/lib/include/srslte/common/logmap.h +++ b/lib/include/srslte/common/logmap.h @@ -78,13 +78,21 @@ public: void register_log(std::unique_ptr log_ptr) { std::lock_guard lock(mutex); - log_map[log_ptr->get_service_name()] = std::move(log_ptr); + if (log_ptr != nullptr) { + log_map[log_ptr->get_service_name()] = std::move(log_ptr); + } } - bool deregister_log(const std::string& servicename) + std::unique_ptr deregister_log(const std::string& servicename) { - std::lock_guard lock(mutex); - return log_map.erase(servicename) > 0; + std::unique_ptr ret; + std::lock_guard lock(mutex); + auto it = log_map.find(servicename); + if (it != log_map.end()) { + ret = std::move(it->second); + log_map.erase(it); + } + return ret; } protected: diff --git a/lib/include/srslte/common/test_common.h b/lib/include/srslte/common/test_common.h index a976d9a99..5b851108c 100644 --- a/lib/include/srslte/common/test_common.h +++ b/lib/include/srslte/common/test_common.h @@ -28,46 +28,26 @@ #include "srslte/common/log.h" #include "srslte/common/log_filter.h" +#include "srslte/common/logmap.h" #include namespace srslte { -class test_log_singleton -{ -public: - static srslte::log* get_log() { return get_instance()->current_log; } - - static test_log_singleton* get_instance() - { - static test_log_singleton* inst = new test_log_singleton{}; - return inst; - } - - void register_log(srslte::log* log_) { current_log = log_; } - -private: - test_log_singleton() = default; - - srslte::log* current_log = nullptr; -}; - -// logger that we can instantiate in a specific test scope +// Description: log filter that we can instantiate in a specific test scope, and cleans itself on scope exit // useful if we want to define specific logging policies within a scope (e.g. null logger, count number of errors, // exit on error, log special diagnostics on destruction). It restores the previous logger after exiting the scope -class scoped_tester_log : public srslte::log_filter +class test_log_filter : public srslte::log_filter { public: - explicit scoped_tester_log(std::string layer) : srslte::log_filter(layer) + explicit test_log_filter(std::string layer) : srslte::log_filter(std::move(layer)) { - previous_log_test = test_log_singleton::get_log(); - test_log_singleton::get_instance()->register_log(this); set_level(srslte::LOG_LEVEL_DEBUG); } - scoped_tester_log(const scoped_tester_log&) = delete; - scoped_tester_log(scoped_tester_log&&) = delete; - scoped_tester_log& operator=(const scoped_tester_log&) = delete; - scoped_tester_log& operator=(scoped_tester_log&&) = delete; - ~scoped_tester_log() override { test_log_singleton::get_instance()->register_log(previous_log_test); } + test_log_filter(const test_log_filter&) = delete; + test_log_filter(test_log_filter&&) = delete; + test_log_filter& operator=(const test_log_filter&) = delete; + test_log_filter& operator=(test_log_filter&&) = delete; + ~test_log_filter() override = default; void error(const char* message, ...) override __attribute__((format(printf, 2, 3))) { @@ -109,16 +89,13 @@ public: bool exit_on_error = false; uint32_t error_counter = 0, warn_counter = 0; - -private: - srslte::log* previous_log_test = nullptr; }; -// specialization of scoped_tester_log to store last logged message -class nullsink_log : public scoped_tester_log +// specialization of test_log_filter to store last logged message +class nullsink_log : public test_log_filter { public: - explicit nullsink_log(std::string layer) : scoped_tester_log(std::move(layer)) {} + explicit nullsink_log(std::string layer) : test_log_filter(std::move(layer)) {} void debug(const char* message, ...) override __attribute__((format(printf, 2, 3))) { @@ -173,25 +150,47 @@ private: } }; +template +class scoped_log +{ +public: + template + explicit scoped_log(Args&&... args) + { + std::unique_ptr l{new Log{std::forward(args)...}}; + // store previous log, and register the newly created one + prev_log = srslte::logmap::get_instance()->deregister_log(l->get_service_name()); + current_log = l.get(); + srslte::logmap::get_instance()->register_log(std::move(l)); + } + scoped_log(scoped_log&&) noexcept = default; + ~scoped_log() + { + srslte::logmap::get_instance()->deregister_log(current_log->get_service_name()); + if (prev_log != nullptr) { + srslte::logmap::get_instance()->register_log(std::move(prev_log)); + } + } + + Log* operator->() { return current_log; } + Log* get() { return current_log; } + +private: + Log* current_log = nullptr; + std::unique_ptr prev_log; +}; + } // namespace srslte #define TESTERROR(fmt, ...) \ do { \ - if (srslte::test_log_singleton::get_instance() == nullptr) { \ - printf(fmt, ##__VA_ARGS__); \ - } else { \ - srslte::test_log_singleton::get_log()->error(fmt, ##__VA_ARGS__); \ - } \ + srslte::logmap::get("TEST")->error(fmt, ##__VA_ARGS__); \ return SRSLTE_ERROR; \ } while (0) #define TESTWARN(fmt, ...) \ do { \ - if (srslte::test_log_singleton::get_instance() == nullptr) { \ - printf(fmt, ##__VA_ARGS__); \ - } else { \ - srslte::test_log_singleton::get_log()->warning(fmt, ##__VA_ARGS__); \ - } \ + srslte::logmap::get("TEST")->warning(fmt, ##__VA_ARGS__); \ } while (0) #define CONDERROR(cond, fmt, ...) \ diff --git a/lib/test/asn1/ngap_asn1_test.cc b/lib/test/asn1/ngap_asn1_test.cc index cca7d3f9c..53f0cacb0 100644 --- a/lib/test/asn1/ngap_asn1_test.cc +++ b/lib/test/asn1/ngap_asn1_test.cc @@ -24,9 +24,6 @@ using namespace asn1; using namespace asn1::ngap_nr; -srslte::log_filter asn_logger("ASN"); -srslte::log_filter ngap_log("NGAP"); - /* TESTS */ int test_amf_upd() @@ -348,10 +345,9 @@ int test_session_res_setup_request() int main() { - asn_logger.set_level("DEBUG"); - ngap_log.set_level("DEBUG"); - srsasn_log_register_handler(&asn_logger); - ngap_nr_log_register_handler(&ngap_log); + srslte::logmap::get_instance()->set_default_log_level(LOG_LEVEL_DEBUG); + srsasn_log_register_handler(srslte::logmap::get("ASN1")); + ngap_nr_log_register_handler(srslte::logmap::get("NGAP")); TESTASSERT(test_amf_upd() == 0); TESTASSERT(test_ngsetup_request() == 0); diff --git a/lib/test/asn1/rrc_asn1_test.cc b/lib/test/asn1/rrc_asn1_test.cc index 3e287fbcc..f957a1d16 100644 --- a/lib/test/asn1/rrc_asn1_test.cc +++ b/lib/test/asn1/rrc_asn1_test.cc @@ -25,10 +25,6 @@ using namespace asn1; using namespace asn1::rrc; -srslte::log_filter asn_logger("ASN1"); -srslte::log_filter rrc_logger("RRC"); -srslte::scoped_tester_log test_logger("TEST"); - // TESTS int test_generic() @@ -48,7 +44,7 @@ int test_generic() TESTASSERT(null_log.last_log_msg == test_str); TESTASSERT(null_log.last_log_level == LOG_LEVEL_INFO); // go back to original logger - rrc_log_register_handler(&rrc_logger); + rrc_log_register_handler(srslte::logmap::get("RRC ")); } // Test deep copy of choice types @@ -603,12 +599,9 @@ int test_rrc_conn_reconf_r15_2() int main() { - asn_logger.set_level(LOG_LEVEL_DEBUG); - rrc_logger.set_level(LOG_LEVEL_DEBUG); - test_logger.set_level(LOG_LEVEL_DEBUG); - - srsasn_log_register_handler(&asn_logger); - rrc_log_register_handler(&rrc_logger); + srslte::logmap::get_instance()->set_default_log_level(LOG_LEVEL_DEBUG); + srsasn_log_register_handler(srslte::logmap::get("ASN1")); + rrc_log_register_handler(srslte::logmap::get("RRC ")); TESTASSERT(test_generic() == 0); TESTASSERT(test_json_printer() == 0); diff --git a/lib/test/asn1/s1ap_test.cc b/lib/test/asn1/s1ap_test.cc index 021f43436..65d921b43 100644 --- a/lib/test/asn1/s1ap_test.cc +++ b/lib/test/asn1/s1ap_test.cc @@ -27,8 +27,6 @@ using namespace asn1; -srslte::scoped_tester_log test_logger("TEST"); - int unpack_test_served_gummeis_with_multiple_plmns() { uint8_t pdu[] = {0x20, 0x11, 0x00, 0x26, 0x00, 0x00, 0x02, 0x00, 0x69, 0x00, 0x1a, 0x01, 0x40, 0x00, @@ -85,7 +83,8 @@ int test_initial_ctxt_setup_response() asn1::bit_ref bref(buffer, sizeof(buffer)); TESTASSERT(tx_pdu.pack(bref) == SRSLTE_SUCCESS); - test_logger.info_hex(buffer, bref.distance_bytes(), "message (nof bytes = %d):\n", bref.distance_bytes()); + srslte::logmap::get("TEST")->info_hex( + buffer, bref.distance_bytes(), "message (nof bytes = %d):\n", bref.distance_bytes()); return SRSLTE_SUCCESS; } @@ -127,15 +126,15 @@ int test_eci_pack() TESTASSERT(buffer[1] == 0x19); TESTASSERT(buffer[2] == 0xC0); - test_logger.info_hex(buffer, bref.distance_bytes(), "Packed cell id:\n"); + srslte::logmap::get("TEST")->info_hex(buffer, bref.distance_bytes(), "Packed cell id:\n"); return SRSLTE_SUCCESS; } int main() { - test_logger.set_level(LOG_LEVEL_DEBUG); - test_logger.set_hex_limit(1024); + srslte::logmap::get_instance()->set_default_log_level(LOG_LEVEL_DEBUG); + srslte::logmap::get_instance()->set_default_hex_limit(1024); TESTASSERT(unpack_test_served_gummeis_with_multiple_plmns() == SRSLTE_SUCCESS); TESTASSERT(test_initial_ctxt_setup_response() == SRSLTE_SUCCESS); diff --git a/lib/test/common/test_common_test.cc b/lib/test/common/test_common_test.cc index 799cf5ed9..dd618771a 100644 --- a/lib/test/common/test_common_test.cc +++ b/lib/test/common/test_common_test.cc @@ -21,22 +21,24 @@ #include "srslte/common/test_common.h" +using srslte::nullsink_log; +using srslte::scoped_log; + int test_nullsink_log() { // Description: Test nullsink_log that only stores the last log message in a local std::string that can be checked // This logger is useful to confirm that a certain action produced an expected error/warning, - // without contaminating the console/log file - srslte::nullsink_log null_logger{"TEST"}; - - TESTASSERT(srslte::test_log_singleton::get_log() == &null_logger); + // without contaminating the console/log file, and to check what error message was stored + scoped_log null_log("TEST"); - TESTASSERT(null_logger.error_counter == 0); - TESTASSERT(null_logger.last_log_level == srslte::LOG_LEVEL_NONE); - TESTASSERT(null_logger.last_log_msg.empty()); - null_logger.error("ERROR MESSAGE"); // This message should not be seen in the console - TESTASSERT(null_logger.error_counter == 1); - TESTASSERT(null_logger.last_log_level == srslte::LOG_LEVEL_ERROR); - TESTASSERT(null_logger.last_log_msg == "ERROR MESSAGE"); + TESTASSERT(srslte::logmap::get("TEST") == null_log.get()); + TESTASSERT(null_log->error_counter == 0); + TESTASSERT(null_log->last_log_level == srslte::LOG_LEVEL_NONE); + TESTASSERT(null_log->last_log_msg.empty()); + null_log->error("ERROR MESSAGE"); // This message should not be seen in the console + TESTASSERT(null_log->error_counter == 1); + TESTASSERT(null_log->last_log_level == srslte::LOG_LEVEL_ERROR); + TESTASSERT(null_log->last_log_msg == "ERROR MESSAGE"); return SRSLTE_SUCCESS; } @@ -47,26 +49,27 @@ int test_log_scoping() // on scope exit the previous logger should be recovered // This behavior is useful for the cases we have one generic logger for all tests, but in a specific test // we want to use a different one - srslte::nullsink_log logger1("TEST1"); - TESTASSERT(srslte::test_log_singleton::get_log() == &logger1); + scoped_log log1("TEST"); + TESTASSERT(srslte::logmap::get("TEST") == log1.get()); - logger1.error("message1"); - logger1.error("message2"); - TESTASSERT(logger1.last_log_msg == "message2"); + log1->error("message1"); + log1->error("message2"); + TESTASSERT(log1->last_log_msg == "message2"); + TESTASSERT(log1->error_counter == 2); { // the global test log should be overwriten here, and used by TESTASSERT macro - srslte::nullsink_log logger2("TEST2"); - TESTASSERT(srslte::test_log_singleton::get_log() == &logger2); - TESTASSERT(logger2.error_counter == 0); - logger2.error("error message in logger2\n"); - TESTASSERT(logger2.last_log_msg == "error message in logger2\n"); - TESTASSERT(logger2.error_counter == 1); + scoped_log log2("TEST"); + TESTASSERT(srslte::logmap::get("TEST") == log2.get()); + TESTASSERT(log2->error_counter == 0); + log2->error("error message in logger2\n"); + TESTASSERT(log2->last_log_msg == "error message in logger2\n"); + TESTASSERT(log2->error_counter == 1); } // the last logger should be recovered - TESTASSERT(srslte::test_log_singleton::get_log() == &logger1); - TESTASSERT(logger1.error_counter == 2); + TESTASSERT(srslte::logmap::get("TEST") == log1.get()); + TESTASSERT(log1->error_counter == 2); return 0; } diff --git a/srsenb/test/mac/scheduler_test_rand.cc b/srsenb/test/mac/scheduler_test_rand.cc index 48dfa93f1..1a8a2b0db 100644 --- a/srsenb/test/mac/scheduler_test_rand.cc +++ b/srsenb/test/mac/scheduler_test_rand.cc @@ -103,11 +103,11 @@ void erase_if(MapContainer& c, Predicate should_remove) * Logging * *******************/ -class log_tester final : public srslte::scoped_tester_log +class sched_test_log final : public srslte::test_log_filter { public: - log_tester() : srslte::scoped_tester_log("MAC") { exit_on_error = true; } - ~log_tester() override { log_diagnostics(); } + sched_test_log() : srslte::test_log_filter("TEST") { exit_on_error = true; } + ~sched_test_log() override { log_diagnostics(); } void log_diagnostics() override { @@ -120,7 +120,7 @@ public: info("[TESTER] This was the seed: %u\n", seed); } }; -log_tester log_global; +srslte::scoped_log log_global{}; /******************* * Dummies * @@ -268,7 +268,7 @@ int sched_tester::add_user(uint16_t rnti, // setup bearers bearer_ue_cfg(rnti, 0, &bearer_cfg); - log_global.info("[TESTER] Adding user rnti=0x%x\n", rnti); + log_global->info("[TESTER] Adding user rnti=0x%x\n", rnti); return SRSLTE_SUCCESS; } @@ -315,7 +315,7 @@ int sched_tester::process_tti_args() bearer_ue_rem(rnti, 0); ue_rem(rnti); rem_user(rnti); - log_global.info("[TESTER] Removing user rnti=0x%x\n", rnti); + log_global->info("[TESTER] Removing user rnti=0x%x\n", rnti); } // push UL SRs and DL packets @@ -417,7 +417,7 @@ int sched_tester::process_results() void sched_tester::run_tti(uint32_t tti_rx) { new_test_tti(tti_rx); - log_global.info("[TESTER] ---- tti=%u | nof_ues=%zd ----\n", tti_rx, ue_db.size()); + log_global->info("[TESTER] ---- tti=%u | nof_ues=%zd ----\n", tti_rx, ue_db.size()); process_tti_args(); @@ -845,10 +845,10 @@ int sched_tester::ack_txs() if (ack_it.second.dl_ack) { CONDERROR(!h->is_empty(), "[TESTER] ACKed dl harq was not emptied\n"); CONDERROR(h->has_pending_retx(0, tti_data.tti_tx_dl), "[TESTER] ACKed dl harq still has pending retx\n"); - log_global.info("[TESTER] DL ACK tti=%u rnti=0x%x pid=%d\n", - tti_data.tti_rx, - ack_it.second.rnti, - ack_it.second.dl_harq.get_id()); + log_global->info("[TESTER] DL ACK tti=%u rnti=0x%x pid=%d\n", + tti_data.tti_rx, + ack_it.second.rnti, + ack_it.second.dl_harq.get_id()); } else { CONDERROR(h->is_empty() and hack.nof_retx(0) + 1 < hack.max_nof_retx(), "[TESTER] NACKed DL harq got emptied\n"); } @@ -873,7 +873,7 @@ int sched_tester::ack_txs() if (ack_it.second.ack) { CONDERROR(!h->is_empty(), "[TESTER] ACKed UL harq did not get emptied\n"); CONDERROR(h->has_pending_retx(), "[TESTER] ACKed UL harq still has pending retx\n"); - log_global.info("[TESTER] UL ACK tti=%u rnti=0x%x pid=%d\n", tti_data.tti_rx, ack_it.second.rnti, hack.get_id()); + log_global->info("[TESTER] UL ACK tti=%u rnti=0x%x pid=%d\n", tti_data.tti_rx, ack_it.second.rnti, hack.get_id()); } else { // NACK CONDERROR(!h->is_empty() and !h->has_pending_retx(), "[TESTER] If NACKed, UL harq has to have pending retx\n"); @@ -935,14 +935,14 @@ void test_scheduler_rand(srsenb::sched_interface::cell_cfg_t cell_cfg, const sch srsenb::dl_metric_rr dl_metric; srsenb::ul_metric_rr ul_metric; - log_global.set_level(srslte::LOG_LEVEL_INFO); + log_global->set_level(srslte::LOG_LEVEL_INFO); tester.sim_args = args; // srslte_cell_t& cell_cfg_phy = cell_cfg.cell; // srsenb::sched_interface::dl_sched_res_t& sched_result_dl = tester.tti_data.sched_result_dl; // srsenb::sched_interface::ul_sched_res_t& sched_result_ul = tester.tti_data.sched_result_ul; - tester.init(nullptr, &log_global); + tester.init(nullptr, log_global.get()); tester.set_metric(&dl_metric, &ul_metric); tester.cell_cfg(&cell_cfg); @@ -953,7 +953,7 @@ void test_scheduler_rand(srsenb::sched_interface::cell_cfg_t cell_cfg, const sch if (nof_ttis > args.nof_ttis) { running = false; } - log_global.step(tti); + log_global->step(tti); tester.run_tti(tti); diff --git a/srsenb/test/upper/erab_setup_test.cc b/srsenb/test/upper/erab_setup_test.cc index d10a55a00..20d3507e9 100644 --- a/srsenb/test/upper/erab_setup_test.cc +++ b/srsenb/test/upper/erab_setup_test.cc @@ -29,9 +29,9 @@ int test_erab_setup(bool qci_exists) { printf("\n===== TEST: test_erab_setup() =====\n"); - srslte::scoped_tester_log rrc_log("RRC "); - srslte::timer_handler timers; - srslte::unique_byte_buffer_t pdu; + srslte::scoped_log rrc_log("RRC "); + srslte::timer_handler timers; + srslte::unique_byte_buffer_t pdu; srsenb::all_args_t args; rrc_cfg_t cfg; @@ -44,9 +44,9 @@ int test_erab_setup(bool qci_exists) phy_dummy phy; test_dummies::s1ap_mobility_dummy s1ap; gtpu_dummy gtpu; - rrc_log.set_level(srslte::LOG_LEVEL_INFO); - rrc_log.set_hex_limit(1024); - rrc.init(&cfg, &phy, &mac, &rlc, &pdcp, &s1ap, >pu, &timers, &rrc_log); + rrc_log->set_level(srslte::LOG_LEVEL_INFO); + rrc_log->set_hex_limit(1024); + rrc.init(&cfg, &phy, &mac, &rlc, &pdcp, &s1ap, >pu, &timers, rrc_log.get()); auto tic = [&timers, &rrc] { timers.step_all(); @@ -56,13 +56,13 @@ int test_erab_setup(bool qci_exists) uint16_t rnti = 0x46; rrc.add_user(rnti); - rrc_log.set_level(srslte::LOG_LEVEL_NONE); // mute all the startup log + rrc_log->set_level(srslte::LOG_LEVEL_NONE); // mute all the startup log // Do all the handshaking until the first RRC Connection Reconf test_helpers::bring_rrc_to_reconf_state(rrc, timers, rnti); - rrc_log.set_level(srslte::LOG_LEVEL_DEBUG); - rrc_log.set_hex_limit(1024); + rrc_log->set_level(srslte::LOG_LEVEL_DEBUG); + rrc_log->set_hex_limit(1024); // MME sends 2nd ERAB Setup request for DRB2 (QCI exists in config) uint8_t drb2_erab_setup_request_ok[] = { @@ -98,9 +98,9 @@ int test_erab_setup(bool qci_exists) rrc.setup_ue_erabs(rnti, s1ap_pdu.init_msg().value.erab_setup_request()); if (qci_exists) { - TESTASSERT(rrc_log.error_counter == 0); + TESTASSERT(rrc_log->error_counter == 0); } else { - TESTASSERT(rrc_log.error_counter == 2); + TESTASSERT(rrc_log->error_counter == 2); } return SRSLTE_SUCCESS; @@ -108,7 +108,7 @@ int test_erab_setup(bool qci_exists) int main(int argc, char** argv) { - log_h.set_level(srslte::LOG_LEVEL_INFO); + srslte::logmap::get_instance()->set_default_log_level(srslte::LOG_LEVEL_INFO); if (argc < 3) { argparse::usage(argv[0]); diff --git a/srsenb/test/upper/rrc_mobility_test.cc b/srsenb/test/upper/rrc_mobility_test.cc index 3736ae0b3..91b00ab1c 100644 --- a/srsenb/test/upper/rrc_mobility_test.cc +++ b/srsenb/test/upper/rrc_mobility_test.cc @@ -76,7 +76,7 @@ int test_correct_insertion() // TEST 1: cell/rep insertion in empty varMeasCfg { - var_meas_cfg_t var_cfg(&log_h); + var_meas_cfg_t var_cfg(srslte::logmap::get("RRC ")); auto ret = var_cfg.add_cell_cfg(cell1); TESTASSERT(std::get<0>(ret) and std::get<1>(ret) != nullptr); const auto& objs = var_cfg.meas_objs(); @@ -94,7 +94,7 @@ int test_correct_insertion() } { - var_meas_cfg_t var_cfg(&log_h); + var_meas_cfg_t var_cfg(srslte::logmap::get("RRC ")); const auto& objs = var_cfg.meas_objs(); // TEST 2: insertion of out-of-order cell ids in same earfcn @@ -133,8 +133,7 @@ int test_correct_insertion() int test_correct_meascfg_calculation() { - srslte::scoped_tester_log log_test("MEASCFG_CALC"); - var_meas_cfg_t src_var(&log_h), target_var(&log_h); + var_meas_cfg_t src_var(srslte::logmap::get("RRC ")), target_var(srslte::logmap::get("RRC ")); meas_cell_cfg_t cell1{}, cell2{}; cell1.earfcn = 3400; @@ -214,7 +213,7 @@ int test_correct_meascfg_calculation() // TEST: Removal of cell/rep from target propagates to the resulting meas_cfg_s src_var = target_var; - target_var = var_meas_cfg_t{&log_h}; + target_var = var_meas_cfg_t{srslte::logmap::get("RRC ")}; target_var.add_cell_cfg(cell2); target_var.add_report_cfg(rep1); target_var.add_report_cfg(rep3); @@ -259,9 +258,9 @@ struct mobility_test_params { int test_mobility_class(mobility_test_params test_params) { printf("\n===== TEST: test_mobility_class() for event \"%s\" =====\n", test_params.to_string()); - srslte::scoped_tester_log rrc_log("RRC "); - srslte::timer_handler timers; - srslte::unique_byte_buffer_t pdu; + srslte::scoped_log rrc_log("RRC "); + srslte::timer_handler timers; + srslte::unique_byte_buffer_t pdu; srsenb::all_args_t args; rrc_cfg_t cfg; @@ -280,9 +279,9 @@ int test_mobility_class(mobility_test_params test_params) phy_dummy phy; test_dummies::s1ap_mobility_dummy s1ap; gtpu_dummy gtpu; - rrc_log.set_level(srslte::LOG_LEVEL_INFO); - rrc_log.set_hex_limit(1024); - rrc.init(&cfg, &phy, &mac, &rlc, &pdcp, &s1ap, >pu, &timers, &rrc_log); + rrc_log->set_level(srslte::LOG_LEVEL_INFO); + rrc_log->set_hex_limit(1024); + rrc.init(&cfg, &phy, &mac, &rlc, &pdcp, &s1ap, >pu, &timers, rrc_log.get()); auto tic = [&timers, &rrc] { timers.step_all(); @@ -292,11 +291,11 @@ int test_mobility_class(mobility_test_params test_params) uint16_t rnti = 0x46; rrc.add_user(rnti); - rrc_log.set_level(srslte::LOG_LEVEL_NONE); // mute all the startup log + rrc_log->set_level(srslte::LOG_LEVEL_NONE); // mute all the startup log // Do all the handshaking until the first RRC Connection Reconf test_helpers::bring_rrc_to_reconf_state(rrc, timers, rnti); - rrc_log.set_level(srslte::LOG_LEVEL_INFO); + rrc_log->set_level(srslte::LOG_LEVEL_INFO); /* Receive MeasReport from UE (correct if PCI=2) */ if (test_params.fail_at == mobility_test_params::test_fail_at::wrong_measreport) { @@ -312,7 +311,7 @@ int test_mobility_class(mobility_test_params test_params) /* Test Case: the MeasReport is not valid */ if (test_params.fail_at == mobility_test_params::test_fail_at::wrong_measreport) { TESTASSERT(s1ap.last_ho_required.rrc_container == nullptr); - TESTASSERT(rrc_log.error_counter == 1); + TESTASSERT(rrc_log->error_counter == 1); return SRSLTE_SUCCESS; } @@ -324,7 +323,7 @@ int test_mobility_class(mobility_test_params test_params) rrc.write_pdu(rnti, 1, std::move(pdu)); tic(); TESTASSERT(s1ap.last_ho_required.rrc_container == nullptr); - TESTASSERT(rrc_log.error_counter == 1); + TESTASSERT(rrc_log->error_counter == 1); return SRSLTE_SUCCESS; } @@ -346,7 +345,7 @@ int test_mobility_class(mobility_test_params test_params) /* Test Case: HandoverPreparation has failed */ if (test_params.fail_at == mobility_test_params::test_fail_at::ho_prep_failure) { rrc.ho_preparation_complete(rnti, false, nullptr); - TESTASSERT(rrc_log.error_counter == 1); + TESTASSERT(rrc_log->error_counter == 1); return SRSLTE_SUCCESS; } @@ -358,13 +357,13 @@ int test_mobility_class(mobility_test_params test_params) test_helpers::copy_msg_to_buffer(pdu, ho_cmd_rrc_container, sizeof(ho_cmd_rrc_container)); rrc.ho_preparation_complete(rnti, true, std::move(pdu)); - TESTASSERT(rrc_log.error_counter == 0); + TESTASSERT(rrc_log->error_counter == 0); return SRSLTE_SUCCESS; } int main(int argc, char** argv) { - log_h.set_level(srslte::LOG_LEVEL_INFO); + srslte::logmap::get_instance()->set_default_log_level(srslte::LOG_LEVEL_INFO); if (argc < 3) { argparse::usage(argv[0]); diff --git a/srsenb/test/upper/test_helpers.h b/srsenb/test/upper/test_helpers.h index 55b3e1c4b..52937e63e 100644 --- a/srsenb/test/upper/test_helpers.h +++ b/srsenb/test/upper/test_helpers.h @@ -28,8 +28,6 @@ using namespace srsenb; using namespace asn1::rrc; -srslte::scoped_tester_log log_h("ALL"); - namespace argparse { std::string repository_dir; @@ -116,7 +114,7 @@ int parse_default_cfg(rrc_cfg_t* rrc_cfg, srsenb::all_args_t& args) args.enb_files.sib_config = argparse::repository_dir + "/sib.conf.example"; args.enb_files.rr_config = argparse::repository_dir + "/rr.conf.example"; args.enb_files.drb_config = argparse::repository_dir + "/drb.conf.example"; - log_h.debug("sib file path=%s\n", args.enb_files.sib_config.c_str()); + srslte::logmap::get("TEST")->debug("sib file path=%s\n", args.enb_files.sib_config.c_str()); args.enb.dl_earfcn = 3400; args.enb.n_prb = 50;