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

Side by Side Diff: snapshot/mac/mach_o_image_annotations_reader_test.cc

Issue 811823003: Cross platform low level file IO wrappers (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: . Created 6 years 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 | « no previous file | snapshot/mac/process_reader_test.cc » ('j') | util/file/file_io.h » ('J')
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 23
24 #include <map> 24 #include <map>
25 #include <string> 25 #include <string>
26 #include <vector> 26 #include <vector>
27 27
28 #include "base/basictypes.h" 28 #include "base/basictypes.h"
29 #include "client/crashpad_info.h" 29 #include "client/crashpad_info.h"
30 #include "client/simple_string_dictionary.h" 30 #include "client/simple_string_dictionary.h"
31 #include "gtest/gtest.h" 31 #include "gtest/gtest.h"
32 #include "snapshot/mac/process_reader.h" 32 #include "snapshot/mac/process_reader.h"
33 #include "util/file/fd_io.h" 33 #include "util/file/file_io.h"
34 #include "util/mac/mac_util.h" 34 #include "util/mac/mac_util.h"
35 #include "util/mach/exc_server_variants.h" 35 #include "util/mach/exc_server_variants.h"
36 #include "util/mach/exception_ports.h" 36 #include "util/mach/exception_ports.h"
37 #include "util/mach/mach_message.h" 37 #include "util/mach/mach_message.h"
38 #include "util/mach/mach_message_server.h" 38 #include "util/mach/mach_message_server.h"
39 #include "util/test/errors.h" 39 #include "util/test/errors.h"
40 #include "util/test/mac/mach_errors.h" 40 #include "util/test/mac/mach_errors.h"
41 #include "util/test/mac/mach_multiprocess.h" 41 #include "util/test/mac/mach_multiprocess.h"
42 42
43 namespace crashpad { 43 namespace crashpad {
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 private: 186 private:
187 // MachMultiprocess: 187 // MachMultiprocess:
188 188
189 void MachMultiprocessParent() override { 189 void MachMultiprocessParent() override {
190 ProcessReader process_reader; 190 ProcessReader process_reader;
191 ASSERT_TRUE(process_reader.Initialize(ChildTask())); 191 ASSERT_TRUE(process_reader.Initialize(ChildTask()));
192 192
193 // Wait for the child process to indicate that it’s done setting up its 193 // Wait for the child process to indicate that it’s done setting up its
194 // annotations via the CrashpadInfo interface. 194 // annotations via the CrashpadInfo interface.
195 char c; 195 char c;
196 CheckedReadFD(ReadPipeFD(), &c, sizeof(c)); 196 CheckedReadFile(ReadPipeFD(), &c, sizeof(c));
197 197
198 // Verify the “simple map” annotations set via the CrashpadInfo interface. 198 // Verify the “simple map” annotations set via the CrashpadInfo interface.
199 const std::vector<ProcessReader::Module>& modules = 199 const std::vector<ProcessReader::Module>& modules =
200 process_reader.Modules(); 200 process_reader.Modules();
201 std::map<std::string, std::string> all_annotations_simple_map; 201 std::map<std::string, std::string> all_annotations_simple_map;
202 for (const ProcessReader::Module& module : modules) { 202 for (const ProcessReader::Module& module : modules) {
203 MachOImageAnnotationsReader module_annotations_reader( 203 MachOImageAnnotationsReader module_annotations_reader(
204 &process_reader, module.reader, module.name); 204 &process_reader, module.reader, module.name);
205 std::map<std::string, std::string> module_annotations_simple_map = 205 std::map<std::string, std::string> module_annotations_simple_map =
206 module_annotations_reader.SimpleMap(); 206 module_annotations_reader.SimpleMap();
207 all_annotations_simple_map.insert(module_annotations_simple_map.begin(), 207 all_annotations_simple_map.insert(module_annotations_simple_map.begin(),
208 module_annotations_simple_map.end()); 208 module_annotations_simple_map.end());
209 } 209 }
210 210
211 EXPECT_GE(all_annotations_simple_map.size(), 5u); 211 EXPECT_GE(all_annotations_simple_map.size(), 5u);
212 EXPECT_EQ("crash", all_annotations_simple_map["#TEST# pad"]); 212 EXPECT_EQ("crash", all_annotations_simple_map["#TEST# pad"]);
213 EXPECT_EQ("value", all_annotations_simple_map["#TEST# key"]); 213 EXPECT_EQ("value", all_annotations_simple_map["#TEST# key"]);
214 EXPECT_EQ("y", all_annotations_simple_map["#TEST# x"]); 214 EXPECT_EQ("y", all_annotations_simple_map["#TEST# x"]);
215 EXPECT_EQ("shorter", all_annotations_simple_map["#TEST# longer"]); 215 EXPECT_EQ("shorter", all_annotations_simple_map["#TEST# longer"]);
216 EXPECT_EQ("", all_annotations_simple_map["#TEST# empty_value"]); 216 EXPECT_EQ("", all_annotations_simple_map["#TEST# empty_value"]);
217 217
218 // Tell the child process that it’s permitted to crash. 218 // Tell the child process that it’s permitted to crash.
219 CheckedWriteFD(WritePipeFD(), &c, sizeof(c)); 219 CheckedWriteFile(WritePipeFD(), &c, sizeof(c));
220 220
221 if (test_type_ != kDontCrash) { 221 if (test_type_ != kDontCrash) {
222 // Handle the child’s crash. Further validation will be done in 222 // Handle the child’s crash. Further validation will be done in
223 // CatchMachException(). 223 // CatchMachException().
224 UniversalMachExcServer universal_mach_exc_server(this); 224 UniversalMachExcServer universal_mach_exc_server(this);
225 225
226 mach_msg_return_t mr = 226 mach_msg_return_t mr =
227 MachMessageServer::Run(&universal_mach_exc_server, 227 MachMessageServer::Run(&universal_mach_exc_server,
228 LocalPort(), 228 LocalPort(),
229 MACH_MSG_OPTION_NONE, 229 MACH_MSG_OPTION_NONE,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 simple_annotations->SetKeyValue("#TEST# key", "value"); 261 simple_annotations->SetKeyValue("#TEST# key", "value");
262 simple_annotations->SetKeyValue("#TEST# pad", "crash"); 262 simple_annotations->SetKeyValue("#TEST# pad", "crash");
263 simple_annotations->SetKeyValue("#TEST# x", "y"); 263 simple_annotations->SetKeyValue("#TEST# x", "y");
264 simple_annotations->SetKeyValue("#TEST# longer", "shorter"); 264 simple_annotations->SetKeyValue("#TEST# longer", "shorter");
265 simple_annotations->SetKeyValue("#TEST# empty_value", ""); 265 simple_annotations->SetKeyValue("#TEST# empty_value", "");
266 266
267 crashpad_info->set_simple_annotations(simple_annotations); 267 crashpad_info->set_simple_annotations(simple_annotations);
268 268
269 // Tell the parent that the environment has been set up. 269 // Tell the parent that the environment has been set up.
270 char c = '\0'; 270 char c = '\0';
271 CheckedWriteFD(WritePipeFD(), &c, sizeof(c)); 271 CheckedWriteFile(WritePipeFD(), &c, sizeof(c));
272 272
273 // Wait for the parent to indicate that it’s safe to crash. 273 // Wait for the parent to indicate that it’s safe to crash.
274 CheckedReadFD(ReadPipeFD(), &c, sizeof(c)); 274 CheckedReadFile(ReadPipeFD(), &c, sizeof(c));
275 275
276 // Direct an exception message to the exception server running in the 276 // Direct an exception message to the exception server running in the
277 // parent. 277 // parent.
278 ExceptionPorts exception_ports(ExceptionPorts::kTargetTypeTask, 278 ExceptionPorts exception_ports(ExceptionPorts::kTargetTypeTask,
279 mach_task_self()); 279 mach_task_self());
280 ASSERT_TRUE(exception_ports.SetExceptionPort( 280 ASSERT_TRUE(exception_ports.SetExceptionPort(
281 EXC_MASK_CRASH, RemotePort(), EXCEPTION_DEFAULT, THREAD_STATE_NONE)); 281 EXC_MASK_CRASH, RemotePort(), EXCEPTION_DEFAULT, THREAD_STATE_NONE));
282 282
283 switch (test_type_) { 283 switch (test_type_) {
284 case kDontCrash: 284 case kDontCrash:
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 330
331 TEST(MachOImageAnnotationsReader, CrashDyld) { 331 TEST(MachOImageAnnotationsReader, CrashDyld) {
332 TestMachOImageAnnotationsReader test_mach_o_image_annotations_reader( 332 TestMachOImageAnnotationsReader test_mach_o_image_annotations_reader(
333 TestMachOImageAnnotationsReader::kCrashDyld); 333 TestMachOImageAnnotationsReader::kCrashDyld);
334 test_mach_o_image_annotations_reader.Run(); 334 test_mach_o_image_annotations_reader.Run();
335 } 335 }
336 336
337 } // namespace 337 } // namespace
338 } // namespace test 338 } // namespace test
339 } // namespace crashpad 339 } // namespace crashpad
OLDNEW
« no previous file with comments | « no previous file | snapshot/mac/process_reader_test.cc » ('j') | util/file/file_io.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698