mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 12:20:27 +01:00
- Add the code cache tests to the default test suite, and test the bookkeeping when the binary is not built with the code cache. - Test the code cache generator to make sure we do not accidentally break it - until we enable code cache in the CI. Refs: https://github.com/nodejs/node/issues/21563 PR-URL: https://github.com/nodejs/node/pull/23855 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
59 lines
1.4 KiB
JavaScript
59 lines
1.4 KiB
JavaScript
'use strict';
|
|
|
|
// This test verifies that the binary is compiled with code cache and the
|
|
// cache is used when built in modules are compiled.
|
|
|
|
const common = require('../common');
|
|
|
|
const tmpdir = require('../common/tmpdir');
|
|
const { spawnSync } = require('child_process');
|
|
const assert = require('assert');
|
|
const path = require('path');
|
|
const fs = require('fs');
|
|
const readline = require('readline');
|
|
|
|
const generator = path.join(
|
|
__dirname, '..', '..', 'tools', 'generate_code_cache.js'
|
|
);
|
|
tmpdir.refresh();
|
|
const dest = path.join(tmpdir.path, 'cache.cc');
|
|
|
|
// Run tools/generate_code_cache.js
|
|
const child = spawnSync(
|
|
process.execPath,
|
|
['--expose-internals', generator, dest]
|
|
);
|
|
assert.ifError(child.error);
|
|
if (child.status !== 0) {
|
|
console.log(child.stderr.toString());
|
|
assert.strictEqual(child.status, 0);
|
|
}
|
|
|
|
// Verifies that:
|
|
// - node::DefineCodeCache()
|
|
// - node::DefineCodeCacheHash()
|
|
// are defined in the generated code.
|
|
// See src/node_code_cache_stub.cc for explanations.
|
|
|
|
const rl = readline.createInterface({
|
|
input: fs.createReadStream(dest),
|
|
crlfDelay: Infinity
|
|
});
|
|
|
|
let hasCacheDef = false;
|
|
let hasHashDef = false;
|
|
|
|
rl.on('line', common.mustCallAtLeast((line) => {
|
|
if (line.includes('DefineCodeCache(')) {
|
|
hasCacheDef = true;
|
|
}
|
|
if (line.includes('DefineCodeCacheHash(')) {
|
|
hasHashDef = true;
|
|
}
|
|
}, 2));
|
|
|
|
rl.on('close', common.mustCall(() => {
|
|
assert.ok(hasCacheDef);
|
|
assert.ok(hasHashDef);
|
|
}));
|