Loading base/include/android-base/logging.h +27 −20 Original line number Diff line number Diff line Loading @@ -120,10 +120,22 @@ class ErrnoRestorer { DISALLOW_COPY_AND_ASSIGN(ErrnoRestorer); }; // A helper macro that produces an expression that accepts both a qualified name and an // unqualified name for a LogSeverity, and returns a LogSeverity value. // Note: DO NOT USE DIRECTLY. This is an implementation detail. #define SEVERITY_LAMBDA(severity) ([&]() { \ using ::android::base::VERBOSE; \ using ::android::base::DEBUG; \ using ::android::base::INFO; \ using ::android::base::WARNING; \ using ::android::base::ERROR; \ using ::android::base::FATAL_WITHOUT_ABORT; \ using ::android::base::FATAL; \ return (severity); }()) // Defines whether the given severity will be logged or silently swallowed. #define WOULD_LOG(severity) WOULD_LOG_SEVERITY(::android::base::severity) #define WOULD_LOG_SEVERITY(severity) \ UNLIKELY((severity) >= ::android::base::GetMinimumLogSeverity()) #define WOULD_LOG(severity) \ UNLIKELY((SEVERITY_LAMBDA(severity)) >= ::android::base::GetMinimumLogSeverity()) // Get an ostream that can be used for logging at the given severity and to the default // destination. Loading @@ -132,23 +144,20 @@ class ErrnoRestorer { // 1) This will not check whether the severity is high enough. One should use WOULD_LOG to filter // usage manually. // 2) This does not save and restore errno. #define LOG_STREAM(severity) LOG_STREAM_S(::android::base::severity) #define LOG_STREAM_S(severity) LOG_STREAM_TO_S(DEFAULT, severity) #define LOG_STREAM(severity) LOG_STREAM_TO(DEFAULT, severity) // Get an ostream that can be used for logging at the given severity and to the // given destination. The same notes as for LOG_STREAM apply. #define LOG_STREAM_TO(dest, severity) LOG_STREAM_TO_S(dest, ::android::base::severity) #define LOG_STREAM_TO_S(dest, severity) \ #define LOG_STREAM_TO(dest, severity) \ ::android::base::LogMessage(__FILE__, __LINE__, \ ::android::base::dest, \ severity, -1).stream() SEVERITY_LAMBDA(severity), -1).stream() // Logs a message to logcat on Android otherwise to stderr. If the severity is // FATAL it also causes an abort. For example: // // LOG(FATAL) << "We didn't expect to reach here"; #define LOG(severity) LOG_S(::android::base::severity) #define LOG_S(severity) LOG_TO_S(DEFAULT, severity) #define LOG(severity) LOG_TO(DEFAULT, severity) // Logs a message to logcat with the specified log ID on Android otherwise to // stderr. If the severity is FATAL it also causes an abort. Loading @@ -156,25 +165,23 @@ class ErrnoRestorer { // else statement after LOG() macro, it won't bind to the if statement in the macro. // do-while(0) statement doesn't work here. Because we need to support << operator // following the macro, like "LOG(DEBUG) << xxx;". #define LOG_TO(dest, severity) LOG_TO_S(dest, ::android::base::severity) #define LOG_TO_S(dest, severity) \ WOULD_LOG_SEVERITY(severity) && \ #define LOG_TO(dest, severity) \ WOULD_LOG(severity) && \ ::android::base::ErrnoRestorer() && \ LOG_STREAM_TO_S(dest, severity) \ LOG_STREAM_TO(dest, severity) // A variant of LOG that also logs the current errno value. To be used when // library calls fail. #define PLOG(severity) PLOG_S(::android::base::severity) #define PLOG_S(severity) PLOG_TO_S(DEFAULT, severity) #define PLOG(severity) PLOG_TO(DEFAULT, severity) // Behaves like PLOG, but logs to the specified log ID. #define PLOG_TO(dest, severity) PLOG_TO_S(dest, ::android::base::severity) #define PLOG_TO_S(dest, severity) \ WOULD_LOG_SEVERITY(severity) && \ #define PLOG_TO(dest, severity) \ WOULD_LOG(SEVERITY_LAMBDA(severity)) && \ ::android::base::ErrnoRestorer() && \ ::android::base::LogMessage(__FILE__, __LINE__, \ ::android::base::dest, \ severity, errno).stream() SEVERITY_LAMBDA(severity), errno).stream() // Marker that code is yet to be implemented. #define UNIMPLEMENTED(level) \ Loading base/logging.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -391,7 +391,7 @@ LogMessage::LogMessage(const char* file, unsigned int line, LogId id, LogMessage::~LogMessage() { // Check severity again. This is duplicate work wrt/ LOG macros, but not LOG_STREAM. if (!WOULD_LOG_SEVERITY(data_->GetSeverity())) { if (!WOULD_LOG(data_->GetSeverity())) { return; } Loading base/logging_test.cpp +113 −353 Original line number Diff line number Diff line Loading @@ -142,22 +142,35 @@ TEST(logging, DCHECK) { // we don't get more bit-rot). } #define CHECK_WOULD_LOG_DISABLED(severity) \ static_assert(android::base::severity < android::base::FATAL, "Bad input"); \ for (size_t i = static_cast<size_t>(android::base::severity) + 1; \ i <= static_cast<size_t>(android::base::FATAL); \ ++i) { \ { \ android::base::ScopedLogSeverity sls2(static_cast<android::base::LogSeverity>(i)); \ EXPECT_FALSE(WOULD_LOG(severity)) << i; \ } } \ { \ android::base::ScopedLogSeverity sls2(static_cast<android::base::LogSeverity>(i)); \ EXPECT_FALSE(WOULD_LOG(::android::base::severity)) << i; \ } \ } \ #define CHECK_WOULD_LOG_ENABLED(severity) \ for (size_t i = static_cast<size_t>(android::base::VERBOSE); \ i <= static_cast<size_t>(android::base::severity); \ ++i) { \ { \ android::base::ScopedLogSeverity sls2(static_cast<android::base::LogSeverity>(i)); \ EXPECT_TRUE(WOULD_LOG(severity)) << i; \ } } \ { \ android::base::ScopedLogSeverity sls2(static_cast<android::base::LogSeverity>(i)); \ EXPECT_TRUE(WOULD_LOG(::android::base::severity)) << i; \ } \ } \ TEST(logging, WOULD_LOG_FATAL) { CHECK_WOULD_LOG_ENABLED(FATAL); Loading Loading @@ -215,78 +228,6 @@ TEST(logging, WOULD_LOG_VERBOSE_enabled) { #undef CHECK_WOULD_LOG_ENABLED #define CHECK_WOULD_LOG_SEVERITY_DISABLED(severity) \ static_assert(android::base::severity < android::base::FATAL, "Bad input"); \ for (size_t i = static_cast<size_t>(android::base::severity) + 1; \ i <= static_cast<size_t>(android::base::FATAL); \ ++i) { \ android::base::ScopedLogSeverity sls2(static_cast<android::base::LogSeverity>(i)); \ EXPECT_FALSE(WOULD_LOG_SEVERITY(::android::base::severity)) << i; \ } #define CHECK_WOULD_LOG_SEVERITY_ENABLED(severity) \ for (size_t i = static_cast<size_t>(android::base::VERBOSE); \ i <= static_cast<size_t>(android::base::severity); \ ++i) { \ android::base::ScopedLogSeverity sls2(static_cast<android::base::LogSeverity>(i)); \ EXPECT_TRUE(WOULD_LOG_SEVERITY(::android::base::severity)) << i; \ } TEST(logging,WOULD_LOG_SEVERITY_FATAL) { CHECK_WOULD_LOG_SEVERITY_ENABLED(FATAL); } TEST(logging,WOULD_LOG_SEVERITY_FATAL_WITHOUT_ABORT_disabled) { CHECK_WOULD_LOG_SEVERITY_DISABLED(FATAL_WITHOUT_ABORT); } TEST(logging, WOULD_LOG_SEVERITY_FATAL_WITHOUT_ABORT_enabled) { CHECK_WOULD_LOG_SEVERITY_ENABLED(FATAL_WITHOUT_ABORT); } TEST(logging, WOULD_LOG_SEVERITY_ERROR_disabled) { CHECK_WOULD_LOG_SEVERITY_DISABLED(ERROR); } TEST(logging, WOULD_LOG_SEVERITY_ERROR_enabled) { CHECK_WOULD_LOG_SEVERITY_ENABLED(ERROR); } TEST(logging, WOULD_LOG_SEVERITY_WARNING_disabled) { CHECK_WOULD_LOG_SEVERITY_DISABLED(WARNING); } TEST(logging, WOULD_LOG_SEVERITY_WARNING_enabled) { CHECK_WOULD_LOG_SEVERITY_ENABLED(WARNING); } TEST(logging, WOULD_LOG_SEVERITY_INFO_disabled) { CHECK_WOULD_LOG_SEVERITY_DISABLED(INFO); } TEST(logging, WOULD_LOG_SEVERITY_INFO_enabled) { CHECK_WOULD_LOG_SEVERITY_ENABLED(INFO); } TEST(logging, WOULD_LOG_SEVERITY_DEBUG_disabled) { CHECK_WOULD_LOG_SEVERITY_DISABLED(DEBUG); } TEST(logging, WOULD_LOG_SEVERITY_DEBUG_enabled) { CHECK_WOULD_LOG_SEVERITY_ENABLED(DEBUG); } TEST(logging, WOULD_LOG_SEVERITYVERBOSE_disabled) { CHECK_WOULD_LOG_SEVERITY_DISABLED(VERBOSE); } TEST(logging, WOULD_LOG_SEVERITY_VERBOSE_enabled) { CHECK_WOULD_LOG_SEVERITY_ENABLED(VERBOSE); } #undef CHECK_WOULD_LOG_SEVERITY_DISABLED #undef CHECK_WOULD_LOG_SEVERITY_ENABLED static std::string make_log_pattern(android::base::LogSeverity severity, const char* message) { static const char log_characters[] = "VDIWEFF"; Loading Loading @@ -317,17 +258,34 @@ static void CheckMessage(const CapturedStderr& cap, #endif } #define CHECK_LOG_STREAM_DISABLED(severity) \ { \ android::base::ScopedLogSeverity sls1(android::base::FATAL); \ CapturedStderr cap1; \ LOG_STREAM(severity) << "foo bar"; \ ASSERT_EQ(0, lseek(cap1.fd(), 0, SEEK_CUR)); ASSERT_EQ(0, lseek(cap1.fd(), 0, SEEK_CUR)); \ } \ { \ android::base::ScopedLogSeverity sls1(android::base::FATAL); \ CapturedStderr cap1; \ LOG_STREAM(::android::base::severity) << "foo bar"; \ ASSERT_EQ(0, lseek(cap1.fd(), 0, SEEK_CUR)); \ } \ #define CHECK_LOG_STREAM_ENABLED(severity) \ { \ android::base::ScopedLogSeverity sls2(android::base::severity); \ CapturedStderr cap2; \ LOG_STREAM(severity) << "foobar"; \ CheckMessage(cap2, android::base::severity, "foobar"); \ } \ { \ android::base::ScopedLogSeverity sls2(android::base::severity); \ CapturedStderr cap2; \ LOG_STREAM(::android::base::severity) << "foobar"; \ CheckMessage(cap2, android::base::severity, "foobar"); \ } \ TEST(logging, LOG_STREAM_FATAL_WITHOUT_ABORT_disabled) { CHECK_LOG_STREAM_DISABLED(FATAL_WITHOUT_ABORT); Loading Loading @@ -380,84 +338,38 @@ TEST(logging, LOG_STREAM_VERBOSE_enabled) { #undef CHECK_LOG_STREAM_DISABLED #undef CHECK_LOG_STREAM_ENABLED #define CHECK_LOG_STREAM_S_DISABLED(severity) \ android::base::ScopedLogSeverity sls1(android::base::FATAL); \ CapturedStderr cap1; \ LOG_STREAM_S(android::base::severity) << "foobar"; \ ASSERT_EQ(0, lseek(cap1.fd(), 0, SEEK_CUR)); #define CHECK_LOG_STREAM_S_ENABLED(severity) \ android::base::ScopedLogSeverity sls2(android::base::severity); \ CapturedStderr cap2; \ LOG_STREAM_S(android::base::severity) << "foobar"; \ CheckMessage(cap2, android::base::severity, "foobar"); \ TEST(logging, LOG_STREAM_S_FATAL_WITHOUT_ABORT_disabled) { CHECK_LOG_STREAM_S_DISABLED(FATAL_WITHOUT_ABORT); } TEST(logging, LOG_STREAM_S_FATAL_WITHOUT_ABORT_enabled) { CHECK_LOG_STREAM_S_ENABLED(FATAL_WITHOUT_ABORT); } TEST(logging, LOG_STREAM_S_ERROR_disabled) { CHECK_LOG_STREAM_S_DISABLED(ERROR); } TEST(logging, LOG_STREAM_S_ERROR_enabled) { CHECK_LOG_STREAM_S_ENABLED(ERROR); } TEST(logging, LOG_STREAM_S_WARNING_disabled) { CHECK_LOG_STREAM_S_DISABLED(WARNING); } TEST(logging, LOG_STREAM_S_WARNING_enabled) { CHECK_LOG_STREAM_S_ENABLED(WARNING); } TEST(logging, LOG_STREAM_S_INFO_disabled) { CHECK_LOG_STREAM_S_DISABLED(INFO); } TEST(logging, LOG_STREAM_S_INFO_enabled) { CHECK_LOG_STREAM_S_ENABLED(INFO); } TEST(logging, LOG_STREAM_S_DEBUG_disabled) { CHECK_LOG_STREAM_S_DISABLED(DEBUG); } TEST(logging, LOG_STREAM_S_DEBUG_enabled) { CHECK_LOG_STREAM_S_ENABLED(DEBUG); } TEST(logging, LOG_STREAM_S_VERBOSE_disabled) { CHECK_LOG_STREAM_S_DISABLED(VERBOSE); } TEST(logging, LOG_STREAM_S_VERBOSE_enabled) { CHECK_LOG_STREAM_S_ENABLED(VERBOSE); } #undef CHECK_LOG_STREAM_S_DISABLED #undef CHECK_LOG_STREAM_S_ENABLED #define CHECK_LOG_DISABLED(severity) \ { \ android::base::ScopedLogSeverity sls1(android::base::FATAL); \ CapturedStderr cap1; \ LOG(severity) << "foo bar"; \ ASSERT_EQ(0, lseek(cap1.fd(), 0, SEEK_CUR)); \ } \ { \ android::base::ScopedLogSeverity sls1(android::base::FATAL); \ CapturedStderr cap1; \ LOG(::android::base::severity) << "foo bar"; \ ASSERT_EQ(0, lseek(cap1.fd(), 0, SEEK_CUR)); \ } \ #define CHECK_LOG_ENABLED(severity) \ { \ android::base::ScopedLogSeverity sls2(android::base::severity); \ CapturedStderr cap2; \ LOG(severity) << "foobar"; \ CheckMessage(cap2, android::base::severity, "foobar"); \ } \ { \ android::base::ScopedLogSeverity sls2(android::base::severity); \ CapturedStderr cap2; \ LOG(::android::base::severity) << "foobar"; \ CheckMessage(cap2, android::base::severity, "foobar"); \ } \ TEST(logging, LOG_FATAL) { ASSERT_DEATH({SuppressAbortUI(); LOG(FATAL) << "foobar";}, "foobar"); ASSERT_DEATH({SuppressAbortUI(); LOG(::android::base::FATAL) << "foobar";}, "foobar"); } TEST(logging, LOG_FATAL_WITHOUT_ABORT_disabled) { Loading Loading @@ -511,80 +423,14 @@ TEST(logging, LOG_VERBOSE_enabled) { #undef CHECK_LOG_DISABLED #undef CHECK_LOG_ENABLED #define CHECK_LOG_S_DISABLED(severity) \ android::base::ScopedLogSeverity sls1(android::base::FATAL); \ CapturedStderr cap1; \ LOG_S(::android::base::severity) << "foo bar"; \ ASSERT_EQ(0, lseek(cap1.fd(), 0, SEEK_CUR)); \ #define CHECK_LOG_S_ENABLED(severity) \ android::base::ScopedLogSeverity sls2(android::base::severity); \ CapturedStderr cap2; \ LOG_S(::android::base::severity) << "foobar"; \ CheckMessage(cap2, android::base::severity, "foobar"); \ TEST(logging, LOG_S_FATAL) { ASSERT_DEATH({SuppressAbortUI(); LOG_S(::android::base::FATAL) << "foobar";}, "foobar"); } TEST(logging, LOG_S_FATAL_WITHOUT_ABORT_disabled) { CHECK_LOG_S_DISABLED(FATAL_WITHOUT_ABORT); } TEST(logging, LOG_S_FATAL_WITHOUT_ABORT_enabled) { CHECK_LOG_S_ENABLED(FATAL_WITHOUT_ABORT); } TEST(logging, LOG_S_ERROR_disabled) { CHECK_LOG_S_DISABLED(ERROR); } TEST(logging, LOG_S_ERROR_enabled) { CHECK_LOG_S_ENABLED(ERROR); } TEST(logging, LOG_S_WARNING_disabled) { CHECK_LOG_S_DISABLED(WARNING); } TEST(logging, LOG_S_WARNING_enabled) { CHECK_LOG_S_ENABLED(WARNING); } TEST(logging, LOG_S_INFO_disabled) { CHECK_LOG_S_DISABLED(INFO); } TEST(logging, LOG_S_INFO_enabled) { CHECK_LOG_S_ENABLED(INFO); } TEST(logging, LOG_S_DEBUG_disabled) { CHECK_LOG_S_DISABLED(DEBUG); } TEST(logging, LOG_S_DEBUG_enabled) { CHECK_LOG_S_ENABLED(DEBUG); } TEST(logging, LOG_S_VERBOSE_disabled) { CHECK_LOG_S_DISABLED(VERBOSE); } TEST(logging, LOG_S_VERBOSE_enabled) { CHECK_LOG_S_ENABLED(VERBOSE); } #undef CHECK_LOG_S_DISABLED #undef CHECK_LOG_S_ENABLED TEST(logging, LOG_S_complex_param) { #define CHECK_LOG_S_COMBINATION(use_scoped_log_severity_info, use_logging_severity_info) \ TEST(logging, LOG_complex_param) { #define CHECK_LOG_COMBINATION(use_scoped_log_severity_info, use_logging_severity_info) \ { \ android::base::ScopedLogSeverity sls( \ (use_scoped_log_severity_info) ? ::android::base::INFO : ::android::base::WARNING); \ CapturedStderr cap; \ LOG_S((use_logging_severity_info) ? ::android::base::INFO : ::android::base::WARNING) \ LOG((use_logging_severity_info) ? ::android::base::INFO : ::android::base::WARNING) \ << "foobar"; \ if ((use_scoped_log_severity_info) || !(use_logging_severity_info)) { \ CheckMessage(cap, \ Loading @@ -595,12 +441,12 @@ TEST(logging, LOG_S_complex_param) { } \ } CHECK_LOG_S_COMBINATION(false,false); CHECK_LOG_S_COMBINATION(false,true); CHECK_LOG_S_COMBINATION(true,false); CHECK_LOG_S_COMBINATION(true,true); CHECK_LOG_COMBINATION(false,false); CHECK_LOG_COMBINATION(false,true); CHECK_LOG_COMBINATION(true,false); CHECK_LOG_COMBINATION(true,true); #undef CHECK_LOG_S_COMBINATION #undef CHECK_LOG_COMBINATION } Loading @@ -613,15 +459,6 @@ TEST(logging, LOG_does_not_clobber_errno) { CheckMessage(cap, android::base::INFO, "67890"); } TEST(logging, LOG_S_does_not_clobber_errno) { CapturedStderr cap; errno = 12345; LOG_S(::android::base::INFO) << (errno = 67890); EXPECT_EQ(12345, errno) << "errno was not restored"; CheckMessage(cap, android::base::INFO, "67890"); } TEST(logging, PLOG_does_not_clobber_errno) { CapturedStderr cap; errno = 12345; Loading @@ -631,16 +468,6 @@ TEST(logging, PLOG_does_not_clobber_errno) { CheckMessage(cap, android::base::INFO, "67890"); } TEST(logging, PLOG_S_does_not_clobber_errno) { CapturedStderr cap; errno = 12345; PLOG_S(::android::base::INFO) << (errno = 67890); EXPECT_EQ(12345, errno) << "errno was not restored"; CheckMessage(cap, android::base::INFO, "67890"); } TEST(logging, LOG_does_not_have_dangling_if) { CapturedStderr cap; // So the logging below has no side-effects. Loading @@ -662,39 +489,41 @@ TEST(logging, LOG_does_not_have_dangling_if) { flag = true; EXPECT_FALSE(flag) << "LOG macro probably has a dangling if with no else"; flag = false; if (true) LOG_S(::android::base::INFO) << "foobar"; else flag = true; EXPECT_FALSE(flag) << "LOG_S macro probably has a dangling if with no else"; flag = false; if (true) LOG_S(::android::base::VERBOSE) << "foobar"; else flag = true; EXPECT_FALSE(flag) << "LOG_S macro probably has a dangling if with no else"; } #define CHECK_PLOG_DISABLED(severity) \ { \ android::base::ScopedLogSeverity sls1(android::base::FATAL); \ CapturedStderr cap1; \ PLOG(severity) << "foo bar"; \ ASSERT_EQ(0, lseek(cap1.fd(), 0, SEEK_CUR)); \ } \ { \ android::base::ScopedLogSeverity sls1(android::base::FATAL); \ CapturedStderr cap1; \ PLOG(severity) << "foo bar"; \ ASSERT_EQ(0, lseek(cap1.fd(), 0, SEEK_CUR)); \ } \ #define CHECK_PLOG_ENABLED(severity) \ { \ android::base::ScopedLogSeverity sls2(android::base::severity); \ CapturedStderr cap2; \ errno = ENOENT; \ PLOG(severity) << "foobar"; \ CheckMessage(cap2, android::base::severity, "foobar: No such file or directory"); \ } \ { \ android::base::ScopedLogSeverity sls2(android::base::severity); \ CapturedStderr cap2; \ errno = ENOENT; \ PLOG(severity) << "foobar"; \ CheckMessage(cap2, android::base::severity, "foobar: No such file or directory"); \ } \ TEST(logging, PLOG_FATAL) { ASSERT_DEATH({SuppressAbortUI(); PLOG(FATAL) << "foobar";}, "foobar"); ASSERT_DEATH({SuppressAbortUI(); PLOG(::android::base::FATAL) << "foobar";}, "foobar"); } TEST(logging, PLOG_FATAL_WITHOUT_ABORT_disabled) { Loading Loading @@ -749,75 +578,6 @@ TEST(logging, PLOG_VERBOSE_enabled) { #undef CHECK_PLOG_ENABLED #define CHECK_PLOG_S_DISABLED(severity) \ android::base::ScopedLogSeverity sls1(android::base::FATAL); \ CapturedStderr cap1; \ PLOG_S(android::base::severity) << "foo bar"; \ ASSERT_EQ(0, lseek(cap1.fd(), 0, SEEK_CUR)); \ #define CHECK_PLOG_S_ENABLED(severity) \ android::base::ScopedLogSeverity sls2(android::base::severity); \ CapturedStderr cap2; \ errno = ENOENT; \ PLOG_S(android::base::severity) << "foobar"; \ CheckMessage(cap2, android::base::severity, "foobar: No such file or directory"); \ TEST(logging, PLOG_S_FATAL) { ASSERT_DEATH({SuppressAbortUI(); PLOG_S(::android::base::FATAL) << "foobar";}, "foobar"); } TEST(logging, PLOG_S_FATAL_WITHOUT_ABORT_disabled) { CHECK_PLOG_S_DISABLED(FATAL_WITHOUT_ABORT); } TEST(logging, PLOG_S_FATAL_WITHOUT_ABORT_enabled) { CHECK_PLOG_S_ENABLED(FATAL_WITHOUT_ABORT); } TEST(logging, PLOG_S_ERROR_disabled) { CHECK_PLOG_S_DISABLED(ERROR); } TEST(logging, PLOG_S_ERROR_enabled) { CHECK_PLOG_S_ENABLED(ERROR); } TEST(logging, PLOG_S_WARNING_disabled) { CHECK_PLOG_S_DISABLED(WARNING); } TEST(logging, PLOG_S_WARNING_enabled) { CHECK_PLOG_S_ENABLED(WARNING); } TEST(logging, PLOG_S_INFO_disabled) { CHECK_PLOG_S_DISABLED(INFO); } TEST(logging, PLOG_S_INFO_enabled) { CHECK_PLOG_S_ENABLED(INFO); } TEST(logging, PLOG_S_DEBUG_disabled) { CHECK_PLOG_S_DISABLED(DEBUG); } TEST(logging, PLOG_S_DEBUG_enabled) { CHECK_PLOG_S_ENABLED(DEBUG); } TEST(logging, PLOG_S_VERBOSE_disabled) { CHECK_PLOG_S_DISABLED(VERBOSE); } TEST(logging, PLOG_S_VERBOSE_enabled) { CHECK_PLOG_S_ENABLED(VERBOSE); } #undef CHECK_PLOG_S_DISABLED #undef CHECK_PLOG_S_ENABLED TEST(logging, UNIMPLEMENTED) { std::string expected = android::base::StringPrintf("%s unimplemented ", __PRETTY_FUNCTION__); Loading Loading
base/include/android-base/logging.h +27 −20 Original line number Diff line number Diff line Loading @@ -120,10 +120,22 @@ class ErrnoRestorer { DISALLOW_COPY_AND_ASSIGN(ErrnoRestorer); }; // A helper macro that produces an expression that accepts both a qualified name and an // unqualified name for a LogSeverity, and returns a LogSeverity value. // Note: DO NOT USE DIRECTLY. This is an implementation detail. #define SEVERITY_LAMBDA(severity) ([&]() { \ using ::android::base::VERBOSE; \ using ::android::base::DEBUG; \ using ::android::base::INFO; \ using ::android::base::WARNING; \ using ::android::base::ERROR; \ using ::android::base::FATAL_WITHOUT_ABORT; \ using ::android::base::FATAL; \ return (severity); }()) // Defines whether the given severity will be logged or silently swallowed. #define WOULD_LOG(severity) WOULD_LOG_SEVERITY(::android::base::severity) #define WOULD_LOG_SEVERITY(severity) \ UNLIKELY((severity) >= ::android::base::GetMinimumLogSeverity()) #define WOULD_LOG(severity) \ UNLIKELY((SEVERITY_LAMBDA(severity)) >= ::android::base::GetMinimumLogSeverity()) // Get an ostream that can be used for logging at the given severity and to the default // destination. Loading @@ -132,23 +144,20 @@ class ErrnoRestorer { // 1) This will not check whether the severity is high enough. One should use WOULD_LOG to filter // usage manually. // 2) This does not save and restore errno. #define LOG_STREAM(severity) LOG_STREAM_S(::android::base::severity) #define LOG_STREAM_S(severity) LOG_STREAM_TO_S(DEFAULT, severity) #define LOG_STREAM(severity) LOG_STREAM_TO(DEFAULT, severity) // Get an ostream that can be used for logging at the given severity and to the // given destination. The same notes as for LOG_STREAM apply. #define LOG_STREAM_TO(dest, severity) LOG_STREAM_TO_S(dest, ::android::base::severity) #define LOG_STREAM_TO_S(dest, severity) \ #define LOG_STREAM_TO(dest, severity) \ ::android::base::LogMessage(__FILE__, __LINE__, \ ::android::base::dest, \ severity, -1).stream() SEVERITY_LAMBDA(severity), -1).stream() // Logs a message to logcat on Android otherwise to stderr. If the severity is // FATAL it also causes an abort. For example: // // LOG(FATAL) << "We didn't expect to reach here"; #define LOG(severity) LOG_S(::android::base::severity) #define LOG_S(severity) LOG_TO_S(DEFAULT, severity) #define LOG(severity) LOG_TO(DEFAULT, severity) // Logs a message to logcat with the specified log ID on Android otherwise to // stderr. If the severity is FATAL it also causes an abort. Loading @@ -156,25 +165,23 @@ class ErrnoRestorer { // else statement after LOG() macro, it won't bind to the if statement in the macro. // do-while(0) statement doesn't work here. Because we need to support << operator // following the macro, like "LOG(DEBUG) << xxx;". #define LOG_TO(dest, severity) LOG_TO_S(dest, ::android::base::severity) #define LOG_TO_S(dest, severity) \ WOULD_LOG_SEVERITY(severity) && \ #define LOG_TO(dest, severity) \ WOULD_LOG(severity) && \ ::android::base::ErrnoRestorer() && \ LOG_STREAM_TO_S(dest, severity) \ LOG_STREAM_TO(dest, severity) // A variant of LOG that also logs the current errno value. To be used when // library calls fail. #define PLOG(severity) PLOG_S(::android::base::severity) #define PLOG_S(severity) PLOG_TO_S(DEFAULT, severity) #define PLOG(severity) PLOG_TO(DEFAULT, severity) // Behaves like PLOG, but logs to the specified log ID. #define PLOG_TO(dest, severity) PLOG_TO_S(dest, ::android::base::severity) #define PLOG_TO_S(dest, severity) \ WOULD_LOG_SEVERITY(severity) && \ #define PLOG_TO(dest, severity) \ WOULD_LOG(SEVERITY_LAMBDA(severity)) && \ ::android::base::ErrnoRestorer() && \ ::android::base::LogMessage(__FILE__, __LINE__, \ ::android::base::dest, \ severity, errno).stream() SEVERITY_LAMBDA(severity), errno).stream() // Marker that code is yet to be implemented. #define UNIMPLEMENTED(level) \ Loading
base/logging.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -391,7 +391,7 @@ LogMessage::LogMessage(const char* file, unsigned int line, LogId id, LogMessage::~LogMessage() { // Check severity again. This is duplicate work wrt/ LOG macros, but not LOG_STREAM. if (!WOULD_LOG_SEVERITY(data_->GetSeverity())) { if (!WOULD_LOG(data_->GetSeverity())) { return; } Loading
base/logging_test.cpp +113 −353 Original line number Diff line number Diff line Loading @@ -142,22 +142,35 @@ TEST(logging, DCHECK) { // we don't get more bit-rot). } #define CHECK_WOULD_LOG_DISABLED(severity) \ static_assert(android::base::severity < android::base::FATAL, "Bad input"); \ for (size_t i = static_cast<size_t>(android::base::severity) + 1; \ i <= static_cast<size_t>(android::base::FATAL); \ ++i) { \ { \ android::base::ScopedLogSeverity sls2(static_cast<android::base::LogSeverity>(i)); \ EXPECT_FALSE(WOULD_LOG(severity)) << i; \ } } \ { \ android::base::ScopedLogSeverity sls2(static_cast<android::base::LogSeverity>(i)); \ EXPECT_FALSE(WOULD_LOG(::android::base::severity)) << i; \ } \ } \ #define CHECK_WOULD_LOG_ENABLED(severity) \ for (size_t i = static_cast<size_t>(android::base::VERBOSE); \ i <= static_cast<size_t>(android::base::severity); \ ++i) { \ { \ android::base::ScopedLogSeverity sls2(static_cast<android::base::LogSeverity>(i)); \ EXPECT_TRUE(WOULD_LOG(severity)) << i; \ } } \ { \ android::base::ScopedLogSeverity sls2(static_cast<android::base::LogSeverity>(i)); \ EXPECT_TRUE(WOULD_LOG(::android::base::severity)) << i; \ } \ } \ TEST(logging, WOULD_LOG_FATAL) { CHECK_WOULD_LOG_ENABLED(FATAL); Loading Loading @@ -215,78 +228,6 @@ TEST(logging, WOULD_LOG_VERBOSE_enabled) { #undef CHECK_WOULD_LOG_ENABLED #define CHECK_WOULD_LOG_SEVERITY_DISABLED(severity) \ static_assert(android::base::severity < android::base::FATAL, "Bad input"); \ for (size_t i = static_cast<size_t>(android::base::severity) + 1; \ i <= static_cast<size_t>(android::base::FATAL); \ ++i) { \ android::base::ScopedLogSeverity sls2(static_cast<android::base::LogSeverity>(i)); \ EXPECT_FALSE(WOULD_LOG_SEVERITY(::android::base::severity)) << i; \ } #define CHECK_WOULD_LOG_SEVERITY_ENABLED(severity) \ for (size_t i = static_cast<size_t>(android::base::VERBOSE); \ i <= static_cast<size_t>(android::base::severity); \ ++i) { \ android::base::ScopedLogSeverity sls2(static_cast<android::base::LogSeverity>(i)); \ EXPECT_TRUE(WOULD_LOG_SEVERITY(::android::base::severity)) << i; \ } TEST(logging,WOULD_LOG_SEVERITY_FATAL) { CHECK_WOULD_LOG_SEVERITY_ENABLED(FATAL); } TEST(logging,WOULD_LOG_SEVERITY_FATAL_WITHOUT_ABORT_disabled) { CHECK_WOULD_LOG_SEVERITY_DISABLED(FATAL_WITHOUT_ABORT); } TEST(logging, WOULD_LOG_SEVERITY_FATAL_WITHOUT_ABORT_enabled) { CHECK_WOULD_LOG_SEVERITY_ENABLED(FATAL_WITHOUT_ABORT); } TEST(logging, WOULD_LOG_SEVERITY_ERROR_disabled) { CHECK_WOULD_LOG_SEVERITY_DISABLED(ERROR); } TEST(logging, WOULD_LOG_SEVERITY_ERROR_enabled) { CHECK_WOULD_LOG_SEVERITY_ENABLED(ERROR); } TEST(logging, WOULD_LOG_SEVERITY_WARNING_disabled) { CHECK_WOULD_LOG_SEVERITY_DISABLED(WARNING); } TEST(logging, WOULD_LOG_SEVERITY_WARNING_enabled) { CHECK_WOULD_LOG_SEVERITY_ENABLED(WARNING); } TEST(logging, WOULD_LOG_SEVERITY_INFO_disabled) { CHECK_WOULD_LOG_SEVERITY_DISABLED(INFO); } TEST(logging, WOULD_LOG_SEVERITY_INFO_enabled) { CHECK_WOULD_LOG_SEVERITY_ENABLED(INFO); } TEST(logging, WOULD_LOG_SEVERITY_DEBUG_disabled) { CHECK_WOULD_LOG_SEVERITY_DISABLED(DEBUG); } TEST(logging, WOULD_LOG_SEVERITY_DEBUG_enabled) { CHECK_WOULD_LOG_SEVERITY_ENABLED(DEBUG); } TEST(logging, WOULD_LOG_SEVERITYVERBOSE_disabled) { CHECK_WOULD_LOG_SEVERITY_DISABLED(VERBOSE); } TEST(logging, WOULD_LOG_SEVERITY_VERBOSE_enabled) { CHECK_WOULD_LOG_SEVERITY_ENABLED(VERBOSE); } #undef CHECK_WOULD_LOG_SEVERITY_DISABLED #undef CHECK_WOULD_LOG_SEVERITY_ENABLED static std::string make_log_pattern(android::base::LogSeverity severity, const char* message) { static const char log_characters[] = "VDIWEFF"; Loading Loading @@ -317,17 +258,34 @@ static void CheckMessage(const CapturedStderr& cap, #endif } #define CHECK_LOG_STREAM_DISABLED(severity) \ { \ android::base::ScopedLogSeverity sls1(android::base::FATAL); \ CapturedStderr cap1; \ LOG_STREAM(severity) << "foo bar"; \ ASSERT_EQ(0, lseek(cap1.fd(), 0, SEEK_CUR)); ASSERT_EQ(0, lseek(cap1.fd(), 0, SEEK_CUR)); \ } \ { \ android::base::ScopedLogSeverity sls1(android::base::FATAL); \ CapturedStderr cap1; \ LOG_STREAM(::android::base::severity) << "foo bar"; \ ASSERT_EQ(0, lseek(cap1.fd(), 0, SEEK_CUR)); \ } \ #define CHECK_LOG_STREAM_ENABLED(severity) \ { \ android::base::ScopedLogSeverity sls2(android::base::severity); \ CapturedStderr cap2; \ LOG_STREAM(severity) << "foobar"; \ CheckMessage(cap2, android::base::severity, "foobar"); \ } \ { \ android::base::ScopedLogSeverity sls2(android::base::severity); \ CapturedStderr cap2; \ LOG_STREAM(::android::base::severity) << "foobar"; \ CheckMessage(cap2, android::base::severity, "foobar"); \ } \ TEST(logging, LOG_STREAM_FATAL_WITHOUT_ABORT_disabled) { CHECK_LOG_STREAM_DISABLED(FATAL_WITHOUT_ABORT); Loading Loading @@ -380,84 +338,38 @@ TEST(logging, LOG_STREAM_VERBOSE_enabled) { #undef CHECK_LOG_STREAM_DISABLED #undef CHECK_LOG_STREAM_ENABLED #define CHECK_LOG_STREAM_S_DISABLED(severity) \ android::base::ScopedLogSeverity sls1(android::base::FATAL); \ CapturedStderr cap1; \ LOG_STREAM_S(android::base::severity) << "foobar"; \ ASSERT_EQ(0, lseek(cap1.fd(), 0, SEEK_CUR)); #define CHECK_LOG_STREAM_S_ENABLED(severity) \ android::base::ScopedLogSeverity sls2(android::base::severity); \ CapturedStderr cap2; \ LOG_STREAM_S(android::base::severity) << "foobar"; \ CheckMessage(cap2, android::base::severity, "foobar"); \ TEST(logging, LOG_STREAM_S_FATAL_WITHOUT_ABORT_disabled) { CHECK_LOG_STREAM_S_DISABLED(FATAL_WITHOUT_ABORT); } TEST(logging, LOG_STREAM_S_FATAL_WITHOUT_ABORT_enabled) { CHECK_LOG_STREAM_S_ENABLED(FATAL_WITHOUT_ABORT); } TEST(logging, LOG_STREAM_S_ERROR_disabled) { CHECK_LOG_STREAM_S_DISABLED(ERROR); } TEST(logging, LOG_STREAM_S_ERROR_enabled) { CHECK_LOG_STREAM_S_ENABLED(ERROR); } TEST(logging, LOG_STREAM_S_WARNING_disabled) { CHECK_LOG_STREAM_S_DISABLED(WARNING); } TEST(logging, LOG_STREAM_S_WARNING_enabled) { CHECK_LOG_STREAM_S_ENABLED(WARNING); } TEST(logging, LOG_STREAM_S_INFO_disabled) { CHECK_LOG_STREAM_S_DISABLED(INFO); } TEST(logging, LOG_STREAM_S_INFO_enabled) { CHECK_LOG_STREAM_S_ENABLED(INFO); } TEST(logging, LOG_STREAM_S_DEBUG_disabled) { CHECK_LOG_STREAM_S_DISABLED(DEBUG); } TEST(logging, LOG_STREAM_S_DEBUG_enabled) { CHECK_LOG_STREAM_S_ENABLED(DEBUG); } TEST(logging, LOG_STREAM_S_VERBOSE_disabled) { CHECK_LOG_STREAM_S_DISABLED(VERBOSE); } TEST(logging, LOG_STREAM_S_VERBOSE_enabled) { CHECK_LOG_STREAM_S_ENABLED(VERBOSE); } #undef CHECK_LOG_STREAM_S_DISABLED #undef CHECK_LOG_STREAM_S_ENABLED #define CHECK_LOG_DISABLED(severity) \ { \ android::base::ScopedLogSeverity sls1(android::base::FATAL); \ CapturedStderr cap1; \ LOG(severity) << "foo bar"; \ ASSERT_EQ(0, lseek(cap1.fd(), 0, SEEK_CUR)); \ } \ { \ android::base::ScopedLogSeverity sls1(android::base::FATAL); \ CapturedStderr cap1; \ LOG(::android::base::severity) << "foo bar"; \ ASSERT_EQ(0, lseek(cap1.fd(), 0, SEEK_CUR)); \ } \ #define CHECK_LOG_ENABLED(severity) \ { \ android::base::ScopedLogSeverity sls2(android::base::severity); \ CapturedStderr cap2; \ LOG(severity) << "foobar"; \ CheckMessage(cap2, android::base::severity, "foobar"); \ } \ { \ android::base::ScopedLogSeverity sls2(android::base::severity); \ CapturedStderr cap2; \ LOG(::android::base::severity) << "foobar"; \ CheckMessage(cap2, android::base::severity, "foobar"); \ } \ TEST(logging, LOG_FATAL) { ASSERT_DEATH({SuppressAbortUI(); LOG(FATAL) << "foobar";}, "foobar"); ASSERT_DEATH({SuppressAbortUI(); LOG(::android::base::FATAL) << "foobar";}, "foobar"); } TEST(logging, LOG_FATAL_WITHOUT_ABORT_disabled) { Loading Loading @@ -511,80 +423,14 @@ TEST(logging, LOG_VERBOSE_enabled) { #undef CHECK_LOG_DISABLED #undef CHECK_LOG_ENABLED #define CHECK_LOG_S_DISABLED(severity) \ android::base::ScopedLogSeverity sls1(android::base::FATAL); \ CapturedStderr cap1; \ LOG_S(::android::base::severity) << "foo bar"; \ ASSERT_EQ(0, lseek(cap1.fd(), 0, SEEK_CUR)); \ #define CHECK_LOG_S_ENABLED(severity) \ android::base::ScopedLogSeverity sls2(android::base::severity); \ CapturedStderr cap2; \ LOG_S(::android::base::severity) << "foobar"; \ CheckMessage(cap2, android::base::severity, "foobar"); \ TEST(logging, LOG_S_FATAL) { ASSERT_DEATH({SuppressAbortUI(); LOG_S(::android::base::FATAL) << "foobar";}, "foobar"); } TEST(logging, LOG_S_FATAL_WITHOUT_ABORT_disabled) { CHECK_LOG_S_DISABLED(FATAL_WITHOUT_ABORT); } TEST(logging, LOG_S_FATAL_WITHOUT_ABORT_enabled) { CHECK_LOG_S_ENABLED(FATAL_WITHOUT_ABORT); } TEST(logging, LOG_S_ERROR_disabled) { CHECK_LOG_S_DISABLED(ERROR); } TEST(logging, LOG_S_ERROR_enabled) { CHECK_LOG_S_ENABLED(ERROR); } TEST(logging, LOG_S_WARNING_disabled) { CHECK_LOG_S_DISABLED(WARNING); } TEST(logging, LOG_S_WARNING_enabled) { CHECK_LOG_S_ENABLED(WARNING); } TEST(logging, LOG_S_INFO_disabled) { CHECK_LOG_S_DISABLED(INFO); } TEST(logging, LOG_S_INFO_enabled) { CHECK_LOG_S_ENABLED(INFO); } TEST(logging, LOG_S_DEBUG_disabled) { CHECK_LOG_S_DISABLED(DEBUG); } TEST(logging, LOG_S_DEBUG_enabled) { CHECK_LOG_S_ENABLED(DEBUG); } TEST(logging, LOG_S_VERBOSE_disabled) { CHECK_LOG_S_DISABLED(VERBOSE); } TEST(logging, LOG_S_VERBOSE_enabled) { CHECK_LOG_S_ENABLED(VERBOSE); } #undef CHECK_LOG_S_DISABLED #undef CHECK_LOG_S_ENABLED TEST(logging, LOG_S_complex_param) { #define CHECK_LOG_S_COMBINATION(use_scoped_log_severity_info, use_logging_severity_info) \ TEST(logging, LOG_complex_param) { #define CHECK_LOG_COMBINATION(use_scoped_log_severity_info, use_logging_severity_info) \ { \ android::base::ScopedLogSeverity sls( \ (use_scoped_log_severity_info) ? ::android::base::INFO : ::android::base::WARNING); \ CapturedStderr cap; \ LOG_S((use_logging_severity_info) ? ::android::base::INFO : ::android::base::WARNING) \ LOG((use_logging_severity_info) ? ::android::base::INFO : ::android::base::WARNING) \ << "foobar"; \ if ((use_scoped_log_severity_info) || !(use_logging_severity_info)) { \ CheckMessage(cap, \ Loading @@ -595,12 +441,12 @@ TEST(logging, LOG_S_complex_param) { } \ } CHECK_LOG_S_COMBINATION(false,false); CHECK_LOG_S_COMBINATION(false,true); CHECK_LOG_S_COMBINATION(true,false); CHECK_LOG_S_COMBINATION(true,true); CHECK_LOG_COMBINATION(false,false); CHECK_LOG_COMBINATION(false,true); CHECK_LOG_COMBINATION(true,false); CHECK_LOG_COMBINATION(true,true); #undef CHECK_LOG_S_COMBINATION #undef CHECK_LOG_COMBINATION } Loading @@ -613,15 +459,6 @@ TEST(logging, LOG_does_not_clobber_errno) { CheckMessage(cap, android::base::INFO, "67890"); } TEST(logging, LOG_S_does_not_clobber_errno) { CapturedStderr cap; errno = 12345; LOG_S(::android::base::INFO) << (errno = 67890); EXPECT_EQ(12345, errno) << "errno was not restored"; CheckMessage(cap, android::base::INFO, "67890"); } TEST(logging, PLOG_does_not_clobber_errno) { CapturedStderr cap; errno = 12345; Loading @@ -631,16 +468,6 @@ TEST(logging, PLOG_does_not_clobber_errno) { CheckMessage(cap, android::base::INFO, "67890"); } TEST(logging, PLOG_S_does_not_clobber_errno) { CapturedStderr cap; errno = 12345; PLOG_S(::android::base::INFO) << (errno = 67890); EXPECT_EQ(12345, errno) << "errno was not restored"; CheckMessage(cap, android::base::INFO, "67890"); } TEST(logging, LOG_does_not_have_dangling_if) { CapturedStderr cap; // So the logging below has no side-effects. Loading @@ -662,39 +489,41 @@ TEST(logging, LOG_does_not_have_dangling_if) { flag = true; EXPECT_FALSE(flag) << "LOG macro probably has a dangling if with no else"; flag = false; if (true) LOG_S(::android::base::INFO) << "foobar"; else flag = true; EXPECT_FALSE(flag) << "LOG_S macro probably has a dangling if with no else"; flag = false; if (true) LOG_S(::android::base::VERBOSE) << "foobar"; else flag = true; EXPECT_FALSE(flag) << "LOG_S macro probably has a dangling if with no else"; } #define CHECK_PLOG_DISABLED(severity) \ { \ android::base::ScopedLogSeverity sls1(android::base::FATAL); \ CapturedStderr cap1; \ PLOG(severity) << "foo bar"; \ ASSERT_EQ(0, lseek(cap1.fd(), 0, SEEK_CUR)); \ } \ { \ android::base::ScopedLogSeverity sls1(android::base::FATAL); \ CapturedStderr cap1; \ PLOG(severity) << "foo bar"; \ ASSERT_EQ(0, lseek(cap1.fd(), 0, SEEK_CUR)); \ } \ #define CHECK_PLOG_ENABLED(severity) \ { \ android::base::ScopedLogSeverity sls2(android::base::severity); \ CapturedStderr cap2; \ errno = ENOENT; \ PLOG(severity) << "foobar"; \ CheckMessage(cap2, android::base::severity, "foobar: No such file or directory"); \ } \ { \ android::base::ScopedLogSeverity sls2(android::base::severity); \ CapturedStderr cap2; \ errno = ENOENT; \ PLOG(severity) << "foobar"; \ CheckMessage(cap2, android::base::severity, "foobar: No such file or directory"); \ } \ TEST(logging, PLOG_FATAL) { ASSERT_DEATH({SuppressAbortUI(); PLOG(FATAL) << "foobar";}, "foobar"); ASSERT_DEATH({SuppressAbortUI(); PLOG(::android::base::FATAL) << "foobar";}, "foobar"); } TEST(logging, PLOG_FATAL_WITHOUT_ABORT_disabled) { Loading Loading @@ -749,75 +578,6 @@ TEST(logging, PLOG_VERBOSE_enabled) { #undef CHECK_PLOG_ENABLED #define CHECK_PLOG_S_DISABLED(severity) \ android::base::ScopedLogSeverity sls1(android::base::FATAL); \ CapturedStderr cap1; \ PLOG_S(android::base::severity) << "foo bar"; \ ASSERT_EQ(0, lseek(cap1.fd(), 0, SEEK_CUR)); \ #define CHECK_PLOG_S_ENABLED(severity) \ android::base::ScopedLogSeverity sls2(android::base::severity); \ CapturedStderr cap2; \ errno = ENOENT; \ PLOG_S(android::base::severity) << "foobar"; \ CheckMessage(cap2, android::base::severity, "foobar: No such file or directory"); \ TEST(logging, PLOG_S_FATAL) { ASSERT_DEATH({SuppressAbortUI(); PLOG_S(::android::base::FATAL) << "foobar";}, "foobar"); } TEST(logging, PLOG_S_FATAL_WITHOUT_ABORT_disabled) { CHECK_PLOG_S_DISABLED(FATAL_WITHOUT_ABORT); } TEST(logging, PLOG_S_FATAL_WITHOUT_ABORT_enabled) { CHECK_PLOG_S_ENABLED(FATAL_WITHOUT_ABORT); } TEST(logging, PLOG_S_ERROR_disabled) { CHECK_PLOG_S_DISABLED(ERROR); } TEST(logging, PLOG_S_ERROR_enabled) { CHECK_PLOG_S_ENABLED(ERROR); } TEST(logging, PLOG_S_WARNING_disabled) { CHECK_PLOG_S_DISABLED(WARNING); } TEST(logging, PLOG_S_WARNING_enabled) { CHECK_PLOG_S_ENABLED(WARNING); } TEST(logging, PLOG_S_INFO_disabled) { CHECK_PLOG_S_DISABLED(INFO); } TEST(logging, PLOG_S_INFO_enabled) { CHECK_PLOG_S_ENABLED(INFO); } TEST(logging, PLOG_S_DEBUG_disabled) { CHECK_PLOG_S_DISABLED(DEBUG); } TEST(logging, PLOG_S_DEBUG_enabled) { CHECK_PLOG_S_ENABLED(DEBUG); } TEST(logging, PLOG_S_VERBOSE_disabled) { CHECK_PLOG_S_DISABLED(VERBOSE); } TEST(logging, PLOG_S_VERBOSE_enabled) { CHECK_PLOG_S_ENABLED(VERBOSE); } #undef CHECK_PLOG_S_DISABLED #undef CHECK_PLOG_S_ENABLED TEST(logging, UNIMPLEMENTED) { std::string expected = android::base::StringPrintf("%s unimplemented ", __PRETTY_FUNCTION__); Loading