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

Side by Side Diff: unclean_shutdown_collector_test.cc

Issue 3179006: Collect and send kernel crash diagnostics (Closed) Base URL: ssh://git@chromiumos-git//crash-reporter.git
Patch Set: Respond to reviews Created 10 years, 4 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 unified diff | Download patch
« no previous file with comments | « unclean_shutdown_collector.cc ('k') | user_collector.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <unistd.h>
6
7 #include "base/file_util.h"
8 #include "base/string_util.h"
9 #include "crash-reporter/unclean_shutdown_collector.h"
10 #include "crash-reporter/system_logging_mock.h"
11 #include "gflags/gflags.h"
12 #include "gtest/gtest.h"
13
14 static int s_crashes = 0;
15 static bool s_metrics = false;
16
17 static const char kTestUnclean[] = "test/unclean";
18
19 void CountCrash() {
20 ++s_crashes;
21 }
22
23 bool IsMetrics() {
24 return s_metrics;
25 }
26
27 class UncleanShutdownCollectorTest : public ::testing::Test {
28 void SetUp() {
29 s_crashes = 0;
30 collector_.Initialize(CountCrash,
31 IsMetrics,
32 &logging_);
33 rmdir("test");
34 test_unclean_ = FilePath(kTestUnclean);
35 collector_.unclean_shutdown_file_ = kTestUnclean;
36 file_util::Delete(test_unclean_, true);
37 }
38 protected:
39 void WriteStringToFile(const FilePath &file_path,
40 const char *data) {
41 ASSERT_EQ(strlen(data),
42 file_util::WriteFile(file_path, data, strlen(data)));
43 }
44
45 SystemLoggingMock logging_;
46 UncleanShutdownCollector collector_;
47 FilePath test_unclean_;
48 };
49
50 TEST_F(UncleanShutdownCollectorTest, EnableWithoutParent) {
51 ASSERT_TRUE(collector_.Enable());
52 ASSERT_TRUE(file_util::PathExists(test_unclean_));
53 }
54
55 TEST_F(UncleanShutdownCollectorTest, EnableWithParent) {
56 mkdir("test", 0777);
57 ASSERT_TRUE(collector_.Enable());
58 ASSERT_TRUE(file_util::PathExists(test_unclean_));
59 }
60
61 TEST_F(UncleanShutdownCollectorTest, EnableCannotWrite) {
62 collector_.unclean_shutdown_file_ = "/bad/path";
63 ASSERT_FALSE(collector_.Enable());
64 ASSERT_NE(std::string::npos,
65 logging_.log().find("Unable to create shutdown check file"));
66 }
67
68 TEST_F(UncleanShutdownCollectorTest, CollectTrue) {
69 ASSERT_TRUE(collector_.Enable());
70 ASSERT_TRUE(file_util::PathExists(test_unclean_));
71 ASSERT_TRUE(collector_.Collect());
72 ASSERT_FALSE(file_util::PathExists(test_unclean_));
73 ASSERT_NE(std::string::npos,
74 logging_.log().find("Last shutdown was not clean"));
75 }
76
77 TEST_F(UncleanShutdownCollectorTest, CollectFalse) {
78 ASSERT_FALSE(collector_.Collect());
79 }
80
81 TEST_F(UncleanShutdownCollectorTest, Disable) {
82 ASSERT_TRUE(collector_.Enable());
83 ASSERT_TRUE(file_util::PathExists(test_unclean_));
84 ASSERT_TRUE(collector_.Disable());
85 ASSERT_FALSE(file_util::PathExists(test_unclean_));
86 ASSERT_FALSE(collector_.Collect());
87 }
88
89 TEST_F(UncleanShutdownCollectorTest, DisableWhenNotEnabled) {
90 ASSERT_TRUE(collector_.Disable());
91 }
92
93 TEST_F(UncleanShutdownCollectorTest, CantDisable) {
94 mkdir(kTestUnclean, 0700);
95 file_util::WriteFile(test_unclean_.Append("foo"), "", 0);
96 ASSERT_FALSE(collector_.Disable());
97 rmdir(kTestUnclean);
98 }
99
100 int main(int argc, char **argv) {
101 ::testing::InitGoogleTest(&argc, argv);
102 return RUN_ALL_TESTS();
103 }
OLDNEW
« no previous file with comments | « unclean_shutdown_collector.cc ('k') | user_collector.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698