- Rewrite log management so that a log sink can be swapped for each testcase.

master
faluco 4 years ago committed by faluco
parent 1d71cf8557
commit c178e362b8

@ -0,0 +1,46 @@
/*
* Copyright 2013-2020 Software Radio Systems Limited
*
* This file is part of srsLTE.
*
* srsLTE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* srsLTE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* A copy of the GNU Affero General Public License can be found in
* the LICENSE file in the top-level directory of this distribution
* and at http://www.gnu.org/licenses/.
*
*/
#ifndef SRSUE_TTCN3_SWAPPABLE_LOG_H
#define SRSUE_TTCN3_SWAPPABLE_LOG_H
#include "srslte/common/logger_srslog_wrapper.h"
/// This is a log wrapper that allows hot swapping the underlying log instance.
class swappable_log : public srslte::logger
{
public:
explicit swappable_log(std::unique_ptr<srslte::srslog_wrapper> log) : l(std::move(log)) {}
void log(unique_log_str_t msg) override
{
assert(l && "Missing log instance");
l->log(std::move(msg));
}
/// Swaps the underlying log wrapper.
void swap_log(std::unique_ptr<srslte::srslog_wrapper> new_log) { l = std::move(new_log); }
private:
std::unique_ptr<srslte::srslog_wrapper> l;
};
#endif // SRSUE_TTCN3_SWAPPABLE_LOG_H

