29#include <gtest/gtest.h>
57 "Exclusive debug flag for the trace tests");
65 auto buf =
os.rdbuf();
66 std::ostringstream oss;
79TEST(TraceTest, LogSimpleMessage)
85 ASSERT_EQ(
getString(&logger),
" 100: Test message");
89TEST(TraceTest, LogMessageName)
95 ASSERT_EQ(
getString(&logger),
" 100: Foo: Test message");
99TEST(TraceTest, LogMessageMaxTick)
101 std::stringstream
ss;
105 ASSERT_EQ(
getString(&logger),
"Foo: Test message");
109TEST(TraceTest, LogMessageFlagDisabled)
111 std::stringstream
ss;
115 ASSERT_EQ(
getString(&logger),
" 100: Foo: Test message");
122TEST(TraceTest, LogMessageTickDisabledAndEnableDisable)
124 std::stringstream
ss;
128 ASSERT_EQ(
getString(&logger),
" 100: Foo: Test message");
135 ASSERT_EQ(
getString(&logger),
"Foo: Test message");
137 ASSERT_EQ(
getString(&logger),
" 200: Foo: Test message");
144 ASSERT_EQ(
getString(&logger),
" 300: Foo: Test message");
151TEST(TraceTest, LogMessageFlagEnabled)
153 std::stringstream
ss;
160 ASSERT_EQ(
getString(&logger),
" 100: Bar: Foo: Test message");
162 ASSERT_EQ(
getString(&logger),
" 100: Foo: Test message");
170TEST(TraceTest, LogMessageActivateOne)
172 std::stringstream
ss;
181 ASSERT_EQ(
getString(&logger),
" 100: Foo: Test message");
190 ASSERT_EQ(
getString(&logger),
" 100: Bar: Test message");
194TEST(TraceTest, LogMessageActivateMultiple)
196 std::stringstream
ss;
207 ASSERT_EQ(
getString(&logger),
" 100: Foo: Test message");
209 ASSERT_EQ(
getString(&logger),
" 100: Bar: Test message");
221 ASSERT_EQ(
getString(&logger),
" 100: Thy: Test message");
225TEST(TraceTest, LogMessageIgnoreOne)
227 std::stringstream
ss;
238 ASSERT_EQ(
getString(&logger),
" 100: Bar: Test message");
243 ASSERT_EQ(
getString(&logger),
" 100: Foo: Test message");
249TEST(TraceTest, LogMessageIgnoreMultiple)
251 std::stringstream
ss;
266 ASSERT_EQ(
getString(&logger),
" 100: Thy: Test message");
272 ASSERT_EQ(
getString(&logger),
" 100: Foo: Test message");
274 ASSERT_EQ(
getString(&logger),
" 100: Bar: Test message");
280TEST(TraceTest, LogMessageActivateAndIgnore)
282 std::stringstream
ss;
292 ASSERT_EQ(
getString(&logger),
" 100: Foo: Test message");
304 std::stringstream
ss;
309 std::string message =
"Test message";
310 logger.
dump(
Tick(100),
"Foo", message.c_str(), message.size(),
"");
323 std::stringstream
ss;
328 std::string message =
"Test message";
329 logger.
dump(
Tick(100),
"Foo", message.c_str(), message.size(),
"Bar");
337 "54 65 73 74 20 6d 65 73 73 61 67 65 "
347 "54 65 73 74 20 6d 65 73 73 61 67 65 "
361 std::stringstream
ss;
364 std::string message =
365 "This is a very long line that will span over multiple lines";
366 logger.
dump(
Tick(100),
"Foo", message.c_str(), message.size(),
"");
368 " 100: Foo: 00000000 "
369 "54 68 69 73 20 69 73 20 61 20 76 65 72 79 20 6c This is a very l\n"
370 " 100: Foo: 00000010 "
371 "6f 6e 67 20 6c 69 6e 65 20 74 68 61 74 20 77 69 ong line that wi\n"
372 " 100: Foo: 00000020 "
373 "6c 6c 20 73 70 61 6e 20 6f 76 65 72 20 6d 75 6c ll span over mul\n"
374 " 100: Foo: 00000030 "
375 "74 69 70 6c 65 20 6c 69 6e 65 73 tiple lines\n");
382TEST(TraceTest, DISABLED_GetNullLogger)
385 ASSERT_FALSE(logger ==
nullptr);
404 ASSERT_EQ(
getString(logger_from_getter),
" 100: Foo: Test message");
415TEST(TraceTest, DprintfFlagIgnore)
417 std::stringstream
ss;
427TEST(TraceTest, DprintfFlagZeroArgs)
429 std::stringstream
ss;
433 ASSERT_EQ(
getString(&logger),
" 100: Foo: Test message");
437TEST(TraceTest, DprintfFlagOneArg)
439 std::stringstream
ss;
443 ASSERT_EQ(
getString(&logger),
" 100: Foo: Test message");
447TEST(TraceTest, DprintfFlagMultipleArgs)
449 std::stringstream
ss;
453 "message",
'A', 217, 0x30);
454 ASSERT_EQ(
getString(&logger),
" 100: Foo: Test message A 217 30");
458TEST(TraceTest, DprintfFlagEnabled)
460 std::stringstream
ss;
467 ASSERT_EQ(
getString(&logger),
" 100: Bar: Foo: Test message");
469 ASSERT_EQ(
getString(&logger),
" 100: Foo: Test message");
478 std::stringstream
ss;
490 std::stringstream
ss;
495 logger.
dprintf(
Tick(100),
"Foo",
"Test %s",
"message");
496 ASSERT_EQ(
getString(&logger),
" 100: Foo: Test message");
504 std::stringstream
ss, ss_flag;
508 logger.
dprintf(
Tick(100),
"Foo",
"Test %s %c %d %x",
509 "message",
'A', 217, 0x30);
511 "message",
'A', 217, 0x30);
519 std::string message =
"Test message";
525 DDUMP(TraceTestDebugFlag, message.c_str(), message.size());
528 " 0: TraceTestDebugFlag: Foo: 00000000 "
529 "54 65 73 74 20 6d 65 73 73 61 67 65 Test message\n");
537 DDUMP(TraceTestDebugFlag, message.c_str(), message.size());
550 DPRINTF(TraceTestDebugFlag,
"Test message");
553 " 0: TraceTestDebugFlag: Foo: Test message");
561 DPRINTF(TraceTestDebugFlag,
"Test message");
570 Named *named_ptr = &named;
578 DPRINTFS(TraceTestDebugFlag, named_ptr,
"Test message");
580 " 0: TraceTestDebugFlag: Foo: Test message");
587 DPRINTFS(TraceTestDebugFlag, named_ptr,
"Test message");
599 DPRINTFR(TraceTestDebugFlag,
"Test message");
609 DPRINTFR(TraceTestDebugFlag,
"Test message");
637TEST(TraceTest, MacroDPRINTF_UNCONDITIONAL)
648 " 0: TraceTestDebugFlag: Foo: Test message");
674 DPRINTF(TraceTestDebugFlag,
"Test message");
677 " 0: TraceTestDebugFlag: global: Test message");
685 DPRINTF(TraceTestDebugFlag,
"Test message");
#define DPRINTFS(x, s,...)
#define DDUMP(x, data, count)
DPRINTF is a debugging trace facility that allows one to selectively enable tracing statements.
Interface for things with names.
ObjectMatch contains a vector of expressions.
Debug logging base class.
void setIgnore(ObjectMatch &ignore_)
Set objects to ignore.
void addActivate(const ObjectMatch &activate_)
Add objects to activate.
void dprintf_flag(Tick when, const std::string &name, const std::string &flag, const char *fmt, const Args &...args)
Log a single message with a flag prefix.
void addIgnore(const ObjectMatch &ignore_)
Add objects to ignore.
virtual std::ostream & getOstream()=0
Return an ostream that can be used to send messages to the 'same place' as formatted logMessage messa...
void setActivate(ObjectMatch &activate_)
Set objects to activate.
virtual void logMessage(Tick when, const std::string &name, const std::string &flag, const std::string &message)=0
Log formatted message.
void dump(Tick when, const std::string &name, const void *d, int len, const std::string &flag)
Dump a block of data of length len.
void dprintf(Tick when, const std::string &name, const char *fmt, const Args &...args)
Log a single message.
Logging wrapper for ostreams with the format: <when>: <name>: <message-body>
void logMessage(Tick when, const std::string &name, const std::string &flag, const std::string &message) override
Log formatted message.
#define DPRINTF_UNCONDITIONAL(x,...)
bool changeFlag(const char *s, bool value)
SimpleFlag TraceTestDebugFlag("TraceTestDebugFlag", "Exclusive debug flag for the trace tests")
Debug flag used for the tests in this file.
void enable()
Enable/disable debug logging.
void setDebugLogger(Logger *logger)
Delete the current global logger and assign a new one.
Logger * getDebugLogger()
Get the current global debug logger.
std::ostream & output()
Get the ostream from the current global logger.
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
uint64_t Tick
Tick count type.
thread_local GTestLogOutput gtestLogOutput
const std::string & name()
std::string getString(std::ostream &os)
trace::OstreamLogger main_logger(ss)
TEST(TraceTest, LogSimpleMessage)
Test creating a simple log message.
GTestTickHandler tickHandler