Skip to content

Commit 20ebe76

Browse files
Honrytlively
authored andcommitted
[test] Use unified assert_result* assertion (WebAssembly#156)
* [test] Use unified assert_result* assertion to replace assert_return_arithmetic_nan and assert_return_canonical_nan Tests are pulled from WAVM/WAVM#240 * Correct property name
1 parent 5f4932b commit 20ebe76

File tree

8 files changed

+4862
-4331
lines changed

8 files changed

+4862
-4331
lines changed

test/core/simd/meta/simd_f32x4.py

Lines changed: 23 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ class Simdf32x4Case(Simdf32x4ArithmeticCase):
3131
binary_nan_template = ('({assert_type} (invoke "{func}" ', '{operand_1}', '{operand_2}))')
3232
unary_nan_template = ('({assert_type} (invoke "{func}" ', '{operand}))')
3333

34-
3534
def full_op_name(self, op_name):
3635
return self.LANE_TYPE + '.' + op_name
3736

@@ -139,43 +138,36 @@ def gen_test_func_template(self):
139138
[
140139
'f32x4.min',
141140
[['nan', '0', '0', '1'], ['0', '-nan', '1', '0']],
142-
[['nan', '-nan', '0', '0']],
141+
[['nan:canonical', 'nan:canonical', '0', '0']],
143142
['f32x4', 'f32x4', 'f32x4']
144143
],
145144
[
146145
'f32x4.min',
147146
[['nan', '0', '0', '0'], ['0', '-nan', '1', '0']],
148-
[['nan', '-nan', '0', '0']],
147+
[['nan:canonical', 'nan:canonical', '0', '0']],
149148
['f32x4', 'f32x4', 'f32x4']
150149
],
151150
[
152151
'f32x4.max',
153152
[['nan', '0', '0', '1'], ['0', '-nan', '1', '0']],
154-
[['nan', '-nan', '1', '1']],
153+
[['nan:canonical', 'nan:canonical', '1', '1']],
155154
['f32x4', 'f32x4', 'f32x4']
156155
],
157156
[
158157
'f32x4.max',
159158
[['nan', '0', '0', '0'], ['0', '-nan', '1', '0']],
160-
[['nan', '-nan', '1', '0']],
159+
[['nan:canonical', 'nan:canonical', '1', '0']],
161160
['f32x4', 'f32x4', 'f32x4']
162161
]
163162
]
164163

165-
# Case number
166-
case_cnt = 0
167-
168-
# Template for func name to extract a lane
169-
tpl_func_by_lane = 'call_indirect_vv_v_f32x4_extract_lane_{}'
170-
171164
# Template for assert
172-
tpl_assert = '({assert_type}\n' \
165+
tpl_assert = '(assert_return\n' \
173166
' (invoke "{func}"\n' \
174167
' {operand_1}\n' \
175168
' {operand_2}\n' \
176-
' {operand_3}\n' \
177169
' )\n' \
178-
'{expected_result}' \
170+
' {expected_result}\n' \
179171
')'
180172

181173
lst_diff_lane_vs_clause_assert = []
@@ -184,79 +176,16 @@ def gen_test_func_template(self):
184176
lst_diff_lane_vs_clause_assert.append('')
185177
lst_diff_lane_vs_clause_assert.append(';; Test different lanes go through different if-then clauses')
186178

187-
template.insert(len(template)-1, '')
188-
template.insert(len(template)-1, ' ;; Test different lanes go through different if-then clauses')
189-
190-
# Add test case for test different lanes go through different if-then clauses
191-
template.insert(len(template)-1, ' (type $vv_v (func (param v128 v128) (result v128)))\n'
192-
' (table funcref (elem $f32x4_min $f32x4_max))\n'
193-
'\n'
194-
' (func $f32x4_min (type $vv_v)\n'
195-
' (f32x4.min (local.get 0) (local.get 1))\n'
196-
' )\n'
197-
'\n'
198-
' (func $f32x4_max (type $vv_v)\n'
199-
' (f32x4.max (local.get 0) (local.get 1))\n'
200-
' )\n'
201-
'\n'
202-
' (func (export "call_indirect_vv_v_f32x4_extract_lane_0")\n'
203-
' (param v128 v128 i32) (result f32)\n'
204-
' (f32x4.extract_lane 0\n'
205-
' (call_indirect (type $vv_v) (local.get 0) (local.get 1) (local.get 2))\n'
206-
' )\n'
207-
' )\n'
208-
' (func (export "call_indirect_vv_v_f32x4_extract_lane_1")\n'
209-
' (param v128 v128 i32) (result f32)\n'
210-
' (f32x4.extract_lane 1\n'
211-
' (call_indirect (type $vv_v) (local.get 0) (local.get 1) (local.get 2))\n'
212-
' )\n'
213-
' )\n'
214-
' (func (export "call_indirect_vv_v_f32x4_extract_lane_2")\n'
215-
' (param v128 v128 i32) (result f32)\n'
216-
' (f32x4.extract_lane 2\n'
217-
' (call_indirect (type $vv_v) (local.get 0) (local.get 1) (local.get 2))\n'
218-
' )\n'
219-
' )\n'
220-
' (func (export "call_indirect_vv_v_f32x4_extract_lane_3")\n'
221-
' (param v128 v128 i32) (result f32)\n'
222-
' (f32x4.extract_lane 3\n'
223-
' (call_indirect (type $vv_v) (local.get 0) (local.get 1) (local.get 2))\n'
224-
' )\n'
225-
' )')
226-
227179
for case_data in lst_diff_lane_vs_clause:
228180

