Skip to content

Commit 69057eb

Browse files
santigimenorichardlau
authored andcommitted
test: add cpu-profiler-crash test
This test is added as it usually crashes without applying the v8 patch: v8/v8@beebee4 PR-URL: #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>
1 parent 15ed780 commit 69057eb

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include "node.h"
2+
#include "v8.h"
3+
#include "v8-profiler.h"
4+
5+
static void StartCpuProfiler(const v8::FunctionCallbackInfo<v8::Value>& args) {
6+
v8::CpuProfiler* profiler = v8::CpuProfiler::New(args.GetIsolate());
7+
v8::Local<v8::String> profile_title = v8::String::NewFromUtf8(
8+
args.GetIsolate(),
9+
"testing",
10+
v8::NewStringType::kInternalized).ToLocalChecked();
11+
profiler->StartProfiling(profile_title, true);
12+
}
13+
14+
NODE_MODULE_INIT(/* exports, module, context */) {
15+
NODE_SET_METHOD(exports, "startCpuProfiler", StartCpuProfiler);
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
'targets': [
3+
{
4+
'target_name': 'binding',
5+
'sources': [ 'binding.cc' ],
6+
'includes': ['../common.gypi'],
7+
}
8+
]
9+
}
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict';
2+
3+
// This test crashes most of the time unless the v8 patch:
4+
// https://github.com/v8/v8/commit/beebee4f80ff2eb91187ef1e8fa00b8ff82a20b3
5+
// is applied.
6+
const common = require('../../common');
7+
const bindings = require(`./build/${common.buildType}/binding`);
8+
9+
function fn() { setImmediate(fn); }
10+
setInterval(function() {
11+
for (let i = 0; i < 1000000; i++)
12+
fn();
13+
clearInterval(this);
14+
setTimeout(process.reallyExit, 2000);
15+
}, 0);
16+
17+
18+
setTimeout(() => {
19+
bindings.startCpuProfiler();
20+
}, 1000);

0 commit comments

Comments
 (0)