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

Side by Side Diff: minidump/minidump_exception_writer_test.cc

Issue 698673002: Add MinidumpExceptionWriter::InitializeFromSnapshot() and test (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@minidump_init_from_snapshot_thread_new
Patch Set: Rebase Created 6 years, 1 month 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 | « minidump/minidump_exception_writer.cc ('k') | snapshot/snapshot.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and 12 // See the License for the specific language governing permissions and
13 // limitations under the License. 13 // limitations under the License.
14 14
15 #include "minidump/minidump_exception_writer.h" 15 #include "minidump/minidump_exception_writer.h"
16 16
17 #include <dbghelp.h> 17 #include <dbghelp.h>
18 #include <stdint.h> 18 #include <stdint.h>
19 #include <sys/types.h> 19 #include <sys/types.h>
20 20
21 #include <string> 21 #include <string>
22 #include <vector> 22 #include <vector>
23 23
24 #include "gtest/gtest.h" 24 #include "gtest/gtest.h"
25 #include "minidump/minidump_context.h" 25 #include "minidump/minidump_context.h"
26 #include "minidump/minidump_context_writer.h" 26 #include "minidump/minidump_context_writer.h"
27 #include "minidump/minidump_extensions.h" 27 #include "minidump/minidump_extensions.h"
28 #include "minidump/minidump_file_writer.h" 28 #include "minidump/minidump_file_writer.h"
29 #include "minidump/minidump_thread_id_map.h"
29 #include "minidump/test/minidump_context_test_util.h" 30 #include "minidump/test/minidump_context_test_util.h"
30 #include "minidump/test/minidump_file_writer_test_util.h" 31 #include "minidump/test/minidump_file_writer_test_util.h"
31 #include "minidump/test/minidump_writable_test_util.h" 32 #include "minidump/test/minidump_writable_test_util.h"
33 #include "snapshot/test/test_cpu_context.h"
34 #include "snapshot/test/test_exception_snapshot.h"
32 #include "util/file/string_file_writer.h" 35 #include "util/file/string_file_writer.h"
33 36
34 namespace crashpad { 37 namespace crashpad {
35 namespace test { 38 namespace test {
36 namespace { 39 namespace {
37 40
38 // This returns the MINIDUMP_EXCEPTION_STREAM stream in |exception_stream|. 41 // This returns the MINIDUMP_EXCEPTION_STREAM stream in |exception_stream|.
39 void GetExceptionStream(const std::string& file_contents, 42 void GetExceptionStream(const std::string& file_contents,
40 const MINIDUMP_EXCEPTION_STREAM** exception_stream) { 43 const MINIDUMP_EXCEPTION_STREAM** exception_stream) {
41 const size_t kDirectoryOffset = sizeof(MINIDUMP_HEADER); 44 const size_t kDirectoryOffset = sizeof(MINIDUMP_HEADER);
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 const MinidumpContextX86* observed_context; 190 const MinidumpContextX86* observed_context;
188 ASSERT_NO_FATAL_FAILURE(ExpectExceptionStream(&expected_exception_stream, 191 ASSERT_NO_FATAL_FAILURE(ExpectExceptionStream(&expected_exception_stream,
189 observed_exception_stream, 192 observed_exception_stream,
190 file_writer.string(), 193 file_writer.string(),
191 &observed_context)); 194 &observed_context));
192 195
193 ASSERT_NO_FATAL_FAILURE( 196 ASSERT_NO_FATAL_FAILURE(
194 ExpectMinidumpContextX86(kSeed, observed_context, false)); 197 ExpectMinidumpContextX86(kSeed, observed_context, false));
195 } 198 }
196 199
200 TEST(MinidumpExceptionWriter, InitializeFromSnapshot) {
201 std::vector<uint64_t> exception_codes;
202 exception_codes.push_back(0x1000000000000000);
203 exception_codes.push_back(0x5555555555555555);
204
205 MINIDUMP_EXCEPTION_STREAM expect_exception = {};
206
207 expect_exception.ThreadId = 123;
208 expect_exception.ExceptionRecord.ExceptionCode = 100;
209 expect_exception.ExceptionRecord.ExceptionFlags = 1;
210 expect_exception.ExceptionRecord.ExceptionAddress = 0xfedcba9876543210;
211 expect_exception.ExceptionRecord.NumberParameters = exception_codes.size();
212 for (size_t index = 0; index < exception_codes.size(); ++index) {
213 expect_exception.ExceptionRecord.ExceptionInformation[index] =
214 exception_codes[index];
215 }
216 const uint64_t kThreadID = 0xaaaaaaaaaaaaaaaa;
217 const uint32_t kSeed = 65;
218
219 TestExceptionSnapshot exception_snapshot;
220 exception_snapshot.SetThreadID(kThreadID);
221 exception_snapshot.SetException(
222 expect_exception.ExceptionRecord.ExceptionCode);
223 exception_snapshot.SetExceptionInfo(
224 expect_exception.ExceptionRecord.ExceptionFlags);
225 exception_snapshot.SetExceptionAddress(
226 expect_exception.ExceptionRecord.ExceptionAddress);
227 exception_snapshot.SetCodes(exception_codes);
228
229 InitializeCPUContextX86(exception_snapshot.MutableContext(), kSeed);
230
231 MinidumpThreadIDMap thread_id_map;
232 thread_id_map[kThreadID] = expect_exception.ThreadId;
233
234 auto exception_writer = make_scoped_ptr(new MinidumpExceptionWriter());
235 exception_writer->InitializeFromSnapshot(&exception_snapshot, &thread_id_map);
236
237 MinidumpFileWriter minidump_file_writer;
238 minidump_file_writer.AddStream(exception_writer.Pass());
239
240 StringFileWriter file_writer;
241 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
242
243 const MINIDUMP_EXCEPTION_STREAM* exception;
244 ASSERT_NO_FATAL_FAILURE(GetExceptionStream(file_writer.string(), &exception));
245
246 const MinidumpContextX86* observed_context;
247 ASSERT_NO_FATAL_FAILURE(ExpectExceptionStream(&expect_exception,
248 exception,
249 file_writer.string(),
250 &observed_context));
251
252 ASSERT_NO_FATAL_FAILURE(
253 ExpectMinidumpContextX86(kSeed, observed_context, true));
254 }
255
197 TEST(MinidumpExceptionWriterDeathTest, NoContext) { 256 TEST(MinidumpExceptionWriterDeathTest, NoContext) {
198 MinidumpFileWriter minidump_file_writer; 257 MinidumpFileWriter minidump_file_writer;
199 auto exception_writer = make_scoped_ptr(new MinidumpExceptionWriter()); 258 auto exception_writer = make_scoped_ptr(new MinidumpExceptionWriter());
200 259
201 minidump_file_writer.AddStream(exception_writer.Pass()); 260 minidump_file_writer.AddStream(exception_writer.Pass());
202 261
203 StringFileWriter file_writer; 262 StringFileWriter file_writer;
204 ASSERT_DEATH(minidump_file_writer.WriteEverything(&file_writer), "context_"); 263 ASSERT_DEATH(minidump_file_writer.WriteEverything(&file_writer), "context_");
205 } 264 }
206 265
207 TEST(MinidumpExceptionWriterDeathTest, TooMuchInformation) { 266 TEST(MinidumpExceptionWriterDeathTest, TooMuchInformation) {
208 MinidumpExceptionWriter exception_writer; 267 MinidumpExceptionWriter exception_writer;
209 std::vector<uint64_t> exception_information(EXCEPTION_MAXIMUM_PARAMETERS + 1, 268 std::vector<uint64_t> exception_information(EXCEPTION_MAXIMUM_PARAMETERS + 1,
210 0x5a5a5a5a5a5a5a5a); 269 0x5a5a5a5a5a5a5a5a);
211 ASSERT_DEATH(exception_writer.SetExceptionInformation(exception_information), 270 ASSERT_DEATH(exception_writer.SetExceptionInformation(exception_information),
212 "kMaxParameters"); 271 "kMaxParameters");
213 } 272 }
214 273
215 } // namespace 274 } // namespace
216 } // namespace test 275 } // namespace test
217 } // namespace crashpad 276 } // namespace crashpad
OLDNEW
« no previous file with comments | « minidump/minidump_exception_writer.cc ('k') | snapshot/snapshot.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698