diff --git a/src/node.cc b/src/node.cc index ca15ddfc26a9a3..65ce3b424f5067 100644 --- a/src/node.cc +++ b/src/node.cc @@ -200,6 +200,7 @@ static std::string trace_enabled_categories; // NOLINT(runtime/string) static std::string trace_file_pattern = // NOLINT(runtime/string) "node_trace.${rotation}.log"; static bool abort_on_uncaught_exception = false; +static std::string report_events; // NOLINT(runtime/string) // Bit flag used to track security reverts (see node_revert.h) unsigned int reverted = 0; @@ -2569,6 +2570,14 @@ void LoadEnvironment(Environment* env) { return; } +#if defined(NODE_REPORT) + fprintf(stderr, "report events: %s \n", report_events.c_str()); + if (!report_events.empty()) { + nodereport::InitializeNodeReport(); + nodereport::SetEvents(env->isolate(), report_events.c_str()); + } +#endif + // Bootstrap Node.js Local bootstrapper = Object::New(env->isolate()); SetupBootstrapObject(env, bootstrapper); @@ -3044,6 +3053,22 @@ static void ParseArgs(int* argc, // Also a V8 option. Pass through as-is. new_v8_argv[new_v8_argc] = arg; new_v8_argc += 1; + } else if (strcmp(arg, "--report-events") == 0) { + const char* events = argv[index + 1]; + if (events == nullptr) { + fprintf(stderr, "%s: %s requires an argument\n", argv[0], arg); + exit(9); + } + args_consumed += 1; + report_events = events; + fprintf(stderr, "parsed events %s \n", report_events.c_str()); + // Replace ',' with '+' separators + std::size_t c = report_events.find_first_of(","); + while (c != std::string::npos) { + report_events.replace(c, 1, "+"); + c = report_events.find_first_of(",", c + 1); + } + fprintf(stderr, "filtered events %s \n", report_events.c_str()); } else { // V8 option. Pass through as-is. new_v8_argv[new_v8_argc] = arg; @@ -3691,11 +3716,6 @@ inline int Start(Isolate* isolate, IsolateData* isolate_data, env.set_trace_sync_io(trace_sync_io); -#if defined(NODE_REPORT) - nodereport::InitializeNodeReport(); - nodereport::SetEvents(isolate, "fatalerror+signal"); -#endif - { SealHandleScope seal(isolate); bool more; diff --git a/test/common/node-report.js b/test/common/node-report.js index 988314d3b025b2..05763f01b35fa3 100644 --- a/test/common/node-report.js +++ b/test/common/node-report.js @@ -1,11 +1,14 @@ const assert = require('assert'); -const reportCommon = require('../../../deps/node-report/test/common'); +const reportCommon = require('../../deps/node-report/test/common'); exports.findReports = reportCommon.findReports; exports.validate = (report, options) => { t = { - test: (name, f) => f(), + match: (actual, re, m) => assert.ok(actual.match(re) != null, m), + plan: () => {}, + test: (name, f) => f(t), } + console.log(t) reportCommon.validate(t, report, options); } diff --git a/test/parallel/test-node-report-signal.js b/test/parallel/test-node-report-signal.js index 3d2f331be88d5a..8b9b789eeae7b9 100644 --- a/test/parallel/test-node-report-signal.js +++ b/test/parallel/test-node-report-signal.js @@ -1,10 +1,31 @@ const common = require('../common'); +const tmpdir = require('../common/tmpdir'); const assert = require('assert'); +const { execFile } = require('child_process'); const reportCommon = require('../common/node-report'); if (common.isWindows) common.skip('signals not supported on Windows'); -process.kill(process.pid, 'SIGUSR2'); -const report = reportCommon.findReports(process.pid); -assertStrictEquals(report.length, 1); + +if (process.argv.includes('child')) { + process.kill(process.pid, 'SIGUSR2'); + return; +} + +tmpdir.refresh(); +process.chdir(tmpdir.path); +let cp; +console.log("running"); +//cp = execFile(process.execPath, ['--report-events', 'signal', __filename, 'child'], { cwd: tmpdir.path }, +cp = execFile(process.execPath, ['--report-events', 'signal', __filename, 'child'], { cwd: tmpdir.path }, +common.mustCall((err, stdout, stderr) => { +console.log(cp); +console.log(stdout); +console.log(stderr); +assert.ifError(err); +const report = reportCommon.findReports(cp.pid); +assert.strictEqual(report.length, 1); +reportCommon.validate(report[0], { pid: cp.pid }); +})); +