Welcome to mirror list, hosted at ThFree Co, Russian Federation.

test-code-cache-generator.js « code-cache « test - github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2fed3294bf4492856cb099eacbc2f02ef1f4c477 (plain)
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
53
54
55
56
57
58
59
60
61
62
63
64
'use strict';

// This test verifies the code cache generator can generate a C++
// file that contains the code cache. This can be removed once we
// actually build that C++ file into our binary.

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');

console.log('Looking for mkcodecache executable');
let buildDir;
const stat = fs.statSync(process.execPath);
if (stat.isSymbolicLink()) {
  console.log('Binary is a symbolic link');
  buildDir = path.dirname(fs.readlinkSync(process.execPath));
} else {
  buildDir = path.dirname(process.execPath);
}

const ext = common.isWindows ? '.exe' : '';
const generator = path.join(buildDir, `mkcodecache${ext}`);
if (!fs.existsSync(generator)) {
  common.skip('Could not find mkcodecache');
}

console.log(`mkcodecache is ${generator}`);

tmpdir.refresh();
const dest = path.join(tmpdir.path, 'cache.cc');

// Run mkcodecache
const child = spawnSync(generator, [dest]);
assert.ifError(child.error);
if (child.status !== 0) {
  console.log(child.stderr.toString());
  assert.strictEqual(child.status, 0);
}

// Verifies that:
// - NativeModuleEnv::InitializeCodeCache()
// are defined in the generated code.
// See src/node_native_module_env.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('InitializeCodeCache(')) {
    hasCacheDef = true;
  }
}, 2));

rl.on('close', common.mustCall(() => {
  assert.ok(hasCacheDef);
}));