diff --git a/check.py b/check.py index 3bf3bafcf5b..dddddb424f0 100755 --- a/check.py +++ b/check.py @@ -189,10 +189,10 @@ def run_opt_test(wast, stdout=None): support.run_command(cmd, stdout=stdout) -def check_expected(actual, expected, stdout=None): +def check_expected(actual, expected): if expected and os.path.exists(expected): expected = open(expected).read() - print(' (using expected output)', file=stdout) + shared.verbose_log(' (using expected output)') actual = actual.strip() expected = expected.strip() if actual != expected: @@ -229,13 +229,13 @@ def run_one_spec_test(wast: Path, stdout=None): actual = run_spec_test(str(wast), stdout=stdout) except Exception as e: if ('wasm-validator error' in str(e) or 'error: ' in str(e)) and '.fail.' in test_name: - print('<< test failed as expected >>', file=stdout) + shared.verbose_log('<< test failed as expected >>') return # don't try all the binary format stuff TODO else: shared.fail_with_error(str(e)) raise - check_expected(actual, expected, stdout=stdout) + check_expected(actual, expected) if not is_splittable(wast): return @@ -249,12 +249,12 @@ def run_one_spec_test(wast: Path, stdout=None): if not module: # Skip any initial assertions that don't have a module continue - print(f' testing split module {i}', file=stdout) + shared.verbose_log(f' testing split module {i}') split_name = base_name + f'_split{i}.wast' support.write_wast(split_name, module) run_opt_test(split_name, stdout=stdout) # also that our optimizer doesn't break on it - result_wast_file = shared.binary_format_check(split_name, verify_final_result=False, base_name=base_name, stdout=stdout) + result_wast_file = shared.binary_format_check(split_name, verify_final_result=False, base_name=base_name) with open(result_wast_file) as f: result_wast = f.read() # add the asserts, and verify that the test still passes @@ -262,7 +262,7 @@ def run_one_spec_test(wast: Path, stdout=None): # compare all the outputs to the expected output actual = run_spec_test(transformed_path, stdout=stdout) - check_expected(actual, os.path.join(shared.get_test_dir('spec'), 'expected-output', test_name + '.log'), stdout=stdout) + check_expected(actual, os.path.join(shared.get_test_dir('spec'), 'expected-output', test_name + '.log')) def run_spec_test_with_wrapped_stdout(wast: Path): diff --git a/scripts/test/shared.py b/scripts/test/shared.py index 4786bf2c755..d97bafb98a7 100644 --- a/scripts/test/shared.py +++ b/scripts/test/shared.py @@ -97,6 +97,9 @@ def parse_args(args): action='store_false', default=True, help='Disables the automatic selection of important initial contents ' 'in fuzzer.') + parser.add_argument( + '--verbose', action='store_true', default=False, + help='Enables verbose logging.') return parser.parse_args(args) @@ -118,6 +121,11 @@ def print_heading(msg): print(f'[ {msg} ]') +def verbose_log(*args, **kwargs): + if options.verbose: + print(*args, **kwargs) + + # setup # Locate Binaryen build artifacts directory (bin/ by default) @@ -466,22 +474,22 @@ def _can_run_spec_test(test): # check utilities -def binary_format_check(wast, verify_final_result=True, base_name=None, stdout=None): +def binary_format_check(wast, verify_final_result=True, base_name=None): # checks we can convert the wast to binary and back as_file = f"{base_name}-a.wasm" if base_name is not None else "a.wasm" disassembled_file = f"{base_name}-ab.wast" if base_name is not None else "ab.wast" - print(' (binary format check)', file=stdout) + verbose_log(' (binary format check)') cmd = WASM_AS + [wast, '-o', as_file, '-all', '-g'] - print(' ', ' '.join(cmd), file=stdout) + verbose_log(' ', ' '.join(cmd)) if os.path.exists(as_file): os.unlink(as_file) subprocess.check_call(cmd, stdout=subprocess.PIPE) assert os.path.exists(as_file) cmd = WASM_DIS + [as_file, '-o', disassembled_file, '-all'] - print(' ', ' '.join(cmd), file=stdout) + verbose_log(' ', ' '.join(cmd)) if os.path.exists(disassembled_file): os.unlink(disassembled_file) subprocess.check_call(cmd, stdout=subprocess.PIPE) @@ -489,7 +497,7 @@ def binary_format_check(wast, verify_final_result=True, base_name=None, stdout=N # make sure it is a valid wast cmd = WASM_OPT + [disassembled_file, '-all', '-q'] - print(' ', ' '.join(cmd), file=stdout) + verbose_log(' ', ' '.join(cmd)) subprocess.check_call(cmd, stdout=subprocess.PIPE) if verify_final_result: