Skip to content

Commit c54ebfd

Browse files
committed
squash: commit test tweaks
1 parent 9b5fb8a commit c54ebfd

File tree

3 files changed

+54
-10
lines changed

3 files changed

+54
-10
lines changed

src/node.cc

+25-5
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ static std::string trace_enabled_categories; // NOLINT(runtime/string)
200200
static std::string trace_file_pattern = // NOLINT(runtime/string)
201201
"node_trace.${rotation}.log";
202202
static bool abort_on_uncaught_exception = false;
203+
static std::string report_events; // NOLINT(runtime/string)
203204

204205
// Bit flag used to track security reverts (see node_revert.h)
205206
unsigned int reverted = 0;
@@ -2569,6 +2570,14 @@ void LoadEnvironment(Environment* env) {
25692570
return;
25702571
}
25712572

2573+
#if defined(NODE_REPORT)
2574+
fprintf(stderr, "report events: %s \n", report_events.c_str());
2575+
if (!report_events.empty()) {
2576+
nodereport::InitializeNodeReport();
2577+
nodereport::SetEvents(env->isolate(), report_events.c_str());
2578+
}
2579+
#endif
2580+
25722581
// Bootstrap Node.js
25732582
Local<Object> bootstrapper = Object::New(env->isolate());
25742583
SetupBootstrapObject(env, bootstrapper);
@@ -3044,6 +3053,22 @@ static void ParseArgs(int* argc,
30443053
// Also a V8 option. Pass through as-is.
30453054
new_v8_argv[new_v8_argc] = arg;
30463055
new_v8_argc += 1;
3056+
} else if (strcmp(arg, "--report-events") == 0) {
3057+
const char* events = argv[index + 1];
3058+
if (events == nullptr) {
3059+
fprintf(stderr, "%s: %s requires an argument\n", argv[0], arg);
3060+
exit(9);
3061+
}
3062+
args_consumed += 1;
3063+
report_events = events;
3064+
fprintf(stderr, "parsed events %s \n", report_events.c_str());
3065+
// Replace ',' with '+' separators
3066+
std::size_t c = report_events.find_first_of(",");
3067+
while (c != std::string::npos) {
3068+
report_events.replace(c, 1, "+");
3069+
c = report_events.find_first_of(",", c + 1);
3070+
}
3071+
fprintf(stderr, "filtered events %s \n", report_events.c_str());
30473072
} else {
30483073
// V8 option. Pass through as-is.
30493074
new_v8_argv[new_v8_argc] = arg;
@@ -3691,11 +3716,6 @@ inline int Start(Isolate* isolate, IsolateData* isolate_data,
36913716

36923717
env.set_trace_sync_io(trace_sync_io);
36933718

3694-
#if defined(NODE_REPORT)
3695-
nodereport::InitializeNodeReport();
3696-
nodereport::SetEvents(isolate, "fatalerror+signal");
3697-
#endif
3698-
36993719
{
37003720
SealHandleScope seal(isolate);
37013721
bool more;

test/common/node-report.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
const assert = require('assert');
2-
const reportCommon = require('../../../deps/node-report/test/common');
2+
const reportCommon = require('../../deps/node-report/test/common');
33

44
exports.findReports = reportCommon.findReports;
55
exports.validate = (report, options) => {
66
t = {
7-
test: (name, f) => f(),
7+
match: (actual, re, m) => assert.ok(actual.match(re) != null, m),
8+
plan: () => {},
9+
test: (name, f) => f(t),
810
}
11+
console.log(t)
912
reportCommon.validate(t, report, options);
1013
}
1114

+24-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,31 @@
11
const common = require('../common');
2+
const tmpdir = require('../common/tmpdir');
23
const assert = require('assert');
4+
const { execFile } = require('child_process');
35
const reportCommon = require('../common/node-report');
46

57
if (common.isWindows)
68
common.skip('signals not supported on Windows');
7-
process.kill(process.pid, 'SIGUSR2');
8-
const report = reportCommon.findReports(process.pid);
9-
assertStrictEquals(report.length, 1);
9+
10+
if (process.argv.includes('child')) {
11+
process.kill(process.pid, 'SIGUSR2');
12+
return;
13+
}
14+
15+
tmpdir.refresh();
16+
process.chdir(tmpdir.path);
17+
let cp;
18+
console.log("running");
19+
//cp = execFile(process.execPath, ['--report-events', 'signal', __filename, 'child'], { cwd: tmpdir.path },
20+
cp = execFile(process.execPath, ['--report-events', 'signal', __filename, 'child'], { cwd: tmpdir.path },
21+
common.mustCall((err, stdout, stderr) => {
22+
console.log(cp);
23+
console.log(stdout);
24+
console.log(stderr);
25+
assert.ifError(err);
26+
const report = reportCommon.findReports(cp.pid);
27+
assert.strictEqual(report.length, 1);
28+
reportCommon.validate(report[0], { pid: cp.pid });
29+
}));
30+
1031

0 commit comments

Comments
 (0)