Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 110 additions & 0 deletions scripts/port_passes_tests_to_lit.py
Original file line number Diff line number Diff line change
@@ -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()
63 changes: 63 additions & 0 deletions test/lit/passes/untee.wast
Original file line number Diff line number Diff line change
@@ -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)))
)
)

47 changes: 0 additions & 47 deletions test/passes/untee.txt

This file was deleted.

12 changes: 0 additions & 12 deletions test/passes/untee.wast

This file was deleted.