Skip to content

Commit 0add6d8

Browse files
committed
Add print_heading testsuite helper. NFC
1 parent 37cf5df commit 0add6d8

7 files changed

Lines changed: 61 additions & 36 deletions

File tree

check.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from pathlib import Path
2727

2828
from scripts.test import binaryenjs, finalize, shared, support, wasm2js, wasm_opt
29+
from scripts.test.shared import print_heading
2930

3031
assert sys.version_info >= (3, 10), 'requires Python 3.10'
3132

@@ -41,7 +42,7 @@ def get_changelog_version():
4142

4243

4344
def run_version_tests():
44-
print('[ checking --version ... ]\n')
45+
print_heading('checking --version ...')
4546

4647
not_executable_suffix = ['.DS_Store', '.txt', '.js', '.ilk', '.pdb', '.dll', '.wasm', '.manifest']
4748
executable_prefix = ['wasm']
@@ -67,7 +68,7 @@ def run_version_tests():
6768

6869

6970
def run_wasm_dis_tests():
70-
print('\n[ checking wasm-dis on provided binaries... ]\n')
71+
print_heading('checking wasm-dis on provided binaries...')
7172

7273
for t in shared.get_tests(shared.options.binaryen_test, ['.wasm']):
7374
print('..', os.path.basename(t))
@@ -85,7 +86,7 @@ def run_wasm_dis_tests():
8586

8687

8788
def run_crash_tests():
88-
print("\n[ checking we don't crash on tricky inputs... ]\n")
89+
print_heading("checking we don't crash on tricky inputs...")
8990

9091
for t in shared.get_tests(shared.get_test_dir('crash'), ['.wast', '.wasm']):
9192
print('..', os.path.basename(t))
@@ -95,7 +96,7 @@ def run_crash_tests():
9596

9697

9798
def run_dylink_tests():
98-
print("\n[ we emit dylink sections properly... ]\n")
99+
print_heading('we emit dylink sections properly...')
99100

100101
dylink_tests = glob.glob(os.path.join(shared.options.binaryen_test, 'dylib*.wasm'))
101102
for t in sorted(dylink_tests):
@@ -109,7 +110,7 @@ def run_dylink_tests():
109110

110111

111112
def run_ctor_eval_tests():
112-
print('\n[ checking wasm-ctor-eval... ]\n')
113+
print_heading('checking wasm-ctor-eval...')
113114

114115
for t in shared.get_tests(shared.get_test_dir('ctor-eval'), ['.wast', '.wasm']):
115116
print('..', os.path.basename(t))
@@ -126,7 +127,7 @@ def run_ctor_eval_tests():
126127

127128

128129
def run_wasm_metadce_tests():
129-
print('\n[ checking wasm-metadce ]\n')
130+
print_heading('checking wasm-metadce')
130131

131132
for t in shared.get_tests(shared.get_test_dir('metadce'), ['.wast', '.wasm']):
132133
print('..', os.path.basename(t))
@@ -141,10 +142,10 @@ def run_wasm_metadce_tests():
141142

142143
def run_wasm_reduce_tests():
143144
if not shared.has_shell_timeout():
144-
print('\n[ skipping wasm-reduce testcases]\n')
145+
print_heading('skipping wasm-reduce testcases')
145146
return
146147

147-
print('\n[ checking wasm-reduce testcases]\n')
148+
print_heading('checking wasm-reduce testcases')
148149

149150
# fixed testcases
150151
for t in shared.get_tests(shared.get_test_dir('reduce'), ['.wast']):
@@ -161,7 +162,7 @@ def run_wasm_reduce_tests():
161162
# run on a nontrivial fuzz testcase, for general coverage
162163
# this is very slow in ThreadSanitizer, so avoid it there
163164
if 'fsanitize=thread' not in str(os.environ):
164-
print('\n[ checking wasm-reduce fuzz testcase ]\n')
165+
print_heading('checking wasm-reduce fuzz testcase')
165166
# TODO: re-enable multivalue once it is better optimized
166167
support.run_command(shared.WASM_OPT + [os.path.join(shared.options.binaryen_test, 'lit/basic/signext.wast'), '-ttf', '-Os', '-o', 'a.wasm', '--detect-features', '--disable-multivalue'])
167168
before = os.stat('a.wasm').st_size
@@ -294,7 +295,7 @@ def red_stderr():
294295

