| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <unistd.h> | 5 #include <unistd.h> |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "crash-reporter/system_logging_mock.h" | 8 #include "crash-reporter/system_logging_mock.h" |
| 9 #include "crash-reporter/user_collector.h" | 9 #include "crash-reporter/user_collector.h" |
| 10 #include "crash-reporter/test_helpers.h" | 10 #include "crash-reporter/test_helpers.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 EXPECT_EQ(golden, contents); | 47 EXPECT_EQ(golden, contents); |
| 48 } | 48 } |
| 49 | 49 |
| 50 SystemLoggingMock logging_; | 50 SystemLoggingMock logging_; |
| 51 UserCollector collector_; | 51 UserCollector collector_; |
| 52 pid_t pid_; | 52 pid_t pid_; |
| 53 }; | 53 }; |
| 54 | 54 |
| 55 TEST_F(UserCollectorTest, EnableOK) { | 55 TEST_F(UserCollectorTest, EnableOK) { |
| 56 ASSERT_TRUE(collector_.Enable()); | 56 ASSERT_TRUE(collector_.Enable()); |
| 57 ExpectFileEquals("|/my/path --signal=%s --pid=%p", "test/core_pattern"); | 57 ExpectFileEquals("|/my/path --user=%p:%s:%e", "test/core_pattern"); |
| 58 ExpectFileEquals("4", "test/core_pipe_limit"); | 58 ExpectFileEquals("4", "test/core_pipe_limit"); |
| 59 ASSERT_EQ(s_crashes, 0); | 59 ASSERT_EQ(s_crashes, 0); |
| 60 ASSERT_NE(logging_.log().find("Enabling user crash handling"), | 60 ASSERT_NE(logging_.log().find("Enabling user crash handling"), |
| 61 std::string::npos); | 61 std::string::npos); |
| 62 } | 62 } |
| 63 | 63 |
| 64 TEST_F(UserCollectorTest, EnableNoPatternFileAccess) { | 64 TEST_F(UserCollectorTest, EnableNoPatternFileAccess) { |
| 65 collector_.set_core_pattern_file("/does_not_exist"); | 65 collector_.set_core_pattern_file("/does_not_exist"); |
| 66 ASSERT_FALSE(collector_.Enable()); | 66 ASSERT_FALSE(collector_.Enable()); |
| 67 ASSERT_EQ(s_crashes, 0); | 67 ASSERT_EQ(s_crashes, 0); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 95 TEST_F(UserCollectorTest, DisableNoFileAccess) { | 95 TEST_F(UserCollectorTest, DisableNoFileAccess) { |
| 96 collector_.set_core_pattern_file("/does_not_exist"); | 96 collector_.set_core_pattern_file("/does_not_exist"); |
| 97 ASSERT_FALSE(collector_.Disable()); | 97 ASSERT_FALSE(collector_.Disable()); |
| 98 ASSERT_EQ(s_crashes, 0); | 98 ASSERT_EQ(s_crashes, 0); |
| 99 ASSERT_NE(logging_.log().find("Disabling user crash handling"), | 99 ASSERT_NE(logging_.log().find("Disabling user crash handling"), |
| 100 std::string::npos); | 100 std::string::npos); |
| 101 ASSERT_NE(logging_.log().find("Unable to write /does_not_exist"), | 101 ASSERT_NE(logging_.log().find("Unable to write /does_not_exist"), |
| 102 std::string::npos); | 102 std::string::npos); |
| 103 } | 103 } |
| 104 | 104 |
| 105 TEST_F(UserCollectorTest, ParseCrashAttributes) { |
| 106 pid_t pid; |
| 107 int signal; |
| 108 std::string exec_name; |
| 109 EXPECT_TRUE(collector_.ParseCrashAttributes("123456:11:foobar", |
| 110 &pid, &signal, &exec_name)); |
| 111 EXPECT_EQ(123456, pid); |
| 112 EXPECT_EQ(11, signal); |
| 113 EXPECT_EQ("foobar", exec_name); |
| 114 |
| 115 EXPECT_FALSE(collector_.ParseCrashAttributes("123456:11", |
| 116 &pid, &signal, &exec_name)); |
| 117 |
| 118 EXPECT_TRUE(collector_.ParseCrashAttributes("123456:11:exec:extra", |
| 119 &pid, &signal, &exec_name)); |
| 120 EXPECT_EQ("exec:extra", exec_name); |
| 121 |
| 122 EXPECT_FALSE(collector_.ParseCrashAttributes("12345p:11:foobar", |
| 123 &pid, &signal, &exec_name)); |
| 124 |
| 125 EXPECT_FALSE(collector_.ParseCrashAttributes("123456:1 :foobar", |
| 126 &pid, &signal, &exec_name)); |
| 127 |
| 128 EXPECT_FALSE(collector_.ParseCrashAttributes("123456::foobar", |
| 129 &pid, &signal, &exec_name)); |
| 130 } |
| 131 |
| 105 TEST_F(UserCollectorTest, HandleCrashWithoutMetrics) { | 132 TEST_F(UserCollectorTest, HandleCrashWithoutMetrics) { |
| 106 s_metrics = false; | 133 s_metrics = false; |
| 107 collector_.HandleCrash(10, 20, "foobar"); | 134 collector_.HandleCrash("20:10:ignored", "foobar"); |
| 108 ASSERT_NE(std::string::npos, | 135 ASSERT_NE(std::string::npos, |
| 109 logging_.log().find( | 136 logging_.log().find( |
| 110 "Received crash notification for foobar[20] sig 10")); | 137 "Received crash notification for foobar[20] sig 10")); |
| 111 ASSERT_EQ(s_crashes, 0); | 138 ASSERT_EQ(s_crashes, 0); |
| 112 } | 139 } |
| 113 | 140 |
| 114 TEST_F(UserCollectorTest, HandleNonChromeCrashWithMetrics) { | 141 TEST_F(UserCollectorTest, HandleNonChromeCrashWithMetrics) { |
| 115 s_metrics = true; | 142 s_metrics = true; |
| 116 collector_.HandleCrash(2, 5, "chromeos-wm"); | 143 collector_.HandleCrash("5:2:ignored", "chromeos-wm"); |
| 117 ASSERT_NE(std::string::npos, | 144 ASSERT_NE(std::string::npos, |
| 118 logging_.log().find( | 145 logging_.log().find( |
| 119 "Received crash notification for chromeos-wm[5] sig 2")); | 146 "Received crash notification for chromeos-wm[5] sig 2")); |
| 120 ASSERT_EQ(s_crashes, 1); | 147 ASSERT_EQ(s_crashes, 1); |
| 121 } | 148 } |
| 122 | 149 |
| 123 TEST_F(UserCollectorTest, HandleChromeCrashWithMetrics) { | 150 TEST_F(UserCollectorTest, HandleChromeCrashWithMetrics) { |
| 124 s_metrics = true; | 151 s_metrics = true; |
| 125 collector_.HandleCrash(2, 5, "chrome"); | 152 collector_.HandleCrash("5:2:ignored", "chrome"); |
| 126 ASSERT_NE(std::string::npos, | 153 ASSERT_NE(std::string::npos, |
| 127 logging_.log().find( | 154 logging_.log().find( |
| 128 "Received crash notification for chrome[5] sig 2")); | 155 "Received crash notification for chrome[5] sig 2")); |
| 129 ASSERT_NE(std::string::npos, | 156 ASSERT_NE(std::string::npos, |
| 130 logging_.log().find("(ignoring - chrome crash)")); | 157 logging_.log().find("(ignoring - chrome crash)")); |
| 131 ASSERT_EQ(s_crashes, 0); | 158 ASSERT_EQ(s_crashes, 0); |
| 132 } | 159 } |
| 133 | 160 |
| 134 TEST_F(UserCollectorTest, GetProcessPath) { | 161 TEST_F(UserCollectorTest, GetProcessPath) { |
| 135 FilePath path = collector_.GetProcessPath(100); | 162 FilePath path = collector_.GetProcessPath(100); |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 EXPECT_EQ(expectations[i].exists, | 302 EXPECT_EQ(expectations[i].exists, |
| 276 file_util::PathExists( | 303 file_util::PathExists( |
| 277 container_path.Append(expectations[i].name))); | 304 container_path.Append(expectations[i].name))); |
| 278 } | 305 } |
| 279 } | 306 } |
| 280 | 307 |
| 281 int main(int argc, char **argv) { | 308 int main(int argc, char **argv) { |
| 282 ::testing::InitGoogleTest(&argc, argv); | 309 ::testing::InitGoogleTest(&argc, argv); |
| 283 return RUN_ALL_TESTS(); | 310 return RUN_ALL_TESTS(); |
| 284 } | 311 } |
| OLD | NEW |