• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include "node_test_fixture.h"
2 #include "cppgc/platform.h"
3 
4 ArrayBufferUniquePtr NodeZeroIsolateTestFixture::allocator{nullptr, nullptr};
5 uv_loop_t NodeZeroIsolateTestFixture::current_loop;
6 NodePlatformUniquePtr NodeZeroIsolateTestFixture::platform;
7 TracingAgentUniquePtr NodeZeroIsolateTestFixture::tracing_agent;
8 bool NodeZeroIsolateTestFixture::node_initialized = false;
9 v8::Isolate* NodeTestFixture::isolate_ = nullptr;
10 node::IsolateData* EnvironmentTestFixture::isolate_data_ = nullptr;
11 
SetUp()12 void NodeTestEnvironment::SetUp() {
13   NodeZeroIsolateTestFixture::tracing_agent =
14       std::make_unique<node::tracing::Agent>();
15   node::tracing::TraceEventHelper::SetAgent(
16       NodeZeroIsolateTestFixture::tracing_agent.get());
17   node::tracing::TracingController* tracing_controller =
18       NodeZeroIsolateTestFixture::tracing_agent->GetTracingController();
19   static constexpr int kV8ThreadPoolSize = 4;
20   NodeZeroIsolateTestFixture::platform.reset(
21       new node::NodePlatform(kV8ThreadPoolSize, tracing_controller));
22   v8::V8::InitializePlatform(NodeZeroIsolateTestFixture::platform.get());
23 #ifdef V8_SANDBOX
24   ASSERT_TRUE(v8::V8::InitializeSandbox());
25 #endif
26   cppgc::InitializeProcess(
27       NodeZeroIsolateTestFixture::platform->GetPageAllocator());
28   v8::V8::Initialize();
29 }
30 
TearDown()31 void NodeTestEnvironment::TearDown() {
32   v8::V8::Dispose();
33   v8::V8::DisposePlatform();
34   NodeZeroIsolateTestFixture::platform->Shutdown();
35   NodeZeroIsolateTestFixture::platform.reset(nullptr);
36   NodeZeroIsolateTestFixture::tracing_agent.reset(nullptr);
37 }
38 
39 ::testing::Environment* const node_env =
40 ::testing::AddGlobalTestEnvironment(new NodeTestEnvironment());
41