From 8c0a9a40835d6e9d78fe812ed3f26605ee7b866b Mon Sep 17 00:00:00 2001 From: Michael FIG Date: Wed, 24 May 2023 19:44:26 -0600 Subject: [PATCH 1/2] test(xsnap): check trivial snapshot golden hashes --- .../xsnap/test/snapshots/test-xsnap.js.md | 15 ++++++ .../xsnap/test/snapshots/test-xsnap.js.snap | Bin 0 -> 318 bytes packages/xsnap/test/test-xsnap.js | 50 ++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 packages/xsnap/test/snapshots/test-xsnap.js.md create mode 100644 packages/xsnap/test/snapshots/test-xsnap.js.snap diff --git a/packages/xsnap/test/snapshots/test-xsnap.js.md b/packages/xsnap/test/snapshots/test-xsnap.js.md new file mode 100644 index 00000000000..eec90719b35 --- /dev/null +++ b/packages/xsnap/test/snapshots/test-xsnap.js.md @@ -0,0 +1,15 @@ +# Snapshot report for `test/test-xsnap.js` + +The actual snapshot is saved in `test-xsnap.js.snap`. + +Generated by [AVA](https://avajs.dev). + +## produce golden snapshot hashes + +> no evaluations + + '91d30e59c1a087d58bb6d8eefcf1262e99e59cfc249222ab25f881ac642437e5' + +> smallish safeInteger multiplication doesn't spill to XS_NUMBER_KIND + + '4b48f6c58c08bb757efd3b8fb21891a386bdc5bfbae6803c8cb7df108e553ace' diff --git a/packages/xsnap/test/snapshots/test-xsnap.js.snap b/packages/xsnap/test/snapshots/test-xsnap.js.snap new file mode 100644 index 0000000000000000000000000000000000000000..c4e93b1b54a770305f26642187162713e2c3522c GIT binary patch literal 318 zcmV-E0m1%3RzV~~R{?8M2`y&^ z9<0TJ%i(NxF*{~{KD(UX^wQQ9>z*W5&{++}v=*2hIjLI3eSaJssis#-p;6iaNTjw= zP2I8PfQCbiN$@*{9TuNr{-0`01Fj_vRQ)KO?%3JdfHO)$FR_N!SklHB { test('write and read snapshot (use FS)', writeAndReadSnapshot, true); test('write and read snapshot (use stream)', writeAndReadSnapshot, false); +test('produce golden snapshot hashes', async t => { + t.log(`\ +The snapshot hashes produced by this test were created from this package's +version of xsnap compiled for and run on Agoric's supported (within-consensus) +platforms. + +The snapshot will change (and the test will fail) if xsnap or this platform +is not compatible with this predefined consensus. This is likely to happen +in the future when xsnap is upgraded, in which case there will need to be +special accommodation for the new version, not just generating new golden +hashes. +`); + const toEvals = [ + [`no evaluations`, ''], + [ + `smallish safeInteger multiplication doesn't spill to XS_NUMBER_KIND`, + `globalThis.bazinga = 100; globalThis.bazinga *= 1_000_000;`, + ], + ]; + for await (const [description, toEval] of toEvals) { + t.log(description); + const messages = []; + async function handleCommand(message) { + messages.push(decode(message)); + return new Uint8Array(); + } + + const vat0 = await xsnap({ + ...options(io), + handleCommand, + snapshotUseFs: false, + }); + if (toEval) { + await vat0.evaluate(toEval); + } + + const hash = createHash('sha256'); + for await (const buf of vat0.makeSnapshotStream()) { + hash.update(buf); + } + await vat0.close(); + + const hexHash = hash.digest('hex'); + t.log(`${description} produces golden hash ${hexHash}`); + t.snapshot(hexHash, description); + t.deepEqual(messages, [], `${description} messages`); + } +}); + test('execute immediately after makeSnapshotStream', async t => { const messages = []; async function handleCommand(message) { From a2b48e1793e4a95e10a47a3650278e24e20e974a Mon Sep 17 00:00:00 2001 From: Michael FIG Date: Wed, 24 May 2023 19:50:31 -0600 Subject: [PATCH 2/2] build(xsnap): use `-D__has_builtin(x)=1` to avoid divergence --- packages/xsnap/src/build.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/xsnap/src/build.js b/packages/xsnap/src/build.js index db1c060dd11..b2b95361581 100644 --- a/packages/xsnap/src/build.js +++ b/packages/xsnap/src/build.js @@ -230,6 +230,7 @@ async function main(args, { env, stdout, spawn, fs, os }) { `MODDABLE=${ModdableSDK.MODDABLE}`, `GOAL=${goal}`, `XSNAP_VERSION=${pkg.version}`, + `CC=cc "-D__has_builtin(x)=1"`, '-f', 'xsnap-worker.mk', ],