Skip to content

Commit 3bcf77b

Browse files
authored
Split generated casts test for more coverage (#7543)
Split the automatically generated optimize-instructions-all-casts.wast into two tests: one that tests casts to exact types and another that tests casts to inexact types. For the test file that does not cast to exact types, additionally test with custom descriptors disabled to ensure that the results validate.
1 parent 2d97856 commit 3bcf77b

File tree

4 files changed

+1587
-1006
lines changed

4 files changed

+1587
-1006
lines changed

scripts/test/fuzzing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
'exact-references-lowering.wast',
115115
'exact-casts.wast',
116116
'exact-casts-trivial.wast',
117-
'optimize-instructions-all-casts.wast',
117+
'optimize-instructions-all-casts-exact.wast',
118118
'local-subtyping-exact.wast',
119119
'remove-unused-types-exact.wast',
120120
'coalesce-locals-exact.wast',

scripts/test/gen-cast-test.py

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#! /usr/bin/python3
22

33
'''
4-
This script is used to generate
5-
test/lit/passes/optimize-instructions-all-casts.wast
4+
Generate test modules with all interesting casts
65
'''
76

7+
import argparse
88
import itertools
99

1010
interesting_pairs = [('$super', '$super', 'cast-to-self-nonfinal'),
@@ -16,14 +16,16 @@
1616
('none', '$super', 'cast-from-bottom')]
1717

1818

19-
def gen_test_configs():
19+
def gen_test_configs(args):
2020
for src_heap, cast_heap, heap_name in interesting_pairs:
2121
for src_nullable, src_exact, cast_nullable, cast_exact in \
2222
itertools.product([True, False], repeat=4):
2323
if src_exact and src_heap == 'none':
2424
continue
2525
if cast_exact and cast_heap == 'none':
2626
continue
27+
if args.enable_descs != cast_exact:
28+
continue
2729
yield heap_name, src_heap, cast_heap, src_nullable, cast_nullable, \
2830
src_exact, cast_exact
2931

@@ -62,23 +64,37 @@ def print_test(config):
6264
print(test)
6365

6466

65-
def print_tests():
66-
for config in gen_test_configs():
67+
def print_tests(args):
68+
for config in gen_test_configs(args):
6769
print_test(config)
6870

6971

70-
def print_header():
71-
header = ''';; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited.
72-
;; NOTE: Test has been generated by scripts/test/gen-cast-test.py. Do not edit manually.
72+
def print_header(args):
73+
flags = ''
74+
if args.enable_descs:
75+
flags = ' --enable-custom-descs'
76+
header = f''';; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited.
77+
;; NOTE: Test has been generated by scripts/test/gen-cast-test.py{flags}. Do not edit manually.
7378
7479
;; Exhaustively test optimization of all interesting casts.
80+
'''
7581

82+
if args.enable_descs:
83+
header += '''
7684
;; RUN: wasm-opt %s -all --optimize-instructions -S -o - | filecheck %s
85+
'''
86+
else:
87+
header += '''
88+
;; RUN: wasm-opt %s -all --optimize-instructions -S -o - | filecheck %s
89+
;; RUN: wasm-opt %s -all --disable-custom-descriptors --optimize-instructions -S -o - | filecheck %s --check-prefix=NO_CD
90+
'''
7791

92+
header += '''
7893
(module
7994
(type $super (sub (struct)))
8095
(type $sub (sub $super (struct)))
8196
(type $sub-final (sub final $super (struct)))'''
97+
8298
print(header)
8399

84100

@@ -87,8 +103,11 @@ def print_footer():
87103

88104

89105
def main():
90-
print_header()
91-
print_tests()
106+
parser = argparse.ArgumentParser(description=__doc__)
107+
parser.add_argument('--enable-custom-descs', action='store_true', dest='enable_descs')
108+
args = parser.parse_args()
109+
print_header(args)
110+
print_tests(args)
92111
print_footer()
93112

94113

0 commit comments

Comments
 (0)