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

Side by Side Diff: minidump/minidump_thread_writer_test.cc

Issue 670853002: minidump: Migrate the rest of the tests to MinidumpWritableAtLocationDescriptor<>() (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Created 6 years, 2 months 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
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_thread_writer.h" 15 #include "minidump/minidump_thread_writer.h"
16 16
17 #include <dbghelp.h> 17 #include <dbghelp.h>
18 18
19 #include "gtest/gtest.h" 19 #include "gtest/gtest.h"
20 #include "minidump/minidump_context_writer.h" 20 #include "minidump/minidump_context_writer.h"
21 #include "minidump/minidump_memory_writer.h" 21 #include "minidump/minidump_memory_writer.h"
22 #include "minidump/minidump_file_writer.h" 22 #include "minidump/minidump_file_writer.h"
23 #include "minidump/test/minidump_context_test_util.h" 23 #include "minidump/test/minidump_context_test_util.h"
24 #include "minidump/test/minidump_memory_writer_test_util.h" 24 #include "minidump/test/minidump_memory_writer_test_util.h"
25 #include "minidump/test/minidump_file_writer_test_util.h" 25 #include "minidump/test/minidump_file_writer_test_util.h"
26 #include "minidump/test/minidump_writable_test_util.h"
26 #include "util/file/string_file_writer.h" 27 #include "util/file/string_file_writer.h"
27 28
28 namespace crashpad { 29 namespace crashpad {
29 namespace test { 30 namespace test {
30 namespace { 31 namespace {
31 32
32 // This returns the MINIDUMP_THREAD_LIST stream in |thread_list|. If 33 // This returns the MINIDUMP_THREAD_LIST stream in |thread_list|. If
33 // |memory_list| is not nullptr, a MINIDUMP_MEMORY_LIST stream is also expected 34 // |memory_list| is not nullptr, a MINIDUMP_MEMORY_LIST stream is also expected
34 // in |file_contents|, and that stream will be returned in |memory_list|. 35 // in |file_contents|, and that stream will be returned in |memory_list|.
35 void GetThreadListStream(const std::string& file_contents, 36 void GetThreadListStream(const std::string& file_contents,
36 const MINIDUMP_THREAD_LIST** thread_list, 37 const MINIDUMP_THREAD_LIST** thread_list,
37 const MINIDUMP_MEMORY_LIST** memory_list) { 38 const MINIDUMP_MEMORY_LIST** memory_list) {
38 const size_t kDirectoryOffset = sizeof(MINIDUMP_HEADER); 39 const size_t kDirectoryOffset = sizeof(MINIDUMP_HEADER);
39 const uint32_t kExpectedStreams = memory_list ? 2 : 1; 40 const uint32_t kExpectedStreams = memory_list ? 2 : 1;
40 const size_t kThreadListStreamOffset = 41 const size_t kThreadListStreamOffset =
41 kDirectoryOffset + kExpectedStreams * sizeof(MINIDUMP_DIRECTORY); 42 kDirectoryOffset + kExpectedStreams * sizeof(MINIDUMP_DIRECTORY);
42 const size_t kThreadsOffset = 43 const size_t kThreadsOffset =
43 kThreadListStreamOffset + sizeof(MINIDUMP_THREAD_LIST); 44 kThreadListStreamOffset + sizeof(MINIDUMP_THREAD_LIST);
44 45
45 ASSERT_GE(file_contents.size(), kThreadsOffset); 46 ASSERT_GE(file_contents.size(), kThreadsOffset);
46 47
47 const MINIDUMP_DIRECTORY* directory; 48 const MINIDUMP_DIRECTORY* directory;
48 const MINIDUMP_HEADER* header = 49 const MINIDUMP_HEADER* header =
49 MinidumpHeaderAtStart(file_contents, &directory); 50 MinidumpHeaderAtStart(file_contents, &directory);
50 ASSERT_NO_FATAL_FAILURE(VerifyMinidumpHeader(header, kExpectedStreams, 0)); 51 ASSERT_NO_FATAL_FAILURE(VerifyMinidumpHeader(header, kExpectedStreams, 0));
51 ASSERT_TRUE(directory); 52 ASSERT_TRUE(directory);
52 53
53 ASSERT_EQ(kMinidumpStreamTypeThreadList, directory[0].StreamType); 54 ASSERT_EQ(kMinidumpStreamTypeThreadList, directory[0].StreamType);
54 ASSERT_GE(directory[0].Location.DataSize, sizeof(MINIDUMP_THREAD_LIST)); 55 EXPECT_EQ(kThreadListStreamOffset, directory[0].Location.Rva);
55 ASSERT_EQ(kThreadListStreamOffset, directory[0].Location.Rva);
56 56
57 *thread_list = reinterpret_cast<const MINIDUMP_THREAD_LIST*>( 57 *thread_list = MinidumpWritableAtLocationDescriptor<MINIDUMP_THREAD_LIST>(
58 &file_contents[kThreadListStreamOffset]); 58 file_contents, directory[0].Location);
59 59 ASSERT_TRUE(thread_list);
60 ASSERT_EQ(sizeof(MINIDUMP_THREAD_LIST) +
61 (*thread_list)->NumberOfThreads * sizeof(MINIDUMP_THREAD),
62 directory[0].Location.DataSize);
63 60
64 if (memory_list) { 61 if (memory_list) {
65 *memory_list = reinterpret_cast<const MINIDUMP_MEMORY_LIST*>( 62 ASSERT_EQ(kMinidumpStreamTypeMemoryList, directory[1].StreamType);
66 &file_contents[directory[1].Location.Rva]); 63
64 *memory_list = MinidumpWritableAtLocationDescriptor<MINIDUMP_MEMORY_LIST>(
65 file_contents, directory[1].Location);
66 ASSERT_TRUE(*memory_list);
67 } 67 }
68 } 68 }
69 69
70 TEST(MinidumpThreadWriter, EmptyThreadList) { 70 TEST(MinidumpThreadWriter, EmptyThreadList) {
71 MinidumpFileWriter minidump_file_writer; 71 MinidumpFileWriter minidump_file_writer;
72 MinidumpThreadListWriter thread_list_writer; 72 MinidumpThreadListWriter thread_list_writer;
73 73
74 minidump_file_writer.AddStream(&thread_list_writer); 74 minidump_file_writer.AddStream(&thread_list_writer);
75 75
76 StringFileWriter file_writer; 76 StringFileWriter file_writer;
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 thread_list_writer.AddThread(&thread_writer); 478 thread_list_writer.AddThread(&thread_writer);
479 minidump_file_writer.AddStream(&thread_list_writer); 479 minidump_file_writer.AddStream(&thread_list_writer);
480 480
481 StringFileWriter file_writer; 481 StringFileWriter file_writer;
482 ASSERT_DEATH(minidump_file_writer.WriteEverything(&file_writer), "context_"); 482 ASSERT_DEATH(minidump_file_writer.WriteEverything(&file_writer), "context_");
483 } 483 }
484 484
485 } // namespace 485 } // namespace
486 } // namespace test 486 } // namespace test
487 } // namespace crashpad 487 } // namespace crashpad
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698