node/test/code-cache/test-code-cache-generator.js
Joyee Cheung fd913fe365
src: remove code cache integrity check
In preparation of sharing code cache among different threads -
we simply rely on v8 to reject invalid cache, since there isn't
any serious consequence when the cache is invalid anyway.

PR-URL: https://github.com/nodejs/node/pull/24950
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2019-01-14 15:40:32 +01:00

53 lines
1.3 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::LoadCodeCache()
// are defined in the generated code.
// See src/node_native_module.h for explanations.
const rl = readline.createInterface({
input: fs.createReadStream(dest),
crlfDelay: Infinity
});
let hasCacheDef = false;
rl.on('line', common.mustCallAtLeast((line) => {
if (line.includes('LoadCodeCache(')) {
hasCacheDef = true;
}
}, 2));
rl.on('close', common.mustCall(() => {
assert.ok(hasCacheDef);
}));