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
43 changes: 38 additions & 5 deletions check.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import sys
import unittest
from collections import OrderedDict
from contextlib import contextmanager
from multiprocessing.pool import ThreadPool
from pathlib import Path

Expand Down Expand Up @@ -219,6 +220,7 @@ def run_one_spec_test(wast: Path, stdout=None):
return # don't try all the binary format stuff TODO
else:
shared.fail_with_error(str(e))
raise

check_expected(actual, expected, stdout=stdout)

Expand Down Expand Up @@ -248,32 +250,63 @@ def run_one_spec_test(wast: Path, stdout=None):


def run_spec_test_with_wrapped_stdout(wast: Path):
'''
Returns (bool, str) where the first element is whether the test was
successful and the second is the combined stdout and stderr of the test.
'''
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The standard format for docstrings is to use tripple-double-quotes, and to include the first line of text on the opening line.

out = io.StringIO()
try:
run_one_spec_test(wast, stdout=out)
except Exception as e:
# Serialize exceptions into the output string buffer
# so they can be reported on the main thread.
print(e, file=out)
raise
return out.getvalue()
return False, out.getvalue()
return True, out.getvalue()


@contextmanager
def red_stdout():
try:
print("\033[31m", end="")
yield
finally:
print("\033[0m", end="")


def run_spec_tests():
print('\n[ checking wasm-shell spec testcases... ]\n')

worker_count = os.cpu_count()
print("Running with", worker_count, "workers")
test_paths = [Path(x) for x in shared.options.spec_tests]
test_paths = (Path(x) for x in shared.options.spec_tests)

failed_stdouts = []
with ThreadPool(processes=worker_count) as pool:
try:
for result in pool.imap_unordered(run_spec_test_with_wrapped_stdout, test_paths):
print(result, end="")
for success, stdout in pool.imap_unordered(run_spec_test_with_wrapped_stdout, test_paths):
if success:
print(stdout, end="")
continue

failed_stdouts.append(stdout)
if shared.options.abort_on_first_failure:
with red_stdout():
print("Aborted tests execution after first failure. Set --no-fail-fast to disable this.")
break
except KeyboardInterrupt:
# Hard exit to avoid threads continuing to run after Ctrl-C.
# There's no concern of deadlocking during shutdown here.
os._exit(1)

if not failed_stdouts:
return

with red_stdout():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would maybe combine theese:

if failed_stdouts:
   with red_stdout():
       ...

I guess early return is good.. but in this case there is only one following block.

print("Failed tests:")
for failed in failed_stdouts:
print(failed, end="")


def run_validator_tests():
print('\n[ running validation tests... ]\n')
Expand Down
4 changes: 2 additions & 2 deletions scripts/test/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ def parse_args(args):
'--no-torture', dest='torture', action='store_false',
help='Disables running the torture testcases.')
parser.add_argument(
'--abort-on-first-failure', dest='abort_on_first_failure',
'--abort-on-first-failure', "--fail-fast", dest='abort_on_first_failure',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Single quotes here.

Also, I think we can just remove the old name here... the number folks who run this script is small enough we don't need to worry about back compat.

Also, you can use argparse.BooleanOptionalAction here maybe?

action='store_true', default=True,
help=('Specifies whether to halt test suite execution on first test error.'
' Default: true.'))
parser.add_argument(
'--no-abort-on-first-failure', dest='abort_on_first_failure',
'--no-abort-on-first-failure', "--no-fail-fast", dest='abort_on_first_failure',
action='store_false',
help=('If set, the whole test suite will run to completion independent of'
' earlier errors.'))
Expand Down
Loading