Ejemplo n.º 1
0
def main(args):
    parser = argparse.ArgumentParser()
    parser.add_argument('-v',
                        '--verbose',
                        help='print more diagnotic messages.',
                        action='store_true')
    parser.add_argument('-o',
                        '--out-dir',
                        metavar='PATH',
                        help='output directory for files.')
    parser.add_argument('--bindir',
                        metavar='PATH',
                        default=find_exe.GetDefaultPath(),
                        help='directory to search for all executables.')
    parser.add_argument(
        '--no-error-cmdline',
        help='don\'t display the subprocess\'s commandline when' +
        ' an error occurs',
        dest='error_cmdline',
        action='store_false')
    parser.add_argument('-p',
                        '--print-cmd',
                        action='store_true',
                        help='print the commands that are run.')
    parser.add_argument('--no-debug-names', action='store_true')
    parser.add_argument('--objdump',
                        action='store_true',
                        help="objdump the resulting binary")
    parser.add_argument('file', help='test file.')
    options = parser.parse_args(args)

    gen_wasm = utils.Executable(sys.executable,
                                GEN_WASM_PY,
                                error_cmdline=options.error_cmdline,
                                basename=os.path.basename(GEN_WASM_PY))

    objdump = utils.Executable(find_exe.GetWasmdumpExecutable(options.bindir),
                               error_cmdline=options.error_cmdline)

    wasm2wat = utils.Executable(find_exe.GetWasm2WatExecutable(options.bindir),
                                error_cmdline=options.error_cmdline)
    wasm2wat.AppendOptionalArgs({
        '--no-debug-names': options.no_debug_names,
    })
    wasm2wat.AppendOptionalArgs({
        '--verbose': options.verbose,
    })

    gen_wasm.verbose = options.print_cmd
    wasm2wat.verbose = options.print_cmd
    objdump.verbose = options.print_cmd

    with utils.TempDirectory(options.out_dir, 'run-gen-wasm-') as out_dir:
        out_file = utils.ChangeDir(utils.ChangeExt(options.file, '.wasm'),
                                   out_dir)
        gen_wasm.RunWithArgs(options.file, '-o', out_file)
        if options.objdump:
            objdump.RunWithArgs(out_file, '-x')
        else:
            wasm2wat.RunWithArgs(out_file)
Ejemplo n.º 2
0
def main(args):
    parser = argparse.ArgumentParser()
    parser.add_argument('-o',
                        '--out-dir',
                        metavar='PATH',
                        help='output directory for files.')
    parser.add_argument('-v',
                        '--verbose',
                        help='print more diagnotic messages.',
                        action='store_true')
    parser.add_argument('--bindir',
                        metavar='PATH',
                        default=find_exe.GetDefaultPath(),
                        help='directory to search for all executables.')
    parser.add_argument(
        '--no-error-cmdline',
        help='don\'t display the subprocess\'s commandline when' +
        ' an error occurs',
        dest='error_cmdline',
        action='store_false')
    parser.add_argument('-p',
                        '--print-cmd',
                        help='print the commands that are run.',
                        action='store_true')
    parser.add_argument('--run-all-exports', action='store_true')
    parser.add_argument('--spec', action='store_true')
    parser.add_argument('-t', '--trace', action='store_true')
    parser.add_argument('file', help='test file.')
    options = parser.parse_args(args)

    wast2wasm = utils.Executable(find_exe.GetWast2WasmExecutable(
        options.bindir),
                                 error_cmdline=options.error_cmdline)
    wast2wasm.AppendOptionalArgs({
        '-v': options.verbose,
        '--spec': options.spec,
    })

    wasm_interp = utils.Executable(find_exe.GetWasmInterpExecutable(
        options.bindir),
                                   error_cmdline=options.error_cmdline)
    wasm_interp.AppendOptionalArgs({
        '-v': options.verbose,
        '--run-all-exports': options.run_all_exports,
        '--spec': options.spec,
        '--trace': options.trace,
    })

    wast2wasm.verbose = options.print_cmd
    wasm_interp.verbose = options.print_cmd

    with utils.TempDirectory(options.out_dir, 'run-interp-') as out_dir:
        new_ext = '.json' if options.spec else '.wasm'
        out_file = utils.ChangeDir(utils.ChangeExt(options.file, new_ext),
                                   out_dir)
        wast2wasm.RunWithArgs(options.file, '-o', out_file)
        wasm_interp.RunWithArgs(out_file)

    return 0
Ejemplo n.º 3
0
def main(args):
  parser = argparse.ArgumentParser()
  parser.add_argument('-o', '--out-dir', metavar='PATH',
                      help='output directory for files.')
  parser.add_argument('--bindir', metavar='PATH',
                      default=find_exe.GetDefaultPath(),
                      help='directory to search for all executables.')
  parser.add_argument(
      '--js-engine', metavar='PATH',
      help='the path to the JavaScript engine with which to run'
      ' the generated JavaScript. If not specified, JavaScript'
      ' output will be written to stdout.')
  parser.add_argument('--js-engine-flags', metavar='FLAGS',
                      help='additional flags for JavaScript engine.',
                      action='append', default=[])
  parser.add_argument('--prefix-js',
                      help='Prefix JavaScript file to pass to gen-spec-js')
  parser.add_argument('-v', '--verbose', help='print more diagnotic messages.',
                      action='store_true')
  parser.add_argument('--no-error-cmdline',
                      help='don\'t display the subprocess\'s commandline when'
                      + ' an error occurs', dest='error_cmdline',
                      action='store_false')
  parser.add_argument('-p', '--print-cmd',
                      help='print the commands that are run.',
                      action='store_true')
  parser.add_argument('file', help='wast file.')
  options = parser.parse_args(args)

  with utils.TempDirectory(options.out_dir, 'run-gen-spec-js-') as out_dir:
    wast2wasm = utils.Executable(
        find_exe.GetWast2WasmExecutable(options.bindir), '--spec',
        error_cmdline=options.error_cmdline)
    wast2wasm.AppendOptionalArgs({'-v': options.verbose})

    gen_spec_js = utils.Executable(sys.executable, GEN_SPEC_JS_PY,
                                   '--temp-dir', out_dir,
                                   error_cmdline=options.error_cmdline)
    gen_spec_js.AppendOptionalArgs({
        '--bindir': options.bindir,
        '--prefix': options.prefix_js,
    })
    gen_spec_js.verbose = options.print_cmd

    json_file = utils.ChangeDir(
        utils.ChangeExt(options.file, '.json'), out_dir)
    js_file = utils.ChangeExt(json_file, '.js')
    wast2wasm.RunWithArgs(options.file, '-o', json_file)

    if options.js_engine:
      gen_spec_js.RunWithArgs(json_file, '-o', js_file)
      js = utils.Executable(options.js_engine, *options.js_engine_flags)
      js.RunWithArgs(js_file)
    else:
      # Write JavaScript output to stdout
      gen_spec_js.RunWithArgs(json_file)
