From a3ee1870fd7b8fbe9afb94d9d9ddd7be4dfa1f02 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Thu, 16 Nov 2023 18:26:45 +0100 Subject: [PATCH] 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: https://github.com/nodejs/node/pull/50759 Refs: https://github.com/nodejs/node/issues/50740 Reviewed-By: Yagiz Nizipli Reviewed-By: James M Snell Reviewed-By: Darshan Sen --- test/common/sea.js | 9 ++++++ ...cation-disable-experimental-sea-warning.js | 25 +++++++++++----- ...est-single-executable-application-empty.js | 19 ++++++++---- ...ble-application-snapshot-and-code-cache.js | 21 +++++++++---- ...-single-executable-application-snapshot.js | 12 +++++++- ...e-executable-application-use-code-cache.js | 30 ++++++++++++++----- .../test-single-executable-application.js | 25 +++++++++++----- 7 files changed, 106 insertions(+), 35 deletions(-) diff --git a/test/common/sea.js b/test/common/sea.js index cc1890a5464012..d57c9e4238d867 100644 --- a/test/common/sea.js +++ b/test/common/sea.js @@ -2,6 +2,7 @@ const common = require('../common'); const fixtures = require('../common/fixtures'); +const tmpdir = require('../common/tmpdir'); const { readFileSync } = require('fs'); const { @@ -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) { diff --git a/test/sequential/test-single-executable-application-disable-experimental-sea-warning.js b/test/sequential/test-single-executable-application-disable-experimental-sea-warning.js index 0b4701b07e1c54..fdd0c23a26da3e 100644 --- a/test/sequential/test-single-executable-application-disable-experimental-sea-warning.js +++ b/test/sequential/test-single-executable-application-disable-experimental-sea-warning.js @@ -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'); @@ -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' + }); diff --git a/test/sequential/test-single-executable-application-empty.js b/test/sequential/test-single-executable-application-empty.js index 13dc2e834b7caa..047685b0074aa9 100644 --- a/test/sequential/test-single-executable-application-empty.js +++ b/test/sequential/test-single-executable-application-empty.js @@ -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'); @@ -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, + } + }, + {}); diff --git a/test/sequential/test-single-executable-application-snapshot-and-code-cache.js b/test/sequential/test-single-executable-application-snapshot-and-code-cache.js index 6d86d6a79d8d68..952003cf02c585 100644 --- a/test/sequential/test-single-executable-application-snapshot-and-code-cache.js +++ b/test/sequential/test-single-executable-application-snapshot-and-code-cache.js @@ -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/ @@ -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, + }); } diff --git a/test/sequential/test-single-executable-application-snapshot.js b/test/sequential/test-single-executable-application-snapshot.js index 5c2d8c36fdd38f..402505a6122c74 100644 --- a/test/sequential/test-single-executable-application-snapshot.js +++ b/test/sequential/test-single-executable-application-snapshot.js @@ -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/ @@ -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', diff --git a/test/sequential/test-single-executable-application-use-code-cache.js b/test/sequential/test-single-executable-application-use-code-cache.js index 96de5769b1fe6b..af5f2855ed6318 100644 --- a/test/sequential/test-single-executable-application-use-code-cache.js +++ b/test/sequential/test-single-executable-application-use-code-cache.js @@ -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'); @@ -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' + }); diff --git a/test/sequential/test-single-executable-application.js b/test/sequential/test-single-executable-application.js index e930254cb0a7ae..6379dfd2ea4b6d 100644 --- a/test/sequential/test-single-executable-application.js +++ b/test/sequential/test-single-executable-application.js @@ -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'); @@ -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' + });