OLD | NEW |
1 // Copyright 2014 The Crashpad Authors. All rights reserved. | 1 // Copyright 2014 The Crashpad Authors. All rights reserved. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
13 // limitations under the License. | 13 // limitations under the License. |
14 | 14 |
15 #include "util/posix/process_info.h" | 15 #include "util/posix/process_info.h" |
16 | 16 |
17 #include <time.h> | 17 #include <time.h> |
| 18 #include <stdio.h> |
18 #include <unistd.h> | 19 #include <unistd.h> |
19 | 20 |
20 #include <set> | 21 #include <set> |
21 #include <string> | 22 #include <string> |
22 #include <vector> | 23 #include <vector> |
23 | 24 |
| 25 #include "base/files/scoped_file.h" |
24 #include "build/build_config.h" | 26 #include "build/build_config.h" |
25 #include "gtest/gtest.h" | 27 #include "gtest/gtest.h" |
26 #include "test/errors.h" | 28 #include "test/errors.h" |
27 #include "util/misc/implicit_cast.h" | 29 #include "util/misc/implicit_cast.h" |
28 | 30 |
29 #if defined(OS_MACOSX) | 31 #if defined(OS_MACOSX) |
30 #include <crt_externs.h> | 32 #include <crt_externs.h> |
31 #endif | 33 #endif |
32 | 34 |
33 namespace crashpad { | 35 namespace crashpad { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 | 93 |
92 std::vector<std::string> argv; | 94 std::vector<std::string> argv; |
93 ASSERT_TRUE(process_info.Arguments(&argv)); | 95 ASSERT_TRUE(process_info.Arguments(&argv)); |
94 | 96 |
95 // gtest argv processing scrambles argv, but it leaves argc and argv[0] | 97 // gtest argv processing scrambles argv, but it leaves argc and argv[0] |
96 // intact, so test those. | 98 // intact, so test those. |
97 | 99 |
98 #if defined(OS_MACOSX) | 100 #if defined(OS_MACOSX) |
99 int expect_argc = *_NSGetArgc(); | 101 int expect_argc = *_NSGetArgc(); |
100 char** expect_argv = *_NSGetArgv(); | 102 char** expect_argv = *_NSGetArgv(); |
| 103 #elif defined(OS_LINUX) || defined(OS_ANDROID) |
| 104 std::vector<std::string> expect_arg_vector; |
| 105 { |
| 106 base::ScopedFILE cmdline(fopen("/proc/self/cmdline", "r")); |
| 107 ASSERT_NE(nullptr, cmdline.get()) << ErrnoMessage("fopen"); |
| 108 |
| 109 int expect_arg_char; |
| 110 std::string expect_arg_string; |
| 111 while ((expect_arg_char = fgetc(cmdline.get())) != EOF) { |
| 112 if (expect_arg_char != '\0') { |
| 113 expect_arg_string.append(1, expect_arg_char); |
| 114 } else { |
| 115 expect_arg_vector.push_back(expect_arg_string); |
| 116 expect_arg_string.clear(); |
| 117 } |
| 118 } |
| 119 ASSERT_EQ(0, ferror(cmdline.get())) << ErrnoMessage("fgetc"); |
| 120 ASSERT_TRUE(expect_arg_string.empty()); |
| 121 } |
| 122 |
| 123 std::vector<const char*> expect_argv_storage; |
| 124 for (const std::string& expect_arg_string : expect_arg_vector) { |
| 125 expect_argv_storage.push_back(expect_arg_string.c_str()); |
| 126 } |
| 127 |
| 128 int expect_argc = expect_argv_storage.size(); |
| 129 const char* const* expect_argv = |
| 130 !expect_argv_storage.empty() ? &expect_argv_storage[0] : nullptr; |
101 #else | 131 #else |
102 #error Obtain expect_argc and expect_argv correctly on your system. | 132 #error Obtain expect_argc and expect_argv correctly on your system. |
103 #endif | 133 #endif |
104 | 134 |
105 int argc = implicit_cast<int>(argv.size()); | 135 int argc = implicit_cast<int>(argv.size()); |
106 EXPECT_EQ(expect_argc, argc); | 136 EXPECT_EQ(expect_argc, argc); |
107 | 137 |
108 ASSERT_GE(expect_argc, 1); | 138 ASSERT_GE(expect_argc, 1); |
109 ASSERT_GE(argc, 1); | 139 ASSERT_GE(argc, 1); |
110 | 140 |
(...skipping 28 matching lines...) Expand all Loading... |
139 EXPECT_EQ(implicit_cast<uid_t>(0), process_info.SavedUserID()); | 169 EXPECT_EQ(implicit_cast<uid_t>(0), process_info.SavedUserID()); |
140 EXPECT_EQ(implicit_cast<gid_t>(0), process_info.RealGroupID()); | 170 EXPECT_EQ(implicit_cast<gid_t>(0), process_info.RealGroupID()); |
141 EXPECT_EQ(implicit_cast<gid_t>(0), process_info.EffectiveGroupID()); | 171 EXPECT_EQ(implicit_cast<gid_t>(0), process_info.EffectiveGroupID()); |
142 EXPECT_EQ(implicit_cast<gid_t>(0), process_info.SavedGroupID()); | 172 EXPECT_EQ(implicit_cast<gid_t>(0), process_info.SavedGroupID()); |
143 EXPECT_FALSE(process_info.AllGroups().empty()); | 173 EXPECT_FALSE(process_info.AllGroups().empty()); |
144 } | 174 } |
145 | 175 |
146 } // namespace | 176 } // namespace |
147 } // namespace test | 177 } // namespace test |
148 } // namespace crashpad | 178 } // namespace crashpad |
OLD | NEW |