Skip to content

Commit

Permalink
Merge pull request #7836 from Agoric/mfig-i-can-haz-builtin
Browse files Browse the repository at this point in the history
Prevent `__has_builtin` compiler differences from causing divergence
  • Loading branch information
michaelfig authored Jun 27, 2023
2 parents dcddffd + a2b48e1 commit a6737cd
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/xsnap/src/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
],
Expand Down
15 changes: 15 additions & 0 deletions packages/xsnap/test/snapshots/test-xsnap.js.md
Original file line number Diff line number Diff line change
@@ -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'
Binary file added packages/xsnap/test/snapshots/test-xsnap.js.snap
Binary file not shown.
50 changes: 50 additions & 0 deletions packages/xsnap/test/test-xsnap.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import '@endo/init/debug.js';
// eslint-disable-next-line import/no-extraneous-dependencies
import test from 'ava';

import { createHash } from 'crypto';
import * as proc from 'child_process';
import * as os from 'os';
import fs from 'fs';
Expand Down Expand Up @@ -302,6 +303,55 @@ const writeAndReadSnapshot = async (t, snapshotUseFs) => {
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) {
Expand Down

0 comments on commit a6737cd

Please sign in to comment.