1'use strict';
2
3// This tests that --cpu-prof generates CPU profile when
4// process.kill(process.pid, "SIGINT"); exits the process.
5
6const common = require('../common');
7const fixtures = require('../common/fixtures');
8common.skipIfInspectorDisabled();
9
10const assert = require('assert');
11const { spawnSync } = require('child_process');
12
13const tmpdir = require('../common/tmpdir');
14const {
15  getCpuProfiles,
16  kCpuProfInterval,
17  env,
18  verifyFrames
19} = require('../common/cpu-prof');
20
21{
22  tmpdir.refresh();
23  const output = spawnSync(process.execPath, [
24    '--cpu-prof',
25    '--cpu-prof-interval',
26    kCpuProfInterval,
27    fixtures.path('workload', 'fibonacci-sigint.js'),
28  ], {
29    cwd: tmpdir.path,
30    env
31  });
32  if (!common.isWindows) {
33    if (output.signal !== 'SIGINT') {
34      console.log(output.stderr.toString());
35    }
36    assert.strictEqual(output.signal, 'SIGINT');
37  }
38  const profiles = getCpuProfiles(tmpdir.path);
39  assert.strictEqual(profiles.length, 1);
40  verifyFrames(output, profiles[0], 'fibonacci-sigint.js');
41}
42