295296

296297
def run_spec_tests():
297-
print('\n[ checking wasm-shell spec testcases... ]\n')
298+
print_heading('checking wasm-shell spec testcases...')
298299

299300
worker_count = os.cpu_count()
300301
print("Running with", worker_count, "workers")
@@ -326,7 +327,7 @@ def run_spec_tests():
326327

327328

328329
def run_validator_tests():
329-
print('\n[ running validation tests... ]\n')
330+
print_heading('running validation tests...')
330331
# Ensure the tests validate by default
331332
cmd = shared.WASM_AS + [os.path.join(shared.get_test_dir('validator'), 'invalid_export.wast'), '-o', 'a.wasm']
332333
support.run_command(cmd)
@@ -343,7 +344,7 @@ def run_validator_tests():
343344

344345

345346
def run_example_tests():
346-
print('\n[ checking native example testcases...]\n')
347+
print_heading('checking native example testcases...')
347348
if not shared.NATIVECC or not shared.NATIVEXX:
348349
shared.fail_with_error('Native compiler (e.g. gcc/g++) was not found in PATH!')
349350
return
@@ -385,7 +386,7 @@ def run_example_tests():
385386

386387

387388
def run_unittest():
388-
print('\n[ checking unit tests...]\n')
389+
print_heading('checking unit tests...')
389390

390391
# equivalent to `python -m unittest discover -s ./test -v`
391392
suite = unittest.defaultTestLoader.discover(os.path.dirname(shared.options.binaryen_test))
@@ -472,13 +473,13 @@ def main():
472473

473474
# Check/display the results
474475
if shared.num_failures == 0:
475-
print('\n[ success! ]')
476+
print_heading('success!', last=True)
476477

477478
if shared.warnings:
478479
print('\n' + '\n'.join(shared.warnings))
479480

480481
if shared.num_failures > 0:
481-
print('\n[ ' + str(shared.num_failures) + ' failures! ]')
482+
print_heading(f'{shared.num_failures} failures!', last=True)
482483
return 1
483484

484485
return 0

scripts/auto_update_tests.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@
1818
import subprocess
1919
import sys
2020

21+
from test.shared import print_heading
22+
2123
from test import binaryenjs, finalize, shared, support, wasm2js, wasm_opt
2224

2325

2426
def update_example_tests():
25-
print('\n[ checking example testcases... ]\n')
27+
print_heading('checking example testcases...')
2628
for src in shared.get_tests(shared.get_test_dir('example')):
2729
basename = os.path.basename(src)
2830
output_file = os.path.join(shared.options.binaryen_bin, 'example')
@@ -64,7 +66,7 @@ def update_example_tests():
6466

6567

6668
def update_wasm_dis_tests():
67-
print('\n[ checking wasm-dis on provided binaries... ]\n')
69+
print_heading('checking wasm-dis on provided binaries...')
6870
for t in shared.get_tests(shared.options.binaryen_test, ['.wasm']):
6971
print('..', os.path.basename(t))
7072
cmd = shared.WASM_DIS + [t]
@@ -76,7 +78,7 @@ def update_wasm_dis_tests():
7678

7779

7880
def update_ctor_eval_tests():
79-
print('\n[ checking wasm-ctor-eval... ]\n')
81+
print_heading('checking wasm-ctor-eval...')
8082
for t in shared.get_tests(shared.get_test_dir('ctor-eval'), ['.wast', '.wasm']):
8183
print('..', os.path.basename(t))
8284
ctors = open(t + '.ctors').read().strip()
@@ -93,7 +95,7 @@ def update_ctor_eval_tests():
9395

9496

9597
def update_metadce_tests():
96-
print('\n[ checking wasm-metadce... ]\n')
98+
print_heading('checking wasm-metadce...')
9799
for t in shared.get_tests(shared.get_test_dir('metadce'), ['.wast', '.wasm']):
98100
print('..', os.path.basename(t))
99101
graph = t + '.graph.txt'
@@ -108,7 +110,7 @@ def update_metadce_tests():
108110

109111

