diff options
author | Max Graey <maxgraey@gmail.com> | 2021-08-27 00:45:29 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-26 14:45:29 -0700 |
commit | 81c10c3db2b1e8aa07d7526332f0350cb0a4306a (patch) | |
tree | 636bad4d30d52201808a49c899a1be6b9dc02a0a | |
parent | 94cf0c2801f784209755d1527d3eda78a38b8034 (diff) | |
download | binaryen-81c10c3db2b1e8aa07d7526332f0350cb0a4306a.tar.gz binaryen-81c10c3db2b1e8aa07d7526332f0350cb0a4306a.tar.bz2 binaryen-81c10c3db2b1e8aa07d7526332f0350cb0a4306a.zip |
[fuzz-opt] Better error output for non-deterministic check (#4102)
When we catches "Output must be deterministic" we can't see any details. This PR fix
this and now we can see diff of b1.wasm and b2.wasm files.
Example output:
Output must be deterministic.
Diff:
--- expected
+++ actual
@@ -2072,9 +2072,7 @@
)
(drop
(block $label$16 (result funcref)
- (local.set $10
- (ref.null func)
- )
+ (nop)
(drop
(call $22
(f64.const 0.296)
-rwxr-xr-x | scripts/fuzz_opt.py | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/scripts/fuzz_opt.py b/scripts/fuzz_opt.py index fc2192137..3e2d83e34 100755 --- a/scripts/fuzz_opt.py +++ b/scripts/fuzz_opt.py @@ -296,13 +296,16 @@ FUZZ_EXEC_CALL_PREFIX = '[fuzz-exec] calling' # compare two strings, strictly -def compare(x, y, context): +def compare(x, y, context, verbose=True): if x != y and x != IGNORE and y != IGNORE: message = ''.join([a + '\n' for a in difflib.unified_diff(x.splitlines(), y.splitlines(), fromfile='expected', tofile='actual')]) - raise Exception(context + " comparison error, expected to have '%s' == '%s', diff:\n\n%s" % ( - x, y, - message - )) + if verbose: + raise Exception(context + " comparison error, expected to have '%s' == '%s', diff:\n\n%s" % ( + x, y, + message + )) + else: + raise Exception(context + "\nDiff:\n\n%s" % (message)) # converts a possibly-signed integer to an unsigned integer @@ -713,7 +716,14 @@ class CheckDeterminism(TestCaseHandler): # check for determinism run([in_bin('wasm-opt'), before_wasm, '-o', 'b1.wasm'] + opts) run([in_bin('wasm-opt'), before_wasm, '-o', 'b2.wasm'] + opts) - assert open('b1.wasm', 'rb').read() == open('b2.wasm', 'rb').read(), 'output must be deterministic' + b1 = open('b1.wasm', 'rb').read() + b2 = open('b2.wasm', 'rb').read() + if (b1 != b2): + run([in_bin('wasm-dis'), 'b1.wasm', '-o', 'b1.wat']) + run([in_bin('wasm-dis'), 'b2.wasm', '-o', 'b2.wat']) + t1 = open('b1.wat', 'r').read() + t2 = open('b2.wat', 'r').read() + compare(t1, t2, 'Output must be deterministic.', verbose=False) class Wasm2JS(TestCaseHandler): |