Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(104)

Side by Side Diff: snapshot/win/exception_snapshot_win_test.cc

Issue 1352323002: win: Make reading NT_IMAGE_HEADERS work cross-bitness (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@cleanup-crashpad-info
Patch Set: fixes2 Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "snapshot/win/exception_snapshot_win.h" 15 #include "snapshot/win/exception_snapshot_win.h"
16 16
17 #include <string> 17 #include <string>
18 18
19 #include "base/files/file_path.h" 19 #include "base/files/file_path.h"
20 #include "base/strings/stringprintf.h" 20 #include "base/strings/stringprintf.h"
21 #include "base/strings/string16.h" 21 #include "base/strings/string16.h"
22 #include "base/strings/utf_string_conversions.h" 22 #include "base/strings/utf_string_conversions.h"
23 #include "client/crashpad_client.h" 23 #include "client/crashpad_client.h"
24 #include "gtest/gtest.h" 24 #include "gtest/gtest.h"
25 #include "snapshot/win/process_snapshot_win.h" 25 #include "snapshot/win/process_snapshot_win.h"
26 #include "test/paths.h" 26 #include "test/paths.h"
27 #include "test/win/win_child_process.h" 27 #include "test/win/child_launcher.h"
28 #include "util/file/file_io.h"
28 #include "util/thread/thread.h" 29 #include "util/thread/thread.h"
29 #include "util/win/exception_handler_server.h" 30 #include "util/win/exception_handler_server.h"
30 #include "util/win/registration_protocol_win.h" 31 #include "util/win/registration_protocol_win.h"
31 #include "util/win/scoped_handle.h" 32 #include "util/win/scoped_handle.h"
32 #include "util/win/scoped_process_suspend.h" 33 #include "util/win/scoped_process_suspend.h"
33 34
34 namespace crashpad { 35 namespace crashpad {
35 namespace test { 36 namespace test {
36 namespace { 37 namespace {
37 38
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 WaitForSingleObject(server_ready.get(), INFINITE); 151 WaitForSingleObject(server_ready.get(), INFINITE);
151 152
152 // Spawn a child process, passing it the pipe name to connect to. 153 // Spawn a child process, passing it the pipe name to connect to.
153 base::FilePath test_executable = Paths::Executable(); 154 base::FilePath test_executable = Paths::Executable();
154 std::wstring child_test_executable = 155 std::wstring child_test_executable =
155 test_executable.DirName() 156 test_executable.DirName()
156 .Append(directory_modification) 157 .Append(directory_modification)
157 .Append(test_executable.BaseName().RemoveFinalExtension().value() + 158 .Append(test_executable.BaseName().RemoveFinalExtension().value() +
158 L"_crashing_child.exe") 159 L"_crashing_child.exe")
159 .value(); 160 .value();
160 161 ChildLauncher child(child_test_executable, base::UTF8ToUTF16(pipe_name));
161 // Create a pipe for the stdout of the child. 162 child.Start();
162 SECURITY_ATTRIBUTES security_attributes = {0};
163 security_attributes.nLength = sizeof(SECURITY_ATTRIBUTES);
164 security_attributes.bInheritHandle = true;
165 HANDLE stdout_read;
166 HANDLE stdout_write;
167 ASSERT_TRUE(CreatePipe(&stdout_read, &stdout_write, &security_attributes, 0));
168 ScopedFileHANDLE read_handle(stdout_read);
169 ScopedFileHANDLE write_handle(stdout_write);
170 ASSERT_TRUE(SetHandleInformation(read_handle.get(), HANDLE_FLAG_INHERIT, 0));
171
172 std::wstring command_line =
173 child_test_executable + L" " + base::UTF8ToUTF16(pipe_name);
174 STARTUPINFO startup_info = {0};
175 startup_info.cb = sizeof(startup_info);
176 startup_info.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
177 startup_info.hStdOutput = write_handle.get();
178 startup_info.hStdError = GetStdHandle(STD_ERROR_HANDLE);
179 startup_info.dwFlags = STARTF_USESTDHANDLES;
180 PROCESS_INFORMATION process_information;
181 ASSERT_TRUE(CreateProcess(child_test_executable.c_str(),
182 &command_line[0],
183 nullptr,
184 nullptr,
185 true,
186 0,
187 nullptr,
188 nullptr,
189 &startup_info,
190 &process_information));
191 // Take ownership of the two process handles returned.
192 ScopedKernelHANDLE process_main_thread_handle(process_information.hThread);
193 ScopedKernelHANDLE process_handle(process_information.hProcess);
194 163
195 // The child tells us (approximately) where it will crash. 164 // The child tells us (approximately) where it will crash.
196 WinVMAddress break_near_address; 165 WinVMAddress break_near_address;
197 LoggingReadFile( 166 LoggingReadFile(child.stdout_read_handle(),
198 read_handle.get(), &break_near_address, sizeof(break_near_address)); 167 &break_near_address,
168 sizeof(break_near_address));
199 delegate.set_break_near(break_near_address); 169 delegate.set_break_near(break_near_address);
200 170
201 // Wait for the child to crash and the exception information to be validated. 171 // Wait for the child to crash and the exception information to be validated.
202 WaitForSingleObject(completed.get(), INFINITE); 172 WaitForSingleObject(completed.get(), INFINITE);
203 } 173 }
204 174
205 TEST(ExceptionSnapshotWinTest, ChildCrash) { 175 TEST(ExceptionSnapshotWinTest, ChildCrash) {
206 TestCrashingChild(FILE_PATH_LITERAL(".")); 176 TestCrashingChild(FILE_PATH_LITERAL("."));
207 } 177 }
208 178
209 #if defined(ARCH_CPU_64_BITS) 179 #if defined(ARCH_CPU_64_BITS)
210 TEST(ExceptionSnapshotWinTest, ChildCrashWOW64) { 180 TEST(ExceptionSnapshotWinTest, ChildCrashWOW64) {
211 #ifndef NDEBUG 181 #ifndef NDEBUG
212 TestCrashingChild(FILE_PATH_LITERAL("..\\..\\out\\Debug")); 182 TestCrashingChild(FILE_PATH_LITERAL("..\\..\\out\\Debug"));
213 #else 183 #else
214 TestCrashingChild(FILE_PATH_LITERAL("..\\..\\out\\Release")); 184 TestCrashingChild(FILE_PATH_LITERAL("..\\..\\out\\Release"));
215 #endif 185 #endif
216 } 186 }
217 #endif // ARCH_CPU_64_BITS 187 #endif // ARCH_CPU_64_BITS
218 188
219 } // namespace 189 } // namespace
220 } // namespace test 190 } // namespace test
221 } // namespace crashpad 191 } // namespace crashpad
OLDNEW
« no previous file with comments | « snapshot/win/crashpad_snapshot_test_image_reader_module.cc ('k') | snapshot/win/module_snapshot_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698