110112
def update_reduce_tests():
111-
print('\n[ checking wasm-reduce ]\n')
113+
print_heading('checking wasm-reduce')
112114
for t in shared.get_tests(shared.get_test_dir('reduce'), ['.wast']):
113115
print('..', os.path.basename(t))
114116
# convert to wasm
@@ -120,7 +122,7 @@ def update_reduce_tests():
120122

121123

122124
def update_spec_tests():
123-
print('\n[ updating wasm-shell spec testcases... ]\n')
125+
print_heading('updating wasm-shell spec testcases...')
124126

125127
for t in shared.options.spec_tests:
126128
print('..', os.path.basename(t))
@@ -138,7 +140,7 @@ def update_spec_tests():
138140

139141

140142
def update_lit_tests():
141-
print('\n[ updating lit testcases... ]\n')
143+
print_heading('updating lit testcases...')
142144
script = os.path.join(shared.options.binaryen_root,
143145
'scripts',
144146
'update_lit_checks.py')
@@ -188,7 +190,7 @@ def main():
188190
for test in shared.requested:
189191
TEST_SUITES[test]()
190192

191-
print('\n[ success! ]')
193+
print_heading('success!', last=True)
192194

193195

194196
if __name__ == '__main__':

scripts/test/binaryenjs.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import subprocess
1717

1818
from . import shared, support
19+
from .shared import print_heading
1920

2021

2122
def make_js_test_header(binaryen_js):
@@ -52,7 +53,7 @@ def test_binaryen_js():
5253
if not os.path.exists(shared.BINARYEN_JS):
5354
shared.fail_with_error('no ' + shared.BINARYEN_JS + ' build to test')
5455

55-
print('\n[ checking binaryen.js testcases (' + shared.BINARYEN_JS + ')... ]\n')
56+
print_heading(f'checking binaryen.js testcases ({shared.BINARYEN_JS})...')
5657

5758
for s in shared.get_tests(shared.get_test_dir('binaryen.js'), ['.js']):
5859
outname = make_js_test(s, shared.BINARYEN_JS)
@@ -87,7 +88,7 @@ def update_binaryen_js_tests():
8788
print('no binaryen.js build to test')
8889
return
8990

90-
print('\n[ checking binaryen.js testcases... ]\n')
91+
print_heading('checking binaryen.js testcases...')
9192
node_has_wasm = shared.NODEJS and support.node_has_webassembly(shared.NODEJS)
9293
for s in shared.get_tests(shared.get_test_dir('binaryen.js'), ['.js']):
9394
outname = make_js_test(s, shared.BINARYEN_JS)

scripts/test/finalize.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import os
1616

1717
from . import shared, support
18+
from .shared import print_heading
1819

1920

2021
def args_for_finalize(filename):
@@ -46,14 +47,14 @@ def run_test(input_path):
4647

4748

4849
def test_wasm_emscripten_finalize():
49-
print('\n[ checking wasm-emscripten-finalize testcases... ]\n')
50+
print_heading('checking wasm-emscripten-finalize testcases...')
5051

5152
for input_path in shared.get_tests(shared.get_test_dir('finalize'), ['.wat', '.wasm']):
5253
run_test(input_path)
5354

5455

5556
def update_finalize_tests():
56-
print('\n[ updating wasm-emscripten-finalize testcases... ]\n')
57+
print_heading('updating wasm-emscripten-finalize testcases...')
5758

5859
for input_path in shared.get_tests(shared.get_test_dir('finalize'), ['.wat', '.wasm']):
5960
print('..', input_path)

scripts/test/shared.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,24 @@ def warn(text):
114114
print('warning:', text, file=sys.stderr)
115115

116116

117+
first = True
118+
119+
120+
def print_heading(msg, last=False):
121+
global first
122+
123+
if last:
124+
print(f'\n[ {msg} ]')
125+
return
126+
127+
if first:
128+
print(f'[ {msg} ]\n')
129+
first = False
130+
return
131+
132+
print(f'\n[ {msg} ]\n')
133+
134+
117135
# setup
118136

119137
# Locate Binaryen build artifacts directory (bin/ by default)

scripts/test/wasm2js.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import subprocess
1717

1818
from . import shared, support
19+
from .shared import print_heading
1920

