summaryrefslogtreecommitdiff
path: root/test/v8-updates
diff options
context:
space:
mode:
authorMatheus Marchini <matheus@sthima.com>2018-05-16 10:56:13 -0300
committerMatheus Marchini <matheus@sthima.com>2018-06-06 11:10:19 -0700
commit227ca87abb9c3a30e13152426c0efc442d908345 (patch)
tree13be42fce9d45a71ff79b06189ac55329377a2b5 /test/v8-updates
parente1fc52d9e6aba7005d1c1017b4825b307ec3859e (diff)
downloadnode-new-227ca87abb9c3a30e13152426c0efc442d908345.tar.gz
test: add test for Linux perf
This commit adds a test to validate if Linux perf is working correctly on Node.js. The test is marked as flaky because its intention is to let us know when changes on V8 potentially broke Linux perf, so we can fix it before a new version of V8 lands on Node.js master. PR-URL: https://github.com/nodejs/node/pull/20783 Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Diffstat (limited to 'test/v8-updates')
-rw-r--r--test/v8-updates/test-linux-perf.js81
1 files changed, 81 insertions, 0 deletions
diff --git a/test/v8-updates/test-linux-perf.js b/test/v8-updates/test-linux-perf.js
new file mode 100644
index 0000000000..0a7f199e04
--- /dev/null
+++ b/test/v8-updates/test-linux-perf.js
@@ -0,0 +1,81 @@
+'use strict';
+
+// This test verifies that JavaScript functions are being correctly sampled by
+// Linux perf. The test runs a JavaScript script, sampling the execution with
+// Linux perf. It then uses `perf script` to generate a human-readable output,
+// and uses regular expressions to find samples of the functions defined in
+// `fixtures/linux-perf.js`.
+
+// NOTE (mmarchini): this test is meant to run only on Linux machines with Linux
+// perf installed. It will skip if those criteria are not met.
+
+const common = require('../common');
+if (!common.hasCrypto)
+ common.skip('missing crypto');
+
+const assert = require('assert');
+const { spawnSync } = require('child_process');
+const fixtures = require('../common/fixtures');
+const tmpdir = require('../common/tmpdir');
+tmpdir.refresh();
+
+if (process.config.variables.node_shared)
+ common.skip("can't test Linux perf with shared libraries yet");
+
+const perfArgs = [
+ 'record',
+ '-F500',
+ '-g',
+ '--',
+ process.execPath,
+ '--perf-basic-prof',
+ '--interpreted-frames-native-stack',
+ '--no-turbo-inlining', // Otherwise simple functions might get inlined.
+ fixtures.path('linux-perf.js'),
+];
+
+const perfScriptArgs = [
+ 'script',
+];
+
+const options = {
+ cwd: tmpdir.path,
+ encoding: 'utf-8',
+};
+
+if (!common.isLinux)
+ common.skip('only testing Linux for now');
+
+const perf = spawnSync('perf', perfArgs, options);
+
+if (perf.error && perf.error.errno === 'ENOENT')
+ common.skip('perf not found on system');
+
+if (perf.status !== 0) {
+ common.skip(`Failed to execute perf: ${perf.stderr}`);
+}
+
+const perfScript = spawnSync('perf', perfScriptArgs, options);
+
+if (perf.error)
+ common.skip(`perf script aborted: ${perf.error.errno}`);
+
+if (perfScript.status !== 0) {
+ common.skip(`Failed to execute perf script: ${perfScript.stderr}`);
+}
+
+const interpretedFunctionOneRe = /InterpretedFunction:functionOne/;
+const compiledFunctionOneRe = /LazyCompile:\*functionOne/;
+const interpretedFunctionTwoRe = /InterpretedFunction:functionTwo/;
+const compiledFunctionTwoRe = /LazyCompile:\*functionTwo/;
+
+const output = perfScript.stdout;
+
+assert.ok(output.match(interpretedFunctionOneRe),
+ "Couldn't find interpreted functionOne()");
+assert.ok(output.match(compiledFunctionOneRe),
+ "Couldn't find compiled functionOne()");
+assert.ok(output.match(interpretedFunctionTwoRe),
+ "Couldn't find interpreted functionTwo()");
+assert.ok(output.match(compiledFunctionTwoRe),
+ "Couldn't find compiled functionTwo");