Skip to content

Commit e684382

Browse files
jasnelltargos
authored andcommitted
test: remove isGlibc from common
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]>
1 parent efe71e9 commit e684382

File tree

3 files changed

+18
-20
lines changed

3 files changed

+18
-20
lines changed

test/abort/test-addon-uv-handle-leak.js

+18-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const fs = require('fs');
66
const path = require('path');
77
const cp = require('child_process');
88
const { Worker } = require('worker_threads');
9+
const { spawnSync } = require('child_process');
910

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

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

53+
function isGlibc() {
54+
try {
55+
const lddOut = spawnSync('ldd', [process.execPath]).stdout;
56+
const libcInfo = lddOut.toString().split('\n').map(
57+
(line) => line.match(/libc\.so.+=>\s*(\S+)\s/)).filter((info) => info);
58+
if (libcInfo.length === 0)
59+
return false;
60+
const nmOut = spawnSync('nm', ['-D', libcInfo[0][1]]).stdout;
61+
if (/gnu_get_libc_version/.test(nmOut))
62+
return true;
63+
} catch {
64+
return false;
65+
}
66+
}
67+
68+
5269
if (!(common.isFreeBSD ||
5370
common.isAIX ||
54-
(common.isLinux && !common.isGlibc()) ||
71+
(common.isLinux && !isGlibc()) ||
5572
common.isWindows)) {
5673
assert(stderr.includes('ExampleOwnerClass'), stderr);
5774
assert(stderr.includes('CloseCallback'), stderr);

test/common/index.js

-17
Original file line numberDiff line numberDiff line change
@@ -67,23 +67,6 @@ exports.isOpenBSD = process.platform === 'openbsd';
6767
exports.isLinux = process.platform === 'linux';
6868
exports.isOSX = process.platform === 'darwin';
6969

70-
let isGlibc;
71-
exports.isGlibc = () => {
72-
if (isGlibc !== undefined)
73-
return isGlibc;
74-
try {
75-
const lddOut = spawnSync('ldd', [process.execPath]).stdout;
76-
const libcInfo = lddOut.toString().split('\n').map(
77-
(line) => line.match(/libc\.so.+=>\s*(\S+)\s/)).filter((info) => info);
78-
if (libcInfo.length === 0)
79-
return isGlibc = false;
80-
const nmOut = spawnSync('nm', ['-D', libcInfo[0][1]]).stdout;
81-
if (/gnu_get_libc_version/.test(nmOut))
82-
return isGlibc = true;
83-
} catch {}
84-
return isGlibc = false;
85-
};
86-
8770
exports.enoughTestMem = os.totalmem() > 0x70000000; /* 1.75 Gb */
8871
const cpus = os.cpus();
8972
exports.enoughTestCpu = Array.isArray(cpus) &&

test/common/index.mjs

-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ const {
1313
isOpenBSD,
1414
isLinux,
1515
isOSX,
16-
isGlibc,
1716
enoughTestMem,
1817
enoughTestCpu,
1918
rootDir,
@@ -71,7 +70,6 @@ export {
7170
isOpenBSD,
7271
isLinux,
7372
isOSX,
74-
isGlibc,
7573
enoughTestMem,
7674
enoughTestCpu,
7775
rootDir,

0 commit comments

Comments
 (0)