OLD | NEW |
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 the V8 project authors. All rights reserved. |
2 // | 2 // |
3 // Tests of logging functions from log.h | 3 // Tests of logging functions from log.h |
4 | 4 |
5 #ifdef ENABLE_LOGGING_AND_PROFILING | 5 #ifdef ENABLE_LOGGING_AND_PROFILING |
6 | 6 |
7 #ifdef __linux__ | 7 #ifdef __linux__ |
8 #include <math.h> | 8 #include <math.h> |
9 #include <pthread.h> | 9 #include <pthread.h> |
10 #include <signal.h> | 10 #include <signal.h> |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 TEST(ProfLazyMode) { | 240 TEST(ProfLazyMode) { |
241 const bool saved_prof_lazy = i::FLAG_prof_lazy; | 241 const bool saved_prof_lazy = i::FLAG_prof_lazy; |
242 const bool saved_prof = i::FLAG_prof; | 242 const bool saved_prof = i::FLAG_prof; |
243 const bool saved_prof_auto = i::FLAG_prof_auto; | 243 const bool saved_prof_auto = i::FLAG_prof_auto; |
244 i::FLAG_prof = true; | 244 i::FLAG_prof = true; |
245 i::FLAG_prof_lazy = true; | 245 i::FLAG_prof_lazy = true; |
246 i::FLAG_prof_auto = false; | 246 i::FLAG_prof_auto = false; |
247 i::FLAG_logfile = "*"; | 247 i::FLAG_logfile = "*"; |
248 | 248 |
249 // If tests are being run manually, V8 will be already initialized | 249 // If tests are being run manually, V8 will be already initialized |
250 // by the test below. | 250 // by the bottom test. |
251 const bool need_to_set_up_logger = i::V8::IsRunning(); | 251 const bool need_to_set_up_logger = i::V8::IsRunning(); |
252 v8::HandleScope scope; | 252 v8::HandleScope scope; |
253 v8::Handle<v8::Context> env = v8::Context::New(); | 253 v8::Handle<v8::Context> env = v8::Context::New(); |
254 if (need_to_set_up_logger) Logger::Setup(); | 254 if (need_to_set_up_logger) Logger::Setup(); |
255 env->Enter(); | 255 env->Enter(); |
256 | 256 |
257 // No sampling should happen prior to resuming profiler. | 257 // No sampling should happen prior to resuming profiler. |
258 CHECK(!LoggerTestHelper::IsSamplerActive()); | 258 CHECK(!LoggerTestHelper::IsSamplerActive()); |
259 | 259 |
260 EmbeddedVector<char, 102400> buffer; | 260 EmbeddedVector<char, 102400> buffer; |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 i::ExternalTwoByteString::cast(*v8::Utils::OpenHandle(*source))); | 467 i::ExternalTwoByteString::cast(*v8::Utils::OpenHandle(*source))); |
468 // This situation can happen if source was an external string disposed | 468 // This situation can happen if source was an external string disposed |
469 // by its owner. | 469 // by its owner. |
470 i_source->set_resource(NULL); | 470 i_source->set_resource(NULL); |
471 | 471 |
472 // Must not crash. | 472 // Must not crash. |
473 i::Logger::LogCompiledFunctions(); | 473 i::Logger::LogCompiledFunctions(); |
474 } | 474 } |
475 | 475 |
476 | 476 |
| 477 static v8::Handle<v8::Value> ObjMethod1(const v8::Arguments& args) { |
| 478 return v8::Handle<v8::Value>(); |
| 479 } |
| 480 |
| 481 TEST(LogCallbacks) { |
| 482 const bool saved_prof_lazy = i::FLAG_prof_lazy; |
| 483 const bool saved_prof = i::FLAG_prof; |
| 484 const bool saved_prof_auto = i::FLAG_prof_auto; |
| 485 i::FLAG_prof = true; |
| 486 i::FLAG_prof_lazy = false; |
| 487 i::FLAG_prof_auto = false; |
| 488 i::FLAG_logfile = "*"; |
| 489 |
| 490 // If tests are being run manually, V8 will be already initialized |
| 491 // by the bottom test. |
| 492 const bool need_to_set_up_logger = i::V8::IsRunning(); |
| 493 v8::HandleScope scope; |
| 494 v8::Handle<v8::Context> env = v8::Context::New(); |
| 495 if (need_to_set_up_logger) Logger::Setup(); |
| 496 env->Enter(); |
| 497 |
| 498 // Skip all initially logged stuff. |
| 499 EmbeddedVector<char, 102400> buffer; |
| 500 int log_pos = GetLogLines(0, &buffer); |
| 501 |
| 502 v8::Persistent<v8::FunctionTemplate> obj = |
| 503 v8::Persistent<v8::FunctionTemplate>::New(v8::FunctionTemplate::New()); |
| 504 obj->SetClassName(v8::String::New("Obj")); |
| 505 v8::Handle<v8::ObjectTemplate> proto = obj->PrototypeTemplate(); |
| 506 v8::Local<v8::Signature> signature = v8::Signature::New(obj); |
| 507 proto->Set(v8::String::New("method1"), |
| 508 v8::FunctionTemplate::New(ObjMethod1, |
| 509 v8::Handle<v8::Value>(), |
| 510 signature), |
| 511 static_cast<v8::PropertyAttribute>(v8::DontDelete)); |
| 512 |
| 513 i::Logger::LogCallbacks(); |
| 514 log_pos = GetLogLines(log_pos, &buffer); |
| 515 CHECK_GT(log_pos, 0); |
| 516 buffer[log_pos] = 0; |
| 517 |
| 518 const char* callback_rec = "code-creation,Callback,"; |
| 519 const char* pos = strstr(buffer.start(), callback_rec); |
| 520 CHECK_NE(NULL, pos); |
| 521 pos += strlen(callback_rec); |
| 522 EmbeddedVector<char, 100> ref_data; |
| 523 i::OS::SNPrintF(ref_data, |
| 524 "0x%" V8PRIxPTR ",0,\"Obj.method1\"\n", ObjMethod1); |
| 525 CHECK_EQ(ref_data.start(), pos); |
| 526 |
| 527 obj.Dispose(); |
| 528 |
| 529 env->Exit(); |
| 530 Logger::TearDown(); |
| 531 i::FLAG_prof_lazy = saved_prof_lazy; |
| 532 i::FLAG_prof = saved_prof; |
| 533 i::FLAG_prof_auto = saved_prof_auto; |
| 534 } |
| 535 |
| 536 |
477 static inline bool IsStringEqualTo(const char* r, const char* s) { | 537 static inline bool IsStringEqualTo(const char* r, const char* s) { |
478 return strncmp(r, s, strlen(r)) == 0; | 538 return strncmp(r, s, strlen(r)) == 0; |
479 } | 539 } |
480 | 540 |
481 | 541 |
482 static bool Consume(const char* str, char** buf) { | 542 static bool Consume(const char* str, char** buf) { |
483 if (IsStringEqualTo(str, *buf)) { | 543 if (IsStringEqualTo(str, *buf)) { |
484 *buf += strlen(str); | 544 *buf += strlen(str); |
485 return true; | 545 return true; |
486 } | 546 } |
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
933 // Make sure that all log data is written prior crash due to CHECK failure. | 993 // Make sure that all log data is written prior crash due to CHECK failure. |
934 fflush(stdout); | 994 fflush(stdout); |
935 CHECK(results_equal); | 995 CHECK(results_equal); |
936 | 996 |
937 env->Exit(); | 997 env->Exit(); |
938 Logger::TearDown(); | 998 Logger::TearDown(); |
939 i::FLAG_always_compact = saved_always_compact; | 999 i::FLAG_always_compact = saved_always_compact; |
940 } | 1000 } |
941 | 1001 |
942 #endif // ENABLE_LOGGING_AND_PROFILING | 1002 #endif // ENABLE_LOGGING_AND_PROFILING |
OLD | NEW |