Browse Source

test: create shared runBenchmark function

Mostly shared/duplicated logic between all benchmark test files, so
creating a new common module to store it.

PR-URL: https://github.com/nodejs/node/pull/15004
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
canary-base
Jon Moss 7 years ago
committed by Refael Ackermann
parent
commit
640b20616d
No known key found for this signature in database GPG Key ID: CD704BD80FDDDB64
  1. 12
      test/common/README.md
  2. 30
      test/common/benchmark.js
  3. 18
      test/parallel/test-benchmark-arrays.js
  4. 19
      test/parallel/test-benchmark-cluster.js
  5. 41
      test/parallel/test-benchmark-crypto.js
  6. 21
      test/parallel/test-benchmark-dns.js
  7. 18
      test/parallel/test-benchmark-domain.js
  8. 17
      test/parallel/test-benchmark-events.js
  9. 17
      test/parallel/test-benchmark-os.js
  10. 30
      test/parallel/test-benchmark-path.js
  11. 26
      test/parallel/test-benchmark-process.js
  12. 30
      test/parallel/test-benchmark-timers.js
  13. 28
      test/parallel/test-benchmark-zlib.js
  14. 37
      test/sequential/test-benchmark-child-process.js
  15. 44
      test/sequential/test-benchmark-http.js
  16. 28
      test/sequential/test-benchmark-net.js

12
test/common/README.md