Ejemplo n.º 4
0
def main(args):
    parser = argparse.ArgumentParser()
    parser.add_argument('-o',
                        '--out-dir',
                        metavar='PATH',
                        help='output directory for files.')
    parser.add_argument('--bindir',
                        metavar='PATH',
                        default=find_exe.GetDefaultPath(),
                        help='directory to search for all executables.')
    parser.add_argument('-v',
                        '--verbose',
                        help='print more diagnotic messages.',
                        action='store_true')
    parser.add_argument(
        '--no-error-cmdline',
        help='don\'t display the subprocess\'s commandline when' +
        ' an error occurs',
        dest='error_cmdline',
        action='store_false')
    parser.add_argument('--print-cmd',
                        help='print the commands that are run.',
                        action='store_true')
    parser.add_argument('--use-libc-allocator', action='store_true')
    parser.add_argument('file', help='test file.')
    options = parser.parse_args(args)

    wast2wasm = utils.Executable(find_exe.GetWast2WasmExecutable(
        options.bindir),
                                 error_cmdline=options.error_cmdline)
    wast2wasm.AppendOptionalArgs({
        '-v':
        options.verbose,
        '--use-libc-allocator':
        options.use_libc_allocator
    })

    wasmopcodecnt = utils.Executable(find_exe.GetWasmOpcodeCntExecutable(
        options.bindir),
                                     error_cmdline=options.error_cmdline)
    wasmopcodecnt.AppendOptionalArgs(
        {'--use-libc-allocator': options.use_libc_allocator})

    wast2wasm.verbose = options.print_cmd
    wasmopcodecnt.verbose = options.print_cmd

    with utils.TempDirectory(options.out_dir, 'run-opcodecnt-') as out_dir:
        out_file = utils.ChangeDir(utils.ChangeExt(options.file, '.wasm'),
                                   out_dir)
        wast2wasm.RunWithArgs(options.file, '-o', out_file)
        wasmopcodecnt.RunWithArgs(out_file)

    return 0
Ejemplo n.º 5
0
def main(args):
    print('Running c-api examples..')
    parser = argparse.ArgumentParser()
    parser.add_argument('--bindir',
                        metavar='PATH',
                        default=find_exe.GetDefaultPath(),
                        help='directory to search for all executables.')

    options = parser.parse_args(args)
    script_dir = os.path.dirname(os.path.abspath(__file__))
    root = os.path.dirname(script_dir)
    upstream_dir = os.path.join(root, 'third_party', 'wasm-c-api', 'example')
    upstream_examples = [
        f for f in os.listdir(upstream_dir)
        if os.path.splitext(f)[1] == '.wasm'
    ]
    upstream_examples = [os.path.splitext(f)[0] for f in upstream_examples]
    check_for_missing(upstream_examples)

    def should_skip(e):
        return any(e.startswith(skip) for skip in SKIP_EXAMPLES)

    to_run = [e for e in upstream_examples if not should_skip(e)]

    os.chdir(options.bindir)
    count = 0
    fail_count = 0
    for f in to_run:
        if IS_WINDOWS:
            f += '.exe'
        exe = os.path.join(options.bindir, 'wasm-c-api-' + f)
        if not os.path.exists(exe):
            error('test executable not found: %s' % exe)

        count += 1
        if run_test(exe) != 0:
            fail_count += 1

    if fail_count:
        print('[%d/%d] c-api examples failed' % (fail_count, count))
        return 1
    return 0
Ejemplo n.º 6
0
def main(args):
    parser = argparse.ArgumentParser()
    parser.add_argument('-v',
                        '--verbose',
                        help='print more diagnotic messages.',
                        action='store_true')
    parser.add_argument('-o',
                        '--out-dir',
                        metavar='PATH',
                        help='output directory for files.')
    parser.add_argument('--bindir',
                        metavar='PATH',
                        default=find_exe.GetDefaultPath(),
                        help='directory to search for all executables.')
    parser.add_argument(
        '--no-error-cmdline',
        help='don\'t display the subprocess\'s commandline when' +
        ' an error occurs',
        dest='error_cmdline',
        action='store_false')
    parser.add_argument('-p',
                        '--print-cmd',
                        help='print the commands that are run.',
                        action='store_true')
    parser.add_argument('--headers', action='store_true')
    parser.add_argument('--no-check', action='store_true')
    parser.add_argument('-c', '--compile-only', action='store_true')
    parser.add_argument('--dump-verbose', action='store_true')
    parser.add_argument('--spec', action='store_true')
    parser.add_argument('--no-canonicalize-leb128s', action='store_true')
    parser.add_argument('--debug-names', action='store_true')
    parser.add_argument('file', help='test file.')
    options = parser.parse_args(args)

    wast2wasm = utils.Executable(find_exe.GetWast2WasmExecutable(
        options.bindir),
                                 error_cmdline=options.error_cmdline)
    wast2wasm.AppendOptionalArgs({
        '--debug-names': options.debug_names,
        '--no-check': options.no_check,
        '--no-canonicalize-leb128s': options.no_canonicalize_leb128s,
        '--spec': options.spec,
        '-v': options.verbose,
        '-c': options.compile_only,
    })

    wasmdump = utils.Executable(find_exe.GetWasmdumpExecutable(options.bindir),
                                error_cmdline=options.error_cmdline)
    wasmdump.AppendOptionalArgs({
        '-h': options.headers,
        '-x': options.dump_verbose,
    })

    wast2wasm.verbose = options.print_cmd
    wasmdump.verbose = options.print_cmd

    filename = options.file

    with utils.TempDirectory(options.out_dir, 'wasmdump-') as out_dir:
        basename = os.path.basename(filename)
        basename_noext = os.path.splitext(basename)[0]
        if options.spec:
            out_file = os.path.join(out_dir, basename_noext + '.json')
        else:
            out_file = os.path.join(out_dir, basename_noext + '.wasm')
        wast2wasm.RunWithArgs('-o', out_file, filename)

        if options.spec:
            wasm_files = utils.GetModuleFilenamesFromSpecJSON(out_file)
            wasm_files = [utils.ChangeDir(f, out_dir) for f in wasm_files]
        else:
            wasm_files = [out_file]

        for wasm_file in wasm_files:
            wasmdump.RunWithArgs('-d', wasm_file)
