11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ci// Testcases for situations involving fatal errors, like Javascript heap OOM 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_cirequire('../common'); 61cb0ef41Sopenharmony_ciconst assert = require('assert'); 71cb0ef41Sopenharmony_ciconst helper = require('../common/report.js'); 81cb0ef41Sopenharmony_ciconst spawnSync = require('child_process').spawnSync; 91cb0ef41Sopenharmony_ciconst tmpdir = require('../common/tmpdir'); 101cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures'); 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ci// Common args that will cause an out-of-memory error for child process. 131cb0ef41Sopenharmony_ciconst ARGS = [ 141cb0ef41Sopenharmony_ci '--max-heap-size=20', 151cb0ef41Sopenharmony_ci fixtures.path('report-oom'), 161cb0ef41Sopenharmony_ci]; 171cb0ef41Sopenharmony_ciconst REPORT_FIELDS = [ 181cb0ef41Sopenharmony_ci ['header.trigger', 'OOMError'], 191cb0ef41Sopenharmony_ci ['javascriptHeap.memoryLimit', 20 * 1024 * 1024 /* 20MB */], 201cb0ef41Sopenharmony_ci]; 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_ci{ 231cb0ef41Sopenharmony_ci // Verify that --report-on-fatalerror is respected when set. 241cb0ef41Sopenharmony_ci tmpdir.refresh(); 251cb0ef41Sopenharmony_ci const args = ['--report-on-fatalerror', ...ARGS]; 261cb0ef41Sopenharmony_ci const child = spawnSync(process.execPath, args, { cwd: tmpdir.path }); 271cb0ef41Sopenharmony_ci assert.notStrictEqual(child.status, 0, 'Process exited unexpectedly'); 281cb0ef41Sopenharmony_ci 291cb0ef41Sopenharmony_ci const reports = helper.findReports(child.pid, tmpdir.path); 301cb0ef41Sopenharmony_ci assert.strictEqual(reports.length, 1); 311cb0ef41Sopenharmony_ci 321cb0ef41Sopenharmony_ci const report = reports[0]; 331cb0ef41Sopenharmony_ci helper.validate(report, REPORT_FIELDS); 341cb0ef41Sopenharmony_ci} 35