OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // | 4 // |
5 // Tests the sampling API in include/v8.h | 5 // Tests the sampling API in include/v8.h |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 #include "include/v8.h" | 9 #include "include/v8.h" |
10 #include "src/simulator.h" | 10 #include "src/simulator.h" |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 } // namespace | 187 } // namespace |
188 | 188 |
189 | 189 |
190 // A JavaScript function which takes stack depth | 190 // A JavaScript function which takes stack depth |
191 // (minimum value 2) as an argument. | 191 // (minimum value 2) as an argument. |
192 // When at the bottom of the recursion, | 192 // When at the bottom of the recursion, |
193 // the JavaScript code calls into C++ test code, | 193 // the JavaScript code calls into C++ test code, |
194 // waiting for the sampler to take a sample. | 194 // waiting for the sampler to take a sample. |
195 static const char* test_function = | 195 static const char* test_function = |
196 "function func(depth) {" | 196 "function func(depth) {" |
197 " if (depth == 2) CollectSample();" | 197 " if (depth == 3) CollectSample();" |
198 " else return func(depth - 1);" | 198 " else return func(depth - 1);" |
199 "}"; | 199 "}"; |
200 | 200 |
201 | 201 |
202 TEST(StackDepthIsConsistent) { | 202 TEST(StackDepthIsConsistent) { |
203 SamplingTestHelper helper(std::string(test_function) + "func(8);"); | 203 SamplingTestHelper helper(std::string(test_function) + "func(8);"); |
204 CHECK_EQ(8, helper.sample().size()); | 204 CHECK_EQ(8, helper.sample().size()); |
205 } | 205 } |
206 | 206 |
207 | 207 |
208 TEST(StackDepthDoesNotExceedMaxValue) { | 208 TEST(StackDepthDoesNotExceedMaxValue) { |
209 SamplingTestHelper helper(std::string(test_function) + "func(300);"); | 209 SamplingTestHelper helper(std::string(test_function) + "func(300);"); |
210 CHECK_EQ(Sample::kFramesLimit, helper.sample().size()); | 210 CHECK_EQ(Sample::kFramesLimit, helper.sample().size()); |
211 } | 211 } |
212 | 212 |
213 | 213 |
214 // The captured sample should have three pc values. | 214 // The captured sample should have three pc values. |
215 // They should fall in the range where the compiled code resides. | 215 // They should fall in the range where the compiled code resides. |
216 // The expected stack is: | 216 // The expected stack is: |
217 // bottom of stack [{anon script}, outer, inner] top of stack | 217 // bottom of stack [{anon script}, outer, inner, c_entry] top of stack |
218 // ^ ^ ^ | 218 // ^ ^ ^ ^ |
219 // sample.stack indices 2 1 0 | 219 // sample.stack indices 3 2 1 0 |
220 TEST(StackFramesConsistent) { | 220 TEST(StackFramesConsistent) { |
221 // Note: The arguments.callee stuff is there so that the | 221 // Note: The arguments.callee stuff is there so that the |
222 // functions are not optimized away. | 222 // functions are not optimized away. |
223 const char* test_script = | 223 const char* test_script = |
224 "function test_sampler_api_inner() {" | 224 "function test_sampler_api_inner() {" |
225 " CollectSample();" | 225 " CollectSample();" |
226 " return arguments.callee.toString();" | 226 " return arguments.callee.toString();" |
227 "}" | 227 "}" |
228 "function test_sampler_api_outer() {" | 228 "function test_sampler_api_outer() {" |
229 " return test_sampler_api_inner() + arguments.callee.toString();" | 229 " return test_sampler_api_inner() + arguments.callee.toString();" |
230 "}" | 230 "}" |
231 "test_sampler_api_outer();"; | 231 "test_sampler_api_outer();"; |
232 | 232 |
233 SamplingTestHelper helper(test_script); | 233 SamplingTestHelper helper(test_script); |
234 Sample& sample = helper.sample(); | 234 Sample& sample = helper.sample(); |
235 CHECK_EQ(3, sample.size()); | 235 CHECK_EQ(4, sample.size()); |
236 | 236 |
237 const SamplingTestHelper::CodeEventEntry* entry; | 237 const SamplingTestHelper::CodeEventEntry* entry; |
238 entry = helper.FindEventEntry(sample.begin()[0]); | 238 entry = helper.FindEventEntry(sample.begin()[1]); |
239 CHECK_NE(NULL, entry); | 239 CHECK_NE(NULL, entry); |
240 CHECK(std::string::npos != entry->name.find("test_sampler_api_inner")); | 240 CHECK(std::string::npos != entry->name.find("test_sampler_api_inner")); |
241 | 241 |
242 entry = helper.FindEventEntry(sample.begin()[1]); | 242 entry = helper.FindEventEntry(sample.begin()[2]); |
243 CHECK_NE(NULL, entry); | 243 CHECK_NE(NULL, entry); |
244 CHECK(std::string::npos != entry->name.find("test_sampler_api_outer")); | 244 CHECK(std::string::npos != entry->name.find("test_sampler_api_outer")); |
245 } | 245 } |
OLD | NEW |