summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCamillo Bruni <camillobruni@users.noreply.github.com>2021-12-09 10:34:43 +0100
committerMichaƫl Zasso <targos@protonmail.com>2022-04-12 22:10:37 +0200
commit62e62757b3afb9734448c632b1e1f1330241d343 (patch)
tree0a625969f1c2a31c5e70bccbb81299845d480366
parent58f3fdcccde30c115e68e7b9877f55bad1984545 (diff)
downloadnode-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.cc32
-rw-r--r--test/cctest/node_test_fixture.h30
-rw-r--r--tools/code_cache/mkcodecache.cc1
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(&current_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(&current_loop)) {
uv_run(&current_loop, UV_RUN_ONCE);
}
- v8::V8::DisposePlatform();
CHECK_EQ(0, uv_loop_close(&current_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;
}