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>
This commit is contained in:
parent
58f3fdcccd
commit
62e62757b3
@ -1,7 +1,39 @@
|
|||||||
#include "node_test_fixture.h"
|
#include "node_test_fixture.h"
|
||||||
|
#include "cppgc/platform.h"
|
||||||
|
|
||||||
ArrayBufferUniquePtr NodeZeroIsolateTestFixture::allocator{nullptr, nullptr};
|
ArrayBufferUniquePtr NodeZeroIsolateTestFixture::allocator{nullptr, nullptr};
|
||||||
uv_loop_t NodeZeroIsolateTestFixture::current_loop;
|
uv_loop_t NodeZeroIsolateTestFixture::current_loop;
|
||||||
NodePlatformUniquePtr NodeZeroIsolateTestFixture::platform;
|
NodePlatformUniquePtr NodeZeroIsolateTestFixture::platform;
|
||||||
TracingAgentUniquePtr NodeZeroIsolateTestFixture::tracing_agent;
|
TracingAgentUniquePtr NodeZeroIsolateTestFixture::tracing_agent;
|
||||||
bool NodeZeroIsolateTestFixture::node_initialized = false;
|
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());
|
||||||
|
@ -60,18 +60,26 @@ using ArrayBufferUniquePtr = std::unique_ptr<node::ArrayBufferAllocator,
|
|||||||
using TracingAgentUniquePtr = std::unique_ptr<node::tracing::Agent>;
|
using TracingAgentUniquePtr = std::unique_ptr<node::tracing::Agent>;
|
||||||
using NodePlatformUniquePtr = std::unique_ptr<node::NodePlatform>;
|
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 {
|
class NodeZeroIsolateTestFixture : public ::testing::Test {
|
||||||
protected:
|
protected:
|
||||||
static ArrayBufferUniquePtr allocator;
|
|
||||||
static TracingAgentUniquePtr tracing_agent;
|
|
||||||
static NodePlatformUniquePtr platform;
|
|
||||||
static uv_loop_t current_loop;
|
static uv_loop_t current_loop;
|
||||||
static bool node_initialized;
|
static bool node_initialized;
|
||||||
|
static ArrayBufferUniquePtr allocator;
|
||||||
|
static NodePlatformUniquePtr platform;
|
||||||
|
static TracingAgentUniquePtr tracing_agent;
|
||||||
|
|
||||||
static void SetUpTestCase() {
|
static void SetUpTestCase() {
|
||||||
if (!node_initialized) {
|
if (!node_initialized) {
|
||||||
uv_os_unsetenv("NODE_OPTIONS");
|
|
||||||
node_initialized = true;
|
node_initialized = true;
|
||||||
|
uv_os_unsetenv("NODE_OPTIONS");
|
||||||
std::vector<std::string> argv { "cctest" };
|
std::vector<std::string> argv { "cctest" };
|
||||||
std::vector<std::string> exec_argv;
|
std::vector<std::string> exec_argv;
|
||||||
std::vector<std::string> errors;
|
std::vector<std::string> errors;
|
||||||
@ -80,25 +88,13 @@ class NodeZeroIsolateTestFixture : public ::testing::Test {
|
|||||||
CHECK_EQ(exitcode, 0);
|
CHECK_EQ(exitcode, 0);
|
||||||
CHECK(errors.empty());
|
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));
|
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() {
|
static void TearDownTestCase() {
|
||||||
platform->Shutdown();
|
|
||||||
while (uv_loop_alive(¤t_loop)) {
|
while (uv_loop_alive(¤t_loop)) {
|
||||||
uv_run(¤t_loop, UV_RUN_ONCE);
|
uv_run(¤t_loop, UV_RUN_ONCE);
|
||||||
}
|
}
|
||||||
v8::V8::DisposePlatform();
|
|
||||||
CHECK_EQ(0, uv_loop_close(¤t_loop));
|
CHECK_EQ(0, uv_loop_close(¤t_loop));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,6 +102,8 @@ class NodeZeroIsolateTestFixture : public ::testing::Test {
|
|||||||
allocator = ArrayBufferUniquePtr(node::CreateArrayBufferAllocator(),
|
allocator = ArrayBufferUniquePtr(node::CreateArrayBufferAllocator(),
|
||||||
&node::FreeArrayBufferAllocator);
|
&node::FreeArrayBufferAllocator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
friend NodeTestEnvironment;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -68,6 +68,7 @@ int main(int argc, char* argv[]) {
|
|||||||
}
|
}
|
||||||
isolate->Dispose();
|
isolate->Dispose();
|
||||||
|
|
||||||
|
v8::V8::Dispose();
|
||||||
v8::V8::DisposePlatform();
|
v8::V8::DisposePlatform();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user