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

Side by Side Diff: test/cctest/test-log.cc

Issue 661246: Logging-related changes. (Closed)
Patch Set: Created 10 years, 10 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
« no previous file with comments | « src/log.cc ('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 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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 old_sigprof_handler.sa_sigaction(signal, info, context); 167 old_sigprof_handler.sa_sigaction(signal, info, context);
168 } 168 }
169 169
170 #endif // __linux__ 170 #endif // __linux__
171 171
172 172
173 namespace { 173 namespace {
174 174
175 class ScopedLoggerInitializer { 175 class ScopedLoggerInitializer {
176 public: 176 public:
177 explicit ScopedLoggerInitializer(bool log, bool prof_lazy) 177 explicit ScopedLoggerInitializer(bool prof_lazy)
178 : saved_log_(i::FLAG_log), 178 : saved_prof_lazy_(i::FLAG_prof_lazy),
179 saved_prof_lazy_(i::FLAG_prof_lazy),
180 saved_prof_(i::FLAG_prof), 179 saved_prof_(i::FLAG_prof),
181 saved_prof_auto_(i::FLAG_prof_auto), 180 saved_prof_auto_(i::FLAG_prof_auto),
182 trick_to_run_init_flags_(init_flags_(log, prof_lazy)), 181 trick_to_run_init_flags_(init_flags_(prof_lazy)),
183 need_to_set_up_logger_(i::V8::IsRunning()), 182 need_to_set_up_logger_(i::V8::IsRunning()),
184 scope_(), 183 scope_(),
185 env_(v8::Context::New()) { 184 env_(v8::Context::New()) {
186 if (need_to_set_up_logger_) Logger::Setup(); 185 if (need_to_set_up_logger_) Logger::Setup();
187 env_->Enter(); 186 env_->Enter();
188 } 187 }
189 188
190 ~ScopedLoggerInitializer() { 189 ~ScopedLoggerInitializer() {
191 env_->Exit(); 190 env_->Exit();
192 Logger::TearDown(); 191 Logger::TearDown();
193 i::FLAG_prof_lazy = saved_prof_lazy_; 192 i::FLAG_prof_lazy = saved_prof_lazy_;
194 i::FLAG_prof = saved_prof_; 193 i::FLAG_prof = saved_prof_;
195 i::FLAG_prof_auto = saved_prof_auto_; 194 i::FLAG_prof_auto = saved_prof_auto_;
196 i::FLAG_log = saved_log_;
197 } 195 }
198 196
199 v8::Handle<v8::Context>& env() { return env_; } 197 v8::Handle<v8::Context>& env() { return env_; }
200 198
201 private: 199 private:
202 static bool init_flags_(bool log, bool prof_lazy) { 200 static bool init_flags_(bool prof_lazy) {
203 i::FLAG_log = log;
204 i::FLAG_prof = true; 201 i::FLAG_prof = true;
205 i::FLAG_prof_lazy = prof_lazy; 202 i::FLAG_prof_lazy = prof_lazy;
206 i::FLAG_prof_auto = false; 203 i::FLAG_prof_auto = false;
207 i::FLAG_logfile = "*"; 204 i::FLAG_logfile = "*";
208 return prof_lazy; 205 return prof_lazy;
209 } 206 }
210 207
211 const bool saved_log_;
212 const bool saved_prof_lazy_; 208 const bool saved_prof_lazy_;
213 const bool saved_prof_; 209 const bool saved_prof_;
214 const bool saved_prof_auto_; 210 const bool saved_prof_auto_;
215 const bool trick_to_run_init_flags_; 211 const bool trick_to_run_init_flags_;
216 const bool need_to_set_up_logger_; 212 const bool need_to_set_up_logger_;
217 v8::HandleScope scope_; 213 v8::HandleScope scope_;
218 v8::Handle<v8::Context> env_; 214 v8::Handle<v8::Context> env_;
219 215
220 DISALLOW_COPY_AND_ASSIGN(ScopedLoggerInitializer); 216 DISALLOW_COPY_AND_ASSIGN(ScopedLoggerInitializer);
221 }; 217 };
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 CHECK_GT(matcher->GetNextChunk(), 0); 309 CHECK_GT(matcher->GetNextChunk(), 0);
314 matcher->PrintBuffer(); 310 matcher->PrintBuffer();
315 CHECK_NE(NULL, matcher->Find(code_creation)); 311 CHECK_NE(NULL, matcher->Find(code_creation));
316 const char* tick = "\ntick,"; 312 const char* tick = "\ntick,";
317 const bool ticks_found = matcher->Find(tick) != NULL; 313 const bool ticks_found = matcher->Find(tick) != NULL;
318 CHECK_EQ(was_sigprof_received, ticks_found); 314 CHECK_EQ(was_sigprof_received, ticks_found);
319 } 315 }
320 316
321 317
322 TEST(ProfLazyMode) { 318 TEST(ProfLazyMode) {
323 ScopedLoggerInitializer initialize_logger(false, true); 319 ScopedLoggerInitializer initialize_logger(true);
324 320
325 // No sampling should happen prior to resuming profiler. 321 // No sampling should happen prior to resuming profiler.
326 CHECK(!LoggerTestHelper::IsSamplerActive()); 322 CHECK(!LoggerTestHelper::IsSamplerActive());
327 323
328 LogBufferMatcher matcher; 324 LogBufferMatcher matcher;
329 // Nothing must be logged until profiling is resumed. 325 // Nothing must be logged until profiling is resumed.
330 CHECK_EQ(0, matcher.log_pos()); 326 CHECK_EQ(0, matcher.log_pos());
331 327
332 CompileAndRunScript("var a = (function(x) { return x + 1; })(10);"); 328 CompileAndRunScript("var a = (function(x) { return x + 1; })(10);");
333 329
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 // Must not crash. 529 // Must not crash.
534 i::Logger::LogCompiledFunctions(); 530 i::Logger::LogCompiledFunctions();
535 } 531 }
536 532
537 533
538 static v8::Handle<v8::Value> ObjMethod1(const v8::Arguments& args) { 534 static v8::Handle<v8::Value> ObjMethod1(const v8::Arguments& args) {
539 return v8::Handle<v8::Value>(); 535 return v8::Handle<v8::Value>();
540 } 536 }
541 537
542 TEST(LogCallbacks) { 538 TEST(LogCallbacks) {
543 ScopedLoggerInitializer initialize_logger(false, false); 539 ScopedLoggerInitializer initialize_logger(false);
544 LogBufferMatcher matcher; 540 LogBufferMatcher matcher;
545 541
546 v8::Persistent<v8::FunctionTemplate> obj = 542 v8::Persistent<v8::FunctionTemplate> obj =
547 v8::Persistent<v8::FunctionTemplate>::New(v8::FunctionTemplate::New()); 543 v8::Persistent<v8::FunctionTemplate>::New(v8::FunctionTemplate::New());
548 obj->SetClassName(v8::String::New("Obj")); 544 obj->SetClassName(v8::String::New("Obj"));
549 v8::Handle<v8::ObjectTemplate> proto = obj->PrototypeTemplate(); 545 v8::Handle<v8::ObjectTemplate> proto = obj->PrototypeTemplate();
550 v8::Local<v8::Signature> signature = v8::Signature::New(obj); 546 v8::Local<v8::Signature> signature = v8::Signature::New(obj);
551 proto->Set(v8::String::New("method1"), 547 proto->Set(v8::String::New("method1"),
552 v8::FunctionTemplate::New(ObjMethod1, 548 v8::FunctionTemplate::New(ObjMethod1,
553 v8::Handle<v8::Value>(), 549 v8::Handle<v8::Value>(),
(...skipping 29 matching lines...) Expand all
583 v8::Local<v8::Value> value, 579 v8::Local<v8::Value> value,
584 const v8::AccessorInfo& info) { 580 const v8::AccessorInfo& info) {
585 } 581 }
586 582
587 static v8::Handle<v8::Value> Prop2Getter(v8::Local<v8::String> property, 583 static v8::Handle<v8::Value> Prop2Getter(v8::Local<v8::String> property,
588 const v8::AccessorInfo& info) { 584 const v8::AccessorInfo& info) {
589 return v8::Handle<v8::Value>(); 585 return v8::Handle<v8::Value>();
590 } 586 }
591 587
592 TEST(LogAccessorCallbacks) { 588 TEST(LogAccessorCallbacks) {
593 ScopedLoggerInitializer initialize_logger(false, false); 589 ScopedLoggerInitializer initialize_logger(false);
594 LogBufferMatcher matcher; 590 LogBufferMatcher matcher;
595 591
596 v8::Persistent<v8::FunctionTemplate> obj = 592 v8::Persistent<v8::FunctionTemplate> obj =
597 v8::Persistent<v8::FunctionTemplate>::New(v8::FunctionTemplate::New()); 593 v8::Persistent<v8::FunctionTemplate>::New(v8::FunctionTemplate::New());
598 obj->SetClassName(v8::String::New("Obj")); 594 obj->SetClassName(v8::String::New("Obj"));
599 v8::Handle<v8::ObjectTemplate> inst = obj->InstanceTemplate(); 595 v8::Handle<v8::ObjectTemplate> inst = obj->InstanceTemplate();
600 inst->SetAccessor(v8::String::New("prop1"), Prop1Getter, Prop1Setter); 596 inst->SetAccessor(v8::String::New("prop1"), Prop1Getter, Prop1Setter);
601 inst->SetAccessor(v8::String::New("prop2"), Prop2Getter); 597 inst->SetAccessor(v8::String::New("prop2"), Prop2Getter);
602 598
603 i::Logger::LogAccessorCallbacks(); 599 i::Logger::LogAccessorCallbacks();
(...skipping 14 matching lines...) Expand all
618 i::OS::SNPrintF(prop2_getter_record, 614 i::OS::SNPrintF(prop2_getter_record,
619 "code-creation,Callback,0x%" V8PRIxPTR ",1,\"get prop2\"", 615 "code-creation,Callback,0x%" V8PRIxPTR ",1,\"get prop2\"",
620 Prop2Getter); 616 Prop2Getter);
621 CHECK_NE(NULL, matcher.Find(prop2_getter_record)); 617 CHECK_NE(NULL, matcher.Find(prop2_getter_record));
622 618
623 obj.Dispose(); 619 obj.Dispose();
624 } 620 }
625 621
626 622
627 TEST(LogTags) { 623 TEST(LogTags) {
628 ScopedLoggerInitializer initialize_logger(true, false); 624 ScopedLoggerInitializer initialize_logger(false);
629 LogBufferMatcher matcher; 625 LogBufferMatcher matcher;
630 626
631 const char* open_tag = "open-tag,"; 627 const char* open_tag = "open-tag,";
632 const char* close_tag = "close-tag,"; 628 const char* close_tag = "close-tag,";
633 629
634 // Check compatibility with the old style behavior. 630 // Check compatibility with the old style behavior.
635 CHECK_EQ(v8::PROFILER_MODULE_NONE, Logger::GetActiveProfilerModules()); 631 CHECK_EQ(v8::PROFILER_MODULE_NONE, Logger::GetActiveProfilerModules());
636 Logger::ResumeProfiler(v8::PROFILER_MODULE_CPU, 0); 632 Logger::ResumeProfiler(v8::PROFILER_MODULE_CPU, 0);
637 CHECK_EQ(v8::PROFILER_MODULE_CPU, Logger::GetActiveProfilerModules()); 633 CHECK_EQ(v8::PROFILER_MODULE_CPU, Logger::GetActiveProfilerModules());
638 Logger::PauseProfiler(v8::PROFILER_MODULE_CPU, 0); 634 Logger::PauseProfiler(v8::PROFILER_MODULE_CPU, 0);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 Logger::PauseProfiler(v8::PROFILER_MODULE_CPU, 3); 699 Logger::PauseProfiler(v8::PROFILER_MODULE_CPU, 3);
704 CHECK_EQ(v8::PROFILER_MODULE_NONE, Logger::GetActiveProfilerModules()); 700 CHECK_EQ(v8::PROFILER_MODULE_NONE, Logger::GetActiveProfilerModules());
705 Logger::ResumeProfiler(v8::PROFILER_MODULE_CPU, 3); 701 Logger::ResumeProfiler(v8::PROFILER_MODULE_CPU, 3);
706 CHECK_EQ(v8::PROFILER_MODULE_NONE, Logger::GetActiveProfilerModules()); 702 CHECK_EQ(v8::PROFILER_MODULE_NONE, Logger::GetActiveProfilerModules());
707 // Must be no tags, because logging must be disabled. 703 // Must be no tags, because logging must be disabled.
708 CHECK_EQ(NULL, matcher.Find(open_tag3)); 704 CHECK_EQ(NULL, matcher.Find(open_tag3));
709 CHECK_EQ(NULL, matcher.Find(close_tag3)); 705 CHECK_EQ(NULL, matcher.Find(close_tag3));
710 } 706 }
711 707
712 708
709 TEST(IsLoggingPreserved) {
710 ScopedLoggerInitializer initialize_logger(false);
711
712 CHECK(Logger::is_logging());
713 Logger::ResumeProfiler(v8::PROFILER_MODULE_CPU, 1);
714 CHECK(Logger::is_logging());
715 Logger::PauseProfiler(v8::PROFILER_MODULE_CPU, 1);
716 CHECK(Logger::is_logging());
717
718 CHECK(Logger::is_logging());
719 Logger::ResumeProfiler(
720 v8::PROFILER_MODULE_HEAP_STATS | v8::PROFILER_MODULE_JS_CONSTRUCTORS, 1);
721 CHECK(Logger::is_logging());
722 Logger::PauseProfiler(
723 v8::PROFILER_MODULE_HEAP_STATS | v8::PROFILER_MODULE_JS_CONSTRUCTORS, 1);
724 CHECK(Logger::is_logging());
725
726 CHECK(Logger::is_logging());
727 Logger::ResumeProfiler(
728 v8::PROFILER_MODULE_CPU |
729 v8::PROFILER_MODULE_HEAP_STATS | v8::PROFILER_MODULE_JS_CONSTRUCTORS, 1);
730 CHECK(Logger::is_logging());
731 Logger::PauseProfiler(
732 v8::PROFILER_MODULE_CPU |
733 v8::PROFILER_MODULE_HEAP_STATS | v8::PROFILER_MODULE_JS_CONSTRUCTORS, 1);
734 CHECK(Logger::is_logging());
735 }
736
737
713 static inline bool IsStringEqualTo(const char* r, const char* s) { 738 static inline bool IsStringEqualTo(const char* r, const char* s) {
714 return strncmp(r, s, strlen(r)) == 0; 739 return strncmp(r, s, strlen(r)) == 0;
715 } 740 }
716 741
717 742
718 static bool Consume(const char* str, char** buf) { 743 static bool Consume(const char* str, char** buf) {
719 if (IsStringEqualTo(str, *buf)) { 744 if (IsStringEqualTo(str, *buf)) {
720 *buf += strlen(str); 745 *buf += strlen(str);
721 return true; 746 return true;
722 } 747 }
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
1169 // Make sure that all log data is written prior crash due to CHECK failure. 1194 // Make sure that all log data is written prior crash due to CHECK failure.
1170 fflush(stdout); 1195 fflush(stdout);
1171 CHECK(results_equal); 1196 CHECK(results_equal);
1172 1197
1173 env->Exit(); 1198 env->Exit();
1174 Logger::TearDown(); 1199 Logger::TearDown();
1175 i::FLAG_always_compact = saved_always_compact; 1200 i::FLAG_always_compact = saved_always_compact;
1176 } 1201 }
1177 1202
1178 #endif // ENABLE_LOGGING_AND_PROFILING 1203 #endif // ENABLE_LOGGING_AND_PROFILING
OLDNEW
« no previous file with comments | « src/log.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698