Ejemplo n.º 7
0
def main(args):
    parser = argparse.ArgumentParser()
    parser.add_argument('-v',
                        '--verbose',
                        help='print more diagnotic messages.',
                        action='store_true')
    parser.add_argument('-o',
                        '--out-dir',
                        metavar='PATH',
                        help='output directory for files.')
    parser.add_argument('--bindir',
                        metavar='PATH',
                        default=find_exe.GetDefaultPath(),
                        help='directory to search for all executables.')
    parser.add_argument(
        '--stdout',
        action='store_true',
        help='do one roundtrip and write wast output to stdout')
    parser.add_argument(
        '--no-error-cmdline',
        help='don\'t display the subprocess\'s commandline when' +
        ' an error occurs',
        dest='error_cmdline',
        action='store_false')
    parser.add_argument('-p',
                        '--print-cmd',
                        help='print the commands that are run.',
                        action='store_true')
    parser.add_argument('--no-check', action='store_true')
    parser.add_argument('--debug-names', action='store_true')
    parser.add_argument('--generate-names', action='store_true')
    parser.add_argument('--fold-exprs', action='store_true')
    parser.add_argument('--enable-exceptions', action='store_true')
    parser.add_argument('--enable-threads', action='store_true')
    parser.add_argument('--enable-simd', action='store_true')
    parser.add_argument('--inline-exports', action='store_true')
    parser.add_argument('--inline-imports', action='store_true')
    parser.add_argument('file', help='test file.')
    options = parser.parse_args(args)

    wat2wasm = utils.Executable(find_exe.GetWat2WasmExecutable(options.bindir),
                                error_cmdline=options.error_cmdline)
    wat2wasm.AppendOptionalArgs({
        '--debug-names': options.debug_names,
        '--enable-exceptions': options.enable_exceptions,
        '--enable-threads': options.enable_threads,
        '--enable-simd': options.enable_simd,
        '--no-check': options.no_check,
    })

    wasm2wat = utils.Executable(find_exe.GetWasm2WatExecutable(options.bindir),
                                error_cmdline=options.error_cmdline)
    wasm2wat.AppendOptionalArgs({
        '--fold-exprs': options.fold_exprs,
        '--enable-exceptions': options.enable_exceptions,
        '--enable-threads': options.enable_threads,
        '--enable-simd': options.enable_simd,
        '--inline-exports': options.inline_exports,
        '--inline-imports': options.inline_imports,
        '--no-debug-names': not options.debug_names,
        '--generate-names': options.generate_names,
        '--no-check': options.no_check,
    })

    wat2wasm.verbose = options.print_cmd
    wasm2wat.verbose = options.print_cmd

    filename = options.file
    if not os.path.exists(filename):
        sys.stderr.write('File not found: %s\n' % filename)
        return ERROR

    with utils.TempDirectory(options.out_dir, 'roundtrip-') as out_dir:
        if options.stdout:
            result, msg = OneRoundtripToStdout(wat2wasm, wasm2wat, out_dir,
                                               filename, options.verbose)
        else:
            result, msg = TwoRoundtrips(wat2wasm, wasm2wat, out_dir, filename,
                                        options.verbose)
        if result == ERROR:
            sys.stderr.write(msg)
        return result
Ejemplo n.º 8
0
def main(args):
    parser = argparse.ArgumentParser()
    parser.add_argument('-o', '--out-dir', metavar='PATH',
                        help='output directory for files.')
    parser.add_argument('-P', '--prefix', metavar='PATH', help='prefix file.',
                        default=os.path.join(SCRIPT_DIR, 'spec-wasm2c-prefix.c'))
    parser.add_argument('--bindir', metavar='PATH',
                        default=find_exe.GetDefaultPath(),
                        help='directory to search for all executables.')
    parser.add_argument('--wasmrt-dir', metavar='PATH',
                        help='directory with wasm-rt files', default=WASM2C_DIR)
    parser.add_argument('--cc', metavar='PATH',
                        help='the path to the C compiler', default='cc')
    parser.add_argument('--cflags', metavar='FLAGS',
                        help='additional flags for C compiler.',
                        action='append', default=[])
    parser.add_argument('--compile', help='compile the C code (default)',
                        dest='compile', action='store_true')
    parser.add_argument('--no-compile', help='don\'t compile the C code',
                        dest='compile', action='store_false')
    parser.set_defaults(compile=True)
    parser.add_argument('--no-run', help='don\'t run the compiled executable',
                        dest='run', action='store_false')
    parser.add_argument('-v', '--verbose', help='print more diagnotic messages.',
                        action='store_true')
    parser.add_argument('--no-error-cmdline',
                        help='don\'t display the subprocess\'s commandline when '
                        'an error occurs', dest='error_cmdline',
                        action='store_false')
    parser.add_argument('-p', '--print-cmd',
                        help='print the commands that are run.',
                        action='store_true')
    parser.add_argument('file', help='wast file.')
    options = parser.parse_args(args)

    with utils.TempDirectory(options.out_dir, 'run-spec-wasm2c-') as out_dir:
        # Parse JSON file and generate main .c file with calls to test functions.
        wast2json = utils.Executable(
            find_exe.GetWast2JsonExecutable(options.bindir),
            error_cmdline=options.error_cmdline)
        wast2json.AppendOptionalArgs({'-v': options.verbose})

        json_file_path = utils.ChangeDir(
            utils.ChangeExt(options.file, '.json'), out_dir)
        wast2json.RunWithArgs(options.file, '-o', json_file_path)

        wasm2c = utils.Executable(
            find_exe.GetWasm2CExecutable(options.bindir),
            error_cmdline=options.error_cmdline)

        cc = utils.Executable(options.cc, *options.cflags)

        with open(json_file_path) as json_file:
            spec_json = json.load(json_file)

        prefix = ''
        if options.prefix:
            with open(options.prefix) as prefix_file:
                prefix = prefix_file.read() + '\n'

        output = io.StringIO()
        cwriter = CWriter(spec_json, prefix, output, out_dir)
        cwriter.Write()

        main_filename = utils.ChangeExt(json_file_path, '-main.c')
        with open(main_filename, 'w') as out_main_file:
            out_main_file.write(output.getvalue())

        o_filenames = []
        includes = '-I%s' % options.wasmrt_dir

        # Compile wasm-rt-impl.
        wasm_rt_impl_c = os.path.join(options.wasmrt_dir, 'wasm-rt-impl.c')
        o_filenames.append(Compile(cc, wasm_rt_impl_c, out_dir, includes))

        for i, wasm_filename in enumerate(cwriter.GetModuleFilenames()):
            c_filename = utils.ChangeExt(wasm_filename, '.c')
            wasm2c.RunWithArgs(wasm_filename, '-o', c_filename, cwd=out_dir)
            if options.compile:
                defines = '-DWASM_RT_MODULE_PREFIX=%s' % cwriter.GetModulePrefix(i)
                o_filenames.append(Compile(cc, c_filename, out_dir, includes, defines))

        if options.compile:
            main_c = os.path.basename(main_filename)
            o_filenames.append(Compile(cc, main_c, out_dir, includes, defines))
            main_exe = os.path.basename(utils.ChangeExt(json_file_path, ''))
            Link(cc, o_filenames, main_exe, out_dir, '-lm')

        if options.compile and options.run:
            utils.Executable(os.path.join(out_dir, main_exe),
                             forward_stdout=True).RunWithArgs()

    return 0
Ejemplo n.º 9
0
def main(args):
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument('-o', '--output', metavar='PATH', help='output file.')
    parser.add_argument('-P',
                        '--prefix',
                        metavar='PATH',
                        help='prefix file.',
                        default=os.path.join(SCRIPT_DIR, 'gen-spec-prefix.js'))
    parser.add_argument('--bindir',
                        metavar='PATH',
                        default=find_exe.GetDefaultPath(),
                        help='directory to search for all executables.')
    parser.add_argument('--temp-dir',
                        metavar='PATH',
                        help='set the directory that temporary wasm/wat'
                        ' files are written.')
    parser.add_argument(
        '--no-error-cmdline',
        help='don\'t display the subprocess\'s commandline when'
        ' an error occurs',
        dest='error_cmdline',
        action='store_false')
    parser.add_argument('-p',
                        '--print-cmd',
                        help='print the commands that are run.',
                        action='store_true')
    parser.add_argument('file', help='spec json file.')
    options = parser.parse_args(args)

    wat2wasm = Executable(find_exe.GetWat2WasmExecutable(options.bindir),
                          error_cmdline=options.error_cmdline)
    wasm2wat = Executable(find_exe.GetWasm2WatExecutable(options.bindir),
                          error_cmdline=options.error_cmdline)

    wat2wasm.verbose = options.print_cmd
    wasm2wat.verbose = options.print_cmd

    with open(options.file) as json_file:
        json_dir = os.path.dirname(options.file)
        spec_json = json.load(json_file)
        all_commands = spec_json['commands']

    # modules is a list of pairs: [(module_command, [assert_command, ...]), ...]
    modules = CollectInvalidModuleCommands(all_commands)

    with utils.TempDirectory(options.temp_dir, 'gen-spec-js-') as temp_dir:
        extender = ModuleExtender(wat2wasm, wasm2wat, temp_dir)
        for module_command, assert_commands in modules:
            if assert_commands:
                wasm_path = os.path.join(json_dir, module_command['filename'])
                new_module_filename = extender.Extend(wasm_path,
                                                      assert_commands)
                module_command['filename'] = new_module_filename

        output = io.StringIO()
        if options.prefix:
            with open(options.prefix) as prefix_file:
                output.write(prefix_file.read())
                output.write('\n')

        JSWriter(json_dir, spec_json, output).Write()

    if options.output:
        out_file = open(options.output, 'w')
    else:
        out_file = sys.stdout

    try:
        out_file.write(output.getvalue())
    finally:
        out_file.close()

    return 0
