From 89046d7840d2ce30b6576d5e1958114f0c512a22 Mon Sep 17 00:00:00 2001 From: Santiago Gimeno Date: Tue, 9 Feb 2021 15:23:35 +0100 Subject: [PATCH] test: add cpu-profiler-crash test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This test is added as it usually crashes without applying the v8 patch: https://github.com/v8/v8/commit/beebee4f80ff2eb91187ef1e8fa00b8ff82a20b3 PR-URL: https://github.com/nodejs/node/pull/37293 Refs: https://github.com/v8/v8/commit/beebee4f80ff2eb91187ef1e8fa00b8ff82a20b Reviewed-By: Jiawen Geng Reviewed-By: Juan José Arboleda Reviewed-By: Richard Lau --- test/addons/cpu-profiler-crash/binding.cc | 16 ++++++++++++++++ test/addons/cpu-profiler-crash/binding.gyp | 9 +++++++++ test/addons/cpu-profiler-crash/test.js | 20 ++++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 test/addons/cpu-profiler-crash/binding.cc create mode 100644 test/addons/cpu-profiler-crash/binding.gyp create mode 100644 test/addons/cpu-profiler-crash/test.js diff --git a/test/addons/cpu-profiler-crash/binding.cc b/test/addons/cpu-profiler-crash/binding.cc new file mode 100644 index 00000000000000..57358e82175e29 --- /dev/null +++ b/test/addons/cpu-profiler-crash/binding.cc @@ -0,0 +1,16 @@ +#include "node.h" +#include "v8.h" +#include "v8-profiler.h" + +static void StartCpuProfiler(const v8::FunctionCallbackInfo& args) { + v8::CpuProfiler* profiler = v8::CpuProfiler::New(args.GetIsolate()); + v8::Local profile_title = v8::String::NewFromUtf8( + args.GetIsolate(), + "testing", + v8::NewStringType::kInternalized).ToLocalChecked(); + profiler->StartProfiling(profile_title, true); +} + +NODE_MODULE_INIT(/* exports, module, context */) { + NODE_SET_METHOD(exports, "startCpuProfiler", StartCpuProfiler); +} diff --git a/test/addons/cpu-profiler-crash/binding.gyp b/test/addons/cpu-profiler-crash/binding.gyp new file mode 100644 index 00000000000000..55fbe7050f18e4 --- /dev/null +++ b/test/addons/cpu-profiler-crash/binding.gyp @@ -0,0 +1,9 @@ +{ + 'targets': [ + { + 'target_name': 'binding', + 'sources': [ 'binding.cc' ], + 'includes': ['../common.gypi'], + } + ] +} diff --git a/test/addons/cpu-profiler-crash/test.js b/test/addons/cpu-profiler-crash/test.js new file mode 100644 index 00000000000000..e7391ebfcc9a5c --- /dev/null +++ b/test/addons/cpu-profiler-crash/test.js @@ -0,0 +1,20 @@ +'use strict'; + +// This test crashes most of the time unless the v8 patch: +// https://github.com/v8/v8/commit/beebee4f80ff2eb91187ef1e8fa00b8ff82a20b3 +// is applied. +const common = require('../../common'); +const bindings = require(`./build/${common.buildType}/binding`); + +function fn() { setImmediate(fn); } +setInterval(function() { + for (let i = 0; i < 1000000; i++) + fn(); + clearInterval(this); + setTimeout(process.reallyExit, 2000); +}, 0); + + +setTimeout(() => { + bindings.startCpuProfiler(); +}, 1000);