Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: fix version check in tick processor #16769

Merged
merged 3 commits into from
Nov 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
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
38 changes: 25 additions & 13 deletions lib/internal/v8_prof_polyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

module.exports = { versionCheck };

// Don't execute when required directly instead of being eval'd from
// lib/internal/v8_prof_processor.js. This way we can test functions
// from this file in isolation.
if (module.id === 'internal/v8_prof_polyfill') return;

// Node polyfill
const fs = require('fs');
const cp = require('child_process');
Expand Down Expand Up @@ -64,7 +71,18 @@ const fd = fs.openSync(logFile, 'r');
const buf = Buffer.allocUnsafe(4096);
const dec = new (require('string_decoder').StringDecoder)('utf-8');
var line = '';
versionCheck();

{
const message = versionCheck(peekline(), process.versions.v8);
if (message) console.log(message);
}

function peekline() {
const s = readline();
line = s + '\n' + line;
return s;
}

function readline() {
while (true) {
const lineBreak = line.indexOf('\n');
Expand All @@ -81,27 +99,21 @@ function readline() {
}
}

function versionCheck() {
function versionCheck(firstLine, expected) {
// v8-version looks like
// "v8-version,$major,$minor,$build,$patch[,$embedder],$candidate"
// whereas process.versions.v8 is either "$major.$minor.$build-$embedder" or
// "$major.$minor.$build.$patch-$embedder".
var firstLine = readline();
line = firstLine + '\n' + line;
firstLine = firstLine.split(',');
const curVer = process.versions.v8.split(/\.-/);
const curVer = expected.split(/[.\-]/);
if (firstLine.length !== 6 && firstLine.length !== 7 ||
firstLine[0] !== 'v8-version') {
console.log('Unable to read v8-version from log file.');
return;
return 'Unable to read v8-version from log file.';
}
// Compare major, minor and build; ignore the patch and candidate fields.
for (var i = 0; i < 3; i++) {
if (curVer[i] !== firstLine[i + 1]) {
console.log('Testing v8 version different from logging version');
return;
}
}
for (var i = 0; i < 3; i++)
if (curVer[i] !== firstLine[i + 1])
return 'Testing v8 version different from logging version';
}

function macCppfiltNm(out) {
Expand Down
41 changes: 41 additions & 0 deletions test/parallel/test-tick-processor-version-check.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Flags: --expose-internals
'use strict';
require('../common');
const assert = require('assert');
const { versionCheck } = require('internal/v8_prof_polyfill');

assert.strictEqual(versionCheck('v8-version,1,2,3,4,0', '1.2.3'), undefined);
assert.strictEqual(versionCheck('v8-version,1,2,3,4,0', '1.2.3.3'), undefined);
assert.strictEqual(versionCheck('v8-version,1,2,3,4,0', '1.2.3.4'), undefined);
assert.strictEqual(versionCheck('v8-version,1,2,3,4,0', '1.2.3.5'), undefined);
assert.strictEqual(versionCheck('v8-version,1,2,3,4,-node.1,0', '1.2.3'),
undefined);
assert.strictEqual(versionCheck('v8-version,1,2,3,4,-node.1,0', '1.2.3.4'),
undefined);
assert.strictEqual(versionCheck('v8-version,1,2,3,4,-node.1,0', '1.2.3-node.1'),
undefined);
assert.strictEqual(versionCheck('v8-version,1,2,3,4,-node.1,0', '1.2.3-node.2'),
undefined);
assert.strictEqual(
versionCheck('v8-version,1,2,3,4,-node.1,0', '1.2.3.4-node.2'),
undefined);

{
const expected = 'Unable to read v8-version from log file.';
assert.strictEqual(versionCheck('faux', '1.2.3'), expected);
assert.strictEqual(versionCheck('v8-version', '1.2.3'), expected);
assert.strictEqual(versionCheck('v8-version,1', '1.2.3'), expected);
assert.strictEqual(versionCheck('v8-version,1,2', '1.2.3'), expected);
assert.strictEqual(versionCheck('v8-version,1,2,3', '1.2.3'), expected);
assert.strictEqual(versionCheck('v8-version,1,2,3,4', '1.2.3'), expected);
assert.strictEqual(versionCheck('v8-version,1,2,3,4,5,6,7', '1.2.3'),
expected);
}

{
const expected = 'Testing v8 version different from logging version';
assert.strictEqual(versionCheck('v8-version,4,3,2,1,0', '1.2.3'), expected);
assert.strictEqual(versionCheck('v8-version,4,3,2,1,0', '1.2.3.4'), expected);
assert.strictEqual(versionCheck('v8-version,4,3,2,1,0', '4.3.1.1'), expected);
assert.strictEqual(versionCheck('v8-version,4,3,2,1,0', '4.3.3.1'), expected);
}