Ejemplo n.º 10
0
def main(args):
    parser = argparse.ArgumentParser()
    parser.add_argument('-a',
                        '--arg',
                        help='additional args to pass to executable',
                        action='append')
    parser.add_argument('--bindir',
                        metavar='PATH',
                        default=find_exe.GetDefaultPath(),
                        help='directory to search for all executables.')
    parser.add_argument('-v',
                        '--verbose',
                        help='print more diagnotic messages.',
                        action='store_true')
    parser.add_argument('-f',
                        '--fail-fast',
                        help='Exit on first failure. '
                        'Extra options with \'--jobs 1\'',
                        action='store_true')
    parser.add_argument('--stop-interactive',
                        help='Enter interactive mode on errors. '
                        'Extra options with \'--jobs 1\'',
                        action='store_true')
    parser.add_argument('-l',
                        '--list',
                        help='list all tests.',
                        action='store_true')
    parser.add_argument('-r',
                        '--rebase',
                        help='rebase a test to its current output.',
                        action='store_true')
    parser.add_argument('-j',
                        '--jobs',
                        help='number of jobs to use to run tests',
                        type=int,
                        default=GetDefaultJobCount())
    parser.add_argument('-t',
                        '--timeout',
                        type=float,
                        default=DEFAULT_TIMEOUT,
                        help='per test timeout in seconds')
    parser.add_argument('--no-roundtrip',
                        help='don\'t run roundtrip.py on all tests',
                        action='store_false',
                        default=True,
                        dest='roundtrip')
    parser.add_argument('patterns',
                        metavar='pattern',
                        nargs='*',
                        help='test patterns.')
    options = parser.parse_args(args)

    if options.jobs != 1:
        if options.fail_fast:
            parser.error('--fail-fast only works with -j1')
        if options.stop_interactive:
            parser.error('--stop-interactive only works with -j1')

    if options.patterns:
        pattern_re = '|'.join(
            fnmatch.translate('*%s*' % p) for p in options.patterns)
    else:
        pattern_re = '.*'

    test_names = FindTestFiles('.txt', pattern_re)

    if options.list:
        for test_name in test_names:
            print(test_name)
        return 0
    if not test_names:
        print('no tests match that filter')
        return 1

    variables = {}
    variables['test_dir'] = os.path.abspath(TEST_DIR)
    variables['bindir'] = options.bindir
    for exe_basename in find_exe.EXECUTABLES:
        exe_override = os.path.join(options.bindir, exe_basename)
        variables[exe_basename] = find_exe.FindExecutable(
            exe_basename, exe_override)

    status = Status(options.verbose)
    infos = GetAllTestInfo(test_names, status)
    infos_to_run = []
    for info in infos:
        if info.skip:
            status.Skipped(info)
            continue
        infos_to_run.append(info)

        if options.roundtrip and info.ShouldCreateRoundtrip():
            infos_to_run.append(info.CreateRoundtripInfo())

    if not os.path.exists(OUT_DIR):
        os.makedirs(OUT_DIR)

    status.Start(len(infos_to_run))

    try:
        if options.jobs > 1:
            RunMultiThreaded(infos_to_run, status, options, variables)
        else:
            RunSingleThreaded(infos_to_run, status, options, variables)
    except KeyboardInterrupt:
        print('\nInterrupted testing\n')

    status.Clear()

    ret = 0

    if status.failed:
        sys.stderr.write('**** FAILED %s\n' % ('*' * (80 - 14)))
        for info in status.failed_tests:
            sys.stderr.write('- %s\n    %s\n' %
                             (info.GetName(), ' '.join(info.last_cmd)))
        ret = 1

    status.Print()
    return ret
Ejemplo n.º 11
0
def main(args):
    parser = argparse.ArgumentParser()
    parser.add_argument('-v',
                        '--verbose',
                        help='print more diagnotic messages.',
                        action='store_true')
    parser.add_argument('-o',
                        '--out-dir',
                        metavar='PATH',
                        help='output directory for files.')
    parser.add_argument('--bindir',
                        metavar='PATH',
                        default=find_exe.GetDefaultPath(),
                        help='directory to search for all executables.')
    parser.add_argument(
        '--no-error-cmdline',
        help='don\'t display the subprocess\'s commandline when' +
        ' an error occurs',
        dest='error_cmdline',
        action='store_false')
    parser.add_argument('-p',
                        '--print-cmd',
                        action='store_true',
                        help='print the commands that are run.')
    parser.add_argument('--no-debug-names', action='store_true')
    parser.add_argument('--objdump',
                        action='store_true',
                        help="objdump the resulting binary")
    parser.add_argument('file', help='test file.')
    options = parser.parse_args(args)

    gen_wasm = utils.Executable(sys.executable,
                                GEN_WASM_PY,
                                error_cmdline=options.error_cmdline,
                                basename=os.path.basename(GEN_WASM_PY))

    objdump = utils.Executable(find_exe.GetWasmdumpExecutable(options.bindir),
                               error_cmdline=options.error_cmdline)

    wasm2wat = utils.Executable(find_exe.GetWasm2WatExecutable(options.bindir),
                                error_cmdline=options.error_cmdline)
    wasm2wat.AppendOptionalArgs({
        '--no-debug-names': options.no_debug_names,
        '--verbose': options.verbose,
    })

    wasmvalidate = utils.Executable(find_exe.GetWasmValidateExecutable(
        options.bindir),
                                    error_cmdline=options.error_cmdline)
    wasmvalidate.AppendOptionalArgs({
        '--no-debug-names': options.no_debug_names,
    })

    gen_wasm.verbose = options.print_cmd
    wasm2wat.verbose = options.print_cmd
    wasmvalidate.verbose = options.print_cmd
    objdump.verbose = options.print_cmd

    with utils.TempDirectory(options.out_dir, 'run-gen-wasm-') as out_dir:
        out_file = utils.ChangeDir(utils.ChangeExt(options.file, '.wasm'),
                                   out_dir)
        gen_wasm.RunWithArgs(options.file, '-o', out_file)
        if options.objdump:
            objdump.RunWithArgs(out_file, '-x')
        else:
            # Test running wasm-validate on all files. wasm2wat should produce the
            # same errors, so let's make sure that's true.
            validate_ok = False
            wasm2wat_ok = False

            try:
                try:
                    wasmvalidate.RunWithArgs(out_file)
                    validate_ok = True
                except Error as e:
                    sys.stderr.write(str(e) + '\n')

                try:
                    wasm2wat.RunWithArgs(out_file)
                    wasm2wat_ok = True
                except Error as e:
                    raise
            finally:
                if validate_ok != wasm2wat_ok:
                    sys.stderr.write(
                        'wasm-validate and wasm2wat have different results!')
