コード例 #1
0
def run_wasm_reduce_tests():
    if not has_shell_timeout():
        print('\n[ skipping wasm-reduce testcases]\n')
        return

    print('\n[ checking wasm-reduce testcases]\n')

    # fixed testcases
    test_dir = os.path.join(options.binaryen_test, 'reduce')
    for t in os.listdir(test_dir):
        if t.endswith('.wast'):
            print('..', t)
            t = os.path.join(test_dir, t)
            # convert to wasm
            run_command(WASM_AS + [t, '-o', 'a.wasm'])
            run_command(WASM_REDUCE + ['a.wasm', '--command=%s b.wasm --fuzz-exec -all' % WASM_OPT[0], '-t', 'b.wasm', '-w', 'c.wasm', '--timeout=4'])
            expected = t + '.txt'
            run_command(WASM_DIS + ['c.wasm', '-o', 'a.wast'])
            with open('a.wast') as seen:
                fail_if_not_identical_to_file(seen.read(), expected)

    # run on a nontrivial fuzz testcase, for general coverage
    # this is very slow in ThreadSanitizer, so avoid it there
    if 'fsanitize=thread' not in str(os.environ):
        print('\n[ checking wasm-reduce fuzz testcase ]\n')

        run_command(WASM_OPT + [os.path.join(options.binaryen_test, 'unreachable-import_wasm-only.asm.js'), '-ttf', '-Os', '-o', 'a.wasm', '-all'])
        before = os.stat('a.wasm').st_size
        run_command(WASM_REDUCE + ['a.wasm', '--command=%s b.wasm --fuzz-exec -all' % WASM_OPT[0], '-t', 'b.wasm', '-w', 'c.wasm'])
        after = os.stat('c.wasm').st_size
        # 0.65 is a custom threshold to check if we have shrunk the output
        # sufficiently
        assert after < 0.65 * before, [before, after]
コード例 #2
0
ファイル: check.py プロジェクト: sthagen/binaryen
def run_wasm_reduce_tests():
    if not shared.has_shell_timeout():
        print('\n[ skipping wasm-reduce testcases]\n')
        return

    print('\n[ checking wasm-reduce testcases]\n')

    # fixed testcases
    for t in shared.get_tests(shared.get_test_dir('reduce'), ['.wast']):
        print('..', os.path.basename(t))
        # convert to wasm
        support.run_command(shared.WASM_AS + [t, '-o', 'a.wasm', '-all'])
        support.run_command(shared.WASM_REDUCE + ['a.wasm', '--command=%s b.wasm --fuzz-exec -all ' % shared.WASM_OPT[0], '-t', 'b.wasm', '-w', 'c.wasm', '--timeout=4'])
        expected = t + '.txt'
        support.run_command(shared.WASM_DIS + ['c.wasm', '-o', 'a.wat'])
        with open('a.wat') as seen:
            shared.fail_if_not_identical_to_file(seen.read(), expected)

    # run on a nontrivial fuzz testcase, for general coverage
    # this is very slow in ThreadSanitizer, so avoid it there
    if 'fsanitize=thread' not in str(os.environ):
        print('\n[ checking wasm-reduce fuzz testcase ]\n')
        # TODO: re-enable multivalue once it is better optimized
        support.run_command(shared.WASM_OPT + [os.path.join(shared.options.binaryen_test, 'signext.wast'), '-ttf', '-Os', '-o', 'a.wasm', '--detect-features', '--disable-multivalue'])
        before = os.stat('a.wasm').st_size
        support.run_command(shared.WASM_REDUCE + ['a.wasm', '--command=%s b.wasm --fuzz-exec --detect-features' % shared.WASM_OPT[0], '-t', 'b.wasm', '-w', 'c.wasm'])
        after = os.stat('c.wasm').st_size
        # This number is a custom threshold to check if we have shrunk the
        # output sufficiently
        assert after < 0.85 * before, [before, after]
コード例 #3
0
def update_reduce_tests():
    if not shared.has_shell_timeout():
        return
    print('\n[ checking wasm-reduce ]\n')
    for t in shared.get_tests(shared.get_test_dir('reduce'), ['.wast']):
        print('..', os.path.basename(t))
        # convert to wasm
        support.run_command(shared.WASM_AS + [t, '-o', 'a.wasm'])
        print(support.run_command(shared.WASM_REDUCE + ['a.wasm', '--command=%s b.wasm --fuzz-exec' % shared.WASM_OPT[0], '-t', 'b.wasm', '-w', 'c.wasm']))
        expected = t + '.txt'
        support.run_command(shared.WASM_DIS + ['c.wasm', '-o', expected])
