diff --git a/test/cctest/node_test_fixture.cc b/test/cctest/node_test_fixture.cc index b6f4af6b9e70e0..9f8aa13787327b 100644 --- a/test/cctest/node_test_fixture.cc +++ b/test/cctest/node_test_fixture.cc @@ -1,7 +1,39 @@ #include "node_test_fixture.h" +#include "cppgc/platform.h" ArrayBufferUniquePtr NodeZeroIsolateTestFixture::allocator{nullptr, nullptr}; uv_loop_t NodeZeroIsolateTestFixture::current_loop; NodePlatformUniquePtr NodeZeroIsolateTestFixture::platform; TracingAgentUniquePtr NodeZeroIsolateTestFixture::tracing_agent; bool NodeZeroIsolateTestFixture::node_initialized = false; + + +void NodeTestEnvironment::SetUp() { + NodeZeroIsolateTestFixture::tracing_agent = + std::make_unique(); + node::tracing::TraceEventHelper::SetAgent( + NodeZeroIsolateTestFixture::tracing_agent.get()); + node::tracing::TracingController* tracing_controller = + NodeZeroIsolateTestFixture::tracing_agent->GetTracingController(); + static constexpr int kV8ThreadPoolSize = 4; + NodeZeroIsolateTestFixture::platform.reset( + new node::NodePlatform(kV8ThreadPoolSize, tracing_controller)); + v8::V8::InitializePlatform(NodeZeroIsolateTestFixture::platform.get()); +#ifdef V8_VIRTUAL_MEMORY_CAGE + ASSERT_TRUE(v8::V8::InitializeVirtualMemoryCage()); +#endif + cppgc::InitializeProcess( + NodeZeroIsolateTestFixture::platform->GetPageAllocator()); + v8::V8::Initialize(); +} + +void NodeTestEnvironment::TearDown() { + v8::V8::Dispose(); + v8::V8::ShutdownPlatform(); + NodeZeroIsolateTestFixture::platform->Shutdown(); + NodeZeroIsolateTestFixture::platform.reset(nullptr); + NodeZeroIsolateTestFixture::tracing_agent.reset(nullptr); +} + +::testing::Environment* const node_env = +::testing::AddGlobalTestEnvironment(new NodeTestEnvironment()); diff --git a/test/cctest/node_test_fixture.h b/test/cctest/node_test_fixture.h index 936085d4ae57bd..4c687118a37054 100644 --- a/test/cctest/node_test_fixture.h +++ b/test/cctest/node_test_fixture.h @@ -60,18 +60,26 @@ using ArrayBufferUniquePtr = std::unique_ptr; using NodePlatformUniquePtr = std::unique_ptr; +class NodeTestEnvironment final : public ::testing::Environment { + public: + NodeTestEnvironment() = default; + void SetUp() override; + void TearDown() override; +}; + + class NodeZeroIsolateTestFixture : public ::testing::Test { protected: - static ArrayBufferUniquePtr allocator; - static TracingAgentUniquePtr tracing_agent; - static NodePlatformUniquePtr platform; static uv_loop_t current_loop; static bool node_initialized; + static ArrayBufferUniquePtr allocator; + static NodePlatformUniquePtr platform; + static TracingAgentUniquePtr tracing_agent; static void SetUpTestCase() { if (!node_initialized) { - uv_os_unsetenv("NODE_OPTIONS"); node_initialized = true; + uv_os_unsetenv("NODE_OPTIONS"); std::vector argv { "cctest" }; std::vector exec_argv; std::vector errors; @@ -80,25 +88,13 @@ class NodeZeroIsolateTestFixture : public ::testing::Test { CHECK_EQ(exitcode, 0); CHECK(errors.empty()); } - - tracing_agent = std::make_unique(); - node::tracing::TraceEventHelper::SetAgent(tracing_agent.get()); - node::tracing::TracingController* tracing_controller = - tracing_agent->GetTracingController(); CHECK_EQ(0, uv_loop_init(¤t_loop)); - static constexpr int kV8ThreadPoolSize = 4; - platform.reset( - new node::NodePlatform(kV8ThreadPoolSize, tracing_controller)); - v8::V8::InitializePlatform(platform.get()); - v8::V8::Initialize(); } static void TearDownTestCase() { - platform->Shutdown(); while (uv_loop_alive(¤t_loop)) { uv_run(¤t_loop, UV_RUN_ONCE); } - v8::V8::DisposePlatform(); CHECK_EQ(0, uv_loop_close(¤t_loop)); } @@ -106,6 +102,8 @@ class NodeZeroIsolateTestFixture : public ::testing::Test { allocator = ArrayBufferUniquePtr(node::CreateArrayBufferAllocator(), &node::FreeArrayBufferAllocator); } + + friend NodeTestEnvironment; }; diff --git a/tools/code_cache/mkcodecache.cc b/tools/code_cache/mkcodecache.cc index 5593e14fae3b55..68690252a147cd 100644 --- a/tools/code_cache/mkcodecache.cc +++ b/tools/code_cache/mkcodecache.cc @@ -68,6 +68,7 @@ int main(int argc, char* argv[]) { } isolate->Dispose(); + v8::V8::Dispose(); v8::V8::DisposePlatform(); return 0; }