| 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 EXPECT_EQ(expected->ExceptionRecord.ExceptionInformation[index], | 86 EXPECT_EQ(expected->ExceptionRecord.ExceptionInformation[index], |
| 87 observed->ExceptionRecord.ExceptionInformation[index]); | 87 observed->ExceptionRecord.ExceptionInformation[index]); |
| 88 } | 88 } |
| 89 *context = MinidumpWritableAtLocationDescriptor<MinidumpContextX86>( | 89 *context = MinidumpWritableAtLocationDescriptor<MinidumpContextX86>( |
| 90 file_contents, observed->ThreadContext); | 90 file_contents, observed->ThreadContext); |
| 91 ASSERT_TRUE(context); | 91 ASSERT_TRUE(context); |
| 92 } | 92 } |
| 93 | 93 |
| 94 TEST(MinidumpExceptionWriter, Minimal) { | 94 TEST(MinidumpExceptionWriter, Minimal) { |
| 95 MinidumpFileWriter minidump_file_writer; | 95 MinidumpFileWriter minidump_file_writer; |
| 96 MinidumpExceptionWriter exception_writer; | 96 auto exception_writer = make_scoped_ptr(new MinidumpExceptionWriter()); |
| 97 | 97 |
| 98 const uint32_t kSeed = 100; | 98 const uint32_t kSeed = 100; |
| 99 | 99 |
| 100 MinidumpContextX86Writer context_x86_writer; | 100 auto context_x86_writer = make_scoped_ptr(new MinidumpContextX86Writer()); |
| 101 InitializeMinidumpContextX86(context_x86_writer.context(), kSeed); | 101 InitializeMinidumpContextX86(context_x86_writer->context(), kSeed); |
| 102 exception_writer.SetContext(&context_x86_writer); | 102 exception_writer->SetContext(context_x86_writer.Pass()); |
| 103 | 103 |
| 104 minidump_file_writer.AddStream(&exception_writer); | 104 minidump_file_writer.AddStream(exception_writer.Pass()); |
| 105 | 105 |
| 106 StringFileWriter file_writer; | 106 StringFileWriter file_writer; |
| 107 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); | 107 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); |
| 108 | 108 |
| 109 const MINIDUMP_EXCEPTION_STREAM* observed_exception_stream; | 109 const MINIDUMP_EXCEPTION_STREAM* observed_exception_stream; |
| 110 ASSERT_NO_FATAL_FAILURE( | 110 ASSERT_NO_FATAL_FAILURE( |
| 111 GetExceptionStream(file_writer.string(), &observed_exception_stream)); | 111 GetExceptionStream(file_writer.string(), &observed_exception_stream)); |
| 112 | 112 |
| 113 MINIDUMP_EXCEPTION_STREAM expected_exception_stream = {}; | 113 MINIDUMP_EXCEPTION_STREAM expected_exception_stream = {}; |
| 114 expected_exception_stream.ThreadContext.DataSize = sizeof(MinidumpContextX86); | 114 expected_exception_stream.ThreadContext.DataSize = sizeof(MinidumpContextX86); |
| 115 | 115 |
| 116 const MinidumpContextX86* observed_context; | 116 const MinidumpContextX86* observed_context; |
| 117 ASSERT_NO_FATAL_FAILURE(ExpectExceptionStream(&expected_exception_stream, | 117 ASSERT_NO_FATAL_FAILURE(ExpectExceptionStream(&expected_exception_stream, |
| 118 observed_exception_stream, | 118 observed_exception_stream, |
| 119 file_writer.string(), | 119 file_writer.string(), |
| 120 &observed_context)); | 120 &observed_context)); |
| 121 | 121 |
| 122 ASSERT_NO_FATAL_FAILURE(ExpectMinidumpContextX86(kSeed, observed_context)); | 122 ASSERT_NO_FATAL_FAILURE(ExpectMinidumpContextX86(kSeed, observed_context)); |
| 123 } | 123 } |
| 124 | 124 |
| 125 TEST(MinidumpExceptionWriter, Standard) { | 125 TEST(MinidumpExceptionWriter, Standard) { |
| 126 MinidumpFileWriter minidump_file_writer; | 126 MinidumpFileWriter minidump_file_writer; |
| 127 MinidumpExceptionWriter exception_writer; | 127 auto exception_writer = make_scoped_ptr(new MinidumpExceptionWriter()); |
| 128 | 128 |
| 129 const uint32_t kSeed = 200; | 129 const uint32_t kSeed = 200; |
| 130 const uint32_t kThreadID = 1; | 130 const uint32_t kThreadID = 1; |
| 131 const uint32_t kExceptionCode = 2; | 131 const uint32_t kExceptionCode = 2; |
| 132 const uint32_t kExceptionFlags = 3; | 132 const uint32_t kExceptionFlags = 3; |
| 133 const uint32_t kExceptionRecord = 4; | 133 const uint32_t kExceptionRecord = 4; |
| 134 const uint32_t kExceptionAddress = 5; | 134 const uint32_t kExceptionAddress = 5; |
| 135 const uint64_t kExceptionInformation0 = 6; | 135 const uint64_t kExceptionInformation0 = 6; |
| 136 const uint64_t kExceptionInformation1 = 7; | 136 const uint64_t kExceptionInformation1 = 7; |
| 137 const uint64_t kExceptionInformation2 = 7; | 137 const uint64_t kExceptionInformation2 = 7; |
| 138 | 138 |
| 139 MinidumpContextX86Writer context_x86_writer; | 139 auto context_x86_writer = make_scoped_ptr(new MinidumpContextX86Writer()); |
| 140 InitializeMinidumpContextX86(context_x86_writer.context(), kSeed); | 140 InitializeMinidumpContextX86(context_x86_writer->context(), kSeed); |
| 141 exception_writer.SetContext(&context_x86_writer); | 141 exception_writer->SetContext(context_x86_writer.Pass()); |
| 142 | 142 |
| 143 exception_writer.SetThreadID(kThreadID); | 143 exception_writer->SetThreadID(kThreadID); |
| 144 exception_writer.SetExceptionCode(kExceptionCode); | 144 exception_writer->SetExceptionCode(kExceptionCode); |
| 145 exception_writer.SetExceptionFlags(kExceptionFlags); | 145 exception_writer->SetExceptionFlags(kExceptionFlags); |
| 146 exception_writer.SetExceptionRecord(kExceptionRecord); | 146 exception_writer->SetExceptionRecord(kExceptionRecord); |
| 147 exception_writer.SetExceptionAddress(kExceptionAddress); | 147 exception_writer->SetExceptionAddress(kExceptionAddress); |
| 148 | 148 |
| 149 // Set a lot of exception information at first, and then replace it with less. | 149 // Set a lot of exception information at first, and then replace it with less. |
| 150 // This tests that the exception that is written does not contain the | 150 // This tests that the exception that is written does not contain the |
| 151 // “garbage” from the initial SetExceptionInformation() call. | 151 // “garbage” from the initial SetExceptionInformation() call. |
| 152 std::vector<uint64_t> exception_information(EXCEPTION_MAXIMUM_PARAMETERS, | 152 std::vector<uint64_t> exception_information(EXCEPTION_MAXIMUM_PARAMETERS, |
| 153 0x5a5a5a5a5a5a5a5a); | 153 0x5a5a5a5a5a5a5a5a); |
| 154 exception_writer.SetExceptionInformation(exception_information); | 154 exception_writer->SetExceptionInformation(exception_information); |
| 155 | 155 |
| 156 exception_information.clear(); | 156 exception_information.clear(); |
| 157 exception_information.push_back(kExceptionInformation0); | 157 exception_information.push_back(kExceptionInformation0); |
| 158 exception_information.push_back(kExceptionInformation1); | 158 exception_information.push_back(kExceptionInformation1); |
| 159 exception_information.push_back(kExceptionInformation2); | 159 exception_information.push_back(kExceptionInformation2); |
| 160 exception_writer.SetExceptionInformation(exception_information); | 160 exception_writer->SetExceptionInformation(exception_information); |
| 161 | 161 |
| 162 minidump_file_writer.AddStream(&exception_writer); | 162 minidump_file_writer.AddStream(exception_writer.Pass()); |
| 163 | 163 |
| 164 StringFileWriter file_writer; | 164 StringFileWriter file_writer; |
| 165 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); | 165 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); |
| 166 | 166 |
| 167 const MINIDUMP_EXCEPTION_STREAM* observed_exception_stream; | 167 const MINIDUMP_EXCEPTION_STREAM* observed_exception_stream; |
| 168 ASSERT_NO_FATAL_FAILURE( | 168 ASSERT_NO_FATAL_FAILURE( |
| 169 GetExceptionStream(file_writer.string(), &observed_exception_stream)); | 169 GetExceptionStream(file_writer.string(), &observed_exception_stream)); |
| 170 | 170 |
| 171 MINIDUMP_EXCEPTION_STREAM expected_exception_stream = {}; | 171 MINIDUMP_EXCEPTION_STREAM expected_exception_stream = {}; |
| 172 expected_exception_stream.ThreadId = kThreadID; | 172 expected_exception_stream.ThreadId = kThreadID; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 187 ASSERT_NO_FATAL_FAILURE(ExpectExceptionStream(&expected_exception_stream, | 187 ASSERT_NO_FATAL_FAILURE(ExpectExceptionStream(&expected_exception_stream, |
| 188 observed_exception_stream, | 188 observed_exception_stream, |
| 189 file_writer.string(), | 189 file_writer.string(), |
| 190 &observed_context)); | 190 &observed_context)); |
| 191 | 191 |
| 192 ASSERT_NO_FATAL_FAILURE(ExpectMinidumpContextX86(kSeed, observed_context)); | 192 ASSERT_NO_FATAL_FAILURE(ExpectMinidumpContextX86(kSeed, observed_context)); |
| 193 } | 193 } |
| 194 | 194 |
| 195 TEST(MinidumpExceptionWriterDeathTest, NoContext) { | 195 TEST(MinidumpExceptionWriterDeathTest, NoContext) { |
| 196 MinidumpFileWriter minidump_file_writer; | 196 MinidumpFileWriter minidump_file_writer; |
| 197 MinidumpExceptionWriter exception_writer; | 197 auto exception_writer = make_scoped_ptr(new MinidumpExceptionWriter()); |
| 198 | 198 |
| 199 minidump_file_writer.AddStream(&exception_writer); | 199 minidump_file_writer.AddStream(exception_writer.Pass()); |
| 200 | 200 |
| 201 StringFileWriter file_writer; | 201 StringFileWriter file_writer; |
| 202 ASSERT_DEATH(minidump_file_writer.WriteEverything(&file_writer), "context_"); | 202 ASSERT_DEATH(minidump_file_writer.WriteEverything(&file_writer), "context_"); |
| 203 } | 203 } |
| 204 | 204 |
| 205 TEST(MinidumpExceptionWriterDeathTest, TooMuchInformation) { | 205 TEST(MinidumpExceptionWriterDeathTest, TooMuchInformation) { |
| 206 MinidumpExceptionWriter exception_writer; | 206 MinidumpExceptionWriter exception_writer; |
| 207 std::vector<uint64_t> exception_information(EXCEPTION_MAXIMUM_PARAMETERS + 1, | 207 std::vector<uint64_t> exception_information(EXCEPTION_MAXIMUM_PARAMETERS + 1, |
| 208 0x5a5a5a5a5a5a5a5a); | 208 0x5a5a5a5a5a5a5a5a); |
| 209 ASSERT_DEATH(exception_writer.SetExceptionInformation(exception_information), | 209 ASSERT_DEATH(exception_writer.SetExceptionInformation(exception_information), |
| 210 "kMaxParameters"); | 210 "kMaxParameters"); |
| 211 } | 211 } |
| 212 | 212 |
| 213 } // namespace | 213 } // namespace |
| 214 } // namespace test | 214 } // namespace test |
| 215 } // namespace crashpad | 215 } // namespace crashpad |
| OLD | NEW |