Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Crashpad Authors. All rights reserved. | |
| 2 // | |
| 3 // Licensed under the Apache License, Version 2.0 (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 | |
| 6 // | |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | |
| 8 // | |
| 9 // Unless required by applicable law or agreed to in writing, software | |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 12 // See the License for the specific language governing permissions and | |
| 13 // limitations under the License. | |
| 14 | |
| 15 #include "snapshot/win/process_snapshot_win.h" | |
| 16 | |
| 17 #include <rpc.h> | |
| 18 | |
| 19 #include "base/files/file_path.h" | |
| 20 #include "gtest/gtest.h" | |
| 21 #include "snapshot/win/module_snapshot_win.h" | |
| 22 #include "snapshot/win/pe_image_reader.h" | |
| 23 #include "snapshot/win/process_reader_win.h" | |
| 24 #include "util/file/file_io.h" | |
| 25 #include "util/win/scoped_handle.h" | |
| 26 #include "util/win/scoped_process_suspend.h" | |
| 27 #include "test/paths.h" | |
| 28 #include "test/win/child_launcher.h" | |
| 29 | |
| 30 namespace crashpad { | |
| 31 namespace test { | |
| 32 namespace { | |
| 33 | |
| 34 void TestImageReaderChild(const base::string16& directory_modification) { | |
| 35 ::UUID system_uuid; | |
| 36 ASSERT_EQ(RPC_S_OK, UuidCreate(&system_uuid)); | |
| 37 UUID done_uuid(reinterpret_cast<const uint8_t*>(&system_uuid.Data1)); | |
|
Mark Mentovai
2015/09/19 03:02:47
Is &system_uuid enough? But even more, isn’t this
scottmg
2015/09/19 04:24:41
Even better, we have a constructor that does this
| |
| 38 ScopedKernelHANDLE done( | |
| 39 CreateEvent(nullptr, true, false, done_uuid.ToString16().c_str())); | |
|
Mark Mentovai
2015/09/19 03:02:47
<windows.h>
scottmg
2015/09/19 04:24:41
It's in process_snapshot_win.h, or does that exemp
Mark Mentovai
2015/09/19 19:20:26
scottmg wrote:
| |
| 40 ASSERT_TRUE(done.get()); | |
| 41 | |
| 42 base::FilePath test_executable = Paths::Executable(); | |
| 43 std::wstring child_test_executable = | |
|
Mark Mentovai
2015/09/19 03:02:47
<string>
scottmg
2015/09/19 04:24:41
Same.
| |
| 44 test_executable.DirName() | |
| 45 .Append(directory_modification) | |
| 46 .Append(test_executable.BaseName().RemoveFinalExtension().value() + | |
| 47 L"_image_reader.exe") | |
| 48 .value(); | |
| 49 ChildLauncher child(child_test_executable, done_uuid.ToString16()); | |
| 50 child.Start(); | |
| 51 | |
| 52 char c; | |
| 53 ASSERT_TRUE(LoggingReadFile(child.stdout_read_handle(), &c, sizeof(c))); | |
| 54 ASSERT_EQ(c, ' '); | |
|
Mark Mentovai
2015/09/19 03:02:47
Reverse the arguments.
scottmg
2015/09/19 04:24:41
Done.
| |
| 55 | |
| 56 ScopedProcessSuspend suspend(child.process_handle()); | |
| 57 | |
| 58 ProcessSnapshotWin process_snapshot; | |
| 59 ASSERT_TRUE(process_snapshot.Initialize(child.process_handle(), | |
| 60 ProcessSuspensionState::kSuspended)); | |
| 61 | |
| 62 ASSERT_GE(process_snapshot.Modules().size(), 2u); | |
| 63 | |
| 64 UUID uuid; | |
| 65 DWORD age; | |
| 66 std::string pdbname; | |
| 67 const std::string suffix(".pdb"); | |
| 68 | |
| 69 // Check the main .exe to see that we can retrieve its sections. | |
| 70 ASSERT_TRUE(reinterpret_cast<const internal::ModuleSnapshotWin*>( | |
| 71 process_snapshot.Modules()[0]) | |
| 72 ->pe_image_reader() | |
|
Mark Mentovai
2015/09/19 03:02:47
All right if this is what clang-format decided sho
scottmg
2015/09/19 04:24:41
Broke it up a bit.
| |
| 73 .DebugDirectoryInformation(&uuid, &age, &pdbname)); | |
| 74 EXPECT_NE(std::string::npos, | |
| 75 pdbname.find("crashpad_snapshot_test_image_reader")); | |
| 76 EXPECT_EQ( | |
| 77 0, | |
| 78 pdbname.compare(pdbname.size() - suffix.size(), suffix.size(), suffix)); | |
| 79 | |
| 80 // Check the dll it loads too. | |
| 81 ASSERT_TRUE(reinterpret_cast<const internal::ModuleSnapshotWin*>( | |
| 82 process_snapshot.Modules().back()) | |
| 83 ->pe_image_reader() | |
| 84 .DebugDirectoryInformation(&uuid, &age, &pdbname)); | |
| 85 EXPECT_NE(std::string::npos, | |
| 86 pdbname.find("crashpad_snapshot_test_image_reader_module")); | |
| 87 EXPECT_EQ( | |
| 88 0, | |
| 89 pdbname.compare(pdbname.size() - suffix.size(), suffix.size(), suffix)); | |
| 90 | |
| 91 // Tell the child it can terminate. | |
| 92 SetEvent(done.get()); | |
| 93 } | |
| 94 | |
| 95 TEST(ProcessSnapshotTest, CrashpadInfoChild) { | |
| 96 TestImageReaderChild(FILE_PATH_LITERAL(".")); | |
| 97 } | |
| 98 | |
| 99 #if defined(ARCH_CPU_64_BITS) | |
| 100 TEST(ProcessSnapshotTest, CrashpadInfoChildWOW64) { | |
| 101 #ifndef NDEBUG | |
| 102 TestImageReaderChild(FILE_PATH_LITERAL("..\\..\\out\\Debug")); | |
| 103 #else | |
| 104 TestImageReaderChild(FILE_PATH_LITERAL("..\\..\\out\\Release")); | |
| 105 #endif | |
| 106 } | |
| 107 #endif | |
| 108 | |
| 109 } // namespace | |
| 110 } // namespace test | |
| 111 } // namespace crashpad | |
| OLD | NEW |