Skip to content

Commit

Permalink
test: add cpu-profiler-crash test
Browse files Browse the repository at this point in the history
This test is added as it usually crashes without applying the v8 patch:
v8/v8@beebee4

PR-URL: nodejs#37293
Refs: v8/v8@beebee4
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
  • Loading branch information
santigimeno authored and juanarbol committed Mar 2, 2021
1 parent 8d3fc8d commit a6eae67
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
16 changes: 16 additions & 0 deletions 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<v8::Value>& args) {
v8::CpuProfiler* profiler = v8::CpuProfiler::New(args.GetIsolate());
v8::Local<v8::String> 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);
}
9 changes: 9 additions & 0 deletions test/addons/cpu-profiler-crash/binding.gyp
@@ -0,0 +1,9 @@
{
'targets': [
{
'target_name': 'binding',
'sources': [ 'binding.cc' ],
'includes': ['../common.gypi'],
}
]
}
20 changes: 20 additions & 0 deletions 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);

0 comments on commit a6eae67

Please sign in to comment.