OLD | NEW |
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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 return context->uts.ts64.__rsp; | 88 return context->uts.ts64.__rsp; |
89 #endif | 89 #endif |
90 } | 90 } |
91 | 91 |
92 void TestCaptureContext() { | 92 void TestCaptureContext() { |
93 NativeCPUContext context_1; | 93 NativeCPUContext context_1; |
94 CaptureContext(&context_1); | 94 CaptureContext(&context_1); |
95 | 95 |
96 { | 96 { |
97 SCOPED_TRACE("context_1"); | 97 SCOPED_TRACE("context_1"); |
98 SanityCheckContext(&context_1); | 98 ASSERT_NO_FATAL_FAILURE(SanityCheckContext(&context_1)); |
99 } | |
100 if (testing::Test::HasFatalFailure()) { | |
101 return; | |
102 } | 99 } |
103 | 100 |
104 // The program counter reference value is this function’s address. The | 101 // The program counter reference value is this function’s address. The |
105 // captured program counter should be slightly greater than or equal to the | 102 // captured program counter should be slightly greater than or equal to the |
106 // reference program counter. | 103 // reference program counter. |
107 const uintptr_t kReferencePC = | 104 const uintptr_t kReferencePC = |
108 reinterpret_cast<uintptr_t>(TestCaptureContext); | 105 reinterpret_cast<uintptr_t>(TestCaptureContext); |
109 uintptr_t pc = ProgramCounterFromContext(&context_1); | 106 uintptr_t pc = ProgramCounterFromContext(&context_1); |
110 EXPECT_LT(pc - kReferencePC, 64u); | 107 EXPECT_LT(pc - kReferencePC, 64u); |
111 | 108 |
(...skipping 15 matching lines...) Expand all Loading... |
127 EXPECT_LT(kReferenceSP - sp, 512u); | 124 EXPECT_LT(kReferenceSP - sp, 512u); |
128 | 125 |
129 // Capture the context again, expecting that the stack pointer stays the same | 126 // Capture the context again, expecting that the stack pointer stays the same |
130 // and the program counter increases. Strictly speaking, there’s no guarantee | 127 // and the program counter increases. Strictly speaking, there’s no guarantee |
131 // that these conditions will hold, although they do for known compilers even | 128 // that these conditions will hold, although they do for known compilers even |
132 // under typical optimization. | 129 // under typical optimization. |
133 CaptureContext(&context_2); | 130 CaptureContext(&context_2); |
134 | 131 |
135 { | 132 { |
136 SCOPED_TRACE("context_2"); | 133 SCOPED_TRACE("context_2"); |
137 SanityCheckContext(&context_2); | 134 ASSERT_NO_FATAL_FAILURE(SanityCheckContext(&context_2)); |
138 } | |
139 if (testing::Test::HasFatalFailure()) { | |
140 return; | |
141 } | 135 } |
142 | 136 |
143 EXPECT_EQ(sp, StackPointerFromContext(&context_2)); | 137 EXPECT_EQ(sp, StackPointerFromContext(&context_2)); |
144 EXPECT_GT(ProgramCounterFromContext(&context_2), pc); | 138 EXPECT_GT(ProgramCounterFromContext(&context_2), pc); |
145 } | 139 } |
146 | 140 |
147 TEST(CaptureContextMac, CaptureContext) { | 141 TEST(CaptureContextMac, CaptureContext) { |
148 TestCaptureContext(); | 142 ASSERT_NO_FATAL_FAILURE(TestCaptureContext()); |
149 if (Test::HasFatalFailure()) { | |
150 return; | |
151 } | |
152 } | 143 } |
153 | 144 |
154 } // namespace | 145 } // namespace |
155 } // namespace test | 146 } // namespace test |
156 } // namespace crashpad | 147 } // namespace crashpad |
OLD | NEW |