From 892a59c999fe5af096d18d27c8bdc4f16f2bb7a9 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Thu, 28 Jan 2016 16:35:38 -0800 Subject: refactor check.py in preparation for running spec tests after being converted to binary and back --- check.py | 72 ++++++++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 45 insertions(+), 27 deletions(-) (limited to 'check.py') diff --git a/check.py b/check.py index 2929fc326..9d33cbd54 100755 --- a/check.py +++ b/check.py @@ -167,6 +167,8 @@ def split_wast(wast): depth += 1 elif wast[j] == ')': depth -= 1 + elif wast[j] == ';' and wast[j+1] == ';': + j = wast.find('\n', j) j += 1 return j i = 0 @@ -174,13 +176,13 @@ def split_wast(wast): start = wast.find('(', i) if start < 0: break i = to_end(start + 1) - if wast[start:].startswith('(module'): - ret += [(wast[start:i], [])] - elif wast[start:].startswith('(assert_invalid'): + chunk = wast[start:i] + if chunk.startswith('(module'): + ret += [(chunk, [])] + elif chunk.startswith('(assert_invalid'): continue - else: - if len(ret) > 0: # otherwise, comments or such before the first module - ret[-1][1].append(wast[start:i]) + elif chunk.startswith('(assert'): + ret[-1][1].append(chunk) assert len(ret) > 0 return ret @@ -314,33 +316,49 @@ for t in spec_tests: if t.startswith('spec') and t.endswith('.wast'): print '..', t wast = os.path.join('test', t) - proc = subprocess.Popen([os.path.join('bin', 'binaryen-shell'), wast], stdout=subprocess.PIPE, stderr=subprocess.PIPE) - actual, err = proc.communicate() - assert proc.returncode == 0, err - expected = os.path.join('test', 'spec', 'expected-output', os.path.basename(wast) + '.log') - if os.path.exists(expected): - expected = open(expected).read() - # fix it up, our pretty (i32.const 83) must become compared to a homely 83 : i32 - def fix(x): - x = x.strip() - if not x: return x - v, t = x.split(' : ') - if v.endswith('.'): v = v[:-1] # remove trailing '.' - return '(' + t + '.const ' + v + ')' - expected = '\n'.join(map(fix, expected.split('\n'))) - print ' (using expected output)' - actual = actual.strip() - expected = expected.strip() - if actual != expected: - fail(actual, expected) + def run_spec_test(wast): + print ' run binaryen-shell on', wast + proc = subprocess.Popen([os.path.join('bin', 'binaryen-shell'), wast], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + actual, err = proc.communicate() + assert proc.returncode == 0, err + return actual + + def check_expected(actual, expected): + if expected and os.path.exists(expected): + expected = open(expected).read() + # fix it up, our pretty (i32.const 83) must become compared to a homely 83 : i32 + def fix(x): + x = x.strip() + if not x: return x + v, t = x.split(' : ') + if v.endswith('.'): v = v[:-1] # remove trailing '.' + return '(' + t + '.const ' + v + ')' + expected = '\n'.join(map(fix, expected.split('\n'))) + print ' (using expected output)' + actual = actual.strip() + expected = expected.strip() + if actual != expected: + fail(actual, expected) + + actual = run_spec_test(wast) + check_expected(actual, os.path.join('test', 'spec', 'expected-output', os.path.basename(wast) + '.log')) # check binary format. here we can verify execution of the final result, no need for an output verification + split_num = 0 if os.path.basename(wast) not in ['has_feature.wast']: # avoid some tests with things still in spec tests, but likely to be taken out soon + actual = '' for module, asserts in split_wast(wast): - print ' testing split module' + print ' testing split module', split_num + split_num += 1 open('split.wast', 'w').write(module + '\n' + '\n'.join(asserts)) - result = binary_format_check('split.wast', verify_final_result=False) + # TODO run_spec_test('split.wast') # before binary stuff - just check it's still ok split out + result_wast = binary_format_check('split.wast', verify_final_result=False) + # add the asserts, and verify that the test still passes + open(result_wast, 'a').write('\n' + '\n'.join(asserts)) + # TODO actual += run_spec_test(result_wast) + # compare all the outputs to the expected output + # TODO check_expected(actual, os.path.join('test', 'spec', 'expected-output', os.path.basename(wast) + '.log')) print '\n[ checking wasm2asm testcases... ]\n' -- cgit v1.2.3 From 1dda2d7a26d4cf214ad723d8ea43a6dc126aa563 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Thu, 28 Jan 2016 16:37:50 -0800 Subject: gather invokes when splitting wasts --- check.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'check.py') diff --git a/check.py b/check.py index 9d33cbd54..f7cc2a504 100755 --- a/check.py +++ b/check.py @@ -181,7 +181,7 @@ def split_wast(wast): ret += [(chunk, [])] elif chunk.startswith('(assert_invalid'): continue - elif chunk.startswith('(assert'): + elif chunk.startswith(('(assert', '(invoke')): ret[-1][1].append(chunk) assert len(ret) > 0 return ret @@ -352,7 +352,7 @@ for t in spec_tests: print ' testing split module', split_num split_num += 1 open('split.wast', 'w').write(module + '\n' + '\n'.join(asserts)) - # TODO run_spec_test('split.wast') # before binary stuff - just check it's still ok split out + run_spec_test('split.wast') # before binary stuff - just check it's still ok split out result_wast = binary_format_check('split.wast', verify_final_result=False) # add the asserts, and verify that the test still passes open(result_wast, 'a').write('\n' + '\n'.join(asserts)) -- cgit v1.2.3 From a0e109c8bf15d55af2280dbd95df67d89fa65520 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 29 Jan 2016 20:17:57 -0800 Subject: enable binary format spec tests --- check.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'check.py') diff --git a/check.py b/check.py index f7cc2a504..575c06222 100755 --- a/check.py +++ b/check.py @@ -356,7 +356,7 @@ for t in spec_tests: result_wast = binary_format_check('split.wast', verify_final_result=False) # add the asserts, and verify that the test still passes open(result_wast, 'a').write('\n' + '\n'.join(asserts)) - # TODO actual += run_spec_test(result_wast) + actual += run_spec_test(result_wast) # compare all the outputs to the expected output # TODO check_expected(actual, os.path.join('test', 'spec', 'expected-output', os.path.basename(wast) + '.log')) -- cgit v1.2.3 From fece87ba4008c20978639580a8dc7264c57c489d Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 29 Jan 2016 20:19:07 -0800 Subject: enable binary format spec test outputs --- check.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'check.py') diff --git a/check.py b/check.py index 575c06222..89a64113f 100755 --- a/check.py +++ b/check.py @@ -358,7 +358,7 @@ for t in spec_tests: open(result_wast, 'a').write('\n' + '\n'.join(asserts)) actual += run_spec_test(result_wast) # compare all the outputs to the expected output - # TODO check_expected(actual, os.path.join('test', 'spec', 'expected-output', os.path.basename(wast) + '.log')) + check_expected(actual, os.path.join('test', 'spec', 'expected-output', os.path.basename(wast) + '.log')) print '\n[ checking wasm2asm testcases... ]\n' -- cgit v1.2.3