OLD | NEW |
1 // Copyright 2014 The Crashpad Authors. All rights reserved. | 1 // Copyright 2014 The Crashpad Authors. All rights reserved. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with 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 | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
(...skipping 17 matching lines...) Expand all Loading... |
28 #include "minidump/minidump_extensions.h" | 28 #include "minidump/minidump_extensions.h" |
29 #include "minidump/minidump_file_writer.h" | 29 #include "minidump/minidump_file_writer.h" |
30 #include "minidump/minidump_thread_id_map.h" | 30 #include "minidump/minidump_thread_id_map.h" |
31 #include "minidump/test/minidump_context_test_util.h" | 31 #include "minidump/test/minidump_context_test_util.h" |
32 #include "minidump/test/minidump_file_writer_test_util.h" | 32 #include "minidump/test/minidump_file_writer_test_util.h" |
33 #include "minidump/test/minidump_writable_test_util.h" | 33 #include "minidump/test/minidump_writable_test_util.h" |
34 #include "snapshot/test/test_cpu_context.h" | 34 #include "snapshot/test/test_cpu_context.h" |
35 #include "snapshot/test/test_exception_snapshot.h" | 35 #include "snapshot/test/test_exception_snapshot.h" |
36 #include "test/gtest_death_check.h" | 36 #include "test/gtest_death_check.h" |
37 #include "util/file/string_file.h" | 37 #include "util/file/string_file.h" |
| 38 #include "util/stdlib/move.h" |
38 | 39 |
39 namespace crashpad { | 40 namespace crashpad { |
40 namespace test { | 41 namespace test { |
41 namespace { | 42 namespace { |
42 | 43 |
43 // This returns the MINIDUMP_EXCEPTION_STREAM stream in |exception_stream|. | 44 // This returns the MINIDUMP_EXCEPTION_STREAM stream in |exception_stream|. |
44 void GetExceptionStream(const std::string& file_contents, | 45 void GetExceptionStream(const std::string& file_contents, |
45 const MINIDUMP_EXCEPTION_STREAM** exception_stream) { | 46 const MINIDUMP_EXCEPTION_STREAM** exception_stream) { |
46 const size_t kDirectoryOffset = sizeof(MINIDUMP_HEADER); | 47 const size_t kDirectoryOffset = sizeof(MINIDUMP_HEADER); |
47 const size_t kExceptionStreamOffset = | 48 const size_t kExceptionStreamOffset = |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 } | 98 } |
98 | 99 |
99 TEST(MinidumpExceptionWriter, Minimal) { | 100 TEST(MinidumpExceptionWriter, Minimal) { |
100 MinidumpFileWriter minidump_file_writer; | 101 MinidumpFileWriter minidump_file_writer; |
101 auto exception_writer = make_scoped_ptr(new MinidumpExceptionWriter()); | 102 auto exception_writer = make_scoped_ptr(new MinidumpExceptionWriter()); |
102 | 103 |
103 const uint32_t kSeed = 100; | 104 const uint32_t kSeed = 100; |
104 | 105 |
105 auto context_x86_writer = make_scoped_ptr(new MinidumpContextX86Writer()); | 106 auto context_x86_writer = make_scoped_ptr(new MinidumpContextX86Writer()); |
106 InitializeMinidumpContextX86(context_x86_writer->context(), kSeed); | 107 InitializeMinidumpContextX86(context_x86_writer->context(), kSeed); |
107 exception_writer->SetContext(context_x86_writer.Pass()); | 108 exception_writer->SetContext(crashpad::move(context_x86_writer)); |
108 | 109 |
109 minidump_file_writer.AddStream(exception_writer.Pass()); | 110 minidump_file_writer.AddStream(crashpad::move(exception_writer)); |
110 | 111 |
111 StringFile string_file; | 112 StringFile string_file; |
112 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); | 113 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); |
113 | 114 |
114 const MINIDUMP_EXCEPTION_STREAM* observed_exception_stream = nullptr; | 115 const MINIDUMP_EXCEPTION_STREAM* observed_exception_stream = nullptr; |
115 ASSERT_NO_FATAL_FAILURE( | 116 ASSERT_NO_FATAL_FAILURE( |
116 GetExceptionStream(string_file.string(), &observed_exception_stream)); | 117 GetExceptionStream(string_file.string(), &observed_exception_stream)); |
117 | 118 |
118 MINIDUMP_EXCEPTION_STREAM expected_exception_stream = {}; | 119 MINIDUMP_EXCEPTION_STREAM expected_exception_stream = {}; |
119 expected_exception_stream.ThreadContext.DataSize = sizeof(MinidumpContextX86); | 120 expected_exception_stream.ThreadContext.DataSize = sizeof(MinidumpContextX86); |
(...skipping 17 matching lines...) Expand all Loading... |
137 const uint32_t kExceptionCode = 2; | 138 const uint32_t kExceptionCode = 2; |
138 const uint32_t kExceptionFlags = 3; | 139 const uint32_t kExceptionFlags = 3; |
139 const uint32_t kExceptionRecord = 4; | 140 const uint32_t kExceptionRecord = 4; |
140 const uint32_t kExceptionAddress = 5; | 141 const uint32_t kExceptionAddress = 5; |
141 const uint64_t kExceptionInformation0 = 6; | 142 const uint64_t kExceptionInformation0 = 6; |
142 const uint64_t kExceptionInformation1 = 7; | 143 const uint64_t kExceptionInformation1 = 7; |
143 const uint64_t kExceptionInformation2 = 7; | 144 const uint64_t kExceptionInformation2 = 7; |
144 | 145 |
145 auto context_x86_writer = make_scoped_ptr(new MinidumpContextX86Writer()); | 146 auto context_x86_writer = make_scoped_ptr(new MinidumpContextX86Writer()); |
146 InitializeMinidumpContextX86(context_x86_writer->context(), kSeed); | 147 InitializeMinidumpContextX86(context_x86_writer->context(), kSeed); |
147 exception_writer->SetContext(context_x86_writer.Pass()); | 148 exception_writer->SetContext(crashpad::move(context_x86_writer)); |
148 | 149 |
149 exception_writer->SetThreadID(kThreadID); | 150 exception_writer->SetThreadID(kThreadID); |
150 exception_writer->SetExceptionCode(kExceptionCode); | 151 exception_writer->SetExceptionCode(kExceptionCode); |
151 exception_writer->SetExceptionFlags(kExceptionFlags); | 152 exception_writer->SetExceptionFlags(kExceptionFlags); |
152 exception_writer->SetExceptionRecord(kExceptionRecord); | 153 exception_writer->SetExceptionRecord(kExceptionRecord); |
153 exception_writer->SetExceptionAddress(kExceptionAddress); | 154 exception_writer->SetExceptionAddress(kExceptionAddress); |
154 | 155 |
155 // Set a lot of exception information at first, and then replace it with less. | 156 // Set a lot of exception information at first, and then replace it with less. |
156 // This tests that the exception that is written does not contain the | 157 // This tests that the exception that is written does not contain the |
157 // “garbage” from the initial SetExceptionInformation() call. | 158 // “garbage” from the initial SetExceptionInformation() call. |
158 std::vector<uint64_t> exception_information(EXCEPTION_MAXIMUM_PARAMETERS, | 159 std::vector<uint64_t> exception_information(EXCEPTION_MAXIMUM_PARAMETERS, |
159 0x5a5a5a5a5a5a5a5a); | 160 0x5a5a5a5a5a5a5a5a); |
160 exception_writer->SetExceptionInformation(exception_information); | 161 exception_writer->SetExceptionInformation(exception_information); |
161 | 162 |
162 exception_information.clear(); | 163 exception_information.clear(); |
163 exception_information.push_back(kExceptionInformation0); | 164 exception_information.push_back(kExceptionInformation0); |
164 exception_information.push_back(kExceptionInformation1); | 165 exception_information.push_back(kExceptionInformation1); |
165 exception_information.push_back(kExceptionInformation2); | 166 exception_information.push_back(kExceptionInformation2); |
166 exception_writer->SetExceptionInformation(exception_information); | 167 exception_writer->SetExceptionInformation(exception_information); |
167 | 168 |
168 minidump_file_writer.AddStream(exception_writer.Pass()); | 169 minidump_file_writer.AddStream(crashpad::move(exception_writer)); |
169 | 170 |
170 StringFile string_file; | 171 StringFile string_file; |
171 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); | 172 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); |
172 | 173 |
173 const MINIDUMP_EXCEPTION_STREAM* observed_exception_stream = nullptr; | 174 const MINIDUMP_EXCEPTION_STREAM* observed_exception_stream = nullptr; |
174 ASSERT_NO_FATAL_FAILURE( | 175 ASSERT_NO_FATAL_FAILURE( |
175 GetExceptionStream(string_file.string(), &observed_exception_stream)); | 176 GetExceptionStream(string_file.string(), &observed_exception_stream)); |
176 | 177 |
177 MINIDUMP_EXCEPTION_STREAM expected_exception_stream = {}; | 178 MINIDUMP_EXCEPTION_STREAM expected_exception_stream = {}; |
178 expected_exception_stream.ThreadId = kThreadID; | 179 expected_exception_stream.ThreadId = kThreadID; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 | 232 |
232 InitializeCPUContextX86(exception_snapshot.MutableContext(), kSeed); | 233 InitializeCPUContextX86(exception_snapshot.MutableContext(), kSeed); |
233 | 234 |
234 MinidumpThreadIDMap thread_id_map; | 235 MinidumpThreadIDMap thread_id_map; |
235 thread_id_map[kThreadID] = expect_exception.ThreadId; | 236 thread_id_map[kThreadID] = expect_exception.ThreadId; |
236 | 237 |
237 auto exception_writer = make_scoped_ptr(new MinidumpExceptionWriter()); | 238 auto exception_writer = make_scoped_ptr(new MinidumpExceptionWriter()); |
238 exception_writer->InitializeFromSnapshot(&exception_snapshot, thread_id_map); | 239 exception_writer->InitializeFromSnapshot(&exception_snapshot, thread_id_map); |
239 | 240 |
240 MinidumpFileWriter minidump_file_writer; | 241 MinidumpFileWriter minidump_file_writer; |
241 minidump_file_writer.AddStream(exception_writer.Pass()); | 242 minidump_file_writer.AddStream(crashpad::move(exception_writer)); |
242 | 243 |
243 StringFile string_file; | 244 StringFile string_file; |
244 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); | 245 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); |
245 | 246 |
246 const MINIDUMP_EXCEPTION_STREAM* exception = nullptr; | 247 const MINIDUMP_EXCEPTION_STREAM* exception = nullptr; |
247 ASSERT_NO_FATAL_FAILURE(GetExceptionStream(string_file.string(), &exception)); | 248 ASSERT_NO_FATAL_FAILURE(GetExceptionStream(string_file.string(), &exception)); |
248 | 249 |
249 const MinidumpContextX86* observed_context = nullptr; | 250 const MinidumpContextX86* observed_context = nullptr; |
250 ASSERT_NO_FATAL_FAILURE(ExpectExceptionStream(&expect_exception, | 251 ASSERT_NO_FATAL_FAILURE(ExpectExceptionStream(&expect_exception, |
251 exception, | 252 exception, |
252 string_file.string(), | 253 string_file.string(), |
253 &observed_context)); | 254 &observed_context)); |
254 | 255 |
255 ASSERT_NO_FATAL_FAILURE( | 256 ASSERT_NO_FATAL_FAILURE( |
256 ExpectMinidumpContextX86(kSeed, observed_context, true)); | 257 ExpectMinidumpContextX86(kSeed, observed_context, true)); |
257 } | 258 } |
258 | 259 |
259 TEST(MinidumpExceptionWriterDeathTest, NoContext) { | 260 TEST(MinidumpExceptionWriterDeathTest, NoContext) { |
260 MinidumpFileWriter minidump_file_writer; | 261 MinidumpFileWriter minidump_file_writer; |
261 auto exception_writer = make_scoped_ptr(new MinidumpExceptionWriter()); | 262 auto exception_writer = make_scoped_ptr(new MinidumpExceptionWriter()); |
262 | 263 |
263 minidump_file_writer.AddStream(exception_writer.Pass()); | 264 minidump_file_writer.AddStream(crashpad::move(exception_writer)); |
264 | 265 |
265 StringFile string_file; | 266 StringFile string_file; |
266 ASSERT_DEATH_CHECK(minidump_file_writer.WriteEverything(&string_file), | 267 ASSERT_DEATH_CHECK(minidump_file_writer.WriteEverything(&string_file), |
267 "context_"); | 268 "context_"); |
268 } | 269 } |
269 | 270 |
270 TEST(MinidumpExceptionWriterDeathTest, TooMuchInformation) { | 271 TEST(MinidumpExceptionWriterDeathTest, TooMuchInformation) { |
271 MinidumpExceptionWriter exception_writer; | 272 MinidumpExceptionWriter exception_writer; |
272 std::vector<uint64_t> exception_information(EXCEPTION_MAXIMUM_PARAMETERS + 1, | 273 std::vector<uint64_t> exception_information(EXCEPTION_MAXIMUM_PARAMETERS + 1, |
273 0x5a5a5a5a5a5a5a5a); | 274 0x5a5a5a5a5a5a5a5a); |
274 ASSERT_DEATH_CHECK( | 275 ASSERT_DEATH_CHECK( |
275 exception_writer.SetExceptionInformation(exception_information), | 276 exception_writer.SetExceptionInformation(exception_information), |
276 "kMaxParameters"); | 277 "kMaxParameters"); |
277 } | 278 } |
278 | 279 |
279 } // namespace | 280 } // namespace |
280 } // namespace test | 281 } // namespace test |
281 } // namespace crashpad | 282 } // namespace crashpad |
OLD | NEW |