Skip to content

Commit

Permalink
test: log more information in SEA tests
Browse files Browse the repository at this point in the history
- 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 <yagiz.nizipli@sentry.io>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
  • Loading branch information
joyeecheung authored and targos committed Dec 4, 2023
1 parent 74f5a1c commit ac3a6ee
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 35 deletions.
9 changes: 9 additions & 0 deletions test/common/sea.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const common = require('../common');
const fixtures = require('../common/fixtures');
const tmpdir = require('../common/tmpdir');

const { readFileSync } = require('fs');
const {
Expand Down Expand Up @@ -43,6 +44,14 @@ function skipIfSingleExecutableIsNotSupported() {
common.skip('On s390x, postject fails with `memory access out of bounds`.');
}
}

tmpdir.refresh();

// The SEA tests involve making a copy of the executable and writing some fixtures
// to the tmpdir. To be safe, ensure that at least 120MB disk space is available.
if (!tmpdir.hasEnoughSpace(120 * 1024 * 1024)) {
common.skip('Available disk space < 120MB');
}
}

function injectAndCodeSign(targetExecutable, resource) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ skipIfSingleExecutableIsNotSupported();
const fixtures = require('../common/fixtures');
const tmpdir = require('../common/tmpdir');
const { copyFileSync, writeFileSync, existsSync } = require('fs');
const { execFileSync } = require('child_process');
const { spawnSyncAndExitWithoutError } = require('../common/child_process');
const { join } = require('path');
const { strictEqual } = require('assert');
const assert = require('assert');

const inputFile = fixtures.path('sea.js');
Expand All @@ -44,17 +43,27 @@ writeFileSync(configFile, `

// Copy input to working directory
copyFileSync(inputFile, tmpdir.resolve('sea.js'));
execFileSync(process.execPath, ['--experimental-sea-config', 'sea-config.json'], {
cwd: tmpdir.path
});
spawnSyncAndExitWithoutError(
process.execPath,
['--experimental-sea-config', 'sea-config.json'],
{ cwd: tmpdir.path },
{});

assert(existsSync(seaPrepBlob));

copyFileSync(process.execPath, outputFile);
injectAndCodeSign(outputFile, seaPrepBlob);

const singleExecutableApplicationOutput = execFileSync(
spawnSyncAndExitWithoutError(
outputFile,
[ '-a', '--b=c', 'd' ],
{ env: { COMMON_DIRECTORY: join(__dirname, '..', 'common') } });
strictEqual(singleExecutableApplicationOutput.toString(), 'Hello, world! 😊\n');
{
env: {
COMMON_DIRECTORY: join(__dirname, '..', 'common'),
NODE_DEBUG_NATIVE: 'SEA',
...process.env,
}
},
{
stdout: 'Hello, world! 😊\n'
});
19 changes: 14 additions & 5 deletions test/sequential/test-single-executable-application-empty.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ skipIfSingleExecutableIsNotSupported();

const tmpdir = require('../common/tmpdir');
const { copyFileSync, writeFileSync, existsSync } = require('fs');
const { execFileSync } = require('child_process');
const { spawnSyncAndExitWithoutError } = require('../common/child_process');
const assert = require('assert');

const configFile = tmpdir.resolve('sea-config.json');
Expand All @@ -31,13 +31,22 @@ writeFileSync(configFile, `
}
`);

execFileSync(process.execPath, ['--experimental-sea-config', 'sea-config.json'], {
cwd: tmpdir.path
});
spawnSyncAndExitWithoutError(
process.execPath,
['--experimental-sea-config', 'sea-config.json'],
{ cwd: tmpdir.path });

assert(existsSync(seaPrepBlob));

copyFileSync(process.execPath, outputFile);
injectAndCodeSign(outputFile, seaPrepBlob);

execFileSync(outputFile);
spawnSyncAndExitWithoutError(
outputFile,
{
env: {
NODE_DEBUG_NATIVE: 'SEA',
...process.env,
}
},
{});
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ const outputFile = join(tmpdir.path, process.platform === 'win32' ? 'sea.exe' :
process.execPath,
['--experimental-sea-config', 'sea-config.json'],
{
cwd: tmpdir.path
cwd: tmpdir.path,
env: {
NODE_DEBUG_NATIVE: 'SEA',
...process.env,
},
},
{
stderr: /"useCodeCache" is redundant when "useSnapshot" is true/
Expand All @@ -61,8 +65,15 @@ const outputFile = join(tmpdir.path, process.platform === 'win32' ? 'sea.exe' :
copyFileSync(process.execPath, outputFile);
injectAndCodeSign(outputFile, seaPrepBlob);

spawnSyncAndExitWithoutError(outputFile, {
stdout: 'Hello from snapshot',
trim: true,
});
spawnSyncAndExitWithoutError(
outputFile,
{
env: {
NODE_DEBUG_NATIVE: 'SEA,MKSNAPSHOT',
...process.env,
}
}, {
stdout: 'Hello from snapshot',
trim: true,
});
}
12 changes: 11 additions & 1 deletion test/sequential/test-single-executable-application-snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ const outputFile = tmpdir.resolve(process.platform === 'win32' ? 'sea.exe' : 'se
process.execPath,
['--experimental-sea-config', 'sea-config.json'],
{
cwd: tmpdir.path
cwd: tmpdir.path,
env: {
NODE_DEBUG_NATIVE: 'SEA',
...process.env,
},
},
{
stderr: /Single executable application is an experimental feature/
Expand All @@ -86,6 +90,12 @@ const outputFile = tmpdir.resolve(process.platform === 'win32' ? 'sea.exe' : 'se

spawnSyncAndExitWithoutError(
outputFile,
{
env: {
NODE_DEBUG_NATIVE: 'SEA,MKSNAPSHOT',
...process.env,
}
},
{
trim: true,
stdout: 'Hello from snapshot',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ skipIfSingleExecutableIsNotSupported();
const fixtures = require('../common/fixtures');
const tmpdir = require('../common/tmpdir');
const { copyFileSync, writeFileSync, existsSync } = require('fs');
const { execFileSync } = require('child_process');
const { spawnSyncAndExitWithoutError } = require('../common/child_process');
const { join } = require('path');
const { strictEqual } = require('assert');
const assert = require('assert');

const inputFile = fixtures.path('sea.js');
Expand All @@ -44,17 +43,32 @@ writeFileSync(configFile, `