@ -26,6 +26,7 @@
#include "srslte/test/ue_test_interfaces.h"
#include "srslte/upper/pdcp.h"
#include "srslte/upper/rlc.h"
#include "swappable_log.h"
#include "ttcn3_common.h"
#include "ttcn3_drb_interface.h"
#include "ttcn3_ip_ctrl_interface.h"
@ -49,7 +50,7 @@ class ttcn3_syssim : public syssim_interface_phy,
public srslte::pdu_queue::process_callback
{
public:
ttcn3_syssim(srslte::logger& logger_file_, srslte::logger& logger_stdout_, ttcn3_ue* ue_);
ttcn3_syssim(swappable_log& logger_file_, srslte::logger& logger_stdout_, ttcn3_ue* ue_);
~ttcn3_syssim();
@ -225,19 +226,19 @@ private:
epoll_signal_handler signal_handler;
// Logging stuff
srslte::logger& logger_stdout;
std::unique_ptr<logger> test_case_logger;
srslte::logger* logger_ptr = nullptr;
srslte::log_ref log;
srslte::log_filter ut_log;
srslte::log_filter sys_log;
srslte::log_filter ip_sock_log;
srslte::log_filter ip_ctrl_log;
srslte::log_filter srb_log;
srslte::log_filter drb_log;
srslte::log_ref ss_mac_log{"SS-MAC"};
srslte::log_ref ss_rlc_log{"SS-RLC"};
srslte::log_ref ss_pdcp_log{"SS-PDCP"};
srslte::logger& logger_stdout;
swappable_log& logger_file;
srslte::logger* logger = nullptr;
srslte::log_ref log;
srslte::log_filter ut_log;
srslte::log_filter sys_log;
srslte::log_filter ip_sock_log;
srslte::log_filter ip_ctrl_log;
srslte::log_filter srb_log;
srslte::log_filter drb_log;
srslte::log_ref ss_mac_log{"SS-MAC"};
srslte::log_ref ss_rlc_log{"SS-RLC"};
srslte::log_ref ss_pdcp_log{"SS-PDCP"};
all_args_t args = {};

@ -20,10 +20,10 @@
*/
#include "srslte/build_info.h"
#include "srslte/common/logger_srslog_wrapper.h"
#include "srslte/common/logmap.h"
#include "srslte/srslog/srslog.h"
#include "srsue/hdr/ue.h"
#include "swappable_log.h"
#include "ttcn3_syssim.h"
#include <boost/program_options.hpp>
#include <boost/program_options/parsers.hpp>
@ -129,7 +129,7 @@ int main(int argc, char** argv)
if (!file_chan) {
return SRSLTE_ERROR;
}
srslog::sink* stdout_sink = srslog::create_stdout_sink();
srslog::sink* stdout_sink = srslog::create_stdout_sink();
if (!stdout_sink) {
return SRSLTE_ERROR;
}
@ -137,8 +137,9 @@ int main(int argc, char** argv)
if (!stdout_chan) {
return SRSLTE_ERROR;
}
swappable_log file_wrapper(std::unique_ptr<srslte::srslog_wrapper>(new srslte::srslog_wrapper(*file_chan)));
srslte::srslog_wrapper stdout_wrapper(*stdout_chan);
srslte::srslog_wrapper file_wrapper(*file_chan);
// Start the log backend.
srslog::init();

@ -37,13 +37,14 @@
#include "ttcn3_ut_interface.h"
#include <functional>
ttcn3_syssim::ttcn3_syssim(srslte::logger& logger_file_, srslte::logger& logger_stdout_, ttcn3_ue* ue_) :
ttcn3_syssim::ttcn3_syssim(swappable_log& logger_file_, srslte::logger& logger_stdout_, ttcn3_ue* ue_) :
log{"SS "},
mac_msg_ul(20, ss_mac_log),
mac_msg_dl(20, ss_mac_log),
pdus(128),
logger_stdout(logger_stdout_),
logger_ptr(&logger_file_),
logger_file(logger_file_),
logger(&logger_file),
pool(byte_buffer_pool::get_instance()),
ue(ue_),
rlc(ss_rlc_log->get_service_name().c_str()),
@ -51,7 +52,7 @@ ttcn3_syssim::ttcn3_syssim(srslte::logger& logger_file_, srslte::logger& logger_
timer_handler(create_tti_timer(), [&](uint64_t res) { new_tti_indication(res); }),
pdcp(&stack.task_sched, ss_pdcp_log->get_service_name().c_str())
{
if (ue->init(all_args_t{}, logger_ptr, this, "INIT_TEST") != SRSLTE_SUCCESS) {
if (ue->init(all_args_t{}, logger, this, "INIT_TEST") != SRSLTE_SUCCESS) {
ue->stop();
fprintf(stderr, "Couldn't initialize UE.\n");
}
@ -65,20 +66,20 @@ int ttcn3_syssim::init(const all_args_t& args_)
// Make sure to get SS logging as well
if (args.log.filename == "stdout") {
logger_ptr = &logger_stdout;
logger = &logger_stdout;
}
srslte::logmap::set_default_logger(logger_ptr);
srslte::logmap::set_default_logger(logger);
// init and configure logging
srslte::logmap::register_log(std::unique_ptr<srslte::log>{new log_filter{"SS ", logger_ptr, true}});
ut_log.init("UT ", logger_ptr);
sys_log.init("SYS ", logger_ptr);
ip_sock_log.init("IP_S", logger_ptr);
ip_ctrl_log.init("IP_C", logger_ptr);
srb_log.init("SRB ", logger_ptr);
drb_log.init("DRB ", logger_ptr);
srslte::logmap::register_log(std::unique_ptr<srslte::log>{new log_filter{"SS-RLC", logger_ptr}});
srslte::logmap::register_log(std::unique_ptr<srslte::log>{new log_filter{"SS-PDCP", logger_ptr}});
srslte::logmap::register_log(std::unique_ptr<srslte::log>{new log_filter{"SS ", logger, true}});
ut_log.init("UT ", logger);
sys_log.init("SYS ", logger);
ip_sock_log.init("IP_S", logger);
ip_ctrl_log.init("IP_C", logger);
srb_log.init("SRB ", logger);
drb_log.init("DRB ", logger);
srslte::logmap::register_log(std::unique_ptr<srslte::log>{new log_filter{"SS-RLC", logger}});
srslte::logmap::register_log(std::unique_ptr<srslte::log>{new log_filter{"SS-PDCP", logger}});
log->set_level(args.log.all_level);
ut_log.set_level(args.log.all_level);
@ -407,13 +408,14 @@ void ttcn3_syssim::tc_start(const char* name)
// set up logging
if (args.log.filename == "stdout") {
logger_ptr = &logger_stdout;
logger = &logger_stdout;
} else {
// Create a new log wrapper that writes to the new test case file and swap it with the old one.
const std::string& file_tc_name = get_filename_with_tc_name(local_args.log.filename, run_id, tc_name);
srslog::sink* s = srslog::create_file_sink(file_tc_name);
srslog::log_channel* c = srslog::create_log_channel(file_tc_name, *s);
test_case_logger = std::unique_ptr<srslte::logger>(new srslte::srslog_wrapper(*c));
logger_ptr = test_case_logger.get();
logger_file.swap_log(std::unique_ptr<srslte::srslog_wrapper>(new srslte::srslog_wrapper(*c)));
logger = &logger_file;
}
log->info("Initializing UE ID=%d for TC=%s\n", run_id, tc_name.c_str());
@ -424,7 +426,7 @@ void ttcn3_syssim::tc_start(const char* name)
local_args.stack.pcap.nas_filename = get_filename_with_tc_name(args.stack.pcap.nas_filename, run_id, tc_name);
// bring up UE
if (ue->init(local_args, logger_ptr, this, tc_name)) {
if (ue->init(local_args, logger, this, tc_name)) {
ue->stop();
std::string err("Couldn't initialize UE.\n");
log->error("%s\n", err.c_str());
@ -641,10 +643,10 @@ bool ttcn3_syssim::process_ce(srslte::sch_subh* subh)
uint32_t buff_size_idx[4] = {};
uint32_t buff_size_bytes[4] = {};
float phr = 0;
int32_t idx = 0;
uint16_t old_rnti = 0;
bool is_bsr = false;
float phr = 0;
int32_t idx = 0;
uint16_t old_rnti = 0;
bool is_bsr = false;
switch (subh->ul_sch_ce_type()) {
case srslte::ul_sch_lcid::PHR_REPORT:
phr = subh->get_phr();

Loading…
Cancel
Save