-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bootstrap: make snapshot reproducible
This patch uses the new V8 API to {de}serialize context slots for snapshot in order to make the snapshot reproducible. Also added a test for the reproducibility of snapshots.
- Loading branch information
1 parent
759ee85
commit 9c8ab5e
Showing
4 changed files
with
121 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
'use strict'; | ||
|
||
require('../common'); | ||
const { spawnSyncAndExitWithoutError } = require('../common/child_process'); | ||
const tmpdir = require('../common/tmpdir'); | ||
const fs = require('fs'); | ||
const assert = require('assert'); | ||
const fixtures = require('../common/fixtures'); | ||
|
||
function generateSnapshot() { | ||
tmpdir.refresh(); | ||
|
||
spawnSyncAndExitWithoutError( | ||
process.execPath, | ||
[ | ||
'--random_seed=42', | ||
'--predictable', | ||
'--build-snapshot', | ||
'node:generate_default_snapshot', | ||
], | ||
{ | ||
cwd: tmpdir.path | ||
} | ||
); | ||
const blobPath = tmpdir.resolve('snapshot.blob'); | ||
return fs.readFileSync(blobPath); | ||
} | ||
|
||
const buf1 = generateSnapshot(); | ||
const buf2 = generateSnapshot(); | ||
const diff = []; | ||
let offset = 0; | ||
const step = 16; | ||
do { | ||
const length = Math.min(buf1.length - offset, step); | ||
const slice1 = buf1.slice(offset, offset + length).toString('hex'); | ||
const slice2 = buf2.slice(offset, offset + length).toString('hex'); | ||
if (slice1 != slice2) { | ||
diff.push({offset, slice1, slice2}); | ||
Check failure on line 39 in test/parallel/test-snapshot-reproducible.js GitHub Actions / lint-js-and-md
|
||
} | ||
offset += length; | ||
} while (offset < buf1.length); | ||
|
||
assert.strictEqual(offset, buf1.length); | ||
if (offset < buf2.length) { | ||
const length = Math.min(buf2.length - offset, step); | ||
const slice2 = buf2.slice(offset, offset + length).toString('hex'); | ||
diff.push({offset, slice1: '', slice2}); | ||
Check failure on line 48 in test/parallel/test-snapshot-reproducible.js GitHub Actions / lint-js-and-md
|
||
offset += length; | ||
} while (offset < buf2.length); | ||
|
||
assert.deepStrictEqual(diff, [], 'Built-in snapshot should not change in different builds.'); | ||
Check failure on line 52 in test/parallel/test-snapshot-reproducible.js GitHub Actions / test-ubsan
Check failure on line 52 in test/parallel/test-snapshot-reproducible.js GitHub Actions / test-linux
|
||
assert.strictEqual(buf1.length, buf2.length); |