Ejemplo n.º 12
0
def main(args):
  parser = argparse.ArgumentParser()
  parser.add_argument('-v', '--verbose', help='print more diagnotic messages.',
                      action='store_true')
  parser.add_argument('-o', '--out-dir', metavar='PATH',
                      help='output directory for files.')
  parser.add_argument('--bindir', metavar='PATH',
                      default=find_exe.GetDefaultPath(),
                      help='directory to search for all executables.')
  parser.add_argument('--no-error-cmdline',
                      help='don\'t display the subprocess\'s commandline when'
                      + ' an error occurs', dest='error_cmdline',
                      action='store_false')
  parser.add_argument('-p', '--print-cmd',
                      help='print the commands that are run.',
                      action='store_true')
  parser.add_argument('--headers', action='store_true')
  parser.add_argument('--no-check', action='store_true')
  parser.add_argument('--dump-verbose', action='store_true')
  parser.add_argument('--dump-debug', action='store_true')
  parser.add_argument('--enable-exceptions', action='store_true')
  parser.add_argument('--enable-saturating-float-to-int', action='store_true')
  parser.add_argument('--enable-threads', action='store_true')
  parser.add_argument('--enable-simd', action='store_true')
  parser.add_argument('--gen-wasm', action='store_true',
                      help='parse with gen-wasm')
  parser.add_argument('--spec', action='store_true')
  parser.add_argument('-r', '--relocatable', action='store_true')
  parser.add_argument('--no-canonicalize-leb128s', action='store_true')
  parser.add_argument('--debug-names', action='store_true')
  parser.add_argument('file', help='test file.')
  options = parser.parse_args(args)

  if options.gen_wasm and options.spec:
    parser.error('Can\'t use both --gen-wasm and --spec')

  gen_wasm = utils.Executable(sys.executable, GEN_WASM_PY,
                              error_cmdline=options.error_cmdline)

  wat_tool = None
  if options.spec:
    wat_tool = utils.Executable(
        find_exe.GetWast2JsonExecutable(options.bindir),
        error_cmdline=options.error_cmdline)
  else:
    wat_tool = utils.Executable(
        find_exe.GetWat2WasmExecutable(options.bindir),
        error_cmdline=options.error_cmdline)

  wat_tool.AppendOptionalArgs({
      '--debug-names': options.debug_names,
      '--enable-exceptions': options.enable_exceptions,
      '--enable-saturating-float-to-int':
          options.enable_saturating_float_to_int,
      '--enable-threads': options.enable_threads,
      '--enable-simd': options.enable_simd,
      '--no-check': options.no_check,
      '--no-canonicalize-leb128s': options.no_canonicalize_leb128s,
      '-v': options.verbose,
      '-r': options.relocatable,
  })

  wasm_objdump = utils.Executable(
      find_exe.GetWasmdumpExecutable(options.bindir),
      error_cmdline=options.error_cmdline)
  wasm_objdump.AppendOptionalArgs({
      '-h': options.headers,
      '-x': options.dump_verbose,
      '--debug': options.dump_debug,
  })

  gen_wasm.verbose = options.print_cmd
  wat_tool.verbose = options.print_cmd
  wasm_objdump.verbose = options.print_cmd

  filename = options.file

  with utils.TempDirectory(options.out_dir, 'objdump-') as out_dir:
    basename = os.path.basename(filename)
    basename_noext = os.path.splitext(basename)[0]
    if options.gen_wasm:
      out_file = os.path.join(out_dir, basename_noext + '.wasm')
      gen_wasm.RunWithArgs('-o', out_file, filename)
    else:
      if options.spec:
        out_file = os.path.join(out_dir, basename_noext + '.json')
      else:
        out_file = os.path.join(out_dir, basename_noext + '.wasm')
      wat_tool.RunWithArgs('-o', out_file, filename)

    if options.spec:
      wasm_files = utils.GetModuleFilenamesFromSpecJSON(out_file)
      wasm_files = [utils.ChangeDir(f, out_dir) for f in wasm_files]
    else:
      wasm_files = [out_file]

    wasm_objdump.RunWithArgs('-r', '-d', *wasm_files)
Ejemplo n.º 13
0
def main(args):
  parser = argparse.ArgumentParser()
  parser.add_argument('-v', '--verbose', help='print more diagnotic messages.',
                      action='store_true')
  parser.add_argument('-r', '--relocatable', action='store_true',
                      help='final output is relocatable')
  parser.add_argument('-o', '--out-dir', metavar='PATH',
                      help='output directory for files.')
  parser.add_argument('--bindir', metavar='PATH',
                      default=find_exe.GetDefaultPath(),
                      help='directory to search for all executables.')
  parser.add_argument('--no-error-cmdline',
                      help='don\'t display the subprocess\'s commandline when'
                      + ' an error occurs', dest='error_cmdline',
                      action='store_false')
  parser.add_argument('-p', '--print-cmd',
                      help='print the commands that are run.',
                      action='store_true')
  parser.add_argument('--incremental', help='incremenatly link one object at' +
                      ' a time to produce the final linked binary.',
                      action='store_true')
  parser.add_argument('--debug-names', action='store_true')
  parser.add_argument('--dump-verbose', action='store_true')
  parser.add_argument('--spec', action='store_true')
  parser.add_argument('file', help='test file.')
  options = parser.parse_args(args)

  wast2json = utils.Executable(
      find_exe.GetWast2JsonExecutable(options.bindir),
      error_cmdline=options.error_cmdline)
  wast2json.AppendOptionalArgs({
      '--debug-names': options.debug_names,
      '-v': options.dump_verbose,
  })

  wasm_link = utils.Executable(
      find_exe.GetWasmlinkExecutable(options.bindir),
      error_cmdline=options.error_cmdline)
  wasm_link.AppendOptionalArgs({
      '-v': options.verbose,
      '-r': options.relocatable,
  })

  wasm_objdump = utils.Executable(
      find_exe.GetWasmdumpExecutable(options.bindir),
      error_cmdline=options.error_cmdline)

  spectest_interp = utils.Executable(
      find_exe.GetSpectestInterpExecutable(options.bindir),
      error_cmdline=options.error_cmdline)

  wast2json.verbose = options.print_cmd
  wasm_link.verbose = options.print_cmd
  wasm_objdump.verbose = options.print_cmd
  spectest_interp.verbose = options.print_cmd

  filename = options.file

  with utils.TempDirectory(options.out_dir, 'wasm-link-') as out_dir:
    basename = os.path.basename(filename)
    basename_noext = os.path.splitext(basename)[0]
    out_file = os.path.join(out_dir, basename_noext + '.json')
    wast2json.RunWithArgs('--debug-names', '--no-check', '-r', '-o',
                          out_file, filename)

    wasm_files = utils.GetModuleFilenamesFromSpecJSON(out_file)
    wasm_files = [utils.ChangeDir(f, out_dir) for f in wasm_files]

    output = os.path.join(out_dir, 'linked.wasm')
    if options.incremental:
      partially_linked = output + '.partial'
      for i, f in enumerate(wasm_files):
        if i == 0:
          wasm_link.RunWithArgs('-o', output, f)
        else:
          if os.path.exists(partially_linked):
            os.remove(partially_linked)
          os.rename(output, partially_linked)
          wasm_link.RunWithArgs('-r', '-o', output, partially_linked, f)
        #wasm_objdump.RunWithArgs('-d', '-h', output)
      wasm_objdump.RunWithArgs('-d', '-x', '-r', '-h', output)
    else:
      wasm_link.RunWithArgs('-o', output, *wasm_files)
      wasm_objdump.RunWithArgs('-d', '-x', '-r', '-h', output)

    if options.spec:
      with open(out_file) as json_file:
        spec = json.load(json_file, object_pairs_hook=OrderedDict)
        spec['commands'] = [c for c in spec['commands']
                            if c['type'] != 'module']
        module = OrderedDict([('type', 'module'),
                              ('line', 0),
                              ('filename', os.path.basename(output)),])
        spec['commands'].insert(0, module)

      with open(out_file, 'wb') as json_file:
        json.dump(spec, json_file, indent=4)

      spectest_interp.RunWithArgs(out_file)
