Skip to content
Open
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
14 changes: 7 additions & 7 deletions check.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -249,20 +249,20 @@ 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
transformed_spec_file.write(result_wast + '\n' + '\n'.join(asserts))

# 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):
Expand Down
18 changes: 13 additions & 5 deletions scripts/test/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
Expand Down Expand Up @@ -466,30 +474,30 @@ 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)
assert os.path.exists(disassembled_file)

# 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:
Expand Down
Loading