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") {
"test-liveedit.cc",
"test-local-handles.cc",
"test-lockers.cc",
"test-log.cc",
"test-managed.cc",
"test-mementos.cc",
"test-orderedhashtable.cc",
......
// Copyright 2022 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Copyright 2006-2009 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// 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
#include "src/logging/log.h"
#include <unordered_set>
#include <vector>
......@@ -17,19 +38,17 @@
#include "src/execution/vm-state-inl.h"
#include "src/init/v8.h"
#include "src/logging/log-utils.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/unittests/test-utils.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "test/cctest/cctest.h"
using v8::base::EmbeddedVector;
using v8::internal::Address;
using v8::internal::V8FileLogger;
namespace v8 {
namespace {
#define SETUP_FLAGS() \
......@@ -49,16 +68,6 @@ static std::vector<std::string> Split(const std::string& s, char delimiter) {
return result;
}
class LogTest : public TestWithIsolate {
public:
static void SetUpTestSuite() {
SETUP_FLAGS();
TestWithIsolate::SetUpTestSuite();
}
static void TearDownTestSuite() { TestWithIsolate::TearDownTestSuite(); }
};
class V8_NODISCARD ScopedLoggerInitializer {
public:
explicit ScopedLoggerInitializer(v8::Isolate* isolate)
......@@ -283,54 +292,59 @@ class SimpleExternalString : public v8::String::ExternalStringResource {
} // namespace
TEST_F(LogTest, Issue23768) {
v8::HandleScope scope(isolate());
v8::Local<v8::Context> env = v8::Context::New(isolate());
TEST(Issue23768) {
v8::HandleScope scope(CcTest::isolate());
v8::Local<v8::Context> env = v8::Context::New(CcTest::isolate());
env->Enter();
SimpleExternalString source_ext_str("(function ext() {})();");
v8::Local<v8::String> source =
v8::String::NewExternalTwoByte(isolate(), &source_ext_str)
v8::String::NewExternalTwoByte(CcTest::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(isolate(), "issue-23768-test");
v8::String::NewFromUtf8Literal(CcTest::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)),
i_isolate());
CcTest::i_isolate());
// This situation can happen if source was an external string disposed
// by its owner.
i_source->SetResource(i_isolate(), nullptr);
i_source->SetResource(CcTest::i_isolate(), nullptr);
// 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(
isolate(), v8::FunctionTemplate::New(isolate()));
obj->SetClassName(NewString("Obj"));
isolate, v8::FunctionTemplate::New(isolate));
obj->SetClassName(v8_str("Obj"));
v8::Local<v8::ObjectTemplate> proto = obj->PrototypeTemplate();
v8::Local<v8::Signature> signature = v8::Signature::New(isolate(), obj);
proto->Set(NewString("method1"),
v8::FunctionTemplate::New(isolate(), ObjMethod1,
v8::Local<v8::Signature> signature = v8::Signature::New(isolate, obj);
proto->Set(v8_str("method1"),
v8::FunctionTemplate::New(isolate, ObjMethod1,
v8::Local<v8::Value>(), signature),
static_cast<v8::PropertyAttribute>(v8::DontDelete));
logger.env()
->Global()
->Set(logger.env(), NewString("Obj"),
->Set(logger.env(), v8_str("Obj"),
obj->GetFunction(logger.env()).ToLocalChecked())
.FromJust();
RunJS("Obj.prototype.method1.toString();");
CompileRun("Obj.prototype.method1.toString();");
logger.LogCompiledFunctions();
logger.StopLogging();
......@@ -345,28 +359,36 @@ TEST_F(LogTest, 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) {
}
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(
isolate(), v8::FunctionTemplate::New(isolate()));
obj->SetClassName(NewString("Obj"));
isolate, v8::FunctionTemplate::New(isolate));
obj->SetClassName(v8_str("Obj"));
v8::Local<v8::ObjectTemplate> inst = obj->InstanceTemplate();
inst->SetAccessor(NewString("prop1"), Prop1Getter, Prop1Setter);
inst->SetAccessor(NewString("prop2"), Prop2Getter);
inst->SetAccessor(v8_str("prop1"), Prop1Getter, Prop1Setter);
inst->SetAccessor(v8_str("prop2"), Prop2Getter);
logger.logger()->LogAccessorCallbacks();
......@@ -402,11 +424,16 @@ TEST_F(LogTest, LogAccessorCallbacks) {
CHECK(logger.ContainsLine({"code-creation,Callback,-2,",
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();
v8::base::EmbeddedVector<char, 100> line_buffer;
......@@ -416,11 +443,12 @@ TEST_F(LogTest, 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.
TEST_F(LogTest, Issue539892) {
UNINITIALIZED_TEST(Issue539892) {
class FakeCodeEventLogger : public i::CodeEventLogger {
public:
explicit FakeCodeEventLogger(i::Isolate* isolate)
......@@ -440,9 +468,15 @@ TEST_F(LogTest, Issue539892) {
int length) override {}
#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);
// Function with a really large name.
......@@ -467,16 +501,15 @@ TEST_F(LogTest, Issue539892) {
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaac"
"(){})();";
RunJS(source_text);
CompileRun(source_text);
// Must not crash.
logger.LogCompiledFunctions();
}
isolate->Dispose();
}
using LogAllTest = TestWithPlatform;
TEST_F(LogAllTest, LogAll) {
UNINITIALIZED_TEST(LogAll) {
SETUP_FLAGS();
i::FLAG_log_all = true;
i::FLAG_log_deopt = true;
......@@ -484,8 +517,7 @@ TEST_F(LogAllTest, LogAll) {
i::FLAG_log_internal_timer_events = true;
i::FLAG_allow_natives_syntax = true;
v8::Isolate::CreateParams create_params;
create_params.array_buffer_allocator =
ArrayBuffer::Allocator::NewDefaultAllocator();
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
v8::Isolate* isolate = v8::Isolate::New(create_params);
{
......@@ -513,12 +545,7 @@ TEST_F(LogAllTest, LogAll) {
result = testAddFn('1', i);
}
)";
Local<Context> context = isolate->GetCurrentContext();
Local<Script> script =
v8::Script::Compile(
context, String::NewFromUtf8(isolate, source_text).ToLocalChecked())
.ToLocalChecked();
script->Run(context).ToLocalChecked();
CompileRun(source_text);
logger.StopLogging();
......@@ -535,20 +562,23 @@ TEST_F(LogAllTest, LogAll) {
}
}
isolate->Dispose();
delete create_params.array_buffer_allocator;
}
#ifndef V8_TARGET_ARCH_ARM
TEST_F(LogTest, LogInterpretedFramesNativeStack) {
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);
{
ScopedLoggerInitializer logger(isolate());
ScopedLoggerInitializer logger(isolate);
const char* source_text =
"function testLogInterpretedFramesNativeStack(a,b) { return a + b };"
"testLogInterpretedFramesNativeStack('1', 1);";
RunJS(source_text);
CompileRun(source_text);
logger.StopLogging();
......@@ -556,17 +586,15 @@ TEST_F(LogTest, LogInterpretedFramesNativeStack) {
{{"LazyCompile", "testLogInterpretedFramesNativeStack"},
{"LazyCompile", "testLogInterpretedFramesNativeStack"}}));
}
isolate->Dispose();
}
using LogInterpretedFramesNativeStackTest = TestWithPlatform;
TEST_F(LogInterpretedFramesNativeStackTest,
LogInterpretedFramesNativeStackWithSerialization) {
UNINITIALIZED_TEST(LogInterpretedFramesNativeStackWithSerialization) {
SETUP_FLAGS();
i::FLAG_interpreted_frames_native_stack = true;
i::FLAG_always_opt = false;
v8::Isolate::CreateParams create_params;
create_params.array_buffer_allocator =
ArrayBuffer::Allocator::NewDefaultAllocator();
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
v8::ScriptCompiler::CachedData* cache = nullptr;
......@@ -590,17 +618,10 @@ TEST_F(LogInterpretedFramesNativeStackTest,
v8::HandleScope scope(isolate);
v8::Isolate::Scope isolate_scope(isolate);
v8::Local<v8::Context> context = v8::Context::New(isolate);
v8::Local<v8::String> source =
String::NewFromUtf8(
isolate,
"function eyecatcher() { return a * a; } return eyecatcher();")
.ToLocalChecked();
v8::Local<v8::String> arg_str =
String::NewFromUtf8(isolate, "a").ToLocalChecked();
v8::ScriptOrigin origin(
isolate, String::NewFromUtf8(isolate, ("filename")).ToLocalChecked());
v8::Local<v8::String> source = v8_str(
"function eyecatcher() { return a * a; } return eyecatcher();");
v8::Local<v8::String> arg_str = v8_str("a");
v8::ScriptOrigin origin(isolate, v8_str("filename"));
i::DisallowCompilation* no_compile_expected =
has_cache ? new i::DisallowCompilation(
......@@ -620,7 +641,7 @@ TEST_F(LogInterpretedFramesNativeStackTest,
CHECK(logger.ContainsLinesInOrder(
{{"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 =
fun->Call(context, v8::Undefined(isolate), 1, &arg).ToLocalChecked();
CHECK_EQ(9, result->Int32Value(context).FromJust());
......@@ -632,26 +653,29 @@ TEST_F(LogInterpretedFramesNativeStackTest,
isolate->Dispose();
} while (!has_cache);
delete cache;
delete create_params.array_buffer_allocator;
}
#endif // V8_TARGET_ARCH_ARM
TEST_F(LogTest, ExternalLogEventListener) {
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);
{
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);
v8::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);";
RunJS(source_text_before_start);
CompileRun(source_text_before_start);
CHECK_EQ(code_event_handler.CountLines("Function",
"testLogEventListenerBeforeStart"),
......@@ -669,17 +693,16 @@ TEST_F(LogTest, ExternalLogEventListener) {
const char* source_text_after_start =
"function testLogEventListenerAfterStart(a,b) { return a + b };"
"testLogEventListenerAfterStart('1', 1);";
RunJS(source_text_after_start);
CompileRun(source_text_after_start);
CHECK_GE(code_event_handler.CountLines("LazyCompile",
"testLogEventListenerAfterStart"),
1);
}
isolate->Dispose();
}
using ExternalLogTest = TestWithPlatform;
TEST_F(ExternalLogTest, ExternalLogEventListenerInnerFunctions) {
UNINITIALIZED_TEST(ExternalLogEventListenerInnerFunctions) {
i::FLAG_log = false;
i::FLAG_prof = false;
......@@ -688,9 +711,7 @@ TEST_F(ExternalLogTest, ExternalLogEventListenerInnerFunctions) {
"(function f1() { return (function f2() {}); })()";
v8::Isolate::CreateParams create_params;
create_params.array_buffer_allocator =
ArrayBuffer::Allocator::NewDefaultAllocator();
create_params.array_buffer_allocator = CcTest::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);
......@@ -701,12 +722,8 @@ TEST_F(ExternalLogTest, ExternalLogEventListenerInnerFunctions) {
TestCodeEventHandler code_event_handler(isolate1);
code_event_handler.Enable();
v8::Local<v8::String> source_string =
String::NewFromUtf8(isolate1, source_cstring).ToLocalChecked();
v8::ScriptOrigin origin(
isolate1, String::NewFromUtf8(isolate1, "test").ToLocalChecked());
v8::Local<v8::String> source_string = v8_str(source_cstring);
v8::ScriptOrigin origin(isolate1, v8_str("test"));
v8::ScriptCompiler::Source source(source_string, origin);
v8::Local<v8::UnboundScript> script =
v8::ScriptCompiler::CompileUnboundScript(isolate1, &source)
......@@ -731,12 +748,8 @@ TEST_F(ExternalLogTest, ExternalLogEventListenerInnerFunctions) {
TestCodeEventHandler code_event_handler(isolate2);
code_event_handler.Enable();
v8::Local<v8::String> source_string =
String::NewFromUtf8(isolate2, source_cstring).ToLocalChecked();
v8::ScriptOrigin origin(
isolate2, String::NewFromUtf8(isolate2, "test").ToLocalChecked());
v8::Local<v8::String> source_string = v8_str(source_cstring);
v8::ScriptOrigin origin(isolate2, v8_str("test"));
v8::ScriptCompiler::Source source(source_string, origin, cache);
{
i::DisallowCompilation no_compile_expected(
......@@ -749,27 +762,30 @@ TEST_F(ExternalLogTest, ExternalLogEventListenerInnerFunctions) {
CHECK_EQ(code_event_handler.CountLines("Function", "f2"), 1);
}
isolate2->Dispose();
delete create_params.array_buffer_allocator;
}
#ifndef V8_TARGET_ARCH_ARM
TEST_F(LogTest, ExternalLogEventListenerWithInterpretedFramesNativeStack) {
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);
{
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);";
RunJS(source_text_before_start);
CompileRun(source_text_before_start);
CHECK_EQ(code_event_handler.CountLines("Function",
"testLogEventListenerBeforeStart"),
......@@ -784,7 +800,7 @@ TEST_F(LogTest, ExternalLogEventListenerWithInterpretedFramesNativeStack) {
const char* source_text_after_start =
"function testLogEventListenerAfterStart(a,b) { return a + b };"
"testLogEventListenerAfterStart('1', 1);";
RunJS(source_text_after_start);
CompileRun(source_text_after_start);
CHECK_GE(code_event_handler.CountLines("LazyCompile",
"testLogEventListenerAfterStart"),
......@@ -796,13 +812,18 @@ TEST_F(LogTest, ExternalLogEventListenerWithInterpretedFramesNativeStack) {
context->Exit();
}
isolate->Dispose();
}
#endif // V8_TARGET_ARCH_ARM
TEST_F(LogTest, TraceMaps) {
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);
{
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"(
......@@ -823,7 +844,7 @@ TEST_F(LogTest, TraceMaps) {
};
t.b = {};
)";
RunJS(source_text);
CompileRunChecked(isolate, source_text);
logger.StopLogging();
......@@ -833,6 +854,7 @@ TEST_F(LogTest, TraceMaps) {
CHECK(logger.ContainsLine({"map-details", ",0x"}));
}
i::FLAG_log_maps = false;
isolate->Dispose();
}
namespace {
......@@ -881,40 +903,40 @@ void ValidateMapDetailsLogging(v8::Isolate* isolate,
} // namespace
class LogMapTest : public TestWithIsolate {
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) {
UNINITIALIZED_TEST(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();
}
TEST_F(LogMapTest, LogMapsDetailsCode) {
UNINITIALIZED_TEST(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 = {};
......@@ -990,53 +1012,65 @@ TEST_F(LogMapTest, LogMapsDetailsCode) {
[1,2,3].helper();
)";
{
ScopedLoggerInitializer logger(isolate());
RunJS(source);
ScopedLoggerInitializer logger(isolate);
CompileRunChecked(isolate, source);
logger.StopLogging();
ValidateMapDetailsLogging(isolate(), &logger);
ValidateMapDetailsLogging(isolate, &logger);
}
i::FLAG_log_function_events = false;
isolate->Dispose();
}
TEST_F(LogMapTest, LogMapsDetailsContexts) {
UNINITIALIZED_TEST(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.
RunJS("{a:1}");
CompileRunChecked(isolate, "{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();
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();
RunJS("{c:1}");
CompileRun(env2, "{c:1}").ToLocalChecked();
env2->Exit();
env1->Exit();
logger.StopLogging();
ValidateMapDetailsLogging(isolate(), &logger);
ValidateMapDetailsLogging(isolate, &logger);
}
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.
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();
......@@ -1051,7 +1085,7 @@ TEST_F(LogTest, ConsoleTimeEvents) {
"console.timeEnd('timerEvent1');"
"console.timeStamp('timerEvent2');"
"console.timeStamp('timerEvent3');";
RunJS(source_text);
CompileRun(source_text);
logger.StopLogging();
......@@ -1062,19 +1096,25 @@ TEST_F(LogTest, ConsoleTimeEvents) {
{"timer-event,timerEvent3,"}};
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.
if (i::FLAG_always_opt) 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.
RunJS(
CompileRun(
"function warmUp(a) {"
" let b = () => 1;"
" return function(c) { return a+b+c; };"
......@@ -1093,7 +1133,7 @@ TEST_F(LogTest, LogFunctionEvents) {
"(function eagerFunction(){ return 'eager' })();"
"function Foo() { this.foo = function(){}; };"
"let i = new Foo(); i.foo();";
RunJS(source_text);
CompileRun(source_text);
logger.StopLogging();
......@@ -1137,11 +1177,16 @@ TEST_F(LogTest, LogFunctionEvents) {
CHECK(logger.ContainsLinesInOrder(lines));
}
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.LogCompiledFunctions();
......@@ -1164,6 +1209,5 @@ TEST_F(LogTest, BuiltinsNotLoggedAsLazyCompile) {
CHECK(!logger.ContainsLine(
{"code-creation,LazyCompile,2,", std::string(buffer.begin())}));
}
isolate->Dispose();
}
} // namespace v8
......@@ -374,7 +374,6 @@ 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",
......
......@@ -137,16 +137,6 @@ 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);
......
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