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 <imagehlp.h> | 17 #include <imagehlp.h> |
18 #include <rpc.h> | |
19 #include <wchar.h> | 18 #include <wchar.h> |
20 | 19 |
21 #include "base/files/file_path.h" | 20 #include "base/files/file_path.h" |
22 #include "build/build_config.h" | 21 #include "build/build_config.h" |
23 #include "gtest/gtest.h" | 22 #include "gtest/gtest.h" |
24 #include "test/paths.h" | 23 #include "test/paths.h" |
| 24 #include "test/win/child_launcher.h" |
25 #include "util/file/file_io.h" | 25 #include "util/file/file_io.h" |
26 #include "util/misc/uuid.h" | 26 #include "util/misc/uuid.h" |
27 #include "util/win/scoped_handle.h" | 27 #include "util/win/scoped_handle.h" |
28 | 28 |
29 namespace crashpad { | 29 namespace crashpad { |
30 namespace test { | 30 namespace test { |
31 namespace { | 31 namespace { |
32 | 32 |
33 const wchar_t kNtdllName[] = L"\\ntdll.dll"; | 33 const wchar_t kNtdllName[] = L"\\ntdll.dll"; |
34 | 34 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 EXPECT_EQ(modules[0].timestamp, | 99 EXPECT_EQ(modules[0].timestamp, |
100 GetTimestampForModule(GetModuleHandle(nullptr))); | 100 GetTimestampForModule(GetModuleHandle(nullptr))); |
101 // System modules are forced to particular stamps and the file header values | 101 // System modules are forced to particular stamps and the file header values |
102 // don't match the on-disk times. Just make sure we got some data here. | 102 // don't match the on-disk times. Just make sure we got some data here. |
103 EXPECT_GT(modules[1].timestamp, 0); | 103 EXPECT_GT(modules[1].timestamp, 0); |
104 } | 104 } |
105 | 105 |
106 void TestOtherProcess(const base::string16& directory_modification) { | 106 void TestOtherProcess(const base::string16& directory_modification) { |
107 ProcessInfo process_info; | 107 ProcessInfo process_info; |
108 | 108 |
109 ::UUID system_uuid; | 109 UUID started_uuid(UUID::InitializeWithNewTag{}); |
110 ASSERT_EQ(RPC_S_OK, UuidCreate(&system_uuid)); | 110 UUID done_uuid(UUID::InitializeWithNewTag{}); |
111 UUID started_uuid(reinterpret_cast<const uint8_t*>(&system_uuid.Data1)); | |
112 ASSERT_EQ(RPC_S_OK, UuidCreate(&system_uuid)); | |
113 UUID done_uuid(reinterpret_cast<const uint8_t*>(&system_uuid.Data1)); | |
114 | 111 |
115 ScopedKernelHANDLE started( | 112 ScopedKernelHANDLE started( |
116 CreateEvent(nullptr, true, false, started_uuid.ToString16().c_str())); | 113 CreateEvent(nullptr, true, false, started_uuid.ToString16().c_str())); |
117 ASSERT_TRUE(started.get()); | 114 ASSERT_TRUE(started.get()); |
118 ScopedKernelHANDLE done( | 115 ScopedKernelHANDLE done( |
119 CreateEvent(nullptr, true, false, done_uuid.ToString16().c_str())); | 116 CreateEvent(nullptr, true, false, done_uuid.ToString16().c_str())); |
120 ASSERT_TRUE(done.get()); | 117 ASSERT_TRUE(done.get()); |
121 | 118 |
122 base::FilePath test_executable = Paths::Executable(); | 119 base::FilePath test_executable = Paths::Executable(); |
123 | 120 |
124 std::wstring child_test_executable = | 121 std::wstring child_test_executable = |
125 test_executable.DirName() | 122 test_executable.DirName() |
126 .Append(directory_modification) | 123 .Append(directory_modification) |
127 .Append(test_executable.BaseName().RemoveFinalExtension().value() + | 124 .Append(test_executable.BaseName().RemoveFinalExtension().value() + |
128 L"_process_info_test_child.exe") | 125 L"_process_info_test_child.exe") |
129 .value(); | 126 .value(); |
130 // TODO(scottmg): Command line escaping utility. | 127 // TODO(scottmg): Command line escaping utility. |
131 std::wstring command_line = child_test_executable + L" " + | 128 ChildLauncher child( |
132 started_uuid.ToString16() + L" " + | 129 child_test_executable, |
133 done_uuid.ToString16(); | 130 started_uuid.ToString16() + L" " + done_uuid.ToString16()); |
134 STARTUPINFO startup_info = {0}; | 131 child.Start(); |
135 startup_info.cb = sizeof(startup_info); | |
136 PROCESS_INFORMATION process_information; | |
137 ASSERT_TRUE(CreateProcess(child_test_executable.c_str(), | |
138 &command_line[0], | |
139 nullptr, | |
140 nullptr, | |
141 false, | |
142 0, | |
143 nullptr, | |
144 nullptr, | |
145 &startup_info, | |
146 &process_information)); | |
147 // Take ownership of the two process handles returned. | |
148 ScopedKernelHANDLE process_main_thread_handle(process_information.hThread); | |
149 ScopedKernelHANDLE process_handle(process_information.hProcess); | |
150 | 132 |
151 // Wait until the test has completed initialization. | 133 // Wait until the test has completed initialization. |
152 ASSERT_EQ(WaitForSingleObject(started.get(), INFINITE), WAIT_OBJECT_0); | 134 ASSERT_EQ(WaitForSingleObject(started.get(), INFINITE), WAIT_OBJECT_0); |
153 | 135 |
154 ASSERT_TRUE(process_info.Initialize(process_information.hProcess)); | 136 ASSERT_TRUE(process_info.Initialize(child.process_handle())); |
155 | 137 |
156 // 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. |
157 SetEvent(done.get()); | 139 SetEvent(done.get()); |
158 | 140 |
159 std::vector<ProcessInfo::Module> modules; | 141 std::vector<ProcessInfo::Module> modules; |
160 EXPECT_TRUE(process_info.Modules(&modules)); | 142 EXPECT_TRUE(process_info.Modules(&modules)); |
161 ASSERT_GE(modules.size(), 3u); | 143 ASSERT_GE(modules.size(), 3u); |
162 std::wstring child_name = L"\\crashpad_util_test_process_info_test_child.exe"; | 144 std::wstring child_name = L"\\crashpad_util_test_process_info_test_child.exe"; |
163 ASSERT_GE(modules[0].name.size(), child_name.size()); | 145 ASSERT_GE(modules[0].name.size(), child_name.size()); |
164 EXPECT_EQ(child_name, | 146 EXPECT_EQ(child_name, |
(...skipping 21 matching lines...) Expand all Loading... |
186 TestOtherProcess(FILE_PATH_LITERAL("..\\..\\out\\Debug")); | 168 TestOtherProcess(FILE_PATH_LITERAL("..\\..\\out\\Debug")); |
187 #else | 169 #else |
188 TestOtherProcess(FILE_PATH_LITERAL("..\\..\\out\\Release")); | 170 TestOtherProcess(FILE_PATH_LITERAL("..\\..\\out\\Release")); |
189 #endif | 171 #endif |
190 } | 172 } |
191 #endif // ARCH_CPU_64_BITS | 173 #endif // ARCH_CPU_64_BITS |
192 | 174 |
193 } // namespace | 175 } // namespace |
194 } // namespace test | 176 } // namespace test |
195 } // namespace crashpad | 177 } // namespace crashpad |
OLD | NEW |