| 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 __linux__ | 5 #ifdef __linux__ |
| 6 #include <math.h> | 6 #include <math.h> |
| 7 #include <pthread.h> | 7 #include <pthread.h> |
| 8 #include <signal.h> | 8 #include <signal.h> |
| 9 #include <unistd.h> | 9 #include <unistd.h> |
| 10 #endif // __linux__ | 10 #endif // __linux__ |
| 11 | 11 |
| 12 #include "v8.h" | 12 #include "v8.h" |
| 13 #include "log.h" | 13 #include "log.h" |
| 14 #include "cpu-profiler.h" | 14 #include "cpu-profiler.h" |
| 15 #include "natives.h" |
| 15 #include "v8threads.h" | 16 #include "v8threads.h" |
| 16 #include "v8utils.h" | 17 #include "v8utils.h" |
| 17 #include "cctest.h" | 18 #include "cctest.h" |
| 18 #include "vm-state-inl.h" | 19 #include "vm-state-inl.h" |
| 19 | 20 |
| 20 using v8::internal::Address; | 21 using v8::internal::Address; |
| 21 using v8::internal::EmbeddedVector; | 22 using v8::internal::EmbeddedVector; |
| 22 using v8::internal::Logger; | 23 using v8::internal::Logger; |
| 23 using v8::internal::StrLength; | 24 using v8::internal::StrLength; |
| 24 | 25 |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 ScopedLoggerInitializer initialize_logger(false); | 463 ScopedLoggerInitializer initialize_logger(false); |
| 463 | 464 |
| 464 CHECK(LOGGER->is_logging()); | 465 CHECK(LOGGER->is_logging()); |
| 465 LOGGER->ResumeProfiler(); | 466 LOGGER->ResumeProfiler(); |
| 466 CHECK(LOGGER->is_logging()); | 467 CHECK(LOGGER->is_logging()); |
| 467 LOGGER->PauseProfiler(); | 468 LOGGER->PauseProfiler(); |
| 468 CHECK(LOGGER->is_logging()); | 469 CHECK(LOGGER->is_logging()); |
| 469 } | 470 } |
| 470 | 471 |
| 471 | 472 |
| 473 typedef i::NativesCollection<i::TEST> TestSources; |
| 474 |
| 472 // Test that logging of code create / move / delete events | 475 // Test that logging of code create / move / delete events |
| 473 // is equivalent to traversal of a resulting heap. | 476 // is equivalent to traversal of a resulting heap. |
| 474 TEST(EquivalenceOfLoggingAndTraversal) { | 477 TEST(EquivalenceOfLoggingAndTraversal) { |
| 475 // This test needs to be run on a "clean" V8 to ensure that snapshot log | 478 // This test needs to be run on a "clean" V8 to ensure that snapshot log |
| 476 // is loaded. This is always true when running using tools/test.py because | 479 // is loaded. This is always true when running using tools/test.py because |
| 477 // it launches a new cctest instance for every test. To be sure that launching | 480 // it launches a new cctest instance for every test. To be sure that launching |
| 478 // cctest manually also works, please be sure that no tests below | 481 // cctest manually also works, please be sure that no tests below |
| 479 // are using V8. | 482 // are using V8. |
| 480 // | 483 // |
| 481 // P.S. No, V8 can't be re-initialized after disposal, see include/v8.h. | 484 // P.S. No, V8 can't be re-initialized after disposal, see include/v8.h. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 498 LOGGER->LogCompiledFunctions(); | 501 LOGGER->LogCompiledFunctions(); |
| 499 LOGGER->StringEvent("test-traversal-done", ""); | 502 LOGGER->StringEvent("test-traversal-done", ""); |
| 500 | 503 |
| 501 bool exists = false; | 504 bool exists = false; |
| 502 i::Vector<const char> log( | 505 i::Vector<const char> log( |
| 503 i::ReadFile(initialize_logger.StopLoggingGetTempFile(), &exists, true)); | 506 i::ReadFile(initialize_logger.StopLoggingGetTempFile(), &exists, true)); |
| 504 CHECK(exists); | 507 CHECK(exists); |
| 505 v8::Handle<v8::String> log_str = v8::String::New(log.start(), log.length()); | 508 v8::Handle<v8::String> log_str = v8::String::New(log.start(), log.length()); |
| 506 initialize_logger.env()->Global()->Set(v8_str("_log"), log_str); | 509 initialize_logger.env()->Global()->Set(v8_str("_log"), log_str); |
| 507 | 510 |
| 508 const char* scripts[] = { | 511 i::Vector<const unsigned char> source = TestSources::GetScriptsSource(); |
| 509 "tools/splaytree.js", "tools/codemap.js", "tools/csvparser.js", | 512 v8::Handle<v8::String> source_str = v8::String::New( |
| 510 "tools/consarray.js", "tools/profile.js", "tools/profile_view.js", | 513 reinterpret_cast<const char*>(source.start()), source.length()); |
| 511 "tools/logreader.js", "test/cctest/log-eq-of-logging-and-traversal.js" | 514 v8::TryCatch try_catch; |
| 512 }; | 515 v8::Handle<v8::Script> script = v8::Script::Compile(source_str, v8_str("")); |
| 513 int scripts_count = sizeof(scripts) / sizeof(scripts[0]); | 516 if (script.IsEmpty()) { |
| 514 v8::Handle<v8::Value> last_result; | 517 v8::String::Utf8Value exception(try_catch.Exception()); |
| 515 for (int i = 0; i < scripts_count; ++i) { | 518 printf("compile: %s\n", *exception); |
| 516 bool exists = true; | 519 CHECK(false); |
| 517 i::Vector<const char> source(i::ReadFile(scripts[i], &exists, true)); | 520 } |
| 518 CHECK(exists); | 521 v8::Handle<v8::Value> result = script->Run(); |
| 519 CHECK_GT(source.length(), 0); | 522 if (result.IsEmpty()) { |
| 520 v8::Handle<v8::String> source_str = | 523 v8::String::Utf8Value exception(try_catch.Exception()); |
| 521 v8::String::New(source.start(), source.length()); | 524 printf("run: %s\n", *exception); |
| 522 v8::TryCatch try_catch; | 525 CHECK(false); |
| 523 v8::Handle<v8::Script> script = | |
| 524 v8::Script::Compile(source_str, v8_str(scripts[i])); | |
| 525 if (script.IsEmpty()) { | |
| 526 v8::String::Utf8Value exception(try_catch.Exception()); | |
| 527 printf("compile %s: %s\n", scripts[i], *exception); | |
| 528 CHECK(false); | |
| 529 } | |
| 530 last_result = script->Run(); | |
| 531 if (last_result.IsEmpty()) { | |
| 532 v8::String::Utf8Value exception(try_catch.Exception()); | |
| 533 printf("run %s: %s\n", scripts[i], *exception); | |
| 534 CHECK(false); | |
| 535 } | |
| 536 } | 526 } |
| 537 // The result either be a "true" literal or problem description. | 527 // The result either be a "true" literal or problem description. |
| 538 if (!last_result->IsTrue()) { | 528 if (!result->IsTrue()) { |
| 539 v8::Local<v8::String> s = last_result->ToString(); | 529 v8::Local<v8::String> s = result->ToString(); |
| 540 i::ScopedVector<char> data(s->Length() + 1); | 530 i::ScopedVector<char> data(s->Length() + 1); |
| 541 CHECK_NE(NULL, data.start()); | 531 CHECK_NE(NULL, data.start()); |
| 542 s->WriteAscii(data.start()); | 532 s->WriteAscii(data.start()); |
| 543 printf("%s\n", data.start()); | 533 printf("%s\n", data.start()); |
| 544 // Make sure that our output is written prior crash due to CHECK failure. | 534 // Make sure that our output is written prior crash due to CHECK failure. |
| 545 fflush(stdout); | 535 fflush(stdout); |
| 546 CHECK(false); | 536 CHECK(false); |
| 547 } | 537 } |
| 548 } | 538 } |
| OLD | NEW |