-
Notifications
You must be signed in to change notification settings - Fork 830
Print failed test results at the end for the spec test suite #8154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
||
|
|
@@ -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) | ||
|
|
||
|
|
@@ -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. | ||
| ''' | ||
| 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(): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would maybe combine theese: 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') | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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', | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| 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.')) | ||
|
|
||
There was a problem hiding this comment.
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.