From 0800f91dcc31d0613ef697f8ea4fa82d270e873e Mon Sep 17 00:00:00 2001 From: LakshmiSwethaG Date: Wed, 5 Sep 2018 10:39:08 -0400 Subject: [PATCH] test: add node-report tests One test per each API, so that additional tests in future are modular. test/common/report.js contain common functions that tests leverage. PR-URL: https://github.com/nodejs/node/pull/22712 Reviewed-By: Anna Henningsen Reviewed-By: James M Snell Reviewed-By: Michael Dawson Reviewed-By: Vse Mozhet Byt --- doc/api/errors.md | 6 ++ lib/internal/errors.js | 2 +- test/common/index.js | 7 ++ test/common/report.js | 43 ++++++++ test/node-report/test-api-getreport.js | 28 +++++ test/node-report/test-api-nohooks.js | 30 ++++++ test/node-report/test-api-pass-error.js | 33 ++++++ test/node-report/test-api-uvhandles.js | 133 ++++++++++++++++++++++++ test/node-report/test-api.js | 29 ++++++ test/node-report/test-exception.js | 44 ++++++++ test/node-report/test-fatal-error.js | 44 ++++++++ test/node-report/test-signal.js | 80 ++++++++++++++ test/node-report/testcfg.py | 6 ++ 13 files changed, 484 insertions(+), 1 deletion(-) create mode 100644 test/common/report.js create mode 100644 test/node-report/test-api-getreport.js create mode 100644 test/node-report/test-api-nohooks.js create mode 100644 test/node-report/test-api-pass-error.js create mode 100644 test/node-report/test-api-uvhandles.js create mode 100644 test/node-report/test-api.js create mode 100644 test/node-report/test-exception.js create mode 100644 test/node-report/test-fatal-error.js create mode 100644 test/node-report/test-signal.js create mode 100644 test/node-report/testcfg.py diff --git a/doc/api/errors.md b/doc/api/errors.md index d9fbc9f2b40..39d131b42aa 100644 --- a/doc/api/errors.md +++ b/doc/api/errors.md @@ -2227,6 +2227,12 @@ size. This `Error` is thrown when a read is attempted on a TTY `WriteStream`, such as `process.stdout.on('data')`. + +#### ERR_SYNTHETIC + +An artifical error object used to capture call stack when diagnostic report +is produced. + [`'uncaughtException'`]: process.html#process_event_uncaughtexception [`--force-fips`]: cli.html#cli_force_fips diff --git a/lib/internal/errors.js b/lib/internal/errors.js index d5cb86c3a5a..f8d7aafeec1 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -709,7 +709,6 @@ E('ERR_INSPECTOR_CLOSED', 'Session was closed', Error); E('ERR_INSPECTOR_NOT_AVAILABLE', 'Inspector is not available', Error); E('ERR_INSPECTOR_NOT_CONNECTED', 'Session is not connected', Error); E('ERR_INVALID_ADDRESS_FAMILY', 'Invalid address family: %s', RangeError); -E('ERR_SYNTHETIC', 'JavaScript Callstack: %s', Error); E('ERR_INVALID_ARG_TYPE', (name, expected, actual) => { assert(typeof name === 'string', "'name' must be a string"); @@ -924,6 +923,7 @@ E('ERR_STREAM_UNSHIFT_AFTER_END_EVENT', 'stream.unshift() after end event', Error); E('ERR_STREAM_WRAP', 'Stream has StringDecoder set or is in objectMode', Error); E('ERR_STREAM_WRITE_AFTER_END', 'write after end', Error); +E('ERR_SYNTHETIC', 'JavaScript Callstack: %s', Error); E('ERR_SYSTEM_ERROR', 'A system error occurred', SystemError); E('ERR_TLS_CERT_ALTNAME_INVALID', 'Hostname/IP does not match certificate\'s altnames: %s', Error); diff --git a/test/common/index.js b/test/common/index.js index 0bd7ab6dbca..308d7376189 100644 --- a/test/common/index.js +++ b/test/common/index.js @@ -636,6 +636,12 @@ function skipIfInspectorDisabled() { } } +function skipIfReportDisabled() { + if (!process.config.variables.node_report) { + skip('Node Report is disabled'); + } +} + function skipIf32Bits() { if (bits < 64) { skip('The tested feature is not available in 32bit builds'); @@ -762,6 +768,7 @@ module.exports = { skipIf32Bits, skipIfEslintMissing, skipIfInspectorDisabled, + skipIfReportDisabled, skipIfWorker, get localhostIPv6() { return '::1'; }, diff --git a/test/common/report.js b/test/common/report.js new file mode 100644 index 00000000000..646660da496 --- /dev/null +++ b/test/common/report.js @@ -0,0 +1,43 @@ +'use strict'; +require('../common'); +const assert = require('assert'); +const fs = require('fs'); +const path = require('path'); + +const REPORT_SECTIONS = [ 'header', + 'javascriptStack', + 'nativeStack', + 'javascriptHeap', + 'libuv', + 'environmentVariables', + 'sharedObjects' ]; + +let tmppath = ''; + +exports.findReports = (pid, path) => { + // Default filenames are of the form + // report..