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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 s_metrics = true; | 151 s_metrics = true; |
152 collector_.HandleCrash("5:2:ignored", "chrome"); | 152 collector_.HandleCrash("5:2:ignored", "chrome"); |
153 ASSERT_NE(std::string::npos, | 153 ASSERT_NE(std::string::npos, |
154 logging_.log().find( | 154 logging_.log().find( |
155 "Received crash notification for chrome[5] sig 2")); | 155 "Received crash notification for chrome[5] sig 2")); |
156 ASSERT_NE(std::string::npos, | 156 ASSERT_NE(std::string::npos, |
157 logging_.log().find("(ignoring - chrome crash)")); | 157 logging_.log().find("(ignoring - chrome crash)")); |
158 ASSERT_EQ(s_crashes, 0); | 158 ASSERT_EQ(s_crashes, 0); |
159 } | 159 } |
160 | 160 |
| 161 TEST_F(UserCollectorTest, HandleSuppliedChromeCrashWithMetrics) { |
| 162 s_metrics = true; |
| 163 collector_.HandleCrash("0:2:chrome", NULL); |
| 164 ASSERT_NE(std::string::npos, |
| 165 logging_.log().find( |
| 166 "Received crash notification for supplied_chrome[0] sig 2")); |
| 167 ASSERT_NE(std::string::npos, |
| 168 logging_.log().find("(ignoring - chrome crash)")); |
| 169 ASSERT_EQ(s_crashes, 0); |
| 170 } |
| 171 |
161 TEST_F(UserCollectorTest, GetProcessPath) { | 172 TEST_F(UserCollectorTest, GetProcessPath) { |
162 FilePath path = collector_.GetProcessPath(100); | 173 FilePath path = collector_.GetProcessPath(100); |
163 ASSERT_EQ("/proc/100", path.value()); | 174 ASSERT_EQ("/proc/100", path.value()); |
164 } | 175 } |
165 | 176 |
166 TEST_F(UserCollectorTest, GetSymlinkTarget) { | 177 TEST_F(UserCollectorTest, GetSymlinkTarget) { |
167 FilePath result; | 178 FilePath result; |
168 ASSERT_FALSE(collector_.GetSymlinkTarget(FilePath("/does_not_exist"), | 179 ASSERT_FALSE(collector_.GetSymlinkTarget(FilePath("/does_not_exist"), |
169 &result)); | 180 &result)); |
170 | 181 ASSERT_NE(std::string::npos, |
| 182 logging_.log().find( |
| 183 "Readlink failed on /does_not_exist with 2")); |
171 std::string long_link; | 184 std::string long_link; |
172 for (int i = 0; i < 50; ++i) | 185 for (int i = 0; i < 50; ++i) |
173 long_link += "0123456789"; | 186 long_link += "0123456789"; |
174 long_link += "/gold"; | 187 long_link += "/gold"; |
175 | 188 |
176 for (size_t len = 1; len <= long_link.size(); ++len) { | 189 for (size_t len = 1; len <= long_link.size(); ++len) { |
177 std::string this_link; | 190 std::string this_link; |
178 static const char kLink[] = "test/this_link"; | 191 static const char kLink[] = "test/this_link"; |
179 this_link.assign(long_link.c_str(), len); | 192 this_link.assign(long_link.c_str(), len); |
180 ASSERT_EQ(len, this_link.size()); | 193 ASSERT_EQ(len, this_link.size()); |
181 unlink(kLink); | 194 unlink(kLink); |
182 ASSERT_EQ(0, symlink(this_link.c_str(), kLink)); | 195 ASSERT_EQ(0, symlink(this_link.c_str(), kLink)); |
183 ASSERT_TRUE(collector_.GetSymlinkTarget(FilePath(kLink), &result)); | 196 ASSERT_TRUE(collector_.GetSymlinkTarget(FilePath(kLink), &result)); |
184 ASSERT_EQ(this_link, result.value()); | 197 ASSERT_EQ(this_link, result.value()); |
185 } | 198 } |
186 } | 199 } |
187 | 200 |
| 201 TEST_F(UserCollectorTest, GetExecutableBaseNameFromPid) { |
| 202 std::string base_name; |
| 203 EXPECT_FALSE(collector_.GetExecutableBaseNameFromPid(0, &base_name)); |
| 204 EXPECT_NE(std::string::npos, |
| 205 logging_.log().find( |
| 206 "Readlink failed on /proc/0/exe with 2")); |
| 207 EXPECT_NE(std::string::npos, |
| 208 logging_.log().find( |
| 209 "GetSymlinkTarget failed - Path " |
| 210 "/proc/0 DirectoryExists: 0")); |
| 211 EXPECT_NE(std::string::npos, |
| 212 logging_.log().find( |
| 213 "stat /proc/0/exe failed: -1 2")); |
| 214 |
| 215 logging_.clear(); |
| 216 pid_t my_pid = getpid(); |
| 217 EXPECT_TRUE(collector_.GetExecutableBaseNameFromPid(my_pid, &base_name)); |
| 218 EXPECT_EQ(std::string::npos, |
| 219 logging_.log().find( |
| 220 "Readlink failed")); |
| 221 EXPECT_EQ("user_collector_test", base_name); |
| 222 } |
| 223 |
188 TEST_F(UserCollectorTest, GetIdFromStatus) { | 224 TEST_F(UserCollectorTest, GetIdFromStatus) { |
189 int id = 1; | 225 int id = 1; |
190 EXPECT_FALSE(collector_.GetIdFromStatus(UserCollector::kUserId, | 226 EXPECT_FALSE(collector_.GetIdFromStatus(UserCollector::kUserId, |
191 UserCollector::kIdEffective, | 227 UserCollector::kIdEffective, |
192 "nothing here", | 228 "nothing here", |
193 &id)); | 229 &id)); |
194 EXPECT_EQ(id, 1); | 230 EXPECT_EQ(id, 1); |
195 | 231 |
196 // Not enough parameters. | 232 // Not enough parameters. |
197 EXPECT_FALSE(collector_.GetIdFromStatus(UserCollector::kUserId, | 233 EXPECT_FALSE(collector_.GetIdFromStatus(UserCollector::kUserId, |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 EXPECT_EQ(expectations[i].exists, | 338 EXPECT_EQ(expectations[i].exists, |
303 file_util::PathExists( | 339 file_util::PathExists( |
304 container_path.Append(expectations[i].name))); | 340 container_path.Append(expectations[i].name))); |
305 } | 341 } |
306 } | 342 } |
307 | 343 |
308 int main(int argc, char **argv) { | 344 int main(int argc, char **argv) { |
309 ::testing::InitGoogleTest(&argc, argv); | 345 ::testing::InitGoogleTest(&argc, argv); |
310 return RUN_ALL_TESTS(); | 346 return RUN_ALL_TESTS(); |
311 } | 347 } |
OLD | NEW |