@ -4,9 +4,21 @@ This directory contains modules used to test the Node.js implementation.
## Table of Contents ## Table of Contents
* [Benchmark module](#benchmark-module)
* [Common module API](#common-module-api) * [Common module API](#common-module-api)
* [WPT module](#wpt-module) * [WPT module](#wpt-module)
## Benchmark Module
The `benchmark` module is used by tests to run benchmarks.
### runBenchmark(name, args, env)
* `name` [&lt;String>] Name of benchmark suite to be run.
* `args` [&lt;Array>] Array of environment variable key/value pairs (ex:
`n=1`) to be applied via `--set`.
* `env` [&lt;Object>] Environment variables to be applied during the run.
## Common Module API ## Common Module API
The `common` module is used by tests for consistency across repeated The `common` module is used by tests for consistency across repeated

30
test/common/benchmark.js

@ -0,0 +1,30 @@
/* eslint-disable required-modules */
'use strict';
const assert = require('assert');
const fork = require('child_process').fork;
const path = require('path');
const runjs = path.join(__dirname, '..', '..', 'benchmark', 'run.js');
function runBenchmark(name, args, env) {
const argv = [];
for (let i = 0; i < args.length; i++) {
argv.push('--set');
argv.push(args[i]);
}
argv.push(name);
const mergedEnv = Object.assign({}, process.env, env);
const child = fork(runjs, argv, { env: mergedEnv });
child.on('exit', (code, signal) => {
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
});
}
module.exports = runBenchmark;

18
test/parallel/test-benchmark-arrays.js

@ -2,20 +2,6 @@
require('../common'); require('../common');
// Minimal test for arrays benchmarks. This makes sure the benchmarks aren't const runBenchmark = require('../common/benchmark');
// horribly broken but nothing more than that.
const assert = require('assert'); runBenchmark('arrays', ['n=1', 'type=Array']);
const fork = require('child_process').fork;
const path = require('path');
const runjs = path.join(__dirname, '..', '..', 'benchmark', 'run.js');
const argv = ['--set', 'n=1',
'--set', 'type=Array',
'arrays'];
const child = fork(runjs, argv);
child.on('exit', (code, signal) => {
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
});

19
test/parallel/test-benchmark-cluster.js

@ -2,21 +2,6 @@
require('../common'); require('../common');
// Minimal test for cluster benchmarks. This makes sure the benchmarks aren't const runBenchmark = require('../common/benchmark');
// horribly broken but nothing more than that.
const assert = require('assert'); runBenchmark('cluster', ['n=1', 'payload=string', 'sendsPerBroadcast=1']);
const fork = require('child_process').fork;
const path = require('path');
const runjs = path.join(__dirname, '..', '..', 'benchmark', 'run.js');
const argv = ['--set', 'n=1',
'--set', 'payload=string',
'--set', 'sendsPerBroadcast=1',
'cluster'];
const child = fork(runjs, argv);
child.on('exit', (code, signal) => {
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
});

41
test/parallel/test-benchmark-crypto.js

@ -8,29 +8,18 @@ if (!common.hasCrypto)
if (common.hasFipsCrypto) if (common.hasFipsCrypto)
common.skip('some benchmarks are FIPS-incompatible'); common.skip('some benchmarks are FIPS-incompatible');
// Minimal test for crypto benchmarks. This makes sure the benchmarks aren't const runBenchmark = require('../common/benchmark');
// horribly broken but nothing more than that.
runBenchmark('crypto',
const assert = require('assert'); [
const fork = require('child_process').fork; 'n=1',
const path = require('path'); 'algo=sha256',
'api=stream',
const runjs = path.join(__dirname, '..', '..', 'benchmark', 'run.js'); 'keylen=1024',
const argv = ['--set', 'algo=sha256', 'len=1',
'--set', 'api=stream', 'out=buffer',
'--set', 'keylen=1024', 'type=buf',
'--set', 'len=1', 'v=crypto',
'--set', 'n=1', 'writes=1'
'--set', 'out=buffer', ],
'--set', 'type=buf', { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 });
'--set', 'v=crypto',
'--set', 'writes=1',
'crypto'];
const child = fork(runjs, argv, { env: Object.assign({}, process.env, {
NODEJS_BENCHMARK_ZERO_ALLOWED: 1 }) });
child.on('exit', (code, signal) => {
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
});

21
test/parallel/test-benchmark-dns.js

@ -2,26 +2,9 @@
require('../common'); require('../common');
// Minimal test for dns benchmarks. This makes sure the benchmarks aren't const runBenchmark = require('../common/benchmark');
// horribly broken but nothing more than that.
const assert = require('assert');
const fork = require('child_process').fork;
const path = require('path');
const runjs = path.join(__dirname, '..', '..', 'benchmark', 'run.js');
const env = Object.assign({}, process.env, const env = Object.assign({}, process.env,
{ NODEJS_BENCHMARK_ZERO_ALLOWED: 1 }); { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 });
const child = fork(runjs, runBenchmark('dns', ['n=1', 'all=false', 'name=127.0.0.1'], env);
['--set', 'n=1',
'--set', 'all=false',
'--set', 'name=127.0.0.1',
'dns'],
{ env });
child.on('exit', (code, signal) => {
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
});

18
test/parallel/test-benchmark-domain.js

@ -2,20 +2,6 @@
require('../common'); require('../common');
// Minimal test for domain benchmarks. This makes sure the benchmarks aren't const runBenchmark = require('../common/benchmark');
// horribly broken but nothing more than that.
const assert = require('assert'); runBenchmark('domain', ['n=1', 'arguments=0']);
const fork = require('child_process').fork;
const path = require('path');
const runjs = path.join(__dirname, '..', '..', 'benchmark', 'run.js');
const argv = ['--set', 'arguments=0',
'--set', 'n=1',
'domain'];
const child = fork(runjs, argv);
child.on('exit', (code, signal) => {
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
});

17
test/parallel/test-benchmark-events.js

@ -2,19 +2,6 @@
require('../common'); require('../common');
// Minimal test for events benchmarks. This makes sure the benchmarks aren't const runBenchmark = require('../common/benchmark');
// horribly broken but nothing more than that.
const assert = require('assert'); runBenchmark('events', ['n=1']);
const fork = require('child_process').fork;
const path = require('path');
const runjs = path.join(__dirname, '..', '..', 'benchmark', 'run.js');
const argv = ['--set', 'n=1',
'events'];
const child = fork(runjs, argv);
child.on('exit', (code, signal) => {
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
});

17
test/parallel/test-benchmark-os.js

@ -2,19 +2,6 @@
require('../common'); require('../common');
// Minimal test for os benchmarks. This makes sure the benchmarks aren't const runBenchmark = require('../common/benchmark');
// horribly broken but nothing more than that.
const assert = require('assert'); runBenchmark('os', ['n=1']);
const fork = require('child_process').fork;
const path = require('path');
const runjs = path.join(__dirname, '..', '..', 'benchmark', 'run.js');
const argv = ['--set', 'n=1',
'os'];
const child = fork(runjs, argv);
child.on('exit', (code, signal) => {
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
});

30
test/parallel/test-benchmark-path.js

@ -2,23 +2,13 @@
require('../common'); require('../common');
// Minimal test for path benchmarks. This makes sure the benchmarks aren't const runBenchmark = require('../common/benchmark');
// horribly broken but nothing more than that.
runBenchmark('path',
const assert = require('assert'); [
const fork = require('child_process').fork; 'n=1',
const path = require('path'); 'path=',
'pathext=',
const runjs = path.join(__dirname, '..', '..', 'benchmark', 'run.js'); 'paths=',
const argv = ['--set', 'n=1', 'props='
'--set', 'path=', ]);
'--set', 'pathext=',
'--set', 'paths=',
'--set', 'props=',
'path'];
const child = fork(runjs, argv);
child.on('exit', (code, signal) => {
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
});

26
test/parallel/test-benchmark-process.js

@ -2,21 +2,11 @@
require('../common'); require('../common');
// Minimal test for process benchmarks. This makes sure the benchmarks aren't const runBenchmark = require('../common/benchmark');
// horribly broken but nothing more than that.
runBenchmark('process',
const assert = require('assert'); [
const fork = require('child_process').fork; 'millions=0.000001',
const path = require('path'); 'n=1',
'type=raw'
const runjs = path.join(__dirname, '..', '..', 'benchmark', 'run.js'); ]);
const argv = ['--set', 'millions=0.000001',
'--set', 'n=1',
'--set', 'type=raw',
'process'];
const child = fork(runjs, argv);
child.on('exit', (code, signal) => {
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
});

30
test/parallel/test-benchmark-timers.js

@ -2,24 +2,12 @@
require('../common'); require('../common');
// Minimal test for timers benchmarks. This makes sure the benchmarks aren't const runBenchmark = require('../common/benchmark');
// horribly broken but nothing more than that.
runBenchmark('timers',
const assert = require('assert'); [
const fork = require('child_process').fork; 'type=depth',
const path = require('path'); 'millions=0.000001',
'thousands=0.001'
const runjs = path.join(__dirname, '..', '..', 'benchmark', 'run.js'); ],
const argv = ['--set', 'type=depth', { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 });
'--set', 'millions=0.000001',
'--set', 'thousands=0.001',
'timers'];
const env = Object.assign({}, process.env,
{ NODEJS_BENCHMARK_ZERO_ALLOWED: 1 });
const child = fork(runjs, argv, { env });
child.on('exit', (code, signal) => {
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
});

28
test/parallel/test-benchmark-zlib.js

@ -2,22 +2,12 @@
require('../common'); require('../common');
// Minimal test for zlib benchmarks. This makes sure the benchmarks aren't const runBenchmark = require('../common/benchmark');
// horribly broken but nothing more than that.
runBenchmark('zlib',
const assert = require('assert'); [
const fork = require('child_process').fork; 'method=deflate',
const path = require('path'); 'n=1',
'options=true',
const runjs = path.join(__dirname, '..', '..', 'benchmark', 'run.js'); 'type=Deflate'
const argv = ['--set', 'method=deflate', ]);
'--set', 'n=1',
'--set', 'options=true',
'--set', 'type=Deflate',
'zlib'];
const child = fork(runjs, argv);
child.on('exit', (code, signal) => {
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
});

37
test/sequential/test-benchmark-child-process.js

@ -2,29 +2,14 @@
require('../common'); require('../common');
const assert = require('assert'); const runBenchmark = require('../common/benchmark');
const fork = require('child_process').fork;
const path = require('path'); runBenchmark('child_process',
[
const runjs = path.join(__dirname, '..', '..', 'benchmark', 'run.js'); 'dur=0',
'n=1',
const env = Object.assign({}, process.env, 'len=1',
{ NODEJS_BENCHMARK_ZERO_ALLOWED: 1 }); 'params=1',
'methodName=execSync',
const child = fork( ],
runjs, { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 });
[
'--set', 'dur=0',
'--set', 'n=1',
'--set', 'len=1',
'--set', 'params=1',
'--set', 'methodName=execSync',
'child_process'
],
{ env }
);
child.on('exit', (code, signal) => {
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
});

44
test/sequential/test-benchmark-http.js

@ -5,35 +5,23 @@ const common = require('../common');
if (!common.enoughTestMem) if (!common.enoughTestMem)
common.skip('Insufficient memory for HTTP benchmark test'); common.skip('Insufficient memory for HTTP benchmark test');
// Minimal test for http benchmarks. This makes sure the benchmarks aren't
// horribly broken but nothing more than that.
// Because the http benchmarks use hardcoded ports, this should be in sequential // Because the http benchmarks use hardcoded ports, this should be in sequential
// rather than parallel to make sure it does not conflict with tests that choose // rather than parallel to make sure it does not conflict with tests that choose
// random available ports. // random available ports.
const assert = require('assert'); const runBenchmark = require('../common/benchmark');
const fork = require('child_process').fork;
const path = require('path'); runBenchmark('http',
[
const runjs = path.join(__dirname, '..', '..', 'benchmark', 'run.js'); 'benchmarker=test-double',
'c=1',
const env = Object.assign({}, process.env, 'chunkedEnc=true',
{ NODEJS_BENCHMARK_ZERO_ALLOWED: 1 }); 'chunks=0',
'dur=0.1',
const child = fork(runjs, ['--set', 'benchmarker=test-double', 'key=""',
'--set', 'c=1', 'len=1',
'--set', 'chunkedEnc=true', 'method=write',
'--set', 'chunks=0', 'n=1',
'--set', 'dur=0.1', 'res=normal'
'--set', 'key=""', ],
'--set', 'len=1', { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 });
'--set', 'method=write',
'--set', 'n=1',
'--set', 'res=normal',
'http'],
{ env });
child.on('exit', (code, signal) => {
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
});

28
test/sequential/test-benchmark-net.js

@ -2,28 +2,16 @@
require('../common'); require('../common');
// Minimal test for net benchmarks. This makes sure the benchmarks aren't
// horribly broken but nothing more than that.
// Because the net benchmarks use hardcoded ports, this should be in sequential // Because the net benchmarks use hardcoded ports, this should be in sequential
// rather than parallel to make sure it does not conflict with tests that choose // rather than parallel to make sure it does not conflict with tests that choose
// random available ports. // random available ports.
const assert = require('assert'); const runBenchmark = require('../common/benchmark');
const fork = require('child_process').fork;
const path = require('path');
const runjs = path.join(__dirname, '..', '..', 'benchmark', 'run.js');
const env = Object.assign({}, process.env, runBenchmark('net',
{ NODEJS_BENCHMARK_ZERO_ALLOWED: 1 }); [
const child = fork(runjs, 'dur=0',
['--set', 'dur=0', 'len=1024',
'--set', 'len=1024', 'type=buf'
'--set', 'type=buf', ],
'net'], { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 });
{ env });
child.on('exit', (code, signal) => {
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
});

Loading…
Cancel
Save