| 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> | 18 #include <rpc.h> |
| 19 #include <wchar.h> | 19 #include <wchar.h> |
| 20 | 20 |
| 21 #include "base/files/file_path.h" | 21 #include "base/files/file_path.h" |
| 22 #include "build/build_config.h" | 22 #include "build/build_config.h" |
| 23 #include "gtest/gtest.h" | 23 #include "gtest/gtest.h" |
| 24 #include "test/paths.h" | 24 #include "test/paths.h" |
| 25 #include "test/win/child_launcher.h" |
| 25 #include "util/file/file_io.h" | 26 #include "util/file/file_io.h" |
| 26 #include "util/misc/uuid.h" | 27 #include "util/misc/uuid.h" |
| 27 #include "util/win/scoped_handle.h" | 28 #include "util/win/scoped_handle.h" |
| 28 | 29 |
| 29 namespace crashpad { | 30 namespace crashpad { |
| 30 namespace test { | 31 namespace test { |
| 31 namespace { | 32 namespace { |
| 32 | 33 |
| 33 const wchar_t kNtdllName[] = L"\\ntdll.dll"; | 34 const wchar_t kNtdllName[] = L"\\ntdll.dll"; |
| 34 | 35 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 | 122 |
| 122 base::FilePath test_executable = Paths::Executable(); | 123 base::FilePath test_executable = Paths::Executable(); |
| 123 | 124 |
| 124 std::wstring child_test_executable = | 125 std::wstring child_test_executable = |
| 125 test_executable.DirName() | 126 test_executable.DirName() |
| 126 .Append(directory_modification) | 127 .Append(directory_modification) |
| 127 .Append(test_executable.BaseName().RemoveFinalExtension().value() + | 128 .Append(test_executable.BaseName().RemoveFinalExtension().value() + |
| 128 L"_process_info_test_child.exe") | 129 L"_process_info_test_child.exe") |
| 129 .value(); | 130 .value(); |
| 130 // TODO(scottmg): Command line escaping utility. | 131 // TODO(scottmg): Command line escaping utility. |
| 131 std::wstring command_line = child_test_executable + L" " + | 132 ChildLauncher child( |
| 132 started_uuid.ToString16() + L" " + | 133 child_test_executable, |
| 133 done_uuid.ToString16(); | 134 started_uuid.ToString16() + L" " + done_uuid.ToString16()); |
| 134 STARTUPINFO startup_info = {0}; | 135 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 | 136 |
| 151 // Wait until the test has completed initialization. | 137 // Wait until the test has completed initialization. |
| 152 ASSERT_EQ(WaitForSingleObject(started.get(), INFINITE), WAIT_OBJECT_0); | 138 ASSERT_EQ(WaitForSingleObject(started.get(), INFINITE), WAIT_OBJECT_0); |
| 153 | 139 |
| 154 ASSERT_TRUE(process_info.Initialize(process_information.hProcess)); | 140 ASSERT_TRUE(process_info.Initialize(child.process_handle())); |
| 155 | 141 |
| 156 // Tell the test it's OK to shut down now that we've read our data. | 142 // Tell the test it's OK to shut down now that we've read our data. |
| 157 SetEvent(done.get()); | 143 SetEvent(done.get()); |
| 158 | 144 |
| 159 std::vector<ProcessInfo::Module> modules; | 145 std::vector<ProcessInfo::Module> modules; |
| 160 EXPECT_TRUE(process_info.Modules(&modules)); | 146 EXPECT_TRUE(process_info.Modules(&modules)); |
| 161 ASSERT_GE(modules.size(), 3u); | 147 ASSERT_GE(modules.size(), 3u); |
| 162 std::wstring child_name = L"\\crashpad_util_test_process_info_test_child.exe"; | 148 std::wstring child_name = L"\\crashpad_util_test_process_info_test_child.exe"; |
| 163 ASSERT_GE(modules[0].name.size(), child_name.size()); | 149 ASSERT_GE(modules[0].name.size(), child_name.size()); |
| 164 EXPECT_EQ(child_name, | 150 EXPECT_EQ(child_name, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 186 TestOtherProcess(FILE_PATH_LITERAL("..\\..\\out\\Debug")); | 172 TestOtherProcess(FILE_PATH_LITERAL("..\\..\\out\\Debug")); |
| 187 #else | 173 #else |
| 188 TestOtherProcess(FILE_PATH_LITERAL("..\\..\\out\\Release")); | 174 TestOtherProcess(FILE_PATH_LITERAL("..\\..\\out\\Release")); |
| 189 #endif | 175 #endif |
| 190 } | 176 } |
| 191 #endif // ARCH_CPU_64_BITS | 177 #endif // ARCH_CPU_64_BITS |
| 192 | 178 |
| 193 } // namespace | 179 } // namespace |
| 194 } // namespace test | 180 } // namespace test |
| 195 } // namespace crashpad | 181 } // namespace crashpad |
| OLD | NEW |