|
|
@ -18,23 +18,25 @@
|
|
|
|
using namespace srslog;
|
|
|
|
using namespace srslog;
|
|
|
|
|
|
|
|
|
|
|
|
/// Helper to build a log entry.
|
|
|
|
/// Helper to build a log entry.
|
|
|
|
static detail::log_entry_metadata build_log_entry_metadata()
|
|
|
|
static detail::log_entry_metadata build_log_entry_metadata(fmt::dynamic_format_arg_store<fmt::printf_context>* store)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Create a time point 50000us from epoch.
|
|
|
|
// Create a time point 50000us from epoch.
|
|
|
|
using tp_ty = std::chrono::time_point<std::chrono::high_resolution_clock>;
|
|
|
|
using tp_ty = std::chrono::time_point<std::chrono::high_resolution_clock>;
|
|
|
|
tp_ty tp(std::chrono::microseconds(50000));
|
|
|
|
tp_ty tp(std::chrono::microseconds(50000));
|
|
|
|
|
|
|
|
|
|
|
|
fmt::dynamic_format_arg_store<fmt::printf_context> store;
|
|
|
|
if (store) {
|
|
|
|
store.push_back(88);
|
|
|
|
store->push_back(88);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return {tp, {10, true}, "Text %d", std::move(store), "ABC", 'Z', small_str_buffer()};
|
|
|
|
return {tp, {10, true}, "Text %d", store, "ABC", 'Z', small_str_buffer()};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool when_fully_filled_log_entry_then_everything_is_formatted()
|
|
|
|
static bool when_fully_filled_log_entry_then_everything_is_formatted()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
fmt::memory_buffer buffer;
|
|
|
|
fmt::memory_buffer buffer;
|
|
|
|
text_formatter{}.format(build_log_entry_metadata(), buffer);
|
|
|
|
fmt::dynamic_format_arg_store<fmt::printf_context> store;
|
|
|
|
std::string result = fmt::to_string(buffer);
|
|
|
|
text_formatter{}.format(build_log_entry_metadata(&store), buffer);
|
|
|
|
|
|
|
|
std::string result = fmt::to_string(buffer);
|
|
|
|
std::string expected = "00:00:00.050000 [ABC ] [Z] [ 10] Text 88\n";
|
|
|
|
std::string expected = "00:00:00.050000 [ABC ] [Z] [ 10] Text 88\n";
|
|
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(result, expected);
|
|
|
|
ASSERT_EQ(result, expected);
|
|
|
@ -44,12 +46,13 @@ static bool when_fully_filled_log_entry_then_everything_is_formatted()
|
|
|
|
|
|
|
|
|
|
|
|
static bool when_log_entry_without_name_is_passed_then_name_is_not_formatted()
|
|
|
|
static bool when_log_entry_without_name_is_passed_then_name_is_not_formatted()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
auto entry = build_log_entry_metadata();
|
|
|
|
fmt::dynamic_format_arg_store<fmt::printf_context> store;
|
|
|
|
entry.log_name = "";
|
|
|
|
auto entry = build_log_entry_metadata(&store);
|
|
|
|
|
|
|
|
entry.log_name = "";
|
|
|
|
|
|
|
|
|
|
|
|
fmt::memory_buffer buffer;
|
|
|
|
fmt::memory_buffer buffer;
|
|
|
|
text_formatter{}.format(std::move(entry), buffer);
|
|
|
|
text_formatter{}.format(std::move(entry), buffer);
|
|
|
|
std::string result = fmt::to_string(buffer);
|
|
|
|
std::string result = fmt::to_string(buffer);
|
|
|
|
std::string expected = "00:00:00.050000 [Z] [ 10] Text 88\n";
|
|
|
|
std::string expected = "00:00:00.050000 [Z] [ 10] Text 88\n";
|
|
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(result, expected);
|
|
|
|
ASSERT_EQ(result, expected);
|
|
|
@ -59,12 +62,13 @@ static bool when_log_entry_without_name_is_passed_then_name_is_not_formatted()
|
|
|
|
|
|
|
|
|
|
|
|
static bool when_log_entry_without_tag_is_passed_then_tag_is_not_formatted()
|
|
|
|
static bool when_log_entry_without_tag_is_passed_then_tag_is_not_formatted()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
auto entry = build_log_entry_metadata();
|
|
|
|
fmt::dynamic_format_arg_store<fmt::printf_context> store;
|
|
|
|
entry.log_tag = '\0';
|
|
|
|
auto entry = build_log_entry_metadata(&store);
|
|
|
|
|
|
|
|
entry.log_tag = '\0';
|
|
|
|
|
|
|
|
|
|
|
|
fmt::memory_buffer buffer;
|
|
|
|
fmt::memory_buffer buffer;
|
|
|
|
text_formatter{}.format(std::move(entry), buffer);
|
|
|
|
text_formatter{}.format(std::move(entry), buffer);
|
|
|
|
std::string result = fmt::to_string(buffer);
|
|
|
|
std::string result = fmt::to_string(buffer);
|
|
|
|
std::string expected = "00:00:00.050000 [ABC ] [ 10] Text 88\n";
|
|
|
|
std::string expected = "00:00:00.050000 [ABC ] [ 10] Text 88\n";
|
|
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(result, expected);
|
|
|
|
ASSERT_EQ(result, expected);
|
|
|
@ -72,15 +76,15 @@ static bool when_log_entry_without_tag_is_passed_then_tag_is_not_formatted()
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool
|
|
|
|
static bool when_log_entry_without_context_is_passed_then_context_is_not_formatted()
|
|
|
|
when_log_entry_without_context_is_passed_then_context_is_not_formatted()
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
auto entry = build_log_entry_metadata();
|
|
|
|
fmt::dynamic_format_arg_store<fmt::printf_context> store;
|
|
|
|
entry.context.enabled = false;
|
|
|
|
auto entry = build_log_entry_metadata(&store);
|
|
|
|
|
|
|
|
entry.context.enabled = false;
|
|
|
|
|
|
|
|
|
|
|
|
fmt::memory_buffer buffer;
|
|
|
|
fmt::memory_buffer buffer;
|
|
|
|
text_formatter{}.format(std::move(entry), buffer);
|
|
|
|
text_formatter{}.format(std::move(entry), buffer);
|
|
|
|
std::string result = fmt::to_string(buffer);
|
|
|
|
std::string result = fmt::to_string(buffer);
|
|
|
|
std::string expected = "00:00:00.050000 [ABC ] [Z] Text 88\n";
|
|
|
|
std::string expected = "00:00:00.050000 [ABC ] [Z] Text 88\n";
|
|
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(result, expected);
|
|
|
|
ASSERT_EQ(result, expected);
|
|
|
@ -90,17 +94,17 @@ when_log_entry_without_context_is_passed_then_context_is_not_formatted()
|
|
|
|
|
|
|
|
|
|
|
|
static bool when_log_entry_with_hex_dump_is_passed_then_hex_dump_is_formatted()
|
|
|
|
static bool when_log_entry_with_hex_dump_is_passed_then_hex_dump_is_formatted()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
auto entry = build_log_entry_metadata();
|
|
|
|
fmt::dynamic_format_arg_store<fmt::printf_context> store;
|
|
|
|
|
|
|
|
auto entry = build_log_entry_metadata(&store);
|
|
|
|
entry.hex_dump.resize(20);
|
|
|
|
entry.hex_dump.resize(20);
|
|
|
|
std::iota(entry.hex_dump.begin(), entry.hex_dump.end(), 0);
|
|
|
|
std::iota(entry.hex_dump.begin(), entry.hex_dump.end(), 0);
|
|
|
|
|
|
|
|
|
|
|
|
fmt::memory_buffer buffer;
|
|
|
|
fmt::memory_buffer buffer;
|
|
|
|
text_formatter{}.format(std::move(entry), buffer);
|
|
|
|
text_formatter{}.format(std::move(entry), buffer);
|
|
|
|
std::string result = fmt::to_string(buffer);
|
|
|
|
std::string result = fmt::to_string(buffer);
|
|
|
|
std::string expected =
|
|
|
|
std::string expected = "00:00:00.050000 [ABC ] [Z] [ 10] Text 88\n"
|
|
|
|
"00:00:00.050000 [ABC ] [Z] [ 10] Text 88\n"
|
|
|
|
" 0000: 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f\n"
|
|
|
|
" 0000: 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f\n"
|
|
|
|
" 0010: 10 11 12 13\n";
|
|
|
|
" 0010: 10 11 12 13\n";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(result, expected);
|
|
|
|
ASSERT_EQ(result, expected);
|
|
|
|
|
|
|
|
|
|
|
@ -120,11 +124,7 @@ DECLARE_METRIC_SET("ue_container", ue_set, thr_t, ip_addr_t, antenna_list_t);
|
|
|
|
DECLARE_METRIC("type", entry_type_t, std::string, "");
|
|
|
|
DECLARE_METRIC("type", entry_type_t, std::string, "");
|
|
|
|
DECLARE_METRIC("sector_id", sector_id_t, unsigned, "");
|
|
|
|
DECLARE_METRIC("sector_id", sector_id_t, unsigned, "");
|
|
|
|
DECLARE_METRIC_LIST("ue_list", ue_list_t, std::vector<ue_set>);
|
|
|
|
DECLARE_METRIC_LIST("ue_list", ue_list_t, std::vector<ue_set>);
|
|
|
|
DECLARE_METRIC_SET("sector_metrics",
|
|
|
|
DECLARE_METRIC_SET("sector_metrics", sector_set, entry_type_t, sector_id_t, ue_list_t);
|
|
|
|
sector_set,
|
|
|
|
|
|
|
|
entry_type_t,
|
|
|
|
|
|
|
|
sector_id_t,
|
|
|
|
|
|
|
|
ue_list_t);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DECLARE_METRIC_LIST("sector_list", sector_list_t, std::vector<sector_set>);
|
|
|
|
DECLARE_METRIC_LIST("sector_list", sector_list_t, std::vector<sector_set>);
|
|
|
|
|
|
|
|
|
|
|
@ -149,54 +149,33 @@ static complex_ctx_t build_complex_context()
|
|
|
|
ctx.at<sector_list_t>(0).at<ue_list_t>(1).write<thr_t>(10.2);
|
|
|
|
ctx.at<sector_list_t>(0).at<ue_list_t>(1).write<thr_t>(10.2);
|
|
|
|
ctx.at<sector_list_t>(0).at<ue_list_t>(1).write<ip_addr_t>("10.20.30.41");
|
|
|
|
ctx.at<sector_list_t>(0).at<ue_list_t>(1).write<ip_addr_t>("10.20.30.41");
|
|
|
|
|
|
|
|
|
|
|
|
ctx.at<sector_list_t>(0)
|
|
|
|
ctx.at<sector_list_t>(0).at<ue_list_t>(0).get<antenna_list_t>().emplace_back();
|
|
|
|
.at<ue_list_t>(0)
|
|
|
|
ctx.at<sector_list_t>(0).at<ue_list_t>(0).at<antenna_list_t>(0).write<snr_t>(5.1);
|
|
|
|
.get<antenna_list_t>()
|
|
|
|
ctx.at<sector_list_t>(0).at<ue_list_t>(0).at<antenna_list_t>(0).write<pwr_t>(-11.5);
|
|
|
|
.emplace_back();
|
|
|
|
|
|
|
|
ctx.at<sector_list_t>(0).at<ue_list_t>(0).at<antenna_list_t>(0).write<snr_t>(
|
|
|
|
ctx.at<sector_list_t>(0).at<ue_list_t>(0).get<antenna_list_t>().emplace_back();
|
|
|
|
5.1);
|
|
|
|
ctx.at<sector_list_t>(0).at<ue_list_t>(0).at<antenna_list_t>(1).write<snr_t>(10.1);
|
|
|
|
ctx.at<sector_list_t>(0).at<ue_list_t>(0).at<antenna_list_t>(0).write<pwr_t>(
|
|
|
|
ctx.at<sector_list_t>(0).at<ue_list_t>(0).at<antenna_list_t>(1).write<pwr_t>(-20.5);
|
|
|
|
-11.5);
|
|
|
|
|
|
|
|
|
|
|
|
ctx.at<sector_list_t>(0).at<ue_list_t>(1).get<antenna_list_t>().emplace_back();
|
|
|
|
ctx.at<sector_list_t>(0)
|
|
|
|
ctx.at<sector_list_t>(0).at<ue_list_t>(1).at<antenna_list_t>(0).write<snr_t>(20.1);
|
|
|
|
.at<ue_list_t>(0)
|
|
|
|
ctx.at<sector_list_t>(0).at<ue_list_t>(1).at<antenna_list_t>(0).write<pwr_t>(-30.5);
|
|
|
|
.get<antenna_list_t>()
|
|
|
|
ctx.at<sector_list_t>(0).at<ue_list_t>(1).get<antenna_list_t>().emplace_back();
|
|
|
|
.emplace_back();
|
|
|
|
ctx.at<sector_list_t>(0).at<ue_list_t>(1).at<antenna_list_t>(1).write<snr_t>(30.1);
|
|
|
|
ctx.at<sector_list_t>(0).at<ue_list_t>(0).at<antenna_list_t>(1).write<snr_t>(
|
|
|
|
ctx.at<sector_list_t>(0).at<ue_list_t>(1).at<antenna_list_t>(1).write<pwr_t>(-40.5);
|
|
|
|
10.1);
|
|
|
|
|
|
|
|
ctx.at<sector_list_t>(0).at<ue_list_t>(0).at<antenna_list_t>(1).write<pwr_t>(
|
|
|
|
|
|
|
|
-20.5);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ctx.at<sector_list_t>(0)
|
|
|
|
|
|
|
|
.at<ue_list_t>(1)
|
|
|
|
|
|
|
|
.get<antenna_list_t>()
|
|
|
|
|
|
|
|
.emplace_back();
|
|
|
|
|
|
|
|
ctx.at<sector_list_t>(0).at<ue_list_t>(1).at<antenna_list_t>(0).write<snr_t>(
|
|
|
|
|
|
|
|
20.1);
|
|
|
|
|
|
|
|
ctx.at<sector_list_t>(0).at<ue_list_t>(1).at<antenna_list_t>(0).write<pwr_t>(
|
|
|
|
|
|
|
|
-30.5);
|
|
|
|
|
|
|
|
ctx.at<sector_list_t>(0)
|
|
|
|
|
|
|
|
.at<ue_list_t>(1)
|
|
|
|
|
|
|
|
.get<antenna_list_t>()
|
|
|
|
|
|
|
|
.emplace_back();
|
|
|
|
|
|
|
|
ctx.at<sector_list_t>(0).at<ue_list_t>(1).at<antenna_list_t>(1).write<snr_t>(
|
|
|
|
|
|
|
|
30.1);
|
|
|
|
|
|
|
|
ctx.at<sector_list_t>(0).at<ue_list_t>(1).at<antenna_list_t>(1).write<pwr_t>(
|
|
|
|
|
|
|
|
-40.5);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ctx;
|
|
|
|
return ctx;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool
|
|
|
|
static bool when_log_entry_with_only_context_is_passed_then_context_is_formatted()
|
|
|
|
when_log_entry_with_only_context_is_passed_then_context_is_formatted()
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
auto ctx = build_complex_context();
|
|
|
|
auto ctx = build_complex_context();
|
|
|
|
auto entry = build_log_entry_metadata();
|
|
|
|
auto entry = build_log_entry_metadata(nullptr);
|
|
|
|
entry.fmtstring = nullptr;
|
|
|
|
entry.fmtstring = nullptr;
|
|
|
|
|
|
|
|
|
|
|
|
fmt::memory_buffer buffer;
|
|
|
|
fmt::memory_buffer buffer;
|
|
|
|
text_formatter{}.format_ctx(ctx, std::move(entry), buffer);
|
|
|
|
text_formatter{}.format_ctx(ctx, std::move(entry), buffer);
|
|
|
|
std::string result = fmt::to_string(buffer);
|
|
|
|
std::string result = fmt::to_string(buffer);
|
|
|
|
std::string expected = "00:00:00.050000 [ABC ] [Z] [ 10] Context dump for "
|
|
|
|
std::string expected = "00:00:00.050000 [ABC ] [Z] [ 10] Context dump for "
|
|
|
|
"\"Complex Context\"\n"
|
|
|
|
"\"Complex Context\"\n"
|
|
|
|
" > List: sector_list\n"
|
|
|
|
" > List: sector_list\n"
|
|
|
@ -230,22 +209,21 @@ when_log_entry_with_only_context_is_passed_then_context_is_formatted()
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool
|
|
|
|
static bool when_log_entry_with_context_and_message_is_passed_then_context_is_formatted()
|
|
|
|
when_log_entry_with_context_and_message_is_passed_then_context_is_formatted()
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
auto entry = build_log_entry_metadata();
|
|
|
|
fmt::dynamic_format_arg_store<fmt::printf_context> store;
|
|
|
|
auto ctx = build_complex_context();
|
|
|
|
auto entry = build_log_entry_metadata(&store);
|
|
|
|
|
|
|
|
auto ctx = build_complex_context();
|
|
|
|
|
|
|
|
|
|
|
|
fmt::memory_buffer buffer;
|
|
|
|
fmt::memory_buffer buffer;
|
|
|
|
text_formatter{}.format_ctx(ctx, std::move(entry), buffer);
|
|
|
|
text_formatter{}.format_ctx(ctx, std::move(entry), buffer);
|
|
|
|
std::string result = fmt::to_string(buffer);
|
|
|
|
std::string result = fmt::to_string(buffer);
|
|
|
|
std::string expected =
|
|
|
|
std::string expected = "00:00:00.050000 [ABC ] [Z] [ 10] [[sector_metrics_type: event, "
|
|
|
|
"00:00:00.050000 [ABC ] [Z] [ 10] [[sector_metrics_type: event, "
|
|
|
|
"sector_metrics_sector_id: 1, [ue_container_Throughput: 1.2 MB/s, "
|
|
|
|
"sector_metrics_sector_id: 1, [ue_container_Throughput: 1.2 MB/s, "
|
|
|
|
"ue_container_Address: 10.20.30.40, [RF_SNR: 5.1 dB, RF_PWR: -11 "
|
|
|
|
"ue_container_Address: 10.20.30.40, [RF_SNR: 5.1 dB, RF_PWR: -11 "
|
|
|
|
"dBm][RF_SNR: 10.1 dB, RF_PWR: -20 dBm]][ue_container_Throughput: 10.2 "
|
|
|
|
"dBm][RF_SNR: 10.1 dB, RF_PWR: -20 dBm]][ue_container_Throughput: 10.2 "
|
|
|
|
"MB/s, ue_container_Address: 10.20.30.41, [RF_SNR: 20.1 dB, RF_PWR: -30 "
|
|
|
|
"MB/s, ue_container_Address: 10.20.30.41, [RF_SNR: 20.1 dB, RF_PWR: -30 "
|
|
|
|
"dBm][RF_SNR: 30.1 dB, RF_PWR: -40 dBm]]]]: Text 88\n";
|
|
|
|
"dBm][RF_SNR: 30.1 dB, RF_PWR: -40 dBm]]]]: Text 88\n";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(result, expected);
|
|
|
|
ASSERT_EQ(result, expected);
|
|
|
|
|
|
|
|
|
|
|
@ -255,17 +233,12 @@ when_log_entry_with_context_and_message_is_passed_then_context_is_formatted()
|
|
|
|
int main()
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
TEST_FUNCTION(when_fully_filled_log_entry_then_everything_is_formatted);
|
|
|
|
TEST_FUNCTION(when_fully_filled_log_entry_then_everything_is_formatted);
|
|
|
|
TEST_FUNCTION(
|
|
|
|
TEST_FUNCTION(when_log_entry_without_name_is_passed_then_name_is_not_formatted);
|
|
|
|
when_log_entry_without_name_is_passed_then_name_is_not_formatted);
|
|
|
|
|
|
|
|
TEST_FUNCTION(when_log_entry_without_tag_is_passed_then_tag_is_not_formatted);
|
|
|
|
TEST_FUNCTION(when_log_entry_without_tag_is_passed_then_tag_is_not_formatted);
|
|
|
|
TEST_FUNCTION(
|
|
|
|
TEST_FUNCTION(when_log_entry_without_context_is_passed_then_context_is_not_formatted);
|
|
|
|
when_log_entry_without_context_is_passed_then_context_is_not_formatted);
|
|
|
|
TEST_FUNCTION(when_log_entry_with_hex_dump_is_passed_then_hex_dump_is_formatted);
|
|
|
|
TEST_FUNCTION(
|
|
|
|
TEST_FUNCTION(when_log_entry_with_only_context_is_passed_then_context_is_formatted);
|
|
|
|
when_log_entry_with_hex_dump_is_passed_then_hex_dump_is_formatted);
|
|
|
|
TEST_FUNCTION(when_log_entry_with_context_and_message_is_passed_then_context_is_formatted);
|
|
|
|
TEST_FUNCTION(
|
|
|
|
|
|
|
|
when_log_entry_with_only_context_is_passed_then_context_is_formatted);
|
|
|
|
|
|
|
|
TEST_FUNCTION(
|
|
|
|
|
|
|
|
when_log_entry_with_context_and_message_is_passed_then_context_is_formatted);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|