| 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_memory_writer.h" | 26 #include "minidump/minidump_memory_writer.h" |
| 27 #include "minidump/minidump_file_writer.h" | 27 #include "minidump/minidump_file_writer.h" |
| 28 #include "minidump/minidump_thread_id_map.h" | 28 #include "minidump/minidump_thread_id_map.h" |
| 29 #include "minidump/test/minidump_context_test_util.h" | 29 #include "minidump/test/minidump_context_test_util.h" |
| 30 #include "minidump/test/minidump_memory_writer_test_util.h" | 30 #include "minidump/test/minidump_memory_writer_test_util.h" |
| 31 #include "minidump/test/minidump_file_writer_test_util.h" | 31 #include "minidump/test/minidump_file_writer_test_util.h" |
| 32 #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" | 33 #include "snapshot/test/test_cpu_context.h" |
| 34 #include "snapshot/test/test_memory_snapshot.h" | 34 #include "snapshot/test/test_memory_snapshot.h" |
| 35 #include "snapshot/test/test_thread_snapshot.h" | 35 #include "snapshot/test/test_thread_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_THREAD_LIST stream in |thread_list|. If | 42 // This returns the MINIDUMP_THREAD_LIST stream in |thread_list|. If |
| 43 // |memory_list| is not nullptr, a MINIDUMP_MEMORY_LIST stream is also expected | 43 // |memory_list| is not nullptr, a MINIDUMP_MEMORY_LIST stream is also expected |
| 44 // in |file_contents|, and that stream will be returned in |memory_list|. | 44 // in |file_contents|, and that stream will be returned in |memory_list|. |
| 45 void GetThreadListStream(const std::string& file_contents, | 45 void GetThreadListStream(const std::string& file_contents, |
| 46 const MINIDUMP_THREAD_LIST** thread_list, | 46 const MINIDUMP_THREAD_LIST** thread_list, |
| (...skipping 28 matching lines...) Expand all Loading... |
| 75 ASSERT_TRUE(*memory_list); | 75 ASSERT_TRUE(*memory_list); |
| 76 } | 76 } |
| 77 } | 77 } |
| 78 | 78 |
| 79 TEST(MinidumpThreadWriter, EmptyThreadList) { | 79 TEST(MinidumpThreadWriter, EmptyThreadList) { |
| 80 MinidumpFileWriter minidump_file_writer; | 80 MinidumpFileWriter minidump_file_writer; |
| 81 auto thread_list_writer = make_scoped_ptr(new MinidumpThreadListWriter()); | 81 auto thread_list_writer = make_scoped_ptr(new MinidumpThreadListWriter()); |
| 82 | 82 |
| 83 minidump_file_writer.AddStream(thread_list_writer.Pass()); | 83 minidump_file_writer.AddStream(thread_list_writer.Pass()); |
| 84 | 84 |
| 85 StringFileWriter file_writer; | 85 StringFile string_file; |
| 86 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); | 86 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); |
| 87 | 87 |
| 88 ASSERT_EQ(sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) + | 88 ASSERT_EQ(sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) + |
| 89 sizeof(MINIDUMP_THREAD_LIST), | 89 sizeof(MINIDUMP_THREAD_LIST), |
| 90 file_writer.string().size()); | 90 string_file.string().size()); |
| 91 | 91 |
| 92 const MINIDUMP_THREAD_LIST* thread_list = nullptr; | 92 const MINIDUMP_THREAD_LIST* thread_list = nullptr; |
| 93 ASSERT_NO_FATAL_FAILURE( | 93 ASSERT_NO_FATAL_FAILURE( |
| 94 GetThreadListStream(file_writer.string(), &thread_list, nullptr)); | 94 GetThreadListStream(string_file.string(), &thread_list, nullptr)); |
| 95 | 95 |
| 96 EXPECT_EQ(0u, thread_list->NumberOfThreads); | 96 EXPECT_EQ(0u, thread_list->NumberOfThreads); |
| 97 } | 97 } |
| 98 | 98 |
| 99 // The MINIDUMP_THREADs |expected| and |observed| are compared against each | 99 // The MINIDUMP_THREADs |expected| and |observed| are compared against each |
| 100 // other using gtest assertions. If |stack| is not nullptr, |observed| is | 100 // other using gtest assertions. If |stack| is not nullptr, |observed| is |
| 101 // expected to contain a populated MINIDUMP_MEMORY_DESCRIPTOR in its Stack | 101 // expected to contain a populated MINIDUMP_MEMORY_DESCRIPTOR in its Stack |
| 102 // field, otherwise, its Stack field is expected to be zeroed out. The memory | 102 // field, otherwise, its Stack field is expected to be zeroed out. The memory |
| 103 // descriptor will be placed in |stack|. |observed| must contain a populated | 103 // descriptor will be placed in |stack|. |observed| must contain a populated |
| 104 // ThreadContext field. The context will be recovered from |file_contents| and | 104 // ThreadContext field. The context will be recovered from |file_contents| and |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 thread_writer->SetPriority(kPriority); | 155 thread_writer->SetPriority(kPriority); |
| 156 thread_writer->SetTEB(kTEB); | 156 thread_writer->SetTEB(kTEB); |
| 157 | 157 |
| 158 auto context_x86_writer = make_scoped_ptr(new MinidumpContextX86Writer()); | 158 auto context_x86_writer = make_scoped_ptr(new MinidumpContextX86Writer()); |
| 159 InitializeMinidumpContextX86(context_x86_writer->context(), kSeed); | 159 InitializeMinidumpContextX86(context_x86_writer->context(), kSeed); |
| 160 thread_writer->SetContext(context_x86_writer.Pass()); | 160 thread_writer->SetContext(context_x86_writer.Pass()); |
| 161 | 161 |
| 162 thread_list_writer->AddThread(thread_writer.Pass()); | 162 thread_list_writer->AddThread(thread_writer.Pass()); |
| 163 minidump_file_writer.AddStream(thread_list_writer.Pass()); | 163 minidump_file_writer.AddStream(thread_list_writer.Pass()); |
| 164 | 164 |
| 165 StringFileWriter file_writer; | 165 StringFile string_file; |
| 166 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); | 166 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); |
| 167 | 167 |
| 168 ASSERT_EQ(sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) + | 168 ASSERT_EQ(sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) + |
| 169 sizeof(MINIDUMP_THREAD_LIST) + 1 * sizeof(MINIDUMP_THREAD) + | 169 sizeof(MINIDUMP_THREAD_LIST) + 1 * sizeof(MINIDUMP_THREAD) + |
| 170 1 * sizeof(MinidumpContextX86), | 170 1 * sizeof(MinidumpContextX86), |
| 171 file_writer.string().size()); | 171 string_file.string().size()); |
| 172 | 172 |
| 173 const MINIDUMP_THREAD_LIST* thread_list = nullptr; | 173 const MINIDUMP_THREAD_LIST* thread_list = nullptr; |
| 174 ASSERT_NO_FATAL_FAILURE( | 174 ASSERT_NO_FATAL_FAILURE( |
| 175 GetThreadListStream(file_writer.string(), &thread_list, nullptr)); | 175 GetThreadListStream(string_file.string(), &thread_list, nullptr)); |
| 176 | 176 |
| 177 EXPECT_EQ(1u, thread_list->NumberOfThreads); | 177 EXPECT_EQ(1u, thread_list->NumberOfThreads); |
| 178 | 178 |
| 179 MINIDUMP_THREAD expected = {}; | 179 MINIDUMP_THREAD expected = {}; |
| 180 expected.ThreadId = kThreadID; | 180 expected.ThreadId = kThreadID; |
| 181 expected.SuspendCount = kSuspendCount; | 181 expected.SuspendCount = kSuspendCount; |
| 182 expected.PriorityClass = kPriorityClass; | 182 expected.PriorityClass = kPriorityClass; |
| 183 expected.Priority = kPriority; | 183 expected.Priority = kPriority; |
| 184 expected.Teb = kTEB; | 184 expected.Teb = kTEB; |
| 185 expected.ThreadContext.DataSize = sizeof(MinidumpContextX86); | 185 expected.ThreadContext.DataSize = sizeof(MinidumpContextX86); |
| 186 | 186 |
| 187 const MinidumpContextX86* observed_context = nullptr; | 187 const MinidumpContextX86* observed_context = nullptr; |
| 188 ASSERT_NO_FATAL_FAILURE( | 188 ASSERT_NO_FATAL_FAILURE( |
| 189 ExpectThread(&expected, | 189 ExpectThread(&expected, |
| 190 &thread_list->Threads[0], | 190 &thread_list->Threads[0], |
| 191 file_writer.string(), | 191 string_file.string(), |
| 192 nullptr, | 192 nullptr, |
| 193 reinterpret_cast<const void**>(&observed_context))); | 193 reinterpret_cast<const void**>(&observed_context))); |
| 194 | 194 |
| 195 ASSERT_NO_FATAL_FAILURE( | 195 ASSERT_NO_FATAL_FAILURE( |
| 196 ExpectMinidumpContextX86(kSeed, observed_context, false)); | 196 ExpectMinidumpContextX86(kSeed, observed_context, false)); |
| 197 } | 197 } |
| 198 | 198 |
| 199 TEST(MinidumpThreadWriter, OneThread_AMD64_Stack) { | 199 TEST(MinidumpThreadWriter, OneThread_AMD64_Stack) { |
| 200 MinidumpFileWriter minidump_file_writer; | 200 MinidumpFileWriter minidump_file_writer; |
| 201 auto thread_list_writer = make_scoped_ptr(new MinidumpThreadListWriter()); | 201 auto thread_list_writer = make_scoped_ptr(new MinidumpThreadListWriter()); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 222 thread_writer->SetStack(memory_writer.Pass()); | 222 thread_writer->SetStack(memory_writer.Pass()); |
| 223 | 223 |
| 224 MSVC_SUPPRESS_WARNING(4316); // Object allocated on heap may not be aligned. | 224 MSVC_SUPPRESS_WARNING(4316); // Object allocated on heap may not be aligned. |
| 225 auto context_amd64_writer = make_scoped_ptr(new MinidumpContextAMD64Writer()); | 225 auto context_amd64_writer = make_scoped_ptr(new MinidumpContextAMD64Writer()); |
| 226 InitializeMinidumpContextAMD64(context_amd64_writer->context(), kSeed); | 226 InitializeMinidumpContextAMD64(context_amd64_writer->context(), kSeed); |
| 227 thread_writer->SetContext(context_amd64_writer.Pass()); | 227 thread_writer->SetContext(context_amd64_writer.Pass()); |
| 228 | 228 |
| 229 thread_list_writer->AddThread(thread_writer.Pass()); | 229 thread_list_writer->AddThread(thread_writer.Pass()); |
| 230 minidump_file_writer.AddStream(thread_list_writer.Pass()); | 230 minidump_file_writer.AddStream(thread_list_writer.Pass()); |
| 231 | 231 |
| 232 StringFileWriter file_writer; | 232 StringFile string_file; |
| 233 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); | 233 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); |
| 234 | 234 |
| 235 ASSERT_EQ(sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) + | 235 ASSERT_EQ(sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) + |
| 236 sizeof(MINIDUMP_THREAD_LIST) + 1 * sizeof(MINIDUMP_THREAD) + | 236 sizeof(MINIDUMP_THREAD_LIST) + 1 * sizeof(MINIDUMP_THREAD) + |
| 237 1 * sizeof(MinidumpContextAMD64) + kMemorySize, | 237 1 * sizeof(MinidumpContextAMD64) + kMemorySize, |
| 238 file_writer.string().size()); | 238 string_file.string().size()); |
| 239 | 239 |
| 240 const MINIDUMP_THREAD_LIST* thread_list = nullptr; | 240 const MINIDUMP_THREAD_LIST* thread_list = nullptr; |
| 241 ASSERT_NO_FATAL_FAILURE( | 241 ASSERT_NO_FATAL_FAILURE( |
| 242 GetThreadListStream(file_writer.string(), &thread_list, nullptr)); | 242 GetThreadListStream(string_file.string(), &thread_list, nullptr)); |
| 243 | 243 |
| 244 EXPECT_EQ(1u, thread_list->NumberOfThreads); | 244 EXPECT_EQ(1u, thread_list->NumberOfThreads); |
| 245 | 245 |
| 246 MINIDUMP_THREAD expected = {}; | 246 MINIDUMP_THREAD expected = {}; |
| 247 expected.ThreadId = kThreadID; | 247 expected.ThreadId = kThreadID; |
| 248 expected.SuspendCount = kSuspendCount; | 248 expected.SuspendCount = kSuspendCount; |
| 249 expected.PriorityClass = kPriorityClass; | 249 expected.PriorityClass = kPriorityClass; |
| 250 expected.Priority = kPriority; | 250 expected.Priority = kPriority; |
| 251 expected.Teb = kTEB; | 251 expected.Teb = kTEB; |
| 252 expected.Stack.StartOfMemoryRange = kMemoryBase; | 252 expected.Stack.StartOfMemoryRange = kMemoryBase; |
| 253 expected.Stack.Memory.DataSize = kMemorySize; | 253 expected.Stack.Memory.DataSize = kMemorySize; |
| 254 expected.ThreadContext.DataSize = sizeof(MinidumpContextAMD64); | 254 expected.ThreadContext.DataSize = sizeof(MinidumpContextAMD64); |
| 255 | 255 |
| 256 const MINIDUMP_MEMORY_DESCRIPTOR* observed_stack = nullptr; | 256 const MINIDUMP_MEMORY_DESCRIPTOR* observed_stack = nullptr; |
| 257 const MinidumpContextAMD64* observed_context = nullptr; | 257 const MinidumpContextAMD64* observed_context = nullptr; |
| 258 ASSERT_NO_FATAL_FAILURE( | 258 ASSERT_NO_FATAL_FAILURE( |
| 259 ExpectThread(&expected, | 259 ExpectThread(&expected, |
| 260 &thread_list->Threads[0], | 260 &thread_list->Threads[0], |
| 261 file_writer.string(), | 261 string_file.string(), |
| 262 &observed_stack, | 262 &observed_stack, |
| 263 reinterpret_cast<const void**>(&observed_context))); | 263 reinterpret_cast<const void**>(&observed_context))); |
| 264 | 264 |
| 265 ASSERT_NO_FATAL_FAILURE( | 265 ASSERT_NO_FATAL_FAILURE( |
| 266 ExpectMinidumpMemoryDescriptorAndContents(&expected.Stack, | 266 ExpectMinidumpMemoryDescriptorAndContents(&expected.Stack, |
| 267 observed_stack, | 267 observed_stack, |
| 268 file_writer.string(), | 268 string_file.string(), |
| 269 kMemoryValue, | 269 kMemoryValue, |
| 270 true)); | 270 true)); |
| 271 ASSERT_NO_FATAL_FAILURE( | 271 ASSERT_NO_FATAL_FAILURE( |
| 272 ExpectMinidumpContextAMD64(kSeed, observed_context, false)); | 272 ExpectMinidumpContextAMD64(kSeed, observed_context, false)); |
| 273 } | 273 } |
| 274 | 274 |
| 275 TEST(MinidumpThreadWriter, ThreeThreads_x86_MemoryList) { | 275 TEST(MinidumpThreadWriter, ThreeThreads_x86_MemoryList) { |
| 276 MinidumpFileWriter minidump_file_writer; | 276 MinidumpFileWriter minidump_file_writer; |
| 277 auto thread_list_writer = make_scoped_ptr(new MinidumpThreadListWriter()); | 277 auto thread_list_writer = make_scoped_ptr(new MinidumpThreadListWriter()); |
| 278 auto memory_list_writer = make_scoped_ptr(new MinidumpMemoryListWriter()); | 278 auto memory_list_writer = make_scoped_ptr(new MinidumpMemoryListWriter()); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 | 355 |
| 356 auto context_x86_writer_2 = make_scoped_ptr(new MinidumpContextX86Writer()); | 356 auto context_x86_writer_2 = make_scoped_ptr(new MinidumpContextX86Writer()); |
| 357 InitializeMinidumpContextX86(context_x86_writer_2->context(), kSeed2); | 357 InitializeMinidumpContextX86(context_x86_writer_2->context(), kSeed2); |
| 358 thread_writer_2->SetContext(context_x86_writer_2.Pass()); | 358 thread_writer_2->SetContext(context_x86_writer_2.Pass()); |
| 359 | 359 |
| 360 thread_list_writer->AddThread(thread_writer_2.Pass()); | 360 thread_list_writer->AddThread(thread_writer_2.Pass()); |
| 361 | 361 |
| 362 minidump_file_writer.AddStream(thread_list_writer.Pass()); | 362 minidump_file_writer.AddStream(thread_list_writer.Pass()); |
| 363 minidump_file_writer.AddStream(memory_list_writer.Pass()); | 363 minidump_file_writer.AddStream(memory_list_writer.Pass()); |
| 364 | 364 |
| 365 StringFileWriter file_writer; | 365 StringFile string_file; |
| 366 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); | 366 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); |
| 367 | 367 |
| 368 ASSERT_EQ(sizeof(MINIDUMP_HEADER) + 2 * sizeof(MINIDUMP_DIRECTORY) + | 368 ASSERT_EQ(sizeof(MINIDUMP_HEADER) + 2 * sizeof(MINIDUMP_DIRECTORY) + |
| 369 sizeof(MINIDUMP_THREAD_LIST) + 3 * sizeof(MINIDUMP_THREAD) + | 369 sizeof(MINIDUMP_THREAD_LIST) + 3 * sizeof(MINIDUMP_THREAD) + |
| 370 sizeof(MINIDUMP_MEMORY_LIST) + | 370 sizeof(MINIDUMP_MEMORY_LIST) + |
| 371 3 * sizeof(MINIDUMP_MEMORY_DESCRIPTOR) + | 371 3 * sizeof(MINIDUMP_MEMORY_DESCRIPTOR) + |
| 372 3 * sizeof(MinidumpContextX86) + kMemorySize0 + kMemorySize1 + | 372 3 * sizeof(MinidumpContextX86) + kMemorySize0 + kMemorySize1 + |
| 373 kMemorySize2 + 12, // 12 for alignment | 373 kMemorySize2 + 12, // 12 for alignment |
| 374 file_writer.string().size()); | 374 string_file.string().size()); |
| 375 | 375 |
| 376 const MINIDUMP_THREAD_LIST* thread_list = nullptr; | 376 const MINIDUMP_THREAD_LIST* thread_list = nullptr; |
| 377 const MINIDUMP_MEMORY_LIST* memory_list = nullptr; | 377 const MINIDUMP_MEMORY_LIST* memory_list = nullptr; |
| 378 ASSERT_NO_FATAL_FAILURE( | 378 ASSERT_NO_FATAL_FAILURE( |
| 379 GetThreadListStream(file_writer.string(), &thread_list, &memory_list)); | 379 GetThreadListStream(string_file.string(), &thread_list, &memory_list)); |
| 380 | 380 |
| 381 EXPECT_EQ(3u, thread_list->NumberOfThreads); | 381 EXPECT_EQ(3u, thread_list->NumberOfThreads); |
| 382 EXPECT_EQ(3u, memory_list->NumberOfMemoryRanges); | 382 EXPECT_EQ(3u, memory_list->NumberOfMemoryRanges); |
| 383 | 383 |
| 384 { | 384 { |
| 385 SCOPED_TRACE("thread 0"); | 385 SCOPED_TRACE("thread 0"); |
| 386 | 386 |
| 387 MINIDUMP_THREAD expected = {}; | 387 MINIDUMP_THREAD expected = {}; |
| 388 expected.ThreadId = kThreadID0; | 388 expected.ThreadId = kThreadID0; |
| 389 expected.SuspendCount = kSuspendCount0; | 389 expected.SuspendCount = kSuspendCount0; |
| 390 expected.PriorityClass = kPriorityClass0; | 390 expected.PriorityClass = kPriorityClass0; |
| 391 expected.Priority = kPriority0; | 391 expected.Priority = kPriority0; |
| 392 expected.Teb = kTEB0; | 392 expected.Teb = kTEB0; |
| 393 expected.Stack.StartOfMemoryRange = kMemoryBase0; | 393 expected.Stack.StartOfMemoryRange = kMemoryBase0; |
| 394 expected.Stack.Memory.DataSize = kMemorySize0; | 394 expected.Stack.Memory.DataSize = kMemorySize0; |
| 395 expected.ThreadContext.DataSize = sizeof(MinidumpContextX86); | 395 expected.ThreadContext.DataSize = sizeof(MinidumpContextX86); |
| 396 | 396 |
| 397 const MINIDUMP_MEMORY_DESCRIPTOR* observed_stack = nullptr; | 397 const MINIDUMP_MEMORY_DESCRIPTOR* observed_stack = nullptr; |
| 398 const MinidumpContextX86* observed_context = nullptr; | 398 const MinidumpContextX86* observed_context = nullptr; |
| 399 ASSERT_NO_FATAL_FAILURE( | 399 ASSERT_NO_FATAL_FAILURE( |
| 400 ExpectThread(&expected, | 400 ExpectThread(&expected, |
| 401 &thread_list->Threads[0], | 401 &thread_list->Threads[0], |
| 402 file_writer.string(), | 402 string_file.string(), |
| 403 &observed_stack, | 403 &observed_stack, |
| 404 reinterpret_cast<const void**>(&observed_context))); | 404 reinterpret_cast<const void**>(&observed_context))); |
| 405 | 405 |
| 406 ASSERT_NO_FATAL_FAILURE( | 406 ASSERT_NO_FATAL_FAILURE( |
| 407 ExpectMinidumpMemoryDescriptorAndContents(&expected.Stack, | 407 ExpectMinidumpMemoryDescriptorAndContents(&expected.Stack, |
| 408 observed_stack, | 408 observed_stack, |
| 409 file_writer.string(), | 409 string_file.string(), |
| 410 kMemoryValue0, | 410 kMemoryValue0, |
| 411 false)); | 411 false)); |
| 412 ASSERT_NO_FATAL_FAILURE( | 412 ASSERT_NO_FATAL_FAILURE( |
| 413 ExpectMinidumpContextX86(kSeed0, observed_context, false)); | 413 ExpectMinidumpContextX86(kSeed0, observed_context, false)); |
| 414 ASSERT_NO_FATAL_FAILURE(ExpectMinidumpMemoryDescriptor( | 414 ASSERT_NO_FATAL_FAILURE(ExpectMinidumpMemoryDescriptor( |
| 415 observed_stack, &memory_list->MemoryRanges[0])); | 415 observed_stack, &memory_list->MemoryRanges[0])); |
| 416 } | 416 } |
| 417 | 417 |
| 418 { | 418 { |
| 419 SCOPED_TRACE("thread 1"); | 419 SCOPED_TRACE("thread 1"); |
| 420 | 420 |
| 421 MINIDUMP_THREAD expected = {}; | 421 MINIDUMP_THREAD expected = {}; |
| 422 expected.ThreadId = kThreadID1; | 422 expected.ThreadId = kThreadID1; |
| 423 expected.SuspendCount = kSuspendCount1; | 423 expected.SuspendCount = kSuspendCount1; |
| 424 expected.PriorityClass = kPriorityClass1; | 424 expected.PriorityClass = kPriorityClass1; |
| 425 expected.Priority = kPriority1; | 425 expected.Priority = kPriority1; |
| 426 expected.Teb = kTEB1; | 426 expected.Teb = kTEB1; |
| 427 expected.Stack.StartOfMemoryRange = kMemoryBase1; | 427 expected.Stack.StartOfMemoryRange = kMemoryBase1; |
| 428 expected.Stack.Memory.DataSize = kMemorySize1; | 428 expected.Stack.Memory.DataSize = kMemorySize1; |
| 429 expected.ThreadContext.DataSize = sizeof(MinidumpContextX86); | 429 expected.ThreadContext.DataSize = sizeof(MinidumpContextX86); |
| 430 | 430 |
| 431 const MINIDUMP_MEMORY_DESCRIPTOR* observed_stack = nullptr; | 431 const MINIDUMP_MEMORY_DESCRIPTOR* observed_stack = nullptr; |
| 432 const MinidumpContextX86* observed_context = nullptr; | 432 const MinidumpContextX86* observed_context = nullptr; |
| 433 ASSERT_NO_FATAL_FAILURE( | 433 ASSERT_NO_FATAL_FAILURE( |
| 434 ExpectThread(&expected, | 434 ExpectThread(&expected, |
| 435 &thread_list->Threads[1], | 435 &thread_list->Threads[1], |
| 436 file_writer.string(), | 436 string_file.string(), |
| 437 &observed_stack, | 437 &observed_stack, |
| 438 reinterpret_cast<const void**>(&observed_context))); | 438 reinterpret_cast<const void**>(&observed_context))); |
| 439 | 439 |
| 440 ASSERT_NO_FATAL_FAILURE( | 440 ASSERT_NO_FATAL_FAILURE( |
| 441 ExpectMinidumpMemoryDescriptorAndContents(&expected.Stack, | 441 ExpectMinidumpMemoryDescriptorAndContents(&expected.Stack, |
| 442 observed_stack, | 442 observed_stack, |
| 443 file_writer.string(), | 443 string_file.string(), |
| 444 kMemoryValue1, | 444 kMemoryValue1, |
| 445 false)); | 445 false)); |
| 446 ASSERT_NO_FATAL_FAILURE( | 446 ASSERT_NO_FATAL_FAILURE( |
| 447 ExpectMinidumpContextX86(kSeed1, observed_context, false)); | 447 ExpectMinidumpContextX86(kSeed1, observed_context, false)); |
| 448 ASSERT_NO_FATAL_FAILURE(ExpectMinidumpMemoryDescriptor( | 448 ASSERT_NO_FATAL_FAILURE(ExpectMinidumpMemoryDescriptor( |
| 449 observed_stack, &memory_list->MemoryRanges[1])); | 449 observed_stack, &memory_list->MemoryRanges[1])); |
| 450 } | 450 } |
| 451 | 451 |
| 452 { | 452 { |
| 453 SCOPED_TRACE("thread 2"); | 453 SCOPED_TRACE("thread 2"); |
| 454 | 454 |
| 455 MINIDUMP_THREAD expected = {}; | 455 MINIDUMP_THREAD expected = {}; |
| 456 expected.ThreadId = kThreadID2; | 456 expected.ThreadId = kThreadID2; |
| 457 expected.SuspendCount = kSuspendCount2; | 457 expected.SuspendCount = kSuspendCount2; |
| 458 expected.PriorityClass = kPriorityClass2; | 458 expected.PriorityClass = kPriorityClass2; |
| 459 expected.Priority = kPriority2; | 459 expected.Priority = kPriority2; |
| 460 expected.Teb = kTEB2; | 460 expected.Teb = kTEB2; |
| 461 expected.Stack.StartOfMemoryRange = kMemoryBase2; | 461 expected.Stack.StartOfMemoryRange = kMemoryBase2; |
| 462 expected.Stack.Memory.DataSize = kMemorySize2; | 462 expected.Stack.Memory.DataSize = kMemorySize2; |
| 463 expected.ThreadContext.DataSize = sizeof(MinidumpContextX86); | 463 expected.ThreadContext.DataSize = sizeof(MinidumpContextX86); |
| 464 | 464 |
| 465 const MINIDUMP_MEMORY_DESCRIPTOR* observed_stack = nullptr; | 465 const MINIDUMP_MEMORY_DESCRIPTOR* observed_stack = nullptr; |
| 466 const MinidumpContextX86* observed_context = nullptr; | 466 const MinidumpContextX86* observed_context = nullptr; |
| 467 ASSERT_NO_FATAL_FAILURE( | 467 ASSERT_NO_FATAL_FAILURE( |
| 468 ExpectThread(&expected, | 468 ExpectThread(&expected, |
| 469 &thread_list->Threads[2], | 469 &thread_list->Threads[2], |
| 470 file_writer.string(), | 470 string_file.string(), |
| 471 &observed_stack, | 471 &observed_stack, |
| 472 reinterpret_cast<const void**>(&observed_context))); | 472 reinterpret_cast<const void**>(&observed_context))); |
| 473 | 473 |
| 474 ASSERT_NO_FATAL_FAILURE( | 474 ASSERT_NO_FATAL_FAILURE( |
| 475 ExpectMinidumpMemoryDescriptorAndContents(&expected.Stack, | 475 ExpectMinidumpMemoryDescriptorAndContents(&expected.Stack, |
| 476 observed_stack, | 476 observed_stack, |
| 477 file_writer.string(), | 477 string_file.string(), |
| 478 kMemoryValue2, | 478 kMemoryValue2, |
| 479 true)); | 479 true)); |
| 480 ASSERT_NO_FATAL_FAILURE( | 480 ASSERT_NO_FATAL_FAILURE( |
| 481 ExpectMinidumpContextX86(kSeed2, observed_context, false)); | 481 ExpectMinidumpContextX86(kSeed2, observed_context, false)); |
| 482 ASSERT_NO_FATAL_FAILURE(ExpectMinidumpMemoryDescriptor( | 482 ASSERT_NO_FATAL_FAILURE(ExpectMinidumpMemoryDescriptor( |
| 483 observed_stack, &memory_list->MemoryRanges[2])); | 483 observed_stack, &memory_list->MemoryRanges[2])); |
| 484 } | 484 } |
| 485 } | 485 } |
| 486 | 486 |
| 487 struct InitializeFromSnapshotX86Traits { | 487 struct InitializeFromSnapshotX86Traits { |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 600 auto thread_list_writer = make_scoped_ptr(new MinidumpThreadListWriter()); | 600 auto thread_list_writer = make_scoped_ptr(new MinidumpThreadListWriter()); |
| 601 auto memory_list_writer = make_scoped_ptr(new MinidumpMemoryListWriter()); | 601 auto memory_list_writer = make_scoped_ptr(new MinidumpMemoryListWriter()); |
| 602 thread_list_writer->SetMemoryListWriter(memory_list_writer.get()); | 602 thread_list_writer->SetMemoryListWriter(memory_list_writer.get()); |
| 603 MinidumpThreadIDMap thread_id_map; | 603 MinidumpThreadIDMap thread_id_map; |
| 604 thread_list_writer->InitializeFromSnapshot(thread_snapshots, &thread_id_map); | 604 thread_list_writer->InitializeFromSnapshot(thread_snapshots, &thread_id_map); |
| 605 | 605 |
| 606 MinidumpFileWriter minidump_file_writer; | 606 MinidumpFileWriter minidump_file_writer; |
| 607 minidump_file_writer.AddStream(thread_list_writer.Pass()); | 607 minidump_file_writer.AddStream(thread_list_writer.Pass()); |
| 608 minidump_file_writer.AddStream(memory_list_writer.Pass()); | 608 minidump_file_writer.AddStream(memory_list_writer.Pass()); |
| 609 | 609 |
| 610 StringFileWriter file_writer; | 610 StringFile string_file; |
| 611 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); | 611 ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file)); |
| 612 | 612 |
| 613 const MINIDUMP_THREAD_LIST* thread_list = nullptr; | 613 const MINIDUMP_THREAD_LIST* thread_list = nullptr; |
| 614 const MINIDUMP_MEMORY_LIST* memory_list = nullptr; | 614 const MINIDUMP_MEMORY_LIST* memory_list = nullptr; |
| 615 ASSERT_NO_FATAL_FAILURE( | 615 ASSERT_NO_FATAL_FAILURE( |
| 616 GetThreadListStream(file_writer.string(), &thread_list, &memory_list)); | 616 GetThreadListStream(string_file.string(), &thread_list, &memory_list)); |
| 617 | 617 |
| 618 ASSERT_EQ(3u, thread_list->NumberOfThreads); | 618 ASSERT_EQ(3u, thread_list->NumberOfThreads); |
| 619 ASSERT_EQ(2u, memory_list->NumberOfMemoryRanges); | 619 ASSERT_EQ(2u, memory_list->NumberOfMemoryRanges); |
| 620 | 620 |
| 621 size_t memory_index = 0; | 621 size_t memory_index = 0; |
| 622 for (size_t index = 0; index < thread_list->NumberOfThreads; ++index) { | 622 for (size_t index = 0; index < thread_list->NumberOfThreads; ++index) { |
| 623 SCOPED_TRACE(base::StringPrintf("index %" PRIuS, index)); | 623 SCOPED_TRACE(base::StringPrintf("index %" PRIuS, index)); |
| 624 | 624 |
| 625 const MINIDUMP_MEMORY_DESCRIPTOR* observed_stack = nullptr; | 625 const MINIDUMP_MEMORY_DESCRIPTOR* observed_stack = nullptr; |
| 626 const MINIDUMP_MEMORY_DESCRIPTOR** observed_stack_p = | 626 const MINIDUMP_MEMORY_DESCRIPTOR** observed_stack_p = |
| 627 expect_threads[index].Stack.Memory.DataSize ? &observed_stack : nullptr; | 627 expect_threads[index].Stack.Memory.DataSize ? &observed_stack : nullptr; |
| 628 const MinidumpContextType* observed_context = nullptr; | 628 const MinidumpContextType* observed_context = nullptr; |
| 629 ASSERT_NO_FATAL_FAILURE( | 629 ASSERT_NO_FATAL_FAILURE( |
| 630 ExpectThread(&expect_threads[index], | 630 ExpectThread(&expect_threads[index], |
| 631 &thread_list->Threads[index], | 631 &thread_list->Threads[index], |
| 632 file_writer.string(), | 632 string_file.string(), |
| 633 observed_stack_p, | 633 observed_stack_p, |
| 634 reinterpret_cast<const void**>(&observed_context))); | 634 reinterpret_cast<const void**>(&observed_context))); |
| 635 | 635 |
| 636 ASSERT_NO_FATAL_FAILURE(Traits::ExpectMinidumpContext( | 636 ASSERT_NO_FATAL_FAILURE(Traits::ExpectMinidumpContext( |
| 637 context_seeds[index], observed_context, true)); | 637 context_seeds[index], observed_context, true)); |
| 638 | 638 |
| 639 if (observed_stack_p) { | 639 if (observed_stack_p) { |
| 640 ASSERT_NO_FATAL_FAILURE(ExpectMinidumpMemoryDescriptorAndContents( | 640 ASSERT_NO_FATAL_FAILURE(ExpectMinidumpMemoryDescriptorAndContents( |
| 641 &expect_threads[index].Stack, | 641 &expect_threads[index].Stack, |
| 642 observed_stack, | 642 observed_stack, |
| 643 file_writer.string(), | 643 string_file.string(), |
| 644 memory_values[index], | 644 memory_values[index], |
| 645 index == thread_list->NumberOfThreads - 1)); | 645 index == thread_list->NumberOfThreads - 1)); |
| 646 | 646 |
| 647 ASSERT_NO_FATAL_FAILURE(ExpectMinidumpMemoryDescriptor( | 647 ASSERT_NO_FATAL_FAILURE(ExpectMinidumpMemoryDescriptor( |
| 648 observed_stack, &memory_list->MemoryRanges[memory_index])); | 648 observed_stack, &memory_list->MemoryRanges[memory_index])); |
| 649 | 649 |
| 650 ++memory_index; | 650 ++memory_index; |
| 651 } | 651 } |
| 652 } | 652 } |
| 653 } | 653 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 666 | 666 |
| 667 TEST(MinidumpThreadWriterDeathTest, NoContext) { | 667 TEST(MinidumpThreadWriterDeathTest, NoContext) { |
| 668 MinidumpFileWriter minidump_file_writer; | 668 MinidumpFileWriter minidump_file_writer; |
| 669 auto thread_list_writer = make_scoped_ptr(new MinidumpThreadListWriter()); | 669 auto thread_list_writer = make_scoped_ptr(new MinidumpThreadListWriter()); |
| 670 | 670 |
| 671 auto thread_writer = make_scoped_ptr(new MinidumpThreadWriter()); | 671 auto thread_writer = make_scoped_ptr(new MinidumpThreadWriter()); |
| 672 | 672 |
| 673 thread_list_writer->AddThread(thread_writer.Pass()); | 673 thread_list_writer->AddThread(thread_writer.Pass()); |
| 674 minidump_file_writer.AddStream(thread_list_writer.Pass()); | 674 minidump_file_writer.AddStream(thread_list_writer.Pass()); |
| 675 | 675 |
| 676 StringFileWriter file_writer; | 676 StringFile string_file; |
| 677 ASSERT_DEATH(minidump_file_writer.WriteEverything(&file_writer), "context_"); | 677 ASSERT_DEATH(minidump_file_writer.WriteEverything(&string_file), "context_"); |
| 678 } | 678 } |
| 679 | 679 |
| 680 TEST(MinidumpThreadWriterDeathTest, InitializeFromSnapshot_NoContext) { | 680 TEST(MinidumpThreadWriterDeathTest, InitializeFromSnapshot_NoContext) { |
| 681 ASSERT_DEATH( | 681 ASSERT_DEATH( |
| 682 RunInitializeFromSnapshotTest<InitializeFromSnapshotNoContextTraits>( | 682 RunInitializeFromSnapshotTest<InitializeFromSnapshotNoContextTraits>( |
| 683 false), "context_"); | 683 false), "context_"); |
| 684 } | 684 } |
| 685 | 685 |
| 686 } // namespace | 686 } // namespace |
| 687 } // namespace test | 687 } // namespace test |
| 688 } // namespace crashpad | 688 } // namespace crashpad |
| OLD | NEW |