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

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

Issue 584223002: ExceptionPorts test: accept a port of MACH_PORT_NULL as “no handler.” (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Created 6 years, 3 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
« util/mach/exception_ports.h ('K') | « util/mach/exception_ports.h ('k') | no next file » | 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 26 matching lines...) Expand all
37 37
38 using namespace crashpad; 38 using namespace crashpad;
39 using namespace crashpad::test; 39 using namespace crashpad::test;
40 40
41 // Calls GetExceptionPorts() on its |exception_ports| argument to look up the 41 // Calls GetExceptionPorts() on its |exception_ports| argument to look up the
42 // EXC_MASK_CRASH handler. If |expect_port| is not MACH_PORT_NULL, it expects to 42 // EXC_MASK_CRASH handler. If |expect_port| is not MACH_PORT_NULL, it expects to
43 // find a handler for this mask whose port matches |expect_port| and whose 43 // find a handler for this mask whose port matches |expect_port| and whose
44 // behavior matches |expect_behavior| exactly. In this case, if 44 // behavior matches |expect_behavior| exactly. In this case, if
45 // |expect_behavior| is a state-carrying behavior, the looked-up thread state 45 // |expect_behavior| is a state-carrying behavior, the looked-up thread state
46 // flavor is expected to be MACHINE_THREAD_STATE, otherwise, it is expected to 46 // flavor is expected to be MACHINE_THREAD_STATE, otherwise, it is expected to
47 // be THREAD_STATE_NONE. If |expect_port| is MACH_PORT_NULL, no handler for 47 // be THREAD_STATE_NONE. If |expect_port| is MACH_PORT_NULL, either no handler
48 // EXC_MASK_CRASH is expected to be found. 48 // for EXC_MASK_CRASH is expected to be found, or a handler whose port is
49 // MACH_PORT_NULL is expected, with the behavior and flavor being irrelevant.
49 // 50 //
50 // A second GetExceptionPorts() lookup is also performed on a wider exception 51 // A second GetExceptionPorts() lookup is also performed on a wider exception
51 // mask, EXC_MASK_ALL | EXC_MASK_CRASH. The EXC_MASK_CRASH handler’s existence 52 // mask, EXC_MASK_ALL | EXC_MASK_CRASH. The EXC_MASK_CRASH handler’s existence
52 // and properties from this second lookup are validated in the same way. 53 // and properties from this second lookup are validated in the same way.
53 // 54 //
54 // This function uses gtest EXPECT_* and ASSERT_* macros to perform its 55 // This function uses gtest EXPECT_* and ASSERT_* macros to perform its
55 // validation. 56 // validation.
56 void TestGetExceptionPorts(const ExceptionPorts& exception_ports, 57 void TestGetExceptionPorts(const ExceptionPorts& exception_ports,
57 mach_port_t expect_port, 58 mach_port_t expect_port,
58 exception_behavior_t expect_behavior) { 59 exception_behavior_t expect_behavior) {
59 const exception_mask_t kExceptionMask = EXC_MASK_CRASH; 60 const exception_mask_t kExceptionMask = EXC_MASK_CRASH;
60 61
61 thread_state_flavor_t expect_flavor = (expect_behavior == EXCEPTION_DEFAULT) 62 thread_state_flavor_t expect_flavor = (expect_behavior == EXCEPTION_DEFAULT)
62 ? THREAD_STATE_NONE 63 ? THREAD_STATE_NONE
63 : MACHINE_THREAD_STATE; 64 : MACHINE_THREAD_STATE;
64 65
65 std::vector<ExceptionPorts::ExceptionHandler> crash_handler; 66 std::vector<ExceptionPorts::ExceptionHandler> crash_handler;
66 ASSERT_TRUE( 67 ASSERT_TRUE(
67 exception_ports.GetExceptionPorts(kExceptionMask, &crash_handler)); 68 exception_ports.GetExceptionPorts(kExceptionMask, &crash_handler));
68 69
69 if (expect_port != MACH_PORT_NULL) { 70 if (expect_port != MACH_PORT_NULL || !crash_handler.empty()) {
70 ASSERT_EQ(1u, crash_handler.size()); 71 ASSERT_EQ(1u, crash_handler.size());
71 base::mac::ScopedMachSendRight port_owner(crash_handler[0].port); 72 base::mac::ScopedMachSendRight port_owner(crash_handler[0].port);
72 73
73 EXPECT_EQ(kExceptionMask, crash_handler[0].mask); 74 EXPECT_EQ(kExceptionMask, crash_handler[0].mask);
74 EXPECT_EQ(expect_port, crash_handler[0].port); 75 EXPECT_EQ(expect_port, crash_handler[0].port);
75 EXPECT_EQ(expect_behavior, crash_handler[0].behavior); 76 if (expect_port != MACH_PORT_NULL) {
76 EXPECT_EQ(expect_flavor, crash_handler[0].flavor); 77 EXPECT_EQ(expect_behavior, crash_handler[0].behavior);
77 } else { 78 EXPECT_EQ(expect_flavor, crash_handler[0].flavor);
78 EXPECT_TRUE(crash_handler.empty()); 79 }
79 } 80 }
80 81
81 std::vector<ExceptionPorts::ExceptionHandler> handlers; 82 std::vector<ExceptionPorts::ExceptionHandler> handlers;
82 ASSERT_TRUE(exception_ports.GetExceptionPorts( 83 ASSERT_TRUE(exception_ports.GetExceptionPorts(
83 ExcMaskAll() | EXC_MASK_CRASH, &handlers)); 84 ExcMaskAll() | EXC_MASK_CRASH, &handlers));
84 85
85 EXPECT_GE(handlers.size(), crash_handler.size()); 86 EXPECT_GE(handlers.size(), crash_handler.size());
86 bool found = false; 87 bool found = false;
87 for (const ExceptionPorts::ExceptionHandler& handler : handlers) { 88 for (const ExceptionPorts::ExceptionHandler& handler : handlers) {
88 if ((handler.mask & kExceptionMask) != 0) { 89 if ((handler.mask & kExceptionMask) != 0) {
89 base::mac::ScopedMachSendRight port_owner(handler.port); 90 base::mac::ScopedMachSendRight port_owner(handler.port);
90 91
91 EXPECT_FALSE(found); 92 if (handler.port != MACH_PORT_NULL) {
92 found = true; 93 EXPECT_FALSE(found);
94 found = true;
95 }
96
93 EXPECT_EQ(expect_port, handler.port); 97 EXPECT_EQ(expect_port, handler.port);
94 EXPECT_EQ(expect_behavior, handler.behavior); 98 if (expect_port != MACH_PORT_NULL) {
95 EXPECT_EQ(expect_flavor, handler.flavor); 99 EXPECT_EQ(expect_behavior, handler.behavior);
100 EXPECT_EQ(expect_flavor, handler.flavor);
101 }
96 } 102 }
97 } 103 }
98 104
99 if (expect_port != MACH_PORT_NULL) { 105 if (expect_port != MACH_PORT_NULL) {
100 EXPECT_TRUE(found); 106 EXPECT_TRUE(found);
101 } else { 107 } else {
102 EXPECT_FALSE(found); 108 EXPECT_FALSE(found);
103 } 109 }
104 } 110 }
105 111
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 rv = implicit_host_ports.GetExceptionPorts( 580 rv = implicit_host_ports.GetExceptionPorts(
575 ExcMaskAll() | EXC_MASK_CRASH, &handlers); 581 ExcMaskAll() | EXC_MASK_CRASH, &handlers);
576 if (geteuid() == 0) { 582 if (geteuid() == 0) {
577 EXPECT_TRUE(rv); 583 EXPECT_TRUE(rv);
578 } else { 584 } else {
579 EXPECT_FALSE(rv); 585 EXPECT_FALSE(rv);
580 } 586 }
581 } 587 }
582 588
583 } // namespace 589 } // namespace
OLDNEW
« util/mach/exception_ports.h ('K') | « util/mach/exception_ports.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698