summaryrefslogtreecommitdiff
path: root/test/cctest/node_test_fixture.h
diff options
context:
space:
mode:
authorMatheus Marchini <matheusdot@gmail.com>2017-12-25 22:17:25 -0200
committerJoyee Cheung <joyeec9h3@gmail.com>2018-01-26 08:55:36 +0800
commit756a34e86386bbc879234c4987eacdcb21e0e54b (patch)
treeacf53ccfd32e9d646cccfe837f32893a87976d94 /test/cctest/node_test_fixture.h
parentbea5f26d341e9dd062d842b1ccceaac031e6ed57 (diff)
downloadandroid-node-v8-756a34e86386bbc879234c4987eacdcb21e0e54b.tar.gz
android-node-v8-756a34e86386bbc879234c4987eacdcb21e0e54b.tar.bz2
android-node-v8-756a34e86386bbc879234c4987eacdcb21e0e54b.zip
src, test: node internals' postmortem metadata
Before these changes, only V8 added postmortem metadata to Node's binary, limiting the possibilities for debugger's developers to add some features that rely on investigating Node's internal structures. These changes are first steps towards empowering debug tools to navigate Node's internal structures. One example of what can be achieved with this is shown at nodejs/llnode#122 (a command which prints information about handles and requests on the queue for a core dump file). Node postmortem metadata are prefixed with nodedbg_. This also adds tests to validate if all postmortem metadata are calculated correctly, plus some documentation on what is postmortem metadata and a few care to be taken to avoid breaking it. Ref: https://github.com/nodejs/llnode/pull/122 Ref: https://github.com/nodejs/post-mortem/issues/46 PR-URL: https://github.com/nodejs/node/pull/14901 Refs: https://github.com/nodejs/post-mortem/issues/46 Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Diffstat (limited to 'test/cctest/node_test_fixture.h')
-rw-r--r--test/cctest/node_test_fixture.h55
1 files changed, 55 insertions, 0 deletions
diff --git a/test/cctest/node_test_fixture.h b/test/cctest/node_test_fixture.h
index d5be613c0b..ffecd34d71 100644
--- a/test/cctest/node_test_fixture.h
+++ b/test/cctest/node_test_fixture.h
@@ -5,6 +5,7 @@
#include "gtest/gtest.h"
#include "node.h"
#include "node_platform.h"
+#include "node_internals.h"
#include "env.h"
#include "v8.h"
#include "libplatform/libplatform.h"
@@ -75,6 +76,13 @@ class NodeTestFixture : public ::testing::Test {
v8::Isolate::CreateParams params_;
params_.array_buffer_allocator = allocator_.get();
isolate_ = v8::Isolate::New(params_);
+
+ // As the TracingController is stored globally, we only need to create it
+ // one time for all tests.
+ if (node::tracing::TraceEventHelper::GetTracingController() == nullptr) {
+ node::tracing::TraceEventHelper::SetTracingController(
+ new v8::TracingController());
+ }
}
virtual void TearDown() {
@@ -95,4 +103,51 @@ class NodeTestFixture : public ::testing::Test {
v8::ArrayBuffer::Allocator::NewDefaultAllocator()};
};
+
+class EnvironmentTestFixture : public NodeTestFixture {
+ public:
+ class Env {
+ public:
+ Env(const v8::HandleScope& handle_scope,
+ const Argv& argv,
+ NodeTestFixture* test_fixture) {
+ auto isolate = handle_scope.GetIsolate();
+ context_ = node::NewContext(isolate);
+ CHECK(!context_.IsEmpty());
+ context_->Enter();
+
+ isolate_data_ = node::CreateIsolateData(isolate,
+ NodeTestFixture::CurrentLoop(),
+ test_fixture->Platform());
+ CHECK_NE(nullptr, isolate_data_);
+ environment_ = node::CreateEnvironment(isolate_data_,
+ context_,
+ 1, *argv,
+ argv.nr_args(), *argv);
+ CHECK_NE(nullptr, environment_);
+ }
+
+ ~Env() {
+ environment_->CleanupHandles();
+ node::FreeEnvironment(environment_);
+ node::FreeIsolateData(isolate_data_);
+ context_->Exit();
+ }
+
+ node::Environment* operator*() const {
+ return environment_;
+ }
+
+ v8::Local<v8::Context> context() const {
+ return context_;
+ }
+
+ private:
+ v8::Local<v8::Context> context_;
+ node::IsolateData* isolate_data_;
+ node::Environment* environment_;
+ DISALLOW_COPY_AND_ASSIGN(Env);
+ };
+};
+
#endif // TEST_CCTEST_NODE_TEST_FIXTURE_H_