Files
node/test/parallel/test-compile-cache-wasm.js
Shelley Vohr dcaf43a167 module: disable the compile cache while V8 coverage is collected
V8 cannot collect block coverage for functions that are deserialized
from the code cache, so it only reports how many times each of them
ran. With a warm compile cache, branches that never ran inside those
functions are reported as covered, and tools that merge reports from
several processes can report functions that ran as never run.

The documentation recommended turning the cache off by hand. Do it
automatically when coverage collection starts with the process, through
NODE_V8_COVERAGE or --experimental-test-coverage.

The compile cache tests stop propagating NODE_V8_COVERAGE to the
processes they spawn, so that they keep working when the test suite
itself runs with coverage.

Signed-off-by: Shelley Vohr <shelley.vohr@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/67120
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
2026-11-20 14:59:50 +00:00

86 lines
2.5 KiB
JavaScript

'use strict';
// This tests NODE_COMPILE_CACHE works for WebAssembly modules imported as ESM.
require('../common');
const { spawnSyncAndAssert } = require('../common/compile-cache');
const assert = require('assert');
const tmpdir = require('../common/tmpdir');
const fixtures = require('../common/fixtures');
const script = fixtures.path('es-modules', 'test-wasm-js-string-builtins.mjs');
// V8 only serializes optimized code, so a complete cache requires eager
// optimizing compilation.
{
tmpdir.refresh();
const dir = tmpdir.resolve('.compile_cache_dir');
const flags = ['--no-liftoff', '--no-wasm-lazy-compilation', '--no-warnings'];
spawnSyncAndAssert(
process.execPath,
[...flags, script],
{
env: {
...process.env,
NODE_DEBUG_NATIVE: 'COMPILE_CACHE',
NODE_COMPILE_CACHE: dir,
},
cwd: tmpdir.path,
},
{
stderr(output) {
assert.match(output, /no cache for Wasm .*js-string-builtins\.wasm/);
assert.match(output, /V8 code cache for Wasm .*js-string-builtins\.wasm was not initialized, initializing the in-memory entry/);
assert.match(output, /writing cache for Wasm .*js-string-builtins\.wasm.*success/);
return true;
},
});
spawnSyncAndAssert(
process.execPath,
[...flags, script],
{
env: {
...process.env,
NODE_DEBUG_NATIVE: 'COMPILE_CACHE',
NODE_COMPILE_CACHE: dir,
},
cwd: tmpdir.path,
},
{
stderr(output) {
assert.match(output, /reading cache from .* for Wasm .*js-string-builtins\.wasm.*success/);
assert.match(output, /deserializing Wasm .*js-string-builtins\.wasm.*success/);
assert.match(output, /skip persisting Wasm .*js-string-builtins\.wasm because cache was the same/);
return true;
},
});
}
// With the default lazy baseline compilation there is no optimized code to
// cache at compile time, and no cache entry is written.
{
tmpdir.refresh();
const dir = tmpdir.resolve('.compile_cache_dir');
spawnSyncAndAssert(
process.execPath,
['--no-warnings', script],
{
env: {
...process.env,
NODE_DEBUG_NATIVE: 'COMPILE_CACHE',
NODE_COMPILE_CACHE: dir,
},
cwd: tmpdir.path,
},
{
stderr(output) {
assert.match(output, /nothing to serialize for Wasm .*js-string-builtins\.wasm/);
assert.match(output, /skip persisting Wasm .*js-string-builtins\.wasm because the cache was not initialized/);
return true;
},
});
}