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

Side by Side Diff: util/mach/exception_ports_test.cc

Issue 1405273002: Mach port scopers should use get() instead of type conversion operators (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: More is_valid() Created 5 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 | « util/mach/child_port_handshake.cc ('k') | util/mach/mach_extensions_test.cc » ('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 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 kern_return_t kr = task_threads(ChildTask(), &threads, &thread_count); 369 kern_return_t kr = task_threads(ChildTask(), &threads, &thread_count);
370 ASSERT_EQ(KERN_SUCCESS, kr) << MachErrorMessage(kr, "task_threads"); 370 ASSERT_EQ(KERN_SUCCESS, kr) << MachErrorMessage(kr, "task_threads");
371 371
372 ScopedForbidReturn threads_need_owners; 372 ScopedForbidReturn threads_need_owners;
373 ASSERT_EQ(2u, thread_count); 373 ASSERT_EQ(2u, thread_count);
374 base::mac::ScopedMachSendRight main_thread(threads[0]); 374 base::mac::ScopedMachSendRight main_thread(threads[0]);
375 base::mac::ScopedMachSendRight other_thread(threads[1]); 375 base::mac::ScopedMachSendRight other_thread(threads[1]);
376 threads_need_owners.Disarm(); 376 threads_need_owners.Disarm();
377 377
378 ExceptionPorts main_thread_ports(ExceptionPorts::kTargetTypeThread, 378 ExceptionPorts main_thread_ports(ExceptionPorts::kTargetTypeThread,
379 main_thread); 379 main_thread.get());
380 ExceptionPorts other_thread_ports(ExceptionPorts::kTargetTypeThread, 380 ExceptionPorts other_thread_ports(ExceptionPorts::kTargetTypeThread,
381 other_thread); 381 other_thread.get());
382 EXPECT_STREQ("thread", main_thread_ports.TargetTypeName()); 382 EXPECT_STREQ("thread", main_thread_ports.TargetTypeName());
383 EXPECT_STREQ("thread", other_thread_ports.TargetTypeName()); 383 EXPECT_STREQ("thread", other_thread_ports.TargetTypeName());
384 384
385 if (set_type_ == kSetOutOfProcess) { 385 if (set_type_ == kSetOutOfProcess) {
386 // Test ExceptionPorts::SetExceptionPorts() being called from 386 // Test ExceptionPorts::SetExceptionPorts() being called from
387 // out-of-process. 387 // out-of-process.
388 // 388 //
389 // local_port is only a receive right, but a send right is needed for 389 // local_port is only a receive right, but a send right is needed for
390 // ExceptionPorts::SetExceptionPort(). Make a send right, which can be 390 // ExceptionPorts::SetExceptionPort(). Make a send right, which can be
391 // deallocated once the calls to ExceptionPorts::SetExceptionPort() are 391 // deallocated once the calls to ExceptionPorts::SetExceptionPort() are
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 // make sure that TargetTypeName() returns the right string, and that the 579 // make sure that TargetTypeName() returns the right string, and that the
580 // underlying host_get_exception_ports() function appears to be called by 580 // underlying host_get_exception_ports() function appears to be called by
581 // looking for a KERN_INVALID_ARGUMENT return value. Or, on the off chance 581 // looking for a KERN_INVALID_ARGUMENT return value. Or, on the off chance
582 // that the test is being run as root, just look for KERN_SUCCESS. 582 // that the test is being run as root, just look for KERN_SUCCESS.
583 // host_set_exception_ports() is not tested, because if the test were running 583 // host_set_exception_ports() is not tested, because if the test were running
584 // as root and the call succeeded, it would have global effects. 584 // as root and the call succeeded, it would have global effects.
585 585
586 const bool expect_success = geteuid() == 0; 586 const bool expect_success = geteuid() == 0;
587 587
588 base::mac::ScopedMachSendRight host(mach_host_self()); 588 base::mac::ScopedMachSendRight host(mach_host_self());
589 ExceptionPorts explicit_host_ports(ExceptionPorts::kTargetTypeHost, host); 589 ExceptionPorts explicit_host_ports(ExceptionPorts::kTargetTypeHost,
590 host.get());
590 EXPECT_STREQ("host", explicit_host_ports.TargetTypeName()); 591 EXPECT_STREQ("host", explicit_host_ports.TargetTypeName());
591 592
592 ExceptionPorts::ExceptionHandlerVector explicit_handlers; 593 ExceptionPorts::ExceptionHandlerVector explicit_handlers;
593 bool rv = 594 bool rv =
594 explicit_host_ports.GetExceptionPorts(ExcMaskValid(), &explicit_handlers); 595 explicit_host_ports.GetExceptionPorts(ExcMaskValid(), &explicit_handlers);
595 EXPECT_EQ(expect_success, rv); 596 EXPECT_EQ(expect_success, rv);
596 597
597 ExceptionPorts implicit_host_ports(ExceptionPorts::kTargetTypeHost, 598 ExceptionPorts implicit_host_ports(ExceptionPorts::kTargetTypeHost,
598 HOST_NULL); 599 HOST_NULL);
599 EXPECT_STREQ("host", implicit_host_ports.TargetTypeName()); 600 EXPECT_STREQ("host", implicit_host_ports.TargetTypeName());
600 601
601 ExceptionPorts::ExceptionHandlerVector implicit_handlers; 602 ExceptionPorts::ExceptionHandlerVector implicit_handlers;
602 rv = 603 rv =
603 implicit_host_ports.GetExceptionPorts(ExcMaskValid(), &implicit_handlers); 604 implicit_host_ports.GetExceptionPorts(ExcMaskValid(), &implicit_handlers);
604 EXPECT_EQ(expect_success, rv); 605 EXPECT_EQ(expect_success, rv);
605 606
606 EXPECT_EQ(explicit_handlers.size(), implicit_handlers.size()); 607 EXPECT_EQ(explicit_handlers.size(), implicit_handlers.size());
607 } 608 }
608 609
609 } // namespace 610 } // namespace
610 } // namespace test 611 } // namespace test
611 } // namespace crashpad 612 } // namespace crashpad
OLDNEW
« no previous file with comments | « util/mach/child_port_handshake.cc ('k') | util/mach/mach_extensions_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698