1'use strict'; 2 3// Testcases for situations involving fatal errors, like Javascript heap OOM 4 5require('../common'); 6const assert = require('assert'); 7const helper = require('../common/report.js'); 8const spawnSync = require('child_process').spawnSync; 9const tmpdir = require('../common/tmpdir'); 10const fixtures = require('../common/fixtures'); 11 12// Common args that will cause an out-of-memory error for child process. 13const ARGS = [ 14 '--max-heap-size=20', 15 fixtures.path('report-oom'), 16]; 17const REPORT_FIELDS = [ 18 ['header.trigger', 'OOMError'], 19 ['javascriptHeap.memoryLimit', 20 * 1024 * 1024 /* 20MB */], 20]; 21 22{ 23 // Verify that --report-compact is respected when set. 24 // Verify that --report-filename is respected when set. 25 tmpdir.refresh(); 26 const args = [ 27 '--report-on-fatalerror', 28 '--report-compact', 29 '--report-filename=stderr', 30 ...ARGS, 31 ]; 32 const child = spawnSync(process.execPath, args, { encoding: 'utf8' }); 33 assert.notStrictEqual(child.status, 0, 'Process exited unexpectedly'); 34 35 const reports = helper.findReports(child.pid, tmpdir.path); 36 assert.strictEqual(reports.length, 0); 37 38 const lines = child.stderr.split('\n'); 39 // Skip over unavoidable free-form output and gc log from V8. 40 const report = lines.find((i) => i.startsWith('{')); 41 helper.validateContent(report, REPORT_FIELDS); 42} 43