summaryrefslogtreecommitdiff
path: root/scripts/port_passes_tests_to_lit.py
diff options
context:
space:
mode:
authorThomas Lively <7121787+tlively@users.noreply.github.com>2021-07-03 00:28:22 +0000
committerGitHub <noreply@github.com>2021-07-03 00:28:22 +0000
commitcdf9ee0fdff72384d2192fb32c20bf05287dba97 (patch)
treea712038e96001e5bc0f9741be61d65bbc7313c05 /scripts/port_passes_tests_to_lit.py
parent643b96736b7b5b75b91ab35ee926154eb33492e0 (diff)
downloadbinaryen-cdf9ee0fdff72384d2192fb32c20bf05287dba97.tar.gz
binaryen-cdf9ee0fdff72384d2192fb32c20bf05287dba97.tar.bz2
binaryen-cdf9ee0fdff72384d2192fb32c20bf05287dba97.zip
Add a script for porting passes tests to lit (#3963)
And use it to port the very simple untee test.
Diffstat (limited to 'scripts/port_passes_tests_to_lit.py')
-rwxr-xr-xscripts/port_passes_tests_to_lit.py110
1 files changed, 110 insertions, 0 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()