Skip to content

Commit

Permalink
Port bytecode determinism test to static_h.
Browse files Browse the repository at this point in the history
Summary:
I raised some questions about whether the compiler was deterministic.  Aakash noted that there was a test for the run-to-run determinism of at least the bytecode produced by hermesc in hermes, but that we weren't running it for static_h.

This diff ports that test over to static_h.  I changed the buck rule to be a sh_test, so we could run it as a standard test if we want.

I left the big file it uses, the Fb4a bundle, in the hermes directory.  I figure that we should only have one copy of big files; when we formally retire hermes someday, we can move those files.

allow-large-files

Reviewed By: lavenzg

Differential Revision: D66480990

fbshipit-source-id: a8eeed89a2d82205d9365d8f4d41abbd5f915418
  • Loading branch information
David Detlefs authored and facebook-github-bot committed Dec 3, 2024
1 parent cc426dd commit 663869e
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions test/determinism/test_bytecode_determinism.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

# This test compiles hermes bytecode from a large js bundle several times and
# verifies that the output is always the same.

set -x -e -o pipefail

exec 2>&1

# hermesc binary
HERMESC=$1
# Path to the large js bundle.
JS_BUNDLE=$2
# Number of iterations that we compile from the same source and compare.
NUM_COMP=5

FIRST_HBC="$(mktemp)" || { echo "Failed to create first hbc temp file"; exit 1; }
# Compile first bytecode.
"$HERMESC" -O -target=HBC -emit-binary -Wno-undefined-variable -out "$FIRST_HBC" "$JS_BUNDLE" 2>/dev/null

SECOND_HBC="$(mktemp)" || { echo "Failed to create second hbc temp file"; exit 1; }
for (( i=1; i<=$((NUM_COMP)); i++ ))
do
# Compile second bytecode.
"$HERMESC" -O -target=HBC -emit-binary -Wno-undefined-variable -out "$SECOND_HBC" "$JS_BUNDLE" 2>/dev/null
# Exits with non-zero status if the bytecode files differ.
diff "$FIRST_HBC" "$SECOND_HBC" || { echo "Bytecode diff failed with status $?."; exit 1; }
done
echo "Bytecode looks deterministic. Success!"

0 comments on commit 663869e

Please sign in to comment.