0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-24 12:10:08 +01:00
nodejs/test/sequential/test-cpu-prof-invalid-options.js
Ben Noordhuis 3700d9edf7
src: fix c++ exception on bad command line arg
Replace stoull() with strtoull(). The former throws an exception when
the input is malformed, the latter doesn't.

Fixes: https://github.com/nodejs/node/issues/46223
PR-URL: https://github.com/nodejs/node/pull/46290
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
2023-01-22 10:39:16 +00:00

80 lines
1.9 KiB
JavaScript

'use strict';
// This tests that invalid --cpu-prof options are rejected.
const common = require('../common');
const fixtures = require('../common/fixtures');
common.skipIfInspectorDisabled();
const assert = require('assert');
const { spawnSync } = require('child_process');
const tmpdir = require('../common/tmpdir');
const {
kCpuProfInterval,
env
} = require('../common/cpu-prof');
// --cpu-prof-name without --cpu-prof
{
tmpdir.refresh();
const output = spawnSync(process.execPath, [
'--cpu-prof-name',
'test.cpuprofile',
fixtures.path('workload', 'fibonacci.js'),
], {
cwd: tmpdir.path,
env
});
const stderr = output.stderr.toString().trim();
if (output.status !== 9) {
console.log(stderr);
}
assert.strictEqual(output.status, 9);
assert.strictEqual(
stderr,
`${process.execPath}: --cpu-prof-name must be used with --cpu-prof`);
}
// --cpu-prof-dir without --cpu-prof
{
tmpdir.refresh();
const output = spawnSync(process.execPath, [
'--cpu-prof-dir',
'prof',
fixtures.path('workload', 'fibonacci.js'),
], {
cwd: tmpdir.path,
env
});
const stderr = output.stderr.toString().trim();
if (output.status !== 9) {
console.log(stderr);
}
assert.strictEqual(output.status, 9);
assert.strictEqual(
stderr,
`${process.execPath}: --cpu-prof-dir must be used with --cpu-prof`);
}
// --cpu-prof-interval without --cpu-prof
for (const arg of [kCpuProfInterval, 'crashme']) {
tmpdir.refresh();
const output = spawnSync(process.execPath, [
'--cpu-prof-interval',
arg,
fixtures.path('workload', 'fibonacci.js'),
], {
cwd: tmpdir.path,
env
});
const stderr = output.stderr.toString().trim();
if (output.status !== 9) {
console.log(stderr);
}
assert.strictEqual(output.status, 9);
assert.strictEqual(
stderr,
`${process.execPath}: --cpu-prof-interval must be used with --cpu-prof`);
}