You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
srsRAN_4G/lib/test/srslog/event_trace_test.cpp

86 lines
1.9 KiB
C++

/**
*
* \section COPYRIGHT
*
* Copyright 2013-2021 Software Radio Systems Limited
*
* By using this file, you agree to the terms and conditions set
* forth in the LICENSE file which can be found at the top level of
* the distribution.
*
*/
#include "srsran/srslog/event_trace.h"
#include "srsran/srslog/log_channel.h"
#include "test_dummies.h"
#include "testing_helpers.h"
using namespace srslog;
namespace {
/// A Spy implementation of a log backend. Tests can query if the push method
/// has been invoked.
class backend_spy : public detail::log_backend
{
public:
void start() override {}
bool push(detail::log_entry&& entry) override
{
++count;
return true;
}
fmt::dynamic_format_arg_store<fmt::printf_context>* alloc_arg_store() override { return &store; }
bool is_running() const override { return true; }
void reset() { count = 0; }
unsigned push_invocation_count() const { return count; }
private:
unsigned count = 0;
fmt::dynamic_format_arg_store<fmt::printf_context> store;
};
} // namespace
static bool when_tracing_with_duration_event_then_two_events_are_generated(backend_spy& spy)
{
trace_duration_begin("a", "b");
ASSERT_EQ(spy.push_invocation_count(), 1);
trace_duration_end("a", "b");
ASSERT_EQ(spy.push_invocation_count(), 2);
return true;
}
static bool when_tracing_with_complete_event_then_one_event_is_generated(backend_spy& spy)
{
{
trace_complete_event("a", "b");
}
ASSERT_EQ(spy.push_invocation_count(), 1);
return true;
}
int main()
{
test_dummies::sink_dummy s;
backend_spy backend;
log_channel c("test", s, backend);
// Inject our spy into the framework.
event_trace_init(c);
TEST_FUNCTION(when_tracing_with_duration_event_then_two_events_are_generated, backend);
backend.reset();
TEST_FUNCTION(when_tracing_with_complete_event_then_one_event_is_generated, backend);
return 0;
}