From 7e5e1c251526a1ee59071f0e312cb2da99454bda Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Fri, 14 Jun 2019 01:09:23 +0800 Subject: test: move --cpu-prof tests to sequential The tests still fail after being split into multiple files, (2 out of 30 runs in roughly 48 hours) and the causes are missing target frames in the samples. This patch moves them to sequential to observe if the flakiness can be fixed when the tests are run on a system with less load. If the flake ever shows up again even after the tests are moved to sequential, we should consider make the test conditions more lenient - that is, we would only assert that there are *some* frames in the generated CPU profile but do not look for the target function there. PR-URL: https://github.com/nodejs/node/pull/28210 Refs: https://github.com/nodejs/node/issues/27611 Reviewed-By: Rich Trott Reviewed-By: Michael Dawson Reviewed-By: James M Snell --- test/parallel/test-cpu-prof-default.js | 36 ----------- test/parallel/test-cpu-prof-dir-absolute.js | 45 -------------- test/parallel/test-cpu-prof-dir-and-name.js | 47 -------------- test/parallel/test-cpu-prof-dir-relative.js | 45 -------------- test/parallel/test-cpu-prof-dir-worker.js | 55 ----------------- test/parallel/test-cpu-prof-drained.js | 40 ------------ test/parallel/test-cpu-prof-exit.js | 39 ------------ test/parallel/test-cpu-prof-invalid-options.js | 79 ------------------------ test/parallel/test-cpu-prof-kill.js | 41 ------------ test/parallel/test-cpu-prof-name.js | 44 ------------- test/parallel/test-cpu-prof-worker-argv.js | 38 ------------ test/sequential/test-cpu-prof-default.js | 36 +++++++++++ test/sequential/test-cpu-prof-dir-absolute.js | 45 ++++++++++++++ test/sequential/test-cpu-prof-dir-and-name.js | 47 ++++++++++++++ test/sequential/test-cpu-prof-dir-relative.js | 45 ++++++++++++++ test/sequential/test-cpu-prof-dir-worker.js | 55 +++++++++++++++++ test/sequential/test-cpu-prof-drained.js | 40 ++++++++++++ test/sequential/test-cpu-prof-exit.js | 39 ++++++++++++ test/sequential/test-cpu-prof-invalid-options.js | 79 ++++++++++++++++++++++++ test/sequential/test-cpu-prof-kill.js | 41 ++++++++++++ test/sequential/test-cpu-prof-name.js | 44 +++++++++++++ test/sequential/test-cpu-prof-worker-argv.js | 38 ++++++++++++ 22 files changed, 509 insertions(+), 509 deletions(-) delete mode 100644 test/parallel/test-cpu-prof-default.js delete mode 100644 test/parallel/test-cpu-prof-dir-absolute.js delete mode 100644 test/parallel/test-cpu-prof-dir-and-name.js delete mode 100644 test/parallel/test-cpu-prof-dir-relative.js delete mode 100644 test/parallel/test-cpu-prof-dir-worker.js delete mode 100644 test/parallel/test-cpu-prof-drained.js delete mode 100644 test/parallel/test-cpu-prof-exit.js delete mode 100644 test/parallel/test-cpu-prof-invalid-options.js delete mode 100644 test/parallel/test-cpu-prof-kill.js delete mode 100644 test/parallel/test-cpu-prof-name.js delete mode 100644 test/parallel/test-cpu-prof-worker-argv.js create mode 100644 test/sequential/test-cpu-prof-default.js create mode 100644 test/sequential/test-cpu-prof-dir-absolute.js create mode 100644 test/sequential/test-cpu-prof-dir-and-name.js create mode 100644 test/sequential/test-cpu-prof-dir-relative.js create mode 100644 test/sequential/test-cpu-prof-dir-worker.js create mode 100644 test/sequential/test-cpu-prof-drained.js create mode 100644 test/sequential/test-cpu-prof-exit.js create mode 100644 test/sequential/test-cpu-prof-invalid-options.js create mode 100644 test/sequential/test-cpu-prof-kill.js create mode 100644 test/sequential/test-cpu-prof-name.js create mode 100644 test/sequential/test-cpu-prof-worker-argv.js diff --git a/test/parallel/test-cpu-prof-default.js b/test/parallel/test-cpu-prof-default.js deleted file mode 100644 index 12c4bc05bb..0000000000 --- a/test/parallel/test-cpu-prof-default.js +++ /dev/null @@ -1,36 +0,0 @@ -'use strict'; - -// Test --cpu-prof without --cpu-prof-interval. Here we just verify that -// we manage to generate a profile since it's hard to tell whether we -// can sample our target function with the default sampling rate across -// different platforms and machine configurations. - -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 { - getCpuProfiles, - env -} = require('../common/cpu-prof'); - -{ - tmpdir.refresh(); - const output = spawnSync(process.execPath, [ - '--cpu-prof', - fixtures.path('workload', 'fibonacci.js'), - ], { - cwd: tmpdir.path, - env - }); - if (output.status !== 0) { - console.log(output.stderr.toString()); - } - assert.strictEqual(output.status, 0); - const profiles = getCpuProfiles(tmpdir.path); - assert.strictEqual(profiles.length, 1); -} diff --git a/test/parallel/test-cpu-prof-dir-absolute.js b/test/parallel/test-cpu-prof-dir-absolute.js deleted file mode 100644 index ad0842dbc4..0000000000 --- a/test/parallel/test-cpu-prof-dir-absolute.js +++ /dev/null @@ -1,45 +0,0 @@ -'use strict'; - -// This tests that relative --cpu-prof-dir works. - -const common = require('../common'); -const fixtures = require('../common/fixtures'); -common.skipIfInspectorDisabled(); - -const assert = require('assert'); -const fs = require('fs'); -const path = require('path'); -const { spawnSync } = require('child_process'); - -const tmpdir = require('../common/tmpdir'); -const { - getCpuProfiles, - kCpuProfInterval, - env, - verifyFrames -} = require('../common/cpu-prof'); - -// relative --cpu-prof-dir -{ - tmpdir.refresh(); - const dir = path.join(tmpdir.path, 'prof'); - const output = spawnSync(process.execPath, [ - '--cpu-prof', - '--cpu-prof-interval', - kCpuProfInterval, - '--cpu-prof-dir', - dir, - fixtures.path('workload', 'fibonacci.js'), - ], { - cwd: tmpdir.path, - env - }); - if (output.status !== 0) { - console.log(output.stderr.toString()); - } - assert.strictEqual(output.status, 0); - assert(fs.existsSync(dir)); - const profiles = getCpuProfiles(dir); - assert.strictEqual(profiles.length, 1); - verifyFrames(output, profiles[0], 'fibonacci.js'); -} diff --git a/test/parallel/test-cpu-prof-dir-and-name.js b/test/parallel/test-cpu-prof-dir-and-name.js deleted file mode 100644 index 7ce775ebc1..0000000000 --- a/test/parallel/test-cpu-prof-dir-and-name.js +++ /dev/null @@ -1,47 +0,0 @@ -'use strict'; - -// This tests that --cpu-prof-dir and --cpu-prof-name works together. - -const common = require('../common'); -const fixtures = require('../common/fixtures'); -common.skipIfInspectorDisabled(); - -const assert = require('assert'); -const fs = require('fs'); -const path = require('path'); -const { spawnSync } = require('child_process'); - -const tmpdir = require('../common/tmpdir'); -const { - getCpuProfiles, - kCpuProfInterval, - env, - verifyFrames -} = require('../common/cpu-prof'); - -{ - tmpdir.refresh(); - const dir = path.join(tmpdir.path, 'prof'); - const file = path.join(dir, 'test.cpuprofile'); - const output = spawnSync(process.execPath, [ - '--cpu-prof', - '--cpu-prof-interval', - kCpuProfInterval, - '--cpu-prof-name', - 'test.cpuprofile', - '--cpu-prof-dir', - dir, - fixtures.path('workload', 'fibonacci.js'), - ], { - cwd: tmpdir.path, - env - }); - if (output.status !== 0) { - console.log(output.stderr.toString()); - } - assert.strictEqual(output.status, 0); - assert(fs.existsSync(dir)); - const profiles = getCpuProfiles(dir); - assert.deepStrictEqual(profiles, [file]); - verifyFrames(output, file, 'fibonacci.js'); -} diff --git a/test/parallel/test-cpu-prof-dir-relative.js b/test/parallel/test-cpu-prof-dir-relative.js deleted file mode 100644 index 2d679959ef..0000000000 --- a/test/parallel/test-cpu-prof-dir-relative.js +++ /dev/null @@ -1,45 +0,0 @@ -'use strict'; - -// This tests that relative --cpu-prof-dir works. - -const common = require('../common'); -const fixtures = require('../common/fixtures'); -common.skipIfInspectorDisabled(); - -const assert = require('assert'); -const fs = require('fs'); -const path = require('path'); -const { spawnSync } = require('child_process'); - -const tmpdir = require('../common/tmpdir'); -const { - getCpuProfiles, - kCpuProfInterval, - env, - verifyFrames -} = require('../common/cpu-prof'); - -// relative --cpu-prof-dir -{ - tmpdir.refresh(); - const output = spawnSync(process.execPath, [ - '--cpu-prof', - '--cpu-prof-interval', - kCpuProfInterval, - '--cpu-prof-dir', - 'prof', - fixtures.path('workload', 'fibonacci.js'), - ], { - cwd: tmpdir.path, - env - }); - if (output.status !== 0) { - console.log(output.stderr.toString()); - } - assert.strictEqual(output.status, 0); - const dir = path.join(tmpdir.path, 'prof'); - assert(fs.existsSync(dir)); - const profiles = getCpuProfiles(dir); - assert.strictEqual(profiles.length, 1); - verifyFrames(output, profiles[0], 'fibonacci.js'); -} diff --git a/test/parallel/test-cpu-prof-dir-worker.js b/test/parallel/test-cpu-prof-dir-worker.js deleted file mode 100644 index fe72af7416..0000000000 --- a/test/parallel/test-cpu-prof-dir-worker.js +++ /dev/null @@ -1,55 +0,0 @@ -'use strict'; - -// This tests that --cpu-prof-dir works for workers. - -const common = require('../common'); -const fixtures = require('../common/fixtures'); -common.skipIfInspectorDisabled(); - -const assert = require('assert'); -const fs = require('fs'); -const path = require('path'); -const { spawnSync } = require('child_process'); - -const tmpdir = require('../common/tmpdir'); -const { - getCpuProfiles, - kCpuProfInterval, - env, - getFrames -} = require('../common/cpu-prof'); - -// --cpu-prof-dir with worker -{ - tmpdir.refresh(); - const output = spawnSync(process.execPath, [ - '--cpu-prof-interval', - kCpuProfInterval, - '--cpu-prof-dir', - 'prof', - '--cpu-prof', - fixtures.path('workload', 'fibonacci-worker.js'), - ], { - cwd: tmpdir.path, - env - }); - if (output.status !== 0) { - console.log(output.stderr.toString()); - } - assert.strictEqual(output.status, 0); - const dir = path.join(tmpdir.path, 'prof'); - assert(fs.existsSync(dir)); - const profiles = getCpuProfiles(dir); - assert.strictEqual(profiles.length, 2); - const profile1 = getFrames(profiles[0], 'fibonacci.js'); - const profile2 = getFrames(profiles[1], 'fibonacci.js'); - if (profile1.frames.length === 0 && profile2.frames.length === 0) { - // Show native debug output and the profile for debugging. - console.log(output.stderr.toString()); - console.log('CPU path: ', profiles[0]); - console.log(profile1.nodes); - console.log('CPU path: ', profiles[1]); - console.log(profile2.nodes); - } - assert(profile1.frames.length > 0 || profile2.frames.length > 0); -} diff --git a/test/parallel/test-cpu-prof-drained.js b/test/parallel/test-cpu-prof-drained.js deleted file mode 100644 index 5be4d1a919..0000000000 --- a/test/parallel/test-cpu-prof-drained.js +++ /dev/null @@ -1,40 +0,0 @@ -'use strict'; - -// This tests that --cpu-prof generates CPU profile when event -// loop is drained. -// TODO(joyeecheung): share the fixtures with v8 coverage tests - -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 { - getCpuProfiles, - kCpuProfInterval, - env, - verifyFrames -} = require('../common/cpu-prof'); - -{ - tmpdir.refresh(); - const output = spawnSync(process.execPath, [ - '--cpu-prof', - '--cpu-prof-interval', - kCpuProfInterval, - fixtures.path('workload', 'fibonacci.js'), - ], { - cwd: tmpdir.path, - env - }); - if (output.status !== 0) { - console.log(output.stderr.toString()); - } - assert.strictEqual(output.status, 0); - const profiles = getCpuProfiles(tmpdir.path); - assert.strictEqual(profiles.length, 1); - verifyFrames(output, profiles[0], 'fibonacci.js'); -} diff --git a/test/parallel/test-cpu-prof-exit.js b/test/parallel/test-cpu-prof-exit.js deleted file mode 100644 index 34b1acff4b..0000000000 --- a/test/parallel/test-cpu-prof-exit.js +++ /dev/null @@ -1,39 +0,0 @@ -'use strict'; - -// This tests that --cpu-prof generates CPU profile when -// process.exit(55) exits the process. - -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 { - getCpuProfiles, - kCpuProfInterval, - env, - verifyFrames -} = require('../common/cpu-prof'); - -{ - tmpdir.refresh(); - const output = spawnSync(process.execPath, [ - '--cpu-prof', - '--cpu-prof-interval', - kCpuProfInterval, - fixtures.path('workload', 'fibonacci-exit.js'), - ], { - cwd: tmpdir.path, - env - }); - if (output.status !== 55) { - console.log(output.stderr.toString()); - } - assert.strictEqual(output.status, 55); - const profiles = getCpuProfiles(tmpdir.path); - assert.strictEqual(profiles.length, 1); - verifyFrames(output, profiles[0], 'fibonacci-exit.js'); -} diff --git a/test/parallel/test-cpu-prof-invalid-options.js b/test/parallel/test-cpu-prof-invalid-options.js deleted file mode 100644 index b5f7619cda..0000000000 --- a/test/parallel/test-cpu-prof-invalid-options.js +++ /dev/null @@ -1,79 +0,0 @@ -'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 -{ - tmpdir.refresh(); - const output = spawnSync(process.execPath, [ - '--cpu-prof-interval', - kCpuProfInterval, - 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`); -} diff --git a/test/parallel/test-cpu-prof-kill.js b/test/parallel/test-cpu-prof-kill.js deleted file mode 100644 index cee66a6256..0000000000 --- a/test/parallel/test-cpu-prof-kill.js +++ /dev/null @@ -1,41 +0,0 @@ -'use strict'; - -// This tests that --cpu-prof generates CPU profile when -// process.kill(process.pid, "SIGINT"); exits the process. - -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 { - getCpuProfiles, - kCpuProfInterval, - env, - verifyFrames -} = require('../common/cpu-prof'); - -{ - tmpdir.refresh(); - const output = spawnSync(process.execPath, [ - '--cpu-prof', - '--cpu-prof-interval', - kCpuProfInterval, - fixtures.path('workload', 'fibonacci-sigint.js'), - ], { - cwd: tmpdir.path, - env - }); - if (!common.isWindows) { - if (output.signal !== 'SIGINT') { - console.log(output.stderr.toString()); - } - assert.strictEqual(output.signal, 'SIGINT'); - } - const profiles = getCpuProfiles(tmpdir.path); - assert.strictEqual(profiles.length, 1); - verifyFrames(output, profiles[0], 'fibonacci-sigint.js'); -} diff --git a/test/parallel/test-cpu-prof-name.js b/test/parallel/test-cpu-prof-name.js deleted file mode 100644 index 58d9a0ec15..0000000000 --- a/test/parallel/test-cpu-prof-name.js +++ /dev/null @@ -1,44 +0,0 @@ -'use strict'; - -// This tests that --cpu-prof-name can be used to specify the -// name of the generated CPU profile. - -const common = require('../common'); -const fixtures = require('../common/fixtures'); -common.skipIfInspectorDisabled(); - -const assert = require('assert'); -const path = require('path'); -const { spawnSync } = require('child_process'); - -const tmpdir = require('../common/tmpdir'); -const { - getCpuProfiles, - kCpuProfInterval, - env, - verifyFrames -} = require('../common/cpu-prof'); - -// --cpu-prof-name -{ - tmpdir.refresh(); - const file = path.join(tmpdir.path, 'test.cpuprofile'); - const output = spawnSync(process.execPath, [ - '--cpu-prof', - '--cpu-prof-interval', - kCpuProfInterval, - '--cpu-prof-name', - 'test.cpuprofile', - fixtures.path('workload', 'fibonacci.js'), - ], { - cwd: tmpdir.path, - env - }); - if (output.status !== 0) { - console.log(output.stderr.toString()); - } - assert.strictEqual(output.status, 0); - const profiles = getCpuProfiles(tmpdir.path); - assert.deepStrictEqual(profiles, [file]); - verifyFrames(output, file, 'fibonacci.js'); -} diff --git a/test/parallel/test-cpu-prof-worker-argv.js b/test/parallel/test-cpu-prof-worker-argv.js deleted file mode 100644 index ad88a2eeb0..0000000000 --- a/test/parallel/test-cpu-prof-worker-argv.js +++ /dev/null @@ -1,38 +0,0 @@ -'use strict'; - -// This tests that --cpu-prof generates CPU profile from worker -// when execArgv is set. - -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 { - getCpuProfiles, - kCpuProfInterval, - verifyFrames -} = require('../common/cpu-prof'); - -{ - tmpdir.refresh(); - const output = spawnSync(process.execPath, [ - fixtures.path('workload', 'fibonacci-worker-argv.js'), - ], { - cwd: tmpdir.path, - env: { - ...process.env, - CPU_PROF_INTERVAL: kCpuProfInterval - } - }); - if (output.status !== 0) { - console.log(output.stderr.toString()); - } - assert.strictEqual(output.status, 0); - const profiles = getCpuProfiles(tmpdir.path); - assert.strictEqual(profiles.length, 1); - verifyFrames(output, profiles[0], 'fibonacci.js'); -} diff --git a/test/sequential/test-cpu-prof-default.js b/test/sequential/test-cpu-prof-default.js new file mode 100644 index 0000000000..12c4bc05bb --- /dev/null +++ b/test/sequential/test-cpu-prof-default.js @@ -0,0 +1,36 @@ +'use strict'; + +// Test --cpu-prof without --cpu-prof-interval. Here we just verify that +// we manage to generate a profile since it's hard to tell whether we +// can sample our target function with the default sampling rate across +// different platforms and machine configurations. + +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 { + getCpuProfiles, + env +} = require('../common/cpu-prof'); + +{ + tmpdir.refresh(); + const output = spawnSync(process.execPath, [ + '--cpu-prof', + fixtures.path('workload', 'fibonacci.js'), + ], { + cwd: tmpdir.path, + env + }); + if (output.status !== 0) { + console.log(output.stderr.toString()); + } + assert.strictEqual(output.status, 0); + const profiles = getCpuProfiles(tmpdir.path); + assert.strictEqual(profiles.length, 1); +} diff --git a/test/sequential/test-cpu-prof-dir-absolute.js b/test/sequential/test-cpu-prof-dir-absolute.js new file mode 100644 index 0000000000..ad0842dbc4 --- /dev/null +++ b/test/sequential/test-cpu-prof-dir-absolute.js @@ -0,0 +1,45 @@ +'use strict'; + +// This tests that relative --cpu-prof-dir works. + +const common = require('../common'); +const fixtures = require('../common/fixtures'); +common.skipIfInspectorDisabled(); + +const assert = require('assert'); +const fs = require('fs'); +const path = require('path'); +const { spawnSync } = require('child_process'); + +const tmpdir = require('../common/tmpdir'); +const { + getCpuProfiles, + kCpuProfInterval, + env, + verifyFrames +} = require('../common/cpu-prof'); + +// relative --cpu-prof-dir +{ + tmpdir.refresh(); + const dir = path.join(tmpdir.path, 'prof'); + const output = spawnSync(process.execPath, [ + '--cpu-prof', + '--cpu-prof-interval', + kCpuProfInterval, + '--cpu-prof-dir', + dir, + fixtures.path('workload', 'fibonacci.js'), + ], { + cwd: tmpdir.path, + env + }); + if (output.status !== 0) { + console.log(output.stderr.toString()); + } + assert.strictEqual(output.status, 0); + assert(fs.existsSync(dir)); + const profiles = getCpuProfiles(dir); + assert.strictEqual(profiles.length, 1); + verifyFrames(output, profiles[0], 'fibonacci.js'); +} diff --git a/test/sequential/test-cpu-prof-dir-and-name.js b/test/sequential/test-cpu-prof-dir-and-name.js new file mode 100644 index 0000000000..7ce775ebc1 --- /dev/null +++ b/test/sequential/test-cpu-prof-dir-and-name.js @@ -0,0 +1,47 @@ +'use strict'; + +// This tests that --cpu-prof-dir and --cpu-prof-name works together. + +const common = require('../common'); +const fixtures = require('../common/fixtures'); +common.skipIfInspectorDisabled(); + +const assert = require('assert'); +const fs = require('fs'); +const path = require('path'); +const { spawnSync } = require('child_process'); + +const tmpdir = require('../common/tmpdir'); +const { + getCpuProfiles, + kCpuProfInterval, + env, + verifyFrames +} = require('../common/cpu-prof'); + +{ + tmpdir.refresh(); + const dir = path.join(tmpdir.path, 'prof'); + const file = path.join(dir, 'test.cpuprofile'); + const output = spawnSync(process.execPath, [ + '--cpu-prof', + '--cpu-prof-interval', + kCpuProfInterval, + '--cpu-prof-name', + 'test.cpuprofile', + '--cpu-prof-dir', + dir, + fixtures.path('workload', 'fibonacci.js'), + ], { + cwd: tmpdir.path, + env + }); + if (output.status !== 0) { + console.log(output.stderr.toString()); + } + assert.strictEqual(output.status, 0); + assert(fs.existsSync(dir)); + const profiles = getCpuProfiles(dir); + assert.deepStrictEqual(profiles, [file]); + verifyFrames(output, file, 'fibonacci.js'); +} diff --git a/test/sequential/test-cpu-prof-dir-relative.js b/test/sequential/test-cpu-prof-dir-relative.js new file mode 100644 index 0000000000..2d679959ef --- /dev/null +++ b/test/sequential/test-cpu-prof-dir-relative.js @@ -0,0 +1,45 @@ +'use strict'; + +// This tests that relative --cpu-prof-dir works. + +const common = require('../common'); +const fixtures = require('../common/fixtures'); +common.skipIfInspectorDisabled(); + +const assert = require('assert'); +const fs = require('fs'); +const path = require('path'); +const { spawnSync } = require('child_process'); + +const tmpdir = require('../common/tmpdir'); +const { + getCpuProfiles, + kCpuProfInterval, + env, + verifyFrames +} = require('../common/cpu-prof'); + +// relative --cpu-prof-dir +{ + tmpdir.refresh(); + const output = spawnSync(process.execPath, [ + '--cpu-prof', + '--cpu-prof-interval', + kCpuProfInterval, + '--cpu-prof-dir', + 'prof', + fixtures.path('workload', 'fibonacci.js'), + ], { + cwd: tmpdir.path, + env + }); + if (output.status !== 0) { + console.log(output.stderr.toString()); + } + assert.strictEqual(output.status, 0); + const dir = path.join(tmpdir.path, 'prof'); + assert(fs.existsSync(dir)); + const profiles = getCpuProfiles(dir); + assert.strictEqual(profiles.length, 1); + verifyFrames(output, profiles[0], 'fibonacci.js'); +} diff --git a/test/sequential/test-cpu-prof-dir-worker.js b/test/sequential/test-cpu-prof-dir-worker.js new file mode 100644 index 0000000000..fe72af7416 --- /dev/null +++ b/test/sequential/test-cpu-prof-dir-worker.js @@ -0,0 +1,55 @@ +'use strict'; + +// This tests that --cpu-prof-dir works for workers. + +const common = require('../common'); +const fixtures = require('../common/fixtures'); +common.skipIfInspectorDisabled(); + +const assert = require('assert'); +const fs = require('fs'); +const path = require('path'); +const { spawnSync } = require('child_process'); + +const tmpdir = require('../common/tmpdir'); +const { + getCpuProfiles, + kCpuProfInterval, + env, + getFrames +} = require('../common/cpu-prof'); + +// --cpu-prof-dir with worker +{ + tmpdir.refresh(); + const output = spawnSync(process.execPath, [ + '--cpu-prof-interval', + kCpuProfInterval, + '--cpu-prof-dir', + 'prof', + '--cpu-prof', + fixtures.path('workload', 'fibonacci-worker.js'), + ], { + cwd: tmpdir.path, + env + }); + if (output.status !== 0) { + console.log(output.stderr.toString()); + } + assert.strictEqual(output.status, 0); + const dir = path.join(tmpdir.path, 'prof'); + assert(fs.existsSync(dir)); + const profiles = getCpuProfiles(dir); + assert.strictEqual(profiles.length, 2); + const profile1 = getFrames(profiles[0], 'fibonacci.js'); + const profile2 = getFrames(profiles[1], 'fibonacci.js'); + if (profile1.frames.length === 0 && profile2.frames.length === 0) { + // Show native debug output and the profile for debugging. + console.log(output.stderr.toString()); + console.log('CPU path: ', profiles[0]); + console.log(profile1.nodes); + console.log('CPU path: ', profiles[1]); + console.log(profile2.nodes); + } + assert(profile1.frames.length > 0 || profile2.frames.length > 0); +} diff --git a/test/sequential/test-cpu-prof-drained.js b/test/sequential/test-cpu-prof-drained.js new file mode 100644 index 0000000000..5be4d1a919 --- /dev/null +++ b/test/sequential/test-cpu-prof-drained.js @@ -0,0 +1,40 @@ +'use strict'; + +// This tests that --cpu-prof generates CPU profile when event +// loop is drained. +// TODO(joyeecheung): share the fixtures with v8 coverage tests + +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 { + getCpuProfiles, + kCpuProfInterval, + env, + verifyFrames +} = require('../common/cpu-prof'); + +{ + tmpdir.refresh(); + const output = spawnSync(process.execPath, [ + '--cpu-prof', + '--cpu-prof-interval', + kCpuProfInterval, + fixtures.path('workload', 'fibonacci.js'), + ], { + cwd: tmpdir.path, + env + }); + if (output.status !== 0) { + console.log(output.stderr.toString()); + } + assert.strictEqual(output.status, 0); + const profiles = getCpuProfiles(tmpdir.path); + assert.strictEqual(profiles.length, 1); + verifyFrames(output, profiles[0], 'fibonacci.js'); +} diff --git a/test/sequential/test-cpu-prof-exit.js b/test/sequential/test-cpu-prof-exit.js new file mode 100644 index 0000000000..34b1acff4b --- /dev/null +++ b/test/sequential/test-cpu-prof-exit.js @@ -0,0 +1,39 @@ +'use strict'; + +// This tests that --cpu-prof generates CPU profile when +// process.exit(55) exits the process. + +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 { + getCpuProfiles, + kCpuProfInterval, + env, + verifyFrames +} = require('../common/cpu-prof'); + +{ + tmpdir.refresh(); + const output = spawnSync(process.execPath, [ + '--cpu-prof', + '--cpu-prof-interval', + kCpuProfInterval, + fixtures.path('workload', 'fibonacci-exit.js'), + ], { + cwd: tmpdir.path, + env + }); + if (output.status !== 55) { + console.log(output.stderr.toString()); + } + assert.strictEqual(output.status, 55); + const profiles = getCpuProfiles(tmpdir.path); + assert.strictEqual(profiles.length, 1); + verifyFrames(output, profiles[0], 'fibonacci-exit.js'); +} diff --git a/test/sequential/test-cpu-prof-invalid-options.js b/test/sequential/test-cpu-prof-invalid-options.js new file mode 100644 index 0000000000..b5f7619cda --- /dev/null +++ b/test/sequential/test-cpu-prof-invalid-options.js @@ -0,0 +1,79 @@ +'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 +{ + tmpdir.refresh(); + const output = spawnSync(process.execPath, [ + '--cpu-prof-interval', + kCpuProfInterval, + 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`); +} diff --git a/test/sequential/test-cpu-prof-kill.js b/test/sequential/test-cpu-prof-kill.js new file mode 100644 index 0000000000..cee66a6256 --- /dev/null +++ b/test/sequential/test-cpu-prof-kill.js @@ -0,0 +1,41 @@ +'use strict'; + +// This tests that --cpu-prof generates CPU profile when +// process.kill(process.pid, "SIGINT"); exits the process. + +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 { + getCpuProfiles, + kCpuProfInterval, + env, + verifyFrames +} = require('../common/cpu-prof'); + +{ + tmpdir.refresh(); + const output = spawnSync(process.execPath, [ + '--cpu-prof', + '--cpu-prof-interval', + kCpuProfInterval, + fixtures.path('workload', 'fibonacci-sigint.js'), + ], { + cwd: tmpdir.path, + env + }); + if (!common.isWindows) { + if (output.signal !== 'SIGINT') { + console.log(output.stderr.toString()); + } + assert.strictEqual(output.signal, 'SIGINT'); + } + const profiles = getCpuProfiles(tmpdir.path); + assert.strictEqual(profiles.length, 1); + verifyFrames(output, profiles[0], 'fibonacci-sigint.js'); +} diff --git a/test/sequential/test-cpu-prof-name.js b/test/sequential/test-cpu-prof-name.js new file mode 100644 index 0000000000..58d9a0ec15 --- /dev/null +++ b/test/sequential/test-cpu-prof-name.js @@ -0,0 +1,44 @@ +'use strict'; + +// This tests that --cpu-prof-name can be used to specify the +// name of the generated CPU profile. + +const common = require('../common'); +const fixtures = require('../common/fixtures'); +common.skipIfInspectorDisabled(); + +const assert = require('assert'); +const path = require('path'); +const { spawnSync } = require('child_process'); + +const tmpdir = require('../common/tmpdir'); +const { + getCpuProfiles, + kCpuProfInterval, + env, + verifyFrames +} = require('../common/cpu-prof'); + +// --cpu-prof-name +{ + tmpdir.refresh(); + const file = path.join(tmpdir.path, 'test.cpuprofile'); + const output = spawnSync(process.execPath, [ + '--cpu-prof', + '--cpu-prof-interval', + kCpuProfInterval, + '--cpu-prof-name', + 'test.cpuprofile', + fixtures.path('workload', 'fibonacci.js'), + ], { + cwd: tmpdir.path, + env + }); + if (output.status !== 0) { + console.log(output.stderr.toString()); + } + assert.strictEqual(output.status, 0); + const profiles = getCpuProfiles(tmpdir.path); + assert.deepStrictEqual(profiles, [file]); + verifyFrames(output, file, 'fibonacci.js'); +} diff --git a/test/sequential/test-cpu-prof-worker-argv.js b/test/sequential/test-cpu-prof-worker-argv.js new file mode 100644 index 0000000000..ad88a2eeb0 --- /dev/null +++ b/test/sequential/test-cpu-prof-worker-argv.js @@ -0,0 +1,38 @@ +'use strict'; + +// This tests that --cpu-prof generates CPU profile from worker +// when execArgv is set. + +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 { + getCpuProfiles, + kCpuProfInterval, + verifyFrames +} = require('../common/cpu-prof'); + +{ + tmpdir.refresh(); + const output = spawnSync(process.execPath, [ + fixtures.path('workload', 'fibonacci-worker-argv.js'), + ], { + cwd: tmpdir.path, + env: { + ...process.env, + CPU_PROF_INTERVAL: kCpuProfInterval + } + }); + if (output.status !== 0) { + console.log(output.stderr.toString()); + } + assert.strictEqual(output.status, 0); + const profiles = getCpuProfiles(tmpdir.path); + assert.strictEqual(profiles.length, 1); + verifyFrames(output, profiles[0], 'fibonacci.js'); +} -- cgit v1.2.3