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

Unified Diff: kernel_collector_test.cc

Issue 6517001: crash-reporter: Use standard logging and new libchromeos Process code (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/crash-reporter.git@master
Patch Set: More comments Created 9 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
« no previous file with comments | « kernel_collector.cc ('k') | system_logging.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: kernel_collector_test.cc
diff --git a/kernel_collector_test.cc b/kernel_collector_test.cc
index 7b84229aa99259348dfcc26894b47e3b7def088c..f7c88f09addfeaa9bf2502cfc3bcbd6077e93c0e 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"
@@ -17,6 +18,8 @@ static bool s_metrics = false;
static const char kTestKCrash[] = "test/kcrash";
static const char kTestCrashDirectory[] = "test/crash_directory";
+using chromeos::FindLog;
+
void CountCrash() {
++s_crashes;
}
@@ -30,13 +33,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);
+ chromeos::ClearLog();
}
protected:
void WriteStringToFile(const FilePath &file_path,
@@ -48,7 +51,6 @@ class KernelCollectorTest : public ::testing::Test {
void SetUpSuccessfulCollect();
void CheckPreservedDumpClear();
- SystemLoggingMock logging_;
KernelCollector collector_;
FilePath test_kcrash_;
};
@@ -68,10 +70,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(FindLog(
+ "Kernel does not support crash dumping"));
ASSERT_EQ(s_crashes, 0);
}
@@ -79,8 +79,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(FindLog("Enabling kernel crash handling"));
ASSERT_EQ(s_crashes, 0);
}
@@ -97,24 +96,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(FindLog("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(FindLog("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(FindLog(
+ "Unable to create appropriate crash directory"));
ASSERT_EQ(1, s_crashes);
}
@@ -135,7 +132,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(FindLog("(ignoring - no consent)"));
ASSERT_EQ(0, s_crashes);
CheckPreservedDumpClear();
@@ -145,12 +142,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(FindLog("(handling)"));
static const char kNamePrefix[] = "Stored kcrash to ";
- size_t pos = logging_.log().find(kNamePrefix);
+ std::string log = chromeos::GetLog();
+ 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 +270,6 @@ TEST_F(KernelCollectorTest, ComputeKernelStackSignature) {
}
int main(int argc, char **argv) {
- ::testing::InitGoogleTest(&argc, argv);
+ SetUpTests(&argc, argv, false);
return RUN_ALL_TESTS();
}
« no previous file with comments | « kernel_collector.cc ('k') | system_logging.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698