diff options
-rwxr-xr-x | scripts/port_passes_tests_to_lit.py | 110 | ||||
-rw-r--r-- | test/lit/passes/untee.wast | 63 | ||||
-rw-r--r-- | test/passes/untee.txt | 47 | ||||
-rw-r--r-- | test/passes/untee.wast | 12 |
4 files changed, 173 insertions, 59 deletions
diff --git a/scripts/port_passes_tests_to_lit.py b/scripts/port_passes_tests_to_lit.py new file mode 100755 index 000000000..bfd0714e0 --- /dev/null +++ b/scripts/port_passes_tests_to_lit.py @@ -0,0 +1,110 @@ +#!/usr/bin/env python3 +# Copyright 2021 WebAssembly Community Group participants +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Automatically port legacy passes tests to be lit tests +""" + +import argparse +import glob +import os +import subprocess +import sys + + +script_dir = os.path.dirname(__file__) +test_dir = os.path.join(os.path.dirname(script_dir), 'test') + + +def warn(msg): + print(f'WARNING: {msg}', file=sys.stderr) + + +def port_test(args, test): + name = os.path.basename(test) + base = name.replace('.wast', '') + print('..', name) + + if not test.endswith('.wast'): + warn('Skipping because only .wast files are supported') + return + + if 'translate-to-fuzz' in test or 'dwarf' in test: + warn('Skipping due to Windows issues') + return + + if 'noprint' in test: + warn('Skipping due to nonstandard output') + return + + dest = os.path.join(test_dir, 'lit', 'passes', name) + if not args.force and os.path.exists(dest): + warn('Skipping because destination file already exist') + return + + joined_passes = base + passes_file = os.path.join(test_dir, 'passes', base + '.passes') + if os.path.exists(passes_file): + with open(passes_file) as f: + joined_passes = f.read().strip() + + passes = joined_passes.split('_') + opts = [('--' + p if not p.startswith('O') and p != 'g' else '-' + p) + for p in passes] + + run_line = (f';; RUN: foreach %s %t wasm-opt {" ".join(opts)} -S -o -' + ' | filecheck %s') + + notice = (f';; NOTE: This test was ported using port_test.py and could be' + ' cleaned up.') + + with open(test, 'r') as src_file: + with open(dest, 'w') as dest_file: + print(notice, file=dest_file) + print('', file=dest_file) + print(run_line, file=dest_file) + print('', file=dest_file) + print(src_file.read(), file=dest_file, end='') + + update_script = os.path.join(script_dir, 'update_lit_checks.py') + subprocess.run([sys.executable, update_script, '-f', '--all-items', dest]) + + if not args.no_delete: + for f in glob.glob(test.replace('.wast', '.*')): + os.remove(f) + if args.git_add: + subprocess.run(['git', 'add', f]) + + if args.git_add: + subprocess.run(['git', 'add', dest]) + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('-f', '--force', action='store_true', + help='Overwrite existing lit tests') + parser.add_argument('--no-delete', action='store_true', + help='Do not remove the old tests') + parser.add_argument('--git-add', action='store_true', + help='Stage changes') + parser.add_argument('tests', nargs='+', help='The test files to port') + args = parser.parse_args() + + for pattern in args.tests: + for test in glob.glob(pattern, recursive=True): + port_test(args, test) + + +if __name__ == '__main__': + main() diff --git a/test/lit/passes/untee.wast b/test/lit/passes/untee.wast new file mode 100644 index 000000000..a352aa84a --- /dev/null +++ b/test/lit/passes/untee.wast @@ -0,0 +1,63 @@ +;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited. +;; NOTE: This test was ported using port_test.py and could be cleaned up. + +;; RUN: foreach %s %t wasm-opt --untee -S -o - | filecheck %s + +(module + ;; CHECK: (type $none_=>_none (func)) + + ;; CHECK: (func $tee + ;; CHECK-NEXT: (local $x i32) + ;; CHECK-NEXT: (local $y f64) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (block (result i32) + ;; CHECK-NEXT: (local.set $x + ;; CHECK-NEXT: (i32.const 1) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (local.get $x) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (block (result f64) + ;; CHECK-NEXT: (local.set $y + ;; CHECK-NEXT: (f64.const 2) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (local.get $y) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (local.set $x + ;; CHECK-NEXT: (block (result i32) + ;; CHECK-NEXT: (local.set $x + ;; CHECK-NEXT: (i32.const 3) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (local.get $x) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (local.set $x + ;; CHECK-NEXT: (block (result i32) + ;; CHECK-NEXT: (local.set $x + ;; CHECK-NEXT: (block (result i32) + ;; CHECK-NEXT: (local.set $x + ;; CHECK-NEXT: (i32.const 3) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (local.get $x) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (local.get $x) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (unreachable) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + (func $tee + (local $x i32) + (local $y f64) + (drop (local.tee $x (i32.const 1))) + (drop (local.tee $y (f64.const 2))) + (local.set $x (local.tee $x (i32.const 3))) + (local.set $x (local.tee $x (local.tee $x (i32.const 3)))) + (drop (local.tee $x (unreachable))) + ) +) + diff --git a/test/passes/untee.txt b/test/passes/untee.txt deleted file mode 100644 index f4b4b3fe8..000000000 --- a/test/passes/untee.txt +++ /dev/null @@ -1,47 +0,0 @@ -(module - (type $none_=>_none (func)) - (func $tee - (local $x i32) - (local $y f64) - (drop - (block (result i32) - (local.set $x - (i32.const 1) - ) - (local.get $x) - ) - ) - (drop - (block (result f64) - (local.set $y - (f64.const 2) - ) - (local.get $y) - ) - ) - (local.set $x - (block (result i32) - (local.set $x - (i32.const 3) - ) - (local.get $x) - ) - ) - (local.set $x - (block (result i32) - (local.set $x - (block (result i32) - (local.set $x - (i32.const 3) - ) - (local.get $x) - ) - ) - (local.get $x) - ) - ) - (drop - (unreachable) - ) - ) -) diff --git a/test/passes/untee.wast b/test/passes/untee.wast deleted file mode 100644 index 6b66ccf84..000000000 --- a/test/passes/untee.wast +++ /dev/null @@ -1,12 +0,0 @@ -(module - (func $tee - (local $x i32) - (local $y f64) - (drop (local.tee $x (i32.const 1))) - (drop (local.tee $y (f64.const 2))) - (local.set $x (local.tee $x (i32.const 3))) - (local.set $x (local.tee $x (local.tee $x (i32.const 3)))) - (drop (local.tee $x (unreachable))) - ) -) - |