Commit 0eb28cd5 authored by Bill Budge's avatar Bill Budge Committed by Commit Bot

[cctest] Simplify tests that mock v8::Platform.

Adds a base class TestPlatform which implements the most common defaults
for v8::Platform methods.

Reworks existing cctests and unittests to use TestPlatform.

Bug: 
Cq-Include-Trybots: master.tryserver.chromium.linux:linux_chromium_rel_ng
Change-Id: Ifeb28a5a190529697d5bcac227e80b10d454d9bd
Reviewed-on: https://chromium-review.googlesource.com/590194Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Commit-Queue: Bill Budge <bbudge@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47050}
parent 7a5a777c
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include <memory> #include <memory>
#include "include/libplatform/libplatform.h" #include "include/libplatform/libplatform.h"
#include "include/v8-platform.h"
#include "src/debug/debug-interface.h" #include "src/debug/debug-interface.h"
#include "src/flags.h" #include "src/flags.h"
#include "src/utils.h" #include "src/utils.h"
...@@ -634,4 +635,58 @@ class ManualGCScope { ...@@ -634,4 +635,58 @@ class ManualGCScope {
bool flag_stress_incremental_marking_; bool flag_stress_incremental_marking_;
}; };
// This is an abstract base class that can be overridden to implement a test
// platform. It delegates all operations to a given platform at the time
// of construction.
class TestPlatform : public v8::Platform {
public:
// v8::Platform implementation.
void OnCriticalMemoryPressure() override {
old_platform_->OnCriticalMemoryPressure();
}
void CallOnBackgroundThread(v8::Task* task,
ExpectedRuntime expected_runtime) override {
old_platform_->CallOnBackgroundThread(task, expected_runtime);
}
void CallOnForegroundThread(v8::Isolate* isolate, v8::Task* task) override {
old_platform_->CallOnForegroundThread(isolate, task);
}
void CallDelayedOnForegroundThread(v8::Isolate* isolate, v8::Task* task,
double delay_in_seconds) override {
old_platform_->CallDelayedOnForegroundThread(isolate, task,
delay_in_seconds);
}
double MonotonicallyIncreasingTime() override {
return old_platform_->MonotonicallyIncreasingTime();
}
void CallIdleOnForegroundThread(v8::Isolate* isolate,
v8::IdleTask* task) override {
old_platform_->CallIdleOnForegroundThread(isolate, task);
}
bool IdleTasksEnabled(v8::Isolate* isolate) override {
return old_platform_->IdleTasksEnabled(isolate);
}
v8::TracingController* GetTracingController() override {
return old_platform_->GetTracingController();
}
protected:
TestPlatform() : old_platform_(i::V8::GetCurrentPlatform()) {}
~TestPlatform() { i::V8::SetPlatformForTesting(old_platform_); }
v8::Platform* old_platform() const { return old_platform_; }
private:
v8::Platform* old_platform_;
DISALLOW_COPY_AND_ASSIGN(TestPlatform);
};
#endif // ifndef CCTEST_H_ #endif // ifndef CCTEST_H_
...@@ -31,41 +31,20 @@ using v8::Isolate; ...@@ -31,41 +31,20 @@ using v8::Isolate;
namespace v8 { namespace v8 {
namespace internal { namespace internal {
class MockPlatform : public v8::Platform { class MockPlatform : public TestPlatform {
public: public:
explicit MockPlatform(v8::Platform* platform) MockPlatform() : task_(nullptr) {
: platform_(platform), task_(nullptr) {} // Now that it's completely constructed, make this the current platform.
virtual ~MockPlatform() { delete task_; } i::V8::SetPlatformForTesting(this);
void CallOnBackgroundThread(Task* task,
ExpectedRuntime expected_runtime) override {
platform_->CallOnBackgroundThread(task, expected_runtime);
} }
virtual ~MockPlatform() { delete task_; }
void CallOnForegroundThread(v8::Isolate* isolate, Task* task) override { void CallOnForegroundThread(v8::Isolate* isolate, Task* task) override {
task_ = task; task_ = task;
} }
void CallDelayedOnForegroundThread(v8::Isolate* isolate, Task* task,
double delay_in_seconds) override {
platform_->CallDelayedOnForegroundThread(isolate, task, delay_in_seconds);
}
double MonotonicallyIncreasingTime() override {
return platform_->MonotonicallyIncreasingTime();
}
void CallIdleOnForegroundThread(v8::Isolate* isolate,
IdleTask* task) override {
platform_->CallIdleOnForegroundThread(isolate, task);
}
bool IdleTasksEnabled(v8::Isolate* isolate) override { return false; } bool IdleTasksEnabled(v8::Isolate* isolate) override { return false; }
v8::TracingController* GetTracingController() override {
return platform_->GetTracingController();
}
bool PendingTask() { return task_ != nullptr; } bool PendingTask() { return task_ != nullptr; }
void PerformTask() { void PerformTask() {
...@@ -76,7 +55,6 @@ class MockPlatform : public v8::Platform { ...@@ -76,7 +55,6 @@ class MockPlatform : public v8::Platform {
} }
private: private:
v8::Platform* platform_;
Task* task_; Task* task_;
}; };
...@@ -84,9 +62,7 @@ TEST(IncrementalMarkingUsingTasks) { ...@@ -84,9 +62,7 @@ TEST(IncrementalMarkingUsingTasks) {
if (!i::FLAG_incremental_marking) return; if (!i::FLAG_incremental_marking) return;
FLAG_stress_incremental_marking = false; FLAG_stress_incremental_marking = false;
CcTest::InitializeVM(); CcTest::InitializeVM();
v8::Platform* old_platform = i::V8::GetCurrentPlatform(); MockPlatform platform;
MockPlatform platform(old_platform);
i::V8::SetPlatformForTesting(&platform);
i::heap::SimulateFullSpace(CcTest::heap()->old_space()); i::heap::SimulateFullSpace(CcTest::heap()->old_space());
i::IncrementalMarking* marking = CcTest::heap()->incremental_marking(); i::IncrementalMarking* marking = CcTest::heap()->incremental_marking();
marking->Stop(); marking->Stop();
...@@ -96,7 +72,6 @@ TEST(IncrementalMarkingUsingTasks) { ...@@ -96,7 +72,6 @@ TEST(IncrementalMarkingUsingTasks) {
platform.PerformTask(); platform.PerformTask();
} }
CHECK(marking->IsStopped()); CHECK(marking->IsStopped());
i::V8::SetPlatformForTesting(old_platform);
} }
} // namespace internal } // namespace internal
......
...@@ -23,54 +23,27 @@ using v8::Task; ...@@ -23,54 +23,27 @@ using v8::Task;
namespace { namespace {
// Minimal implementation of platform that can receive OOM callbacks. // Implementation of v8::Platform that can register OOM callbacks.
class MockAllocationPlatform : public v8::Platform { class AllocationPlatform : public TestPlatform {
public: public:
MockAllocationPlatform() { current_platform = this; } AllocationPlatform() {
virtual ~MockAllocationPlatform() {} current_platform = this;
// Now that it's completely constructed, make this the current platform.
void OnCriticalMemoryPressure() override { oom_callback_called = true; } i::V8::SetPlatformForTesting(this);
void CallOnBackgroundThread(Task* task,
ExpectedRuntime expected_runtime) override {}
void CallOnForegroundThread(Isolate* isolate, Task* task) override {}
void CallDelayedOnForegroundThread(Isolate* isolate, Task* task,
double delay_in_seconds) override {}
double MonotonicallyIncreasingTime() override { return 0.0; }
void CallIdleOnForegroundThread(Isolate* isolate, IdleTask* task) override {}
bool IdleTasksEnabled(Isolate* isolate) override { return false; }
v8::TracingController* GetTracingController() override {
return &tracing_controller_;
} }
virtual ~AllocationPlatform() = default;
bool PendingIdleTask() { return false; } void OnCriticalMemoryPressure() override { oom_callback_called = true; }
void PerformIdleTask(double idle_time_in_seconds) {}
bool PendingDelayedTask() { return false; }
void PerformDelayedTask() {}
static MockAllocationPlatform* current_platform; static AllocationPlatform* current_platform;
bool oom_callback_called = false; bool oom_callback_called = false;
private:
v8::TracingController tracing_controller_;
DISALLOW_COPY_AND_ASSIGN(MockAllocationPlatform);
}; };
MockAllocationPlatform* MockAllocationPlatform::current_platform = nullptr; AllocationPlatform* AllocationPlatform::current_platform = nullptr;
bool DidCallOnCriticalMemoryPressure() { bool DidCallOnCriticalMemoryPressure() {
return MockAllocationPlatform::current_platform && return AllocationPlatform::current_platform &&
MockAllocationPlatform::current_platform->oom_callback_called; AllocationPlatform::current_platform->oom_callback_called;
} }
// No OS should be able to malloc/new this number of bytes. Generate enough // No OS should be able to malloc/new this number of bytes. Generate enough
...@@ -112,25 +85,16 @@ void OnAlignedAllocOOM(const char* location, const char* message) { ...@@ -112,25 +85,16 @@ void OnAlignedAllocOOM(const char* location, const char* message) {
} // namespace } // namespace
TEST(AccountingAllocatorOOM) { TEST(AccountingAllocatorOOM) {
// TODO(bbudge) Implement a TemporaryPlatformScope to simplify test code. AllocationPlatform platform;
v8::Platform* old_platform = i::V8::GetCurrentPlatform();
MockAllocationPlatform platform;
i::V8::SetPlatformForTesting(&platform);
v8::internal::AccountingAllocator allocator; v8::internal::AccountingAllocator allocator;
CHECK(!platform.oom_callback_called); CHECK(!platform.oom_callback_called);
v8::internal::Segment* result = allocator.GetSegment(GetHugeMemoryAmount()); v8::internal::Segment* result = allocator.GetSegment(GetHugeMemoryAmount());
// On a few systems, allocation somehow succeeds. // On a few systems, allocation somehow succeeds.
CHECK_EQ(result == nullptr, platform.oom_callback_called); CHECK_EQ(result == nullptr, platform.oom_callback_called);
i::V8::SetPlatformForTesting(old_platform);
} }
TEST(MallocedOperatorNewOOM) { TEST(MallocedOperatorNewOOM) {
v8::Platform* old_platform = i::V8::GetCurrentPlatform(); AllocationPlatform platform;
MockAllocationPlatform platform;
i::V8::SetPlatformForTesting(&platform);
CHECK(!platform.oom_callback_called); CHECK(!platform.oom_callback_called);
CcTest::isolate()->SetFatalErrorHandler(OnMallocedOperatorNewOOM); CcTest::isolate()->SetFatalErrorHandler(OnMallocedOperatorNewOOM);
// On failure, this won't return, since a Malloced::New failure is fatal. // On failure, this won't return, since a Malloced::New failure is fatal.
...@@ -138,15 +102,10 @@ TEST(MallocedOperatorNewOOM) { ...@@ -138,15 +102,10 @@ TEST(MallocedOperatorNewOOM) {
void* result = v8::internal::Malloced::New(GetHugeMemoryAmount()); void* result = v8::internal::Malloced::New(GetHugeMemoryAmount());
// On a few systems, allocation somehow succeeds. // On a few systems, allocation somehow succeeds.
CHECK_EQ(result == nullptr, platform.oom_callback_called); CHECK_EQ(result == nullptr, platform.oom_callback_called);
i::V8::SetPlatformForTesting(old_platform);
} }
TEST(NewArrayOOM) { TEST(NewArrayOOM) {
v8::Platform* old_platform = i::V8::GetCurrentPlatform(); AllocationPlatform platform;
MockAllocationPlatform platform;
i::V8::SetPlatformForTesting(&platform);
CHECK(!platform.oom_callback_called); CHECK(!platform.oom_callback_called);
CcTest::isolate()->SetFatalErrorHandler(OnNewArrayOOM); CcTest::isolate()->SetFatalErrorHandler(OnNewArrayOOM);
// On failure, this won't return, since a NewArray failure is fatal. // On failure, this won't return, since a NewArray failure is fatal.
...@@ -154,15 +113,10 @@ TEST(NewArrayOOM) { ...@@ -154,15 +113,10 @@ TEST(NewArrayOOM) {
int8_t* result = v8::internal::NewArray<int8_t>(GetHugeMemoryAmount()); int8_t* result = v8::internal::NewArray<int8_t>(GetHugeMemoryAmount());
// On a few systems, allocation somehow succeeds. // On a few systems, allocation somehow succeeds.
CHECK_EQ(result == nullptr, platform.oom_callback_called); CHECK_EQ(result == nullptr, platform.oom_callback_called);
i::V8::SetPlatformForTesting(old_platform);
} }
TEST(AlignedAllocOOM) { TEST(AlignedAllocOOM) {
v8::Platform* old_platform = i::V8::GetCurrentPlatform(); AllocationPlatform platform;
MockAllocationPlatform platform;
i::V8::SetPlatformForTesting(&platform);
CHECK(!platform.oom_callback_called); CHECK(!platform.oom_callback_called);
CcTest::isolate()->SetFatalErrorHandler(OnAlignedAllocOOM); CcTest::isolate()->SetFatalErrorHandler(OnAlignedAllocOOM);
// On failure, this won't return, since an AlignedAlloc failure is fatal. // On failure, this won't return, since an AlignedAlloc failure is fatal.
...@@ -171,15 +125,10 @@ TEST(AlignedAllocOOM) { ...@@ -171,15 +125,10 @@ TEST(AlignedAllocOOM) {
v8::base::OS::AllocateAlignment()); v8::base::OS::AllocateAlignment());
// On a few systems, allocation somehow succeeds. // On a few systems, allocation somehow succeeds.
CHECK_EQ(result == nullptr, platform.oom_callback_called); CHECK_EQ(result == nullptr, platform.oom_callback_called);
i::V8::SetPlatformForTesting(old_platform);
} }
TEST(AllocVirtualMemoryOOM) { TEST(AllocVirtualMemoryOOM) {
v8::Platform* old_platform = i::V8::GetCurrentPlatform(); AllocationPlatform platform;
MockAllocationPlatform platform;
i::V8::SetPlatformForTesting(&platform);
CHECK(!platform.oom_callback_called); CHECK(!platform.oom_callback_called);
v8::base::VirtualMemory result; v8::base::VirtualMemory result;
bool success = bool success =
...@@ -187,15 +136,10 @@ TEST(AllocVirtualMemoryOOM) { ...@@ -187,15 +136,10 @@ TEST(AllocVirtualMemoryOOM) {
// On a few systems, allocation somehow succeeds. // On a few systems, allocation somehow succeeds.
CHECK_IMPLIES(success, result.IsReserved()); CHECK_IMPLIES(success, result.IsReserved());
CHECK_IMPLIES(!success, !result.IsReserved() && platform.oom_callback_called); CHECK_IMPLIES(!success, !result.IsReserved() && platform.oom_callback_called);
i::V8::SetPlatformForTesting(old_platform);
} }
TEST(AlignedAllocVirtualMemoryOOM) { TEST(AlignedAllocVirtualMemoryOOM) {
v8::Platform* old_platform = i::V8::GetCurrentPlatform(); AllocationPlatform platform;
MockAllocationPlatform platform;
i::V8::SetPlatformForTesting(&platform);
CHECK(!platform.oom_callback_called); CHECK(!platform.oom_callback_called);
v8::base::VirtualMemory result; v8::base::VirtualMemory result;
bool success = v8::internal::AlignedAllocVirtualMemory( bool success = v8::internal::AlignedAllocVirtualMemory(
...@@ -204,8 +148,6 @@ TEST(AlignedAllocVirtualMemoryOOM) { ...@@ -204,8 +148,6 @@ TEST(AlignedAllocVirtualMemoryOOM) {
// On a few systems, allocation somehow succeeds. // On a few systems, allocation somehow succeeds.
CHECK_IMPLIES(success, result.IsReserved()); CHECK_IMPLIES(success, result.IsReserved());
CHECK_IMPLIES(!success, !result.IsReserved() && platform.oom_callback_called); CHECK_IMPLIES(!success, !result.IsReserved() && platform.oom_callback_called);
i::V8::SetPlatformForTesting(old_platform);
} }
#endif // !defined(V8_USE_ADDRESS_SANITIZER) && !defined(MEMORY_SANITIZER) && #endif // !defined(V8_USE_ADDRESS_SANITIZER) && !defined(MEMORY_SANITIZER) &&
......
...@@ -84,65 +84,39 @@ class MockTracingController : public v8::TracingController { ...@@ -84,65 +84,39 @@ class MockTracingController : public v8::TracingController {
DISALLOW_COPY_AND_ASSIGN(MockTracingController); DISALLOW_COPY_AND_ASSIGN(MockTracingController);
}; };
class MockTracingPlatform : public v8::Platform { class MockTracingPlatform : public TestPlatform {
public: public:
explicit MockTracingPlatform(v8::Platform* platform) {} MockTracingPlatform() {
// Now that it's completely constructed, make this the current platform.
i::V8::SetPlatformForTesting(this);
}
virtual ~MockTracingPlatform() {} virtual ~MockTracingPlatform() {}
void CallOnBackgroundThread(Task* task,
ExpectedRuntime expected_runtime) override {}
void CallOnForegroundThread(Isolate* isolate, Task* task) override {}
void CallDelayedOnForegroundThread(Isolate* isolate, Task* task,
double delay_in_seconds) override {}
double MonotonicallyIncreasingTime() override { return 0.0; }
void CallIdleOnForegroundThread(Isolate* isolate, IdleTask* task) override {}
bool IdleTasksEnabled(Isolate* isolate) override { return false; }
v8::TracingController* GetTracingController() override { v8::TracingController* GetTracingController() override {
return &tracing_controller_; return &tracing_controller_;
} }
bool PendingIdleTask() { return false; }
void PerformIdleTask(double idle_time_in_seconds) {}
bool PendingDelayedTask() { return false; }
void PerformDelayedTask() {}
MockTraceObjectList* GetMockTraceObjects() { MockTraceObjectList* GetMockTraceObjects() {
return tracing_controller_.GetMockTraceObjects(); return tracing_controller_.GetMockTraceObjects();
} }
private: private:
MockTracingController tracing_controller_; MockTracingController tracing_controller_;
DISALLOW_COPY_AND_ASSIGN(MockTracingPlatform);
}; };
TEST(TraceEventDisabledCategory) { TEST(TraceEventDisabledCategory) {
v8::Platform* old_platform = i::V8::GetCurrentPlatform(); MockTracingPlatform platform;
MockTracingPlatform platform(old_platform);
i::V8::SetPlatformForTesting(&platform);
// Disabled category, will not add events. // Disabled category, will not add events.
TRACE_EVENT_BEGIN0("cat", "e1"); TRACE_EVENT_BEGIN0("cat", "e1");
TRACE_EVENT_END0("cat", "e1"); TRACE_EVENT_END0("cat", "e1");
CHECK_EQ(0, GET_TRACE_OBJECTS_LIST->length()); CHECK_EQ(0, GET_TRACE_OBJECTS_LIST->length());
i::V8::SetPlatformForTesting(old_platform);
} }
TEST(TraceEventNoArgs) { TEST(TraceEventNoArgs) {
v8::Platform* old_platform = i::V8::GetCurrentPlatform(); MockTracingPlatform platform;
MockTracingPlatform platform(old_platform);
i::V8::SetPlatformForTesting(&platform);
// Enabled category will add 2 events. // Enabled category will add 2 events.
TRACE_EVENT_BEGIN0("v8-cat", "e1"); TRACE_EVENT_BEGIN0("v8-cat", "e1");
...@@ -156,15 +130,11 @@ TEST(TraceEventNoArgs) { ...@@ -156,15 +130,11 @@ TEST(TraceEventNoArgs) {
CHECK_EQ('E', GET_TRACE_OBJECT(1)->phase); CHECK_EQ('E', GET_TRACE_OBJECT(1)->phase);
CHECK_EQ("e1", GET_TRACE_OBJECT(1)->name); CHECK_EQ("e1", GET_TRACE_OBJECT(1)->name);
CHECK_EQ(0, GET_TRACE_OBJECT(1)->num_args); CHECK_EQ(0, GET_TRACE_OBJECT(1)->num_args);
i::V8::SetPlatformForTesting(old_platform);
} }
TEST(TraceEventWithOneArg) { TEST(TraceEventWithOneArg) {
v8::Platform* old_platform = i::V8::GetCurrentPlatform(); MockTracingPlatform platform;
MockTracingPlatform platform(old_platform);
i::V8::SetPlatformForTesting(&platform);
TRACE_EVENT_BEGIN1("v8-cat", "e1", "arg1", 42); TRACE_EVENT_BEGIN1("v8-cat", "e1", "arg1", 42);
TRACE_EVENT_END1("v8-cat", "e1", "arg1", 42); TRACE_EVENT_END1("v8-cat", "e1", "arg1", 42);
...@@ -177,15 +147,11 @@ TEST(TraceEventWithOneArg) { ...@@ -177,15 +147,11 @@ TEST(TraceEventWithOneArg) {
CHECK_EQ(1, GET_TRACE_OBJECT(1)->num_args); CHECK_EQ(1, GET_TRACE_OBJECT(1)->num_args);
CHECK_EQ(1, GET_TRACE_OBJECT(2)->num_args); CHECK_EQ(1, GET_TRACE_OBJECT(2)->num_args);
CHECK_EQ(1, GET_TRACE_OBJECT(3)->num_args); CHECK_EQ(1, GET_TRACE_OBJECT(3)->num_args);
i::V8::SetPlatformForTesting(old_platform);
} }
TEST(TraceEventWithTwoArgs) { TEST(TraceEventWithTwoArgs) {
v8::Platform* old_platform = i::V8::GetCurrentPlatform(); MockTracingPlatform platform;
MockTracingPlatform platform(old_platform);
i::V8::SetPlatformForTesting(&platform);
TRACE_EVENT_BEGIN2("v8-cat", "e1", "arg1", 42, "arg2", "abc"); TRACE_EVENT_BEGIN2("v8-cat", "e1", "arg1", 42, "arg2", "abc");
TRACE_EVENT_END2("v8-cat", "e1", "arg1", 42, "arg2", "abc"); TRACE_EVENT_END2("v8-cat", "e1", "arg1", 42, "arg2", "abc");
...@@ -198,15 +164,11 @@ TEST(TraceEventWithTwoArgs) { ...@@ -198,15 +164,11 @@ TEST(TraceEventWithTwoArgs) {
CHECK_EQ(2, GET_TRACE_OBJECT(1)->num_args); CHECK_EQ(2, GET_TRACE_OBJECT(1)->num_args);
CHECK_EQ(2, GET_TRACE_OBJECT(2)->num_args); CHECK_EQ(2, GET_TRACE_OBJECT(2)->num_args);
CHECK_EQ(2, GET_TRACE_OBJECT(3)->num_args); CHECK_EQ(2, GET_TRACE_OBJECT(3)->num_args);
i::V8::SetPlatformForTesting(old_platform);
} }
TEST(ScopedTraceEvent) { TEST(ScopedTraceEvent) {
v8::Platform* old_platform = i::V8::GetCurrentPlatform(); MockTracingPlatform platform;
MockTracingPlatform platform(old_platform);
i::V8::SetPlatformForTesting(&platform);
{ TRACE_EVENT0("v8-cat", "e"); } { TRACE_EVENT0("v8-cat", "e"); }
...@@ -222,15 +184,11 @@ TEST(ScopedTraceEvent) { ...@@ -222,15 +184,11 @@ TEST(ScopedTraceEvent) {
CHECK_EQ(3, GET_TRACE_OBJECTS_LIST->length()); CHECK_EQ(3, GET_TRACE_OBJECTS_LIST->length());
CHECK_EQ(2, GET_TRACE_OBJECT(2)->num_args); CHECK_EQ(2, GET_TRACE_OBJECT(2)->num_args);
i::V8::SetPlatformForTesting(old_platform);
} }
TEST(TestEventWithFlow) { TEST(TestEventWithFlow) {
v8::Platform* old_platform = i::V8::GetCurrentPlatform(); MockTracingPlatform platform;
MockTracingPlatform platform(old_platform);
i::V8::SetPlatformForTesting(&platform);
static uint64_t bind_id = 21; static uint64_t bind_id = 21;
{ {
...@@ -251,15 +209,11 @@ TEST(TestEventWithFlow) { ...@@ -251,15 +209,11 @@ TEST(TestEventWithFlow) {
GET_TRACE_OBJECT(1)->flags); GET_TRACE_OBJECT(1)->flags);
CHECK_EQ(bind_id, GET_TRACE_OBJECT(2)->bind_id); CHECK_EQ(bind_id, GET_TRACE_OBJECT(2)->bind_id);
CHECK_EQ(TRACE_EVENT_FLAG_FLOW_IN, GET_TRACE_OBJECT(2)->flags); CHECK_EQ(TRACE_EVENT_FLAG_FLOW_IN, GET_TRACE_OBJECT(2)->flags);
i::V8::SetPlatformForTesting(old_platform);
} }
TEST(TestEventWithId) { TEST(TestEventWithId) {
v8::Platform* old_platform = i::V8::GetCurrentPlatform(); MockTracingPlatform platform;
MockTracingPlatform platform(old_platform);
i::V8::SetPlatformForTesting(&platform);
static uint64_t event_id = 21; static uint64_t event_id = 21;
TRACE_EVENT_ASYNC_BEGIN0("v8-cat", "a1", event_id); TRACE_EVENT_ASYNC_BEGIN0("v8-cat", "a1", event_id);
...@@ -270,14 +224,10 @@ TEST(TestEventWithId) { ...@@ -270,14 +224,10 @@ TEST(TestEventWithId) {
CHECK_EQ(event_id, GET_TRACE_OBJECT(0)->id); CHECK_EQ(event_id, GET_TRACE_OBJECT(0)->id);
CHECK_EQ(TRACE_EVENT_PHASE_ASYNC_END, GET_TRACE_OBJECT(1)->phase); CHECK_EQ(TRACE_EVENT_PHASE_ASYNC_END, GET_TRACE_OBJECT(1)->phase);
CHECK_EQ(event_id, GET_TRACE_OBJECT(1)->id); CHECK_EQ(event_id, GET_TRACE_OBJECT(1)->id);
i::V8::SetPlatformForTesting(old_platform);
} }
TEST(TestEventInContext) { TEST(TestEventInContext) {
v8::Platform* old_platform = i::V8::GetCurrentPlatform(); MockTracingPlatform platform;
MockTracingPlatform platform(old_platform);
i::V8::SetPlatformForTesting(&platform);
static uint64_t isolate_id = 0x20151021; static uint64_t isolate_id = 0x20151021;
{ {
...@@ -294,6 +244,4 @@ TEST(TestEventInContext) { ...@@ -294,6 +244,4 @@ TEST(TestEventInContext) {
CHECK_EQ(TRACE_EVENT_PHASE_LEAVE_CONTEXT, GET_TRACE_OBJECT(2)->phase); CHECK_EQ(TRACE_EVENT_PHASE_LEAVE_CONTEXT, GET_TRACE_OBJECT(2)->phase);
CHECK_EQ("Isolate", GET_TRACE_OBJECT(2)->name); CHECK_EQ("Isolate", GET_TRACE_OBJECT(2)->name);
CHECK_EQ(isolate_id, GET_TRACE_OBJECT(2)->id); CHECK_EQ(isolate_id, GET_TRACE_OBJECT(2)->id);
i::V8::SetPlatformForTesting(old_platform);
} }
...@@ -115,12 +115,12 @@ namespace { ...@@ -115,12 +115,12 @@ namespace {
class MockPlatform : public v8::Platform { class MockPlatform : public v8::Platform {
public: public:
explicit MockPlatform(v8::TracingController* tracing_controller) MockPlatform()
: time_(0.0), : time_(0.0),
time_step_(0.0), time_step_(0.0),
idle_task_(nullptr), idle_task_(nullptr),
sem_(0), sem_(0),
tracing_controller_(tracing_controller) {} tracing_controller_(V8::GetCurrentPlatform()->GetTracingController()) {}
~MockPlatform() override { ~MockPlatform() override {
base::LockGuard<base::Mutex> lock(&mutex_); base::LockGuard<base::Mutex> lock(&mutex_);
EXPECT_TRUE(foreground_tasks_.empty()); EXPECT_TRUE(foreground_tasks_.empty());
...@@ -300,12 +300,12 @@ const char test_script[] = "(x) { x*x; }"; ...@@ -300,12 +300,12 @@ const char test_script[] = "(x) { x*x; }";
} // namespace } // namespace
TEST_F(CompilerDispatcherTest, Construct) { TEST_F(CompilerDispatcherTest, Construct) {
MockPlatform platform(V8::GetCurrentPlatform()->GetTracingController()); MockPlatform platform;
CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size); CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
} }
TEST_F(CompilerDispatcherTest, IsEnqueued) { TEST_F(CompilerDispatcherTest, IsEnqueued) {
MockPlatform platform(V8::GetCurrentPlatform()->GetTracingController()); MockPlatform platform;
CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size); CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
const char script[] = TEST_SCRIPT(); const char script[] = TEST_SCRIPT();
...@@ -323,7 +323,7 @@ TEST_F(CompilerDispatcherTest, IsEnqueued) { ...@@ -323,7 +323,7 @@ TEST_F(CompilerDispatcherTest, IsEnqueued) {
} }
TEST_F(CompilerDispatcherTest, FinishNow) { TEST_F(CompilerDispatcherTest, FinishNow) {
MockPlatform platform(V8::GetCurrentPlatform()->GetTracingController()); MockPlatform platform;
CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size); CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
const char script[] = TEST_SCRIPT(); const char script[] = TEST_SCRIPT();
...@@ -342,7 +342,7 @@ TEST_F(CompilerDispatcherTest, FinishNow) { ...@@ -342,7 +342,7 @@ TEST_F(CompilerDispatcherTest, FinishNow) {
} }
TEST_F(CompilerDispatcherTest, FinishAllNow) { TEST_F(CompilerDispatcherTest, FinishAllNow) {
MockPlatform platform(V8::GetCurrentPlatform()->GetTracingController()); MockPlatform platform;
CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size); CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
constexpr int num_funcs = 2; constexpr int num_funcs = 2;
...@@ -372,7 +372,7 @@ TEST_F(CompilerDispatcherTest, FinishAllNow) { ...@@ -372,7 +372,7 @@ TEST_F(CompilerDispatcherTest, FinishAllNow) {
} }
TEST_F(CompilerDispatcherTest, IdleTask) { TEST_F(CompilerDispatcherTest, IdleTask) {
MockPlatform platform(V8::GetCurrentPlatform()->GetTracingController()); MockPlatform platform;
CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size); CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
const char script[] = TEST_SCRIPT(); const char script[] = TEST_SCRIPT();
...@@ -393,7 +393,7 @@ TEST_F(CompilerDispatcherTest, IdleTask) { ...@@ -393,7 +393,7 @@ TEST_F(CompilerDispatcherTest, IdleTask) {
} }
TEST_F(CompilerDispatcherTest, IdleTaskSmallIdleTime) { TEST_F(CompilerDispatcherTest, IdleTaskSmallIdleTime) {
MockPlatform platform(V8::GetCurrentPlatform()->GetTracingController()); MockPlatform platform;
CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size); CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
const char script[] = TEST_SCRIPT(); const char script[] = TEST_SCRIPT();
...@@ -432,7 +432,7 @@ TEST_F(CompilerDispatcherTest, IdleTaskSmallIdleTime) { ...@@ -432,7 +432,7 @@ TEST_F(CompilerDispatcherTest, IdleTaskSmallIdleTime) {
} }
TEST_F(CompilerDispatcherTest, IdleTaskException) { TEST_F(CompilerDispatcherTest, IdleTaskException) {
MockPlatform platform(V8::GetCurrentPlatform()->GetTracingController()); MockPlatform platform;
CompilerDispatcher dispatcher(i_isolate(), &platform, 50); CompilerDispatcher dispatcher(i_isolate(), &platform, 50);
std::string func_name("f" STR(__LINE__)); std::string func_name("f" STR(__LINE__));
...@@ -459,7 +459,7 @@ TEST_F(CompilerDispatcherTest, IdleTaskException) { ...@@ -459,7 +459,7 @@ TEST_F(CompilerDispatcherTest, IdleTaskException) {
} }
TEST_F(CompilerDispatcherTest, CompileOnBackgroundThread) { TEST_F(CompilerDispatcherTest, CompileOnBackgroundThread) {
MockPlatform platform(V8::GetCurrentPlatform()->GetTracingController()); MockPlatform platform;
CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size); CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
const char script[] = TEST_SCRIPT(); const char script[] = TEST_SCRIPT();
...@@ -503,7 +503,7 @@ TEST_F(CompilerDispatcherTest, CompileOnBackgroundThread) { ...@@ -503,7 +503,7 @@ TEST_F(CompilerDispatcherTest, CompileOnBackgroundThread) {
} }
TEST_F(CompilerDispatcherTest, FinishNowWithBackgroundTask) { TEST_F(CompilerDispatcherTest, FinishNowWithBackgroundTask) {
MockPlatform platform(V8::GetCurrentPlatform()->GetTracingController()); MockPlatform platform;
CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size); CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
const char script[] = TEST_SCRIPT(); const char script[] = TEST_SCRIPT();
...@@ -543,7 +543,7 @@ TEST_F(CompilerDispatcherTest, FinishNowWithBackgroundTask) { ...@@ -543,7 +543,7 @@ TEST_F(CompilerDispatcherTest, FinishNowWithBackgroundTask) {
} }
TEST_F(CompilerDispatcherTest, IdleTaskMultipleJobs) { TEST_F(CompilerDispatcherTest, IdleTaskMultipleJobs) {
MockPlatform platform(V8::GetCurrentPlatform()->GetTracingController()); MockPlatform platform;
CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size); CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
const char script1[] = TEST_SCRIPT(); const char script1[] = TEST_SCRIPT();
...@@ -572,7 +572,7 @@ TEST_F(CompilerDispatcherTest, IdleTaskMultipleJobs) { ...@@ -572,7 +572,7 @@ TEST_F(CompilerDispatcherTest, IdleTaskMultipleJobs) {
} }
TEST_F(CompilerDispatcherTest, FinishNowException) { TEST_F(CompilerDispatcherTest, FinishNowException) {
MockPlatform platform(V8::GetCurrentPlatform()->GetTracingController()); MockPlatform platform;
CompilerDispatcher dispatcher(i_isolate(), &platform, 50); CompilerDispatcher dispatcher(i_isolate(), &platform, 50);
std::string func_name("f" STR(__LINE__)); std::string func_name("f" STR(__LINE__));
...@@ -600,7 +600,7 @@ TEST_F(CompilerDispatcherTest, FinishNowException) { ...@@ -600,7 +600,7 @@ TEST_F(CompilerDispatcherTest, FinishNowException) {
} }
TEST_F(CompilerDispatcherTest, AsyncAbortAllPendingBackgroundTask) { TEST_F(CompilerDispatcherTest, AsyncAbortAllPendingBackgroundTask) {
MockPlatform platform(V8::GetCurrentPlatform()->GetTracingController()); MockPlatform platform;
CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size); CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
const char script[] = TEST_SCRIPT(); const char script[] = TEST_SCRIPT();
...@@ -643,7 +643,7 @@ TEST_F(CompilerDispatcherTest, AsyncAbortAllPendingBackgroundTask) { ...@@ -643,7 +643,7 @@ TEST_F(CompilerDispatcherTest, AsyncAbortAllPendingBackgroundTask) {
} }
TEST_F(CompilerDispatcherTest, AsyncAbortAllRunningBackgroundTask) { TEST_F(CompilerDispatcherTest, AsyncAbortAllRunningBackgroundTask) {
MockPlatform platform(V8::GetCurrentPlatform()->GetTracingController()); MockPlatform platform;
CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size); CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
const char script1[] = TEST_SCRIPT(); const char script1[] = TEST_SCRIPT();
...@@ -725,7 +725,7 @@ TEST_F(CompilerDispatcherTest, AsyncAbortAllRunningBackgroundTask) { ...@@ -725,7 +725,7 @@ TEST_F(CompilerDispatcherTest, AsyncAbortAllRunningBackgroundTask) {
} }
TEST_F(CompilerDispatcherTest, FinishNowDuringAbortAll) { TEST_F(CompilerDispatcherTest, FinishNowDuringAbortAll) {
MockPlatform platform(V8::GetCurrentPlatform()->GetTracingController()); MockPlatform platform;
CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size); CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
const char script[] = TEST_SCRIPT(); const char script[] = TEST_SCRIPT();
...@@ -804,7 +804,7 @@ TEST_F(CompilerDispatcherTest, FinishNowDuringAbortAll) { ...@@ -804,7 +804,7 @@ TEST_F(CompilerDispatcherTest, FinishNowDuringAbortAll) {
} }
TEST_F(CompilerDispatcherTest, MemoryPressure) { TEST_F(CompilerDispatcherTest, MemoryPressure) {
MockPlatform platform(V8::GetCurrentPlatform()->GetTracingController()); MockPlatform platform;
CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size); CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
const char script[] = TEST_SCRIPT(); const char script[] = TEST_SCRIPT();
...@@ -852,7 +852,7 @@ class PressureNotificationTask : public CancelableTask { ...@@ -852,7 +852,7 @@ class PressureNotificationTask : public CancelableTask {
} // namespace } // namespace
TEST_F(CompilerDispatcherTest, MemoryPressureFromBackground) { TEST_F(CompilerDispatcherTest, MemoryPressureFromBackground) {
MockPlatform platform(V8::GetCurrentPlatform()->GetTracingController()); MockPlatform platform;
CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size); CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
const char script[] = TEST_SCRIPT(); const char script[] = TEST_SCRIPT();
...@@ -885,7 +885,7 @@ TEST_F(CompilerDispatcherTest, MemoryPressureFromBackground) { ...@@ -885,7 +885,7 @@ TEST_F(CompilerDispatcherTest, MemoryPressureFromBackground) {
} }
TEST_F(CompilerDispatcherTest, EnqueueJob) { TEST_F(CompilerDispatcherTest, EnqueueJob) {
MockPlatform platform(V8::GetCurrentPlatform()->GetTracingController()); MockPlatform platform;
CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size); CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
const char script[] = TEST_SCRIPT(); const char script[] = TEST_SCRIPT();
Handle<JSFunction> f = Handle<JSFunction> f =
...@@ -904,7 +904,7 @@ TEST_F(CompilerDispatcherTest, EnqueueJob) { ...@@ -904,7 +904,7 @@ TEST_F(CompilerDispatcherTest, EnqueueJob) {
} }
TEST_F(CompilerDispatcherTest, EnqueueWithoutSFI) { TEST_F(CompilerDispatcherTest, EnqueueWithoutSFI) {
MockPlatform platform(V8::GetCurrentPlatform()->GetTracingController()); MockPlatform platform;
CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size); CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
ASSERT_TRUE(dispatcher.jobs_.empty()); ASSERT_TRUE(dispatcher.jobs_.empty());
ASSERT_TRUE(dispatcher.shared_to_unoptimized_job_id_.empty()); ASSERT_TRUE(dispatcher.shared_to_unoptimized_job_id_.empty());
...@@ -929,7 +929,7 @@ TEST_F(CompilerDispatcherTest, EnqueueWithoutSFI) { ...@@ -929,7 +929,7 @@ TEST_F(CompilerDispatcherTest, EnqueueWithoutSFI) {
} }
TEST_F(CompilerDispatcherTest, EnqueueAndStep) { TEST_F(CompilerDispatcherTest, EnqueueAndStep) {
MockPlatform platform(V8::GetCurrentPlatform()->GetTracingController()); MockPlatform platform;
CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size); CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
const char script[] = TEST_SCRIPT(); const char script[] = TEST_SCRIPT();
...@@ -1000,7 +1000,7 @@ TEST_F(CompilerDispatcherTest, CompileLazy2FinishesDispatcherJob) { ...@@ -1000,7 +1000,7 @@ TEST_F(CompilerDispatcherTest, CompileLazy2FinishesDispatcherJob) {
} }
TEST_F(CompilerDispatcherTest, EnqueueAndStepTwice) { TEST_F(CompilerDispatcherTest, EnqueueAndStepTwice) {
MockPlatform platform(V8::GetCurrentPlatform()->GetTracingController()); MockPlatform platform;
CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size); CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
const char script[] = TEST_SCRIPT(); const char script[] = TEST_SCRIPT();
...@@ -1026,7 +1026,7 @@ TEST_F(CompilerDispatcherTest, EnqueueAndStepTwice) { ...@@ -1026,7 +1026,7 @@ TEST_F(CompilerDispatcherTest, EnqueueAndStepTwice) {
} }
TEST_F(CompilerDispatcherTest, CompileMultipleOnBackgroundThread) { TEST_F(CompilerDispatcherTest, CompileMultipleOnBackgroundThread) {
MockPlatform platform(V8::GetCurrentPlatform()->GetTracingController()); MockPlatform platform;
CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size); CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
const char script1[] = TEST_SCRIPT(); const char script1[] = TEST_SCRIPT();
......
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