229-
lst_diff_lane_vs_clause_assert.append(';; {lane_type} {index}'.format(lane_type=case_data[0], index=case_cnt))
230-
231-
# generate assert for every data lane
232-
for lane_idx in range(0, len(case_data[2][0])):
233-
234-
# get the result by lane
235-
ret = case_data[2][0][lane_idx]
236-
237-
idx_func = '0' if 'min' in case_data[0] else '1'
238-
239-
# append assert
240-
if 'nan' in ret:
241-
242-
lst_diff_lane_vs_clause_assert.append(tpl_assert.format(assert_type='assert_return_canonical_nan',
243-
func=tpl_func_by_lane.format(lane_idx),
244-
operand_1=self.v128_const('f32x4', case_data[1][0]),
245-
operand_2=self.v128_const('f32x4', case_data[1][1]),
246-
operand_3=self.v128_const('i32', idx_func),
247-
expected_result=''))
248-
else:
249-
250-
lst_diff_lane_vs_clause_assert.append(tpl_assert.format(assert_type='assert_return',
251-
func=tpl_func_by_lane.format(lane_idx),
252-
operand_1=self.v128_const('f32x4', case_data[1][0]),
253-
operand_2=self.v128_const('f32x4', case_data[1][1]),
254-
operand_3=self.v128_const('i32', idx_func),
255-
expected_result=' '+self.v128_const('f32', ret)+'\n'))
181+
lst_diff_lane_vs_clause_assert.append(';; {lane_type}'.format(lane_type=case_data[0]))
256182

257-
case_cnt += 1
258-
if case_cnt == 2:
259-
case_cnt = 0
183+
lst_diff_lane_vs_clause_assert.append(tpl_assert.format(
184+
func=case_data[0],
185+
operand_1=self.v128_const(case_data[3][0], case_data[1][0]),
186+
operand_2=self.v128_const(case_data[3][1], case_data[1][1]),
187+
expected_result=self.v128_const(case_data[3][2], case_data[2][0])
188+
))
260189

261190
lst_diff_lane_vs_clause_assert.append('')
262191

@@ -312,11 +241,7 @@ def combine_binary_arith_test_data(self):
312241
}
313242

314243
def get_normal_case(self):
315-
"""Normal test cases from WebAssembly core tests, 4 assert statements:
316-
assert_return
317-
assert_return_canonical_nan
318-
assert_return_arithmetic_nan
319-
assert_malformed
244+
"""Normal test cases from WebAssembly core tests.
320245
"""
321246
cases = []
322247
binary_test_data = []
@@ -331,34 +256,28 @@ def get_normal_case(self):
331256
# Normal floating point numbers as the results
332257
binary_test_data.append(['assert_return', op_name, p1, p2, result])
333258
else:
334-
# Since the results contain the 'nan' string, it should be in the
335-
# assert_return_canonical_nan statements
336-
binary_test_data.append(['assert_return_canonical_nan_f32x4', op_name, p1, p2])
259+
# Since the results contain the 'nan' string, the result literals would be
260+
# nan:canonical
261+
binary_test_data.append(['assert_return', op_name, p1, p2, 'nan:canonical'])
337262

338263
for p1 in self.LITERAL_NUMBERS:
339264
for p2 in self.LITERAL_NUMBERS:
340265
result = self.floatOp.binary_op(op, p1, p2, hex_form=False)
341266
binary_test_data.append(['assert_return', op_name, p1, p2, result])
342267

343-
# assert_return_canonical_nan and assert_return_arithmetic_nan cases
344268
for p1 in self.NAN_NUMBERS:
345269
for p2 in self.FLOAT_NUMBERS:
346270
if 'nan:' in p1 or 'nan:' in p2:
347-
# When the arguments contain 'nan:', always use assert_return_arithmetic_nan
348-
# statements for the cases. Since there 2 parameters for binary operation and
349-
# the order of the parameters matter. Different order makes different cases.
350-
binary_test_data.append(['assert_return_arithmetic_nan_f32x4', op_name, p1, p2])
351-
binary_test_data.append(['assert_return_arithmetic_nan_f32x4', op_name, p2, p1])
271+
# When the arguments contain 'nan:', the result literal is nan:arithmetic
272+
binary_test_data.append(['assert_return', op_name, p1, p2, 'nan:arithmetic'])
352273
else:
353-
# No 'nan' string found, then it should be assert_return_canonical_nan.
354-
binary_test_data.append(['assert_return_canonical_nan_f32x4', op_name, p1, p2])
355-
binary_test_data.append(['assert_return_canonical_nan_f32x4', op_name, p2, p1])
274+
# No 'nan' string found, then the result literal is nan:canonical
275+
binary_test_data.append(['assert_return', op_name, p1, p2, 'nan:canonical'])
356276
for p2 in self.NAN_NUMBERS:
357-
# Both parameters contain 'nan', then there must be no assert_return.
358277
if 'nan:' in p1 or 'nan:' in p2:
359-
binary_test_data.append(['assert_return_arithmetic_nan_f32x4', op_name, p1, p2])
278+
binary_test_data.append(['assert_return', op_name, p1, p2, 'nan:arithmetic'])
360279
else:
361-
binary_test_data.append(['assert_return_canonical_nan_f32x4', op_name, p1, p2])
280+
binary_test_data.append(['assert_return', op_name, p1, p2, 'nan:canonical'])
362281

363282
for case in binary_test_data:
364283
cases.append(self.single_binary_test(case))

0 commit comments

Comments
 (0)