Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
test: force garbage collection on crypto timing test
Garbage collection interferes with timing statistics gathering so force
it before beginning the data collection.
  • Loading branch information
Trott committed Aug 21, 2016
commit b487bfbfab836f4ddd76c909b1477321b5ac716b
7 changes: 6 additions & 1 deletion test/sequential/test-crypto-timing-safe-equal.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Flags: --allow_natives_syntax
// Flags: --allow_natives_syntax --expose-gc
'use strict';
const common = require('../common');
const assert = require('assert');
Expand All @@ -8,6 +8,8 @@ if (!common.hasCrypto) {
return;
}

assert.equal(typeof global.gc, 'function', 'Run this test with --expose-gc');

const crypto = require('crypto');

assert.strictEqual(
Expand Down Expand Up @@ -127,6 +129,8 @@ runBenchmark(crypto.timingSafeEqual, Buffer.from('A'), Buffer.from('A'), true);
// significantly affect the threshold.
const T_THRESHOLD = 3.291;

// Make sure garbage collection does not interfere with timing
global.gc();
const t = getTValue(crypto.timingSafeEqual);
assert(
Math.abs(t) < T_THRESHOLD,
Expand All @@ -137,6 +141,7 @@ assert(
// same benchmarks again, this time with an unsafe comparison function. In this
// case the t-value should be above the threshold.
const unsafeCompare = (bufA, bufB) => bufA.equals(bufB);
global.gc();
const t2 = getTValue(unsafeCompare);
assert(
Math.abs(t2) > T_THRESHOLD,
Expand Down