11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst common = require('../common'); 41cb0ef41Sopenharmony_ciconst tmpdir = require('../common/tmpdir'); 51cb0ef41Sopenharmony_ciconst assert = require('assert'); 61cb0ef41Sopenharmony_ciconst { spawnSync } = require('child_process'); 71cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures'); 81cb0ef41Sopenharmony_ciconst fs = require('fs'); 91cb0ef41Sopenharmony_ciconst env = { 101cb0ef41Sopenharmony_ci ...process.env, 111cb0ef41Sopenharmony_ci NODE_DEBUG_NATIVE: 'diagnostics', 121cb0ef41Sopenharmony_ci}; 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_ciif (!common.enoughTestMem) 151cb0ef41Sopenharmony_ci common.skip('Insufficient memory for snapshot test'); 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ci{ 181cb0ef41Sopenharmony_ci console.log('\nTesting limit = 3'); 191cb0ef41Sopenharmony_ci tmpdir.refresh(); 201cb0ef41Sopenharmony_ci const child = spawnSync(process.execPath, [ 211cb0ef41Sopenharmony_ci '--heapsnapshot-near-heap-limit=3', 221cb0ef41Sopenharmony_ci '--max-old-space-size=512', 231cb0ef41Sopenharmony_ci fixtures.path('workload', 'grow.js'), 241cb0ef41Sopenharmony_ci ], { 251cb0ef41Sopenharmony_ci cwd: tmpdir.path, 261cb0ef41Sopenharmony_ci env: { 271cb0ef41Sopenharmony_ci ...env, 281cb0ef41Sopenharmony_ci TEST_CHUNK: 2000, 291cb0ef41Sopenharmony_ci }, 301cb0ef41Sopenharmony_ci }); 311cb0ef41Sopenharmony_ci const stderr = child.stderr.toString(); 321cb0ef41Sopenharmony_ci console.log(stderr); 331cb0ef41Sopenharmony_ci assert(common.nodeProcessAborted(child.status, child.signal), 341cb0ef41Sopenharmony_ci 'process should have aborted, but did not'); 351cb0ef41Sopenharmony_ci const list = fs.readdirSync(tmpdir.path) 361cb0ef41Sopenharmony_ci .filter((file) => file.endsWith('.heapsnapshot')); 371cb0ef41Sopenharmony_ci const risky = [...stderr.matchAll( 381cb0ef41Sopenharmony_ci /Not generating snapshots because it's too risky/g)].length; 391cb0ef41Sopenharmony_ci assert(list.length + risky > 0 && list.length <= 3, 401cb0ef41Sopenharmony_ci `Generated ${list.length} snapshots ` + 411cb0ef41Sopenharmony_ci `and ${risky} was too risky`); 421cb0ef41Sopenharmony_ci} 43