OLD | NEW |
(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 "crash-reporter/crash_collector.h" |
| 9 #include "crash-reporter/system_logging_mock.h" |
| 10 #include "gflags/gflags.h" |
| 11 #include "gtest/gtest.h" |
| 12 |
| 13 void CountCrash() { |
| 14 ADD_FAILURE(); |
| 15 } |
| 16 |
| 17 bool IsMetrics() { |
| 18 ADD_FAILURE(); |
| 19 return false; |
| 20 } |
| 21 |
| 22 class CrashCollectorTest : public ::testing::Test { |
| 23 void SetUp() { |
| 24 collector_.Initialize(CountCrash, |
| 25 IsMetrics, |
| 26 &logging_); |
| 27 } |
| 28 protected: |
| 29 SystemLoggingMock logging_; |
| 30 CrashCollector collector_; |
| 31 pid_t pid_; |
| 32 }; |
| 33 |
| 34 TEST_F(CrashCollectorTest, Initialize) { |
| 35 ASSERT_TRUE(CountCrash == collector_.count_crash_function_); |
| 36 ASSERT_TRUE(IsMetrics == collector_.is_feedback_allowed_function_); |
| 37 ASSERT_TRUE(&logging_ == collector_.logger_); |
| 38 } |
| 39 |
| 40 TEST_F(CrashCollectorTest, GetCrashDirectoryInfo) { |
| 41 FilePath path; |
| 42 const int kRootUid = 0; |
| 43 const int kRootGid = 0; |
| 44 const int kNtpUid = 5; |
| 45 const int kChronosUid = 1000; |
| 46 const int kChronosGid = 1001; |
| 47 const mode_t kExpectedSystemMode = 01755; |
| 48 const mode_t kExpectedUserMode = 0755; |
| 49 |
| 50 mode_t directory_mode; |
| 51 uid_t directory_owner; |
| 52 gid_t directory_group; |
| 53 |
| 54 path = collector_.GetCrashDirectoryInfo(kRootUid, |
| 55 kChronosUid, |
| 56 kChronosGid, |
| 57 &directory_mode, |
| 58 &directory_owner, |
| 59 &directory_group); |
| 60 EXPECT_EQ("/var/spool/crash", path.value()); |
| 61 EXPECT_EQ(kExpectedSystemMode, directory_mode); |
| 62 EXPECT_EQ(kRootUid, directory_owner); |
| 63 EXPECT_EQ(kRootGid, directory_group); |
| 64 |
| 65 path = collector_.GetCrashDirectoryInfo(kNtpUid, |
| 66 kChronosUid, |
| 67 kChronosGid, |
| 68 &directory_mode, |
| 69 &directory_owner, |
| 70 &directory_group); |
| 71 EXPECT_EQ("/var/spool/crash", path.value()); |
| 72 EXPECT_EQ(kExpectedSystemMode, directory_mode); |
| 73 EXPECT_EQ(kRootUid, directory_owner); |
| 74 EXPECT_EQ(kRootGid, directory_group); |
| 75 |
| 76 path = collector_.GetCrashDirectoryInfo(kChronosUid, |
| 77 kChronosUid, |
| 78 kChronosGid, |
| 79 &directory_mode, |
| 80 &directory_owner, |
| 81 &directory_group); |
| 82 EXPECT_EQ("/home/chronos/user/crash", path.value()); |
| 83 EXPECT_EQ(kExpectedUserMode, directory_mode); |
| 84 EXPECT_EQ(kChronosUid, directory_owner); |
| 85 EXPECT_EQ(kChronosGid, directory_group); |
| 86 } |
| 87 |
| 88 TEST_F(CrashCollectorTest, FormatDumpBasename) { |
| 89 struct tm tm = {0}; |
| 90 tm.tm_sec = 15; |
| 91 tm.tm_min = 50; |
| 92 tm.tm_hour = 13; |
| 93 tm.tm_mday = 23; |
| 94 tm.tm_mon = 4; |
| 95 tm.tm_year = 110; |
| 96 tm.tm_isdst = -1; |
| 97 std::string basename = |
| 98 collector_.FormatDumpBasename("foo", mktime(&tm), 100); |
| 99 ASSERT_EQ("foo.20100523.135015.100", basename); |
| 100 } |
| 101 |
| 102 int main(int argc, char **argv) { |
| 103 ::testing::InitGoogleTest(&argc, argv); |
| 104 return RUN_ALL_TESTS(); |
| 105 } |
OLD | NEW |