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 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
531 obj.Dispose(); | 531 obj.Dispose(); |
532 | 532 |
533 env->Exit(); | 533 env->Exit(); |
534 Logger::TearDown(); | 534 Logger::TearDown(); |
535 i::FLAG_prof_lazy = saved_prof_lazy; | 535 i::FLAG_prof_lazy = saved_prof_lazy; |
536 i::FLAG_prof = saved_prof; | 536 i::FLAG_prof = saved_prof; |
537 i::FLAG_prof_auto = saved_prof_auto; | 537 i::FLAG_prof_auto = saved_prof_auto; |
538 } | 538 } |
539 | 539 |
540 | 540 |
| 541 static v8::Handle<v8::Value> Prop1Getter(v8::Local<v8::String> property, |
| 542 const v8::AccessorInfo& info) { |
| 543 return v8::Handle<v8::Value>(); |
| 544 } |
| 545 |
| 546 static void Prop1Setter(v8::Local<v8::String> property, |
| 547 v8::Local<v8::Value> value, |
| 548 const v8::AccessorInfo& info) { |
| 549 } |
| 550 |
| 551 static v8::Handle<v8::Value> Prop2Getter(v8::Local<v8::String> property, |
| 552 const v8::AccessorInfo& info) { |
| 553 return v8::Handle<v8::Value>(); |
| 554 } |
| 555 |
| 556 TEST(LogAccessorCallbacks) { |
| 557 const bool saved_prof_lazy = i::FLAG_prof_lazy; |
| 558 const bool saved_prof = i::FLAG_prof; |
| 559 const bool saved_prof_auto = i::FLAG_prof_auto; |
| 560 i::FLAG_prof = true; |
| 561 i::FLAG_prof_lazy = false; |
| 562 i::FLAG_prof_auto = false; |
| 563 i::FLAG_logfile = "*"; |
| 564 |
| 565 // If tests are being run manually, V8 will be already initialized |
| 566 // by the bottom test. |
| 567 const bool need_to_set_up_logger = i::V8::IsRunning(); |
| 568 v8::HandleScope scope; |
| 569 v8::Handle<v8::Context> env = v8::Context::New(); |
| 570 if (need_to_set_up_logger) Logger::Setup(); |
| 571 env->Enter(); |
| 572 |
| 573 // Skip all initially logged stuff. |
| 574 EmbeddedVector<char, 102400> buffer; |
| 575 int log_pos = GetLogLines(0, &buffer); |
| 576 |
| 577 v8::Persistent<v8::FunctionTemplate> obj = |
| 578 v8::Persistent<v8::FunctionTemplate>::New(v8::FunctionTemplate::New()); |
| 579 obj->SetClassName(v8::String::New("Obj")); |
| 580 v8::Handle<v8::ObjectTemplate> inst = obj->InstanceTemplate(); |
| 581 inst->SetAccessor(v8::String::New("prop1"), Prop1Getter, Prop1Setter); |
| 582 inst->SetAccessor(v8::String::New("prop2"), Prop2Getter); |
| 583 |
| 584 i::Logger::LogAccessorCallbacks(); |
| 585 log_pos = GetLogLines(log_pos, &buffer); |
| 586 CHECK_GT(log_pos, 0); |
| 587 buffer[log_pos] = 0; |
| 588 printf("%s", buffer.start()); |
| 589 |
| 590 EmbeddedVector<char, 100> prop1_getter_record; |
| 591 i::OS::SNPrintF(prop1_getter_record, |
| 592 "code-creation,Callback,0x%" V8PRIxPTR ",1,\"get prop1\"", |
| 593 Prop1Getter); |
| 594 CHECK_NE(NULL, strstr(buffer.start(), prop1_getter_record.start())); |
| 595 EmbeddedVector<char, 100> prop1_setter_record; |
| 596 i::OS::SNPrintF(prop1_setter_record, |
| 597 "code-creation,Callback,0x%" V8PRIxPTR ",1,\"set prop1\"", |
| 598 Prop1Setter); |
| 599 CHECK_NE(NULL, strstr(buffer.start(), prop1_setter_record.start())); |
| 600 EmbeddedVector<char, 100> prop2_getter_record; |
| 601 i::OS::SNPrintF(prop2_getter_record, |
| 602 "code-creation,Callback,0x%" V8PRIxPTR ",1,\"get prop2\"", |
| 603 Prop2Getter); |
| 604 CHECK_NE(NULL, strstr(buffer.start(), prop2_getter_record.start())); |
| 605 |
| 606 obj.Dispose(); |
| 607 |
| 608 env->Exit(); |
| 609 Logger::TearDown(); |
| 610 i::FLAG_prof_lazy = saved_prof_lazy; |
| 611 i::FLAG_prof = saved_prof; |
| 612 i::FLAG_prof_auto = saved_prof_auto; |
| 613 } |
| 614 |
| 615 |
541 static inline bool IsStringEqualTo(const char* r, const char* s) { | 616 static inline bool IsStringEqualTo(const char* r, const char* s) { |
542 return strncmp(r, s, strlen(r)) == 0; | 617 return strncmp(r, s, strlen(r)) == 0; |
543 } | 618 } |
544 | 619 |
545 | 620 |
546 static bool Consume(const char* str, char** buf) { | 621 static bool Consume(const char* str, char** buf) { |
547 if (IsStringEqualTo(str, *buf)) { | 622 if (IsStringEqualTo(str, *buf)) { |
548 *buf += strlen(str); | 623 *buf += strlen(str); |
549 return true; | 624 return true; |
550 } | 625 } |
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
997 // Make sure that all log data is written prior crash due to CHECK failure. | 1072 // Make sure that all log data is written prior crash due to CHECK failure. |
998 fflush(stdout); | 1073 fflush(stdout); |
999 CHECK(results_equal); | 1074 CHECK(results_equal); |
1000 | 1075 |
1001 env->Exit(); | 1076 env->Exit(); |
1002 Logger::TearDown(); | 1077 Logger::TearDown(); |
1003 i::FLAG_always_compact = saved_always_compact; | 1078 i::FLAG_always_compact = saved_always_compact; |
1004 } | 1079 } |
1005 | 1080 |
1006 #endif // ENABLE_LOGGING_AND_PROFILING | 1081 #endif // ENABLE_LOGGING_AND_PROFILING |
OLD | NEW |