-
Notifications
You must be signed in to change notification settings - Fork 30.7k
/
Copy pathtest-code-cache-generator.js
52 lines (42 loc) · 1.25 KB
/
test-code-cache-generator.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
'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);
}));