Skip to content

Commit

Permalink
test: remove isGlibc from common
Browse files Browse the repository at this point in the history
The `common.isGlibc()` function is called exactly once from only
one test. There's no reason for it to be in `require('../common')`
at the current time. If it ends up needing to be used by multiple
tests, it can easily be moved into it's own common sub-module
(e.g. `require('../common/isglibc')` ... for now tho, just move
it into the one test that uses it and simplify the implementation
a bit to remove unnecessary caching.

PR-URL: #22443
Reviewed-By: Refael Ackermann <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
  • Loading branch information
jasnell authored and targos committed Sep 3, 2018
1 parent efe71e9 commit e684382
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 20 deletions.
19 changes: 18 additions & 1 deletion test/abort/test-addon-uv-handle-leak.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const fs = require('fs');
const path = require('path');
const cp = require('child_process');
const { Worker } = require('worker_threads');
const { spawnSync } = require('child_process');

// This is a sibling test to test/addons/uv-handle-leak.

Expand Down Expand Up @@ -49,9 +50,25 @@ if (process.argv[2] === 'child') {
// Close callback: 0x7f2df31de220 CloseCallback(uv_handle_s*) [...]
// Data: 0x42

function isGlibc() {
try {
const lddOut = spawnSync('ldd', [process.execPath]).stdout;
const libcInfo = lddOut.toString().split('\n').map(
(line) => line.match(/libc\.so.+=>\s*(\S+)\s/)).filter((info) => info);
if (libcInfo.length === 0)
return false;
const nmOut = spawnSync('nm', ['-D', libcInfo[0][1]]).stdout;
if (/gnu_get_libc_version/.test(nmOut))
return true;
} catch {
return false;
}
}


if (!(common.isFreeBSD ||
common.isAIX ||
(common.isLinux && !common.isGlibc()) ||
(common.isLinux && !isGlibc()) ||
common.isWindows)) {
assert(stderr.includes('ExampleOwnerClass'), stderr);
assert(stderr.includes('CloseCallback'), stderr);
Expand Down
17 changes: 0 additions & 17 deletions test/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,6 @@ exports.isOpenBSD = process.platform === 'openbsd';
exports.isLinux = process.platform === 'linux';
exports.isOSX = process.platform === 'darwin';

let isGlibc;
exports.isGlibc = () => {
if (isGlibc !== undefined)
return isGlibc;
try {
const lddOut = spawnSync('ldd', [process.execPath]).stdout;
const libcInfo = lddOut.toString().split('\n').map(
(line) => line.match(/libc\.so.+=>\s*(\S+)\s/)).filter((info) => info);
if (libcInfo.length === 0)
return isGlibc = false;
const nmOut = spawnSync('nm', ['-D', libcInfo[0][1]]).stdout;
if (/gnu_get_libc_version/.test(nmOut))
return isGlibc = true;
} catch {}
return isGlibc = false;
};

exports.enoughTestMem = os.totalmem() > 0x70000000; /* 1.75 Gb */
const cpus = os.cpus();
exports.enoughTestCpu = Array.isArray(cpus) &&
Expand Down
2 changes: 0 additions & 2 deletions test/common/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const {
isOpenBSD,
isLinux,
isOSX,
isGlibc,
enoughTestMem,
enoughTestCpu,
rootDir,
Expand Down Expand Up @@ -71,7 +70,6 @@ export {
isOpenBSD,
isLinux,
isOSX,
isGlibc,
enoughTestMem,
enoughTestCpu,
rootDir,
Expand Down

0 comments on commit e684382

Please sign in to comment.