11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ci// This tests that invalid --cpu-prof options are rejected.
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ciconst common = require('../common');
61cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures');
71cb0ef41Sopenharmony_cicommon.skipIfInspectorDisabled();
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ciconst assert = require('assert');
101cb0ef41Sopenharmony_ciconst { spawnSync } = require('child_process');
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_ciconst tmpdir = require('../common/tmpdir');
131cb0ef41Sopenharmony_ciconst {
141cb0ef41Sopenharmony_ci  kCpuProfInterval,
151cb0ef41Sopenharmony_ci  env
161cb0ef41Sopenharmony_ci} = require('../common/cpu-prof');
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_ci// --cpu-prof-name without --cpu-prof
191cb0ef41Sopenharmony_ci{
201cb0ef41Sopenharmony_ci  tmpdir.refresh();
211cb0ef41Sopenharmony_ci  const output = spawnSync(process.execPath, [
221cb0ef41Sopenharmony_ci    '--cpu-prof-name',
231cb0ef41Sopenharmony_ci    'test.cpuprofile',
241cb0ef41Sopenharmony_ci    fixtures.path('workload', 'fibonacci.js'),
251cb0ef41Sopenharmony_ci  ], {
261cb0ef41Sopenharmony_ci    cwd: tmpdir.path,
271cb0ef41Sopenharmony_ci    env
281cb0ef41Sopenharmony_ci  });
291cb0ef41Sopenharmony_ci  const stderr = output.stderr.toString().trim();
301cb0ef41Sopenharmony_ci  if (output.status !== 9) {
311cb0ef41Sopenharmony_ci    console.log(stderr);
321cb0ef41Sopenharmony_ci  }
331cb0ef41Sopenharmony_ci  assert.strictEqual(output.status, 9);
341cb0ef41Sopenharmony_ci  assert.strictEqual(
351cb0ef41Sopenharmony_ci    stderr,
361cb0ef41Sopenharmony_ci    `${process.execPath}: --cpu-prof-name must be used with --cpu-prof`);
371cb0ef41Sopenharmony_ci}
381cb0ef41Sopenharmony_ci
391cb0ef41Sopenharmony_ci// --cpu-prof-dir without --cpu-prof
401cb0ef41Sopenharmony_ci{
411cb0ef41Sopenharmony_ci  tmpdir.refresh();
421cb0ef41Sopenharmony_ci  const output = spawnSync(process.execPath, [
431cb0ef41Sopenharmony_ci    '--cpu-prof-dir',
441cb0ef41Sopenharmony_ci    'prof',
451cb0ef41Sopenharmony_ci    fixtures.path('workload', 'fibonacci.js'),
461cb0ef41Sopenharmony_ci  ], {
471cb0ef41Sopenharmony_ci    cwd: tmpdir.path,
481cb0ef41Sopenharmony_ci    env
491cb0ef41Sopenharmony_ci  });
501cb0ef41Sopenharmony_ci  const stderr = output.stderr.toString().trim();
511cb0ef41Sopenharmony_ci  if (output.status !== 9) {
521cb0ef41Sopenharmony_ci    console.log(stderr);
531cb0ef41Sopenharmony_ci  }
541cb0ef41Sopenharmony_ci  assert.strictEqual(output.status, 9);
551cb0ef41Sopenharmony_ci  assert.strictEqual(
561cb0ef41Sopenharmony_ci    stderr,
571cb0ef41Sopenharmony_ci    `${process.execPath}: --cpu-prof-dir must be used with --cpu-prof`);
581cb0ef41Sopenharmony_ci}
591cb0ef41Sopenharmony_ci
601cb0ef41Sopenharmony_ci// --cpu-prof-interval without --cpu-prof
611cb0ef41Sopenharmony_cifor (const arg of [kCpuProfInterval, 'crashme']) {
621cb0ef41Sopenharmony_ci  tmpdir.refresh();
631cb0ef41Sopenharmony_ci  const output = spawnSync(process.execPath, [
641cb0ef41Sopenharmony_ci    '--cpu-prof-interval',
651cb0ef41Sopenharmony_ci    arg,
661cb0ef41Sopenharmony_ci    fixtures.path('workload', 'fibonacci.js'),
671cb0ef41Sopenharmony_ci  ], {
681cb0ef41Sopenharmony_ci    cwd: tmpdir.path,
691cb0ef41Sopenharmony_ci    env
701cb0ef41Sopenharmony_ci  });
711cb0ef41Sopenharmony_ci  const stderr = output.stderr.toString().trim();
721cb0ef41Sopenharmony_ci  if (output.status !== 9) {
731cb0ef41Sopenharmony_ci    console.log(stderr);
741cb0ef41Sopenharmony_ci  }
751cb0ef41Sopenharmony_ci  assert.strictEqual(output.status, 9);
761cb0ef41Sopenharmony_ci  assert.strictEqual(
771cb0ef41Sopenharmony_ci    stderr,
781cb0ef41Sopenharmony_ci    `${process.execPath}: --cpu-prof-interval must be used with --cpu-prof`);
791cb0ef41Sopenharmony_ci}
80