コード例 #4
0
def update_reduce_tests():
    if not has_shell_timeout():
        return
    print('\n[ checking wasm-reduce ]\n')
    for t in os.listdir(os.path.join(options.binaryen_test, 'reduce')):
        if t.endswith('.wast'):
            print('..', t)
            t = os.path.join(options.binaryen_test, 'reduce', t)
            # convert to wasm
            run_command(WASM_AS + [t, '-o', 'a.wasm'])
            print(run_command(WASM_REDUCE + ['a.wasm', '--command=%s b.wasm --fuzz-exec' % WASM_OPT[0], '-t', 'b.wasm', '-w', 'c.wasm']))
            expected = t + '.txt'
            run_command(WASM_DIS + ['c.wasm', '-o', expected])
コード例 #5
0
ファイル: auto_update_tests.py プロジェクト: aheejin/binaryen
def update_reduce_tests():
  if not has_shell_timeout():
    return
  print '\n[ checking wasm-reduce ]\n'
  for t in os.listdir(os.path.join('test', 'reduce')):
    if t.endswith('.wast'):
      print '..', t
      t = os.path.join('test', 'reduce', t)
      # convert to wasm
      run_command(WASM_AS + [t, '-o', 'a.wasm'])
      print run_command(WASM_REDUCE + ['a.wasm', '--command=%s b.wasm --fuzz-exec' % WASM_OPT[0], '-t', 'b.wasm', '-w', 'c.wasm'])
      expected = t + '.txt'
      run_command(WASM_DIS + ['c.wasm', '-o', expected])
コード例 #6
0
def main():
    run_help_tests()
    run_wasm_opt_tests()
    asm2wasm.test_asm2wasm()
    asm2wasm.test_asm2wasm_binary()
    run_wasm_dis_tests()
    run_wasm_merge_tests()
    run_crash_tests()
    run_ctor_eval_tests()
    run_wasm_metadce_tests()
    if has_shell_timeout():
        run_wasm_reduce_tests()

    run_spec_tests()
    run_binaryen_js_tests()
    s2wasm.test_s2wasm()
    s2wasm.test_linker()
    lld.test_wasm_link_metadata()
    lld.test_wasm_emscripten_finalize()
    wasm2asm.test_wasm2asm()
    run_validator_tests()
    if options.torture and options.test_waterfall:
        run_torture_tests()
    if has_vanilla_emcc and has_vanilla_llvm and 0:
        run_vanilla_tests()
    print '\n[ checking example testcases... ]\n'
    if options.run_gcc_tests:
        run_gcc_torture_tests()
    if EMCC:
        run_emscripten_tests()

    # Check/display the results
    if num_failures == 0:
        print '\n[ success! ]'

    if warnings:
        print '\n' + '\n'.join(warnings)

    if num_failures > 0:
        print '\n[ ' + str(num_failures) + ' failures! ]'

    sys.exit(num_failures)
コード例 #7
0
ファイル: check.py プロジェクト: hhy5277/binaryen
def main():
  run_help_tests()
  run_wasm_opt_tests()
  asm2wasm.test_asm2wasm()
  asm2wasm.test_asm2wasm_binary()
  run_wasm_dis_tests()
  run_wasm_merge_tests()
  run_crash_tests()
  run_dylink_tests()
  run_ctor_eval_tests()
  run_wasm_metadce_tests()
  if has_shell_timeout():
    run_wasm_reduce_tests()

  run_spec_tests()
  run_binaryen_js_tests()
  lld.test_wasm_emscripten_finalize()
  wasm2js.test_wasm2js()
  run_validator_tests()
  if has_vanilla_emcc and has_vanilla_llvm and 0:
    run_vanilla_tests()
  print '\n[ checking example testcases... ]\n'
  if options.run_gcc_tests:
    run_gcc_tests()

  run_unittest()

  # Check/display the results
  if shared.num_failures == 0:
    print '\n[ success! ]'

  if warnings:
    print '\n' + '\n'.join(warnings)

  if shared.num_failures > 0:
    print '\n[ ' + str(shared.num_failures) + ' failures! ]'
    return 1

  return 0
コード例 #8
0
for t in os.listdir(os.path.join('test', 'metadce')):
    if t.endswith(('.wast', '.wasm')):
        print '..', t
        t = os.path.join('test', 'metadce', t)
        graph = t + '.graph.txt'
        cmd = WASM_METADCE + [t, '--graph-file=' + graph, '-o', 'a.wast', '-S']
        stdout = run_command(cmd)
        actual = open('a.wast').read()
        out = t + '.dced'
        with open(out, 'w') as o:
            o.write(actual)
        with open(out + '.stdout', 'w') as o:
            o.write(stdout)

if has_shell_timeout():
    print '\n[ checking wasm-reduce ]\n'

    for t in os.listdir(os.path.join('test', 'reduce')):
        if t.endswith('.wast'):
            print '..', t
            t = os.path.join('test', 'reduce', t)
            # convert to wasm
            run_command(WASM_AS + [t, '-o', 'a.wasm'])
            print run_command(WASM_REDUCE + [
                'a.wasm', '--command=bin/wasm-opt b.wasm --fuzz-exec', '-t',
                'b.wasm', '-w', 'c.wasm'
            ])
            expected = t + '.txt'
            run_command(WASM_DIS + ['c.wasm', '-o', expected])