OLD | NEW |
1 // Copyright 2015 The Crashpad Authors. All rights reserved. | 1 // Copyright 2015 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/win/process_info.h" | 15 #include "util/win/process_info.h" |
16 | 16 |
17 #include <rpc.h> | 17 #include <rpc.h> |
18 #include <wchar.h> | 18 #include <wchar.h> |
19 | 19 |
20 #include "base/files/file_path.h" | 20 #include "base/files/file_path.h" |
21 #include "build/build_config.h" | 21 #include "build/build_config.h" |
22 #include "gtest/gtest.h" | 22 #include "gtest/gtest.h" |
23 #include "test/paths.h" | 23 #include "test/paths.h" |
| 24 #include "util/file/file_io.h" |
24 #include "util/misc/uuid.h" | 25 #include "util/misc/uuid.h" |
25 #include "util/win/scoped_handle.h" | 26 #include "util/win/scoped_handle.h" |
26 | 27 |
27 namespace crashpad { | 28 namespace crashpad { |
28 namespace test { | 29 namespace test { |
29 namespace { | 30 namespace { |
30 | 31 |
31 const wchar_t kNtdllName[] = L"\\ntdll.dll"; | 32 const wchar_t kNtdllName[] = L"\\ntdll.dll"; |
32 | 33 |
| 34 time_t GetTimestampForModule(HMODULE module) { |
| 35 wchar_t filename[MAX_PATH]; |
| 36 if (!GetModuleFileName(module, filename, arraysize(filename))) |
| 37 return 0; |
| 38 struct _stat stat_buf; |
| 39 int rv = _wstat(filename, &stat_buf); |
| 40 EXPECT_EQ(0, rv); |
| 41 if (rv != 0) |
| 42 return 0; |
| 43 return stat_buf.st_mtime; |
| 44 } |
| 45 |
33 TEST(ProcessInfo, Self) { | 46 TEST(ProcessInfo, Self) { |
34 ProcessInfo process_info; | 47 ProcessInfo process_info; |
35 ASSERT_TRUE(process_info.Initialize(GetCurrentProcess())); | 48 ASSERT_TRUE(process_info.Initialize(GetCurrentProcess())); |
36 EXPECT_EQ(GetCurrentProcessId(), process_info.ProcessID()); | 49 EXPECT_EQ(GetCurrentProcessId(), process_info.ProcessID()); |
37 EXPECT_GT(process_info.ParentProcessID(), 0u); | 50 EXPECT_GT(process_info.ParentProcessID(), 0u); |
38 | 51 |
39 #if defined(ARCH_CPU_64_BITS) | 52 #if defined(ARCH_CPU_64_BITS) |
40 EXPECT_TRUE(process_info.Is64Bit()); | 53 EXPECT_TRUE(process_info.Is64Bit()); |
41 EXPECT_FALSE(process_info.IsWow64()); | 54 EXPECT_FALSE(process_info.IsWow64()); |
42 #else | 55 #else |
43 EXPECT_FALSE(process_info.Is64Bit()); | 56 EXPECT_FALSE(process_info.Is64Bit()); |
44 // Assume we won't be running these tests on a 32 bit host OS. | 57 // Assume we won't be running these tests on a 32 bit host OS. |
45 EXPECT_TRUE(process_info.IsWow64()); | 58 EXPECT_TRUE(process_info.IsWow64()); |
46 #endif | 59 #endif |
47 | 60 |
48 std::wstring command_line; | 61 std::wstring command_line; |
49 EXPECT_TRUE(process_info.CommandLine(&command_line)); | 62 EXPECT_TRUE(process_info.CommandLine(&command_line)); |
50 EXPECT_EQ(std::wstring(GetCommandLine()), command_line); | 63 EXPECT_EQ(std::wstring(GetCommandLine()), command_line); |
51 | 64 |
52 std::vector<std::wstring> modules; | 65 std::vector<ProcessInfo::Module> modules; |
53 EXPECT_TRUE(process_info.Modules(&modules)); | 66 EXPECT_TRUE(process_info.Modules(&modules)); |
54 ASSERT_GE(modules.size(), 2u); | 67 ASSERT_GE(modules.size(), 2u); |
55 const wchar_t kSelfName[] = L"\\crashpad_util_test.exe"; | 68 const wchar_t kSelfName[] = L"\\crashpad_util_test.exe"; |
56 ASSERT_GE(modules[0].size(), wcslen(kSelfName)); | 69 ASSERT_GE(modules[0].name.size(), wcslen(kSelfName)); |
57 EXPECT_EQ(kSelfName, | 70 EXPECT_EQ(kSelfName, |
58 modules[0].substr(modules[0].size() - wcslen(kSelfName))); | 71 modules[0].name.substr(modules[0].name.size() - wcslen(kSelfName))); |
59 ASSERT_GE(modules[1].size(), wcslen(kNtdllName)); | 72 ASSERT_GE(modules[1].name.size(), wcslen(kNtdllName)); |
60 EXPECT_EQ(kNtdllName, | 73 EXPECT_EQ( |
61 modules[1].substr(modules[1].size() - wcslen(kNtdllName))); | 74 kNtdllName, |
| 75 modules[1].name.substr(modules[1].name.size() - wcslen(kNtdllName))); |
| 76 |
| 77 EXPECT_EQ(modules[0].dll_base, |
| 78 reinterpret_cast<uintptr_t>(GetModuleHandle(nullptr))); |
| 79 EXPECT_EQ(modules[1].dll_base, |
| 80 reinterpret_cast<uintptr_t>(GetModuleHandle(L"ntdll.dll"))); |
| 81 |
| 82 EXPECT_GT(modules[0].size, 0); |
| 83 EXPECT_GT(modules[1].size, 0); |
| 84 |
| 85 EXPECT_EQ(modules[0].timestamp, |
| 86 GetTimestampForModule(GetModuleHandle(nullptr))); |
| 87 // System modules are forced to particular stamps and the file header values |
| 88 // don't match the on-disk times. Just make sure we got some data here. |
| 89 EXPECT_GT(modules[1].timestamp, 0); |
62 } | 90 } |
63 | 91 |
64 void TestOtherProcess(const std::wstring& child_name_suffix) { | 92 void TestOtherProcess(const std::wstring& child_name_suffix) { |
65 ProcessInfo process_info; | 93 ProcessInfo process_info; |
66 | 94 |
67 ::UUID system_uuid; | 95 ::UUID system_uuid; |
68 ASSERT_EQ(RPC_S_OK, UuidCreate(&system_uuid)); | 96 ASSERT_EQ(RPC_S_OK, UuidCreate(&system_uuid)); |
69 UUID started_uuid(reinterpret_cast<const uint8_t*>(&system_uuid.Data1)); | 97 UUID started_uuid(reinterpret_cast<const uint8_t*>(&system_uuid.Data1)); |
70 ASSERT_EQ(RPC_S_OK, UuidCreate(&system_uuid)); | 98 ASSERT_EQ(RPC_S_OK, UuidCreate(&system_uuid)); |
71 UUID done_uuid(reinterpret_cast<const uint8_t*>(&system_uuid.Data1)); | 99 UUID done_uuid(reinterpret_cast<const uint8_t*>(&system_uuid.Data1)); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 ScopedKernelHANDLE process_handle(process_information.hProcess); | 131 ScopedKernelHANDLE process_handle(process_information.hProcess); |
104 | 132 |
105 // Wait until the test has completed initialization. | 133 // Wait until the test has completed initialization. |
106 ASSERT_EQ(WaitForSingleObject(started.get(), INFINITE), WAIT_OBJECT_0); | 134 ASSERT_EQ(WaitForSingleObject(started.get(), INFINITE), WAIT_OBJECT_0); |
107 | 135 |
108 ASSERT_TRUE(process_info.Initialize(process_information.hProcess)); | 136 ASSERT_TRUE(process_info.Initialize(process_information.hProcess)); |
109 | 137 |
110 // Tell the test it's OK to shut down now that we've read our data. | 138 // Tell the test it's OK to shut down now that we've read our data. |
111 SetEvent(done.get()); | 139 SetEvent(done.get()); |
112 | 140 |
113 std::vector<std::wstring> modules; | 141 std::vector<ProcessInfo::Module> modules; |
114 EXPECT_TRUE(process_info.Modules(&modules)); | 142 EXPECT_TRUE(process_info.Modules(&modules)); |
115 ASSERT_GE(modules.size(), 3u); | 143 ASSERT_GE(modules.size(), 3u); |
116 std::wstring child_name = L"\\crashpad_util_test_process_info_test_child_" + | 144 std::wstring child_name = L"\\crashpad_util_test_process_info_test_child_" + |
117 child_name_suffix + L".exe"; | 145 child_name_suffix + L".exe"; |
118 ASSERT_GE(modules[0].size(), child_name.size()); | 146 ASSERT_GE(modules[0].name.size(), child_name.size()); |
119 EXPECT_EQ(child_name, | 147 EXPECT_EQ(child_name, |
120 modules[0].substr(modules[0].size() - child_name.size())); | 148 modules[0].name.substr(modules[0].name.size() - child_name.size())); |
121 ASSERT_GE(modules[1].size(), wcslen(kNtdllName)); | 149 ASSERT_GE(modules[1].name.size(), wcslen(kNtdllName)); |
122 EXPECT_EQ(kNtdllName, | 150 EXPECT_EQ( |
123 modules[1].substr(modules[1].size() - wcslen(kNtdllName))); | 151 kNtdllName, |
| 152 modules[1].name.substr(modules[1].name.size() - wcslen(kNtdllName))); |
124 // lz32.dll is an uncommonly-used-but-always-available module that the test | 153 // lz32.dll is an uncommonly-used-but-always-available module that the test |
125 // binary manually loads. | 154 // binary manually loads. |
126 const wchar_t kLz32dllName[] = L"\\lz32.dll"; | 155 const wchar_t kLz32dllName[] = L"\\lz32.dll"; |
127 ASSERT_GE(modules.back().size(), wcslen(kLz32dllName)); | 156 ASSERT_GE(modules.back().name.size(), wcslen(kLz32dllName)); |
128 EXPECT_EQ( | 157 EXPECT_EQ(kLz32dllName, |
129 kLz32dllName, | 158 modules.back().name.substr(modules.back().name.size() - |
130 modules.back().substr(modules.back().size() - wcslen(kLz32dllName))); | 159 wcslen(kLz32dllName))); |
131 } | 160 } |
132 | 161 |
133 TEST(ProcessInfo, OtherProcessX64) { | 162 TEST(ProcessInfo, OtherProcessX64) { |
134 TestOtherProcess(L"x64"); | 163 TestOtherProcess(L"x64"); |
135 } | 164 } |
136 | 165 |
137 TEST(ProcessInfo, OtherProcessX86) { | 166 TEST(ProcessInfo, OtherProcessX86) { |
138 TestOtherProcess(L"x86"); | 167 TestOtherProcess(L"x86"); |
139 } | 168 } |
140 | 169 |
141 } // namespace | 170 } // namespace |
142 } // namespace test | 171 } // namespace test |
143 } // namespace crashpad | 172 } // namespace crashpad |
OLD | NEW |