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

Side by Side Diff: util/mach/exception_ports_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
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 "util/mach/exception_ports.h" 15 #include "util/mach/exception_ports.h"
16 16
17 #include <mach/mach.h> 17 #include <mach/mach.h>
18 #include <pthread.h> 18 #include <pthread.h>
19 #include <signal.h> 19 #include <signal.h>
20 #include <unistd.h> 20 #include <unistd.h>
21 21
22 #include "base/basictypes.h" 22 #include "base/basictypes.h"
23 #include "base/logging.h" 23 #include "base/logging.h"
24 #include "base/mac/mach_logging.h" 24 #include "base/mac/mach_logging.h"
25 #include "base/mac/scoped_mach_port.h" 25 #include "base/mac/scoped_mach_port.h"
26 #include "base/strings/stringprintf.h" 26 #include "base/strings/stringprintf.h"
27 #include "gtest/gtest.h" 27 #include "gtest/gtest.h"
28 #include "util/file/fd_io.h" 28 #include "util/file/file_io.h"
29 #include "util/mach/exc_server_variants.h" 29 #include "util/mach/exc_server_variants.h"
30 #include "util/mach/mach_extensions.h" 30 #include "util/mach/mach_extensions.h"
31 #include "util/mach/mach_message.h" 31 #include "util/mach/mach_message.h"
32 #include "util/mach/mach_message_server.h" 32 #include "util/mach/mach_message_server.h"
33 #include "util/misc/scoped_forbid_return.h" 33 #include "util/misc/scoped_forbid_return.h"
34 #include "util/synchronization/semaphore.h" 34 #include "util/synchronization/semaphore.h"
35 #include "util/test/mac/mach_errors.h" 35 #include "util/test/mac/mach_errors.h"
36 #include "util/test/mac/mach_multiprocess.h" 36 #include "util/test/mac/mach_multiprocess.h"
37 37
38 namespace crashpad { 38 namespace crashpad {
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 } 235 }
236 236
237 int rv_int = pthread_create(&thread_, nullptr, ThreadMainThunk, this); 237 int rv_int = pthread_create(&thread_, nullptr, ThreadMainThunk, this);
238 ASSERT_EQ(0, rv_int); 238 ASSERT_EQ(0, rv_int);
239 239
240 // Wait for the new thread to be ready. 240 // Wait for the new thread to be ready.
241 init_semaphore_.Wait(); 241 init_semaphore_.Wait();
242 242
243 // Tell the parent process that everything is set up. 243 // Tell the parent process that everything is set up.
244 char c = '\0'; 244 char c = '\0';
245 CheckedWriteFD(test_exception_ports_->WritePipeFD(), &c, 1); 245 CheckedWriteFile(test_exception_ports_->WritePipeFD(), &c, 1);
246 246
247 // Wait for the parent process to say that its end is set up. 247 // Wait for the parent process to say that its end is set up.
248 CheckedReadFD(test_exception_ports_->ReadPipeFD(), &c, 1); 248 CheckedReadFile(test_exception_ports_->ReadPipeFD(), &c, 1);
249 EXPECT_EQ('\0', c); 249 EXPECT_EQ('\0', c);
250 250
251 // Regardless of where ExceptionPorts::SetExceptionPort() ran, 251 // Regardless of where ExceptionPorts::SetExceptionPort() ran,
252 // ExceptionPorts::GetExceptionPorts() can always be tested in-process. 252 // ExceptionPorts::GetExceptionPorts() can always be tested in-process.
253 { 253 {
254 SCOPED_TRACE("task"); 254 SCOPED_TRACE("task");
255 TestGetExceptionPorts(self_task_ports, remote_port, EXCEPTION_DEFAULT); 255 TestGetExceptionPorts(self_task_ports, remote_port, EXCEPTION_DEFAULT);
256 } 256 }
257 257
258 { 258 {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 352
353 DISALLOW_COPY_AND_ASSIGN(Child); 353 DISALLOW_COPY_AND_ASSIGN(Child);
354 }; 354 };
355 355
356 // MachMultiprocess: 356 // MachMultiprocess:
357 357
358 void MachMultiprocessParent() override { 358 void MachMultiprocessParent() override {
359 // Wait for the child process to be ready. It needs to have all of its 359 // Wait for the child process to be ready. It needs to have all of its
360 // threads set up before proceeding if in kSetOutOfProcess mode. 360 // threads set up before proceeding if in kSetOutOfProcess mode.
361 char c; 361 char c;
362 CheckedReadFD(ReadPipeFD(), &c, 1); 362 CheckedReadFile(ReadPipeFD(), &c, 1);
363 EXPECT_EQ('\0', c); 363 EXPECT_EQ('\0', c);
364 364
365 mach_port_t local_port = LocalPort(); 365 mach_port_t local_port = LocalPort();
366 366
367 // Get an ExceptionPorts object for the task and each of its threads. 367 // Get an ExceptionPorts object for the task and each of its threads.
368 ExceptionPorts task_ports(ExceptionPorts::kTargetTypeTask, ChildTask()); 368 ExceptionPorts task_ports(ExceptionPorts::kTargetTypeTask, ChildTask());
369 EXPECT_EQ("task", task_ports.TargetTypeName()); 369 EXPECT_EQ("task", task_ports.TargetTypeName());
370 370
371 // Hopefully the threads returned by task_threads() are in order, with the 371 // Hopefully the threads returned by task_threads() are in order, with the
372 // main thread first and the other thread second. This is currently always 372 // main thread first and the other thread second. This is currently always
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 435
436 { 436 {
437 SCOPED_TRACE("other_thread"); 437 SCOPED_TRACE("other_thread");
438 TestGetExceptionPorts( 438 TestGetExceptionPorts(
439 other_thread_ports, thread_handler, EXCEPTION_STATE_IDENTITY); 439 other_thread_ports, thread_handler, EXCEPTION_STATE_IDENTITY);
440 } 440 }
441 441
442 // Let the child process know that everything in the parent process is set 442 // Let the child process know that everything in the parent process is set
443 // up. 443 // up.
444 c = '\0'; 444 c = '\0';
445 CheckedWriteFD(WritePipeFD(), &c, 1); 445 CheckedWriteFile(WritePipeFD(), &c, 1);
446 446
447 if (who_crashes_ != kNobodyCrashes) { 447 if (who_crashes_ != kNobodyCrashes) {
448 UniversalMachExcServer universal_mach_exc_server(this); 448 UniversalMachExcServer universal_mach_exc_server(this);
449 449
450 kern_return_t kr = 450 kern_return_t kr =
451 MachMessageServer::Run(&universal_mach_exc_server, 451 MachMessageServer::Run(&universal_mach_exc_server,
452 local_port, 452 local_port,
453 MACH_MSG_OPTION_NONE, 453 MACH_MSG_OPTION_NONE,
454 MachMessageServer::kOneShot, 454 MachMessageServer::kOneShot,
455 MachMessageServer::kReceiveLargeError, 455 MachMessageServer::kReceiveLargeError,
456 kMachMessageTimeoutWaitIndefinitely); 456 kMachMessageTimeoutWaitIndefinitely);
457 EXPECT_EQ(KERN_SUCCESS, kr) 457 EXPECT_EQ(KERN_SUCCESS, kr)
458 << MachErrorMessage(kr, "MachMessageServer::Run"); 458 << MachErrorMessage(kr, "MachMessageServer::Run");
459 459
460 EXPECT_TRUE(handled_); 460 EXPECT_TRUE(handled_);
461 } 461 }
462 462
463 // Wait for the child process to exit or terminate, as indicated by it 463 // Wait for the child process to exit or terminate, as indicated by it
464 // closing its pipe. This keeps LocalPort() alive in the child as 464 // closing its pipe. This keeps LocalPort() alive in the child as
465 // RemotePort(), for the child’s use in its TestGetExceptionPorts(). 465 // RemotePort(), for the child’s use in its TestGetExceptionPorts().
466 CheckedReadFDAtEOF(ReadPipeFD()); 466 CheckedReadFileAtEOF(ReadPipeFD());
467 } 467 }
468 468
469 void MachMultiprocessChild() override { 469 void MachMultiprocessChild() override {
470 Child child(this); 470 Child child(this);
471 child.Run(); 471 child.Run();
472 } 472 }
473 473
474 SetType set_type_; 474 SetType set_type_;
475 SetOn set_on_; 475 SetOn set_on_;
476 WhoCrashes who_crashes_; 476 WhoCrashes who_crashes_;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 if (geteuid() == 0) { 574 if (geteuid() == 0) {
575 EXPECT_TRUE(rv); 575 EXPECT_TRUE(rv);
576 } else { 576 } else {
577 EXPECT_FALSE(rv); 577 EXPECT_FALSE(rv);
578 } 578 }
579 } 579 }
580 580
581 } // namespace 581 } // namespace
582 } // namespace test 582 } // namespace test
583 } // namespace crashpad 583 } // namespace crashpad
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698