1+ #include < gmock/gmock.h>
12#include < gtest/gtest.h>
23
34#include " kernel/yosys.h"
@@ -11,4 +12,38 @@ TEST(KernelLogTest, logvValidValues)
1112 EXPECT_EQ (7 , 7 );
1213}
1314
15+ class TestSink : public LogSink {
16+ public:
17+ void log (const LogMessage& message) override {
18+ messages_.push_back (message);
19+ }
20+ std::vector<LogMessage> messages_;
21+ };
22+
23+ TEST (KernelLogTest, logToSink)
24+ {
25+ TestSink sink;
26+ log_sinks.push_back (&sink);
27+ log (" test info log" );
28+ log_warning (" test warning log" );
29+
30+ std::vector<LogMessage> expected{
31+ LogMessage (LogSeverity::LOG_INFO, " test info log" ),
32+ LogMessage (LogSeverity::LOG_WARNING, " test warning log" ),
33+ };
34+ // Certain calls to the log.h interface may prepend a string to
35+ // the provided string. We should ensure that the expected string
36+ // is a subset of the actual string. Additionally, we don't want to
37+ // compare timestamps. So, we use a custom comparator.
38+ for (const LogMessage& expected_msg : expected) {
39+ EXPECT_THAT (sink.messages_ , ::testing::Contains (::testing::Truly (
40+ [&](const LogMessage& actual) {
41+ return actual.severity == expected_msg.severity &&
42+ actual.message .find (expected_msg.message ) != std::string::npos;
43+ }
44+ )));
45+ }
46+ EXPECT_NE (sink.messages_ [0 ].timestamp , 0 );
47+ }
48+
1449YOSYS_NAMESPACE_END
0 commit comments