diff options
author | Ben Noordhuis <info@bnoordhuis.nl> | 2015-05-28 21:46:54 +0200 |
---|---|---|
committer | Ben Noordhuis <info@bnoordhuis.nl> | 2015-05-28 22:01:10 +0200 |
commit | 4e90c82cdb9d69dbffe340e7ac9bd1b4b6e1d781 (patch) | |
tree | d6aa6eb52f98ea78d530f0b9c57717f8c007d25e /test | |
parent | 3a1bc067d467c54853747e1697c7c1bcc010aae1 (diff) | |
download | nodejs-4e90c82cdb9d69dbffe340e7ac9bd1b4b6e1d781.tar.gz nodejs-4e90c82cdb9d69dbffe340e7ac9bd1b4b6e1d781.tar.bz2 nodejs-4e90c82cdb9d69dbffe340e7ac9bd1b4b6e1d781.zip |
test: add heap profiler add-on regression test
Add a regression test for https://github.com/nodejs/io.js/pull/1827.
PR-URL: https://github.com/nodejs/io.js/pull/1828
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/addons/heap-profiler/binding.cc | 27 | ||||
-rw-r--r-- | test/addons/heap-profiler/binding.gyp | 8 | ||||
-rw-r--r-- | test/addons/heap-profiler/test.js | 12 |
3 files changed, 47 insertions, 0 deletions
diff --git a/test/addons/heap-profiler/binding.cc b/test/addons/heap-profiler/binding.cc new file mode 100644 index 000000000..846d53a9c --- /dev/null +++ b/test/addons/heap-profiler/binding.cc @@ -0,0 +1,27 @@ +#include "node.h" +#include "v8.h" +#include "v8-profiler.h" + +namespace { + +inline void Test(const v8::FunctionCallbackInfo<v8::Value>& args) { + v8::Isolate* const isolate = args.GetIsolate(); + const v8::HeapSnapshot* const heap_snapshot = + isolate->GetHeapProfiler()->TakeHeapSnapshot(v8::String::Empty(isolate)); + struct : public v8::OutputStream { + WriteResult WriteAsciiChunk(char*, int) override { return kContinue; } + void EndOfStream() override {} + } output_stream; + heap_snapshot->Serialize(&output_stream, v8::HeapSnapshot::kJSON); + const_cast<v8::HeapSnapshot*>(heap_snapshot)->Delete(); +} + +inline void Initialize(v8::Local<v8::Object> binding) { + v8::Isolate* const isolate = binding->GetIsolate(); + binding->Set(v8::String::NewFromUtf8(isolate, "test"), + v8::FunctionTemplate::New(isolate, Test)->GetFunction()); +} + +NODE_MODULE(test, Initialize) + +} // anonymous namespace diff --git a/test/addons/heap-profiler/binding.gyp b/test/addons/heap-profiler/binding.gyp new file mode 100644 index 000000000..3bfb84493 --- /dev/null +++ b/test/addons/heap-profiler/binding.gyp @@ -0,0 +1,8 @@ +{ + 'targets': [ + { + 'target_name': 'binding', + 'sources': [ 'binding.cc' ] + } + ] +} diff --git a/test/addons/heap-profiler/test.js b/test/addons/heap-profiler/test.js new file mode 100644 index 000000000..a4a316fa5 --- /dev/null +++ b/test/addons/heap-profiler/test.js @@ -0,0 +1,12 @@ +'use strict'; + +const binding = require('./build/Release/binding'); + +// Create an AsyncWrap object. +const timer = setTimeout(function() {}, 1); +timer.unref(); + +// Stress-test the heap profiler. +binding.test(); + +clearTimeout(timer); |