updated the test logging utils

master
Francisco Paisana 5 years ago
parent daf471be1f
commit c8cd12ac53

@ -78,13 +78,21 @@ public:
void register_log(std::unique_ptr<log> log_ptr) void register_log(std::unique_ptr<log> log_ptr)
{ {
std::lock_guard<std::mutex> lock(mutex); std::lock_guard<std::mutex> lock(mutex);
if (log_ptr != nullptr) {
log_map[log_ptr->get_service_name()] = std::move(log_ptr); log_map[log_ptr->get_service_name()] = std::move(log_ptr);
} }
}
bool deregister_log(const std::string& servicename) std::unique_ptr<srslte::log> deregister_log(const std::string& servicename)
{ {
std::unique_ptr<srslte::log> ret;
std::lock_guard<std::mutex> lock(mutex); std::lock_guard<std::mutex> lock(mutex);
return log_map.erase(servicename) > 0; auto it = log_map.find(servicename);
if (it != log_map.end()) {
ret = std::move(it->second);
log_map.erase(it);
}
return ret;
} }
protected: protected:

@ -28,46 +28,26 @@
#include "srslte/common/log.h" #include "srslte/common/log.h"
#include "srslte/common/log_filter.h" #include "srslte/common/log_filter.h"
#include "srslte/common/logmap.h"
#include <cstdio> #include <cstdio>
namespace srslte { namespace srslte {
class test_log_singleton // Description: log filter that we can instantiate in a specific test scope, and cleans itself on scope exit
{
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
// useful if we want to define specific logging policies within a scope (e.g. null logger, count number of errors, // 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 // 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: 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); set_level(srslte::LOG_LEVEL_DEBUG);
} }
scoped_tester_log(const scoped_tester_log&) = delete; test_log_filter(const test_log_filter&) = delete;
scoped_tester_log(scoped_tester_log&&) = delete; test_log_filter(test_log_filter&&) = delete;
scoped_tester_log& operator=(const scoped_tester_log&) = delete; test_log_filter& operator=(const test_log_filter&) = delete;
scoped_tester_log& operator=(scoped_tester_log&&) = delete; test_log_filter& operator=(test_log_filter&&) = delete;
~scoped_tester_log() override { test_log_singleton::get_instance()->register_log(previous_log_test); } ~test_log_filter() override = default;
void error(const char* message, ...) override __attribute__((format(printf, 2, 3))) void error(const char* message, ...) override __attribute__((format(printf, 2, 3)))
{ {
@ -109,16 +89,13 @@ public:
bool exit_on_error = false; bool exit_on_error = false;
uint32_t error_counter = 0, warn_counter = 0; 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 // specialization of test_log_filter to store last logged message
class nullsink_log : public scoped_tester_log class nullsink_log : public test_log_filter
{ {
public: 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))) void debug(const char* message, ...) override __attribute__((format(printf, 2, 3)))
{ {
@ -173,25 +150,47 @@ private:
} }
}; };
template <typename Log>
class scoped_log
{
public:
template <typename... Args>
explicit scoped_log(Args&&... args)
{
std::unique_ptr<Log> l{new Log{std::forward<Args>(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<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<srslte::log> prev_log;
};
} // namespace srslte } // namespace srslte
#define TESTERROR(fmt, ...) \ #define TESTERROR(fmt, ...) \
do { \ do { \
if (srslte::test_log_singleton::get_instance() == nullptr) { \ srslte::logmap::get("TEST")->error(fmt, ##__VA_ARGS__); \
printf(fmt, ##__VA_ARGS__); \
} else { \
srslte::test_log_singleton::get_log()->error(fmt, ##__VA_ARGS__); \
} \
return SRSLTE_ERROR; \ return SRSLTE_ERROR; \
} while (0) } while (0)
#define TESTWARN(fmt, ...) \ #define TESTWARN(fmt, ...) \
do { \ do { \
if (srslte::test_log_singleton::get_instance() == nullptr) { \ srslte::logmap::get("TEST")->warning(fmt, ##__VA_ARGS__); \
printf(fmt, ##__VA_ARGS__); \
} else { \
srslte::test_log_singleton::get_log()->warning(fmt, ##__VA_ARGS__); \
} \
} while (0) } while (0)
#define CONDERROR(cond, fmt, ...) \ #define CONDERROR(cond, fmt, ...) \

@ -24,9 +24,6 @@
using namespace asn1; using namespace asn1;
using namespace asn1::ngap_nr; using namespace asn1::ngap_nr;
srslte::log_filter asn_logger("ASN");
srslte::log_filter ngap_log("NGAP");
/* TESTS */ /* TESTS */
int test_amf_upd() int test_amf_upd()
@ -348,10 +345,9 @@ int test_session_res_setup_request()
int main() int main()
{ {
asn_logger.set_level("DEBUG"); srslte::logmap::get_instance()->set_default_log_level(LOG_LEVEL_DEBUG);
ngap_log.set_level("DEBUG"); srsasn_log_register_handler(srslte::logmap::get("ASN1"));
srsasn_log_register_handler(&asn_logger); ngap_nr_log_register_handler(srslte::logmap::get("NGAP"));
ngap_nr_log_register_handler(&ngap_log);
TESTASSERT(test_amf_upd() == 0); TESTASSERT(test_amf_upd() == 0);
TESTASSERT(test_ngsetup_request() == 0); TESTASSERT(test_ngsetup_request() == 0);

@ -25,10 +25,6 @@
using namespace asn1; using namespace asn1;
using namespace asn1::rrc; using namespace asn1::rrc;
srslte::log_filter asn_logger("ASN1");
srslte::log_filter rrc_logger("RRC");
srslte::scoped_tester_log test_logger("TEST");
// TESTS // TESTS
int test_generic() int test_generic()
@ -48,7 +44,7 @@ int test_generic()
TESTASSERT(null_log.last_log_msg == test_str); TESTASSERT(null_log.last_log_msg == test_str);
TESTASSERT(null_log.last_log_level == LOG_LEVEL_INFO); TESTASSERT(null_log.last_log_level == LOG_LEVEL_INFO);
// go back to original logger // 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 // Test deep copy of choice types
@ -603,12 +599,9 @@ int test_rrc_conn_reconf_r15_2()
int main() int main()
{ {
asn_logger.set_level(LOG_LEVEL_DEBUG); srslte::logmap::get_instance()->set_default_log_level(LOG_LEVEL_DEBUG);
rrc_logger.set_level(LOG_LEVEL_DEBUG); srsasn_log_register_handler(srslte::logmap::get("ASN1"));
test_logger.set_level(LOG_LEVEL_DEBUG); rrc_log_register_handler(srslte::logmap::get("RRC "));
srsasn_log_register_handler(&asn_logger);
rrc_log_register_handler(&rrc_logger);
TESTASSERT(test_generic() == 0); TESTASSERT(test_generic() == 0);
TESTASSERT(test_json_printer() == 0); TESTASSERT(test_json_printer() == 0);

@ -27,8 +27,6 @@
using namespace asn1; using namespace asn1;
srslte::scoped_tester_log test_logger("TEST");
int unpack_test_served_gummeis_with_multiple_plmns() 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, 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)); asn1::bit_ref bref(buffer, sizeof(buffer));
TESTASSERT(tx_pdu.pack(bref) == SRSLTE_SUCCESS); 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; return SRSLTE_SUCCESS;
} }
@ -127,15 +126,15 @@ int test_eci_pack()
TESTASSERT(buffer[1] == 0x19); TESTASSERT(buffer[1] == 0x19);
TESTASSERT(buffer[2] == 0xC0); 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; return SRSLTE_SUCCESS;
} }
int main() int main()
{ {
test_logger.set_level(LOG_LEVEL_DEBUG); srslte::logmap::get_instance()->set_default_log_level(LOG_LEVEL_DEBUG);
test_logger.set_hex_limit(1024); srslte::logmap::get_instance()->set_default_hex_limit(1024);
TESTASSERT(unpack_test_served_gummeis_with_multiple_plmns() == SRSLTE_SUCCESS); TESTASSERT(unpack_test_served_gummeis_with_multiple_plmns() == SRSLTE_SUCCESS);
TESTASSERT(test_initial_ctxt_setup_response() == SRSLTE_SUCCESS); TESTASSERT(test_initial_ctxt_setup_response() == SRSLTE_SUCCESS);

@ -21,22 +21,24 @@
#include "srslte/common/test_common.h" #include "srslte/common/test_common.h"
using srslte::nullsink_log;
using srslte::scoped_log;
int test_nullsink_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 // 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, // This logger is useful to confirm that a certain action produced an expected error/warning,
// without contaminating the console/log file // without contaminating the console/log file, and to check what error message was stored
srslte::nullsink_log null_logger{"TEST"}; scoped_log<nullsink_log> null_log("TEST");
TESTASSERT(srslte::test_log_singleton::get_log() == &null_logger);
TESTASSERT(null_logger.error_counter == 0); TESTASSERT(srslte::logmap::get("TEST") == null_log.get());
TESTASSERT(null_logger.last_log_level == srslte::LOG_LEVEL_NONE); TESTASSERT(null_log->error_counter == 0);
TESTASSERT(null_logger.last_log_msg.empty()); TESTASSERT(null_log->last_log_level == srslte::LOG_LEVEL_NONE);
null_logger.error("ERROR MESSAGE"); // This message should not be seen in the console TESTASSERT(null_log->last_log_msg.empty());
TESTASSERT(null_logger.error_counter == 1); null_log->error("ERROR MESSAGE"); // This message should not be seen in the console
TESTASSERT(null_logger.last_log_level == srslte::LOG_LEVEL_ERROR); TESTASSERT(null_log->error_counter == 1);
TESTASSERT(null_logger.last_log_msg == "ERROR MESSAGE"); TESTASSERT(null_log->last_log_level == srslte::LOG_LEVEL_ERROR);
TESTASSERT(null_log->last_log_msg == "ERROR MESSAGE");
return SRSLTE_SUCCESS; return SRSLTE_SUCCESS;
} }
@ -47,26 +49,27 @@ int test_log_scoping()
// on scope exit the previous logger should be recovered // 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 // 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 // we want to use a different one
srslte::nullsink_log logger1("TEST1"); scoped_log<nullsink_log> log1("TEST");
TESTASSERT(srslte::test_log_singleton::get_log() == &logger1); TESTASSERT(srslte::logmap::get("TEST") == log1.get());
logger1.error("message1"); log1->error("message1");
logger1.error("message2"); log1->error("message2");
TESTASSERT(logger1.last_log_msg == "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 // the global test log should be overwriten here, and used by TESTASSERT macro
srslte::nullsink_log logger2("TEST2"); scoped_log<nullsink_log> log2("TEST");
TESTASSERT(srslte::test_log_singleton::get_log() == &logger2); TESTASSERT(srslte::logmap::get("TEST") == log2.get());
TESTASSERT(logger2.error_counter == 0); TESTASSERT(log2->error_counter == 0);
logger2.error("error message in logger2\n"); log2->error("error message in logger2\n");
TESTASSERT(logger2.last_log_msg == "error message in logger2\n"); TESTASSERT(log2->last_log_msg == "error message in logger2\n");
TESTASSERT(logger2.error_counter == 1); TESTASSERT(log2->error_counter == 1);
} }
// the last logger should be recovered // the last logger should be recovered
TESTASSERT(srslte::test_log_singleton::get_log() == &logger1); TESTASSERT(srslte::logmap::get("TEST") == log1.get());
TESTASSERT(logger1.error_counter == 2); TESTASSERT(log1->error_counter == 2);
return 0; return 0;
} }

@ -103,11 +103,11 @@ void erase_if(MapContainer& c, Predicate should_remove)
* Logging * * Logging *
*******************/ *******************/
class log_tester final : public srslte::scoped_tester_log class sched_test_log final : public srslte::test_log_filter
{ {
public: public:
log_tester() : srslte::scoped_tester_log("MAC") { exit_on_error = true; } sched_test_log() : srslte::test_log_filter("TEST") { exit_on_error = true; }
~log_tester() override { log_diagnostics(); } ~sched_test_log() override { log_diagnostics(); }
void log_diagnostics() override void log_diagnostics() override
{ {
@ -120,7 +120,7 @@ public:
info("[TESTER] This was the seed: %u\n", seed); info("[TESTER] This was the seed: %u\n", seed);
} }
}; };
log_tester log_global; srslte::scoped_log<sched_test_log> log_global{};
/******************* /*******************
* Dummies * * Dummies *
@ -268,7 +268,7 @@ int sched_tester::add_user(uint16_t rnti,
// setup bearers // setup bearers
bearer_ue_cfg(rnti, 0, &bearer_cfg); 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; return SRSLTE_SUCCESS;
} }
@ -315,7 +315,7 @@ int sched_tester::process_tti_args()
bearer_ue_rem(rnti, 0); bearer_ue_rem(rnti, 0);
ue_rem(rnti); ue_rem(rnti);
rem_user(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 // push UL SRs and DL packets
@ -417,7 +417,7 @@ int sched_tester::process_results()
void sched_tester::run_tti(uint32_t tti_rx) void sched_tester::run_tti(uint32_t tti_rx)
{ {
new_test_tti(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(); process_tti_args();
@ -845,7 +845,7 @@ int sched_tester::ack_txs()
if (ack_it.second.dl_ack) { if (ack_it.second.dl_ack) {
CONDERROR(!h->is_empty(), "[TESTER] ACKed dl harq was not emptied\n"); 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"); 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", log_global->info("[TESTER] DL ACK tti=%u rnti=0x%x pid=%d\n",
tti_data.tti_rx, tti_data.tti_rx,
ack_it.second.rnti, ack_it.second.rnti,
ack_it.second.dl_harq.get_id()); ack_it.second.dl_harq.get_id());
@ -873,7 +873,7 @@ int sched_tester::ack_txs()
if (ack_it.second.ack) { if (ack_it.second.ack) {
CONDERROR(!h->is_empty(), "[TESTER] ACKed UL harq did not get emptied\n"); 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"); 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 { } else {
// NACK // NACK
CONDERROR(!h->is_empty() and !h->has_pending_retx(), "[TESTER] If NACKed, UL harq has to have pending retx\n"); 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::dl_metric_rr dl_metric;
srsenb::ul_metric_rr ul_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; tester.sim_args = args;
// srslte_cell_t& cell_cfg_phy = cell_cfg.cell; // 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::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; // 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.set_metric(&dl_metric, &ul_metric);
tester.cell_cfg(&cell_cfg); 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) { if (nof_ttis > args.nof_ttis) {
running = false; running = false;
} }
log_global.step(tti); log_global->step(tti);
tester.run_tti(tti); tester.run_tti(tti);

@ -29,7 +29,7 @@
int test_erab_setup(bool qci_exists) int test_erab_setup(bool qci_exists)
{ {
printf("\n===== TEST: test_erab_setup() =====\n"); printf("\n===== TEST: test_erab_setup() =====\n");
srslte::scoped_tester_log rrc_log("RRC "); srslte::scoped_log<srslte::test_log_filter> rrc_log("RRC ");
srslte::timer_handler timers; srslte::timer_handler timers;
srslte::unique_byte_buffer_t pdu; srslte::unique_byte_buffer_t pdu;
@ -44,9 +44,9 @@ int test_erab_setup(bool qci_exists)
phy_dummy phy; phy_dummy phy;
test_dummies::s1ap_mobility_dummy s1ap; test_dummies::s1ap_mobility_dummy s1ap;
gtpu_dummy gtpu; gtpu_dummy gtpu;
rrc_log.set_level(srslte::LOG_LEVEL_INFO); rrc_log->set_level(srslte::LOG_LEVEL_INFO);
rrc_log.set_hex_limit(1024); rrc_log->set_hex_limit(1024);
rrc.init(&cfg, &phy, &mac, &rlc, &pdcp, &s1ap, &gtpu, &timers, &rrc_log); rrc.init(&cfg, &phy, &mac, &rlc, &pdcp, &s1ap, &gtpu, &timers, rrc_log.get());
auto tic = [&timers, &rrc] { auto tic = [&timers, &rrc] {
timers.step_all(); timers.step_all();
@ -56,13 +56,13 @@ int test_erab_setup(bool qci_exists)
uint16_t rnti = 0x46; uint16_t rnti = 0x46;
rrc.add_user(rnti); 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 // Do all the handshaking until the first RRC Connection Reconf
test_helpers::bring_rrc_to_reconf_state(rrc, timers, rnti); test_helpers::bring_rrc_to_reconf_state(rrc, timers, rnti);
rrc_log.set_level(srslte::LOG_LEVEL_DEBUG); rrc_log->set_level(srslte::LOG_LEVEL_DEBUG);
rrc_log.set_hex_limit(1024); rrc_log->set_hex_limit(1024);
// MME sends 2nd ERAB Setup request for DRB2 (QCI exists in config) // MME sends 2nd ERAB Setup request for DRB2 (QCI exists in config)
uint8_t drb2_erab_setup_request_ok[] = { 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()); rrc.setup_ue_erabs(rnti, s1ap_pdu.init_msg().value.erab_setup_request());
if (qci_exists) { if (qci_exists) {
TESTASSERT(rrc_log.error_counter == 0); TESTASSERT(rrc_log->error_counter == 0);
} else { } else {
TESTASSERT(rrc_log.error_counter == 2); TESTASSERT(rrc_log->error_counter == 2);
} }
return SRSLTE_SUCCESS; return SRSLTE_SUCCESS;
@ -108,7 +108,7 @@ int test_erab_setup(bool qci_exists)
int main(int argc, char** argv) 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) { if (argc < 3) {
argparse::usage(argv[0]); argparse::usage(argv[0]);

@ -76,7 +76,7 @@ int test_correct_insertion()
// TEST 1: cell/rep insertion in empty varMeasCfg // 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); auto ret = var_cfg.add_cell_cfg(cell1);
TESTASSERT(std::get<0>(ret) and std::get<1>(ret) != nullptr); TESTASSERT(std::get<0>(ret) and std::get<1>(ret) != nullptr);
const auto& objs = var_cfg.meas_objs(); 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(); const auto& objs = var_cfg.meas_objs();
// TEST 2: insertion of out-of-order cell ids in same earfcn // 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() int test_correct_meascfg_calculation()
{ {
srslte::scoped_tester_log log_test("MEASCFG_CALC"); var_meas_cfg_t src_var(srslte::logmap::get("RRC ")), target_var(srslte::logmap::get("RRC "));
var_meas_cfg_t src_var(&log_h), target_var(&log_h);
meas_cell_cfg_t cell1{}, cell2{}; meas_cell_cfg_t cell1{}, cell2{};
cell1.earfcn = 3400; 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 // TEST: Removal of cell/rep from target propagates to the resulting meas_cfg_s
src_var = target_var; 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_cell_cfg(cell2);
target_var.add_report_cfg(rep1); target_var.add_report_cfg(rep1);
target_var.add_report_cfg(rep3); target_var.add_report_cfg(rep3);
@ -259,7 +258,7 @@ struct mobility_test_params {
int test_mobility_class(mobility_test_params 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()); printf("\n===== TEST: test_mobility_class() for event \"%s\" =====\n", test_params.to_string());
srslte::scoped_tester_log rrc_log("RRC "); srslte::scoped_log<srslte::test_log_filter> rrc_log("RRC ");
srslte::timer_handler timers; srslte::timer_handler timers;
srslte::unique_byte_buffer_t pdu; srslte::unique_byte_buffer_t pdu;
@ -280,9 +279,9 @@ int test_mobility_class(mobility_test_params test_params)
phy_dummy phy; phy_dummy phy;
test_dummies::s1ap_mobility_dummy s1ap; test_dummies::s1ap_mobility_dummy s1ap;
gtpu_dummy gtpu; gtpu_dummy gtpu;
rrc_log.set_level(srslte::LOG_LEVEL_INFO); rrc_log->set_level(srslte::LOG_LEVEL_INFO);
rrc_log.set_hex_limit(1024); rrc_log->set_hex_limit(1024);
rrc.init(&cfg, &phy, &mac, &rlc, &pdcp, &s1ap, &gtpu, &timers, &rrc_log); rrc.init(&cfg, &phy, &mac, &rlc, &pdcp, &s1ap, &gtpu, &timers, rrc_log.get());
auto tic = [&timers, &rrc] { auto tic = [&timers, &rrc] {
timers.step_all(); timers.step_all();
@ -292,11 +291,11 @@ int test_mobility_class(mobility_test_params test_params)
uint16_t rnti = 0x46; uint16_t rnti = 0x46;
rrc.add_user(rnti); 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 // Do all the handshaking until the first RRC Connection Reconf
test_helpers::bring_rrc_to_reconf_state(rrc, timers, rnti); 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) */ /* Receive MeasReport from UE (correct if PCI=2) */
if (test_params.fail_at == mobility_test_params::test_fail_at::wrong_measreport) { 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 */ /* Test Case: the MeasReport is not valid */
if (test_params.fail_at == mobility_test_params::test_fail_at::wrong_measreport) { if (test_params.fail_at == mobility_test_params::test_fail_at::wrong_measreport) {
TESTASSERT(s1ap.last_ho_required.rrc_container == nullptr); TESTASSERT(s1ap.last_ho_required.rrc_container == nullptr);
TESTASSERT(rrc_log.error_counter == 1); TESTASSERT(rrc_log->error_counter == 1);
return SRSLTE_SUCCESS; return SRSLTE_SUCCESS;
} }
@ -324,7 +323,7 @@ int test_mobility_class(mobility_test_params test_params)
rrc.write_pdu(rnti, 1, std::move(pdu)); rrc.write_pdu(rnti, 1, std::move(pdu));
tic(); tic();
TESTASSERT(s1ap.last_ho_required.rrc_container == nullptr); TESTASSERT(s1ap.last_ho_required.rrc_container == nullptr);
TESTASSERT(rrc_log.error_counter == 1); TESTASSERT(rrc_log->error_counter == 1);
return SRSLTE_SUCCESS; return SRSLTE_SUCCESS;
} }
@ -346,7 +345,7 @@ int test_mobility_class(mobility_test_params test_params)
/* Test Case: HandoverPreparation has failed */ /* Test Case: HandoverPreparation has failed */
if (test_params.fail_at == mobility_test_params::test_fail_at::ho_prep_failure) { if (test_params.fail_at == mobility_test_params::test_fail_at::ho_prep_failure) {
rrc.ho_preparation_complete(rnti, false, nullptr); rrc.ho_preparation_complete(rnti, false, nullptr);
TESTASSERT(rrc_log.error_counter == 1); TESTASSERT(rrc_log->error_counter == 1);
return SRSLTE_SUCCESS; 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)); 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)); rrc.ho_preparation_complete(rnti, true, std::move(pdu));
TESTASSERT(rrc_log.error_counter == 0); TESTASSERT(rrc_log->error_counter == 0);
return SRSLTE_SUCCESS; return SRSLTE_SUCCESS;
} }
int main(int argc, char** argv) 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) { if (argc < 3) {
argparse::usage(argv[0]); argparse::usage(argv[0]);

@ -28,8 +28,6 @@
using namespace srsenb; using namespace srsenb;
using namespace asn1::rrc; using namespace asn1::rrc;
srslte::scoped_tester_log log_h("ALL");
namespace argparse { namespace argparse {
std::string repository_dir; 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.sib_config = argparse::repository_dir + "/sib.conf.example";
args.enb_files.rr_config = argparse::repository_dir + "/rr.conf.example"; args.enb_files.rr_config = argparse::repository_dir + "/rr.conf.example";
args.enb_files.drb_config = argparse::repository_dir + "/drb.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.dl_earfcn = 3400;
args.enb.n_prb = 50; args.enb.n_prb = 50;

Loading…
Cancel
Save