23
23
/* eslint-disable node-core/crypto-check */
24
24
'use strict' ;
25
25
const process = global . process ; // Some tests tamper with the process global.
26
- const path = require ( 'path' ) ;
27
- const fs = require ( 'fs' ) ;
26
+
28
27
const assert = require ( 'assert' ) ;
29
- const os = require ( 'os' ) ;
30
28
const { exec, execSync, spawnSync } = require ( 'child_process' ) ;
29
+ const fs = require ( 'fs' ) ;
30
+ // Do not require 'os' until needed so that test-os-checked-fucnction can
31
+ // monkey patch it. If 'os' is required here, that test will fail.
32
+ const path = require ( 'path' ) ;
31
33
const util = require ( 'util' ) ;
34
+ const { isMainThread } = require ( 'worker_threads' ) ;
35
+
32
36
const tmpdir = require ( './tmpdir' ) ;
33
37
const bits = [ 'arm64' , 'mips' , 'mipsel' , 'ppc64' , 's390x' , 'x64' ]
34
38
. includes ( process . arch ) ? 64 : 32 ;
35
39
const hasIntl = ! ! process . config . variables . v8_enable_i18n_support ;
36
- const { isMainThread } = require ( 'worker_threads' ) ;
37
40
38
41
// Some tests assume a umask of 0o022 so set that up front. Tests that need a
39
42
// different umask will set it themselves.
@@ -102,23 +105,12 @@ if (process.argv.length === 2 &&
102
105
103
106
const isWindows = process . platform === 'win32' ;
104
107
const isAIX = process . platform === 'aix' ;
105
- // On IBMi, process.platform and os.platform() both return 'aix',
106
- // It is not enough to differentiate between IBMi and real AIX system.
107
- const isIBMi = os . type ( ) === 'OS400' ;
108
- const isLinuxPPCBE = ( process . platform === 'linux' ) &&
109
- ( process . arch === 'ppc64' ) &&
110
- ( os . endianness ( ) === 'BE' ) ;
111
108
const isSunOS = process . platform === 'sunos' ;
112
109
const isFreeBSD = process . platform === 'freebsd' ;
113
110
const isOpenBSD = process . platform === 'openbsd' ;
114
111
const isLinux = process . platform === 'linux' ;
115
112
const isOSX = process . platform === 'darwin' ;
116
113
117
- const enoughTestMem = os . totalmem ( ) > 0x70000000 ; /* 1.75 Gb */
118
- const cpus = os . cpus ( ) ;
119
- const enoughTestCpu = Array . isArray ( cpus ) &&
120
- ( cpus . length > 1 || cpus [ 0 ] . speed > 999 ) ;
121
-
122
114
const rootDir = isWindows ? 'c:\\' : '/' ;
123
115
124
116
const buildType = process . config . target_defaults ?
@@ -198,15 +190,6 @@ const PIPE = (() => {
198
190
return path . join ( pipePrefix , pipeName ) ;
199
191
} ) ( ) ;
200
192
201
- const hasIPv6 = ( ( ) => {
202
- const iFaces = os . networkInterfaces ( ) ;
203
- const re = isWindows ? / L o o p b a c k P s e u d o - I n t e r f a c e / : / l o / ;
204
- return Object . keys ( iFaces ) . some ( ( name ) => {
205
- return re . test ( name ) &&
206
- iFaces [ name ] . some ( ( { family } ) => family === 'IPv6' ) ;
207
- } ) ;
208
- } ) ( ) ;
209
-
210
193
/*
211
194
* Check that when running a test with
212
195
* `$node --abort-on-uncaught-exception $file child`
@@ -742,8 +725,6 @@ module.exports = {
742
725
childShouldThrowAndAbort,
743
726
createZeroFilledFile,
744
727
disableCrashOnUnhandledRejection,
745
- enoughTestCpu,
746
- enoughTestMem,
747
728
expectsError,
748
729
expectsInternalAssertion,
749
730
expectWarning,
@@ -753,14 +734,11 @@ module.exports = {
753
734
getTTYfd,
754
735
hasIntl,
755
736
hasCrypto,
756
- hasIPv6,
757
737
hasMultiLocalhost,
758
738
isAIX,
759
739
isAlive,
760
740
isFreeBSD,
761
- isIBMi,
762
741
isLinux,
763
- isLinuxPPCBE,
764
742
isMainThread,
765
743
isOpenBSD,
766
744
isOSX,
@@ -784,12 +762,28 @@ module.exports = {
784
762
skipIfReportDisabled,
785
763
skipIfWorker,
786
764
787
- get localhostIPv6 ( ) { return '::1' ; } ,
765
+ get enoughTestCPU ( ) {
766
+ const cpus = require ( 'os' ) . cpus ( ) ;
767
+ return Array . isArray ( cpus ) && ( cpus . length > 1 || cpus [ 0 ] . speed > 999 ) ;
768
+ } ,
769
+
770
+ get enoughTestMeme ( ) {
771
+ return require ( 'os' ) . totalmem ( ) > 0x70000000 ; /* 1.75 Gb */
772
+ } ,
788
773
789
774
get hasFipsCrypto ( ) {
790
775
return hasCrypto && require ( 'crypto' ) . getFips ( ) ;
791
776
} ,
792
777
778
+ get hasIPv6 ( ) {
779
+ const iFaces = require ( 'os' ) . networkInterfaces ( ) ;
780
+ const re = isWindows ? / L o o p b a c k P s e u d o - I n t e r f a c e / : / l o / ;
781
+ return Object . keys ( iFaces ) . some ( ( name ) => {
782
+ return re . test ( name ) &&
783
+ iFaces [ name ] . some ( ( { family } ) => family === 'IPv6' ) ;
784
+ } ) ;
785
+ } ,
786
+
793
787
get inFreeBSDJail ( ) {
794
788
if ( inFreeBSDJail !== null ) return inFreeBSDJail ;
795
789
@@ -802,6 +796,17 @@ module.exports = {
802
796
return inFreeBSDJail ;
803
797
} ,
804
798
799
+ // On IBMi, process.platform and os.platform() both return 'aix',
800
+ // It is not enough to differentiate between IBMi and real AIX system.
801
+ get isIBMi ( ) {
802
+ return require ( 'os' ) . type ( ) === 'OS400' ;
803
+ } ,
804
+
805
+ get isLinuxPPCBE ( ) {
806
+ return ( process . platform === 'linux' ) && ( process . arch === 'ppc64' ) &&
807
+ ( require ( 'os' ) . endianness ( ) === 'BE' ) ;
808
+ } ,
809
+
805
810
get localhostIPv4 ( ) {
806
811
if ( localhostIPv4 !== null ) return localhostIPv4 ;
807
812
@@ -823,6 +828,8 @@ module.exports = {
823
828
return localhostIPv4 ;
824
829
} ,
825
830
831
+ get localhostIPv6 ( ) { return '::1' ; } ,
832
+
826
833
// opensslCli defined lazily to reduce overhead of spawnSync
827
834
get opensslCli ( ) {
828
835
if ( opensslCli !== null ) return opensslCli ;
0 commit comments