2018-06-18 19:02:57 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
// Flags: --expose-internals
|
2018-10-24 17:24:31 +02:00
|
|
|
// This test verifies that if the binary is compiled with code cache,
|
|
|
|
// and the cache is used when built in modules are compiled.
|
|
|
|
// Otherwise, verifies that no cache is used when compiling builtins.
|
2018-06-18 19:02:57 +02:00
|
|
|
|
|
|
|
require('../common');
|
|
|
|
const assert = require('assert');
|
|
|
|
const {
|
2018-06-27 16:31:01 +02:00
|
|
|
cachableBuiltins,
|
2018-11-03 07:26:32 +01:00
|
|
|
cannotUseCache
|
2018-06-18 19:02:57 +02:00
|
|
|
} = require('internal/bootstrap/cache');
|
2018-11-03 07:26:32 +01:00
|
|
|
const {
|
|
|
|
isMainThread
|
|
|
|
} = require('worker_threads');
|
|
|
|
|
|
|
|
const {
|
|
|
|
internalBinding
|
|
|
|
} = require('internal/test/binding');
|
|
|
|
const {
|
2018-11-14 15:38:12 +01:00
|
|
|
getCacheUsage
|
2018-11-03 07:26:32 +01:00
|
|
|
} = internalBinding('native_module');
|
|
|
|
|
|
|
|
for (const key of cachableBuiltins) {
|
|
|
|
if (!isMainThread && key === 'trace_events') {
|
|
|
|
continue; // Cannot load trace_events in workers
|
|
|
|
}
|
|
|
|
require(key);
|
|
|
|
}
|
2018-06-18 19:02:57 +02:00
|
|
|
|
2018-11-14 15:38:12 +01:00
|
|
|
// The computation has to be delayed until we have done loading modules
|
|
|
|
const {
|
|
|
|
compiledWithoutCache,
|
|
|
|
compiledWithCache
|
|
|
|
} = getCacheUsage();
|
|
|
|
|
2018-06-18 19:02:57 +02:00
|
|
|
const loadedModules = process.moduleLoadList
|
|
|
|
.filter((m) => m.startsWith('NativeModule'))
|
|
|
|
.map((m) => m.replace('NativeModule ', ''));
|
|
|
|
|
2018-10-24 17:24:31 +02:00
|
|
|
// The binary is not configured with code cache, verifies that the builtins
|
|
|
|
// are all compiled without cache and we are doing the bookkeeping right.
|
|
|
|
if (process.config.variables.node_code_cache_path === undefined) {
|
2018-11-03 07:26:32 +01:00
|
|
|
console.log('The binary is not configured with code cache');
|
|
|
|
assert.deepStrictEqual(compiledWithCache, new Set());
|
2018-11-14 15:38:12 +01:00
|
|
|
|
|
|
|
for (const key of loadedModules) {
|
|
|
|
assert(compiledWithoutCache.has(key),
|
|
|
|
`"${key}" should've been compiled without code cache`);
|
|
|
|
}
|
2018-10-24 17:24:31 +02:00
|
|
|
} else {
|
2018-11-03 07:26:32 +01:00
|
|
|
console.log('The binary is configured with code cache');
|
2018-10-24 17:24:31 +02:00
|
|
|
assert.strictEqual(
|
|
|
|
typeof process.config.variables.node_code_cache_path,
|
|
|
|
'string'
|
|
|
|
);
|
|
|
|
|
|
|
|
for (const key of loadedModules) {
|
2018-11-03 07:26:32 +01:00
|
|
|
if (cannotUseCache.includes(key)) {
|
|
|
|
assert(compiledWithoutCache.has(key),
|
|
|
|
`"${key}" should've been compiled without code cache`);
|
|
|
|
} else {
|
|
|
|
assert(compiledWithCache.has(key),
|
|
|
|
`"${key}" should've been compiled with code cache`);
|
|
|
|
}
|
2018-10-24 17:24:31 +02:00
|
|
|
}
|
2018-06-18 19:02:57 +02:00
|
|
|
}
|