diff options
author | Refael Ackermann <refack@gmail.com> | 2019-04-07 15:02:04 -0400 |
---|---|---|
committer | Refael Ackermann <refack@gmail.com> | 2019-04-16 18:25:04 -0400 |
commit | 14df42fd008ef8e95d60d0d70084943d180bab91 (patch) | |
tree | b536d1a90d19190599970fd2659345248885d35f /test/parallel/test-code-cache.js | |
parent | 5ac0308af90c2ab9842682d06a720cfab11eb661 (diff) | |
download | android-node-v8-14df42fd008ef8e95d60d0d70084943d180bab91.tar.gz android-node-v8-14df42fd008ef8e95d60d0d70084943d180bab91.tar.bz2 android-node-v8-14df42fd008ef8e95d60d0d70084943d180bab91.zip |
build: run `mkcodecache` as an action
* fix test-code-cache (for the common cases)
* deprecate `configure --code-cache-path`
PR-URL: https://github.com/nodejs/node/pull/27161
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Diffstat (limited to 'test/parallel/test-code-cache.js')
-rw-r--r-- | test/parallel/test-code-cache.js | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/test/parallel/test-code-cache.js b/test/parallel/test-code-cache.js new file mode 100644 index 0000000000..f120b76af2 --- /dev/null +++ b/test/parallel/test-code-cache.js @@ -0,0 +1,71 @@ +// Flags: --expose-internals +'use strict'; + +// 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. + +const { isMainThread } = require('../common'); +const assert = require('assert'); +const { + internalBinding +} = require('internal/test/binding'); +const { + getCacheUsage, + moduleCategories: { canBeRequired, cannotBeRequired } +} = internalBinding('native_module'); + +for (const key of canBeRequired) { + require(key); +} + +// The computation has to be delayed until we have done loading modules +const { + compiledWithoutCache, + compiledWithCache +} = getCacheUsage(); + +const loadedModules = process.moduleLoadList + .filter((m) => m.startsWith('NativeModule')) + .map((m) => m.replace('NativeModule ', '')); + +// Cross-compiled binaries do not have code cache, verifies that the builtins +// are all compiled without cache and we are doing the bookkeeping right. +if (process.config.variables.want_separate_host_toolset === 1) { + console.log('The binary is not configured with code cache'); + if (isMainThread) { + assert.deepStrictEqual(compiledWithCache, new Set()); + for (const key of loadedModules) { + assert(compiledWithoutCache.has(key), + `"${key}" should've been compiled without code cache`); + } + } else { + // TODO(joyeecheung): create a list of modules whose cache can be shared + // from the main thread to the worker thread and check that their + // cache are hit + assert.notDeepStrictEqual(compiledWithCache, new Set()); + } +} else { // Native compiled + assert.strictEqual( + process.config.variables.node_code_cache_path, + 'yes' + ); + + if (!isMainThread) { + for (const key of [ 'internal/bootstrap/pre_execution' ]) { + canBeRequired.add(key); + cannotBeRequired.delete(key); + } + } + + const wrong = []; + for (const key of loadedModules) { + if (cannotBeRequired.has(key) && !compiledWithoutCache.has(key)) { + wrong.push(`"${key}" should've been compiled **without** code cache`); + } + if (canBeRequired.has(key) && !compiledWithCache.has(key)) { + wrong.push(`"${key}" should've been compiled **with** code cache`); + } + } + assert.strictEqual(wrong.length, 0, wrong.join('\n')); +} |