| 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 15 matching lines...) Expand all Loading... |
| 26 #include "minidump/minidump_context.h" | 26 #include "minidump/minidump_context.h" |
| 27 #include "minidump/minidump_context_writer.h" | 27 #include "minidump/minidump_context_writer.h" |
| 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 "util/file/string_file_writer.h" | 36 #include "util/file/string_file.h" |
| 37 | 37 |
| 38 namespace crashpad { | 38 namespace crashpad { |
| 39 namespace test { | 39 namespace test { |
| 40 namespace { | 40 namespace { |
| 41 | 41 |
| 42 // This returns the MINIDUMP_EXCEPTION_STREAM stream in |exception_stream|. | 42 // This returns the MINIDUMP_EXCEPTION_STREAM stream in |exception_stream|. |
| 43 void GetExceptionStream(const std::string& file_contents, | 43 void GetExceptionStream(const std::string& file_contents, |
| 44 const MINIDUMP_EXCEPTION_STREAM** exception_stream) { | 44 const MINIDUMP_EXCEPTION_STREAM** exception_stream) { |
| 45 const size_t kDirectoryOffset = sizeof(MINIDUMP_HEADER); | 45 const size_t kDirectoryOffset = sizeof(MINIDUMP_HEADER); |
| 46 const size_t kExceptionStreamOffset = | 46 const size_t kExceptionStreamOffset = |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 auto exception_writer = make_scoped_ptr(new MinidumpExceptionWriter()); | 100 auto exception_writer = make_scoped_ptr(new MinidumpExceptionWriter()); |
| 101 | 101 |
| 102 const uint32_t kSeed = 100; | 102 const uint32_t kSeed = 100; |
| 103 | 103 |
| 104 auto context_x86_writer = make_scoped_ptr(new MinidumpContextX86Writer()); | 104 auto context_x86_writer = make_scoped_ptr(new MinidumpContextX86Writer()); |
| 105 InitializeMinidumpContextX86(context_x86_writer->context(), kSeed); | 105 InitializeMinidumpContextX86(context_x86_writer->context(), kSeed); |
| 106 exception_writer->SetContext(context_x86_writer.Pass()); | 106 exception_writer->SetContext(context_x86_writer.Pass()); |
| 107 | 107 |
| 108 minidump_file_writer.AddStream(exception_writer.Pass()); | 108 minidump_file_writer.AddStream(exception_writer.Pass()); |
| 109 | 109 |
| 110 StringFileWriter file_writer; | 110 StringFile string_file; |
| 111 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); | 111 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); |
| 112 | 112 |
| 113 const MINIDUMP_EXCEPTION_STREAM* observed_exception_stream = nullptr; | 113 const MINIDUMP_EXCEPTION_STREAM* observed_exception_stream = nullptr; |
| 114 ASSERT_NO_FATAL_FAILURE( | 114 ASSERT_NO_FATAL_FAILURE( |
| 115 GetExceptionStream(file_writer.string(), &observed_exception_stream)); | 115 GetExceptionStream(string_file.string(), &observed_exception_stream)); |
| 116 | 116 |
| 117 MINIDUMP_EXCEPTION_STREAM expected_exception_stream = {}; | 117 MINIDUMP_EXCEPTION_STREAM expected_exception_stream = {}; |
| 118 expected_exception_stream.ThreadContext.DataSize = sizeof(MinidumpContextX86); | 118 expected_exception_stream.ThreadContext.DataSize = sizeof(MinidumpContextX86); |
| 119 | 119 |
| 120 const MinidumpContextX86* observed_context = nullptr; | 120 const MinidumpContextX86* observed_context = nullptr; |
| 121 ASSERT_NO_FATAL_FAILURE(ExpectExceptionStream(&expected_exception_stream, | 121 ASSERT_NO_FATAL_FAILURE(ExpectExceptionStream(&expected_exception_stream, |
| 122 observed_exception_stream, | 122 observed_exception_stream, |
| 123 file_writer.string(), | 123 string_file.string(), |
| 124 &observed_context)); | 124 &observed_context)); |
| 125 | 125 |
| 126 ASSERT_NO_FATAL_FAILURE( | 126 ASSERT_NO_FATAL_FAILURE( |
| 127 ExpectMinidumpContextX86(kSeed, observed_context, false)); | 127 ExpectMinidumpContextX86(kSeed, observed_context, false)); |
| 128 } | 128 } |
| 129 | 129 |
| 130 TEST(MinidumpExceptionWriter, Standard) { | 130 TEST(MinidumpExceptionWriter, Standard) { |
| 131 MinidumpFileWriter minidump_file_writer; | 131 MinidumpFileWriter minidump_file_writer; |
| 132 auto exception_writer = make_scoped_ptr(new MinidumpExceptionWriter()); | 132 auto exception_writer = make_scoped_ptr(new MinidumpExceptionWriter()); |
| 133 | 133 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 159 exception_writer->SetExceptionInformation(exception_information); | 159 exception_writer->SetExceptionInformation(exception_information); |
| 160 | 160 |
| 161 exception_information.clear(); | 161 exception_information.clear(); |
| 162 exception_information.push_back(kExceptionInformation0); | 162 exception_information.push_back(kExceptionInformation0); |
| 163 exception_information.push_back(kExceptionInformation1); | 163 exception_information.push_back(kExceptionInformation1); |
| 164 exception_information.push_back(kExceptionInformation2); | 164 exception_information.push_back(kExceptionInformation2); |
| 165 exception_writer->SetExceptionInformation(exception_information); | 165 exception_writer->SetExceptionInformation(exception_information); |
| 166 | 166 |
| 167 minidump_file_writer.AddStream(exception_writer.Pass()); | 167 minidump_file_writer.AddStream(exception_writer.Pass()); |
| 168 | 168 |
| 169 StringFileWriter file_writer; | 169 StringFile string_file; |
| 170 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); | 170 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); |
| 171 | 171 |
| 172 const MINIDUMP_EXCEPTION_STREAM* observed_exception_stream = nullptr; | 172 const MINIDUMP_EXCEPTION_STREAM* observed_exception_stream = nullptr; |
| 173 ASSERT_NO_FATAL_FAILURE( | 173 ASSERT_NO_FATAL_FAILURE( |
| 174 GetExceptionStream(file_writer.string(), &observed_exception_stream)); | 174 GetExceptionStream(string_file.string(), &observed_exception_stream)); |
| 175 | 175 |
| 176 MINIDUMP_EXCEPTION_STREAM expected_exception_stream = {}; | 176 MINIDUMP_EXCEPTION_STREAM expected_exception_stream = {}; |
| 177 expected_exception_stream.ThreadId = kThreadID; | 177 expected_exception_stream.ThreadId = kThreadID; |
| 178 expected_exception_stream.ExceptionRecord.ExceptionCode = kExceptionCode; | 178 expected_exception_stream.ExceptionRecord.ExceptionCode = kExceptionCode; |
| 179 expected_exception_stream.ExceptionRecord.ExceptionFlags = kExceptionFlags; | 179 expected_exception_stream.ExceptionRecord.ExceptionFlags = kExceptionFlags; |
| 180 expected_exception_stream.ExceptionRecord.ExceptionRecord = kExceptionRecord; | 180 expected_exception_stream.ExceptionRecord.ExceptionRecord = kExceptionRecord; |
| 181 expected_exception_stream.ExceptionRecord.ExceptionAddress = | 181 expected_exception_stream.ExceptionRecord.ExceptionAddress = |
| 182 kExceptionAddress; | 182 kExceptionAddress; |
| 183 expected_exception_stream.ExceptionRecord.NumberParameters = | 183 expected_exception_stream.ExceptionRecord.NumberParameters = |
| 184 exception_information.size(); | 184 exception_information.size(); |
| 185 for (size_t index = 0; index < exception_information.size(); ++index) { | 185 for (size_t index = 0; index < exception_information.size(); ++index) { |
| 186 expected_exception_stream.ExceptionRecord.ExceptionInformation[index] = | 186 expected_exception_stream.ExceptionRecord.ExceptionInformation[index] = |
| 187 exception_information[index]; | 187 exception_information[index]; |
| 188 } | 188 } |
| 189 expected_exception_stream.ThreadContext.DataSize = sizeof(MinidumpContextX86); | 189 expected_exception_stream.ThreadContext.DataSize = sizeof(MinidumpContextX86); |
| 190 | 190 |
| 191 const MinidumpContextX86* observed_context = nullptr; | 191 const MinidumpContextX86* observed_context = nullptr; |
| 192 ASSERT_NO_FATAL_FAILURE(ExpectExceptionStream(&expected_exception_stream, | 192 ASSERT_NO_FATAL_FAILURE(ExpectExceptionStream(&expected_exception_stream, |
| 193 observed_exception_stream, | 193 observed_exception_stream, |
| 194 file_writer.string(), | 194 string_file.string(), |
| 195 &observed_context)); | 195 &observed_context)); |
| 196 | 196 |
| 197 ASSERT_NO_FATAL_FAILURE( | 197 ASSERT_NO_FATAL_FAILURE( |
| 198 ExpectMinidumpContextX86(kSeed, observed_context, false)); | 198 ExpectMinidumpContextX86(kSeed, observed_context, false)); |
| 199 } | 199 } |
| 200 | 200 |
| 201 TEST(MinidumpExceptionWriter, InitializeFromSnapshot) { | 201 TEST(MinidumpExceptionWriter, InitializeFromSnapshot) { |
| 202 std::vector<uint64_t> exception_codes; | 202 std::vector<uint64_t> exception_codes; |
| 203 exception_codes.push_back(0x1000000000000000); | 203 exception_codes.push_back(0x1000000000000000); |
| 204 exception_codes.push_back(0x5555555555555555); | 204 exception_codes.push_back(0x5555555555555555); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 231 | 231 |
| 232 MinidumpThreadIDMap thread_id_map; | 232 MinidumpThreadIDMap thread_id_map; |
| 233 thread_id_map[kThreadID] = expect_exception.ThreadId; | 233 thread_id_map[kThreadID] = expect_exception.ThreadId; |
| 234 | 234 |
| 235 auto exception_writer = make_scoped_ptr(new MinidumpExceptionWriter()); | 235 auto exception_writer = make_scoped_ptr(new MinidumpExceptionWriter()); |
| 236 exception_writer->InitializeFromSnapshot(&exception_snapshot, thread_id_map); | 236 exception_writer->InitializeFromSnapshot(&exception_snapshot, thread_id_map); |
| 237 | 237 |
| 238 MinidumpFileWriter minidump_file_writer; | 238 MinidumpFileWriter minidump_file_writer; |
| 239 minidump_file_writer.AddStream(exception_writer.Pass()); | 239 minidump_file_writer.AddStream(exception_writer.Pass()); |
| 240 | 240 |
| 241 StringFileWriter file_writer; | 241 StringFile string_file; |
| 242 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); | 242 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); |
| 243 | 243 |
| 244 const MINIDUMP_EXCEPTION_STREAM* exception = nullptr; | 244 const MINIDUMP_EXCEPTION_STREAM* exception = nullptr; |
| 245 ASSERT_NO_FATAL_FAILURE(GetExceptionStream(file_writer.string(), &exception)); | 245 ASSERT_NO_FATAL_FAILURE(GetExceptionStream(string_file.string(), &exception)); |
| 246 | 246 |
| 247 const MinidumpContextX86* observed_context = nullptr; | 247 const MinidumpContextX86* observed_context = nullptr; |
| 248 ASSERT_NO_FATAL_FAILURE(ExpectExceptionStream(&expect_exception, | 248 ASSERT_NO_FATAL_FAILURE(ExpectExceptionStream(&expect_exception, |
| 249 exception, | 249 exception, |
| 250 file_writer.string(), | 250 string_file.string(), |
| 251 &observed_context)); | 251 &observed_context)); |
| 252 | 252 |
| 253 ASSERT_NO_FATAL_FAILURE( | 253 ASSERT_NO_FATAL_FAILURE( |
| 254 ExpectMinidumpContextX86(kSeed, observed_context, true)); | 254 ExpectMinidumpContextX86(kSeed, observed_context, true)); |
| 255 } | 255 } |
| 256 | 256 |
| 257 TEST(MinidumpExceptionWriterDeathTest, NoContext) { | 257 TEST(MinidumpExceptionWriterDeathTest, NoContext) { |
| 258 MinidumpFileWriter minidump_file_writer; | 258 MinidumpFileWriter minidump_file_writer; |
| 259 auto exception_writer = make_scoped_ptr(new MinidumpExceptionWriter()); | 259 auto exception_writer = make_scoped_ptr(new MinidumpExceptionWriter()); |
| 260 | 260 |
| 261 minidump_file_writer.AddStream(exception_writer.Pass()); | 261 minidump_file_writer.AddStream(exception_writer.Pass()); |
| 262 | 262 |
| 263 StringFileWriter file_writer; | 263 StringFile string_file; |
| 264 ASSERT_DEATH(minidump_file_writer.WriteEverything(&file_writer), "context_"); | 264 ASSERT_DEATH(minidump_file_writer.WriteEverything(&string_file), "context_"); |
| 265 } | 265 } |
| 266 | 266 |
| 267 TEST(MinidumpExceptionWriterDeathTest, TooMuchInformation) { | 267 TEST(MinidumpExceptionWriterDeathTest, TooMuchInformation) { |
| 268 MinidumpExceptionWriter exception_writer; | 268 MinidumpExceptionWriter exception_writer; |
| 269 std::vector<uint64_t> exception_information(EXCEPTION_MAXIMUM_PARAMETERS + 1, | 269 std::vector<uint64_t> exception_information(EXCEPTION_MAXIMUM_PARAMETERS + 1, |
| 270 0x5a5a5a5a5a5a5a5a); | 270 0x5a5a5a5a5a5a5a5a); |
| 271 ASSERT_DEATH(exception_writer.SetExceptionInformation(exception_information), | 271 ASSERT_DEATH(exception_writer.SetExceptionInformation(exception_information), |
| 272 "kMaxParameters"); | 272 "kMaxParameters"); |
| 273 } | 273 } |
| 274 | 274 |
| 275 } // namespace | 275 } // namespace |
| 276 } // namespace test | 276 } // namespace test |
| 277 } // namespace crashpad | 277 } // namespace crashpad |
| OLD | NEW |