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

Side by Side Diff: third_party/crashpad/crashpad/snapshot/win/pe_image_annotations_reader_test.cc

Issue 1505213004: Copy Crashpad into the Chrome tree instead of importing it via DEPS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update Created 5 years 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
(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/pe_image_annotations_reader.h"
16
17 #include <stdlib.h>
18 #include <string.h>
19
20 #include <map>
21 #include <string>
22 #include <vector>
23
24 #include "base/basictypes.h"
25 #include "base/files/file_path.h"
26 #include "base/strings/utf_string_conversions.h"
27 #include "client/crashpad_info.h"
28 #include "client/simple_string_dictionary.h"
29 #include "gtest/gtest.h"
30 #include "snapshot/win/pe_image_reader.h"
31 #include "snapshot/win/process_reader_win.h"
32 #include "test/paths.h"
33 #include "test/win/child_launcher.h"
34 #include "test/win/win_multiprocess.h"
35 #include "util/file/file_io.h"
36 #include "util/win/process_info.h"
37
38 namespace crashpad {
39 namespace test {
40 namespace {
41
42 enum TestType {
43 // Don't crash, just test the CrashpadInfo interface.
44 kDontCrash = 0,
45
46 // The child process should crash by __debugbreak().
47 kCrashDebugBreak,
48 };
49
50 void TestAnnotationsOnCrash(TestType type,
51 const base::string16& directory_modification) {
52 // Spawn a child process, passing it the pipe name to connect to.
53 base::FilePath test_executable = Paths::Executable();
54 std::wstring child_test_executable =
55 test_executable.DirName()
56 .Append(directory_modification)
57 .Append(test_executable.BaseName().RemoveFinalExtension().value() +
58 L"_simple_annotations.exe")
59 .value();
60 ChildLauncher child(child_test_executable, L"");
61 child.Start();
62
63 // Wait for the child process to indicate that it's done setting up its
64 // annotations via the CrashpadInfo interface.
65 char c;
66 CheckedReadFile(child.stdout_read_handle(), &c, sizeof(c));
67
68 ProcessReaderWin process_reader;
69 ASSERT_TRUE(process_reader.Initialize(child.process_handle(),
70 ProcessSuspensionState::kRunning));
71
72 // Verify the "simple map" annotations set via the CrashpadInfo interface.
73 const std::vector<ProcessInfo::Module>& modules = process_reader.Modules();
74 std::map<std::string, std::string> all_annotations_simple_map;
75 for (const ProcessInfo::Module& module : modules) {
76 PEImageReader pe_image_reader;
77 pe_image_reader.Initialize(&process_reader,
78 module.dll_base,
79 module.size,
80 base::UTF16ToUTF8(module.name));
81 PEImageAnnotationsReader module_annotations_reader(
82 &process_reader, &pe_image_reader, module.name);
83 std::map<std::string, std::string> module_annotations_simple_map =
84 module_annotations_reader.SimpleMap();
85 all_annotations_simple_map.insert(module_annotations_simple_map.begin(),
86 module_annotations_simple_map.end());
87 }
88
89 EXPECT_GE(all_annotations_simple_map.size(), 5u);
90 EXPECT_EQ("crash", all_annotations_simple_map["#TEST# pad"]);
91 EXPECT_EQ("value", all_annotations_simple_map["#TEST# key"]);
92 EXPECT_EQ("y", all_annotations_simple_map["#TEST# x"]);
93 EXPECT_EQ("shorter", all_annotations_simple_map["#TEST# longer"]);
94 EXPECT_EQ("", all_annotations_simple_map["#TEST# empty_value"]);
95
96 // Tell the child process to continue.
97 DWORD expected_exit_code;
98 switch (type) {
99 case kDontCrash:
100 c = ' ';
101 expected_exit_code = 0;
102 break;
103 case kCrashDebugBreak:
104 c = 'd';
105 expected_exit_code = STATUS_BREAKPOINT;
106 break;
107 default:
108 FAIL();
109 }
110 CheckedWriteFile(child.stdin_write_handle(), &c, sizeof(c));
111
112 EXPECT_EQ(expected_exit_code, child.WaitForExit());
113 }
114
115 TEST(PEImageAnnotationsReader, DontCrash) {
116 TestAnnotationsOnCrash(kDontCrash, FILE_PATH_LITERAL("."));
117 }
118
119 TEST(PEImageAnnotationsReader, CrashDebugBreak) {
120 TestAnnotationsOnCrash(kCrashDebugBreak, FILE_PATH_LITERAL("."));
121 }
122
123 #if defined(ARCH_CPU_64_BITS)
124 TEST(PEImageAnnotationsReader, DontCrashWOW64) {
125 #ifndef NDEBUG
126 TestAnnotationsOnCrash(kDontCrash, FILE_PATH_LITERAL("..\\..\\out\\Debug"));
127 #else
128 TestAnnotationsOnCrash(kDontCrash, FILE_PATH_LITERAL("..\\..\\out\\Release"));
129 #endif
130 }
131
132 TEST(PEImageAnnotationsReader, CrashDebugBreakWOW64) {
133 #ifndef NDEBUG
134 TestAnnotationsOnCrash(kCrashDebugBreak,
135 FILE_PATH_LITERAL("..\\..\\out\\Debug"));
136 #else
137 TestAnnotationsOnCrash(kCrashDebugBreak,
138 FILE_PATH_LITERAL("..\\..\\out\\Release"));
139 #endif
140 }
141 #endif // ARCH_CPU_64_BITS
142
143 } // namespace
144 } // namespace test
145 } // namespace crashpad
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698