From f7a8bb9963617b8e50b72253cef5353af06f2919 Mon Sep 17 00:00:00 2001 From: Petrov Igor Date: Sat, 30 Mar 2024 11:38:06 +0800 Subject: [PATCH] [Script] Support arm64 for jsperftest runner Issue: #I9CVCS Testing: `run_js_perf_test.sh` Signed-off-by: Petrov Igor --- test/jsperftest/config.json | 29 +++- test/jsperftest/run_js_perf_test.sh | 173 ++++++++++++++++--- test/jsperftest/run_js_test.py | 259 ++++++++++++++++++++-------- 3 files changed, 362 insertions(+), 99 deletions(-) diff --git a/test/jsperftest/config.json b/test/jsperftest/config.json index 8354609c41..3d605d61e0 100644 --- a/test/jsperftest/config.json +++ b/test/jsperftest/config.json @@ -1,16 +1,29 @@ { - "full_x86_64":{ + "full_x86_64": { "ETS_RUNTIME_PATH": "out/rk3568/clang_x64/arkcompiler/ets_runtime/", - "ICU_PATH": "out/rk3568/clang_x64/thirdparty/icu/", - "ZLIB_PATH": "out/rk3568/clang_x64/thirdparty/zlib/", - "LIB_PATH": "prebuilts/clang/ohos/linux-x86_64/llvm/lib/", + "STUB_AN": "out/rk3568/clang_x64/gen/arkcompiler/ets_runtime/stub.an", + "LIBS_LIST": [ + "out/rk3568/clang_x64/thirdparty/icu/", + "out/rk3568/clang_x64/thirdparty/zlib/", + "prebuilts/clang/ohos/linux-x86_64/llvm/lib/" + ], "ES2ABC": "out/rk3568/clang_x64/arkcompiler/ets_frontend/es2abc" }, "independent_x86_64": { "ETS_RUNTIME_PATH": "out/x64.release/arkcompiler/ets_runtime", - "ICU_PATH": "out/x64.release/thirdparty/icu/", - "ZLIB_PATH": "", - "LIB_PATH": "", + "STUB_AN": "out/x64.release/gen/arkcompiler/ets_runtime/stub.an", + "LIBS_LIST": [ + "out/x64.release/thirdparty/icu/" + ], "ES2ABC": "out/x64.release/arkcompiler/ets_frontend/es2abc" - } + }, + "independent_arm64": { + "ETS_RUNTIME_PATH": "out/arm64.release/arkcompiler/ets_runtime", + "STUB_AN": "out/arm64.release/gen/arkcompiler/ets_runtime/stub.an", + "LIBS_LIST": [ + "out/arm64.release/thirdparty/icu/", + "out/arm64.release/thirdparty/bounds_checking_function" + ], + "ES2ABC": "out/x64.release/arkcompiler/ets_frontend/es2abc" + } } \ No newline at end of file diff --git a/test/jsperftest/run_js_perf_test.sh b/test/jsperftest/run_js_perf_test.sh index 7aa92d31fd..4947706e8e 100755 --- a/test/jsperftest/run_js_perf_test.sh +++ b/test/jsperftest/run_js_perf_test.sh @@ -20,12 +20,24 @@ SCRIPT_NAME="$(basename "$0")" declare JS_PERF_RESULT_PATH="" declare OPENHARMONY_ROOT_PATH="" declare D8_BINARY_PATH="/usr/bin/v8/d8" +declare D8_DEVICE_DIR="" +declare CONFIG_PATH +CONFIG_PATH="$(dirname "${BASH_SOURCE[0]}")"/config.json declare VER_PLATFORM="full_x86_64" declare -a BENCH_FILTER=() +declare -a EXCLUDE_BENCHMARKS=() declare NO_NEED_DOWNLOAD_BENCHS=false declare BENCH_MULTIPLIER="" +declare HDC_PATH="" +declare TASKSET_MASK="" declare -i ITERATIONS=1 +function echo_fatal() +{ + echo "Error: $1" + exit 1 +} + function init() { while [[ -n "$1" ]] @@ -35,18 +47,30 @@ function init() usage exit 0 ;; - --d8-path) + --d8-host-path) shift D8_BINARY_PATH="$1" ;; + --d8-device-dir) + shift + D8_DEVICE_DIR="$1" + ;; --platform) shift VER_PLATFORM="$1" ;; + --config) + shift + CONFIG_PATH="$1" + ;; --bench-filter=*) local BENCH_FILTER_STR="${1#*=}" BENCH_FILTER=(${BENCH_FILTER_STR//:/ }) ;; + --exclude=*) + local EXCLUDE_BENCHS_STR="${1#*=}" + EXCLUDE_BENCHMARKS=(${EXCLUDE_BENCHS_STR//:/ }) + ;; --no-download-benchs) NO_NEED_DOWNLOAD_BENCHS=true ;; @@ -58,6 +82,14 @@ function init() shift ITERATIONS=$1 ;; + --hdc-path) + shift + HDC_PATH="$1" + ;; + --taskset) + shift + TASKSET_MASK="$1" + ;; *) JS_PERF_RESULT_PATH="$1" OPENHARMONY_ROOT_PATH="$2" @@ -66,24 +98,66 @@ function init() esac shift done - if [[ -z "${OPENHARMONY_ROOT_PATH}" || -z "${JS_PERF_RESULT_PATH}" ]] + if [[ "${VER_PLATFORM}" == *arm64* ]] + then + if [[ -z "${D8_DEVICE_DIR}" ]] + then + echo_fatal "--d8-device-dir is required for device" + fi + if [[ ! -d "${D8_DEVICE_DIR}" ]] + then + echo_fatal "${D8_DEVICE_DIR}: directory with v8 libs for device does not exist" + fi + if [[ ! -f "${D8_DEVICE_DIR}/d8" ]] + then + echo_fatal "${D8_DEVICE_DIR}/d8 is required, but does not exist" + fi + if [[ ! -f "${D8_DEVICE_DIR}/snapshot_blob.bin" ]] + then + echo_fatal "${D8_DEVICE_DIR}/snapshot_blob.bin is required, but does not exist" + fi + if [[ ! -f "${D8_DEVICE_DIR}/icudtl.dat" ]] + then + echo_fatal "${D8_DEVICE_DIR}/icudtl.dat is required, but does not exist" + fi + if [[ -z "${HDC_PATH}" ]] + then + if ! command -v hdc + then + echo_fatal "hdc path was not specified" + fi + HDC_PATH=$(command -v hdc) + elif [[ ! -e "${HDC_PATH}" ]] + then + echo_fatal "Executable file does not exist: ${HDC_PATH}" + else + HDC_PATH=$(realpath "${HDC_PATH}") + fi + elif [[ ! -x "${D8_BINARY_PATH}" ]] + then + echo_fatal "Executable file does not exist: ${D8_BINARY_PATH}" + fi + if [[ ! -f "${CONFIG_PATH}" ]] + then + echo_fatal "Config file does not exist: ${CONFIG_PATH}" + fi + CONFIG_PATH=$(realpath "${CONFIG_PATH}") + if [[ -z "${JS_PERF_RESULT_PATH}" ]] + then + usage + echo_fatal "JS_PERF_RESULT_PATH argument is not set" + fi + if [[ -z "${OPENHARMONY_ROOT_PATH}" ]] then usage - echo "Invalid input arguments" - exit 1 + echo_fatal "OPENHARMONY_ROOT argument is not set" fi if [[ ! -d "${OPENHARMONY_ROOT_PATH}" ]] then - echo "Path to openharmony root dir does not exist: ${OPENHARMONY_ROOT_PATH}" - exit 1 + echo_fatal "Path to openharmony root dir does not exist: ${OPENHARMONY_ROOT_PATH}" else OPENHARMONY_ROOT_PATH="$(realpath "${OPENHARMONY_ROOT_PATH}")" fi - if [[ ! -x "${D8_BINARY_PATH}" ]] - then - echo "Executable file does not exist: ${D8_BINARY_PATH}" - exit 1 - fi if [[ ! -d "${JS_PERF_RESULT_PATH}" ]] then mkdir -p "${JS_PERF_RESULT_PATH}" @@ -97,8 +171,8 @@ function init() mkdir -p "${WORKDIR_PATH}" echo " OpenHarmony root path: ${OPENHARMONY_ROOT_PATH} -D8 path: ${D8_BINARY_PATH} JS perf results: ${JS_PERF_RESULT_PATH} +Config: ${CONFIG_PATH} Platform: ${VER_PLATFORM} " } @@ -154,26 +228,73 @@ function prepare_js_test_files() fi done fi + if [[ ${#EXCLUDE_BENCHMARKS[@]} -ne 0 ]] + then + for bench in "${EXCLUDE_BENCHMARKS[@]}" + do + if [[ -e "${JS_TEST_PATH}/${bench}" ]] + then + rm -rf "${JS_TEST_PATH}/${bench}" + else + echo "No excluding benchmark '${bench}'" + fi + done + fi +} + +function prepare_device() +{ + # Check device + local -a devices + devices=$(${HDC_PATH} list targets) + if [[ ${#devices[@]} -eq 1 ]] + then + if [[ "${devices[0]}" == "[Empty]"* ]] + then + echo_fatal "No devices" + fi + echo "Device id: ${devices[0]}" + else + echo_fatal "Required immidieatly one device" + fi + # Create workdir + local -r WORKDIR_ON_DEVICE="/data/local/tmp/jsperftest" + D8_BINARY_PATH="${WORKDIR_ON_DEVICE}/v8/d8" + set -x + ${HDC_PATH} shell "rm -rf ${WORKDIR_ON_DEVICE}" + ${HDC_PATH} shell "mkdir -p ${WORKDIR_ON_DEVICE}/v8 ${WORKDIR_ON_DEVICE}/lib ${WORKDIR_ON_DEVICE}/thirdparty" + ${HDC_PATH} file send "${D8_DEVICE_DIR}"/d8 ${D8_BINARY_PATH} + ${HDC_PATH} shell chmod u+x "${D8_BINARY_PATH}" + ${HDC_PATH} file send "${D8_DEVICE_DIR}"/snapshot_blob.bin ${WORKDIR_ON_DEVICE}/v8 + ${HDC_PATH} file send "${D8_DEVICE_DIR}"/icudtl.dat ${WORKDIR_ON_DEVICE}/v8 + set +x } function usage() { echo "${SCRIPT_NAME} [options] Options: - --d8-path - path to d8 binary file. - Default: /usr/bin/v8/d8 - --platform - used platform. Possible values in config.json. - Default: full_x86_64 - --multiplier N - iteration multiplier for js benchmarks - --iterations N - number of benchmark launches and get average + --d8-host-path - path to d8 binary file. + Default: /usr/bin/v8/d8 + --d8-device-dir - path to dir with d8 for ohos device. + See https://gitee.com/qishui7/ohcompiler-daily/repository/archive/master.zip + --hdc-path - path to hdc executable file. Use from PATH env variable by default + --platform - used platform. Possible values in config.json. + Default: full_x86_64 + --config - path to specific json config + --taskset mask - use CPU affinity with mask for benchmark runnings + --multiplier N - iteration multiplier for js benchmarks + --iterations N - number of benchmark launches and get average --bench-filter=BenchDir1:BenchDir2:BenchDir3/bench.js:... - - filter for benchmarks: directory or file - --no-download-benchs - no download benchmarks from repository if repo already exists - --help, -h - print help info about script + - filter for benchmarks: directory or file + --exclude=BenchDir1:BenchDir2:BenchDir3/bench.js:... + - exclude benchmarks from running: directory or file + --no-download-benchs - no download benchmarks from repository if repo already exists + --help, -h - print help info about script Positional arguments: JS_PERF_RESULT_PATH - directory path to benchmark results - OPENHARMONY_ROOT - path to root directory for ark_js_vm and es2panda + OPENHARMONY_ROOT - path to root directory for ark_js_vm and es2panda " } @@ -189,6 +310,11 @@ main() check_pip_component "openpyxl" || { pip3 install openpyxl; } [ -f "$cur_path/run_js_test.py" ] || { echo "no run_js_test.py, please check it";return $ret_error;} + + if [[ "${VER_PLATFORM}" == *arm64* ]] + then + prepare_device + fi prepare_js_test_files || { return $ret_error; } @@ -205,11 +331,14 @@ main() local -i benchs_time_start benchs_time benchs_minutes benchs_time_start=$(date +%s) python3 "${cur_path}"/run_js_test.py \ + -c "${CONFIG_PATH}" \ -bp "${OPENHARMONY_ROOT_PATH}" \ -p "${JS_TEST_PATH}" \ -o "${JS_PERF_RESULT_PATH}" \ -v "${D8_BINARY_PATH}" \ -e "${VER_PLATFORM}" \ + --hdc "${HDC_PATH}" \ + -t "${TASKSET_MASK}" \ -n "${ITERATIONS}" benchs_time=$(($(date +%s) - benchs_time_start)) benchs_minutes=$((benchs_time / 60)) diff --git a/test/jsperftest/run_js_test.py b/test/jsperftest/run_js_test.py index f9a63bbb98..54bbb1dc83 100644 --- a/test/jsperftest/run_js_test.py +++ b/test/jsperftest/run_js_test.py @@ -25,13 +25,15 @@ import os import shutil import stat import subprocess -from typing import Union +import sys +from typing import Union, List, Tuple from collections import namedtuple from openpyxl import Workbook, load_workbook from openpyxl.styles import PatternFill def get_logger(logger_name, log_file_path, level=logging.INFO): + """Create logger for this script""" formatter = logging.Formatter(fmt='[%(asctime)s] [%(levelname)s] %(message)s', datefmt='%Y-%m-%d %H:%M:%S') @@ -81,10 +83,18 @@ class Constants: VER_PLATFORM = "full_x86_64" ES2ABC_PATH = "" ARK_JS_VM_PATH = "" + ETS_RUNTIME = "" + LD_LIBRARY_PATH = "" + HDC_PATH: str = "hdc" + DEVICE_WORKDIR: str = "/data/local/tmp/jsperftest" + LIBS_LIST: List[str] = [] + STUB_AN: str = "" + TASKSET_MASK: str = "" CaseTestDataType = namedtuple('test', ['exec_status', 'exec_time']) def get_js_file_class_api_scenes(js_file_path): + """Get all cases for one benchmark file""" scenes = [] with open(js_file_path, 'r') as f: for line in f: @@ -222,39 +232,80 @@ def append_row_data(report_file, case_test_data): wb.save(report_file) return Constants.RET_OK -def run_js_case_via_ark(binary_path, js_file_path, class_name, api_name, iterations, report_file): - composite_scenes = get_js_file_class_api_scenes(js_file_path) - case_test_data = {} - execute_status = Constants.FAIL - execute_time = ' ' - - for _, composite_scene in enumerate(composite_scenes): - case_test_data[composite_scene] = Constants.CaseTestDataType(execute_status, execute_time) - js_file_name = class_name + '/' + api_name + '.js' +def get_ark_js_cmd(abc_file: str) -> List[str]: + """Get command for ark js vm""" + cmd: List[str] = [] + if Constants.VER_PLATFORM.find("arm64") != -1: + cmd = [Constants.HDC_PATH, "shell"] + run_cmd = f"LD_LIBRARY_PATH={Constants.LD_LIBRARY_PATH}" + if len(Constants.TASKSET_MASK) != 0: + run_cmd += f" taskset -a {Constants.TASKSET_MASK}" + run_cmd += " " + os.path.join(Constants.DEVICE_WORKDIR, "ark_js_vm") + run_cmd += " --stub-file " + os.path.join(Constants.DEVICE_WORKDIR, "lib", "stub.an") + run_cmd += " --icu-data-path " + os.path.join(Constants.DEVICE_WORKDIR, "data") + run_cmd += " " + abc_file + cmd.append(run_cmd) + else: + cmd = [Constants.ARK_JS_VM_PATH, + "--log-level=info", + "--enable-runtime-stat=true", + "--stub-file", Constants.STUB_AN, + "--icu-data-path", ICU_DATA_PATH, + abc_file] + if len(Constants.TASKSET_MASK) != 0: + cmd = ["taskset", "-a", Constants.TASKSET_MASK] + cmd + return cmd + + +def prepare_for_ark_run(class_name: str, api_name: str) -> Tuple[str, str]: + """Prepare workspace for benchmark""" fangzhou_test_path = os.path.join(Constants.TMP_PATH, "fangzhou_test") # for abc file if os.path.exists(fangzhou_test_path): shutil.rmtree(fangzhou_test_path) os.makedirs(fangzhou_test_path) - class_folder_path = os.path.join(fangzhou_test_path, class_name) if not os.path.exists(class_folder_path): os.makedirs(class_folder_path) - cur_abc_file = os.path.join(Constants.CUR_PATH, api_name + ".abc") - api_log_path = os.path.join(class_folder_path, api_name + ".log") + return (os.path.join(Constants.CUR_PATH, api_name + ".abc"), + os.path.join(class_folder_path, api_name + ".log")) - cmd = [Constants.ES2ABC_PATH, "--output", cur_abc_file, js_file_path] +def run_es2panda(abc_file: str, js_file: str) -> int: + """Run es2panda for one benchmark file""" + cmd = [Constants.ES2ABC_PATH, "--output", abc_file, js_file] logger.info("run cmd: %s", cmd) - ret = subprocess.run(cmd) + ret = subprocess.run(cmd, check=False) if ret.returncode != 0: - logger.error("ret = %s, %s generate abc file failed. cmd: %s", str(ret), js_file_name, cmd) + logger.error("ret = %s, %s generate abc file failed. cmd: %s", str(ret), js_file, cmd) + return ret.returncode + + +def run_js_case_via_ark(js_file_path, class_name, api_name, iterations, report_file): + """Run js perf benchmark via ark js vm""" + composite_scenes = get_js_file_class_api_scenes(js_file_path) + case_test_data = {} + execute_status = Constants.FAIL + execute_time = ' ' + + for _, composite_scene in enumerate(composite_scenes): + case_test_data[composite_scene] = Constants.CaseTestDataType(execute_status, execute_time) + + js_file_name = class_name + '/' + api_name + '.js' + cur_abc_file, api_log_path = prepare_for_ark_run(class_name, api_name) + using_abc_file = cur_abc_file + + ret = run_es2panda(cur_abc_file, js_file_path) + if ret != 0: append_row_data(report_file, case_test_data) return case_test_data + if Constants.VER_PLATFORM.find("arm64") != -1: + using_abc_file = os.path.join(Constants.DEVICE_WORKDIR, os.path.basename(cur_abc_file)) + if hdc_send(cur_abc_file, using_abc_file) != 0: + append_row_data(report_file, case_test_data) + return case_test_data # execute abc - ark_js_vm_path = Constants.ARK_JS_VM_PATH - cmd = [ark_js_vm_path, "--log-level=info", "--enable-runtime-stat=true", "--icu-data-path", - ICU_DATA_PATH, cur_abc_file] + cmd = get_ark_js_cmd(using_abc_file) logger.info("run cmd: %s", cmd) flags = os.O_WRONLY | os.O_CREAT | os.O_EXCL @@ -302,7 +353,7 @@ def run_via_ark(jspath, report_file, iterations): api_name = results[-1].split(".")[0] js_case_name = '/'.join([class_name, results[-1]]) logger.info("begin to execute %s.", js_case_name) - test_data = run_js_case_via_ark(BINARY_PATH, file_path, class_name, api_name, iterations, report_file) + test_data = run_js_case_via_ark(file_path, class_name, api_name, iterations, report_file) for _, key in enumerate(test_data.keys()): Constants.TODAY_EXCUTE_INFO[key] = test_data.get(key) logger.info("finish executing %s. executing info: %s.", js_case_name, Constants.TODAY_EXCUTE_INFO) @@ -434,7 +485,7 @@ def process_args(args: argparse.Namespace) -> argparse.Namespace: args.output_folder_path = os.getcwd() if not os.path.isabs(args.output_folder_path): args.output_folder_path = os.path.abspath(args.output_folder_path) - if not os.path.exists(args.d_8_binary_path): + if args.ver_platform.find("arm64") == -1 and not os.path.exists(args.d_8_binary_path): logger.error("parameter --d_8_binary_path is not exist. Please check it! d 8 binary path: %s", args.d_8_binary_path) raise RuntimeError("error bad parameters --d_8_binary_path: {}".format(args.d_8_binary_path)) @@ -447,48 +498,42 @@ def process_args(args: argparse.Namespace) -> argparse.Namespace: def get_args(): parser = argparse.ArgumentParser() parser.add_argument( - "--binarypath", - "-bp", - required=True, + "--binarypath", "-bp", required=True, help="path of binary folder. refer to harmony root folder path", ) parser.add_argument( - "--jspath", - "-p", - required=True, + "--jspath", "-p", required=True, help="path of js scripts, support folder and file", ) parser.add_argument( - "--deterioration_boundary_value", - "-d", - default=0.05, + "--deterioration_boundary_value", "-d", default=0.05, help="deterioration boundary value, default 0.05", ) parser.add_argument( - "--output_folder_path", - "-o", - default=None, + "--output_folder_path", "-o", default=None, help="output folder for executing js cases, default current folder", ) parser.add_argument( - "--d_8_binary_path", - "-v", - default=None, + "--d_8_binary_path", "-v", default=None, help="v 8 engine d 8 binary path", ) parser.add_argument( - "--ver_platform", - "-e", - default="full_x86_64", + "--ver_platform", "-e", default="full_x86_64", help="Code repository version and platform", ) parser.add_argument( - "--iterations", - "-n", - default=1, - type=int, + "--iterations", "-n", default=1, type=int, help="Number of benchmark launches" ) + parser.add_argument( + "--hdc", default="hdc", type=str, + help="path to hdc" + ) + parser.add_argument( + "--taskset", "-t", default="", type=str, + help="Use taskset mask for affinity on specific CPUs" + ) + parser.add_argument("--config", "-c", required=True, type=str, help="config json-file") return process_args(parser.parse_args()) @@ -595,7 +640,23 @@ def update_data_by_log(data: dict, log_path: str, js_name: str) -> dict: data[key_str] += float(exec_time) return data + +def get_v_8_cmd(parameter: str, js_file_path: str) -> List[str]: + """Get command for v 8""" + cmd: List[str] = [] + if Constants.VER_PLATFORM.find("arm64") != -1: + cmd = [Constants.HDC_PATH, "shell"] + if len(Constants.TASKSET_MASK) != 0: + cmd += ["taskset", "-a", Constants.TASKSET_MASK] + if len(parameter) == 0: + cmd += [Constants.V_8_ENGINED_PATH, js_file_path] + else: + cmd += [Constants.V_8_ENGINED_PATH, parameter, js_file_path] + return cmd + + def run_v_8_single_js_case(js_file_path, cmd_para, js_case_name, iterations: int): + """Run single js case for v 8 based with parameters""" v_8_exec_time_dict = {} scenes = get_js_file_class_api_scenes(js_file_path) @@ -603,11 +664,19 @@ def run_v_8_single_js_case(js_file_path, cmd_para, js_case_name, iterations: int flags = os.O_WRONLY | os.O_CREAT | os.O_EXCL modes = stat.S_IWUSR | stat.S_IRUSR + used_js_file = js_file_path - if len(cmd_para) == 0: - cmd = [Constants.V_8_ENGINED_PATH, js_file_path] - else: - cmd = [Constants.V_8_ENGINED_PATH, cmd_para, js_file_path] + if Constants.VER_PLATFORM.find("arm64") != -1: + js_file_path_device = os.path.join(Constants.DEVICE_WORKDIR, + os.path.basename(js_case_name + '.js')) + used_js_file = js_file_path_device + if hdc_send(js_file_path, js_file_path_device) != 0: + for elem in enumerate(scenes): + v_8_exec_time_dict[elem] = 0 + logger.error("Couldn't send file %s to device", js_file_path) + return v_8_exec_time_dict + + cmd = get_v_8_cmd(cmd_para, used_js_file) logger.info("run cmd:%s", cmd) data = {} for _ in range(iterations): @@ -705,30 +774,79 @@ def get_v_8_jitless_excute_times(jspath, v_8_based_report_file_path, iterations) return Constants.RET_OK - -def get_config(): - config_json_path = os.path.join(Constants.CUR_PATH, "config.json") - with open(config_json_path, 'r', encoding='UTF-8') as f: +def hdc_send(source: str, destination: str) -> int: + """Run hdc send command""" + hdc_cmd: List[str] = [Constants.HDC_PATH, "file", "send"] + hdc_cmd += [source, destination] + logger.info("run cmd: %s", hdc_cmd) + return subprocess.run(hdc_cmd, check=False).returncode + + +def hdc_run(cmd: List[str]) -> int: + """Run command on device via hdc shell""" + hdc_cmd = [Constants.HDC_PATH, "shell"] + cmd + return subprocess.run(hdc_cmd).returncode + +def prepare_device(): + """Preapare device workdir for js perf testing""" + if hdc_send(Constants.ARK_JS_VM_PATH, Constants.DEVICE_WORKDIR) != 0: + logger.error("Couldn't send ark_js_vm to device") + sys.exit(1) + hdc_run(["chmod", "u+x", os.path.join(Constants.DEVICE_WORKDIR, "ark_js_vm")]) + arkjsvm_lib = os.path.join(Constants.ETS_RUNTIME, "libark_jsruntime.so") + if hdc_send(arkjsvm_lib, os.path.join(Constants.DEVICE_WORKDIR, "lib")) != 0: + logger.error("Couldn't send libark_jsruntime.so to device") + sys.exit(1) + if hdc_send(ICU_DATA_PATH, Constants.DEVICE_WORKDIR) != 0: + logger.error("Couldn't send icu data to device") + sys.exit(1) + thirdparty_path = os.path.join(Constants.DEVICE_WORKDIR, "thirdparty") + for lib in Constants.LIBS_LIST: + if not os.path.isdir(lib): + logger.error("Couldn't find lib from config %s", lib) + sys.exit(1) + if hdc_send(lib, thirdparty_path) != 0: + logger.error("Couldn't send %s lib to device", lib) + sys.exit(1) + if hdc_send(Constants.STUB_AN, os.path.join(Constants.DEVICE_WORKDIR, "lib")) != 0: + logger.error("Couldn't send %s file to device", Constants.STUB_AN) + sys.exit(1) + + +def get_config(parameters: argparse.Namespace): + """Get config from arguments and json file""" + Constants.V_8_ENGINED_PATH = parameters.d_8_binary_path + Constants.VER_PLATFORM = parameters.ver_platform + Constants.HDC_PATH = parameters.hdc + Constants.TASKSET_MASK = parameters.taskset + with open(parameters.config, 'r', encoding='UTF-8') as f: json_data = json.load(f) Constants.ES2ABC_PATH = os.path.join(BINARY_PATH, json_data[Constants.VER_PLATFORM]["ES2ABC"]) - Constants.ARK_JS_VM_PATH = os.path.join(BINARY_PATH, json_data[Constants.VER_PLATFORM]["ETS_RUNTIME_PATH"], - "ark_js_vm") - ETS_RUNTIME_PATH = os.path.join(BINARY_PATH, json_data[Constants.VER_PLATFORM]["ETS_RUNTIME_PATH"]) - ICU_PATH = os.path.join(BINARY_PATH, json_data[Constants.VER_PLATFORM]["ICU_PATH"]) - ZLIB_PATH = os.path.join(BINARY_PATH, json_data[Constants.VER_PLATFORM]["ZLIB_PATH"]) - LIB_PATH = os.path.join(BINARY_PATH, json_data[Constants.VER_PLATFORM]["LIB_PATH"]) - old_ld_library_path = os.environ.get('LD_LIBRARY_PATH', '') - os.environ['LD_LIBRARY_PATH'] = f'{ETS_RUNTIME_PATH}:' + f'{ICU_PATH}:' + f'{ZLIB_PATH}:' + f'{LIB_PATH}:'\ - + old_ld_library_path + Constants.ETS_RUNTIME = os.path.join(BINARY_PATH, + json_data[Constants.VER_PLATFORM]["ETS_RUNTIME_PATH"]) + Constants.ARK_JS_VM_PATH = os.path.join(Constants.ETS_RUNTIME, "ark_js_vm") + Constants.STUB_AN = os.path.join(BINARY_PATH, json_data[Constants.VER_PLATFORM]["STUB_AN"]) + libs = json_data[Constants.VER_PLATFORM]["LIBS_LIST"] + for lib in libs: + Constants.LIBS_LIST.append(os.path.normpath(os.path.join(BINARY_PATH, lib))) + if Constants.VER_PLATFORM.find("x86_64") != -1: + old_ld_library_path = os.environ.get('LD_LIBRARY_PATH', '') + Constants.LD_LIBRARY_PATH = Constants.ETS_RUNTIME + ":" + if len(Constants.LIBS_LIST) != 0: + Constants.LD_LIBRARY_PATH += ":".join(Constants.LIBS_LIST) + if len(old_ld_library_path) != 0: + Constants.LD_LIBRARY_PATH += f":{old_ld_library_path}" + os.environ['LD_LIBRARY_PATH'] = Constants.LD_LIBRARY_PATH + elif Constants.VER_PLATFORM.find("arm64") != -1: + Constants.LD_LIBRARY_PATH = os.path.join(Constants.DEVICE_WORKDIR, "lib") + for lib in Constants.LIBS_LIST: + lib = os.path.normpath(lib) + Constants.LD_LIBRARY_PATH += ":" +\ + os.path.join(Constants.DEVICE_WORKDIR, "thirdparty", os.path.basename(lib)) if __name__ == "__main__": - """ - command format: python3 run_js_test.py -bp /home/out -p /home/arkjs-perf-test/js-perf-test -o output_path - -v d_8_binary_path -e ver_platform - notes: all paths must be absolute path - """ LOG_PATH = os.path.join(Constants.TMP_PATH, "test.log") if os.path.exists(LOG_PATH): os.remove(LOG_PATH) @@ -739,11 +857,14 @@ if __name__ == "__main__": DETERIORATION_BOUNDARY_VALUE = paras.deterioration_boundary_value BINARY_PATH = paras.binarypath - ICU_DATA_PATH = os.path.join(BINARY_PATH, "third_party/icu/ohos_icu4j/data/") + ICU_DATA_PATH = os.path.join(BINARY_PATH, "third_party/icu/ohos_icu4j/data") OUTPUT_PATH = Constants.CUR_PATH - Constants.V_8_ENGINED_PATH = paras.d_8_binary_path - Constants.VER_PLATFORM = paras.ver_platform - get_config() + get_config(paras) + if not os.path.exists(Constants.ARK_JS_VM_PATH): + logger.error("%s does not exist", Constants.ARK_JS_VM_PATH) + sys.exit(1) + if Constants.VER_PLATFORM.find("arm64") != -1: + prepare_device() if paras.output_folder_path is not None: OUTPUT_PATH = paras.output_folder_path -- Gitee