Ejemplo n.º 14
0
def main(args):
    parser = argparse.ArgumentParser()
    parser.add_argument('-o',
                        '--out-dir',
                        metavar='PATH',
                        help='output directory for files.')
    parser.add_argument('-v',
                        '--verbose',
                        help='print more diagnotic messages.',
                        action='store_true')
    parser.add_argument('--bindir',
                        metavar='PATH',
                        default=find_exe.GetDefaultPath(),
                        help='directory to search for all executables.')
    parser.add_argument(
        '--no-error-cmdline',
        help='don\'t display the subprocess\'s commandline when' +
        ' an error occurs',
        dest='error_cmdline',
        action='store_false')
    parser.add_argument('-p',
                        '--print-cmd',
                        help='print the commands that are run.',
                        action='store_true')
    parser.add_argument('--run-all-exports', action='store_true')
    parser.add_argument('--host-print', action='store_true')
    parser.add_argument('-t', '--trace', action='store_true')
    parser.add_argument('file', help='test file.')
    parser.add_argument('--enable-saturating-float-to-int',
                        action='store_true')
    parser.add_argument('--enable-threads', action='store_true')
    parser.add_argument('--trap-on-failed-comp', action='store_true')
    options = parser.parse_args(args)

    wast_tool = None
    interp_tool = None
    interp_jit_tool = None
    wast_tool = utils.Executable(find_exe.GetWat2WasmExecutable(
        options.bindir),
                                 error_cmdline=options.error_cmdline)
    interp_tool = utils.Executable(find_exe.GetWasmInterpExecutable(
        options.bindir),
                                   error_cmdline=options.error_cmdline)
    interp_tool.AppendOptionalArgs({
        '--host-print':
        options.host_print,
        '--run-all-exports':
        options.run_all_exports,
    })

    interp_jit_tool = utils.Executable(find_exe.GetWasmInterpExecutable(
        options.bindir),
                                       error_cmdline=options.error_cmdline)
    interp_jit_tool.AppendOptionalArgs({
        '--host-print':
        options.host_print,
        '--run-all-exports':
        options.run_all_exports,
    })

    wast_tool.AppendOptionalArgs({
        '-v': options.verbose,
        '--enable-saturating-float-to-int':
        options.enable_saturating_float_to_int,
        '--enable-threads': options.enable_threads,
    })

    interp_tool.AppendOptionalArgs({
        '-v':
        options.verbose,
        '--run-all-exports':
        options.run_all_exports,
        '--trace':
        options.trace,
        '--enable-saturating-float-to-int':
        options.enable_saturating_float_to_int,
        '--enable-threads':
        options.enable_threads,
        '--disable-jit':
        True,
    })
    interp_jit_tool.AppendOptionalArgs({
        '-v':
        options.verbose,
        '--run-all-exports':
        options.run_all_exports,
        '--trace':
        options.trace,
        '--enable-saturating-float-to-int':
        options.enable_saturating_float_to_int,
        '--enable-threads':
        options.enable_threads,
        '--trap-on-failed-comp':
        options.trap_on_failed_comp,
    })

    wast_tool.verbose = options.print_cmd
    interp_tool.verbose = options.print_cmd
    interp_jit_tool.verbose = options.print_cmd

    with utils.TempDirectory(options.out_dir, 'run-jit-perform-') as out_dir:
        if not options.file.endswith('.wasm'):
            new_ext = '.wasm'
            out_file = utils.ChangeDir(utils.ChangeExt(options.file, new_ext),
                                       out_dir)
            wast_tool.RunWithArgs(options.file, '-o', out_file)
        else:
            out_file = options.file
        start = time.time()
        interp_out = interp_tool.RunWithArgsForStdout(out_file)
        interp_time = time.time() - start
        start = time.time()
        jit_out = interp_jit_tool.RunWithArgsForStdout(out_file)
        jit_time = time.time() - start
        print("Interpreter: {}\nJIT: {}".format(interp_time, jit_time))
        expected_lines = [line for line in interp_out.splitlines() if line]
        actual_lines = [line for line in jit_out.splitlines() if line]
        diff_lines = list(
            difflib.unified_diff(expected_lines,
                                 actual_lines,
                                 fromfile='expected',
                                 tofile='actual',
                                 lineterm=''))
        msg = ""
        if len(diff_lines) > 0:
            msg += 'STDOUT MISMATCH:\n' + '\n'.join(diff_lines) + '\n'

        if msg:
            raise Error(msg)

    return 0
