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

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

Issue 1138923004: win: Retrieve "simple map" annotations from modules (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@module-version
Patch Set: . Created 5 years, 6 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
« no previous file with comments | « snapshot/win/pe_image_annotations_reader.cc ('k') | test/test.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/strings/utf_string_conversions.h"
26 #include "client/crashpad_info.h"
27 #include "client/simple_string_dictionary.h"
28 #include "gtest/gtest.h"
29 #include "snapshot/win/pe_image_reader.h"
30 #include "snapshot/win/process_reader_win.h"
31 #include "test/win/win_multiprocess.h"
32 #include "util/file/file_io.h"
33 #include "util/win/process_info.h"
34
35 namespace crashpad {
36 namespace test {
37 namespace {
38
39 class TestPEImageAnnotationsReader final : public WinMultiprocess {
40 public:
41 enum TestType {
42 // Don't crash, just test the CrashpadInfo interface.
43 kDontCrash = 0,
44
45 // The child process should crash by __debugbreak().
46 kCrashDebugBreak,
47 };
48
49 explicit TestPEImageAnnotationsReader(TestType test_type)
50 : WinMultiprocess(), test_type_(test_type) {}
51
52 ~TestPEImageAnnotationsReader() {}
53
54 private:
55 // WinMultiprocess:
56
57 void WinMultiprocessParent() override {
58 ProcessReaderWin process_reader;
59 ASSERT_TRUE(process_reader.Initialize(ChildProcess()));
60
61 // Wait for the child process to indicate that it's done setting up its
62 // annotations via the CrashpadInfo interface.
63 char c;
64 CheckedReadFile(ReadPipeHandle(), &c, sizeof(c));
65
66 // Verify the "simple map" annotations set via the CrashpadInfo interface.
67 const std::vector<ProcessInfo::Module>& modules = process_reader.Modules();
68 std::map<std::string, std::string> all_annotations_simple_map;
69 for (const ProcessInfo::Module& module : modules) {
70 PEImageReader pe_image_reader;
71 pe_image_reader.Initialize(&process_reader,
72 module.dll_base,
73 module.size,
74 base::UTF16ToUTF8(module.name));
75 PEImageAnnotationsReader module_annotations_reader(
76 &process_reader, &pe_image_reader, module.name);
77 std::map<std::string, std::string> module_annotations_simple_map =
78 module_annotations_reader.SimpleMap();
79 all_annotations_simple_map.insert(module_annotations_simple_map.begin(),
80 module_annotations_simple_map.end());
81 }
82
83 EXPECT_GE(all_annotations_simple_map.size(), 5u);
84 EXPECT_EQ("crash", all_annotations_simple_map["#TEST# pad"]);
85 EXPECT_EQ("value", all_annotations_simple_map["#TEST# key"]);
86 EXPECT_EQ("y", all_annotations_simple_map["#TEST# x"]);
87 EXPECT_EQ("shorter", all_annotations_simple_map["#TEST# longer"]);
88 EXPECT_EQ("", all_annotations_simple_map["#TEST# empty_value"]);
89
90 if (test_type_ == kCrashDebugBreak)
91 SetExpectedChildExitCode(STATUS_BREAKPOINT);
92
93 // Tell the child process to continue.
94 CheckedWriteFile(WritePipeHandle(), &c, sizeof(c));
95 }
96
97 void WinMultiprocessChild() override {
98 CrashpadInfo* crashpad_info = CrashpadInfo::GetCrashpadInfo();
99
100 // This is "leaked" to crashpad_info.
101 SimpleStringDictionary* simple_annotations = new SimpleStringDictionary();
102 simple_annotations->SetKeyValue("#TEST# pad", "break");
103 simple_annotations->SetKeyValue("#TEST# key", "value");
104 simple_annotations->SetKeyValue("#TEST# pad", "crash");
105 simple_annotations->SetKeyValue("#TEST# x", "y");
106 simple_annotations->SetKeyValue("#TEST# longer", "shorter");
107 simple_annotations->SetKeyValue("#TEST# empty_value", "");
108
109 crashpad_info->set_simple_annotations(simple_annotations);
110
111 // Tell the parent that the environment has been set up.
112 char c = '\0';
113 CheckedWriteFile(WritePipeHandle(), &c, sizeof(c));
114
115 // Wait for the parent to indicate that it's safe to continue/crash.
116 CheckedReadFile(ReadPipeHandle(), &c, sizeof(c));
117
118 switch (test_type_) {
119 case kDontCrash:
120 break;
121
122 case kCrashDebugBreak:
123 __debugbreak();
124 break;
125 }
126 }
127
128 TestType test_type_;
129
130 DISALLOW_COPY_AND_ASSIGN(TestPEImageAnnotationsReader);
131 };
132
133 TEST(PEImageAnnotationsReader, DontCrash) {
134 TestPEImageAnnotationsReader test_pe_image_annotations_reader(
135 TestPEImageAnnotationsReader::kDontCrash);
136 test_pe_image_annotations_reader.Run();
137 }
138
139 TEST(PEImageAnnotationsReader, CrashDebugBreak) {
140 TestPEImageAnnotationsReader test_pe_image_annotations_reader(
141 TestPEImageAnnotationsReader::kCrashDebugBreak);
142 test_pe_image_annotations_reader.Run();
143 }
144
145 } // namespace
146 } // namespace test
147 } // namespace crashpad
OLDNEW
« no previous file with comments | « snapshot/win/pe_image_annotations_reader.cc ('k') | test/test.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698