From 6b4cee6ca8def153d2bc594ef250af88fd20ff36 Mon Sep 17 00:00:00 2001 From: Hailiang Hu Date: Sat, 11 Jun 2022 11:22:41 +0800 Subject: [PATCH] ES262 AOT Support 1. Add AOT option to enable aot test, AOT tool location path. 2. Add AOT compiler command, and AOT running command. 3. Add command print when erros occurred, so as to debug. Issue: https://gitee.com/openharmony/ark_ts2abc/issues/I5BSTE Signed-off-by: Hailiang Hu Change-Id: I296bf96a8ed3be0f3e1e09ff1e8381113524ade5 --- test262/README.md | 5 ++ test262/config.py | 1 + test262/run_sunspider.py | 121 ++++++++++++++++++++++++++++++++++++++- test262/run_test262.py | 13 ++++- 4 files changed, 137 insertions(+), 3 deletions(-) diff --git a/test262/README.md b/test262/README.md index 51c3e85..8259b92 100644 --- a/test262/README.md +++ b/test262/README.md @@ -21,6 +21,8 @@ usage: run_test262.py [-h] [--dir DIR] [--file FILE] [--mode [{1,2,3}]] [--es51] [--es2015 [{all,only}]] [--esnext] [--engine FILE] [--babel] [--timeout TIMEOUT] [--threads THREADS] [--hostArgs HOSTARGS] + [--ark-aot] + [--ark-aot-tool ARK_AOT_TOOL] [--ark-tool ARK_TOOL] [--ark-frontend-tool ARK_FRONTEND_TOOL] [--libs-dir LIBS_DIR] @@ -45,6 +47,9 @@ optional arguments: --threads THREADS Run this many tests in parallel. Note that the browser runners don't work great with t > 1. --hostArgs HOSTARGS command-line arguments to pass to eshost host + --ark-aot Run test262 with aot + --ark-aot-tool ARK_AOT_TOOL + ark's aot tool --ark-tool ARK_TOOL ark's binary tool --ark-frontend-tool ARK_FRONTEND_TOOL ark frontend conversion tool diff --git a/test262/config.py b/test262/config.py index bd87d40..a2f738b 100755 --- a/test262/config.py +++ b/test262/config.py @@ -45,6 +45,7 @@ TEST_CI_DIR = os.path.join(DATA_DIR, "test_CI") DEFAULT_ARK_FRONTEND_TOOL = os.path.join(ARK_DIR, "build", "src", "index.js") DEFAULT_ARK_TOOL = os.path.join(ARK_JS_RUNTIME_DIR, "ark_js_vm") +DEFAULT_ARK_AOT_TOOL = os.path.join(ARK_JS_RUNTIME_DIR, "ark_aot_compiler") DEFAULT_LIBS_DIR = f"{ARK_DIR}:{ICUI_DIR}:{LLVM_DIR}:{ARK_JS_RUNTIME_DIR}" DEFAULT_HOST_TYPE = "panda" diff --git a/test262/run_sunspider.py b/test262/run_sunspider.py index cb59b4f..67bcf46 100755 --- a/test262/run_sunspider.py +++ b/test262/run_sunspider.py @@ -23,6 +23,8 @@ import os import platform import sys import signal +import re +import fileinput import subprocess from utils import * from config import * @@ -34,6 +36,13 @@ def parse_args(): default=DEFAULT_ARK_TOOL, required=False, help="ark's binary tool") + parser.add_argument('--ark-aot', action='store_true', + required=False, + help="Run test262 with aot") + parser.add_argument('--ark-aot-tool', + default=DEFAULT_ARK_AOT_TOOL, + required=False, + help="ark's aot tool") parser.add_argument('--ark-frontend-tool', default=DEFAULT_ARK_FRONTEND_TOOL, required=False, @@ -72,6 +81,7 @@ if platform.system() == "Windows" : ARK_TOOL = DEFAULT_ARK_TOOL ARK_FRONTEND_TOOL = DEFAULT_ARK_FRONTEND_TOOL LIBS_DIR = DEFAULT_LIBS_DIR +ARK_AOT_TOOL = DEFAULT_ARK_AOT_TOOL ARK_FRONTEND = DEFAULT_ARK_FRONTEND ARK_ARCH = DEFAULT_ARK_ARCH @@ -131,16 +141,32 @@ def exec_command(cmd_args, timeout=DEFAULT_TIMEOUT): output(code, msg) return code +def print_command(cmd_args): + sys.stderr.write("\n") + for arg in cmd_args: + sys.stderr.write(arg + " ") + sys.stderr.write("\n") + +def run_command(cmd_args): + timeout = DEFAULT_TIMEOUT / 1000 + cmd = f"timeout {timeout} " + for arg in cmd_args: + cmd += f"{arg} " + return os.system(cmd) class ArkProgram(): def __init__(self, args): self.args = args self.ark_tool = ARK_TOOL + self.ark_aot = False + self.ark_aot_tool = ARK_AOT_TOOL self.ark_frontend_tool = ARK_FRONTEND_TOOL self.libs_dir = LIBS_DIR self.ark_frontend = ARK_FRONTEND self.module_list = [] self.js_file = "" + self.module = False + self.abc_file = "" self.arch = ARK_ARCH self.arch_root = "" @@ -148,6 +174,12 @@ class ArkProgram(): if self.args.ark_tool: self.ark_tool = self.args.ark_tool + if self.args.ark_aot: + self.ark_aot = self.args.ark_aot + + if self.args.ark_aot_tool: + self.ark_aot_tool = self.args.ark_aot_tool + if self.args.ark_frontend_tool: self.ark_frontend_tool = self.args.ark_frontend_tool @@ -170,6 +202,7 @@ class ArkProgram(): file_name_pre = os.path.splitext(js_file)[0] file_name = os.path.basename(js_file) out_file = f"{file_name_pre}.abc" + self.abc_file = out_file mod_opt_index = 0 cmd_args = [] frontend_tool = self.ark_frontend_tool @@ -184,9 +217,88 @@ class ArkProgram(): if file_name in self.module_list: cmd_args.insert(mod_opt_index, "-m") + self.module = True + if self.ark_aot: + os.system(f'''sed -i 's/;$262.destroy();/\/\/;$262.destroy();/g' {js_file}''') + if self.module: + js_dir = os.path.dirname(js_file) + for line in fileinput.input(js_file): + import_line = re.findall(r"^(?:ex|im)port.*from.*\.js", line) + if len(import_line): + import_file = re.findall(r"['\"].*\.js", import_line[0]) + if len(import_file): + abc_file = import_file[0][1:].replace(".js", ".abc") + if self.abc_file.find(abc_file) < 0: + self.abc_file += f':{js_dir}/{abc_file}' retcode = exec_command(cmd_args) return retcode + def compile_aot(self): + os.environ["LD_LIBRARY_PATH"] = self.libs_dir + file_name_pre = os.path.splitext(self.js_file)[0] + abc_file = f'{file_name_pre}.abc' + cmd_args = [] + if self.arch == ARK_ARCH_LIST[1]: + cmd_args = [self.ark_aot_tool, ICU_PATH, + f'--target-triple=aarch64-unknown-linux-gnu', + f'--aot-file={file_name_pre}.m', + f'--snapshot-output-file={file_name_pre}.snapshot', + self.abc_file, + f'> {file_name_pre}.log 2>&1'] + elif self.arch == ARK_ARCH_LIST[2]: + cmd_args = [self.ark_aot_tool, ICU_PATH, + f'--target-triple=arm-unknown-linux-gnu', + f'--aot-file={file_name_pre}.m', + f'--snapshot-output-file={file_name_pre}.snapshot', + self.abc_file, + f'> {file_name_pre}.log 2>&1'] + elif self.arch == ARK_ARCH_LIST[0]: + cmd_args = [self.ark_aot_tool, ICU_PATH, + f'--aot-file={file_name_pre}.m', + f'--snapshot-output-file={file_name_pre}.snapshot', + self.abc_file, + f'> {file_name_pre}.log 2>&1'] + retcode = run_command(cmd_args) + if retcode: + print_command(cmd_args) + + def execute_aot(self): + os.environ["LD_LIBRARY_PATH"] = self.libs_dir + file_name_pre = os.path.splitext(self.js_file)[0] + cmd_args = [] + if self.arch == ARK_ARCH_LIST[1]: + qemu_tool = "qemu-aarch64" + qemu_arg1 = "-L" + qemu_arg2 = self.arch_root + cmd_args = [qemu_tool, qemu_arg1, qemu_arg2, self.ark_tool, + ICU_PATH, + '--asm-interpreter=1', + f'--aot-file={file_name_pre}.m', + f'--snapshot-output-file={file_name_pre}.snapshot', + f'{file_name_pre}.abc'] + elif self.arch == ARK_ARCH_LIST[2]: + qemu_tool = "qemu-arm" + qemu_arg1 = "-L" + qemu_arg2 = self.arch_root + cmd_args = [qemu_tool, qemu_arg1, qemu_arg2, self.ark_tool, + ICU_PATH, + '--asm-interpreter=1', + f'--aot-file={file_name_pre}.m', + f'--snapshot-output-file={file_name_pre}.snapshot', + f'{file_name_pre}.abc'] + elif self.arch == ARK_ARCH_LIST[0]: + cmd_args = [self.ark_tool, ICU_PATH, + '--asm-interpreter=1', + f'--aot-file={file_name_pre}.m', + f'--snapshot-output-file={file_name_pre}.snapshot', + f'{file_name_pre}.abc'] + + retcode = run_command(cmd_args) + if retcode: + os.system(f'cp {self.js_file} {BASE_OUT_DIR}/../') + print_command(cmd_args) + return retcode + def execute(self): if platform.system() == "Windows" : os.environ["PATH"] = self.libs_dir + ";" + os.environ["PATH"] @@ -215,6 +327,8 @@ class ArkProgram(): f'{file_name_pre}.abc'] retcode = exec_command(cmd_args) + if retcode: + print_command(cmd_args) return retcode def is_legal_frontend(self): @@ -229,8 +343,11 @@ class ArkProgram(): return if self.gen_abc(): return - self.execute() - + if self.ark_aot: + self.compile_aot() + self.execute_aot() + else: + self.execute() def main(): args = parse_args() diff --git a/test262/run_test262.py b/test262/run_test262.py index d8f05aa..585b236 100755 --- a/test262/run_test262.py +++ b/test262/run_test262.py @@ -74,6 +74,10 @@ def parse_args(): help="command-line arguments to pass to eshost host\n") parser.add_argument('--ark-tool', help="ark's binary tool") + parser.add_argument('--ark-aot', action='store_true', + help="Run test262 with aot") + parser.add_argument('--ark-aot-tool', + help="ark's aot tool") parser.add_argument('--ark-frontend-tool', help="ark frontend conversion tool") parser.add_argument("--libs-dir", @@ -465,6 +469,7 @@ def get_threads(args): def get_host_args(args, host_type): host_args = "" ark_tool = DEFAULT_ARK_TOOL + ark_aot_tool = DEFAULT_ARK_AOT_TOOL ark_frontend_tool = DEFAULT_ARK_FRONTEND_TOOL libs_dir = DEFAULT_LIBS_DIR ark_frontend = DEFAULT_ARK_FRONTEND @@ -479,6 +484,9 @@ def get_host_args(args, host_type): if args.ark_tool: ark_tool = args.ark_tool + if args.ark_aot_tool: + ark_aot_tool = args.ark_aot_tool + if args.ark_frontend_tool: ark_frontend_tool = args.ark_frontend_tool @@ -491,10 +499,13 @@ def get_host_args(args, host_type): if host_type == DEFAULT_HOST_TYPE: host_args = f"-B test262/run_sunspider.py " host_args += f"--ark-tool={ark_tool} " + if args.ark_aot: + host_args += f"--ark-aot " + host_args += f"--ark-aot-tool={ark_aot_tool} " host_args += f"--ark-frontend-tool={ark_frontend_tool} " host_args += f"--libs-dir={libs_dir} " host_args += f"--ark-frontend={ark_frontend} " - host_args += f"--module-list={module_list}" + host_args += f"--module-list={module_list} " if args.ark_arch != ark_arch: host_args += f"--ark-arch={args.ark_arch} "