Index: kernel_collector_test.cc |
diff --git a/kernel_collector_test.cc b/kernel_collector_test.cc |
index 7b84229aa99259348dfcc26894b47e3b7def088c..bea25779b0ac56d0ccdaad8b5b61a479d01ba6c6 100644 |
--- a/kernel_collector_test.cc |
+++ b/kernel_collector_test.cc |
@@ -6,8 +6,9 @@ |
#include "base/file_util.h" |
#include "base/string_util.h" |
+#include "chromeos/syslog_logging.h" |
+#include "chromeos/test_helpers.h" |
#include "crash-reporter/kernel_collector.h" |
-#include "crash-reporter/system_logging_mock.h" |
#include "gflags/gflags.h" |
#include "gtest/gtest.h" |
@@ -30,13 +31,13 @@ class KernelCollectorTest : public ::testing::Test { |
s_crashes = 0; |
s_metrics = true; |
collector_.Initialize(CountCrash, |
- IsMetrics, |
- &logging_); |
+ IsMetrics); |
mkdir("test", 0777); |
test_kcrash_ = FilePath(kTestKCrash); |
collector_.OverridePreservedDumpPath(test_kcrash_); |
unlink(kTestKCrash); |
mkdir(kTestCrashDirectory, 0777); |
+ syslog_logging::ClearAccumulatedLog(); |
} |
protected: |
void WriteStringToFile(const FilePath &file_path, |
@@ -48,7 +49,6 @@ class KernelCollectorTest : public ::testing::Test { |
void SetUpSuccessfulCollect(); |
void CheckPreservedDumpClear(); |
- SystemLoggingMock logging_; |
KernelCollector collector_; |
FilePath test_kcrash_; |
}; |
@@ -68,10 +68,8 @@ TEST_F(KernelCollectorTest, LoadPreservedDump) { |
TEST_F(KernelCollectorTest, EnableMissingKernel) { |
ASSERT_FALSE(collector_.Enable()); |
ASSERT_FALSE(collector_.IsEnabled()); |
- ASSERT_EQ(std::string::npos, |
- logging_.log().find("Enabling kernel crash handling")); |
- ASSERT_NE(std::string::npos, |
- logging_.log().find("Kernel does not support crash dumping")); |
+ ASSERT_TRUE(syslog_logging::Contains( |
+ "Kernel does not support crash dumping")); |
ASSERT_EQ(s_crashes, 0); |
} |
@@ -79,8 +77,7 @@ TEST_F(KernelCollectorTest, EnableOK) { |
WriteStringToFile(test_kcrash_, ""); |
ASSERT_TRUE(collector_.Enable()); |
ASSERT_TRUE(collector_.IsEnabled()); |
- ASSERT_NE(std::string::npos, |
- logging_.log().find("Enabling kernel crash handling")); |
+ ASSERT_TRUE(syslog_logging::Contains("Enabling kernel crash handling")); |
ASSERT_EQ(s_crashes, 0); |
} |
@@ -97,24 +94,22 @@ TEST_F(KernelCollectorTest, ClearPreservedDump) { |
TEST_F(KernelCollectorTest, CollectPreservedFileMissing) { |
ASSERT_FALSE(collector_.Collect()); |
- ASSERT_NE(logging_.log().find("Unable to read test/kcrash"), |
- std::string::npos); |
+ ASSERT_TRUE(syslog_logging::Contains("Unable to read test/kcrash")); |
ASSERT_EQ(0, s_crashes); |
} |
TEST_F(KernelCollectorTest, CollectNoCrash) { |
WriteStringToFile(test_kcrash_, ""); |
ASSERT_FALSE(collector_.Collect()); |
- ASSERT_EQ(logging_.log().find("Collected kernel crash"), |
- std::string::npos); |
+ ASSERT_FALSE(syslog_logging::Contains("Collected kernel crash")); |
ASSERT_EQ(0, s_crashes); |
} |
TEST_F(KernelCollectorTest, CollectBadDirectory) { |
WriteStringToFile(test_kcrash_, "something"); |
ASSERT_TRUE(collector_.Collect()); |
- ASSERT_NE(logging_.log().find( |
- "Unable to create appropriate crash directory"), std::string::npos); |
+ ASSERT_TRUE(syslog_logging::Contains( |
+ "Unable to create appropriate crash directory")); |
ASSERT_EQ(1, s_crashes); |
} |
@@ -135,7 +130,7 @@ TEST_F(KernelCollectorTest, CollectOptedOut) { |
SetUpSuccessfulCollect(); |
s_metrics = false; |
ASSERT_TRUE(collector_.Collect()); |
- ASSERT_NE(std::string::npos, logging_.log().find("(ignoring - no consent)")); |
+ ASSERT_TRUE(syslog_logging::Contains("(ignoring - no consent)")); |
ASSERT_EQ(0, s_crashes); |
CheckPreservedDumpClear(); |
@@ -145,12 +140,13 @@ TEST_F(KernelCollectorTest, CollectOK) { |
SetUpSuccessfulCollect(); |
ASSERT_TRUE(collector_.Collect()); |
ASSERT_EQ(1, s_crashes); |
- ASSERT_NE(std::string::npos, logging_.log().find("(handling)")); |
+ ASSERT_TRUE(syslog_logging::Contains("(handling)")); |
static const char kNamePrefix[] = "Stored kcrash to "; |
- size_t pos = logging_.log().find(kNamePrefix); |
+ std::string log = syslog_logging::GetAccumulatedLogging(); |
+ size_t pos = log.find(kNamePrefix); |
ASSERT_NE(std::string::npos, pos); |
pos += strlen(kNamePrefix); |
- std::string filename = logging_.log().substr(pos, std::string::npos); |
+ std::string filename = log.substr(pos, std::string::npos); |
// Take the name up until \n |
size_t end_pos = filename.find_first_of("\n"); |
ASSERT_NE(std::string::npos, end_pos); |
@@ -272,6 +268,6 @@ TEST_F(KernelCollectorTest, ComputeKernelStackSignature) { |
} |
int main(int argc, char **argv) { |
- ::testing::InitGoogleTest(&argc, argv); |
+ SetUpTests(&argc, argv, false); |
return RUN_ALL_TESTS(); |
} |