// Copy input to working directory
copyFileSync(inputFile, tmpdir.resolve('sea.js'));
execFileSync(process.execPath, ['--experimental-sea-config', 'sea-config.json'], {
cwd: tmpdir.path
});
spawnSyncAndExitWithoutError(
process.execPath,
['--experimental-sea-config', 'sea-config.json'],
{
cwd: tmpdir.path,
env: {
NODE_DEBUG_NATIVE: 'SEA',
...process.env,
},
});

assert(existsSync(seaPrepBlob));

copyFileSync(process.execPath, outputFile);
injectAndCodeSign(outputFile, seaPrepBlob);

const singleExecutableApplicationOutput = execFileSync(
spawnSyncAndExitWithoutError(
outputFile,
[ '-a', '--b=c', 'd' ],
{ env: { COMMON_DIRECTORY: join(__dirname, '..', 'common') } });
strictEqual(singleExecutableApplicationOutput.toString(), 'Hello, world! 😊\n');
{
env: {
COMMON_DIRECTORY: join(__dirname, '..', 'common'),
NODE_DEBUG_NATIVE: 'SEA',
...process.env,
}
},
{
stdout: 'Hello, world! 😊\n'
});
25 changes: 17 additions & 8 deletions test/sequential/test-single-executable-application.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ skipIfSingleExecutableIsNotSupported();
const fixtures = require('../common/fixtures');
const tmpdir = require('../common/tmpdir');
const { copyFileSync, writeFileSync, existsSync } = require('fs');
const { execFileSync } = require('child_process');
const { spawnSyncAndExitWithoutError } = require('../common/child_process');
const { join } = require('path');
const { strictEqual } = require('assert');
const assert = require('assert');

const inputFile = fixtures.path('sea.js');
Expand All @@ -43,17 +42,27 @@ writeFileSync(configFile, `

// Copy input to working directory
copyFileSync(inputFile, tmpdir.resolve('sea.js'));
execFileSync(process.execPath, ['--experimental-sea-config', 'sea-config.json'], {
cwd: tmpdir.path
});
spawnSyncAndExitWithoutError(
process.execPath,
['--experimental-sea-config', 'sea-config.json'],
{ cwd: tmpdir.path },
{});

assert(existsSync(seaPrepBlob));

copyFileSync(process.execPath, outputFile);
injectAndCodeSign(outputFile, seaPrepBlob);

const singleExecutableApplicationOutput = execFileSync(
spawnSyncAndExitWithoutError(
outputFile,
[ '-a', '--b=c', 'd' ],
{ env: { COMMON_DIRECTORY: join(__dirname, '..', 'common') } });
strictEqual(singleExecutableApplicationOutput.toString(), 'Hello, world! 😊\n');
{
env: {
COMMON_DIRECTORY: join(__dirname, '..', 'common'),
NODE_DEBUG_NATIVE: 'SEA',
...process.env,
}
},
{
stdout: 'Hello, world! 😊\n'
});

0 comments on commit ac3a6ee

Please sign in to comment.