Skip to content

Commit

Permalink
test/run-roundtrip.py: test roundtrip even with --stdout
Browse files Browse the repository at this point in the history
  • Loading branch information
keithw committed Nov 8, 2024
1 parent 765b47d commit e83a148
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
8 changes: 7 additions & 1 deletion test/regress/write-memuse.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
;;; TOOL: run-roundtrip
;;; ARGS*: --enable-multi-memory --debug-names
;;; ARGS*: --enable-multi-memory --debug-names --stdout
(memory 0)
(memory $k (data))
(;; STDOUT ;;;
(module
(memory (;0;) 0)
(memory $k 0 0)
(data (;0;) (memory $k) (i32.const 0) ""))
;;; STDOUT ;;)
20 changes: 12 additions & 8 deletions test/run-roundtrip.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def FilesAreEqual(filename1, filename2, verbose=False):
return (OK, '')


def DoRoundtrip(wat2wasm, wasm2wat, out_dir, filename, verbose, stdout):
def DoRoundtrip(wat2wasm, wasm2wat, out_dir, filename, verbose, stdout, skip_roundtrip_check):
basename = os.path.basename(filename)
basename_noext = os.path.splitext(basename)[0]
wasm1_file = os.path.join(out_dir, basename_noext + '-1.wasm')
Expand All @@ -75,10 +75,9 @@ def DoRoundtrip(wat2wasm, wasm2wat, out_dir, filename, verbose, stdout):
if stdout:
with open(wat2_file) as f:
sys.stdout.write(f.read())
if skip_roundtrip_check:
return (OK, '')
else:
return FilesAreEqual(wasm1_file, wasm3_file, verbose)

return FilesAreEqual(wasm1_file, wasm3_file, verbose)

def main(args):
parser = argparse.ArgumentParser()
Expand All @@ -90,7 +89,7 @@ def main(args):
default=find_exe.GetDefaultPath(),
help='directory to search for all executables.')
parser.add_argument('--stdout', action='store_true',
help='do one roundtrip and write wat output to stdout')
help='write wat output to stdout')
parser.add_argument('--no-error-cmdline',
help='don\'t display the subprocess\'s commandline when '
'an error occurs', dest='error_cmdline',
Expand All @@ -100,7 +99,9 @@ def main(args):
action='store_true')
parser.add_argument('--no-check', action='store_true')
parser.add_argument('--debug-names', action='store_true')
parser.add_argument('--generate-names', action='store_true')
# --generate-names modifies name section, so skip roundtrip check
parser.add_argument('--generate-names', action='store_true',
help="write debug names and skip end-to-end roundtrip check")
parser.add_argument('--fold-exprs', action='store_true')
parser.add_argument('--enable-exceptions', action='store_true')
parser.add_argument('--enable-saturating-float-to-int', action='store_true')
Expand All @@ -115,7 +116,9 @@ def main(args):
parser.add_argument('--enable-annotations', action='store_true')
parser.add_argument('--enable-code-metadata', action='store_true')
parser.add_argument('--enable-custom-page-sizes', action='store_true')
parser.add_argument('--inline-exports', action='store_true')
# --inline-exports can reorder exports, so skip roundtrip check
parser.add_argument('--inline-exports', action='store_true',
help="write exports inline and skip end-to-end roundtrip check")
parser.add_argument('--inline-imports', action='store_true')
parser.add_argument('--reloc', action='store_true')
parser.add_argument('file', help='test file.')
Expand Down Expand Up @@ -178,9 +181,10 @@ def main(args):
sys.stderr.write('File not found: %s\n' % filename)
return ERROR

skip_roundtrip_check = options.generate_names or options.inline_exports
with utils.TempDirectory(options.out_dir, 'roundtrip-') as out_dir:
result, msg = DoRoundtrip(wat2wasm, wasm2wat, out_dir, filename,
options.verbose, options.stdout)
options.verbose, options.stdout, skip_roundtrip_check)
if result == ERROR:
sys.stderr.write(msg)
return result
Expand Down

0 comments on commit e83a148

Please sign in to comment.