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

Side by Side Diff: minidump/minidump_thread_writer_test.cc

Issue 656703002: Convert NULL to nullptr (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Fix 80-column violations 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
« no previous file with comments | « minidump/minidump_thread_writer.cc ('k') | snapshot/cpu_context_mac.h » ('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,
(...skipping 12 matching lines...) Expand all
23 #include "minidump/minidump_memory_writer_test_util.h" 23 #include "minidump/minidump_memory_writer_test_util.h"
24 #include "minidump/minidump_file_writer.h" 24 #include "minidump/minidump_file_writer.h"
25 #include "minidump/minidump_file_writer_test_util.h" 25 #include "minidump/minidump_file_writer_test_util.h"
26 #include "util/file/string_file_writer.h" 26 #include "util/file/string_file_writer.h"
27 27
28 namespace crashpad { 28 namespace crashpad {
29 namespace test { 29 namespace test {
30 namespace { 30 namespace {
31 31
32 // This returns the MINIDUMP_THREAD_LIST stream in |thread_list|. If 32 // This returns the MINIDUMP_THREAD_LIST stream in |thread_list|. If
33 // |memory_list| is non-NULL, a MINIDUMP_MEMORY_LIST stream is also expected in 33 // |memory_list| is not nullptr, a MINIDUMP_MEMORY_LIST stream is also expected
34 // |file_contents|, and that stream will be returned in |memory_list|. 34 // in |file_contents|, and that stream will be returned in |memory_list|.
35 void GetThreadListStream(const std::string& file_contents, 35 void GetThreadListStream(const std::string& file_contents,
36 const MINIDUMP_THREAD_LIST** thread_list, 36 const MINIDUMP_THREAD_LIST** thread_list,
37 const MINIDUMP_MEMORY_LIST** memory_list) { 37 const MINIDUMP_MEMORY_LIST** memory_list) {
38 const size_t kDirectoryOffset = sizeof(MINIDUMP_HEADER); 38 const size_t kDirectoryOffset = sizeof(MINIDUMP_HEADER);
39 const uint32_t kExpectedStreams = memory_list ? 2 : 1; 39 const uint32_t kExpectedStreams = memory_list ? 2 : 1;
40 const size_t kThreadListStreamOffset = 40 const size_t kThreadListStreamOffset =
41 kDirectoryOffset + kExpectedStreams * sizeof(MINIDUMP_DIRECTORY); 41 kDirectoryOffset + kExpectedStreams * sizeof(MINIDUMP_DIRECTORY);
42 const size_t kThreadsOffset = 42 const size_t kThreadsOffset =
43 kThreadListStreamOffset + sizeof(MINIDUMP_THREAD_LIST); 43 kThreadListStreamOffset + sizeof(MINIDUMP_THREAD_LIST);
44 44
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 78
79 StringFileWriter file_writer; 79 StringFileWriter file_writer;
80 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); 80 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
81 81
82 ASSERT_EQ(sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) + 82 ASSERT_EQ(sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) +
83 sizeof(MINIDUMP_THREAD_LIST), 83 sizeof(MINIDUMP_THREAD_LIST),
84 file_writer.string().size()); 84 file_writer.string().size());
85 85
86 const MINIDUMP_THREAD_LIST* thread_list; 86 const MINIDUMP_THREAD_LIST* thread_list;
87 ASSERT_NO_FATAL_FAILURE( 87 ASSERT_NO_FATAL_FAILURE(
88 GetThreadListStream(file_writer.string(), &thread_list, NULL)); 88 GetThreadListStream(file_writer.string(), &thread_list, nullptr));
89 89
90 EXPECT_EQ(0u, thread_list->NumberOfThreads); 90 EXPECT_EQ(0u, thread_list->NumberOfThreads);
91 } 91 }
92 92
93 // The MINIDUMP_THREADs |expected| and |observed| are compared against each 93 // The MINIDUMP_THREADs |expected| and |observed| are compared against each
94 // other using gtest assertions. If |stack| is non-NULL, |observed| is expected 94 // other using gtest assertions. If |stack| is not nullptr, |observed| is
95 // to contain a populated MINIDUMP_MEMORY_DESCRIPTOR in its Stack field, 95 // expected to contain a populated MINIDUMP_MEMORY_DESCRIPTOR in its Stack
96 // otherwise, its Stack field is expected to be zeroed out. The memory 96 // field, otherwise, its Stack field is expected to be zeroed out. The memory
97 // descriptor will be placed in |stack|. |observed| must contain a populated 97 // descriptor will be placed in |stack|. |observed| must contain a populated
98 // ThreadContext field. The context will be recovered from |file_contents| and 98 // ThreadContext field. The context will be recovered from |file_contents| and
99 // stored in |context_base|. 99 // stored in |context_base|.
100 void ExpectThread(const MINIDUMP_THREAD* expected, 100 void ExpectThread(const MINIDUMP_THREAD* expected,
101 const MINIDUMP_THREAD* observed, 101 const MINIDUMP_THREAD* observed,
102 const std::string& file_contents, 102 const std::string& file_contents,
103 const MINIDUMP_MEMORY_DESCRIPTOR** stack, 103 const MINIDUMP_MEMORY_DESCRIPTOR** stack,
104 const void** context_base) { 104 const void** context_base) {
105 EXPECT_EQ(expected->ThreadId, observed->ThreadId); 105 EXPECT_EQ(expected->ThreadId, observed->ThreadId);
106 EXPECT_EQ(expected->SuspendCount, observed->SuspendCount); 106 EXPECT_EQ(expected->SuspendCount, observed->SuspendCount);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 StringFileWriter file_writer; 159 StringFileWriter file_writer;
160 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); 160 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
161 161
162 ASSERT_EQ(sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) + 162 ASSERT_EQ(sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) +
163 sizeof(MINIDUMP_THREAD_LIST) + 1 * sizeof(MINIDUMP_THREAD) + 163 sizeof(MINIDUMP_THREAD_LIST) + 1 * sizeof(MINIDUMP_THREAD) +
164 1 * sizeof(MinidumpContextX86), 164 1 * sizeof(MinidumpContextX86),
165 file_writer.string().size()); 165 file_writer.string().size());
166 166
167 const MINIDUMP_THREAD_LIST* thread_list; 167 const MINIDUMP_THREAD_LIST* thread_list;
168 ASSERT_NO_FATAL_FAILURE( 168 ASSERT_NO_FATAL_FAILURE(
169 GetThreadListStream(file_writer.string(), &thread_list, NULL)); 169 GetThreadListStream(file_writer.string(), &thread_list, nullptr));
170 170
171 EXPECT_EQ(1u, thread_list->NumberOfThreads); 171 EXPECT_EQ(1u, thread_list->NumberOfThreads);
172 172
173 MINIDUMP_THREAD expected = {}; 173 MINIDUMP_THREAD expected = {};
174 expected.ThreadId = kThreadID; 174 expected.ThreadId = kThreadID;
175 expected.SuspendCount = kSuspendCount; 175 expected.SuspendCount = kSuspendCount;
176 expected.PriorityClass = kPriorityClass; 176 expected.PriorityClass = kPriorityClass;
177 expected.Priority = kPriority; 177 expected.Priority = kPriority;
178 expected.Teb = kTEB; 178 expected.Teb = kTEB;
179 expected.ThreadContext.DataSize = sizeof(MinidumpContextX86); 179 expected.ThreadContext.DataSize = sizeof(MinidumpContextX86);
180 180
181 const MinidumpContextX86* observed_context; 181 const MinidumpContextX86* observed_context;
182 ASSERT_NO_FATAL_FAILURE( 182 ASSERT_NO_FATAL_FAILURE(
183 ExpectThread(&expected, 183 ExpectThread(&expected,
184 &thread_list->Threads[0], 184 &thread_list->Threads[0],
185 file_writer.string(), 185 file_writer.string(),
186 NULL, 186 nullptr,
187 reinterpret_cast<const void**>(&observed_context))); 187 reinterpret_cast<const void**>(&observed_context)));
188 188
189 ASSERT_NO_FATAL_FAILURE(ExpectMinidumpContextX86(kSeed, observed_context)); 189 ASSERT_NO_FATAL_FAILURE(ExpectMinidumpContextX86(kSeed, observed_context));
190 } 190 }
191 191
192 TEST(MinidumpThreadWriter, OneThread_AMD64_Stack) { 192 TEST(MinidumpThreadWriter, OneThread_AMD64_Stack) {
193 MinidumpFileWriter minidump_file_writer; 193 MinidumpFileWriter minidump_file_writer;
194 MinidumpThreadListWriter thread_list_writer; 194 MinidumpThreadListWriter thread_list_writer;
195 195
196 const uint32_t kThreadID = 0x22222222; 196 const uint32_t kThreadID = 0x22222222;
(...skipping 27 matching lines...) Expand all
224 StringFileWriter file_writer; 224 StringFileWriter file_writer;
225 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer)); 225 ASSERT_TRUE(minidump_file_writer.WriteEverything(&file_writer));
226 226
227 ASSERT_EQ(sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) + 227 ASSERT_EQ(sizeof(MINIDUMP_HEADER) + sizeof(MINIDUMP_DIRECTORY) +
228 sizeof(MINIDUMP_THREAD_LIST) + 1 * sizeof(MINIDUMP_THREAD) + 228 sizeof(MINIDUMP_THREAD_LIST) + 1 * sizeof(MINIDUMP_THREAD) +
229 1 * sizeof(MinidumpContextAMD64) + kMemorySize, 229 1 * sizeof(MinidumpContextAMD64) + kMemorySize,
230 file_writer.string().size()); 230 file_writer.string().size());
231 231
232 const MINIDUMP_THREAD_LIST* thread_list; 232 const MINIDUMP_THREAD_LIST* thread_list;
233 ASSERT_NO_FATAL_FAILURE( 233 ASSERT_NO_FATAL_FAILURE(
234 GetThreadListStream(file_writer.string(), &thread_list, NULL)); 234 GetThreadListStream(file_writer.string(), &thread_list, nullptr));
235 235
236 EXPECT_EQ(1u, thread_list->NumberOfThreads); 236 EXPECT_EQ(1u, thread_list->NumberOfThreads);
237 237
238 MINIDUMP_THREAD expected = {}; 238 MINIDUMP_THREAD expected = {};
239 expected.ThreadId = kThreadID; 239 expected.ThreadId = kThreadID;
240 expected.SuspendCount = kSuspendCount; 240 expected.SuspendCount = kSuspendCount;
241 expected.PriorityClass = kPriorityClass; 241 expected.PriorityClass = kPriorityClass;
242 expected.Priority = kPriority; 242 expected.Priority = kPriority;
243 expected.Teb = kTEB; 243 expected.Teb = kTEB;
244 expected.Stack.StartOfMemoryRange = kMemoryBase; 244 expected.Stack.StartOfMemoryRange = kMemoryBase;
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 thread_list_writer.AddThread(&thread_writer); 481 thread_list_writer.AddThread(&thread_writer);
482 minidump_file_writer.AddStream(&thread_list_writer); 482 minidump_file_writer.AddStream(&thread_list_writer);
483 483
484 StringFileWriter file_writer; 484 StringFileWriter file_writer;
485 ASSERT_DEATH(minidump_file_writer.WriteEverything(&file_writer), "context_"); 485 ASSERT_DEATH(minidump_file_writer.WriteEverything(&file_writer), "context_");
486 } 486 }
487 487
488 } // namespace 488 } // namespace
489 } // namespace test 489 } // namespace test
490 } // namespace crashpad 490 } // namespace crashpad
OLDNEW
« no previous file with comments | « minidump/minidump_thread_writer.cc ('k') | snapshot/cpu_context_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698