Ejemplo n.º 15
0
def main(args):
    parser = argparse.ArgumentParser()
    parser.add_argument('-a',
                        '--arg',
                        help='additional args to pass to executable',
                        action='append')
    parser.add_argument('--bindir',
                        metavar='PATH',
                        default=find_exe.GetDefaultPath(),
                        help='directory to search for all executables.')
    parser.add_argument('-v',
                        '--verbose',
                        help='print more diagnotic messages.',
                        action='store_true')
    parser.add_argument('-f',
                        '--fail-fast',
                        help='Exit on first failure. '
                        'Extra options with \'--jobs 1\'',
                        action='store_true')
    parser.add_argument('--stop-interactive',
                        help='Enter interactive mode on errors. '
                        'Extra options with \'--jobs 1\'',
                        action='store_true')
    parser.add_argument('-l',
                        '--list',
                        help='list all tests.',
                        action='store_true')
    parser.add_argument('-r',
                        '--rebase',
                        help='rebase a test to its current output.',
                        action='store_true')
    parser.add_argument('-j',
                        '--jobs',
                        help='number of jobs to use to run tests',
                        type=int,
                        default=GetDefaultJobCount())
    parser.add_argument('-t',
                        '--timeout',
                        type=float,
                        default=DEFAULT_TIMEOUT,
                        help='per test timeout in seconds')
    parser.add_argument('--no-roundtrip',
                        help='don\'t run roundtrip.py on all tests',
                        action='store_false',
                        default=True,
                        dest='roundtrip')
    parser.add_argument('-p',
                        '--print-cmd',
                        help='print the commands that are run.',
                        action='store_true')
    parser.add_argument('patterns',
                        metavar='pattern',
                        nargs='*',
                        help='test patterns.')
    options = parser.parse_args(args)

    if options.jobs != 1:
        if options.fail_fast:
            parser.error('--fail-fast only works with -j1')
        if options.stop_interactive:
            parser.error('--stop-interactive only works with -j1')

    if options.patterns:
        exclude_dirs = []
        pattern_re = '|'.join(
            fnmatch.translate('*%s*' % p) for p in options.patterns)
    else:
        pattern_re = '.*'
        # By default, exclude wasi tests because WASI support is not include
        # by int the build by default.
        # TODO(sbc): Find some way to detect the WASI support.
        exclude_dirs = ['wasi']

    test_names = FindTestFiles('.txt', pattern_re, exclude_dirs)

    if options.list:
        for test_name in test_names:
            print(test_name)
        return 0
    if not test_names:
        print('no tests match that filter')
        return 1

    variables = {}
    variables['test_dir'] = os.path.abspath(TEST_DIR)
    variables['bindir'] = options.bindir
    variables['gen_wasm_py'] = os.path.join(TEST_DIR, 'gen-wasm.py')
    variables['gen_spec_js_py'] = os.path.join(TEST_DIR, 'gen-spec-js.py')
    for exe_basename in find_exe.EXECUTABLES:
        exe_override = os.path.join(options.bindir, exe_basename)
        variables[exe_basename] = find_exe.FindExecutable(
            exe_basename, exe_override)

    status = Status(sys.stderr.isatty() and not options.verbose)
    infos = GetAllTestInfo(test_names, status)
    infos_to_run = []
    for info in infos:
        if info.skip:
            status.Skipped(info)
            continue
        infos_to_run.append(info)

        if options.roundtrip:
            for fold_exprs in False, True:
                try:
                    infos_to_run.append(
                        info.CreateRoundtripInfo(fold_exprs=fold_exprs))
                except NoRoundtripError:
                    pass

    if not os.path.exists(OUT_DIR):
        os.makedirs(OUT_DIR)

    status.Start(len(infos_to_run))

    try:
        if options.jobs > 1:
            RunMultiThreaded(infos_to_run, status, options, variables)
        else:
            RunSingleThreaded(infos_to_run, status, options, variables)
    except KeyboardInterrupt:
        print('\nInterrupted testing\n')

    status.Done()

    ret = 0
    if status.failed:
        sys.stderr.write('**** FAILED %s\n' % ('*' * (80 - 14)))
        for info, result in status.failed_tests:
            if isinstance(result, TestResult):
                msg = result.GetLastCommand()
            elif isinstance(result, Error):
                msg = result
            else:
                msg = ''
            sys.stderr.write('- %s\n    %s\n' % (info.GetName(), msg))
        ret = 1

    return ret
Ejemplo n.º 16
0
def main(args):
    default_compiler = 'cc'
    if IS_WINDOWS:
        default_compiler = 'cl.exe'
    parser = argparse.ArgumentParser()
    parser.add_argument('-o', '--out-dir', metavar='PATH',
                        help='output directory for files.')
    parser.add_argument('-P', '--prefix', metavar='PATH', help='prefix file.',
                        default=os.path.join(SCRIPT_DIR, 'spec-wasm2c-prefix.c'))
    parser.add_argument('--bindir', metavar='PATH',
                        default=find_exe.GetDefaultPath(),
                        help='directory to search for all executables.')
    parser.add_argument('--wasmrt-dir', metavar='PATH',
                        help='directory with wasm-rt files', default=WASM2C_DIR)
    parser.add_argument('--cc', metavar='PATH',
                        help='the path to the C compiler',
                        default=default_compiler)
    parser.add_argument('--cflags', metavar='FLAGS',
                        help='additional flags for C compiler.',
                        action='append', default=[])
    parser.add_argument('--compile', help='compile the C code (default)',
                        dest='compile', action='store_true')
    parser.add_argument('--no-compile', help='don\'t compile the C code',
                        dest='compile', action='store_false')
    parser.set_defaults(compile=True)
    parser.add_argument('--no-run', help='don\'t run the compiled executable',
                        dest='run', action='store_false')
    parser.add_argument('-v', '--verbose', help='print more diagnotic messages.',
                        action='store_true')
    parser.add_argument('--no-error-cmdline',
                        help='don\'t display the subprocess\'s commandline when '
                        'an error occurs', dest='error_cmdline',
                        action='store_false')
    parser.add_argument('-p', '--print-cmd',
                        help='print the commands that are run.',
                        action='store_true')
    parser.add_argument('file', help='wast file.')
    parser.add_argument('--enable-multi-memory', action='store_true')
    parser.add_argument('--disable-bulk-memory', action='store_true')
    parser.add_argument('--disable-reference-types', action='store_true')
    options = parser.parse_args(args)

    with utils.TempDirectory(options.out_dir, 'run-spec-wasm2c-') as out_dir:
        # Parse JSON file and generate main .c file with calls to test functions.
        wast2json = utils.Executable(
            find_exe.GetWast2JsonExecutable(options.bindir),
            error_cmdline=options.error_cmdline)
        wast2json.verbose = options.print_cmd
        wast2json.AppendOptionalArgs({
            '-v': options.verbose,
            '--enable-multi-memory': options.enable_multi_memory,
            '--disable-bulk-memory': options.disable_bulk_memory,
            '--disable-reference-types': options.disable_reference_types})

        json_file_path = utils.ChangeDir(
            utils.ChangeExt(options.file, '.json'), out_dir)
        wast2json.RunWithArgs(options.file, '-o', json_file_path)

        wasm2c = utils.Executable(
            find_exe.GetWasm2CExecutable(options.bindir),
            error_cmdline=options.error_cmdline)
        wasm2c.verbose = options.print_cmd
        wasm2c.AppendOptionalArgs({
            '--enable-multi-memory': options.enable_multi_memory})

        options.cflags += shlex.split(os.environ.get('WASM2C_CFLAGS', ''))
        cc = utils.Executable(options.cc, *options.cflags, forward_stderr=True,
                              forward_stdout=False)
        cc.verbose = options.print_cmd

        with open(json_file_path, encoding='utf-8') as json_file:
            spec_json = json.load(json_file)

        prefix = ''
        if options.prefix:
            with open(options.prefix) as prefix_file:
                prefix = prefix_file.read() + '\n'

        output = io.StringIO()
        cwriter = CWriter(spec_json, prefix, output, out_dir)
        cwriter.Write()

        main_filename = utils.ChangeExt(json_file_path, '-main.c')
        with open(main_filename, 'w') as out_main_file:
            out_main_file.write(output.getvalue())

        o_filenames = []
        includes = '-I%s' % options.wasmrt_dir

        for i, wasm_filename in enumerate(cwriter.GetModuleFilenames()):
            wasm_filename = os.path.join(out_dir, wasm_filename)
            c_filename = utils.ChangeExt(wasm_filename, '.c')
            args = ['-n', cwriter.GetModulePrefixUnmangled(i)]
            wasm2c.RunWithArgs(wasm_filename, '-o', c_filename, *args)
            if options.compile:
                o_filenames.append(Compile(cc, c_filename, out_dir, includes))

        if options.compile:
            # Compile wasm-rt-impl.
            wasm_rt_impl_c = os.path.join(options.wasmrt_dir, 'wasm-rt-impl.c')
            o_filenames.append(Compile(cc, wasm_rt_impl_c, out_dir, includes))

            # Compile and link -main test run entry point
            o_filenames.append(Compile(cc, main_filename, out_dir, includes))
            if IS_WINDOWS:
                exe_ext = '.exe'
                libs = []
            else:
                exe_ext = ''
                libs = ['-lm']
            main_exe = utils.ChangeExt(json_file_path, exe_ext)
            Link(cc, o_filenames, main_exe, *libs)

            # Run the resulting binary
            if options.run:
                utils.Executable(main_exe, forward_stdout=True).RunWithArgs()

    return 0
