[test] Move cctest/test-log to unittests/logging/log-unittest

This is a reland of https://chromium-review.googlesource.com/c/v8/v8/+/3607389.
The previous revert is https://chromium-review.googlesource.com/c/v8/v8/+/3610448.
Reason for revert: https://crbug.com/v8/12838.

The original CL has merge conflicts and cannot be relanded,
so this CL is newly opened.

This CL moves cctest/test-log to unittests/logging/log-unittest
, fixes the flaky tests in https://bugs.chromium.org/p/v8/issues/detail?id=12838 and updates the unittests status for log-unittest.


Flaky Tests:
- https://ci.chromium.org/ui/p/v8/builders/ci/V8%20Linux64%20TSAN%20-%20stress-incremental-marking/7287/overview
  - flaky LogTest.Issue539892 is caused by in stress-incremental-marking
    mode, Heap::MarkCompact will trigger CodeMovingGCEvent in https://source.chromium.org/chromium/chromium/src/+/main:v8/src/heap/heap.cc;l=2586;drc=52f06e6b43ff95eccf79e0a5df8d4d83c029130a for
    FakeCodeEventLogger which was already destructed
    when Heap::PerformGarbageCollection task was handled in
    DefaultPlatform::PumpMessageLoop. This should be fixed by removing
    FakeCodeEventLogger in LogTest.Issue539892.

  - flaky LogTest.LogAccessorCallbacks is caused by the data race in
    Sampler::DoSample. This should be fixed in https://chromium-
    review.googlesource.com/c/v8/v8/+/3616429.

-https://ci.chromium.org/ui/p/v8/builders/ci/V8%20Linux64%20TSAN/41327/overview
  - flaky LogTest.ExternalLogEventListenerWithInterpretedFramesNativeStack
    is caused by the data race of i::FLAG_* which were written again after
    setting up the isolate. This should be fixed by only writting
    i::FLAG_* before setting up the Isolate.

- https://ci.chromium.org/ui/p/v8/builders/ci/V8%20Linux64/47277/overview
  - flaky LogTest.BuiltinsNotLoggedAsLazyCompile is caused by the data
    race in Sampler::DoSample. This should be fixed in https://chromium-
    review.googlesource.com/c/v8/v8/+/3616429.

Bug: v8:12781
Change-Id: I3f736d4ffb3b8f147006bebe92285684b0c3952a
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3616424
Reviewed-by: Leszek Swirski <leszeks@chromium.org>
Commit-Queue: 王澳 <wangao.james@bytedance.com>
Cr-Commit-Position: refs/heads/main@{#80423}
This commit is contained in:
jameslahm 2022-05-09 19:23:59 +08:00 committed by V8 LUCI CQ
parent d48558e6b7
commit 9e3f20b225
6 changed files with 271 additions and 229 deletions

View File

@ -232,7 +232,6 @@ v8_source_set("cctest_sources") {
"test-liveedit.cc",
"test-local-handles.cc",
"test-lockers.cc",
"test-log.cc",
"test-managed.cc",
"test-mementos.cc",
"test-orderedhashtable.cc",

View File

@ -345,9 +345,6 @@
##############################################################################
['arch == arm', {
# BUG(355): Test crashes on ARM.
'test-log/ProfLazyMode': [SKIP],
# BUG(1075): Unresolved crashes.
'test-serialize/StartupSerializerOnce': [SKIP],
'test-serialize/StartupSerializerTwice': [SKIP],
@ -560,7 +557,6 @@
'test-parsing/*': [SKIP],
'test-page-promotion/*': [SKIP],
'test-decls/*': [SKIP],
'test-log/*': [SKIP],
'test-gap-resolver/*': [SKIP],
'test-dtoa/*': [SKIP],
}], # variant == no_wasm_traps
@ -662,9 +658,6 @@
# TODO(mythria): Code logging tests that currently fail with lazy feedback
# allocation. Fix logging to work without feedback vectors and enable these
# tests in lite_mode.
'test-log/ExternalLogEventListenerWithInterpretedFramesNativeStack': [SKIP],
'test-log/LogInterpretedFramesNativeStack': [SKIP],
'test-log/LogInterpretedFramesNativeStackWithSerialization': [SKIP],
'test-serialize/CodeSerializerOnePlusOneWithInterpretedFramesNativeStack': [SKIP]
}], # lite_mode
@ -692,9 +685,6 @@
'test-verify-type/*': [SKIP],
# --interpreted-frames-native-stack tests
'test-log/ExternalLogEventListenerWithInterpretedFramesNativeStack': [SKIP],
'test-log/LogInterpretedFramesNativeStack': [SKIP],
'test-log/LogInterpretedFramesNativeStackWithSerialization': [SKIP],
'test-serialize/CodeSerializerOnePlusOneWithInterpretedFramesNativeStack': [SKIP],
'test-interpreter/InterpreterWithNativeStack': [SKIP],
@ -820,8 +810,6 @@
'test-heap/Regress538257': [SKIP],
'test-heap/ReinitializeStringHashSeed': [SKIP],
'test-lockers/*': [SKIP],
'test-log/ExternalLogEventListenerInnerFunctions': [SKIP],
'test-log/LogInterpretedFramesNativeStackWithSerialization': [SKIP],
'test-managed/*': [SKIP],
'test-mark-compact/RegressJoinThreadsOnIsolateDeinit': [SKIP],
'test-memory-measurement/RandomizedTimeout': [SKIP],

