Commit c84b8fa4 authored by Nico Hartmann's avatar Nico Hartmann Committed by V8 LUCI CQ

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

This reverts commit f196c878.

Reason for revert: https://crbug.com/v8/12838

Original change's description:
> [test] Move cctest/test-log to unittests/logging/log-unittest
>
> Bug: v8:12781
> Change-Id: If94de50440b15f000ff2f961f2dd77abd9c90ca4
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3607389
> Reviewed-by: Leszek Swirski <leszeks@chromium.org>
> Commit-Queue: 王澳 <wangao.james@bytedance.com>
> Cr-Commit-Position: refs/heads/main@{#80209}

Bug: v8:12781
Change-Id: I9e2d9496f16581ebbb851fb207191d6b77b51c0d
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3610448
Auto-Submit: Nico Hartmann <nicohartmann@chromium.org>
Commit-Queue: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Cr-Commit-Position: refs/heads/main@{#80220}
parent ce100720
...@@ -232,6 +232,7 @@ v8_source_set("cctest_sources") { ...@@ -232,6 +232,7 @@ v8_source_set("cctest_sources") {
"test-liveedit.cc", "test-liveedit.cc",
"test-local-handles.cc", "test-local-handles.cc",
"test-lockers.cc", "test-lockers.cc",
"test-log.cc",
"test-managed.cc", "test-managed.cc",
"test-mementos.cc", "test-mementos.cc",
"test-orderedhashtable.cc", "test-orderedhashtable.cc",
......
// Copyright 2022 the V8 project authors. All rights reserved. // Copyright 2006-2009 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Redistribution and use in source and binary forms, with or without
// found in the LICENSE file. // modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Tests of logging functions from log.h // Tests of logging functions from log.h
#include "src/logging/log.h"
#include <unordered_set> #include <unordered_set>
#include <vector> #include <vector>
...@@ -17,19 +38,17 @@ ...@@ -17,19 +38,17 @@
#include "src/execution/vm-state-inl.h" #include "src/execution/vm-state-inl.h"
#include "src/init/v8.h" #include "src/init/v8.h"
#include "src/logging/log-utils.h" #include "src/logging/log-utils.h"
#include "src/logging/log.h"
#include "src/objects/objects-inl.h" #include "src/objects/objects-inl.h"
#include "src/profiler/cpu-profiler.h" #include "src/profiler/cpu-profiler.h"
#include "src/utils/ostreams.h" #include "src/utils/ostreams.h"
#include "src/utils/version.h" #include "src/utils/version.h"
#include "test/unittests/test-utils.h" #include "test/cctest/cctest.h"
#include "testing/gtest/include/gtest/gtest.h"
using v8::base::EmbeddedVector; using v8::base::EmbeddedVector;
using v8::internal::Address; using v8::internal::Address;
using v8::internal::V8FileLogger; using v8::internal::V8FileLogger;
namespace v8 {
namespace { namespace {
#define SETUP_FLAGS() \ #define SETUP_FLAGS() \
...@@ -49,16 +68,6 @@ static std::vector<std::string> Split(const std::string& s, char delimiter) { ...@@ -49,16 +68,6 @@ static std::vector<std::string> Split(const std::string& s, char delimiter) {
return result; return result;
} }
class LogTest : public TestWithIsolate {
public:
static void SetUpTestSuite() {
SETUP_FLAGS();
TestWithIsolate::SetUpTestSuite();
}
static void TearDownTestSuite() { TestWithIsolate::TearDownTestSuite(); }
};
class V8_NODISCARD ScopedLoggerInitializer { class V8_NODISCARD ScopedLoggerInitializer {
public: public:
explicit ScopedLoggerInitializer(v8::Isolate* isolate) explicit ScopedLoggerInitializer(v8::Isolate* isolate)
...@@ -283,54 +292,59 @@ class SimpleExternalString : public v8::String::ExternalStringResource { ...@@ -283,54 +292,59 @@ class SimpleExternalString : public v8::String::ExternalStringResource {
} // namespace } // namespace
TEST_F(LogTest, Issue23768) { TEST(Issue23768) {
v8::HandleScope scope(isolate()); v8::HandleScope scope(CcTest::isolate());
v8::Local<v8::Context> env = v8::Context::New(isolate()); v8::Local<v8::Context> env = v8::Context::New(CcTest::isolate());
env->Enter(); env->Enter();
SimpleExternalString source_ext_str("(function ext() {})();"); SimpleExternalString source_ext_str("(function ext() {})();");
v8::Local<v8::String> source = v8::Local<v8::String> source =
v8::String::NewExternalTwoByte(isolate(), &source_ext_str) v8::String::NewExternalTwoByte(CcTest::isolate(), &source_ext_str)
.ToLocalChecked(); .ToLocalChecked();
// Script needs to have a name in order to trigger InitLineEnds execution. // Script needs to have a name in order to trigger InitLineEnds execution.
v8::Local<v8::String> origin = v8::Local<v8::String> origin =
v8::String::NewFromUtf8Literal(isolate(), "issue-23768-test"); v8::String::NewFromUtf8Literal(CcTest::isolate(), "issue-23768-test");
v8::Local<v8::Script> evil_script = CompileWithOrigin(source, origin, false); v8::Local<v8::Script> evil_script = CompileWithOrigin(source, origin, false);
CHECK(!evil_script.IsEmpty()); CHECK(!evil_script.IsEmpty());
CHECK(!evil_script->Run(env).IsEmpty()); CHECK(!evil_script->Run(env).IsEmpty());
i::Handle<i::ExternalTwoByteString> i_source( i::Handle<i::ExternalTwoByteString> i_source(
i::ExternalTwoByteString::cast(*v8::Utils::OpenHandle(*source)), i::ExternalTwoByteString::cast(*v8::Utils::OpenHandle(*source)),
i_isolate()); CcTest::i_isolate());
// This situation can happen if source was an external string disposed // This situation can happen if source was an external string disposed
// by its owner. // by its owner.
i_source->SetResource(i_isolate(), nullptr); i_source->SetResource(CcTest::i_isolate(), nullptr);
// Must not crash. // Must not crash.
i_isolate()->logger()->LogCompiledFunctions(); CcTest::i_isolate()->logger()->LogCompiledFunctions();
} }
static void ObjMethod1(const v8::FunctionCallbackInfo<v8::Value>& args) {} static void ObjMethod1(const v8::FunctionCallbackInfo<v8::Value>& args) {
}
TEST_F(LogTest, LogCallbacks) { 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);
{ {
ScopedLoggerInitializer logger(isolate()); ScopedLoggerInitializer logger(isolate);
v8::Local<v8::FunctionTemplate> obj = v8::Local<v8::FunctionTemplate>::New( v8::Local<v8::FunctionTemplate> obj = v8::Local<v8::FunctionTemplate>::New(
isolate(), v8::FunctionTemplate::New(isolate())); isolate, v8::FunctionTemplate::New(isolate));
obj->SetClassName(NewString("Obj")); obj->SetClassName(v8_str("Obj"));
v8::Local<v8::ObjectTemplate> proto = obj->PrototypeTemplate(); v8::Local<v8::ObjectTemplate> proto = obj->PrototypeTemplate();
v8::Local<v8::Signature> signature = v8::Signature::New(isolate(), obj); v8::Local<v8::Signature> signature = v8::Signature::New(isolate, obj);
proto->Set(NewString("method1"), proto->Set(v8_str("method1"),
v8::FunctionTemplate::New(isolate(), ObjMethod1, v8::FunctionTemplate::New(isolate, ObjMethod1,
v8::Local<v8::Value>(), signature), v8::Local<v8::Value>(), signature),
static_cast<v8::PropertyAttribute>(v8::DontDelete)); static_cast<v8::PropertyAttribute>(v8::DontDelete));
logger.env() logger.env()
->Global() ->Global()
->Set(logger.env(), NewString("Obj"), ->Set(logger.env(), v8_str("Obj"),
obj->GetFunction(logger.env()).ToLocalChecked()) obj->GetFunction(logger.env()).ToLocalChecked())
.FromJust(); .FromJust();
RunJS("Obj.prototype.method1.toString();"); CompileRun("Obj.prototype.method1.toString();");
logger.LogCompiledFunctions(); logger.LogCompiledFunctions();
logger.StopLogging(); logger.StopLogging();
...@@ -345,28 +359,36 @@ TEST_F(LogTest, LogCallbacks) { ...@@ -345,28 +359,36 @@ TEST_F(LogTest, LogCallbacks) {
CHECK(logger.ContainsLine( CHECK(logger.ContainsLine(
{"code-creation,Callback,-2,", std::string(suffix_buffer.begin())})); {"code-creation,Callback,-2,", std::string(suffix_buffer.begin())}));
} }
isolate->Dispose();
} }
static void Prop1Getter(v8::Local<v8::String> property, 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, static void Prop1Setter(v8::Local<v8::String> property,
v8::Local<v8::Value> value, v8::Local<v8::Value> value,
const v8::PropertyCallbackInfo<void>& info) {} const v8::PropertyCallbackInfo<void>& info) {
}
static void Prop2Getter(v8::Local<v8::String> property, static void Prop2Getter(v8::Local<v8::String> property,
const v8::PropertyCallbackInfo<v8::Value>& info) {} const v8::PropertyCallbackInfo<v8::Value>& info) {
}
TEST_F(LogTest, LogAccessorCallbacks) { 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);
{ {
ScopedLoggerInitializer logger(isolate()); ScopedLoggerInitializer logger(isolate);
v8::Local<v8::FunctionTemplate> obj = v8::Local<v8::FunctionTemplate>::New( v8::Local<v8::FunctionTemplate> obj = v8::Local<v8::FunctionTemplate>::New(
isolate(), v8::FunctionTemplate::New(isolate())); isolate, v8::FunctionTemplate::New(isolate));
obj->SetClassName(NewString("Obj")); obj->SetClassName(v8_str("Obj"));
v8::Local<v8::ObjectTemplate> inst = obj->InstanceTemplate(); v8::Local<v8::ObjectTemplate> inst = obj->InstanceTemplate();
inst->SetAccessor(NewString("prop1"), Prop1Getter, Prop1Setter); inst->SetAccessor(v8_str("prop1"), Prop1Getter, Prop1Setter);
inst->SetAccessor(NewString("prop2"), Prop2Getter); inst->SetAccessor(v8_str("prop2"), Prop2Getter);
logger.logger()->LogAccessorCallbacks(); logger.logger()->LogAccessorCallbacks();
...@@ -402,11 +424,16 @@ TEST_F(LogTest, LogAccessorCallbacks) { ...@@ -402,11 +424,16 @@ TEST_F(LogTest, LogAccessorCallbacks) {
CHECK(logger.ContainsLine({"code-creation,Callback,-2,", CHECK(logger.ContainsLine({"code-creation,Callback,-2,",
std::string(prop2_getter_record.begin())})); std::string(prop2_getter_record.begin())}));
} }
isolate->Dispose();
} }
TEST_F(LogTest, LogVersion) { 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);
{ {
ScopedLoggerInitializer logger(isolate()); ScopedLoggerInitializer logger(isolate);
logger.StopLogging(); logger.StopLogging();
v8::base::EmbeddedVector<char, 100> line_buffer; v8::base::EmbeddedVector<char, 100> line_buffer;
...@@ -416,11 +443,12 @@ TEST_F(LogTest, LogVersion) { ...@@ -416,11 +443,12 @@ TEST_F(LogTest, LogVersion) {
CHECK( CHECK(
logger.ContainsLine({"v8-version,", std::string(line_buffer.begin())})); logger.ContainsLine({"v8-version,", std::string(line_buffer.begin())}));
} }
isolate->Dispose();
} }
// https://crbug.com/539892 // https://crbug.com/539892
// CodeCreateEvents with really large names should not crash. // CodeCreateEvents with really large names should not crash.
TEST_F(LogTest, Issue539892) { UNINITIALIZED_TEST(Issue539892) {
class FakeCodeEventLogger : public i::CodeEventLogger { class FakeCodeEventLogger : public i::CodeEventLogger {
public: public:
explicit FakeCodeEventLogger(i::Isolate* isolate) explicit FakeCodeEventLogger(i::Isolate* isolate)
...@@ -440,9 +468,15 @@ TEST_F(LogTest, Issue539892) { ...@@ -440,9 +468,15 @@ TEST_F(LogTest, Issue539892) {
int length) override {} int length) override {}
#endif // V8_ENABLE_WEBASSEMBLY #endif // V8_ENABLE_WEBASSEMBLY
}; };
FakeCodeEventLogger code_event_logger(i_isolate());
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));
{ {
ScopedLoggerInitializer logger(isolate()); ScopedLoggerInitializer logger(isolate);
logger.logger()->AddLogEventListener(&code_event_logger); logger.logger()->AddLogEventListener(&code_event_logger);
// Function with a really large name. // Function with a really large name.
...@@ -467,16 +501,15 @@ TEST_F(LogTest, Issue539892) { ...@@ -467,16 +501,15 @@ TEST_F(LogTest, Issue539892) {
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaac" "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaac"
"(){})();"; "(){})();";
RunJS(source_text); CompileRun(source_text);
// Must not crash. // Must not crash.
logger.LogCompiledFunctions(); logger.LogCompiledFunctions();
} }
isolate->Dispose();
} }
using LogAllTest = TestWithPlatform; UNINITIALIZED_TEST(LogAll) {
TEST_F(LogAllTest, LogAll) {
SETUP_FLAGS(); SETUP_FLAGS();
i::FLAG_log_all = true; i::FLAG_log_all = true;
i::FLAG_log_deopt = true; i::FLAG_log_deopt = true;
...@@ -484,8 +517,7 @@ TEST_F(LogAllTest, LogAll) { ...@@ -484,8 +517,7 @@ TEST_F(LogAllTest, LogAll) {
i::FLAG_log_internal_timer_events = true; i::FLAG_log_internal_timer_events = true;
i::FLAG_allow_natives_syntax = true; i::FLAG_allow_natives_syntax = true;
v8::Isolate::CreateParams create_params; v8::Isolate::CreateParams create_params;
create_params.array_buffer_allocator = create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
ArrayBuffer::Allocator::NewDefaultAllocator();
v8::Isolate* isolate = v8::Isolate::New(create_params); v8::Isolate* isolate = v8::Isolate::New(create_params);
{ {
...@@ -513,12 +545,7 @@ TEST_F(LogAllTest, LogAll) { ...@@ -513,12 +545,7 @@ TEST_F(LogAllTest, LogAll) {
result = testAddFn('1', i); result = testAddFn('1', i);
} }
)"; )";
Local<Context> context = isolate->GetCurrentContext(); CompileRun(source_text);
Local<Script> script =
v8::Script::Compile(
context, String::NewFromUtf8(isolate, source_text).ToLocalChecked())
.ToLocalChecked();
script->Run(context).ToLocalChecked();
logger.StopLogging(); logger.StopLogging();
...@@ -535,20 +562,23 @@ TEST_F(LogAllTest, LogAll) { ...@@ -535,20 +562,23 @@ TEST_F(LogAllTest, LogAll) {
} }
} }
isolate->Dispose(); isolate->Dispose();
delete create_params.array_buffer_allocator;
} }
#ifndef V8_TARGET_ARCH_ARM #ifndef V8_TARGET_ARCH_ARM
TEST_F(LogTest, LogInterpretedFramesNativeStack) { UNINITIALIZED_TEST(LogInterpretedFramesNativeStack) {
SETUP_FLAGS();
i::FLAG_interpreted_frames_native_stack = true; 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);
{ {
ScopedLoggerInitializer logger(isolate()); ScopedLoggerInitializer logger(isolate);
const char* source_text = const char* source_text =
"function testLogInterpretedFramesNativeStack(a,b) { return a + b };" "function testLogInterpretedFramesNativeStack(a,b) { return a + b };"
"testLogInterpretedFramesNativeStack('1', 1);"; "testLogInterpretedFramesNativeStack('1', 1);";
RunJS(source_text); CompileRun(source_text);
logger.StopLogging(); logger.StopLogging();
...@@ -556,17 +586,15 @@ TEST_F(LogTest, LogInterpretedFramesNativeStack) { ...@@ -556,17 +586,15 @@ TEST_F(LogTest, LogInterpretedFramesNativeStack) {
{{"LazyCompile", "testLogInterpretedFramesNativeStack"}, {{"LazyCompile", "testLogInterpretedFramesNativeStack"},
{"LazyCompile", "testLogInterpretedFramesNativeStack"}})); {"LazyCompile", "testLogInterpretedFramesNativeStack"}}));
} }
isolate->Dispose();
} }
using LogInterpretedFramesNativeStackTest = TestWithPlatform; UNINITIALIZED_TEST(LogInterpretedFramesNativeStackWithSerialization) {
TEST_F(LogInterpretedFramesNativeStackTest,
LogInterpretedFramesNativeStackWithSerialization) {
SETUP_FLAGS(); SETUP_FLAGS();
i::FLAG_interpreted_frames_native_stack = true; i::FLAG_interpreted_frames_native_stack = true;
i::FLAG_always_opt = false; i::FLAG_always_opt = false;
v8::Isolate::CreateParams create_params; v8::Isolate::CreateParams create_params;
create_params.array_buffer_allocator = create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
ArrayBuffer::Allocator::NewDefaultAllocator();
v8::ScriptCompiler::CachedData* cache = nullptr; v8::ScriptCompiler::CachedData* cache = nullptr;
...@@ -590,17 +618,10 @@ TEST_F(LogInterpretedFramesNativeStackTest, ...@@ -590,17 +618,10 @@ TEST_F(LogInterpretedFramesNativeStackTest,
v8::HandleScope scope(isolate); v8::HandleScope scope(isolate);
v8::Isolate::Scope isolate_scope(isolate); v8::Isolate::Scope isolate_scope(isolate);
v8::Local<v8::Context> context = v8::Context::New(isolate); v8::Local<v8::Context> context = v8::Context::New(isolate);
v8::Local<v8::String> source = v8::Local<v8::String> source = v8_str(
String::NewFromUtf8( "function eyecatcher() { return a * a; } return eyecatcher();");
isolate, v8::Local<v8::String> arg_str = v8_str("a");
"function eyecatcher() { return a * a; } return eyecatcher();") v8::ScriptOrigin origin(isolate, v8_str("filename"));
.ToLocalChecked();
v8::Local<v8::String> arg_str =
String::NewFromUtf8(isolate, "a").ToLocalChecked();
v8::ScriptOrigin origin(
isolate, String::NewFromUtf8(isolate, ("filename")).ToLocalChecked());
i::DisallowCompilation* no_compile_expected = i::DisallowCompilation* no_compile_expected =
has_cache ? new i::DisallowCompilation( has_cache ? new i::DisallowCompilation(
...@@ -620,7 +641,7 @@ TEST_F(LogInterpretedFramesNativeStackTest, ...@@ -620,7 +641,7 @@ TEST_F(LogInterpretedFramesNativeStackTest,
CHECK(logger.ContainsLinesInOrder( CHECK(logger.ContainsLinesInOrder(
{{"Function", "eyecatcher"}, {"Function", "eyecatcher"}})); {{"Function", "eyecatcher"}, {"Function", "eyecatcher"}}));
} }
v8::Local<v8::Value> arg = Number::New(isolate, 3); v8::Local<v8::Value> arg = v8_num(3);
v8::Local<v8::Value> result = v8::Local<v8::Value> result =
fun->Call(context, v8::Undefined(isolate), 1, &arg).ToLocalChecked(); fun->Call(context, v8::Undefined(isolate), 1, &arg).ToLocalChecked();
CHECK_EQ(9, result->Int32Value(context).FromJust()); CHECK_EQ(9, result->Int32Value(context).FromJust());
...@@ -632,26 +653,29 @@ TEST_F(LogInterpretedFramesNativeStackTest, ...@@ -632,26 +653,29 @@ TEST_F(LogInterpretedFramesNativeStackTest,
isolate->Dispose(); isolate->Dispose();
} while (!has_cache); } while (!has_cache);
delete cache; delete cache;
delete create_params.array_buffer_allocator;
} }
#endif // V8_TARGET_ARCH_ARM #endif // V8_TARGET_ARCH_ARM
TEST_F(LogTest, ExternalLogEventListener) { UNINITIALIZED_TEST(ExternalLogEventListener) {
i::FLAG_log = false; i::FLAG_log = false;
i::FLAG_prof = 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);
{ {
v8::HandleScope scope(isolate()); v8::HandleScope scope(isolate);
v8::Isolate::Scope isolate_scope(isolate()); v8::Isolate::Scope isolate_scope(isolate);
v8::Local<v8::Context> context = v8::Context::New(isolate()); v8::Local<v8::Context> context = v8::Context::New(isolate);
v8::Context::Scope context_scope(context); v8::Context::Scope context_scope(context);
v8::TestCodeEventHandler code_event_handler(isolate()); TestCodeEventHandler code_event_handler(isolate);
const char* source_text_before_start = const char* source_text_before_start =
"function testLogEventListenerBeforeStart(a,b) { return a + b };" "function testLogEventListenerBeforeStart(a,b) { return a + b };"
"testLogEventListenerBeforeStart('1', 1);"; "testLogEventListenerBeforeStart('1', 1);";
RunJS(source_text_before_start); CompileRun(source_text_before_start);
CHECK_EQ(code_event_handler.CountLines("Function", CHECK_EQ(code_event_handler.CountLines("Function",
"testLogEventListenerBeforeStart"), "testLogEventListenerBeforeStart"),
...@@ -669,17 +693,16 @@ TEST_F(LogTest, ExternalLogEventListener) { ...@@ -669,17 +693,16 @@ TEST_F(LogTest, ExternalLogEventListener) {
const char* source_text_after_start = const char* source_text_after_start =
"function testLogEventListenerAfterStart(a,b) { return a + b };" "function testLogEventListenerAfterStart(a,b) { return a + b };"
"testLogEventListenerAfterStart('1', 1);"; "testLogEventListenerAfterStart('1', 1);";
RunJS(source_text_after_start); CompileRun(source_text_after_start);
CHECK_GE(code_event_handler.CountLines("LazyCompile", CHECK_GE(code_event_handler.CountLines("LazyCompile",
"testLogEventListenerAfterStart"), "testLogEventListenerAfterStart"),
1); 1);
} }
isolate->Dispose();
} }
using ExternalLogTest = TestWithPlatform; UNINITIALIZED_TEST(ExternalLogEventListenerInnerFunctions) {
TEST_F(ExternalLogTest, ExternalLogEventListenerInnerFunctions) {
i::FLAG_log = false; i::FLAG_log = false;
i::FLAG_prof = false; i::FLAG_prof = false;
...@@ -688,9 +711,7 @@ TEST_F(ExternalLogTest, ExternalLogEventListenerInnerFunctions) { ...@@ -688,9 +711,7 @@ TEST_F(ExternalLogTest, ExternalLogEventListenerInnerFunctions) {
"(function f1() { return (function f2() {}); })()"; "(function f1() { return (function f2() {}); })()";
v8::Isolate::CreateParams create_params; v8::Isolate::CreateParams create_params;
create_params.array_buffer_allocator = create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
ArrayBuffer::Allocator::NewDefaultAllocator();
v8::Isolate* isolate1 = v8::Isolate::New(create_params); v8::Isolate* isolate1 = v8::Isolate::New(create_params);
{ // Test that we emit the correct code events from eagerly compiling. { // Test that we emit the correct code events from eagerly compiling.
v8::HandleScope scope(isolate1); v8::HandleScope scope(isolate1);
...@@ -701,12 +722,8 @@ TEST_F(ExternalLogTest, ExternalLogEventListenerInnerFunctions) { ...@@ -701,12 +722,8 @@ TEST_F(ExternalLogTest, ExternalLogEventListenerInnerFunctions) {
TestCodeEventHandler code_event_handler(isolate1); TestCodeEventHandler code_event_handler(isolate1);
code_event_handler.Enable(); code_event_handler.Enable();
v8::Local<v8::String> source_string = v8::Local<v8::String> source_string = v8_str(source_cstring);
String::NewFromUtf8(isolate1, source_cstring).ToLocalChecked(); v8::ScriptOrigin origin(isolate1, v8_str("test"));
v8::ScriptOrigin origin(
isolate1, String::NewFromUtf8(isolate1, "test").ToLocalChecked());
v8::ScriptCompiler::Source source(source_string, origin); v8::ScriptCompiler::Source source(source_string, origin);
v8::Local<v8::UnboundScript> script = v8::Local<v8::UnboundScript> script =
v8::ScriptCompiler::CompileUnboundScript(isolate1, &source) v8::ScriptCompiler::CompileUnboundScript(isolate1, &source)
...@@ -731,12 +748,8 @@ TEST_F(ExternalLogTest, ExternalLogEventListenerInnerFunctions) { ...@@ -731,12 +748,8 @@ TEST_F(ExternalLogTest, ExternalLogEventListenerInnerFunctions) {
TestCodeEventHandler code_event_handler(isolate2); TestCodeEventHandler code_event_handler(isolate2);
code_event_handler.Enable(); code_event_handler.Enable();
v8::Local<v8::String> source_string = v8::Local<v8::String> source_string = v8_str(source_cstring);
String::NewFromUtf8(isolate2, source_cstring).ToLocalChecked(); v8::ScriptOrigin origin(isolate2, v8_str("test"));
v8::ScriptOrigin origin(
isolate2, String::NewFromUtf8(isolate2, "test").ToLocalChecked());
v8::ScriptCompiler::Source source(source_string, origin, cache); v8::ScriptCompiler::Source source(source_string, origin, cache);
{ {
i::DisallowCompilation no_compile_expected( i::DisallowCompilation no_compile_expected(
...@@ -749,27 +762,30 @@ TEST_F(ExternalLogTest, ExternalLogEventListenerInnerFunctions) { ...@@ -749,27 +762,30 @@ TEST_F(ExternalLogTest, ExternalLogEventListenerInnerFunctions) {
CHECK_EQ(code_event_handler.CountLines("Function", "f2"), 1); CHECK_EQ(code_event_handler.CountLines("Function", "f2"), 1);
} }
isolate2->Dispose(); isolate2->Dispose();
delete create_params.array_buffer_allocator;
} }
#ifndef V8_TARGET_ARCH_ARM #ifndef V8_TARGET_ARCH_ARM
TEST_F(LogTest, ExternalLogEventListenerWithInterpretedFramesNativeStack) { UNINITIALIZED_TEST(ExternalLogEventListenerWithInterpretedFramesNativeStack) {
i::FLAG_log = false; i::FLAG_log = false;
i::FLAG_prof = false; i::FLAG_prof = false;
i::FLAG_interpreted_frames_native_stack = true; 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);
{ {
v8::HandleScope scope(isolate()); v8::HandleScope scope(isolate);
v8::Isolate::Scope isolate_scope(isolate()); v8::Isolate::Scope isolate_scope(isolate);
v8::Local<v8::Context> context = v8::Context::New(isolate()); v8::Local<v8::Context> context = v8::Context::New(isolate);
context->Enter(); context->Enter();
TestCodeEventHandler code_event_handler(isolate()); TestCodeEventHandler code_event_handler(isolate);
const char* source_text_before_start = const char* source_text_before_start =
"function testLogEventListenerBeforeStart(a,b) { return a + b };" "function testLogEventListenerBeforeStart(a,b) { return a + b };"
"testLogEventListenerBeforeStart('1', 1);"; "testLogEventListenerBeforeStart('1', 1);";
RunJS(source_text_before_start); CompileRun(source_text_before_start);
CHECK_EQ(code_event_handler.CountLines("Function", CHECK_EQ(code_event_handler.CountLines("Function",
"testLogEventListenerBeforeStart"), "testLogEventListenerBeforeStart"),
...@@ -784,7 +800,7 @@ TEST_F(LogTest, ExternalLogEventListenerWithInterpretedFramesNativeStack) { ...@@ -784,7 +800,7 @@ TEST_F(LogTest, ExternalLogEventListenerWithInterpretedFramesNativeStack) {
const char* source_text_after_start = const char* source_text_after_start =
"function testLogEventListenerAfterStart(a,b) { return a + b };" "function testLogEventListenerAfterStart(a,b) { return a + b };"
"testLogEventListenerAfterStart('1', 1);"; "testLogEventListenerAfterStart('1', 1);";
RunJS(source_text_after_start); CompileRun(source_text_after_start);
CHECK_GE(code_event_handler.CountLines("LazyCompile", CHECK_GE(code_event_handler.CountLines("LazyCompile",
"testLogEventListenerAfterStart"), "testLogEventListenerAfterStart"),
...@@ -796,13 +812,18 @@ TEST_F(LogTest, ExternalLogEventListenerWithInterpretedFramesNativeStack) { ...@@ -796,13 +812,18 @@ TEST_F(LogTest, ExternalLogEventListenerWithInterpretedFramesNativeStack) {
context->Exit(); context->Exit();
} }
isolate->Dispose();
} }
#endif // V8_TARGET_ARCH_ARM #endif // V8_TARGET_ARCH_ARM
TEST_F(LogTest, TraceMaps) { UNINITIALIZED_TEST(TraceMaps) {
SETUP_FLAGS();
i::FLAG_log_maps = true; 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);
// Try to create many different kind of maps to make sure the logging won't // Try to create many different kind of maps to make sure the logging won't
// crash. More detailed tests are implemented separately. // crash. More detailed tests are implemented separately.
const char* source_text = R"( const char* source_text = R"(
...@@ -823,7 +844,7 @@ TEST_F(LogTest, TraceMaps) { ...@@ -823,7 +844,7 @@ TEST_F(LogTest, TraceMaps) {
}; };
t.b = {}; t.b = {};
)"; )";
RunJS(source_text); CompileRunChecked(isolate, source_text);
logger.StopLogging(); logger.StopLogging();
...@@ -833,6 +854,7 @@ TEST_F(LogTest, TraceMaps) { ...@@ -833,6 +854,7 @@ TEST_F(LogTest, TraceMaps) {
CHECK(logger.ContainsLine({"map-details", ",0x"})); CHECK(logger.ContainsLine({"map-details", ",0x"}));
} }
i::FLAG_log_maps = false; i::FLAG_log_maps = false;
isolate->Dispose();
} }
namespace { namespace {
...@@ -881,40 +903,40 @@ void ValidateMapDetailsLogging(v8::Isolate* isolate, ...@@ -881,40 +903,40 @@ void ValidateMapDetailsLogging(v8::Isolate* isolate,
} // namespace } // namespace
class LogMapTest : public TestWithIsolate { UNINITIALIZED_TEST(LogMapsDetailsStartup) {
public:
static void SetUpTestSuite() {
SETUP_FLAGS();
i::FLAG_retain_maps_for_n_gc = 0xFFFFFFF;
i::FLAG_log_maps = true;
TestWithIsolate::SetUpTestSuite();
}
static void TearDownTestSuite() { TestWithIsolate::TearDownTestSuite(); }
};
TEST_F(LogMapTest, LogMapsDetailsStartup) {
// Reusing map addresses might cause these tests to fail. // Reusing map addresses might cause these tests to fail.
if (i::FLAG_gc_global || i::FLAG_stress_compaction || if (i::FLAG_gc_global || i::FLAG_stress_compaction ||
i::FLAG_stress_incremental_marking || i::FLAG_enable_third_party_heap) { i::FLAG_stress_incremental_marking || i::FLAG_enable_third_party_heap) {
return; return;
} }
// Test that all Map details from Maps in the snapshot are logged properly. // 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(); logger.StopLogging();
ValidateMapDetailsLogging(isolate(), &logger); ValidateMapDetailsLogging(isolate, &logger);
} }
i::FLAG_log_function_events = false; i::FLAG_log_function_events = false;
isolate->Dispose();
} }
TEST_F(LogMapTest, LogMapsDetailsCode) { UNINITIALIZED_TEST(LogMapsDetailsCode) {
// Reusing map addresses might cause these tests to fail. // Reusing map addresses might cause these tests to fail.
if (i::FLAG_gc_global || i::FLAG_stress_compaction || if (i::FLAG_gc_global || i::FLAG_stress_compaction ||
i::FLAG_stress_incremental_marking || i::FLAG_enable_third_party_heap) { i::FLAG_stress_incremental_marking || i::FLAG_enable_third_party_heap) {
return; 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"( const char* source = R"(
// Normal properties overflowing into dict-mode. // Normal properties overflowing into dict-mode.
let a = {}; let a = {};
...@@ -990,53 +1012,65 @@ TEST_F(LogMapTest, LogMapsDetailsCode) { ...@@ -990,53 +1012,65 @@ TEST_F(LogMapTest, LogMapsDetailsCode) {
[1,2,3].helper(); [1,2,3].helper();
)"; )";
{ {
ScopedLoggerInitializer logger(isolate()); ScopedLoggerInitializer logger(isolate);
RunJS(source); CompileRunChecked(isolate, source);
logger.StopLogging(); logger.StopLogging();
ValidateMapDetailsLogging(isolate(), &logger); ValidateMapDetailsLogging(isolate, &logger);
} }
i::FLAG_log_function_events = false; i::FLAG_log_function_events = false;
isolate->Dispose();
} }
TEST_F(LogMapTest, LogMapsDetailsContexts) { UNINITIALIZED_TEST(LogMapsDetailsContexts) {
// Reusing map addresses might cause these tests to fail. // Reusing map addresses might cause these tests to fail.
if (i::FLAG_gc_global || i::FLAG_stress_compaction || if (i::FLAG_gc_global || i::FLAG_stress_compaction ||
i::FLAG_stress_incremental_marking || i::FLAG_enable_third_party_heap) { i::FLAG_stress_incremental_marking || i::FLAG_enable_third_party_heap) {
return; return;
} }
// Test that all Map details from Maps in the snapshot are logged properly. // 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. // Use the default context.
RunJS("{a:1}"); CompileRunChecked(isolate, "{a:1}");
// Create additional contexts. // Create additional contexts.
v8::Local<v8::Context> env1 = v8::Context::New(isolate()); v8::Local<v8::Context> env1 = v8::Context::New(isolate);
env1->Enter(); env1->Enter();
RunJS("{b:1}"); CompileRun(env1, "{b:1}").ToLocalChecked();
v8::Local<v8::Context> env2 = v8::Context::New(isolate()); v8::Local<v8::Context> env2 = v8::Context::New(isolate);
env2->Enter(); env2->Enter();
RunJS("{c:1}"); CompileRun(env2, "{c:1}").ToLocalChecked();
env2->Exit(); env2->Exit();
env1->Exit(); env1->Exit();
logger.StopLogging(); logger.StopLogging();
ValidateMapDetailsLogging(isolate(), &logger); ValidateMapDetailsLogging(isolate, &logger);
} }
i::FLAG_log_function_events = false; i::FLAG_log_function_events = false;
isolate->Dispose();
} }
TEST_F(LogTest, ConsoleTimeEvents) { 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);
{ {
ScopedLoggerInitializer logger(isolate()); ScopedLoggerInitializer logger(isolate);
{ {
// setup console global. // setup console global.
v8::HandleScope scope(isolate()); v8::HandleScope scope(isolate);
v8::Local<v8::String> name = v8::String::NewFromUtf8Literal( v8::Local<v8::String> name = v8::String::NewFromUtf8Literal(
isolate(), "console", v8::NewStringType::kInternalized); isolate, "console", v8::NewStringType::kInternalized);
v8::Local<v8::Context> context = isolate()->GetCurrentContext(); v8::Local<v8::Context> context = isolate->GetCurrentContext();
v8::Local<v8::Value> console = context->GetExtrasBindingObject() v8::Local<v8::Value> console = context->GetExtrasBindingObject()
->Get(context, name) ->Get(context, name)
.ToLocalChecked(); .ToLocalChecked();
...@@ -1051,7 +1085,7 @@ TEST_F(LogTest, ConsoleTimeEvents) { ...@@ -1051,7 +1085,7 @@ TEST_F(LogTest, ConsoleTimeEvents) {
"console.timeEnd('timerEvent1');" "console.timeEnd('timerEvent1');"
"console.timeStamp('timerEvent2');" "console.timeStamp('timerEvent2');"
"console.timeStamp('timerEvent3');"; "console.timeStamp('timerEvent3');";
RunJS(source_text); CompileRun(source_text);
logger.StopLogging(); logger.StopLogging();
...@@ -1062,19 +1096,25 @@ TEST_F(LogTest, ConsoleTimeEvents) { ...@@ -1062,19 +1096,25 @@ TEST_F(LogTest, ConsoleTimeEvents) {
{"timer-event,timerEvent3,"}}; {"timer-event,timerEvent3,"}};
CHECK(logger.ContainsLinesInOrder(lines)); CHECK(logger.ContainsLinesInOrder(lines));
} }
isolate->Dispose();
} }
TEST_F(LogTest, LogFunctionEvents) { UNINITIALIZED_TEST(LogFunctionEvents) {
// Always opt and stress opt will break the fine-grained log order. // Always opt and stress opt will break the fine-grained log order.
if (i::FLAG_always_opt) return; if (i::FLAG_always_opt) return;
SETUP_FLAGS();
i::FLAG_log_function_events = true; 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. // Run some warmup code to help ignoring existing log entries.
RunJS( CompileRun(
"function warmUp(a) {" "function warmUp(a) {"
" let b = () => 1;" " let b = () => 1;"
" return function(c) { return a+b+c; };" " return function(c) { return a+b+c; };"
...@@ -1093,7 +1133,7 @@ TEST_F(LogTest, LogFunctionEvents) { ...@@ -1093,7 +1133,7 @@ TEST_F(LogTest, LogFunctionEvents) {
"(function eagerFunction(){ return 'eager' })();" "(function eagerFunction(){ return 'eager' })();"
"function Foo() { this.foo = function(){}; };" "function Foo() { this.foo = function(){}; };"
"let i = new Foo(); i.foo();"; "let i = new Foo(); i.foo();";
RunJS(source_text); CompileRun(source_text);
logger.StopLogging(); logger.StopLogging();
...@@ -1137,11 +1177,16 @@ TEST_F(LogTest, LogFunctionEvents) { ...@@ -1137,11 +1177,16 @@ TEST_F(LogTest, LogFunctionEvents) {
CHECK(logger.ContainsLinesInOrder(lines)); CHECK(logger.ContainsLinesInOrder(lines));
} }
i::FLAG_log_function_events = false; i::FLAG_log_function_events = false;
isolate->Dispose();
} }
TEST_F(LogTest, BuiltinsNotLoggedAsLazyCompile) { 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);
{ {
ScopedLoggerInitializer logger(isolate()); ScopedLoggerInitializer logger(isolate);
logger.LogCodeObjects(); logger.LogCodeObjects();
logger.LogCompiledFunctions(); logger.LogCompiledFunctions();
...@@ -1164,6 +1209,5 @@ TEST_F(LogTest, BuiltinsNotLoggedAsLazyCompile) { ...@@ -1164,6 +1209,5 @@ TEST_F(LogTest, BuiltinsNotLoggedAsLazyCompile) {
CHECK(!logger.ContainsLine( CHECK(!logger.ContainsLine(
{"code-creation,LazyCompile,2,", std::string(buffer.begin())})); {"code-creation,LazyCompile,2,", std::string(buffer.begin())}));
} }
isolate->Dispose();
} }
} // namespace v8
...@@ -374,7 +374,6 @@ v8_source_set("unittests_sources") { ...@@ -374,7 +374,6 @@ v8_source_set("unittests_sources") {
"libplatform/task-queue-unittest.cc", "libplatform/task-queue-unittest.cc",
"libplatform/worker-thread-unittest.cc", "libplatform/worker-thread-unittest.cc",
"logging/counters-unittest.cc", "logging/counters-unittest.cc",
"logging/log-unittest.cc",
"numbers/bigint-unittest.cc", "numbers/bigint-unittest.cc",
"numbers/conversions-unittest.cc", "numbers/conversions-unittest.cc",
"objects/array-list-unittest.cc", "objects/array-list-unittest.cc",
......
...@@ -137,16 +137,6 @@ class WithIsolateScopeMixin : public TMixin { ...@@ -137,16 +137,6 @@ class WithIsolateScopeMixin : public TMixin {
.ToLocalChecked()); .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) { void CollectGarbage(i::AllocationSpace space) {
i_isolate()->heap()->CollectGarbage(space, i_isolate()->heap()->CollectGarbage(space,
i::GarbageCollectionReason::kTesting); i::GarbageCollectionReason::kTesting);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment