Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
squash: commit test tweaks
  • Loading branch information
richardlau committed Aug 14, 2018
commit c54ebfd2e88b3ce6966ceff2d3bf054927cbbc48
30 changes: 25 additions & 5 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Object> bootstrapper = Object::New(env->isolate());
SetupBootstrapObject(env, bootstrapper);
Expand Down Expand Up @@ -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());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we have a default value for --report-events ? i.e., in case if user specifies this flag but no values, how about picking the most relevant trace events and feed those into report_events filed?

} else {
// V8 option. Pass through as-is.
new_v8_argv[new_v8_argc] = arg;
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 5 additions & 2 deletions test/common/node-report.js
Original file line number Diff line number Diff line change
@@ -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);
}

27 changes: 24 additions & 3 deletions test/parallel/test-node-report-signal.js
Original file line number Diff line number Diff line change
@@ -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 });
}));