View File

@ -375,6 +375,7 @@ v8_source_set("unittests_sources") {
"libplatform/task-queue-unittest.cc",
"libplatform/worker-thread-unittest.cc",
"logging/counters-unittest.cc",
"logging/log-unittest.cc",
"numbers/bigint-unittest.cc",
"numbers/conversions-unittest.cc",
"objects/array-list-unittest.cc",

View File

@ -27,6 +27,8 @@
//
// Tests of logging functions from log.h
#include "src/logging/log.h"
#include <unordered_set>
#include <vector>
@ -38,25 +40,31 @@
#include "src/execution/vm-state-inl.h"
#include "src/init/v8.h"
#include "src/logging/log-file.h"
#include "src/logging/log.h"
#include "src/objects/objects-inl.h"
#include "src/profiler/cpu-profiler.h"
#include "src/utils/ostreams.h"
#include "src/utils/version.h"
#include "test/cctest/cctest.h"
#include "test/unittests/test-utils.h"
#include "testing/gtest/include/gtest/gtest.h"
using v8::base::EmbeddedVector;
using v8::internal::Address;
using v8::internal::V8FileLogger;
namespace v8 {
namespace {
#define SETUP_FLAGS() \
i::FLAG_log = true; \
i::FLAG_prof = true; \
i::FLAG_log_code = true; \
i::FLAG_logfile = i::LogFile::kLogToTemporaryFile; \
i::FLAG_logfile_per_isolate = false
class LogTest : public TestWithIsolate {
public:
static void SetUpTestSuite() {
i::FLAG_log = true;
i::FLAG_prof = true;
i::FLAG_log_code = true;
i::FLAG_logfile = i::LogFile::kLogToTemporaryFile;
i::FLAG_logfile_per_isolate = false;
TestWithIsolate::SetUpTestSuite();
}
};
static std::vector<std::string> Split(const std::string& s, char delimiter) {
std::vector<std::string> result;
@ -292,59 +300,54 @@ class SimpleExternalString : public v8::String::ExternalStringResource {
} // namespace
TEST(Issue23768) {
v8::HandleScope scope(CcTest::isolate());
v8::Local<v8::Context> env = v8::Context::New(CcTest::isolate());
TEST_F(TestWithIsolate, Issue23768) {
v8::HandleScope scope(isolate());
v8::Local<v8::Context> env = v8::Context::New(isolate());
env->Enter();
SimpleExternalString source_ext_str("(function ext() {})();");
v8::Local<v8::String> source =
v8::String::NewExternalTwoByte(CcTest::isolate(), &source_ext_str)
v8::String::NewExternalTwoByte(isolate(), &source_ext_str)
.ToLocalChecked();
// Script needs to have a name in order to trigger InitLineEnds execution.
v8::Local<v8::String> origin =
v8::String::NewFromUtf8Literal(CcTest::isolate(), "issue-23768-test");
v8::String::NewFromUtf8Literal(isolate(), "issue-23768-test");
v8::Local<v8::Script> evil_script = CompileWithOrigin(source, origin, false);
CHECK(!evil_script.IsEmpty());
CHECK(!evil_script->Run(env).IsEmpty());
i::Handle<i::ExternalTwoByteString> i_source(
i::ExternalTwoByteString::cast(*v8::Utils::OpenHandle(*source)),
CcTest::i_isolate());
i_isolate());
// This situation can happen if source was an external string disposed
// by its owner.
i_source->SetResource(CcTest::i_isolate(), nullptr);
i_source->SetResource(i_isolate(), nullptr);
// Must not crash.
CcTest::i_isolate()->logger()->LogCompiledFunctions();
i_isolate()->logger()->LogCompiledFunctions();
}
static void ObjMethod1(const v8::FunctionCallbackInfo<v8::Value>& args) {
}
static void ObjMethod1(const v8::FunctionCallbackInfo<v8::Value>& args) {}
UNINITIALIZED_TEST(LogCallbacks) {
SETUP_FLAGS();
v8::Isolate::CreateParams create_params;
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
v8::Isolate* isolate = v8::Isolate::New(create_params);
TEST_F(LogTest, LogCallbacks) {
{
ScopedLoggerInitializer logger(isolate);
ScopedLoggerInitializer logger(isolate());
v8::Local<v8::FunctionTemplate> obj = v8::Local<v8::FunctionTemplate>::New(
isolate, v8::FunctionTemplate::New(isolate));
obj->SetClassName(v8_str("Obj"));
isolate(), v8::FunctionTemplate::New(isolate()));
obj->SetClassName(NewString("Obj"));
v8::Local<v8::ObjectTemplate> proto = obj->PrototypeTemplate();
v8::Local<v8::Signature> signature = v8::Signature::New(isolate, obj);
proto->Set(v8_str("method1"),
v8::FunctionTemplate::New(isolate, ObjMethod1,
v8::Local<v8::Signature> signature = v8::Signature::New(isolate(), obj);
proto->Set(NewString("method1"),
v8::FunctionTemplate::New(isolate(), ObjMethod1,
v8::Local<v8::Value>(), signature),
static_cast<v8::PropertyAttribute>(v8::DontDelete));
logger.env()
->Global()
->Set(logger.env(), v8_str("Obj"),
->Set(logger.env(), NewString("Obj"),
obj->GetFunction(logger.env()).ToLocalChecked())
.FromJust();
CompileRun("Obj.prototype.method1.toString();");
RunJS("Obj.prototype.method1.toString();");
logger.LogCompiledFunctions();
logger.StopLogging();
@ -359,36 +362,28 @@ UNINITIALIZED_TEST(LogCallbacks) {
CHECK(logger.ContainsLine(
{"code-creation,Callback,-2,", std::string(suffix_buffer.begin())}));
}
isolate->Dispose();
}
static void Prop1Getter(v8::Local<v8::String> property,
const v8::PropertyCallbackInfo<v8::Value>& info) {
}
const v8::PropertyCallbackInfo<v8::Value>& info) {}
static void Prop1Setter(v8::Local<v8::String> property,
v8::Local<v8::Value> value,
const v8::PropertyCallbackInfo<void>& info) {
}
const v8::PropertyCallbackInfo<void>& info) {}
static void Prop2Getter(v8::Local<v8::String> property,
const v8::PropertyCallbackInfo<v8::Value>& info) {
}
const v8::PropertyCallbackInfo<v8::Value>& info) {}
UNINITIALIZED_TEST(LogAccessorCallbacks) {
SETUP_FLAGS();
v8::Isolate::CreateParams create_params;
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
v8::Isolate* isolate = v8::Isolate::New(create_params);
TEST_F(LogTest, LogAccessorCallbacks) {
{
ScopedLoggerInitializer logger(isolate);
ScopedLoggerInitializer logger(isolate());
v8::Local<v8::FunctionTemplate> obj = v8::Local<v8::FunctionTemplate>::New(
isolate, v8::FunctionTemplate::New(isolate));
obj->SetClassName(v8_str("Obj"));
isolate(), v8::FunctionTemplate::New(isolate()));
obj->SetClassName(NewString("Obj"));
v8::Local<v8::ObjectTemplate> inst = obj->InstanceTemplate();
inst->SetAccessor(v8_str("prop1"), Prop1Getter, Prop1Setter);
inst->SetAccessor(v8_str("prop2"), Prop2Getter);
inst->SetAccessor(NewString("prop1"), Prop1Getter, Prop1Setter);
inst->SetAccessor(NewString("prop2"), Prop2Getter);
logger.logger()->LogAccessorCallbacks();
@ -424,16 +419,11 @@ UNINITIALIZED_TEST(LogAccessorCallbacks) {
CHECK(logger.ContainsLine({"code-creation,Callback,-2,",
std::string(prop2_getter_record.begin())}));
}
isolate->Dispose();
}
UNINITIALIZED_TEST(LogVersion) {
SETUP_FLAGS();
v8::Isolate::CreateParams create_params;
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
v8::Isolate* isolate = v8::Isolate::New(create_params);
TEST_F(LogTest, LogVersion) {
{
ScopedLoggerInitializer logger(isolate);
ScopedLoggerInitializer logger(isolate());
logger.StopLogging();
v8::base::EmbeddedVector<char, 100> line_buffer;
@ -443,12 +433,11 @@ UNINITIALIZED_TEST(LogVersion) {
CHECK(
logger.ContainsLine({"v8-version,", std::string(line_buffer.begin())}));
}
isolate->Dispose();
}
// https://crbug.com/539892
// CodeCreateEvents with really large names should not crash.
UNINITIALIZED_TEST(Issue539892) {
TEST_F(LogTest, Issue539892) {
class FakeCodeEventLogger : public i::CodeEventLogger {
public:
explicit FakeCodeEventLogger(i::Isolate* isolate)
@ -469,14 +458,10 @@ UNINITIALIZED_TEST(Issue539892) {
#endif // V8_ENABLE_WEBASSEMBLY
};
SETUP_FLAGS();
v8::Isolate::CreateParams create_params;
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
v8::Isolate* isolate = v8::Isolate::New(create_params);
FakeCodeEventLogger code_event_logger(reinterpret_cast<i::Isolate*>(isolate));
FakeCodeEventLogger code_event_logger(i_isolate());
{
ScopedLoggerInitializer logger(isolate);
ScopedLoggerInitializer logger(isolate());
logger.logger()->AddLogEventListener(&code_event_logger);
// Function with a really large name.
@ -501,27 +486,29 @@ UNINITIALIZED_TEST(Issue539892) {
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaac"
"(){})();";
CompileRun(source_text);
RunJS(source_text);
// Must not crash.
logger.LogCompiledFunctions();
logger.logger()->RemoveLogEventListener(&code_event_logger);
}
isolate->Dispose();
}
UNINITIALIZED_TEST(LogAll) {
SETUP_FLAGS();
i::FLAG_log_all = true;
i::FLAG_log_deopt = true;
i::FLAG_turbo_inlining = false;
i::FLAG_log_internal_timer_events = true;
i::FLAG_allow_natives_syntax = true;
v8::Isolate::CreateParams create_params;
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
v8::Isolate* isolate = v8::Isolate::New(create_params);
class LogAllTest : public LogTest {
public:
static void SetUpTestSuite() {
i::FLAG_log_all = true;
i::FLAG_log_deopt = true;
i::FLAG_turbo_inlining = false;
i::FLAG_log_internal_timer_events = true;
i::FLAG_allow_natives_syntax = true;
LogTest::SetUpTestSuite();
}
};
TEST_F(LogAllTest, LogAll) {
{
ScopedLoggerInitializer logger(isolate);
ScopedLoggerInitializer logger(isolate());
const char* source_text = R"(
function testAddFn(a,b) {
@ -545,7 +532,7 @@ UNINITIALIZED_TEST(LogAll) {
result = testAddFn('1', i);
}
)";
CompileRun(source_text);
RunJS(source_text);
logger.StopLogging();
@ -561,24 +548,26 @@ UNINITIALIZED_TEST(LogAll) {
CHECK(logger.ContainsLine({"timer-event-end", "V8.DeoptimizeCode"}));
}
}
isolate->Dispose();
}
#ifndef V8_TARGET_ARCH_ARM
UNINITIALIZED_TEST(LogInterpretedFramesNativeStack) {
SETUP_FLAGS();
i::FLAG_interpreted_frames_native_stack = true;
v8::Isolate::CreateParams create_params;
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
v8::Isolate* isolate = v8::Isolate::New(create_params);
class LogInterpretedFramesNativeStackTest : public LogTest {
public:
static void SetUpTestSuite() {
i::FLAG_interpreted_frames_native_stack = true;
LogTest::SetUpTestSuite();
}
};
TEST_F(LogInterpretedFramesNativeStackTest, LogInterpretedFramesNativeStack) {
{
ScopedLoggerInitializer logger(isolate);
ScopedLoggerInitializer logger(isolate());
const char* source_text =
"function testLogInterpretedFramesNativeStack(a,b) { return a + b };"
"testLogInterpretedFramesNativeStack('1', 1);";
CompileRun(source_text);
RunJS(source_text);
logger.StopLogging();
@ -586,15 +575,42 @@ UNINITIALIZED_TEST(LogInterpretedFramesNativeStack) {
{{"LazyCompile", "testLogInterpretedFramesNativeStack"},
{"LazyCompile", "testLogInterpretedFramesNativeStack"}}));
}
isolate->Dispose();
}
UNINITIALIZED_TEST(LogInterpretedFramesNativeStackWithSerialization) {
SETUP_FLAGS();
i::FLAG_interpreted_frames_native_stack = true;
i::FLAG_always_turbofan = false;
class LogInterpretedFramesNativeStackWithSerializationTest
: public TestWithPlatform {
public:
LogInterpretedFramesNativeStackWithSerializationTest()
: array_buffer_allocator_(
v8::ArrayBuffer::Allocator::NewDefaultAllocator()) {}
static void SetUpTestSuite() {
i::FLAG_log = true;
i::FLAG_prof = true;
i::FLAG_log_code = true;
i::FLAG_logfile = i::LogFile::kLogToTemporaryFile;
i::FLAG_logfile_per_isolate = false;
i::FLAG_interpreted_frames_native_stack = true;
i::FLAG_always_turbofan = false;
TestWithPlatform::SetUpTestSuite();
}
v8::Local<v8::String> NewString(const char* source) {
return v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), source)
.ToLocalChecked();
}
v8::ArrayBuffer::Allocator* array_buffer_allocator() {
return array_buffer_allocator_.get();
}
private:
std::unique_ptr<v8::ArrayBuffer::Allocator> array_buffer_allocator_;
};
TEST_F(LogInterpretedFramesNativeStackWithSerializationTest,
LogInterpretedFramesNativeStackWithSerialization) {
v8::Isolate::CreateParams create_params;
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
create_params.array_buffer_allocator = array_buffer_allocator();
v8::ScriptCompiler::CachedData* cache = nullptr;
@ -618,10 +634,10 @@ UNINITIALIZED_TEST(LogInterpretedFramesNativeStackWithSerialization) {
v8::HandleScope scope(isolate);
v8::Isolate::Scope isolate_scope(isolate);
v8::Local<v8::Context> context = v8::Context::New(isolate);
v8::Local<v8::String> source = v8_str(
v8::Local<v8::String> source = NewString(
"function eyecatcher() { return a * a; } return eyecatcher();");
v8::Local<v8::String> arg_str = v8_str("a");
v8::ScriptOrigin origin(isolate, v8_str("filename"));
v8::Local<v8::String> arg_str = NewString("a");
v8::ScriptOrigin origin(isolate, NewString("filename"));
i::DisallowCompilation* no_compile_expected =
has_cache ? new i::DisallowCompilation(
@ -641,7 +657,7 @@ UNINITIALIZED_TEST(LogInterpretedFramesNativeStackWithSerialization) {
CHECK(logger.ContainsLinesInOrder(
{{"Function", "eyecatcher"}, {"Function", "eyecatcher"}}));
}
v8::Local<v8::Value> arg = v8_num(3);
v8::Local<v8::Value> arg = Number::New(isolate, 3);
v8::Local<v8::Value> result =
fun->Call(context, v8::Undefined(isolate), 1, &arg).ToLocalChecked();
CHECK_EQ(9, result->Int32Value(context).FromJust());
@ -656,26 +672,28 @@ UNINITIALIZED_TEST(LogInterpretedFramesNativeStackWithSerialization) {
}
#endif // V8_TARGET_ARCH_ARM
UNINITIALIZED_TEST(ExternalLogEventListener) {
i::FLAG_log = false;
i::FLAG_prof = false;
v8::Isolate::CreateParams create_params;
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
v8::Isolate* isolate = v8::Isolate::New(create_params);
class LogExternalLogEventListenerTest : public TestWithIsolate {
public:
static void SetUpTestSuite() {
i::FLAG_log = false;
i::FLAG_prof = false;
TestWithIsolate::SetUpTestSuite();
}
};
TEST_F(LogExternalLogEventListenerTest, ExternalLogEventListener) {
{
v8::HandleScope scope(isolate);
v8::Isolate::Scope isolate_scope(isolate);
v8::Local<v8::Context> context = v8::Context::New(isolate);
v8::HandleScope scope(isolate());
v8::Isolate::Scope isolate_scope(isolate());
v8::Local<v8::Context> context = v8::Context::New(isolate());
v8::Context::Scope context_scope(context);
TestCodeEventHandler code_event_handler(isolate);
TestCodeEventHandler code_event_handler(isolate());
const char* source_text_before_start =
"function testLogEventListenerBeforeStart(a,b) { return a + b };"
"testLogEventListenerBeforeStart('1', 1);";
CompileRun(source_text_before_start);
RunJS(source_text_before_start);
CHECK_EQ(code_event_handler.CountLines("Function",
"testLogEventListenerBeforeStart"),
@ -693,25 +711,46 @@ UNINITIALIZED_TEST(ExternalLogEventListener) {
const char* source_text_after_start =
"function testLogEventListenerAfterStart(a,b) { return a + b };"
"testLogEventListenerAfterStart('1', 1);";
CompileRun(source_text_after_start);
RunJS(source_text_after_start);
CHECK_GE(code_event_handler.CountLines("LazyCompile",
"testLogEventListenerAfterStart"),
1);
}
isolate->Dispose();
}
UNINITIALIZED_TEST(ExternalLogEventListenerInnerFunctions) {
i::FLAG_log = false;
i::FLAG_prof = false;
class LogExternalLogEventListenerInnerFunctionTest : public TestWithPlatform {
public:
LogExternalLogEventListenerInnerFunctionTest()
: array_buffer_allocator_(
v8::ArrayBuffer::Allocator::NewDefaultAllocator()) {}
static void SetUpTestSuite() {
i::FLAG_log = false;
i::FLAG_prof = false;
TestWithPlatform::SetUpTestSuite();
}
v8::ArrayBuffer::Allocator* array_buffer_allocator() {
return array_buffer_allocator_.get();
}
v8::Local<v8::String> NewString(const char* source) {
return v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), source)
.ToLocalChecked();
}
private:
std::unique_ptr<v8::ArrayBuffer::Allocator> array_buffer_allocator_;
};
TEST_F(LogExternalLogEventListenerInnerFunctionTest,
ExternalLogEventListenerInnerFunctions) {
v8::ScriptCompiler::CachedData* cache;
static const char* source_cstring =
"(function f1() { return (function f2() {}); })()";
v8::Isolate::CreateParams create_params;
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
create_params.array_buffer_allocator = array_buffer_allocator();
v8::Isolate* isolate1 = v8::Isolate::New(create_params);
{ // Test that we emit the correct code events from eagerly compiling.
v8::HandleScope scope(isolate1);
@ -722,8 +761,8 @@ UNINITIALIZED_TEST(ExternalLogEventListenerInnerFunctions) {
TestCodeEventHandler code_event_handler(isolate1);
code_event_handler.Enable();
v8::Local<v8::String> source_string = v8_str(source_cstring);
v8::ScriptOrigin origin(isolate1, v8_str("test"));
v8::Local<v8::String> source_string = NewString(source_cstring);
v8::ScriptOrigin origin(isolate1, NewString("test"));
v8::ScriptCompiler::Source source(source_string, origin);
v8::Local<v8::UnboundScript> script =
v8::ScriptCompiler::CompileUnboundScript(isolate1, &source)
@ -748,8 +787,8 @@ UNINITIALIZED_TEST(ExternalLogEventListenerInnerFunctions) {
TestCodeEventHandler code_event_handler(isolate2);
code_event_handler.Enable();
v8::Local<v8::String> source_string = v8_str(source_cstring);
v8::ScriptOrigin origin(isolate2, v8_str("test"));
v8::Local<v8::String> source_string = NewString(source_cstring);
v8::ScriptOrigin origin(isolate2, NewString("test"));
v8::ScriptCompiler::Source source(source_string, origin, cache);
{
i::DisallowCompilation no_compile_expected(
@ -765,27 +804,30 @@ UNINITIALIZED_TEST(ExternalLogEventListenerInnerFunctions) {
}
#ifndef V8_TARGET_ARCH_ARM
UNINITIALIZED_TEST(ExternalLogEventListenerWithInterpretedFramesNativeStack) {
i::FLAG_log = false;
i::FLAG_prof = false;
i::FLAG_interpreted_frames_native_stack = true;
v8::Isolate::CreateParams create_params;
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
v8::Isolate* isolate = v8::Isolate::New(create_params);
class LogExternalInterpretedFramesNativeStackTest : public TestWithIsolate {
public:
static void SetUpTestSuite() {
i::FLAG_log = false;
i::FLAG_prof = false;
i::FLAG_interpreted_frames_native_stack = true;
TestWithIsolate::SetUpTestSuite();
}
};
TEST_F(LogExternalInterpretedFramesNativeStackTest,
ExternalLogEventListenerWithInterpretedFramesNativeStack) {
{
v8::HandleScope scope(isolate);
v8::Isolate::Scope isolate_scope(isolate);
v8::Local<v8::Context> context = v8::Context::New(isolate);
v8::HandleScope scope(isolate());
v8::Isolate::Scope isolate_scope(isolate());
v8::Local<v8::Context> context = v8::Context::New(isolate());
context->Enter();
TestCodeEventHandler code_event_handler(isolate);
TestCodeEventHandler code_event_handler(isolate());
const char* source_text_before_start =
"function testLogEventListenerBeforeStart(a,b) { return a + b };"
"testLogEventListenerBeforeStart('1', 1);";
CompileRun(source_text_before_start);
RunJS(source_text_before_start);
CHECK_EQ(code_event_handler.CountLines("Function",
"testLogEventListenerBeforeStart"),
@ -800,7 +842,7 @@ UNINITIALIZED_TEST(ExternalLogEventListenerWithInterpretedFramesNativeStack) {
const char* source_text_after_start =
"function testLogEventListenerAfterStart(a,b) { return a + b };"
"testLogEventListenerAfterStart('1', 1);";
CompileRun(source_text_after_start);
RunJS(source_text_after_start);
CHECK_GE(code_event_handler.CountLines("LazyCompile",
"testLogEventListenerAfterStart"),
@ -812,18 +854,19 @@ UNINITIALIZED_TEST(ExternalLogEventListenerWithInterpretedFramesNativeStack) {
context->Exit();
}
isolate->Dispose();
}
#endif // V8_TARGET_ARCH_ARM
UNINITIALIZED_TEST(TraceMaps) {
SETUP_FLAGS();
i::FLAG_log_maps = true;
v8::Isolate::CreateParams create_params;
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
v8::Isolate* isolate = v8::Isolate::New(create_params);
class LogMapsTest : public LogTest {
public:
static void SetUpTestSuite() {
i::FLAG_log_maps = true;
LogTest::SetUpTestSuite();
}
};
TEST_F(LogMapsTest, TraceMaps) {
{
ScopedLoggerInitializer logger(isolate);
ScopedLoggerInitializer logger(isolate());
// Try to create many different kind of maps to make sure the logging won't
// crash. More detailed tests are implemented separately.
const char* source_text = R"(
@ -844,7 +887,7 @@ UNINITIALIZED_TEST(TraceMaps) {
};
t.b = {};
)";
CompileRunChecked(isolate, source_text);
RunJS(source_text);
logger.StopLogging();
@ -853,8 +896,6 @@ UNINITIALIZED_TEST(TraceMaps) {
CHECK(logger.ContainsLine({"map,Transition", ",0x"}));
CHECK(logger.ContainsLine({"map-details", ",0x"}));
}
i::FLAG_log_maps = false;
isolate->Dispose();
}
namespace {
@ -903,40 +944,36 @@ void ValidateMapDetailsLogging(v8::Isolate* isolate,
} // namespace
UNINITIALIZED_TEST(LogMapsDetailsStartup) {
TEST_F(LogMapsTest, LogMapsDetailsStartup) {
// Reusing map addresses might cause these tests to fail.
if (i::FLAG_gc_global || i::FLAG_stress_compaction ||
i::FLAG_stress_incremental_marking || i::FLAG_enable_third_party_heap) {
return;
}
// Test that all Map details from Maps in the snapshot are logged properly.
SETUP_FLAGS();
i::FLAG_log_maps = true;
v8::Isolate::CreateParams create_params;
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
v8::Isolate* isolate = v8::Isolate::New(create_params);
{
ScopedLoggerInitializer logger(isolate);
ScopedLoggerInitializer logger(isolate());
logger.StopLogging();
ValidateMapDetailsLogging(isolate, &logger);
ValidateMapDetailsLogging(isolate(), &logger);
}
i::FLAG_log_function_events = false;
isolate->Dispose();
}
UNINITIALIZED_TEST(LogMapsDetailsCode) {
class LogMapsCodeTest : public LogTest {
public:
static void SetUpTestSuite() {
i::FLAG_retain_maps_for_n_gc = 0xFFFFFFF;
i::FLAG_log_maps = true;
LogTest::SetUpTestSuite();
}
};
TEST_F(LogMapsCodeTest, LogMapsDetailsCode) {
// Reusing map addresses might cause these tests to fail.
if (i::FLAG_gc_global || i::FLAG_stress_compaction ||
i::FLAG_stress_incremental_marking || i::FLAG_enable_third_party_heap) {
return;
}
SETUP_FLAGS();
i::FLAG_retain_maps_for_n_gc = 0xFFFFFFF;
i::FLAG_log_maps = true;
v8::Isolate::CreateParams create_params;
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
v8::Isolate* isolate = v8::Isolate::New(create_params);
const char* source = R"(
// Normal properties overflowing into dict-mode.
let a = {};
@ -1012,65 +1049,49 @@ UNINITIALIZED_TEST(LogMapsDetailsCode) {
[1,2,3].helper();
)";
{
ScopedLoggerInitializer logger(isolate);
CompileRunChecked(isolate, source);
ScopedLoggerInitializer logger(isolate());
RunJS(source);
logger.StopLogging();
ValidateMapDetailsLogging(isolate, &logger);
ValidateMapDetailsLogging(isolate(), &logger);
}
i::FLAG_log_function_events = false;
isolate->Dispose();
}
UNINITIALIZED_TEST(LogMapsDetailsContexts) {
TEST_F(LogMapsTest, LogMapsDetailsContexts) {
// Reusing map addresses might cause these tests to fail.
if (i::FLAG_gc_global || i::FLAG_stress_compaction ||
i::FLAG_stress_incremental_marking || i::FLAG_enable_third_party_heap) {
return;
}
// Test that all Map details from Maps in the snapshot are logged properly.
SETUP_FLAGS();
i::FLAG_log_maps = true;
v8::Isolate::CreateParams create_params;
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
v8::Isolate* isolate = v8::Isolate::New(create_params);
{
ScopedLoggerInitializer logger(isolate);
ScopedLoggerInitializer logger(isolate());
// Use the default context.
CompileRunChecked(isolate, "{a:1}");
RunJS("{a:1}");
// Create additional contexts.
v8::Local<v8::Context> env1 = v8::Context::New(isolate);
v8::Local<v8::Context> env1 = v8::Context::New(isolate());
env1->Enter();
CompileRun(env1, "{b:1}").ToLocalChecked();
RunJS("{b:1}");
v8::Local<v8::Context> env2 = v8::Context::New(isolate);
v8::Local<v8::Context> env2 = v8::Context::New(isolate());
env2->Enter();
CompileRun(env2, "{c:1}").ToLocalChecked();
RunJS("{c:1}");
env2->Exit();
env1->Exit();
logger.StopLogging();
ValidateMapDetailsLogging(isolate, &logger);
ValidateMapDetailsLogging(isolate(), &logger);
}
i::FLAG_log_function_events = false;
isolate->Dispose();
}
UNINITIALIZED_TEST(ConsoleTimeEvents) {
SETUP_FLAGS();
v8::Isolate::CreateParams create_params;
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
v8::Isolate* isolate = v8::Isolate::New(create_params);
TEST_F(LogTest, ConsoleTimeEvents) {
{
ScopedLoggerInitializer logger(isolate);
ScopedLoggerInitializer logger(isolate());
{
// setup console global.
v8::HandleScope scope(isolate);
v8::HandleScope scope(isolate());
v8::Local<v8::String> name = v8::String::NewFromUtf8Literal(
isolate, "console", v8::NewStringType::kInternalized);
v8::Local<v8::Context> context = isolate->GetCurrentContext();
isolate(), "console", v8::NewStringType::kInternalized);
v8::Local<v8::Context> context = isolate()->GetCurrentContext();
v8::Local<v8::Value> console = context->GetExtrasBindingObject()
->Get(context, name)
.ToLocalChecked();
@ -1085,7 +1106,7 @@ UNINITIALIZED_TEST(ConsoleTimeEvents) {
"console.timeEnd('timerEvent1');"
"console.timeStamp('timerEvent2');"
"console.timeStamp('timerEvent3');";
CompileRun(source_text);
RunJS(source_text);
logger.StopLogging();
@ -1096,25 +1117,25 @@ UNINITIALIZED_TEST(ConsoleTimeEvents) {
{"timer-event,timerEvent3,"}};
CHECK(logger.ContainsLinesInOrder(lines));
}
isolate->Dispose();
}
UNINITIALIZED_TEST(LogFunctionEvents) {
class LogFunctionEventsTest : public LogTest {
public:
static void SetUpTestSuite() {
i::FLAG_log_function_events = true;
LogTest::SetUpTestSuite();
}
};
TEST_F(LogFunctionEventsTest, LogFunctionEvents) {
// Always opt and stress opt will break the fine-grained log order.
if (i::FLAG_always_turbofan) return;
SETUP_FLAGS();
i::FLAG_log_function_events = true;
v8::Isolate::CreateParams create_params;
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
v8::Isolate* isolate = v8::Isolate::New(create_params);
{
ScopedLoggerInitializer logger(isolate);
ScopedLoggerInitializer logger(isolate());
// Run some warmup code to help ignoring existing log entries.
CompileRun(
RunJS(
"function warmUp(a) {"
" let b = () => 1;"
" return function(c) { return a+b+c; };"
@ -1133,7 +1154,7 @@ UNINITIALIZED_TEST(LogFunctionEvents) {
"(function eagerFunction(){ return 'eager' })();"
"function Foo() { this.foo = function(){}; };"
"let i = new Foo(); i.foo();";
CompileRun(source_text);
RunJS(source_text);
logger.StopLogging();
@ -1176,17 +1197,11 @@ UNINITIALIZED_TEST(LogFunctionEvents) {
};
CHECK(logger.ContainsLinesInOrder(lines));
}
i::FLAG_log_function_events = false;
isolate->Dispose();
}
UNINITIALIZED_TEST(BuiltinsNotLoggedAsLazyCompile) {
SETUP_FLAGS();
v8::Isolate::CreateParams create_params;
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
v8::Isolate* isolate = v8::Isolate::New(create_params);
TEST_F(LogTest, BuiltinsNotLoggedAsLazyCompile) {
{
ScopedLoggerInitializer logger(isolate);
ScopedLoggerInitializer logger(isolate());
logger.LogCodeObjects();
logger.LogCompiledFunctions();
@ -1209,5 +1224,5 @@ UNINITIALIZED_TEST(BuiltinsNotLoggedAsLazyCompile) {
CHECK(!logger.ContainsLine(
{"code-creation,LazyCompile,2,", std::string(buffer.begin())}));
}
isolate->Dispose();
}
} // namespace v8

View File

@ -137,6 +137,16 @@ class WithIsolateScopeMixin : public TMixin {
.ToLocalChecked());
}
Local<Script> CompileWithOrigin(Local<String> source,
Local<String> origin_url,
bool is_shared_cross_origin) {
Isolate* isolate = Isolate::GetCurrent();
ScriptOrigin origin(isolate, origin_url, 0, 0, is_shared_cross_origin);
ScriptCompiler::Source script_source(source, origin);
return ScriptCompiler::Compile(isolate->GetCurrentContext(), &script_source)
.ToLocalChecked();
}
void CollectGarbage(i::AllocationSpace space) {
i_isolate()->heap()->CollectGarbage(space,
i::GarbageCollectionReason::kTesting);

View File

@ -117,6 +117,23 @@
'LoggingTest.SourceLocation':[SKIP] # issue-174
}],
##############################################################################
['lite_mode', {
# TODO(mythria): Code logging tests that currently fail with lazy feedback
# allocation. Fix logging to work without feedback vectors and enable these
# tests in lite_mode.
'LogExternalInterpretedFramesNativeStackTest.ExternalLogEventListenerWithInterpretedFramesNativeStack': [SKIP],
'LogInterpretedFramesNativeStackTest.LogInterpretedFramesNativeStack': [SKIP],
'LogInterpretedFramesNativeStackWithSerializationTest.LogInterpretedFramesNativeStackWithSerialization': [SKIP],
}], # lite_mode
['variant == jitless', {
# --interpreted-frames-native-stack tests
'LogExternalInterpretedFramesNativeStackTest.ExternalLogEventListenerWithInterpretedFramesNativeStack': [SKIP],
'LogInterpretedFramesNativeStackTest.LogInterpretedFramesNativeStack': [SKIP],
'LogInterpretedFramesNativeStackWithSerializationTest.LogInterpretedFramesNativeStackWithSerialization': [SKIP],
}], # jitless
################################################################################
['third_party_heap', {
# Tests on OptimizingCompileDispatcher
@ -140,6 +157,8 @@
'SpacesTest.WriteBarrierInYoungGenerationFromSpace': [SKIP],
# Requires a second isolate
'ValueSerializerTest.DecodeArrayBufferOOM': [SKIP],
'LogExternalLogEventListenerInnerFunctionTest.ExternalLogEventListenerInnerFunctions': [SKIP],
'LogInterpretedFramesNativeStackWithSerializationTest.LogInterpretedFramesNativeStackWithSerialization': [SKIP],
# Performs GC
'APIExceptionTest.ExceptionMessageDoesNotKeepContextAlive': [SKIP],
'LocalHeapTest.GCEpilogue': [SKIP],
@ -188,7 +207,17 @@
##############################################################################
['variant == no_wasm_traps', {
'APIExceptionTest.*': [SKIP],
'LogTest.*': [SKIP],
'TestWithIsolate.Issue23768': [SKIP],
'LogAllTest.LogAll': [SKIP],
'LogInterpretedFramesNativeStackTest.LogInterpretedFramesNativeStack': [SKIP],
'LogInterpretedFramesNativeStackWithSerializationTest.LogInterpretedFramesNativeStackWithSerialization': [SKIP],
'LogExternalLogEventListenerTest.ExternalLogEventListener': [SKIP],
'LogExternalLogEventListenerInnerFunctionTest.ExternalLogEventListenerInnerFunctions': [SKIP],
'LogExternalInterpretedFramesNativeStackTest.ExternalLogEventListenerWithInterpretedFramesNativeStack': [SKIP],
'LogMapsTest.*': [SKIP],
'LogMapsCodeTest.LogMapsDetailsCode': [SKIP],
'LogFunctionEventsTest.LogFunctionEvents': [SKIP],
}], # variant == no_wasm_traps
##############################################################################