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 "base/files/file_path.h" |
| 18 #include "gtest/gtest.h" |
| 19 #include "snapshot/win/module_snapshot_win.h" |
| 20 #include "snapshot/win/pe_image_reader.h" |
| 21 #include "snapshot/win/process_reader_win.h" |
| 22 #include "util/file/file_io.h" |
| 23 #include "util/win/scoped_handle.h" |
| 24 #include "util/win/scoped_process_suspend.h" |
| 25 #include "test/paths.h" |
| 26 #include "test/win/child_launcher.h" |
| 27 |
| 28 namespace crashpad { |
| 29 namespace test { |
| 30 namespace { |
| 31 |
| 32 void TestImageReaderChild(const base::string16& directory_modification) { |
| 33 UUID done_uuid(UUID::InitializeWithNewTag{}); |
| 34 ScopedKernelHANDLE done( |
| 35 CreateEvent(nullptr, true, false, done_uuid.ToString16().c_str())); |
| 36 ASSERT_TRUE(done.get()); |
| 37 |
| 38 base::FilePath test_executable = Paths::Executable(); |
| 39 std::wstring child_test_executable = |
| 40 test_executable.DirName() |
| 41 .Append(directory_modification) |
| 42 .Append(test_executable.BaseName().RemoveFinalExtension().value() + |
| 43 L"_image_reader.exe") |
| 44 .value(); |
| 45 ChildLauncher child(child_test_executable, done_uuid.ToString16()); |
| 46 child.Start(); |
| 47 |
| 48 char c; |
| 49 ASSERT_TRUE(LoggingReadFile(child.stdout_read_handle(), &c, sizeof(c))); |
| 50 ASSERT_EQ(' ', c); |
| 51 |
| 52 ScopedProcessSuspend suspend(child.process_handle()); |
| 53 |
| 54 ProcessSnapshotWin process_snapshot; |
| 55 ASSERT_TRUE(process_snapshot.Initialize(child.process_handle(), |
| 56 ProcessSuspensionState::kSuspended)); |
| 57 |
| 58 ASSERT_GE(process_snapshot.Modules().size(), 2u); |
| 59 |
| 60 UUID uuid; |
| 61 DWORD age; |
| 62 std::string pdbname; |
| 63 const std::string suffix(".pdb"); |
| 64 |
| 65 // Check the main .exe to see that we can retrieve its sections. |
| 66 auto module = reinterpret_cast<const internal::ModuleSnapshotWin*>( |
| 67 process_snapshot.Modules()[0]); |
| 68 ASSERT_TRUE(module->pe_image_reader().DebugDirectoryInformation( |
| 69 &uuid, &age, &pdbname)); |
| 70 EXPECT_NE(std::string::npos, |
| 71 pdbname.find("crashpad_snapshot_test_image_reader")); |
| 72 EXPECT_EQ( |
| 73 0, |
| 74 pdbname.compare(pdbname.size() - suffix.size(), suffix.size(), suffix)); |
| 75 |
| 76 // Check the dll it loads too. |
| 77 module = reinterpret_cast<const internal::ModuleSnapshotWin*>( |
| 78 process_snapshot.Modules().back()); |
| 79 ASSERT_TRUE(module->pe_image_reader().DebugDirectoryInformation( |
| 80 &uuid, &age, &pdbname)); |
| 81 EXPECT_NE(std::string::npos, |
| 82 pdbname.find("crashpad_snapshot_test_image_reader_module")); |
| 83 EXPECT_EQ( |
| 84 0, |
| 85 pdbname.compare(pdbname.size() - suffix.size(), suffix.size(), suffix)); |
| 86 |
| 87 // Tell the child it can terminate. |
| 88 SetEvent(done.get()); |
| 89 } |
| 90 |
| 91 TEST(ProcessSnapshotTest, CrashpadInfoChild) { |
| 92 TestImageReaderChild(FILE_PATH_LITERAL(".")); |
| 93 } |
| 94 |
| 95 #if defined(ARCH_CPU_64_BITS) |
| 96 TEST(ProcessSnapshotTest, CrashpadInfoChildWOW64) { |
| 97 #ifndef NDEBUG |
| 98 TestImageReaderChild(FILE_PATH_LITERAL("..\\..\\out\\Debug")); |
| 99 #else |
| 100 TestImageReaderChild(FILE_PATH_LITERAL("..\\..\\out\\Release")); |
| 101 #endif |
| 102 } |
| 103 #endif |
| 104 |
| 105 } // namespace |
| 106 } // namespace test |
| 107 } // namespace crashpad |
OLD | NEW |