| 73 | return subprocess.call(cmd, shell=True) |
| 74 | |
| 75 | class Runner(object): |
| 76 | def __init__(self, name, outdir, tempdir): |
| 77 | self.name = name |
| 78 | self.outdir = outdir |
| 79 | self.tempdir = tempdir |
| 80 | self.src_file_basename = os.path.join(WASM_PATH, "example", name) |
| 81 | self.dst_file_basename = os.path.join(tempdir, name) |
| 82 | self.lib_file = os.path.join(outdir, "obj", "libwee8.a") |
| 83 | if not os.path.exists(self.lib_file): |
| 84 | print("libwee8 library not found, make sure to pass the outdir as " |
| 85 | "first argument; see --help") |
| 86 | sys.exit(1) |
| 87 | src_wasm_file = self.src_file_basename + ".wasm" |
| 88 | dst_wasm_file = self.dst_file_basename + ".wasm" |
| 89 | shutil.copyfile(src_wasm_file, dst_wasm_file) |
| 90 | |
| 91 | def _Error(self, step, lang, compiler, code): |
| 92 | print("Error: %s failed. To repro: tools/run-wasm-api-tests.py " |
| 93 | "%s %s %s %s %s" % |
| 94 | (step, self.outdir, self.tempdir, self.name, lang, |
| 95 | compiler["name"].lower())) |
| 96 | return code |
| 97 | |
| 98 | def CompileAndRun(self, compiler, language): |
| 99 | print("==== %s %s/%s ====" % |
| 100 | (self.name, language["name"], compiler["name"])) |
| 101 | lang = language["suffix"] |
| 102 | src_file = self.src_file_basename + "." + lang |
| 103 | exe_file = self.dst_file_basename + "-" + lang |
| 104 | obj_file = exe_file + ".o" |
| 105 | # Compile. |
| 106 | c = _Call([compiler[lang], "-c", language["cflags"], CFLAGS, |
| 107 | "-I", WASM_PATH, "-o", obj_file, src_file]) |
| 108 | if c: return self._Error("compilation", lang, compiler, c) |
| 109 | # Link. |
| 110 | c = _Call([compiler["cc"], CFLAGS, compiler["ldflags"], obj_file, |
| 111 | "-o", exe_file, self.lib_file, "-ldl -pthread"]) |
| 112 | if c: return self._Error("linking", lang, compiler, c) |
| 113 | # Execute. |
| 114 | exe_file = "./%s-%s" % (self.name, lang) |
| 115 | c = _Call(["cd", self.tempdir, ";", exe_file]) |
| 116 | if c: return self._Error("execution", lang, compiler, c) |
| 117 | return 0 |
| 118 | |
| 119 | def Main(args): |
| 120 | if (len(args) < MIN_ARGS or args[1] in ("-h", "--help", "help")): |