Commit 49c507dc authored by Leszek Swirski's avatar Leszek Swirski Committed by V8 LUCI CQ

[test] Make cctest run one test, with maybe custom platform

Remove cctest's ability to run multiple tests (which has long been
deprecated and mostly broken). We can then make platform & V8
initialisation be part of running the test's Run method.

In particular, this allows us to inject custom logic into the platform
initialisation, like setting up a platform wrapper. Add a
TEST_WITH_PLATFORM which exercises this by registering a platform
factory on the test, and wrapping the default platform using this
factory. This allows these tests to guarantee that the lifetime of the
platform is longer than the lifetime of the isolate.

As a result of this, we can also remove the complexity around draining
platform state in the TestPlatform (since it will now have a longer
lifetime than the Isolate using it), and as a drive-by clean up the
TestPlaform to use a CcTest-global "default platform" instead of trying
to scope over the "current" platform.

As another drive-by, change the linked-list of CcTests and the linear
search through it into an std::map of tests.

Change-Id: I610f6312fe042f29f45cc4dfba311e4184bc7759
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3569223Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/main@{#79772}
parent 899f0af7
This diff is collapsed.
......@@ -69,23 +69,40 @@ class JSHeapBroker;
} // namespace v8
#ifndef TEST
#define TEST(Name) \
static void Test##Name(); \
CcTest register_test_##Name(Test##Name, __FILE__, #Name, true, true); \
#define TEST(Name) \
static void Test##Name(); \
CcTest register_test_##Name(Test##Name, __FILE__, #Name, true, true, \
nullptr); \
static void Test##Name()
#endif
#ifndef UNINITIALIZED_TEST
#define UNINITIALIZED_TEST(Name) \
static void Test##Name(); \
CcTest register_test_##Name(Test##Name, __FILE__, #Name, true, false); \
#define UNINITIALIZED_TEST(Name) \
static void Test##Name(); \
CcTest register_test_##Name(Test##Name, __FILE__, #Name, true, false, \
nullptr); \
static void Test##Name()
#endif
#ifndef TEST_WITH_PLATFORM
#define TEST_WITH_PLATFORM(Name, PlatformClass) \
static void Test##Name(PlatformClass& platform); \
static void TestWithoutPlatform##Name() { \
Test##Name(*static_cast<PlatformClass*>(i::V8::GetCurrentPlatform())); \
} \
CcTest register_test_##Name(TestWithoutPlatform##Name, __FILE__, #Name, \
true, true, \
[]() -> std::unique_ptr<TestPlatform> { \
return std::make_unique<PlatformClass>(); \
}); \
static void Test##Name(PlatformClass& platform)
#endif
#ifndef DISABLED_TEST
#define DISABLED_TEST(Name) \
static void Test##Name(); \
CcTest register_test_##Name(Test##Name, __FILE__, #Name, false, true); \
#define DISABLED_TEST(Name) \
static void Test##Name(); \
CcTest register_test_##Name(Test##Name, __FILE__, #Name, false, true, \
nullptr); \
static void Test##Name()
#endif
......@@ -97,9 +114,9 @@ class JSHeapBroker;
// to correctly associate the tests with the test suite using them.
// 2. To actually execute the tests, create an instance of the class
// containing the MEMBER_TESTs.
#define MEMBER_TEST(Name) \
CcTest register_test_##Name = \
CcTest(Test##Name, kTestFileName, #Name, true, true); \
#define MEMBER_TEST(Name) \
CcTest register_test_##Name = \
CcTest(Test##Name, kTestFileName, #Name, true, true, nullptr); \
static void Test##Name()
#define EXTENSION_LIST(V) \
......@@ -119,18 +136,19 @@ static constexpr const char* kExtensionName[kMaxExtensions] = {
EXTENSION_LIST(DEFINE_EXTENSION_NAME)};
#undef DEFINE_EXTENSION_NAME
class CcTest;
class TestPlatform;
using CcTestMapType = std::map<std::string, CcTest*>;
class CcTest {
public:
using TestFunction = void();
using TestPlatformFactory = std::unique_ptr<TestPlatform>();
CcTest(TestFunction* callback, const char* file, const char* name,
bool enabled, bool initialize);
~CcTest() { i::DeleteArray(file_); }
void Run();
static CcTest* last() { return last_; }
CcTest* prev() { return prev_; }
const char* file() { return file_; }
const char* name() { return name_; }
bool enabled() { return enabled_; }
bool enabled, bool initialize,
TestPlatformFactory* platform_factory = nullptr);
void Run(const char* argv0);
static v8::Isolate* isolate() {
CHECK_NOT_NULL(isolate_);
......@@ -150,6 +168,8 @@ class CcTest {
static i::Heap* heap();
static i::ReadOnlyHeap* read_only_heap();
static v8::Platform* default_platform() { return default_platform_; }
static void AddGlobalFunction(v8::Local<v8::Context> env, const char* name,
v8::FunctionCallback callback);
static void CollectGarbage(i::AllocationSpace space,
......@@ -178,9 +198,6 @@ class CcTest {
// This must be called first in a test.
static void InitializeVM();
// Only for UNINITIALIZED_TESTs
static void DisableAutomaticDispose();
// Helper function to configure a context.
// Must be in a HandleScope.
static v8::Local<v8::Context> NewContext(
......@@ -196,21 +213,17 @@ class CcTest {
return NewContext(CcTestExtensionFlags{extensions}, isolate);
}
static void TearDown();
private:
static CcTest* last_;
static std::unordered_map<std::string, CcTest*>* tests_;
static v8::ArrayBuffer::Allocator* allocator_;
static v8::Isolate* isolate_;
static v8::Platform* default_platform_;
static bool initialize_called_;
static v8::base::Atomic32 isolate_used_;
TestFunction* callback_;
const char* file_;
const char* name_;
bool enabled_;
bool initialize_;
CcTest* prev_;
TestPlatformFactory* test_platform_factory_;
friend int main(int argc, char** argv);
friend class ManualGCScope;
......@@ -632,8 +645,7 @@ static inline void DisableDebugger(v8::Isolate* isolate) {
static inline void EmptyMessageQueues(v8::Isolate* isolate) {
while (v8::platform::PumpMessageLoop(v8::internal::V8::GetCurrentPlatform(),
isolate)) {
while (v8::platform::PumpMessageLoop(CcTest::default_platform(), isolate)) {
}
}
......@@ -701,19 +713,10 @@ class V8_NODISCARD ManualGCScope {
};
// This is a base class that can be overridden to implement a test platform. It
// delegates all operations to a given platform at the time of construction.
// Breaks if tasks cache the platform themselves.
// delegates all operations to the default platform.
class TestPlatform : public v8::Platform {
public:
// Users inheriting from `TestPlatform` need to invoke `NotifyPlatformReady()`
// at the end of their constructor.
void NotifyPlatformReady();
// Eagerly removes the platform from being used by V8.
void RemovePlatform();
TestPlatform(const TestPlatform&) = delete;
TestPlatform& operator=(const TestPlatform&) = delete;
~TestPlatform() override = default;
// v8::Platform implementation.
v8::PageAllocator* GetPageAllocator() override;
......@@ -734,14 +737,7 @@ class TestPlatform : public v8::Platform {
v8::TracingController* GetTracingController() override;
protected:
TestPlatform();
~TestPlatform() override;
v8::Platform* old_platform() const { return old_platform_; }
private:
std::atomic<v8::Platform*> old_platform_;
bool active_ = false;
TestPlatform() = default;
};
#if defined(USE_SIMULATOR)
......
......@@ -35,11 +35,10 @@ namespace heap {
class MockPlatform : public TestPlatform {
public:
MockPlatform() : taskrunner_(new MockTaskRunner()) { NotifyPlatformReady(); }
MockPlatform() : taskrunner_(new MockTaskRunner()) {}
~MockPlatform() override {
RemovePlatform();
for (auto& task : worker_tasks_) {
old_platform()->CallOnWorkerThread(std::move(task));
CcTest::default_platform()->CallOnWorkerThread(std::move(task));
}
worker_tasks_.clear();
}
......@@ -103,14 +102,11 @@ class MockPlatform : public TestPlatform {
std::vector<std::unique_ptr<Task>> worker_tasks_;
};
UNINITIALIZED_TEST(IncrementalMarkingUsingTasks) {
TEST_WITH_PLATFORM(IncrementalMarkingUsingTasks, MockPlatform) {
if (!i::FLAG_incremental_marking) return;
FLAG_stress_concurrent_allocation = false; // For SimulateFullSpace.
FLAG_stress_incremental_marking = false;
MockPlatform platform;
v8::Isolate::CreateParams create_params;
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
v8::Isolate* isolate = v8::Isolate::New(create_params);
v8::Isolate* isolate = CcTest::isolate();
{
v8::HandleScope handle_scope(isolate);
v8::Local<v8::Context> context = CcTest::NewContext(isolate);
......@@ -134,7 +130,6 @@ UNINITIALIZED_TEST(IncrementalMarkingUsingTasks) {
}
CHECK(marking->IsStopped());
}
isolate->Dispose();
}
} // namespace heap
......
......@@ -132,10 +132,7 @@ namespace {
class MockPlatform : public TestPlatform {
public:
MockPlatform() : mock_task_runner_(new MockTaskRunner()) {
NotifyPlatformReady();
}
~MockPlatform() override { RemovePlatform(); }
MockPlatform() : mock_task_runner_(new MockTaskRunner()) {}
std::shared_ptr<v8::TaskRunner> GetForegroundTaskRunner(
v8::Isolate*) override {
......@@ -199,14 +196,10 @@ class MockMeasureMemoryDelegate : public v8::MeasureMemoryDelegate {
} // namespace
TEST(RandomizedTimeout) {
MockPlatform platform;
TEST_WITH_PLATFORM(RandomizedTimeout, MockPlatform) {
v8::Isolate::CreateParams create_params;
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
// We have to create the isolate manually here. Using CcTest::isolate() would
// lead to the situation when the isolate outlives MockPlatform which may lead
// to UAF on the background thread.
v8::Isolate* isolate = v8::Isolate::New(create_params);
v8::Isolate* isolate = CcTest::isolate();
std::vector<double> delays;
for (int i = 0; i < 10; i++) {
isolate->MeasureMemory(std::make_unique<MockMeasureMemoryDelegate>());
......@@ -214,7 +207,6 @@ TEST(RandomizedTimeout) {
platform.PerformTask();
}
std::sort(delays.begin(), delays.end());
isolate->Dispose();
CHECK_LT(delays[0], delays.back());
}
......
......@@ -20,11 +20,9 @@ namespace heap {
class MockPlatformForUnmapper : public TestPlatform {
public:
MockPlatformForUnmapper() { NotifyPlatformReady(); }
~MockPlatformForUnmapper() override {
RemovePlatform();
for (auto& task : worker_tasks_) {
old_platform()->CallOnWorkerThread(std::move(task));
CcTest::default_platform()->CallOnWorkerThread(std::move(task));
}
worker_tasks_.clear();
}
......
......@@ -32,11 +32,7 @@ namespace {
// Implementation of v8::Platform that can register OOM callbacks.
class AllocationPlatform : public TestPlatform {
public:
AllocationPlatform() {
current_platform = this;
NotifyPlatformReady();
}
~AllocationPlatform() override { RemovePlatform(); }
AllocationPlatform() { current_platform = this; }
void OnCriticalMemoryPressure() override { oom_callback_called = true; }
......@@ -94,8 +90,7 @@ void OnAlignedAllocOOM(const char* location, const char* message) {
} // namespace
TEST(AccountingAllocatorOOM) {
AllocationPlatform platform;
TEST_WITH_PLATFORM(AccountingAllocatorOOM, AllocationPlatform) {
v8::internal::AccountingAllocator allocator;
CHECK(!platform.oom_callback_called);
const bool support_compression = false;
......@@ -105,8 +100,7 @@ TEST(AccountingAllocatorOOM) {
CHECK_EQ(result == nullptr, platform.oom_callback_called);
}
TEST(AccountingAllocatorCurrentAndMax) {
AllocationPlatform platform;
TEST_WITH_PLATFORM(AccountingAllocatorCurrentAndMax, AllocationPlatform) {
v8::internal::AccountingAllocator allocator;
static constexpr size_t kAllocationSizes[] = {51, 231, 27};
std::vector<v8::internal::Segment*> segments;
......@@ -134,8 +128,7 @@ TEST(AccountingAllocatorCurrentAndMax) {
CHECK(!platform.oom_callback_called);
}
TEST(MallocedOperatorNewOOM) {
AllocationPlatform platform;
TEST_WITH_PLATFORM(MallocedOperatorNewOOM, AllocationPlatform) {
CHECK(!platform.oom_callback_called);
CcTest::isolate()->SetFatalErrorHandler(OnMallocedOperatorNewOOM);
// On failure, this won't return, since a Malloced::New failure is fatal.
......@@ -145,8 +138,7 @@ TEST(MallocedOperatorNewOOM) {
CHECK_EQ(result == nullptr, platform.oom_callback_called);
}
TEST(NewArrayOOM) {
AllocationPlatform platform;
TEST_WITH_PLATFORM(NewArrayOOM, AllocationPlatform) {
CHECK(!platform.oom_callback_called);
CcTest::isolate()->SetFatalErrorHandler(OnNewArrayOOM);
// On failure, this won't return, since a NewArray failure is fatal.
......@@ -156,8 +148,7 @@ TEST(NewArrayOOM) {
CHECK_EQ(result == nullptr, platform.oom_callback_called);
}
TEST(AlignedAllocOOM) {
AllocationPlatform platform;
TEST_WITH_PLATFORM(AlignedAllocOOM, AllocationPlatform) {
CHECK(!platform.oom_callback_called);
CcTest::isolate()->SetFatalErrorHandler(OnAlignedAllocOOM);
// On failure, this won't return, since an AlignedAlloc failure is fatal.
......@@ -168,8 +159,7 @@ TEST(AlignedAllocOOM) {
CHECK_EQ(result == nullptr, platform.oom_callback_called);
}
TEST(AllocVirtualMemoryOOM) {
AllocationPlatform platform;
TEST_WITH_PLATFORM(AllocVirtualMemoryOOM, AllocationPlatform) {
CHECK(!platform.oom_callback_called);
v8::internal::VirtualMemory result(v8::internal::GetPlatformPageAllocator(),
GetHugeMemoryAmount(), nullptr);
......@@ -177,8 +167,7 @@ TEST(AllocVirtualMemoryOOM) {
CHECK_IMPLIES(!result.IsReserved(), platform.oom_callback_called);
}
TEST(AlignedAllocVirtualMemoryOOM) {
AllocationPlatform platform;
TEST_WITH_PLATFORM(AlignedAllocVirtualMemoryOOM, AllocationPlatform) {
CHECK(!platform.oom_callback_called);
v8::internal::VirtualMemory result(v8::internal::GetPlatformPageAllocator(),
GetHugeMemoryAmount(), nullptr,
......
......@@ -33,6 +33,8 @@
#include <memory>
#include <string>
#include "test/cctest/cctest.h"
#if V8_OS_POSIX
#include <unistd.h>
#endif
......@@ -23104,9 +23106,6 @@ namespace {
class MockPlatform final : public TestPlatform {
public:
MockPlatform() { NotifyPlatformReady(); }
~MockPlatform() final { RemovePlatform(); }
bool dump_without_crashing_called() const {
return dump_without_crashing_called_;
}
......@@ -23119,9 +23118,7 @@ class MockPlatform final : public TestPlatform {
} // namespace
TEST(DumpOnJavascriptExecution) {
MockPlatform platform;
TEST_WITH_PLATFORM(DumpOnJavascriptExecution, MockPlatform) {
LocalContext context;
v8::Isolate* isolate = context->GetIsolate();
v8::HandleScope scope(isolate);
......@@ -530,10 +530,7 @@ class DiscardedSamplesDelegateImpl : public v8::DiscardedSamplesDelegate {
class MockPlatform final : public TestPlatform {
public:
MockPlatform() : mock_task_runner_(new MockTaskRunner()) {
NotifyPlatformReady();
}
~MockPlatform() override { RemovePlatform(); }
MockPlatform() : mock_task_runner_(new MockTaskRunner()) {}
std::shared_ptr<v8::TaskRunner> GetForegroundTaskRunner(
v8::Isolate*) override {
......@@ -561,6 +558,8 @@ class MockPlatform final : public TestPlatform {
}
bool IdleTasksEnabled() override { return false; }
bool NonNestableTasksEnabled() const override { return true; }
bool NonNestableDelayedTasksEnabled() const override { return true; }
int posted_count() { return posted_count_; }
......@@ -574,12 +573,11 @@ class MockPlatform final : public TestPlatform {
};
} // namespace
TEST(MaxSamplesCallback) {
TEST_WITH_PLATFORM(MaxSamplesCallback, MockPlatform) {
i::Isolate* isolate = CcTest::i_isolate();
CpuProfilesCollection profiles(isolate);
CpuProfiler profiler(isolate);
profiles.set_cpu_profiler(&profiler);
MockPlatform* mock_platform = new MockPlatform();
std::unique_ptr<DiscardedSamplesDelegateImpl> impl =
std::make_unique<DiscardedSamplesDelegateImpl>(
DiscardedSamplesDelegateImpl());
......@@ -600,7 +598,7 @@ TEST(MaxSamplesCallback) {
profiles.AddPathToCurrentProfiles(
sample1.timestamp, symbolized.stack_trace, symbolized.src_line, true,
base::TimeDelta(), StateTag::JS, EmbedderStateTag::EMPTY);
CHECK_EQ(0, mock_platform->posted_count());
CHECK_EQ(0, platform.posted_count());
TickSample sample2;
sample2.timestamp = v8::base::TimeTicks::Now();
sample2.pc = ToPointer(0x1925);
......@@ -610,7 +608,7 @@ TEST(MaxSamplesCallback) {
profiles.AddPathToCurrentProfiles(
sample2.timestamp, symbolized.stack_trace, symbolized.src_line, true,
base::TimeDelta(), StateTag::JS, EmbedderStateTag::EMPTY);
CHECK_EQ(1, mock_platform->posted_count());
CHECK_EQ(1, platform.posted_count());
TickSample sample3;
sample3.timestamp = v8::base::TimeTicks::Now();
sample3.pc = ToPointer(0x1510);
......@@ -619,11 +617,10 @@ TEST(MaxSamplesCallback) {
profiles.AddPathToCurrentProfiles(
sample3.timestamp, symbolized.stack_trace, symbolized.src_line, true,
base::TimeDelta(), StateTag::JS, EmbedderStateTag::EMPTY);
CHECK_EQ(1, mock_platform->posted_count());
CHECK_EQ(1, platform.posted_count());
// Teardown
profiles.StopProfiling("");
delete mock_platform;
}
TEST(NoSamples) {
......
......@@ -6,6 +6,7 @@
#include <string.h>
#include "include/v8-function.h"
#include "include/v8-platform.h"
#include "src/init/v8.h"
#include "src/tracing/trace-event.h"
#include "test/cctest/cctest.h"
......@@ -86,9 +87,6 @@ class MockTracingController : public v8::TracingController {
class MockTracingPlatform : public TestPlatform {
public:
MockTracingPlatform() { NotifyPlatformReady(); }
~MockTracingPlatform() override { RemovePlatform(); }
v8::TracingController* GetTracingController() override {
return &tracing_controller_;
}
......@@ -107,18 +105,14 @@ class MockTracingPlatform : public TestPlatform {
} // namespace
TEST(TraceEventDisabledCategory) {
MockTracingPlatform platform;
TEST_WITH_PLATFORM(TraceEventDisabledCategory, MockTracingPlatform) {
// Disabled category, will not add events.
TRACE_EVENT_BEGIN0("cat", "e1");
TRACE_EVENT_END0("cat", "e1");
CHECK_EQ(0, platform.NumberOfTraceObjects());
}
TEST(TraceEventNoArgs) {
MockTracingPlatform platform;
TEST_WITH_PLATFORM(TraceEventNoArgs, MockTracingPlatform) {
// Enabled category will add 2 events.
TRACE_EVENT_BEGIN0("v8-cat", "e1");
TRACE_EVENT_END0("v8-cat", "e1");
......@@ -133,9 +127,7 @@ TEST(TraceEventNoArgs) {
CHECK_EQ(0, platform.GetTraceObject(1)->num_args);
}
TEST(TraceEventWithOneArg) {
MockTracingPlatform platform;
TEST_WITH_PLATFORM(TraceEventWithOneArg, MockTracingPlatform) {
TRACE_EVENT_BEGIN1("v8-cat", "e1", "arg1", 42);
TRACE_EVENT_END1("v8-cat", "e1", "arg1", 42);
TRACE_EVENT_BEGIN1("v8-cat", "e2", "arg1", "abc");
......@@ -149,9 +141,7 @@ TEST(TraceEventWithOneArg) {
CHECK_EQ(1, platform.GetTraceObject(3)->num_args);
}
TEST(TraceEventWithTwoArgs) {
MockTracingPlatform platform;
TEST_WITH_PLATFORM(TraceEventWithTwoArgs, MockTracingPlatform) {
TRACE_EVENT_BEGIN2("v8-cat", "e1", "arg1", 42, "arg2", "abc");
TRACE_EVENT_END2("v8-cat", "e1", "arg1", 42, "arg2", "abc");
TRACE_EVENT_BEGIN2("v8-cat", "e2", "arg1", "abc", "arg2", 43);
......@@ -165,9 +155,7 @@ TEST(TraceEventWithTwoArgs) {
CHECK_EQ(2, platform.GetTraceObject(3)->num_args);
}
TEST(ScopedTraceEvent) {
MockTracingPlatform platform;
TEST_WITH_PLATFORM(ScopedTraceEvent, MockTracingPlatform) {
{ TRACE_EVENT0("v8-cat", "e"); }
CHECK_EQ(1, platform.NumberOfTraceObjects());
......@@ -184,9 +172,7 @@ TEST(ScopedTraceEvent) {
CHECK_EQ(2, platform.GetTraceObject(2)->num_args);
}
TEST(TestEventWithFlow) {
MockTracingPlatform platform;
TEST_WITH_PLATFORM(TestEventWithFlow, MockTracingPlatform) {
static uint64_t bind_id = 21;
{
TRACE_EVENT_WITH_FLOW0("v8-cat", "f1", bind_id, TRACE_EVENT_FLAG_FLOW_OUT);
......@@ -208,9 +194,7 @@ TEST(TestEventWithFlow) {
CHECK_EQ(TRACE_EVENT_FLAG_FLOW_IN, platform.GetTraceObject(2)->flags);
}
TEST(TestEventWithId) {
MockTracingPlatform platform;
TEST_WITH_PLATFORM(TestEventWithId, MockTracingPlatform) {
static uint64_t event_id = 21;
TRACE_EVENT_ASYNC_BEGIN0("v8-cat", "a1", event_id);
TRACE_EVENT_ASYNC_END0("v8-cat", "a1", event_id);
......@@ -222,9 +206,7 @@ TEST(TestEventWithId) {
CHECK_EQ(event_id, platform.GetTraceObject(1)->id);
}
TEST(TestEventWithTimestamp) {
MockTracingPlatform platform;
TEST_WITH_PLATFORM(TestEventWithTimestamp, MockTracingPlatform) {
TRACE_EVENT_INSTANT_WITH_TIMESTAMP0("v8-cat", "0arg",
TRACE_EVENT_SCOPE_GLOBAL, 1729);
TRACE_EVENT_INSTANT_WITH_TIMESTAMP1("v8-cat", "1arg",
......@@ -251,9 +233,8 @@ TEST(TestEventWithTimestamp) {
CHECK_EQ(32832, platform.GetTraceObject(4)->timestamp);
}
TEST(BuiltinsIsTraceCategoryEnabled) {
TEST_WITH_PLATFORM(BuiltinsIsTraceCategoryEnabled, MockTracingPlatform) {
CcTest::InitializeVM();
MockTracingPlatform platform;
v8::Isolate* isolate = CcTest::isolate();
v8::HandleScope handle_scope(isolate);
......@@ -299,9 +280,8 @@ TEST(BuiltinsIsTraceCategoryEnabled) {
}
}
TEST(BuiltinsTrace) {
TEST_WITH_PLATFORM(BuiltinsTrace, MockTracingPlatform) {
CcTest::InitializeVM();
MockTracingPlatform platform;
v8::Isolate* isolate = CcTest::isolate();
v8::HandleScope handle_scope(isolate);
......
......@@ -29,12 +29,9 @@ namespace wasm {
class MockPlatform final : public TestPlatform {
public:
MockPlatform() : task_runner_(std::make_shared<MockTaskRunner>()) {
NotifyPlatformReady();
}
MockPlatform() : task_runner_(std::make_shared<MockTaskRunner>()) {}
~MockPlatform() {
RemovePlatform();
for (auto* job_handle : job_handles_) job_handle->ResetPlatform();
}
......@@ -239,25 +236,18 @@ class StreamTester {
};
} // namespace
#define RUN_STREAM(name) \
MockPlatform mock_platform; \
CHECK_EQ(V8::GetCurrentPlatform(), &mock_platform); \
v8::Isolate::CreateParams create_params; \
create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); \
v8::Isolate* isolate = v8::Isolate::New(create_params); \
{ \
v8::HandleScope handle_scope(isolate); \
v8::Local<v8::Context> context = v8::Context::New(isolate); \
v8::Context::Scope context_scope(context); \
RunStream_##name(&mock_platform, isolate); \
} \
isolate->Dispose();
#define RUN_STREAM(name) \
v8::Isolate* isolate = CcTest::isolate(); \
v8::HandleScope handle_scope(isolate); \
v8::Local<v8::Context> context = v8::Context::New(isolate); \
v8::Context::Scope context_scope(context); \
RunStream_##name(&platform, isolate);
#define STREAM_TEST(name) \
void RunStream_##name(MockPlatform*, v8::Isolate*); \
UNINITIALIZED_TEST(Async##name) { RUN_STREAM(name); } \
TEST_WITH_PLATFORM(Async##name, MockPlatform) { RUN_STREAM(name); } \
\
UNINITIALIZED_TEST(SingleThreaded##name) { \
TEST_WITH_PLATFORM(SingleThreaded##name, MockPlatform) { \
i::FlagScope<bool> single_threaded_scope(&i::FLAG_single_threaded, true); \
RUN_STREAM(name); \
} \
......
......@@ -6,6 +6,7 @@
#include "include/libplatform/libplatform.h"
#include "include/v8-metrics.h"
#include "include/v8-platform.h"
#include "src/api/api-inl.h"
#include "src/base/platform/time.h"
#include "src/wasm/wasm-engine.h"
......@@ -24,12 +25,9 @@ namespace {
class MockPlatform final : public TestPlatform {
public:
MockPlatform() : task_runner_(std::make_shared<MockTaskRunner>()) {
NotifyPlatformReady();
}
MockPlatform() : task_runner_(std::make_shared<MockTaskRunner>()) {}
~MockPlatform() override {
RemovePlatform();
for (auto* job_handle : job_handles_) job_handle->ResetPlatform();
}
......@@ -208,32 +206,24 @@ class TestCompileResolver : public CompilationResultResolver {
} // namespace
#define RUN_COMPILE(name) \
MockPlatform mock_platform; \
CHECK_EQ(V8::GetCurrentPlatform(), &mock_platform); \
v8::Isolate::CreateParams create_params; \
create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); \
v8::Isolate* isolate = v8::Isolate::New(create_params); \
{ \
v8::HandleScope handle_scope(isolate); \
v8::Local<v8::Context> context = v8::Context::New(isolate); \
v8::Context::Scope context_scope(context); \
Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); \
testing::SetupIsolateForWasmModule(i_isolate); \
RunCompile_##name(&mock_platform, i_isolate); \
} \
isolate->Dispose();
#define RUN_COMPILE(name) \
v8::HandleScope handle_scope(CcTest::isolate()); \
v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); \
v8::Context::Scope context_scope(context); \
Isolate* i_isolate = CcTest::i_isolate(); \
testing::SetupIsolateForWasmModule(i_isolate); \
RunCompile_##name(&platform, i_isolate);
#define COMPILE_TEST(name) \
void RunCompile_##name(MockPlatform*, i::Isolate*); \
UNINITIALIZED_TEST(Sync##name) { \
TEST_WITH_PLATFORM(Sync##name, MockPlatform) { \
i::FlagScope<bool> sync_scope(&i::FLAG_wasm_async_compilation, false); \
RUN_COMPILE(name); \
} \
\
UNINITIALIZED_TEST(Async##name) { RUN_COMPILE(name); } \
TEST_WITH_PLATFORM(Async##name, MockPlatform) { RUN_COMPILE(name); } \
\
UNINITIALIZED_TEST(Streaming##name) { \
TEST_WITH_PLATFORM(Streaming##name, MockPlatform) { \
i::FlagScope<bool> streaming_scope(&i::FLAG_wasm_test_streaming, true); \
RUN_COMPILE(name); \
} \
......
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