Ejemplo n.º 17
0
def main(args):
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument('-o', '--output', metavar='PATH', help='output file.')
    parser.add_argument('file', help='spec json file.')
    parser.add_argument('--bindir',
                        metavar='PATH',
                        default=find_exe.GetDefaultPath(),
                        help='directory to search for all executables.')
    parser.add_argument('--temp-dir',
                        metavar='PATH',
                        help='set the directory that temporary wasm/wat'
                        ' files are written.')
    parser.add_argument(
        '--no-error-cmdline',
        help='don\'t display the subprocess\'s commandline when'
        ' an error occurs',
        dest='error_cmdline',
        action='store_false')
    parser.add_argument('-p',
                        '--print-cmd',
                        help='print the commands that are run.',
                        action='store_true')
    parser.add_argument('--enable-exceptions', action='store_true')
    parser.add_argument('--enable-saturating-float-to-int',
                        action='store_true')
    parser.add_argument('--enable-threads', action='store_true')
    parser.add_argument('--enable-simd', action='store_true')
    parser.add_argument('--enable-sign-extension', action='store_true')
    parser.add_argument('--enable-multi-value', action='store_true')
    parser.add_argument('--enable-bulk-memory', action='store_true')
    parser.add_argument('--enable-tail-call', action='store_true')
    parser.add_argument('--enable-reference-types', action='store_true')
    options = parser.parse_args(args)

    wast2json = Executable(find_exe.GetWast2JsonExecutable(options.bindir),
                           error_cmdline=options.error_cmdline)
    wast2json.verbose = options.print_cmd
    wast2json.AppendOptionalArgs({
        '--enable-exceptions':
        options.enable_exceptions,
        '--enable-multi-value':
        options.enable_multi_value,
        '--enable-saturating-float-to-int':
        options.enable_saturating_float_to_int,
        '--enable-sign-extension':
        options.enable_sign_extension,
        '--enable-simd':
        options.enable_simd,
        '--enable-threads':
        options.enable_threads,
        '--enable-bulk-memory':
        options.enable_bulk_memory,
        '--enable-tail-call':
        options.enable_tail_call,
        '--enable-reference-types':
        options.enable_reference_types,
    })

    json_filename = options.file

    with utils.TempDirectory(options.temp_dir, 'gen-spec-wast-') as temp_dir:
        file_base, file_ext = os.path.splitext(json_filename)
        if file_ext == '.wast':
            wast_filename = options.file
            json_filename = ChangeDir(file_base + '.json', temp_dir)
            wast2json.RunWithArgs(wast_filename, '-o', json_filename)

        with open(json_filename) as json_file:
            json_dir = os.path.dirname(json_filename)
            spec_json = json.load(json_file)

        output = io.StringIO()
        WastWriter(json_dir, spec_json, output).Write()

    if options.output:
        out_file = open(options.output, 'w')
    else:
        out_file = sys.stdout

    try:
        out_file.write(output.getvalue())
    finally:
        out_file.close()

    return 0
Ejemplo n.º 18
0
def main(args):
    parser = argparse.ArgumentParser()
    parser.add_argument('-o',
                        '--out-dir',
                        metavar='PATH',
                        help='output directory for files.')
    parser.add_argument('-v',
                        '--verbose',
                        help='print more diagnotic messages.',
                        action='store_true')
    parser.add_argument('--bindir',
                        metavar='PATH',
                        default=find_exe.GetDefaultPath(),
                        help='directory to search for all executables.')
    parser.add_argument(
        '--no-error-cmdline',
        help='don\'t display the subprocess\'s commandline when' +
        ' an error occurs',
        dest='error_cmdline',
        action='store_false')
    parser.add_argument('-p',
                        '--print-cmd',
                        help='print the commands that are run.',
                        action='store_true')
    parser.add_argument('--run-all-exports', action='store_true')
    parser.add_argument('--host-print', action='store_true')
    parser.add_argument('--spec', action='store_true')
    parser.add_argument('-t', '--trace', action='store_true')
    parser.add_argument('file', help='test file.')
    parser.add_argument('--enable-saturating-float-to-int',
                        action='store_true')
    parser.add_argument('--enable-threads', action='store_true')
    parser.add_argument('--disable-jit', action='store_true')
    parser.add_argument('--trap-on-failed-comp', action='store_true')
    options = parser.parse_args(args)

    wast_tool = None
    interp_tool = None
    if options.spec:
        wast_tool = utils.Executable(find_exe.GetWast2JsonExecutable(
            options.bindir),
                                     error_cmdline=options.error_cmdline)
        interp_tool = utils.Executable(find_exe.GetSpectestInterpExecutable(
            options.bindir),
                                       error_cmdline=options.error_cmdline)
    else:
        wast_tool = utils.Executable(find_exe.GetWat2WasmExecutable(
            options.bindir),
                                     error_cmdline=options.error_cmdline)
        interp_tool = utils.Executable(find_exe.GetWasmInterpExecutable(
            options.bindir),
                                       error_cmdline=options.error_cmdline)
        interp_tool.AppendOptionalArgs({
            '--host-print':
            options.host_print,
            '--run-all-exports':
            options.run_all_exports,
        })

    wast_tool.AppendOptionalArgs({
        '-v': options.verbose,
        '--enable-saturating-float-to-int':
        options.enable_saturating_float_to_int,
        '--enable-threads': options.enable_threads,
    })

    interp_tool.AppendOptionalArgs({
        '-v':
        options.verbose,
        '--run-all-exports':
        options.run_all_exports,
        '--trap-on-failed-comp':
        options.trap_on_failed_comp,
        '--trace':
        options.trace,
        '--enable-saturating-float-to-int':
        options.enable_saturating_float_to_int,
        '--enable-threads':
        options.enable_threads,
        '--disable-jit':
        options.disable_jit,
        '--no-stack-trace':
        not options.spec
    })

    wast_tool.verbose = options.print_cmd
    interp_tool.verbose = options.print_cmd

    with utils.TempDirectory(options.out_dir, 'run-interp-') as out_dir:
        new_ext = '.json' if options.spec else '.wasm'
        out_file = utils.ChangeDir(utils.ChangeExt(options.file, new_ext),
                                   out_dir)
        wast_tool.RunWithArgs(options.file, '-o', out_file)
        interp_tool.RunWithArgs(out_file)

    return 0