Skip to content

Commit a4f5052

Browse files
joyeecheungrichardlau
authored andcommitted
test: log more information in SEA tests
- Use spawnSyncAndExitWithoutError to log more information on error. - Use NODE_DEBUG_NATIVE to log internals - Skip the test when available disk space < 120MB PR-URL: #50759 Refs: #50740 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Darshan Sen <[email protected]>
1 parent 6df3e31 commit a4f5052

7 files changed

+106
-35
lines changed

‎test/common/sea.js‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
constcommon=require('../common');
44
constfixtures=require('../common/fixtures');
5+
consttmpdir=require('../common/tmpdir');
56

67
const{ readFileSync }=require('fs');
78
const{
@@ -43,6 +44,14 @@ function skipIfSingleExecutableIsNotSupported(){
4344
common.skip('On s390x, postject fails with `memory access out of bounds`.');
4445
}
4546
}
47+
48+
tmpdir.refresh();
49+
50+
// The SEA tests involve making a copy of the executable and writing some fixtures
51+
// to the tmpdir. To be safe, ensure that at least 120MB disk space is available.
52+
if(!tmpdir.hasEnoughSpace(120*1024*1024)){
53+
common.skip('Available disk space < 120MB');
54+
}
4655
}
4756

4857
functioninjectAndCodeSign(targetExecutable,resource){

‎test/sequential/test-single-executable-application-disable-experimental-sea-warning.js‎

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ skipIfSingleExecutableIsNotSupported();
1515
constfixtures=require('../common/fixtures');
1616
consttmpdir=require('../common/tmpdir');
1717
const{ copyFileSync, writeFileSync, existsSync }=require('fs');
18-
const{execFileSync}=require('child_process');
18+
const{spawnSyncAndExitWithoutError}=require('../common/child_process');
1919
const{ join }=require('path');
20-
const{ strictEqual }=require('assert');
2120
constassert=require('assert');
2221

2322
constinputFile=fixtures.path('sea.js');
@@ -44,17 +43,27 @@ writeFileSync(configFile, `
4443

4544
// Copy input to working directory
4645
copyFileSync(inputFile,tmpdir.resolve('sea.js'));
47-
execFileSync(process.execPath,['--experimental-sea-config','sea-config.json'],{
48-
cwd: tmpdir.path
49-
});
46+
spawnSyncAndExitWithoutError(
47+
process.execPath,
48+
['--experimental-sea-config','sea-config.json'],
49+
{cwd: tmpdir.path},
50+
{});
5051

5152
assert(existsSync(seaPrepBlob));
5253

5354
copyFileSync(process.execPath,outputFile);
5455
injectAndCodeSign(outputFile,seaPrepBlob);
5556

56-
constsingleExecutableApplicationOutput=execFileSync(
57+
spawnSyncAndExitWithoutError(
5758
outputFile,
5859
['-a','--b=c','d'],
59-
{env: {COMMON_DIRECTORY: join(__dirname,'..','common')}});
60-
strictEqual(singleExecutableApplicationOutput.toString(),'Hello, world! 😊\n');
60+
{
61+
env: {
62+
COMMON_DIRECTORY: join(__dirname,'..','common'),
63+
NODE_DEBUG_NATIVE: 'SEA',
64+
...process.env,
65+
}
66+
},
67+
{
68+
stdout: 'Hello, world! 😊\n'
69+
});

‎test/sequential/test-single-executable-application-empty.js‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ skipIfSingleExecutableIsNotSupported();
1414

1515
consttmpdir=require('../common/tmpdir');
1616
const{ copyFileSync, writeFileSync, existsSync }=require('fs');
17-
const{execFileSync}=require('child_process');
17+
const{spawnSyncAndExitWithoutError}=require('../common/child_process');
1818
constassert=require('assert');
1919

2020
constconfigFile=tmpdir.resolve('sea-config.json');
@@ -31,13 +31,22 @@ writeFileSync(configFile, `
3131
}
3232
`);
3333

34-
execFileSync(process.execPath,['--experimental-sea-config','sea-config.json'],{
35-
cwd: tmpdir.path
36-
});
34+
spawnSyncAndExitWithoutError(
35+
process.execPath,
36+
['--experimental-sea-config','sea-config.json'],
37+
{cwd: tmpdir.path});
3738

3839
assert(existsSync(seaPrepBlob));
3940

4041
copyFileSync(process.execPath,outputFile);
4142
injectAndCodeSign(outputFile,seaPrepBlob);
4243

43-
execFileSync(outputFile);
44+
spawnSyncAndExitWithoutError(
45+
outputFile,
46+
{
47+
env: {
48+
NODE_DEBUG_NATIVE: 'SEA',
49+
...process.env,
50+
}
51+
},
52+
{});

‎test/sequential/test-single-executable-application-snapshot-and-code-cache.js‎

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ const outputFile = join(tmpdir.path, process.platform === 'win32' ? 'sea.exe' :
4949
process.execPath,
5050
['--experimental-sea-config','sea-config.json'],
5151
{
52-
cwd: tmpdir.path
52+
cwd: tmpdir.path,
53+
env: {
54+
NODE_DEBUG_NATIVE: 'SEA',
55+
...process.env,
56+
},
5357
},
5458
{
5559
stderr: /"useCodeCache"isredundantwhen"useSnapshot"istrue/
@@ -61,8 +65,15 @@ const outputFile = join(tmpdir.path, process.platform === 'win32' ? 'sea.exe' :
6165
copyFileSync(process.execPath,outputFile);
6266
injectAndCodeSign(outputFile,seaPrepBlob);
6367

64-
spawnSyncAndExitWithoutError(outputFile,{
65-
stdout: 'Hello from snapshot',
66-
trim: true,
67-
});
68+
spawnSyncAndExitWithoutError(
69+
outputFile,
70+
{
71+
env: {
72+
NODE_DEBUG_NATIVE: 'SEA,MKSNAPSHOT',
73+
...process.env,
74+
}
75+
},{
76+
stdout: 'Hello from snapshot',
77+
trim: true,
78+
});
6879
}

‎test/sequential/test-single-executable-application-snapshot.js‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@ const outputFile = tmpdir.resolve(process.platform === 'win32' ? 'sea.exe' : 'se
7373
process.execPath,
7474
['--experimental-sea-config','sea-config.json'],
7575
{
76-
cwd: tmpdir.path
76+
cwd: tmpdir.path,
77+
env: {
78+
NODE_DEBUG_NATIVE: 'SEA',
79+
...process.env,
80+
},
7781
},
7882
{
7983
stderr: /Singleexecutableapplicationisanexperimentalfeature/
@@ -86,6 +90,12 @@ const outputFile = tmpdir.resolve(process.platform === 'win32' ? 'sea.exe' : 'se
8690

8791
spawnSyncAndExitWithoutError(
8892
outputFile,
93+
{
94+
env: {
95+
NODE_DEBUG_NATIVE: 'SEA,MKSNAPSHOT',
96+
...process.env,
97+
}
98+
},
8999
{
90100
trim: true,
91101
stdout: 'Hello from snapshot',

‎test/sequential/test-single-executable-application-use-code-cache.js‎

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ skipIfSingleExecutableIsNotSupported();
1515
constfixtures=require('../common/fixtures');
1616
consttmpdir=require('../common/tmpdir');
1717
const{ copyFileSync, writeFileSync, existsSync }=require('fs');
18-
const{execFileSync}=require('child_process');
18+
const{spawnSyncAndExitWithoutError}=require('../common/child_process');
1919
const{ join }=require('path');
20-
const{ strictEqual }=require('assert');
2120
constassert=require('assert');
2221

2322
constinputFile=fixtures.path('sea.js');
@@ -44,17 +43,32 @@ writeFileSync(configFile, `
4443

4544
// Copy input to working directory
4645
copyFileSync(inputFile,tmpdir.resolve('sea.js'));
47-
execFileSync(process.execPath,['--experimental-sea-config','sea-config.json'],{
48-
cwd: tmpdir.path
49-
});
46+
spawnSyncAndExitWithoutError(
47+
process.execPath,
48+
['--experimental-sea-config','sea-config.json'],
49+
{
50+
cwd: tmpdir.path,
51+
env: {
52+
NODE_DEBUG_NATIVE: 'SEA',
53+
...process.env,
54+
},
55+
});
5056

5157
assert(existsSync(seaPrepBlob));
5258

5359
copyFileSync(process.execPath,outputFile);
5460
injectAndCodeSign(outputFile,seaPrepBlob);
5561

56-
constsingleExecutableApplicationOutput=execFileSync(
62+
spawnSyncAndExitWithoutError(
5763
outputFile,
5864
['-a','--b=c','d'],
59-
{env: {COMMON_DIRECTORY: join(__dirname,'..','common')}});
60-
strictEqual(singleExecutableApplicationOutput.toString(),'Hello, world! 😊\n');
65+
{
66+
env: {
67+
COMMON_DIRECTORY: join(__dirname,'..','common'),
68+
NODE_DEBUG_NATIVE: 'SEA',
69+
...process.env,
70+
}
71+
},
72+
{
73+
stdout: 'Hello, world! 😊\n'
74+
});

‎test/sequential/test-single-executable-application.js‎

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ skipIfSingleExecutableIsNotSupported();
1414
constfixtures=require('../common/fixtures');
1515
consttmpdir=require('../common/tmpdir');
1616
const{ copyFileSync, writeFileSync, existsSync }=require('fs');
17-
const{execFileSync}=require('child_process');
17+
const{spawnSyncAndExitWithoutError}=require('../common/child_process');
1818
const{ join }=require('path');
19-
const{ strictEqual }=require('assert');
2019
constassert=require('assert');
2120

2221
constinputFile=fixtures.path('sea.js');
@@ -43,17 +42,27 @@ writeFileSync(configFile, `
4342

4443
// Copy input to working directory
4544
copyFileSync(inputFile,tmpdir.resolve('sea.js'));
46-
execFileSync(process.execPath,['--experimental-sea-config','sea-config.json'],{
47-
cwd: tmpdir.path
48-
});
45+
spawnSyncAndExitWithoutError(
46+
process.execPath,
47+
['--experimental-sea-config','sea-config.json'],
48+
{cwd: tmpdir.path},
49+
{});
4950

5051
assert(existsSync(seaPrepBlob));
5152

5253
copyFileSync(process.execPath,outputFile);
5354
injectAndCodeSign(outputFile,seaPrepBlob);
5455

55-
constsingleExecutableApplicationOutput=execFileSync(
56+
spawnSyncAndExitWithoutError(
5657
outputFile,
5758
['-a','--b=c','d'],
58-
{env: {COMMON_DIRECTORY: join(__dirname,'..','common')}});
59-
strictEqual(singleExecutableApplicationOutput.toString(),'Hello, world! 😊\n');
59+
{
60+
env: {
61+
COMMON_DIRECTORY: join(__dirname,'..','common'),
62+
NODE_DEBUG_NATIVE: 'SEA',
63+
...process.env,
64+
}
65+
},
66+
{
67+
stdout: 'Hello, world! 😊\n'
68+
});

0 commit comments

Comments
(0)