11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ci// Tests --heap-prof generates a heap profile when
41cb0ef41Sopenharmony_ci// process.kill(process.pid, "SIGINT"); exits process.
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ciconst common = require('../common');
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures');
91cb0ef41Sopenharmony_cicommon.skipIfInspectorDisabled();
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ciconst assert = require('assert');
121cb0ef41Sopenharmony_ciconst { spawnSync } = require('child_process');
131cb0ef41Sopenharmony_ci
141cb0ef41Sopenharmony_ciconst tmpdir = require('../common/tmpdir');
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_ciconst {
171cb0ef41Sopenharmony_ci  getHeapProfiles,
181cb0ef41Sopenharmony_ci  verifyFrames,
191cb0ef41Sopenharmony_ci  kHeapProfInterval,
201cb0ef41Sopenharmony_ci  env
211cb0ef41Sopenharmony_ci} = require('../common/prof');
221cb0ef41Sopenharmony_ci
231cb0ef41Sopenharmony_ci{
241cb0ef41Sopenharmony_ci  tmpdir.refresh();
251cb0ef41Sopenharmony_ci  const output = spawnSync(process.execPath, [
261cb0ef41Sopenharmony_ci    '--heap-prof',
271cb0ef41Sopenharmony_ci    '--heap-prof-interval',
281cb0ef41Sopenharmony_ci    kHeapProfInterval,
291cb0ef41Sopenharmony_ci    fixtures.path('workload', 'allocation-sigint.js'),
301cb0ef41Sopenharmony_ci  ], {
311cb0ef41Sopenharmony_ci    cwd: tmpdir.path,
321cb0ef41Sopenharmony_ci    env
331cb0ef41Sopenharmony_ci  });
341cb0ef41Sopenharmony_ci  if (!common.isWindows) {
351cb0ef41Sopenharmony_ci    if (output.signal !== 'SIGINT') {
361cb0ef41Sopenharmony_ci      console.log(output.stderr.toString());
371cb0ef41Sopenharmony_ci    }
381cb0ef41Sopenharmony_ci    assert.strictEqual(output.signal, 'SIGINT');
391cb0ef41Sopenharmony_ci  }
401cb0ef41Sopenharmony_ci  const profiles = getHeapProfiles(tmpdir.path);
411cb0ef41Sopenharmony_ci  assert.strictEqual(profiles.length, 1);
421cb0ef41Sopenharmony_ci  verifyFrames(output, profiles[0], 'runAllocation');
431cb0ef41Sopenharmony_ci}
44