Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Unified Diff: base/metrics/statistics_recorder_unittest.cc

Issue 1748403003: Log histograms on shutdown when verbose logging is on (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/metrics/statistics_recorder_unittest.cc
diff --git a/base/metrics/statistics_recorder_unittest.cc b/base/metrics/statistics_recorder_unittest.cc
index 17511a4d4ffa5ea7d57131b743300c08a8708308..ec18afc76212183343494d79fd794cf1f6a9b1ff 100644
--- a/base/metrics/statistics_recorder_unittest.cc
+++ b/base/metrics/statistics_recorder_unittest.cc
@@ -8,6 +8,7 @@
#include "base/bind.h"
#include "base/json/json_reader.h"
+#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/metrics/histogram_macros.h"
#include "base/metrics/histogram_persistence.h"
@@ -61,6 +62,56 @@ class StatisticsRecorderTest : public testing::Test {
StatisticsRecorder* statistics_recorder_;
};
+// Class to make sure any manipulations we do to the min log level are
+// contained (i.e., do not affect other unit tests).
+class LogStateSaver {
Alexei Svitkine (slow) 2016/04/14 20:47:39 Put this in an anon namespace at the top of the fi
+ public:
+ LogStateSaver() : old_min_log_level_(logging::GetMinLogLevel()) {}
+
+ ~LogStateSaver() {
+ logging::SetMinLogLevel(old_min_log_level_);
+ logging::SetLogAssertHandler(nullptr);
+ }
+
+ private:
+ int old_min_log_level_;
+
+ DISALLOW_COPY_AND_ASSIGN(LogStateSaver);
+};
+
+class StatisticsRecorderLoggingTestBase : public StatisticsRecorderTest {
+ protected:
+ void InitLogOnShutdown() {
+ DCHECK(statistics_recorder_);
+ statistics_recorder_->InitLogOnShutdownWithoutLock();
+ }
+
+ private:
+ LogStateSaver log_state_saver_;
Alexei Svitkine (slow) 2016/04/14 20:47:39 Is there any problem doing this unconditionally fo
+};
+
+class StatisticsRecorderLoggingWarningOnStartupTest
Alexei Svitkine (slow) 2016/04/14 20:47:39 You don't need to create a separate test harness c
+ : public StatisticsRecorderLoggingTestBase {
+ protected:
+ void SetUp() override {
+ logging::SetMinLogLevel(logging::LOG_WARNING);
+ StatisticsRecorderLoggingTestBase::SetUp();
+ }
+};
+
+class StatisticsRecorderLoggingVerboseOnStartupTest
+ : public StatisticsRecorderLoggingTestBase {
+ protected:
+ void SetUp() override {
+ logging::SetMinLogLevel(logging::LOG_VERBOSE);
+ StatisticsRecorderTest::SetUp();
+ }
+
+ private:
+ LogStateSaver log_state_saver_;
+};
+
+
TEST_F(StatisticsRecorderTest, NotInitialized) {
UninitializeStatisticsRecorder();
@@ -513,4 +564,28 @@ TEST_F(StatisticsRecorderTest, CallbackUsedBeforeHistogramCreatedTest) {
EXPECT_EQ(callback_wrapper.last_histogram_value, 1);
}
+TEST_F(StatisticsRecorderLoggingWarningOnStartupTest,
+ LogOnShutdownNotInitialized) {
+ EXPECT_FALSE(VLOG_IS_ON(1));
+ EXPECT_FALSE(StatisticsRecorder::VLogInitializedForTesting());
+ InitLogOnShutdown();
+ EXPECT_FALSE(StatisticsRecorder::VLogInitializedForTesting());
+}
+
+TEST_F(StatisticsRecorderLoggingWarningOnStartupTest,
+ LogOnShutdownInitializedExplicitly) {
+ EXPECT_FALSE(VLOG_IS_ON(1));
+ EXPECT_FALSE(StatisticsRecorder::VLogInitializedForTesting());
+ logging::SetMinLogLevel(logging::LOG_VERBOSE);
+ EXPECT_TRUE(VLOG_IS_ON(1));
+ InitLogOnShutdown();
+ EXPECT_TRUE(StatisticsRecorder::VLogInitializedForTesting());
+}
+
+TEST_F(StatisticsRecorderLoggingVerboseOnStartupTest,
+ LogOnShutdownInitialized) {
+ EXPECT_TRUE(VLOG_IS_ON(1));
+ EXPECT_TRUE(StatisticsRecorder::VLogInitializedForTesting());
+}
+
} // namespace base

Powered by Google App Engine
This is Rietveld 408576698