Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: log more information in SEA tests #50759

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/node_realm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ void Realm::PrintInfoForSnapshot() {
fprintf(stderr, "BaseObjects of the Realm:\n");
size_t i = 0;
ForEachBaseObject([&](BaseObject* obj) {
std::cout << "#" << i++ << " " << obj << ": " << obj->MemoryInfoName()
std::cerr << "#" << i++ << " " << obj << ": " << obj->MemoryInfoName()
<< "\n";
});

Expand Down
2 changes: 1 addition & 1 deletion src/node_snapshotable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1075,7 +1075,7 @@ ExitCode SnapshotBuilder::CreateSnapshot(SnapshotData* out,

if (per_process::enabled_debug_list.enabled(DebugCategory::MKSNAPSHOT)) {
env->ForEachRealm([](Realm* realm) { realm->PrintInfoForSnapshot(); });
printf("Environment = %p\n", env);
fprintf(stderr, "Environment = %p\n", env);
}

// Serialize the native states
Expand Down
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)) {
RaisinTen marked this conversation as resolved.
Show resolved Hide resolved
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'
});