• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3// This tests that invalid --cpu-prof options are rejected.
4
5const common = require('../common');
6const fixtures = require('../common/fixtures');
7common.skipIfInspectorDisabled();
8
9const assert = require('assert');
10const { spawnSync } = require('child_process');
11
12const tmpdir = require('../common/tmpdir');
13const {
14  kCpuProfInterval,
15  env
16} = require('../common/cpu-prof');
17
18// --cpu-prof-name without --cpu-prof
19{
20  tmpdir.refresh();
21  const output = spawnSync(process.execPath, [
22    '--cpu-prof-name',
23    'test.cpuprofile',
24    fixtures.path('workload', 'fibonacci.js'),
25  ], {
26    cwd: tmpdir.path,
27    env
28  });
29  const stderr = output.stderr.toString().trim();
30  if (output.status !== 9) {
31    console.log(stderr);
32  }
33  assert.strictEqual(output.status, 9);
34  assert.strictEqual(
35    stderr,
36    `${process.execPath}: --cpu-prof-name must be used with --cpu-prof`);
37}
38
39// --cpu-prof-dir without --cpu-prof
40{
41  tmpdir.refresh();
42  const output = spawnSync(process.execPath, [
43    '--cpu-prof-dir',
44    'prof',
45    fixtures.path('workload', 'fibonacci.js'),
46  ], {
47    cwd: tmpdir.path,
48    env
49  });
50  const stderr = output.stderr.toString().trim();
51  if (output.status !== 9) {
52    console.log(stderr);
53  }
54  assert.strictEqual(output.status, 9);
55  assert.strictEqual(
56    stderr,
57    `${process.execPath}: --cpu-prof-dir must be used with --cpu-prof`);
58}
59
60// --cpu-prof-interval without --cpu-prof
61for (const arg of [kCpuProfInterval, 'crashme']) {
62  tmpdir.refresh();
63  const output = spawnSync(process.execPath, [
64    '--cpu-prof-interval',
65    arg,
66    fixtures.path('workload', 'fibonacci.js'),
67  ], {
68    cwd: tmpdir.path,
69    env
70  });
71  const stderr = output.stderr.toString().trim();
72  if (output.status !== 9) {
73    console.log(stderr);
74  }
75  assert.strictEqual(output.status, 9);
76  assert.strictEqual(
77    stderr,
78    `${process.execPath}: --cpu-prof-interval must be used with --cpu-prof`);
79}
80