2021
basic_tests = shared.get_tests(os.path.join(shared.options.binaryen_test, 'lit', 'basic'))
2122
# memory64 is not supported in wasm2js yet (but may be with BigInt eventually).
@@ -159,7 +160,7 @@ def test_asserts_output():
159160

160161

161162
def test_wasm2js():
162-
print('\n[ checking wasm2js testcases... ]\n')
163+
print_heading('checking wasm2js testcases...')
163164
check_for_stale_files()
164165
if shared.skip_if_on_windows('wasm2js'):
165166
return
@@ -168,7 +169,7 @@ def test_wasm2js():
168169

169170

170171
def update_wasm2js_tests():
171-
print('\n[ checking wasm2js ]\n')
172+
print_heading('checking wasm2js')
172173

173174
for opt in (0, 1):
174175
for wasm in basic_tests + spec_tests + wasm2js_tests:

scripts/test/wasm_opt.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717
import subprocess
1818

1919
from . import shared, support
20+
from .shared import print_heading
2021

2122

2223
def test_wasm_opt():
23-
print('\n[ checking wasm-opt -o notation... ]\n')
24+
print_heading('checking wasm-opt -o notation...')
2425

2526
for extra_args in [[], ['--no-validation']]:
2627
wast = os.path.join(shared.options.binaryen_test, 'hello_world.wat')
@@ -30,7 +31,7 @@ def test_wasm_opt():
3031
support.run_command(cmd)
3132
shared.fail_if_not_identical_to_file(open(out).read(), wast)
3233

33-
print('\n[ checking wasm-opt binary reading/writing... ]\n')
34+
print_heading('checking wasm-opt binary reading/writing...')
3435

3536
shutil.copyfile(os.path.join(shared.options.binaryen_test, 'hello_world.wat'), 'a.wat')
3637
shared.delete_from_orbit('a.wasm')
@@ -40,7 +41,7 @@ def test_wasm_opt():
4041
support.run_command(shared.WASM_OPT + ['a.wasm', '-o', 'b.wast', '-S', '-q'])
4142
assert open('b.wast', 'rb').read()[0] != 0, 'we emit text with -S'
4243

43-
print('\n[ checking wasm-opt passes... ]\n')
44+
print_heading('checking wasm-opt passes...')
4445

4546
for t in shared.get_tests(shared.get_test_dir('passes'), ['.wast', '.wasm']):
4647
print('..', os.path.basename(t))
@@ -87,7 +88,7 @@ def test_wasm_opt():
8788
with open('a.wat') as actual:
8889
shared.fail_if_not_identical_to_file(actual.read(), t + '.wat')
8990

90-
print('\n[ checking wasm-opt parsing & printing... ]\n')
91+
print_heading('checking wasm-opt parsing & printing...')
9192

9293
for t in shared.get_tests(shared.get_test_dir('print'), ['.wast']):
9394
print('..', os.path.basename(t))
@@ -104,13 +105,13 @@ def test_wasm_opt():
104105

105106

106107
def update_wasm_opt_tests():
107-
print('\n[ updating wasm-opt -o notation... ]\n')
108+
print_heading('updating wasm-opt -o notation...')
108109
wast = os.path.join(shared.options.binaryen_test, 'hello_world.wat')
109110
cmd = shared.WASM_OPT + [wast, '-o', 'a.wast', '-S']
110111
support.run_command(cmd)
111112
open(wast, 'w').write(open('a.wast').read())
112113

113-
print('\n[ updating wasm-opt parsing & printing... ]\n')
114+
print_heading('updating wasm-opt parsing & printing...')
114115
for t in shared.get_tests(shared.get_test_dir('print'), ['.wast']):
115116
print('..', os.path.basename(t))
116117
wasm = t.replace('.wast', '')
@@ -126,7 +127,7 @@ def update_wasm_opt_tests():
126127
with open(wasm + '.minified.txt', 'wb') as o:
127128
o.write(actual)
128129

129-
print('\n[ updating wasm-opt passes... ]\n')
130+
print_heading('updating wasm-opt passes...')
130131
for t in shared.get_tests(shared.get_test_dir('passes'), ['.wast', '.wasm']):
131132
print('..', os.path.basename(t))
132133
# windows has some failures that need to be investigated:

0 commit comments

Comments
 (0)