Merge "Switch adb to <android-base/properties.h>."
diff --git a/base/include/android-base/logging.h b/base/include/android-base/logging.h
index 1285f53..50677a3 100644
--- a/base/include/android-base/logging.h
+++ b/base/include/android-base/logging.h
@@ -120,10 +120,22 @@
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.
@@ -132,23 +144,20 @@
// 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.
@@ -156,25 +165,23 @@
// 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) \
diff --git a/base/logging.cpp b/base/logging.cpp
index 2ca2246..eaed9ab 100644
--- a/base/logging.cpp
+++ b/base/logging.cpp
@@ -391,7 +391,7 @@
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;
}
diff --git a/base/logging_test.cpp b/base/logging_test.cpp
index dccb774..9fc7736 100644
--- a/base/logging_test.cpp
+++ b/base/logging_test.cpp
@@ -142,22 +142,35 @@
// 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; \
- }
-#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; \
- }
+#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);
@@ -215,78 +228,6 @@
#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";
@@ -317,17 +258,34 @@
#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));
+ { \
+ android::base::ScopedLogSeverity sls1(android::base::FATAL); \
+ CapturedStderr cap1; \
+ LOG_STREAM(severity) << "foo bar"; \
+ 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(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);
@@ -380,84 +338,38 @@
#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(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(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) {
@@ -511,80 +423,14 @@
#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, \
@@ -595,12 +441,12 @@
} \
}
- 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
}
@@ -613,15 +459,6 @@
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;
@@ -631,16 +468,6 @@
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.
@@ -662,39 +489,41 @@
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)); \
+ } \
+ { \
+ 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"); \
+ } \
+ { \
+ 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) {
@@ -749,75 +578,6 @@
#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__);
diff --git a/fastboot/fastboot.cpp b/fastboot/fastboot.cpp
index 987ba83..d6b631f 100644
--- a/fastboot/fastboot.cpp
+++ b/fastboot/fastboot.cpp
@@ -402,6 +402,9 @@
" --skip-secondary Will not flash secondary slots when\n"
" performing a flashall or update. This\n"
" will preserve data on other slots.\n"
+ " --skip-reboot Will not reboot the device when\n"
+ " performing commands that normally\n"
+ " trigger a reboot.\n"
#if !defined(_WIN32)
" --wipe-and-use-fbe On devices which support it,\n"
" erase userdata and cache, and\n"
@@ -1392,6 +1395,7 @@
bool wants_wipe = false;
bool wants_reboot = false;
bool wants_reboot_bootloader = false;
+ bool skip_reboot = false;
bool wants_set_active = false;
bool skip_secondary = false;
bool erase_first = true;
@@ -1419,6 +1423,7 @@
{"set_active", optional_argument, 0, 'a'},
{"set-active", optional_argument, 0, 'a'},
{"skip-secondary", no_argument, 0, 0},
+ {"skip-reboot", no_argument, 0, 0},
#if !defined(_WIN32)
{"wipe-and-use-fbe", no_argument, 0, 0},
#endif
@@ -1505,6 +1510,8 @@
slot_override = std::string(optarg);
} else if (strcmp("skip-secondary", longopts[longindex].name) == 0 ) {
skip_secondary = true;
+ } else if (strcmp("skip-reboot", longopts[longindex].name) == 0 ) {
+ skip_reboot = true;
#if !defined(_WIN32)
} else if (strcmp("wipe-and-use-fbe", longopts[longindex].name) == 0) {
wants_wipe = true;
@@ -1729,7 +1736,7 @@
do_update(transport, "update.zip", slot_override, erase_first, skip_secondary || slot_all);
skip(1);
}
- wants_reboot = 1;
+ wants_reboot = true;
} else if(!strcmp(*argv, "set_active")) {
require(2);
std::string slot = verify_slot(transport, std::string(argv[1]), false);
@@ -1784,7 +1791,7 @@
if (wants_set_active) {
fb_set_active(next_active.c_str());
}
- if (wants_reboot) {
+ if (wants_reboot && !skip_reboot) {
fb_queue_reboot();
fb_queue_wait_for_disconnect();
} else if (wants_reboot_bootloader) {