lib: shuffle v8_prof_polyfill.js for unit testing
Make it possible to test the versionCheck() function from that file in isolation. PR-URL: https://github.com/nodejs/node/pull/16769 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
421316dca1
commit
09d22ddab5
@ -25,6 +25,13 @@
|
|||||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
// 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
|
// Node polyfill
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const cp = require('child_process');
|
const cp = require('child_process');
|
||||||
@ -64,7 +71,18 @@ const fd = fs.openSync(logFile, 'r');
|
|||||||
const buf = Buffer.allocUnsafe(4096);
|
const buf = Buffer.allocUnsafe(4096);
|
||||||
const dec = new (require('string_decoder').StringDecoder)('utf-8');
|
const dec = new (require('string_decoder').StringDecoder)('utf-8');
|
||||||
var line = '';
|
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() {
|
function readline() {
|
||||||
while (true) {
|
while (true) {
|
||||||
const lineBreak = line.indexOf('\n');
|
const lineBreak = line.indexOf('\n');
|
||||||
@ -81,27 +99,21 @@ function readline() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function versionCheck() {
|
function versionCheck(firstLine, expected) {
|
||||||
// v8-version looks like
|
// v8-version looks like
|
||||||
// "v8-version,$major,$minor,$build,$patch[,$embedder],$candidate"
|
// "v8-version,$major,$minor,$build,$patch[,$embedder],$candidate"
|
||||||
// whereas process.versions.v8 is either "$major.$minor.$build-$embedder" or
|
// whereas process.versions.v8 is either "$major.$minor.$build-$embedder" or
|
||||||
// "$major.$minor.$build.$patch-$embedder".
|
// "$major.$minor.$build.$patch-$embedder".
|
||||||
var firstLine = readline();
|
|
||||||
line = firstLine + '\n' + line;
|
|
||||||
firstLine = firstLine.split(',');
|
firstLine = firstLine.split(',');
|
||||||
const curVer = process.versions.v8.split(/[.\-]/);
|
const curVer = expected.split(/[.\-]/);
|
||||||
if (firstLine.length !== 6 && firstLine.length !== 7 ||
|
if (firstLine.length !== 6 && firstLine.length !== 7 ||
|
||||||
firstLine[0] !== 'v8-version') {
|
firstLine[0] !== 'v8-version') {
|
||||||
console.log('Unable to read v8-version from log file.');
|
return 'Unable to read v8-version from log file.';
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
// Compare major, minor and build; ignore the patch and candidate fields.
|
// Compare major, minor and build; ignore the patch and candidate fields.
|
||||||
for (var i = 0; i < 3; i++) {
|
for (var i = 0; i < 3; i++)
|
||||||
if (curVer[i] !== firstLine[i + 1]) {
|
if (curVer[i] !== firstLine[i + 1])
|
||||||
console.log('Testing v8 version different from logging version');
|
return 'Testing v8 version different from logging version';
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function macCppfiltNm(out) {
|
function macCppfiltNm(out) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user