diff options
author | Camillo Bruni <camillobruni@users.noreply.github.com> | 2021-12-09 10:34:43 +0100 |
---|---|---|
committer | Michaƫl Zasso <targos@protonmail.com> | 2022-04-12 22:10:37 +0200 |
commit | 62e62757b3afb9734448c632b1e1f1330241d343 (patch) | |
tree | 0a625969f1c2a31c5e70bccbb81299845d480366 | |
parent | 58f3fdcccde30c115e68e7b9877f55bad1984545 (diff) | |
download | node-new-62e62757b3afb9734448c632b1e1f1330241d343.tar.gz |
tools,test: fix V8 initialization order
Refs: https://chromium-review.googlesource.com/c/v8/v8/+/3300129/
PR-URL: https://github.com/nodejs/node/pull/42657
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
-rw-r--r-- | test/cctest/node_test_fixture.cc | 32 | ||||
-rw-r--r-- | test/cctest/node_test_fixture.h | 30 | ||||
-rw-r--r-- | tools/code_cache/mkcodecache.cc | 1 |
3 files changed, 47 insertions, 16 deletions
diff --git a/test/cctest/node_test_fixture.cc b/test/cctest/node_test_fixture.cc index b6f4af6b9e..8179c78644 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::Agent>(); + 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_SANDBOX + ASSERT_TRUE(v8::V8::InitializeSandbox()); +#endif + cppgc::InitializeProcess( + NodeZeroIsolateTestFixture::platform->GetPageAllocator()); + v8::V8::Initialize(); +} + +void NodeTestEnvironment::TearDown() { + v8::V8::Dispose(); + v8::V8::DisposePlatform(); + 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 936085d4ae..4c687118a3 100644 --- a/test/cctest/node_test_fixture.h +++ b/test/cctest/node_test_fixture.h @@ -60,18 +60,26 @@ using ArrayBufferUniquePtr = std::unique_ptr<node::ArrayBufferAllocator, using TracingAgentUniquePtr = std::unique_ptr<node::tracing::Agent>; using NodePlatformUniquePtr = std::unique_ptr<node::NodePlatform>; +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<std::string> argv { "cctest" }; std::vector<std::string> exec_argv; std::vector<std::string> errors; @@ -80,25 +88,13 @@ class NodeZeroIsolateTestFixture : public ::testing::Test { CHECK_EQ(exitcode, 0); CHECK(errors.empty()); } - - tracing_agent = std::make_unique<node::tracing::Agent>(); - 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 5593e14fae..68690252a1 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; } |