Index: snapshot/win/process_snapshot_win_test.cc |
diff --git a/snapshot/win/process_snapshot_win_test.cc b/snapshot/win/process_snapshot_win_test.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..ed3db9adf0a81a48f59087478ada8748ef58fc00 |
--- /dev/null |
+++ b/snapshot/win/process_snapshot_win_test.cc |
@@ -0,0 +1,111 @@ |
+// Copyright 2015 The Crashpad Authors. All rights reserved. |
+// |
+// Licensed under the Apache License, Version 2.0 (the "License"); |
+// you may not use this file except in compliance with the License. |
+// You may obtain a copy of the License at |
+// |
+// http://www.apache.org/licenses/LICENSE-2.0 |
+// |
+// Unless required by applicable law or agreed to in writing, software |
+// distributed under the License is distributed on an "AS IS" BASIS, |
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
+// See the License for the specific language governing permissions and |
+// limitations under the License. |
+ |
+#include "snapshot/win/process_snapshot_win.h" |
+ |
+#include <rpc.h> |
+ |
+#include "base/files/file_path.h" |
+#include "gtest/gtest.h" |
+#include "snapshot/win/module_snapshot_win.h" |
+#include "snapshot/win/pe_image_reader.h" |
+#include "snapshot/win/process_reader_win.h" |
+#include "util/file/file_io.h" |
+#include "util/win/scoped_handle.h" |
+#include "util/win/scoped_process_suspend.h" |
+#include "test/paths.h" |
+#include "test/win/child_launcher.h" |
+ |
+namespace crashpad { |
+namespace test { |
+namespace { |
+ |
+void TestImageReaderChild(const base::string16& directory_modification) { |
+ ::UUID system_uuid; |
+ ASSERT_EQ(RPC_S_OK, UuidCreate(&system_uuid)); |
+ 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
|
+ ScopedKernelHANDLE done( |
+ 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:
|
+ ASSERT_TRUE(done.get()); |
+ |
+ base::FilePath test_executable = Paths::Executable(); |
+ std::wstring child_test_executable = |
Mark Mentovai
2015/09/19 03:02:47
<string>
scottmg
2015/09/19 04:24:41
Same.
|
+ test_executable.DirName() |
+ .Append(directory_modification) |
+ .Append(test_executable.BaseName().RemoveFinalExtension().value() + |
+ L"_image_reader.exe") |
+ .value(); |
+ ChildLauncher child(child_test_executable, done_uuid.ToString16()); |
+ child.Start(); |
+ |
+ char c; |
+ ASSERT_TRUE(LoggingReadFile(child.stdout_read_handle(), &c, sizeof(c))); |
+ ASSERT_EQ(c, ' '); |
Mark Mentovai
2015/09/19 03:02:47
Reverse the arguments.
scottmg
2015/09/19 04:24:41
Done.
|
+ |
+ ScopedProcessSuspend suspend(child.process_handle()); |
+ |
+ ProcessSnapshotWin process_snapshot; |
+ ASSERT_TRUE(process_snapshot.Initialize(child.process_handle(), |
+ ProcessSuspensionState::kSuspended)); |
+ |
+ ASSERT_GE(process_snapshot.Modules().size(), 2u); |
+ |
+ UUID uuid; |
+ DWORD age; |
+ std::string pdbname; |
+ const std::string suffix(".pdb"); |
+ |
+ // Check the main .exe to see that we can retrieve its sections. |
+ ASSERT_TRUE(reinterpret_cast<const internal::ModuleSnapshotWin*>( |
+ process_snapshot.Modules()[0]) |
+ ->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.
|
+ .DebugDirectoryInformation(&uuid, &age, &pdbname)); |
+ EXPECT_NE(std::string::npos, |
+ pdbname.find("crashpad_snapshot_test_image_reader")); |
+ EXPECT_EQ( |
+ 0, |
+ pdbname.compare(pdbname.size() - suffix.size(), suffix.size(), suffix)); |
+ |
+ // Check the dll it loads too. |
+ ASSERT_TRUE(reinterpret_cast<const internal::ModuleSnapshotWin*>( |
+ process_snapshot.Modules().back()) |
+ ->pe_image_reader() |
+ .DebugDirectoryInformation(&uuid, &age, &pdbname)); |
+ EXPECT_NE(std::string::npos, |
+ pdbname.find("crashpad_snapshot_test_image_reader_module")); |
+ EXPECT_EQ( |
+ 0, |
+ pdbname.compare(pdbname.size() - suffix.size(), suffix.size(), suffix)); |
+ |
+ // Tell the child it can terminate. |
+ SetEvent(done.get()); |
+} |
+ |
+TEST(ProcessSnapshotTest, CrashpadInfoChild) { |
+ TestImageReaderChild(FILE_PATH_LITERAL(".")); |
+} |
+ |
+#if defined(ARCH_CPU_64_BITS) |
+TEST(ProcessSnapshotTest, CrashpadInfoChildWOW64) { |
+#ifndef NDEBUG |
+ TestImageReaderChild(FILE_PATH_LITERAL("..\\..\\out\\Debug")); |
+#else |
+ TestImageReaderChild(FILE_PATH_LITERAL("..\\..\\out\\Release")); |
+#endif |
+} |
+#endif |
+ |
+} // namespace |
+} // namespace test |
+} // namespace crashpad |