14514f5e3Sopenharmony_ci#!/usr/bin/env python
24514f5e3Sopenharmony_ci# -*- coding: utf-8 -*-
34514f5e3Sopenharmony_ci"""
44514f5e3Sopenharmony_ciCopyright (c) 2024 Huawei Device Co., Ltd.
54514f5e3Sopenharmony_ciLicensed under the Apache License, Version 2.0 (the "License");
64514f5e3Sopenharmony_ciyou may not use this file except in compliance with the License.
74514f5e3Sopenharmony_ciYou may obtain a copy of the License at
84514f5e3Sopenharmony_ci
94514f5e3Sopenharmony_ci    http://www.apache.org/licenses/LICENSE-2.0
104514f5e3Sopenharmony_ci
114514f5e3Sopenharmony_ciUnless required by applicable law or agreed to in writing, software
124514f5e3Sopenharmony_cidistributed under the License is distributed on an "AS IS" BASIS,
134514f5e3Sopenharmony_ciWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
144514f5e3Sopenharmony_ciSee the License for the specific language governing permissions and
154514f5e3Sopenharmony_cilimitations under the License.
164514f5e3Sopenharmony_ci
174514f5e3Sopenharmony_ciDescription: Use ark to execute workload test suite
184514f5e3Sopenharmony_ci"""
194514f5e3Sopenharmony_ci
204514f5e3Sopenharmony_ciimport argparse
214514f5e3Sopenharmony_ciimport datetime
224514f5e3Sopenharmony_ciimport json
234514f5e3Sopenharmony_ciimport logging
244514f5e3Sopenharmony_ciimport os
254514f5e3Sopenharmony_ciimport shutil
264514f5e3Sopenharmony_ciimport stat
274514f5e3Sopenharmony_ciimport subprocess
284514f5e3Sopenharmony_ciimport sys
294514f5e3Sopenharmony_cifrom typing import Union, List, Tuple
304514f5e3Sopenharmony_cifrom collections import namedtuple
314514f5e3Sopenharmony_cifrom openpyxl import Workbook, load_workbook
324514f5e3Sopenharmony_cifrom openpyxl.styles import PatternFill
334514f5e3Sopenharmony_ci
344514f5e3Sopenharmony_ci
354514f5e3Sopenharmony_cidef get_logger(logger_name, log_file_path, level=logging.INFO):
364514f5e3Sopenharmony_ci    """Create logger for this script"""
374514f5e3Sopenharmony_ci    formatter = logging.Formatter(fmt='[%(asctime)s]  [%(levelname)s]   %(message)s',
384514f5e3Sopenharmony_ci                                  datefmt='%Y-%m-%d  %H:%M:%S')
394514f5e3Sopenharmony_ci
404514f5e3Sopenharmony_ci    fh = logging.FileHandler(encoding='utf-8', mode='a', filename=log_file_path)
414514f5e3Sopenharmony_ci    fh.setFormatter(formatter)
424514f5e3Sopenharmony_ci    fh.setLevel(logging.DEBUG)
434514f5e3Sopenharmony_ci    # console output
444514f5e3Sopenharmony_ci    ch = logging.StreamHandler()
454514f5e3Sopenharmony_ci    ch.setFormatter(formatter)
464514f5e3Sopenharmony_ci    ch.setLevel(logging.DEBUG)
474514f5e3Sopenharmony_ci    log = logging.getLogger(logger_name)
484514f5e3Sopenharmony_ci    log.addHandler(fh)
494514f5e3Sopenharmony_ci    log.addHandler(ch)
504514f5e3Sopenharmony_ci    log.setLevel(level)
514514f5e3Sopenharmony_ci
524514f5e3Sopenharmony_ci    return log
534514f5e3Sopenharmony_ci
544514f5e3Sopenharmony_ci
554514f5e3Sopenharmony_ciclass Constants:
564514f5e3Sopenharmony_ci    logger = None
574514f5e3Sopenharmony_ci    CUR_PATH = os.path.abspath(os.path.dirname(__file__))
584514f5e3Sopenharmony_ci    TMP_PATH = os.path.join(os.getcwd(), "tmp")
594514f5e3Sopenharmony_ci    REPORT_NAME_HEAD_FIX = "js_perf_test_result"
604514f5e3Sopenharmony_ci    RET_OK = 0
614514f5e3Sopenharmony_ci    RET_FAILED = 1
624514f5e3Sopenharmony_ci    BINARY_PATH = ""
634514f5e3Sopenharmony_ci    OUTPUT_PATH = ""
644514f5e3Sopenharmony_ci    LOG_PATH = ""
654514f5e3Sopenharmony_ci    TODAY_EXCEL_PATH = ""
664514f5e3Sopenharmony_ci    YESTERDAY_EXCEL_PATH = ""
674514f5e3Sopenharmony_ci    DETERIORATION_BOUNDARY_VALUE = 0.05
684514f5e3Sopenharmony_ci    TODAY_EXCUTE_INFO = {}
694514f5e3Sopenharmony_ci    YESTERDAY_EXCUTE_TIME_DICT = {}
704514f5e3Sopenharmony_ci    V_8_EXCUTE_TIME_DICT = {}
714514f5e3Sopenharmony_ci    V_8_JITLESS_EXCUTE_TIME_DICT = {}
724514f5e3Sopenharmony_ci    JS_FILE_SUPER_LINK_DICT = {}
734514f5e3Sopenharmony_ci    HYPERLINK_HEAD = "https://gitee.com/dov1s/arkjs-perf-test/tree/builtins_test1110/js-perf-test"
744514f5e3Sopenharmony_ci    PASS = 'pass'
754514f5e3Sopenharmony_ci    FAIL = 'fail'
764514f5e3Sopenharmony_ci    SOLID = 'solid'
774514f5e3Sopenharmony_ci    NA_FIX = 'NA'
784514f5e3Sopenharmony_ci    # 1e-6 s
794514f5e3Sopenharmony_ci    COMPARISON_ACCURACY = 0.001
804514f5e3Sopenharmony_ci    ICU_DATA_PATH = ""
814514f5e3Sopenharmony_ci    FIX_STR = "8/d"
824514f5e3Sopenharmony_ci    V_8_ENGINED_PATH = '/usr/bin/v{}8'.format(FIX_STR)
834514f5e3Sopenharmony_ci    VER_PLATFORM = "full_x86_64"
844514f5e3Sopenharmony_ci    ES2ABC_PATH = ""
854514f5e3Sopenharmony_ci    ARK_JS_VM_PATH = ""
864514f5e3Sopenharmony_ci    ETS_RUNTIME = ""
874514f5e3Sopenharmony_ci    LD_LIBRARY_PATH = ""
884514f5e3Sopenharmony_ci    HDC_PATH: str = "hdc"
894514f5e3Sopenharmony_ci    DEVICE_WORKDIR: str = "/data/local/tmp/jsperftest"
904514f5e3Sopenharmony_ci    LIBS_LIST: List[str] = []
914514f5e3Sopenharmony_ci    STUB_AN: str = ""
924514f5e3Sopenharmony_ci    TASKSET_MASK: str = ""
934514f5e3Sopenharmony_ci    CaseTestDataType = namedtuple('test', ['exec_status', 'exec_time'])
944514f5e3Sopenharmony_ci
954514f5e3Sopenharmony_ci
964514f5e3Sopenharmony_cidef get_js_file_class_api_scenes(js_file_path):
974514f5e3Sopenharmony_ci    """Get all cases for one benchmark file"""
984514f5e3Sopenharmony_ci    scenes = []
994514f5e3Sopenharmony_ci    with open(js_file_path, 'r') as f:
1004514f5e3Sopenharmony_ci        for line in f:
1014514f5e3Sopenharmony_ci            if "scene_output" in line:
1024514f5e3Sopenharmony_ci                str_array = line.split(':')
1034514f5e3Sopenharmony_ci                mid_str = str_array[1].strip()
1044514f5e3Sopenharmony_ci                elements = mid_str.split(' ')
1054514f5e3Sopenharmony_ci                main_key = '/'.join([elements[0], elements[1] + '.js', elements[2]]).lower()
1064514f5e3Sopenharmony_ci                scenes.append(main_key)
1074514f5e3Sopenharmony_ci    return scenes
1084514f5e3Sopenharmony_ci
1094514f5e3Sopenharmony_ci
1104514f5e3Sopenharmony_cidef degraded_str(yesterday_excute_time, exec_time):
1114514f5e3Sopenharmony_ci    is_degraded_str = Constants.NA_FIX
1124514f5e3Sopenharmony_ci    if len(str(yesterday_excute_time).strip()) != 0:
1134514f5e3Sopenharmony_ci        if abs(float(yesterday_excute_time)) <= Constants.COMPARISON_ACCURACY:
1144514f5e3Sopenharmony_ci            is_degraded_str = str(True) if abs(float(exec_time)) >= DETERIORATION_BOUNDARY_VALUE else str(False)
1154514f5e3Sopenharmony_ci        else:
1164514f5e3Sopenharmony_ci            is_degraded_tmp = float(exec_time) / float(yesterday_excute_time) >= (1 + DETERIORATION_BOUNDARY_VALUE)
1174514f5e3Sopenharmony_ci            is_degraded_str = str(True) if is_degraded_tmp else str(False)
1184514f5e3Sopenharmony_ci
1194514f5e3Sopenharmony_ci    return is_degraded_str
1204514f5e3Sopenharmony_ci
1214514f5e3Sopenharmony_ci
1224514f5e3Sopenharmony_cidef v_8_excute_time_compute(main_key):
1234514f5e3Sopenharmony_ci    v_8_excute_time_str = ''
1244514f5e3Sopenharmony_ci    if len(Constants.V_8_EXCUTE_TIME_DICT) > 0 and main_key in Constants.V_8_EXCUTE_TIME_DICT.keys():
1254514f5e3Sopenharmony_ci        v_8_excute_time_str = Constants.V_8_EXCUTE_TIME_DICT[main_key].strip()
1264514f5e3Sopenharmony_ci
1274514f5e3Sopenharmony_ci    if len(v_8_excute_time_str) == 0:
1284514f5e3Sopenharmony_ci        v_8_excute_time = ' '
1294514f5e3Sopenharmony_ci    else:
1304514f5e3Sopenharmony_ci        v_8_excute_time = v_8_excute_time_str
1314514f5e3Sopenharmony_ci
1324514f5e3Sopenharmony_ci    return v_8_excute_time
1334514f5e3Sopenharmony_ci
1344514f5e3Sopenharmony_ci
1354514f5e3Sopenharmony_cidef v_8_gitless_excute_time_compute(main_key):
1364514f5e3Sopenharmony_ci    v_8_jitless_excute_time_str = ''
1374514f5e3Sopenharmony_ci    if len(Constants.V_8_JITLESS_EXCUTE_TIME_DICT) > 0 and main_key in Constants.V_8_JITLESS_EXCUTE_TIME_DICT.keys():
1384514f5e3Sopenharmony_ci        v_8_jitless_excute_time_str = Constants.V_8_JITLESS_EXCUTE_TIME_DICT[main_key].strip()
1394514f5e3Sopenharmony_ci
1404514f5e3Sopenharmony_ci    if len(v_8_jitless_excute_time_str) == 0:
1414514f5e3Sopenharmony_ci        v_8_jitless_excute_time = ' '
1424514f5e3Sopenharmony_ci    else:
1434514f5e3Sopenharmony_ci        v_8_jitless_excute_time = v_8_jitless_excute_time_str
1444514f5e3Sopenharmony_ci
1454514f5e3Sopenharmony_ci    return v_8_jitless_excute_time
1464514f5e3Sopenharmony_ci
1474514f5e3Sopenharmony_ci
1484514f5e3Sopenharmony_cidef ark_divide_v_8_compute(exec_time, v_8_excute_time):
1494514f5e3Sopenharmony_ci    if len(exec_time) == 0 or len(v_8_excute_time.strip()) == 0:
1504514f5e3Sopenharmony_ci        ark_divide_v_8 = Constants.NA_FIX
1514514f5e3Sopenharmony_ci    elif abs(float(exec_time)) <= Constants.COMPARISON_ACCURACY:
1524514f5e3Sopenharmony_ci        if abs(float(v_8_excute_time)) <= Constants.COMPARISON_ACCURACY:
1534514f5e3Sopenharmony_ci            ark_divide_v_8 = '1'
1544514f5e3Sopenharmony_ci        else:
1554514f5e3Sopenharmony_ci            ark_divide_v_8 = '0'
1564514f5e3Sopenharmony_ci    else:
1574514f5e3Sopenharmony_ci        v_8_excute_time = v_8_excute_time.strip()
1584514f5e3Sopenharmony_ci        if len(v_8_excute_time) == 0 or abs(float(v_8_excute_time)) <= Constants.COMPARISON_ACCURACY:
1594514f5e3Sopenharmony_ci            ark_divide_v_8 = Constants.NA_FIX
1604514f5e3Sopenharmony_ci        else:
1614514f5e3Sopenharmony_ci            ark_divide_v_8 = str("{:.2f}".format(float(exec_time) / float(v_8_excute_time)))
1624514f5e3Sopenharmony_ci
1634514f5e3Sopenharmony_ci    return ark_divide_v_8
1644514f5e3Sopenharmony_ci
1654514f5e3Sopenharmony_ci
1664514f5e3Sopenharmony_cidef cast_to_float_or_str(value: str) -> Union[float, str]:
1674514f5e3Sopenharmony_ci    """Return float value by str if it is possible, return input str otherwise"""
1684514f5e3Sopenharmony_ci    try:
1694514f5e3Sopenharmony_ci        result = float(value)
1704514f5e3Sopenharmony_ci    except ValueError:
1714514f5e3Sopenharmony_ci        result = value
1724514f5e3Sopenharmony_ci    return result
1734514f5e3Sopenharmony_ci
1744514f5e3Sopenharmony_ci
1754514f5e3Sopenharmony_cidef append_row_data(report_file, case_test_data):
1764514f5e3Sopenharmony_ci    wb = load_workbook(report_file)
1774514f5e3Sopenharmony_ci    ws = wb.worksheets[0]
1784514f5e3Sopenharmony_ci    for main_key in case_test_data.keys():
1794514f5e3Sopenharmony_ci        str_arr = main_key.split('/')
1804514f5e3Sopenharmony_ci        class_name = str_arr[0]
1814514f5e3Sopenharmony_ci        api_name = str_arr[1]
1824514f5e3Sopenharmony_ci        scene = str_arr[2]
1834514f5e3Sopenharmony_ci        js_case_name = '/'.join([class_name, api_name])
1844514f5e3Sopenharmony_ci        excute_status = case_test_data[main_key].exec_status
1854514f5e3Sopenharmony_ci        exec_time = case_test_data[main_key].exec_time.strip()
1864514f5e3Sopenharmony_ci        yesterday_excute_time = ''
1874514f5e3Sopenharmony_ci        if (len(Constants.YESTERDAY_EXCUTE_TIME_DICT) > 0 and
1884514f5e3Sopenharmony_ci                Constants.YESTERDAY_EXCUTE_TIME_DICT.get(main_key) is not None):
1894514f5e3Sopenharmony_ci            yesterday_excute_time = str(Constants.YESTERDAY_EXCUTE_TIME_DICT[main_key])
1904514f5e3Sopenharmony_ci        is_degraded_str = degraded_str(yesterday_excute_time, exec_time)
1914514f5e3Sopenharmony_ci        v_8_excute_time = v_8_excute_time_compute(main_key)
1924514f5e3Sopenharmony_ci        v_8_jitless_excute_time = v_8_gitless_excute_time_compute(main_key)
1934514f5e3Sopenharmony_ci        ark_divide_v_8 = ark_divide_v_8_compute(exec_time, v_8_excute_time)
1944514f5e3Sopenharmony_ci        if len(exec_time) == 0 or len(v_8_jitless_excute_time.strip()) == 0:
1954514f5e3Sopenharmony_ci            ark_divide_v_8_with_jitless = Constants.NA_FIX
1964514f5e3Sopenharmony_ci        elif abs(float(exec_time)) <= Constants.COMPARISON_ACCURACY:
1974514f5e3Sopenharmony_ci            if abs(float(v_8_jitless_excute_time)) <= Constants.COMPARISON_ACCURACY:
1984514f5e3Sopenharmony_ci                ark_divide_v_8_with_jitless = '1'
1994514f5e3Sopenharmony_ci            else:
2004514f5e3Sopenharmony_ci                ark_divide_v_8_with_jitless = '0'
2014514f5e3Sopenharmony_ci        else:
2024514f5e3Sopenharmony_ci            v_8_jitless_excute_time = v_8_jitless_excute_time.strip()
2034514f5e3Sopenharmony_ci            if (len(v_8_jitless_excute_time) == 0 or
2044514f5e3Sopenharmony_ci                    abs(float(v_8_jitless_excute_time)) <= Constants.COMPARISON_ACCURACY):
2054514f5e3Sopenharmony_ci                ark_divide_v_8_with_jitless = Constants.NA_FIX
2064514f5e3Sopenharmony_ci            else:
2074514f5e3Sopenharmony_ci                ark_divide_v_8_with_jitless = str("{:.2f}".format(float(exec_time) / float(v_8_jitless_excute_time)))
2084514f5e3Sopenharmony_ci        jis_case_file_name_with_class = Constants.JS_FILE_SUPER_LINK_DICT['/'.join([class_name, api_name])]
2094514f5e3Sopenharmony_ci        js_file_super_link = '/'.join([Constants.HYPERLINK_HEAD, jis_case_file_name_with_class])
2104514f5e3Sopenharmony_ci        new_row = [js_case_name, scene, excute_status, cast_to_float_or_str(exec_time), yesterday_excute_time,
2114514f5e3Sopenharmony_ci                   is_degraded_str, cast_to_float_or_str(v_8_excute_time),
2124514f5e3Sopenharmony_ci                   cast_to_float_or_str(v_8_jitless_excute_time), cast_to_float_or_str(ark_divide_v_8),
2134514f5e3Sopenharmony_ci                   cast_to_float_or_str(ark_divide_v_8_with_jitless), js_file_super_link, ' ']
2144514f5e3Sopenharmony_ci        ws.append(new_row)
2154514f5e3Sopenharmony_ci        check(is_degraded_str, ark_divide_v_8, ark_divide_v_8_with_jitless, ws)
2164514f5e3Sopenharmony_ci    wb.save(report_file)
2174514f5e3Sopenharmony_ci    return Constants.RET_OK
2184514f5e3Sopenharmony_ci
2194514f5e3Sopenharmony_ci
2204514f5e3Sopenharmony_cidef check(is_degraded_str, ark_divide_v_8, ark_divide_v_8_with_jitless, ws):
2214514f5e3Sopenharmony_ci    if is_degraded_str is str(True):
2224514f5e3Sopenharmony_ci        ws.cell(row=ws.max_row, column=6).fill = PatternFill(start_color='FF0000', end_color='FF0000',
2234514f5e3Sopenharmony_ci                                                             fill_type=Constants.SOLID)
2244514f5e3Sopenharmony_ci    if (ark_divide_v_8 != Constants.NA_FIX and
2254514f5e3Sopenharmony_ci            (float(ark_divide_v_8) > 2 or abs(float(ark_divide_v_8) - 2) <= Constants.COMPARISON_ACCURACY)):
2264514f5e3Sopenharmony_ci        ws.cell(row=ws.max_row, column=9).fill = PatternFill(start_color='FFFF00', end_color='FFFF00',
2274514f5e3Sopenharmony_ci                                                             fill_type=Constants.SOLID)
2284514f5e3Sopenharmony_ci    if (ark_divide_v_8_with_jitless != Constants.NA_FIX and
2294514f5e3Sopenharmony_ci            (float(ark_divide_v_8_with_jitless) > 2 or
2304514f5e3Sopenharmony_ci             abs(float(ark_divide_v_8_with_jitless) - 2) <= Constants.COMPARISON_ACCURACY)):
2314514f5e3Sopenharmony_ci        ws.cell(row=ws.max_row, column=10).fill = PatternFill(start_color='FF00FF', end_color='FF00FF',
2324514f5e3Sopenharmony_ci                                                              fill_type=Constants.SOLID)
2334514f5e3Sopenharmony_ci
2344514f5e3Sopenharmony_ci
2354514f5e3Sopenharmony_cidef get_ark_js_cmd(abc_file: str) -> List[str]:
2364514f5e3Sopenharmony_ci    """Get command for ark js vm"""
2374514f5e3Sopenharmony_ci    cmd: List[str] = []
2384514f5e3Sopenharmony_ci    if Constants.VER_PLATFORM.find("arm64") != -1:
2394514f5e3Sopenharmony_ci        cmd = [Constants.HDC_PATH, "shell"]
2404514f5e3Sopenharmony_ci        run_cmd = f"LD_LIBRARY_PATH={Constants.LD_LIBRARY_PATH}"
2414514f5e3Sopenharmony_ci        if len(Constants.TASKSET_MASK) != 0:
2424514f5e3Sopenharmony_ci            run_cmd += f" taskset -a {Constants.TASKSET_MASK}"
2434514f5e3Sopenharmony_ci        run_cmd += " " + os.path.join(Constants.DEVICE_WORKDIR, "ark_js_vm")
2444514f5e3Sopenharmony_ci        run_cmd += " --stub-file " + os.path.join(Constants.DEVICE_WORKDIR, "lib", "stub.an")
2454514f5e3Sopenharmony_ci        run_cmd += " --icu-data-path " + os.path.join(Constants.DEVICE_WORKDIR, "data")
2464514f5e3Sopenharmony_ci        run_cmd += " " + abc_file
2474514f5e3Sopenharmony_ci        cmd.append(run_cmd)
2484514f5e3Sopenharmony_ci    else:
2494514f5e3Sopenharmony_ci        cmd = [Constants.ARK_JS_VM_PATH,
2504514f5e3Sopenharmony_ci               "--log-level=info",
2514514f5e3Sopenharmony_ci               "--enable-runtime-stat=true",
2524514f5e3Sopenharmony_ci               "--stub-file", Constants.STUB_AN,
2534514f5e3Sopenharmony_ci               "--icu-data-path", ICU_DATA_PATH,
2544514f5e3Sopenharmony_ci               abc_file]
2554514f5e3Sopenharmony_ci        if len(Constants.TASKSET_MASK) != 0:
2564514f5e3Sopenharmony_ci            cmd = ["taskset", "-a", Constants.TASKSET_MASK] + cmd
2574514f5e3Sopenharmony_ci    return cmd
2584514f5e3Sopenharmony_ci
2594514f5e3Sopenharmony_ci
2604514f5e3Sopenharmony_cidef prepare_for_ark_run(class_name: str, api_name: str) -> Tuple[str, str]:
2614514f5e3Sopenharmony_ci    """Prepare workspace for benchmark"""
2624514f5e3Sopenharmony_ci    fangzhou_test_path = os.path.join(Constants.TMP_PATH, "fangzhou_test")  # for abc file
2634514f5e3Sopenharmony_ci    if os.path.exists(fangzhou_test_path):
2644514f5e3Sopenharmony_ci        shutil.rmtree(fangzhou_test_path)
2654514f5e3Sopenharmony_ci    os.makedirs(fangzhou_test_path)
2664514f5e3Sopenharmony_ci    class_folder_path = os.path.join(fangzhou_test_path, class_name)
2674514f5e3Sopenharmony_ci    if not os.path.exists(class_folder_path):
2684514f5e3Sopenharmony_ci        os.makedirs(class_folder_path)
2694514f5e3Sopenharmony_ci    return (os.path.join(Constants.CUR_PATH, api_name + ".abc"),
2704514f5e3Sopenharmony_ci            os.path.join(class_folder_path, api_name + ".log"))
2714514f5e3Sopenharmony_ci
2724514f5e3Sopenharmony_ci
2734514f5e3Sopenharmony_cidef run_es2panda(abc_file: str, js_file: str) -> int:
2744514f5e3Sopenharmony_ci    """Run es2panda for one benchmark file"""
2754514f5e3Sopenharmony_ci    cmd = [Constants.ES2ABC_PATH, "--output", abc_file, js_file]
2764514f5e3Sopenharmony_ci    logger.info("run cmd: %s", cmd)
2774514f5e3Sopenharmony_ci    ret = subprocess.run(cmd, check=False)
2784514f5e3Sopenharmony_ci    if ret.returncode != 0:
2794514f5e3Sopenharmony_ci        logger.error("ret = %s, %s generate abc file failed. cmd: %s", str(ret), js_file, cmd)
2804514f5e3Sopenharmony_ci    return ret.returncode
2814514f5e3Sopenharmony_ci
2824514f5e3Sopenharmony_ci
2834514f5e3Sopenharmony_cidef run_js_case_via_ark(js_file_path, class_name, api_name, iterations, report_file):
2844514f5e3Sopenharmony_ci    """Run js perf benchmark via ark js vm"""
2854514f5e3Sopenharmony_ci    composite_scenes = get_js_file_class_api_scenes(js_file_path)
2864514f5e3Sopenharmony_ci    case_test_data = {}
2874514f5e3Sopenharmony_ci    execute_status = Constants.FAIL
2884514f5e3Sopenharmony_ci    execute_time = ' '
2894514f5e3Sopenharmony_ci
2904514f5e3Sopenharmony_ci    for _, composite_scene in enumerate(composite_scenes):
2914514f5e3Sopenharmony_ci        case_test_data[composite_scene] = Constants.CaseTestDataType(execute_status, execute_time)
2924514f5e3Sopenharmony_ci
2934514f5e3Sopenharmony_ci    js_file_name = class_name + '/' + api_name + '.js'
2944514f5e3Sopenharmony_ci    cur_abc_file, api_log_path = prepare_for_ark_run(class_name, api_name)
2954514f5e3Sopenharmony_ci    using_abc_file = cur_abc_file
2964514f5e3Sopenharmony_ci
2974514f5e3Sopenharmony_ci    ret = run_es2panda(cur_abc_file, js_file_path)
2984514f5e3Sopenharmony_ci    if ret != 0:
2994514f5e3Sopenharmony_ci        append_row_data(report_file, case_test_data)
3004514f5e3Sopenharmony_ci        return case_test_data
3014514f5e3Sopenharmony_ci    if Constants.VER_PLATFORM.find("arm64") != -1:
3024514f5e3Sopenharmony_ci        using_abc_file = os.path.join(Constants.DEVICE_WORKDIR, os.path.basename(cur_abc_file))
3034514f5e3Sopenharmony_ci        if hdc_send(cur_abc_file, using_abc_file) != 0:
3044514f5e3Sopenharmony_ci            append_row_data(report_file, case_test_data)
3054514f5e3Sopenharmony_ci            return case_test_data
3064514f5e3Sopenharmony_ci    # execute abc
3074514f5e3Sopenharmony_ci    cmd = get_ark_js_cmd(using_abc_file)
3084514f5e3Sopenharmony_ci
3094514f5e3Sopenharmony_ci    logger.info("run cmd: %s", cmd)
3104514f5e3Sopenharmony_ci    flags = os.O_WRONLY | os.O_CREAT | os.O_EXCL
3114514f5e3Sopenharmony_ci    modes = stat.S_IWUSR | stat.S_IRUSR
3124514f5e3Sopenharmony_ci
3134514f5e3Sopenharmony_ci    data = {}
3144514f5e3Sopenharmony_ci    for _ in range(iterations):
3154514f5e3Sopenharmony_ci        if os.path.exists(api_log_path):
3164514f5e3Sopenharmony_ci            os.remove(api_log_path)
3174514f5e3Sopenharmony_ci        with os.fdopen(os.open(api_log_path, flags, modes), 'wb') as outfile:
3184514f5e3Sopenharmony_ci            ret = subprocess.run(cmd, stdout=outfile)
3194514f5e3Sopenharmony_ci
3204514f5e3Sopenharmony_ci        if ret.returncode != 0:
3214514f5e3Sopenharmony_ci            logger.error("%s execute abc file failed. cmd: %s", js_file_name, cmd)
3224514f5e3Sopenharmony_ci            append_row_data(report_file, case_test_data)
3234514f5e3Sopenharmony_ci            return case_test_data
3244514f5e3Sopenharmony_ci        if os.path.exists(api_log_path):
3254514f5e3Sopenharmony_ci            data = update_data_by_log(data, api_log_path, js_file_name[:-3])
3264514f5e3Sopenharmony_ci
3274514f5e3Sopenharmony_ci    case_test_data.clear()
3284514f5e3Sopenharmony_ci    execute_status = Constants.PASS
3294514f5e3Sopenharmony_ci    for k, time_value in data.items():
3304514f5e3Sopenharmony_ci        case_test_data[k] = Constants.CaseTestDataType(execute_status, str(time_value / iterations))
3314514f5e3Sopenharmony_ci    append_row_data(report_file, case_test_data)
3324514f5e3Sopenharmony_ci    logger.info("%s execute abc file successfully. cmd: %s case_test_data: %s",
3334514f5e3Sopenharmony_ci                js_file_name, cmd, case_test_data)
3344514f5e3Sopenharmony_ci    os.remove(cur_abc_file)
3354514f5e3Sopenharmony_ci    return case_test_data
3364514f5e3Sopenharmony_ci
3374514f5e3Sopenharmony_ci
3384514f5e3Sopenharmony_cidef run_via_ark(jspath, report_file, iterations):
3394514f5e3Sopenharmony_ci    if not os.path.exists(jspath):
3404514f5e3Sopenharmony_ci        logger.error("js perf cases path is not exist. jspath: %s", jspath)
3414514f5e3Sopenharmony_ci    logger.info("begin to run js perf test via ark. js perf cases path: %s", jspath)
3424514f5e3Sopenharmony_ci    for root, _, files in os.walk(jspath):
3434514f5e3Sopenharmony_ci        if "TestCaseError" in root:
3444514f5e3Sopenharmony_ci            continue
3454514f5e3Sopenharmony_ci        for file in files:
3464514f5e3Sopenharmony_ci            if not file.endswith('.js'):
3474514f5e3Sopenharmony_ci                continue
3484514f5e3Sopenharmony_ci
3494514f5e3Sopenharmony_ci            file_path = os.path.join(root, file)
3504514f5e3Sopenharmony_ci            results = file_path.split("/")
3514514f5e3Sopenharmony_ci            class_name = results[-2]
3524514f5e3Sopenharmony_ci            api_name = results[-1].split(".")[0]
3534514f5e3Sopenharmony_ci            js_case_name = '/'.join([class_name, results[-1]])
3544514f5e3Sopenharmony_ci            logger.info("begin to execute %s.", js_case_name)
3554514f5e3Sopenharmony_ci            test_data = run_js_case_via_ark(file_path, class_name, api_name, iterations, report_file)
3564514f5e3Sopenharmony_ci            for _, key in enumerate(test_data.keys()):
3574514f5e3Sopenharmony_ci                Constants.TODAY_EXCUTE_INFO[key] = test_data.get(key)
3584514f5e3Sopenharmony_ci            logger.info("finish executing %s. executing info: %s.", js_case_name, Constants.TODAY_EXCUTE_INFO)
3594514f5e3Sopenharmony_ci
3604514f5e3Sopenharmony_ci
3614514f5e3Sopenharmony_cidef get_js_case_super_link_data(jspath):
3624514f5e3Sopenharmony_ci    logger.info("get js case super link data")
3634514f5e3Sopenharmony_ci    for root, _, files in os.walk(jspath):
3644514f5e3Sopenharmony_ci        for file in files:
3654514f5e3Sopenharmony_ci            if not file.endswith('.js'):
3664514f5e3Sopenharmony_ci                continue
3674514f5e3Sopenharmony_ci
3684514f5e3Sopenharmony_ci            file_path = os.path.join(root, file)
3694514f5e3Sopenharmony_ci            results = file_path.split("/")
3704514f5e3Sopenharmony_ci            class_name = results[-2]
3714514f5e3Sopenharmony_ci            js_case_name = '/'.join([class_name, results[-1]])
3724514f5e3Sopenharmony_ci            key = js_case_name.lower()
3734514f5e3Sopenharmony_ci            Constants.JS_FILE_SUPER_LINK_DICT[key] = js_case_name
3744514f5e3Sopenharmony_ci
3754514f5e3Sopenharmony_ci
3764514f5e3Sopenharmony_cidef export_sumary_info_for_notifying_email(json_path, total_cases_num, ark_divide_v_8_num, ark_divide_v_8_jitless_num):
3774514f5e3Sopenharmony_ci    data = {}
3784514f5e3Sopenharmony_ci    data['kind'] = 'V 8 js-perf-test'
3794514f5e3Sopenharmony_ci    data['Total'] = total_cases_num
3804514f5e3Sopenharmony_ci    data['Ark劣化v 8'] = ark_divide_v_8_num
3814514f5e3Sopenharmony_ci    data['Ark劣化v 8 jitless'] = ark_divide_v_8_jitless_num
3824514f5e3Sopenharmony_ci    flags = os.O_WRONLY | os.O_CREAT | os.O_EXCL
3834514f5e3Sopenharmony_ci    modes = stat.S_IWUSR | stat.S_IRUSR
3844514f5e3Sopenharmony_ci    if os.path.exists(json_path):
3854514f5e3Sopenharmony_ci        os.remove(json_path)
3864514f5e3Sopenharmony_ci    with os.fdopen(os.open(json_path, flags, modes), 'w', encoding='utf-8') as f:
3874514f5e3Sopenharmony_ci        json.dump(data, f, indent=4, ensure_ascii=False)
3884514f5e3Sopenharmony_ci        logger.info("export summary info to json file successfully.")
3894514f5e3Sopenharmony_ci
3904514f5e3Sopenharmony_ci
3914514f5e3Sopenharmony_cidef get_umary_info_json_file_path(daily_report_file_path):
3924514f5e3Sopenharmony_ci    dir_path = os.path.dirname(daily_report_file_path)
3934514f5e3Sopenharmony_ci    json_file_name = 'jsperftest_notifying_info_in_email.json'
3944514f5e3Sopenharmony_ci    json_file_path = os.path.join(dir_path, json_file_name)
3954514f5e3Sopenharmony_ci    return json_file_path
3964514f5e3Sopenharmony_ci
3974514f5e3Sopenharmony_ci
3984514f5e3Sopenharmony_cidef append_summary_info(report_file, total_cost_time):
3994514f5e3Sopenharmony_ci    """
4004514f5e3Sopenharmony_ci        summary info:
4014514f5e3Sopenharmony_ci            pass count:
4024514f5e3Sopenharmony_ci            fail count:
4034514f5e3Sopenharmony_ci            totle count:
4044514f5e3Sopenharmony_ci            degraded count:
4054514f5e3Sopenharmony_ci            total excute time is(s) :
4064514f5e3Sopenharmony_ci            degraded percentage upper limit:
4074514f5e3Sopenharmony_ci            ark/v 8 degraded count:
4084514f5e3Sopenharmony_ci            ark/v 8 jitless degraded count:
4094514f5e3Sopenharmony_ci    """
4104514f5e3Sopenharmony_ci    wb = load_workbook(report_file)
4114514f5e3Sopenharmony_ci    ws = wb.worksheets[0]
4124514f5e3Sopenharmony_ci
4134514f5e3Sopenharmony_ci    totle_num = 0
4144514f5e3Sopenharmony_ci    degraded_upper_limit = DETERIORATION_BOUNDARY_VALUE
4154514f5e3Sopenharmony_ci    pass_num = 0
4164514f5e3Sopenharmony_ci    failed_num = 0
4174514f5e3Sopenharmony_ci    degraded_num = 0
4184514f5e3Sopenharmony_ci    ark_divide_v_8_degraded_count = 0
4194514f5e3Sopenharmony_ci    ark_divide_v_8_jitless_degraded_count = 0
4204514f5e3Sopenharmony_ci
4214514f5e3Sopenharmony_ci    last_bench_line = ws.max_row
4224514f5e3Sopenharmony_ci    for row_num in range(2, last_bench_line + 1):
4234514f5e3Sopenharmony_ci        excu_status = str(ws.cell(row=row_num, column=3).value)
4244514f5e3Sopenharmony_ci        is_degraded = str(ws.cell(row=row_num, column=6).value)
4254514f5e3Sopenharmony_ci        if is_degraded == str(True):
4264514f5e3Sopenharmony_ci            degraded_num += 1
4274514f5e3Sopenharmony_ci
4284514f5e3Sopenharmony_ci        if excu_status == Constants.PASS:
4294514f5e3Sopenharmony_ci            pass_num += 1
4304514f5e3Sopenharmony_ci            totle_num += 1
4314514f5e3Sopenharmony_ci        elif excu_status == Constants.FAIL:
4324514f5e3Sopenharmony_ci            failed_num += 1
4334514f5e3Sopenharmony_ci            totle_num += 1
4344514f5e3Sopenharmony_ci
4354514f5e3Sopenharmony_ci        obj = ws.cell(row=row_num, column=9).value
4364514f5e3Sopenharmony_ci        if obj is None:
4374514f5e3Sopenharmony_ci            obj = 0
4384514f5e3Sopenharmony_ci        ark_divide_v_8 = obj
4394514f5e3Sopenharmony_ci        if ark_divide_v_8 != Constants.NA_FIX and float(ark_divide_v_8) > 1:
4404514f5e3Sopenharmony_ci            ark_divide_v_8_degraded_count += 1
4414514f5e3Sopenharmony_ci        obj = ws.cell(row=row_num, column=10).value
4424514f5e3Sopenharmony_ci        if obj is None:
4434514f5e3Sopenharmony_ci            obj = 0
4444514f5e3Sopenharmony_ci        ark_divide_v_8_jitless = obj
4454514f5e3Sopenharmony_ci        if ark_divide_v_8_jitless != Constants.NA_FIX and float(ark_divide_v_8_jitless) > 1:
4464514f5e3Sopenharmony_ci            ark_divide_v_8_jitless_degraded_count += 1
4474514f5e3Sopenharmony_ci
4484514f5e3Sopenharmony_ci    avg_funcs = ['AVERAGE', 'GEOMEAN', 'MEDIAN']
4494514f5e3Sopenharmony_ci    for avg_func in avg_funcs:
4504514f5e3Sopenharmony_ci        new_row = [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
4514514f5e3Sopenharmony_ci                   f'=\"{avg_func}: \"&{avg_func}(I2:I{last_bench_line})',
4524514f5e3Sopenharmony_ci                   f'=\"{avg_func}: \"&{avg_func}(J2:J{last_bench_line})', ' ', ' ']
4534514f5e3Sopenharmony_ci        ws.append(new_row)
4544514f5e3Sopenharmony_ci    new_row = ['劣化判定比率上限', degraded_upper_limit, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']
4554514f5e3Sopenharmony_ci    ws.append(new_row)
4564514f5e3Sopenharmony_ci    new_row = ['js 用例总数', totle_num, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']
4574514f5e3Sopenharmony_ci    ws.append(new_row)
4584514f5e3Sopenharmony_ci    new_row = ['Pass 数量', pass_num, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']
4594514f5e3Sopenharmony_ci    ws.append(new_row)
4604514f5e3Sopenharmony_ci    new_row = ['Fail 数量', failed_num, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']
4614514f5e3Sopenharmony_ci    ws.append(new_row)
4624514f5e3Sopenharmony_ci    new_row = ['ark今日劣化数量', degraded_num, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']
4634514f5e3Sopenharmony_ci    ws.append(new_row)
4644514f5e3Sopenharmony_ci    new_row = ['Total excute time(时:分:秒.微妙)', total_cost_time, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']
4654514f5e3Sopenharmony_ci    ws.append(new_row)
4664514f5e3Sopenharmony_ci    new_row = ['ark/v 8 劣化数量', ark_divide_v_8_degraded_count, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']
4674514f5e3Sopenharmony_ci    ws.append(new_row)
4684514f5e3Sopenharmony_ci    new_row = ['ark/v 8 jitless 劣化数量', ark_divide_v_8_jitless_degraded_count, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
4694514f5e3Sopenharmony_ci               ' ', ' ']
4704514f5e3Sopenharmony_ci    ws.append(new_row)
4714514f5e3Sopenharmony_ci
4724514f5e3Sopenharmony_ci    ws.column_dimensions.group('E', hidden=True)
4734514f5e3Sopenharmony_ci    wb.save(report_file)
4744514f5e3Sopenharmony_ci
4754514f5e3Sopenharmony_ci    json_file_path = get_umary_info_json_file_path(report_file)
4764514f5e3Sopenharmony_ci    export_sumary_info_for_notifying_email(json_file_path, totle_num, ark_divide_v_8_degraded_count,
4774514f5e3Sopenharmony_ci                                           ark_divide_v_8_jitless_degraded_count)
4784514f5e3Sopenharmony_ci    return Constants.RET_OK
4794514f5e3Sopenharmony_ci
4804514f5e3Sopenharmony_ci
4814514f5e3Sopenharmony_cidef process_args(args: argparse.Namespace) -> argparse.Namespace:
4824514f5e3Sopenharmony_ci    """Process and check argument values"""
4834514f5e3Sopenharmony_ci    if not os.path.exists(args.binarypath):
4844514f5e3Sopenharmony_ci        logger.error("parameter --binarypath is not exist. Please check it! binary path: %s", args.binarypath)
4854514f5e3Sopenharmony_ci        raise RuntimeError("error bad  parameters  --binarypath")
4864514f5e3Sopenharmony_ci    if args.output_folder_path is None:
4874514f5e3Sopenharmony_ci        args.output_folder_path = os.getcwd()
4884514f5e3Sopenharmony_ci    if not os.path.isabs(args.output_folder_path):
4894514f5e3Sopenharmony_ci        args.output_folder_path = os.path.abspath(args.output_folder_path)
4904514f5e3Sopenharmony_ci    if args.ver_platform.find("arm64") == -1 and not os.path.exists(args.d_8_binary_path):
4914514f5e3Sopenharmony_ci        logger.error("parameter --d_8_binary_path is not exist. Please check it! d 8  binary path: %s",
4924514f5e3Sopenharmony_ci                     args.d_8_binary_path)
4934514f5e3Sopenharmony_ci        raise RuntimeError("error bad  parameters  --d_8_binary_path: {}".format(args.d_8_binary_path))
4944514f5e3Sopenharmony_ci    if args.iterations <= 0:
4954514f5e3Sopenharmony_ci        logger.error("parameter --iterations <= 0. Please check it! iterations: %s",
4964514f5e3Sopenharmony_ci                     args.iterations)
4974514f5e3Sopenharmony_ci        raise RuntimeError(f"error bad  parameters --iterations: {args.iterations}")
4984514f5e3Sopenharmony_ci    return args
4994514f5e3Sopenharmony_ci
5004514f5e3Sopenharmony_ci
5014514f5e3Sopenharmony_cidef get_args():
5024514f5e3Sopenharmony_ci    parser = argparse.ArgumentParser()
5034514f5e3Sopenharmony_ci    parser.add_argument(
5044514f5e3Sopenharmony_ci        "--binarypath", "-bp", required=True,
5054514f5e3Sopenharmony_ci        help="path of binary folder. refer to harmony root folder path",
5064514f5e3Sopenharmony_ci    )
5074514f5e3Sopenharmony_ci    parser.add_argument(
5084514f5e3Sopenharmony_ci        "--jspath", "-p", required=True,
5094514f5e3Sopenharmony_ci        help="path of js scripts, support folder and file",
5104514f5e3Sopenharmony_ci    )
5114514f5e3Sopenharmony_ci    parser.add_argument(
5124514f5e3Sopenharmony_ci        "--deterioration_boundary_value", "-d", default=0.05,
5134514f5e3Sopenharmony_ci        help="deterioration boundary value, default 0.05",
5144514f5e3Sopenharmony_ci    )
5154514f5e3Sopenharmony_ci    parser.add_argument(
5164514f5e3Sopenharmony_ci        "--output_folder_path", "-o", default=None,
5174514f5e3Sopenharmony_ci        help="output folder for executing js cases, default current folder",
5184514f5e3Sopenharmony_ci    )
5194514f5e3Sopenharmony_ci    parser.add_argument(
5204514f5e3Sopenharmony_ci        "--d_8_binary_path", "-v", default=None,
5214514f5e3Sopenharmony_ci        help="v 8 engine d 8 binary path",
5224514f5e3Sopenharmony_ci    )
5234514f5e3Sopenharmony_ci    parser.add_argument(
5244514f5e3Sopenharmony_ci        "--ver_platform", "-e", default="full_x86_64",
5254514f5e3Sopenharmony_ci        help="Code repository version and platform",
5264514f5e3Sopenharmony_ci    )
5274514f5e3Sopenharmony_ci    parser.add_argument(
5284514f5e3Sopenharmony_ci        "--iterations", "-n", default=1, type=int,
5294514f5e3Sopenharmony_ci        help="Number of benchmark launches"
5304514f5e3Sopenharmony_ci    )
5314514f5e3Sopenharmony_ci    parser.add_argument(
5324514f5e3Sopenharmony_ci        "--hdc", default="hdc", type=str,
5334514f5e3Sopenharmony_ci        help="path to hdc"
5344514f5e3Sopenharmony_ci    )
5354514f5e3Sopenharmony_ci    parser.add_argument(
5364514f5e3Sopenharmony_ci        "--taskset", "-t", default="", type=str,
5374514f5e3Sopenharmony_ci        help="Use taskset mask for affinity on specific CPUs"
5384514f5e3Sopenharmony_ci    )
5394514f5e3Sopenharmony_ci    parser.add_argument("--config", "-c", required=True, type=str, help="config json-file")
5404514f5e3Sopenharmony_ci    return process_args(parser.parse_args())
5414514f5e3Sopenharmony_ci
5424514f5e3Sopenharmony_ci
5434514f5e3Sopenharmony_cidef init_report(report_file):
5444514f5e3Sopenharmony_ci    try:
5454514f5e3Sopenharmony_ci        today_wb = load_workbook(report_file)
5464514f5e3Sopenharmony_ci        today_ws = today_wb.worksheets[0]
5474514f5e3Sopenharmony_ci    except FileNotFoundError:
5484514f5e3Sopenharmony_ci        headers_row = ['用例名称', '场景', '执行状态', 'ark用例执行耗时(ms)', '昨日ark用例执行耗时(ms)', '是否劣化',
5494514f5e3Sopenharmony_ci                       'v 8(ms)', 'v 8 --jitless(ms)', 'ark/v 8', 'ark/v 8 jitless', 'hyperlink', '备注']
5504514f5e3Sopenharmony_ci        today_wb = Workbook()
5514514f5e3Sopenharmony_ci        today_ws = today_wb.active
5524514f5e3Sopenharmony_ci
5534514f5e3Sopenharmony_ci        today_ws.column_dimensions['A'].width = 35.0
5544514f5e3Sopenharmony_ci        today_ws.column_dimensions['B'].width = 15.0
5554514f5e3Sopenharmony_ci        today_ws.column_dimensions['C'].width = 15.0
5564514f5e3Sopenharmony_ci        today_ws.column_dimensions['D'].width = 15.0
5574514f5e3Sopenharmony_ci        today_ws.column_dimensions['E'].width = 25.0
5584514f5e3Sopenharmony_ci        today_ws.column_dimensions['F'].width = 15.0
5594514f5e3Sopenharmony_ci        today_ws.column_dimensions['G'].width = 15.0
5604514f5e3Sopenharmony_ci        today_ws.column_dimensions['H'].width = 15.0
5614514f5e3Sopenharmony_ci        today_ws.column_dimensions['I'].width = 15.0
5624514f5e3Sopenharmony_ci        today_ws.column_dimensions['J'].width = 15.0
5634514f5e3Sopenharmony_ci        today_ws.column_dimensions['K'].width = 50.0
5644514f5e3Sopenharmony_ci        today_ws.column_dimensions['L'].width = 15.0
5654514f5e3Sopenharmony_ci        today_ws.append(headers_row)
5664514f5e3Sopenharmony_ci        today_ws.freeze_panes = 'A2'
5674514f5e3Sopenharmony_ci        today_wb.save(report_file)
5684514f5e3Sopenharmony_ci
5694514f5e3Sopenharmony_ci
5704514f5e3Sopenharmony_cidef append_date_label(target_str, date_input):
5714514f5e3Sopenharmony_ci    formatted_date = date_input.strftime('%Y%m%d')
5724514f5e3Sopenharmony_ci    new_str = target_str + "_{}".format(formatted_date)
5734514f5e3Sopenharmony_ci
5744514f5e3Sopenharmony_ci    return new_str
5754514f5e3Sopenharmony_ci
5764514f5e3Sopenharmony_ci
5774514f5e3Sopenharmony_cidef get_v_8_benchmark_daily_report_path():
5784514f5e3Sopenharmony_ci    '''
5794514f5e3Sopenharmony_ci        get v 8 based data. v 8 based data obtained on 1,11,21 day for dayevery month.that is to say, in 1,11,21,
5804514f5e3Sopenharmony_ci        v 8 executes js cases.
5814514f5e3Sopenharmony_ci    '''
5824514f5e3Sopenharmony_ci    now = datetime.datetime.now(tz=datetime.timezone.utc)
5834514f5e3Sopenharmony_ci    today_str = now.strftime("%Y.%m.%d")
5844514f5e3Sopenharmony_ci    str_list = today_str.split('.')
5854514f5e3Sopenharmony_ci    year_str = str_list[0]
5864514f5e3Sopenharmony_ci    month_str = str_list[1]
5874514f5e3Sopenharmony_ci    day = int(str_list[2])
5884514f5e3Sopenharmony_ci    based_day = 0
5894514f5e3Sopenharmony_ci    if day > 21:
5904514f5e3Sopenharmony_ci        based_day = 21
5914514f5e3Sopenharmony_ci    elif day > 11:
5924514f5e3Sopenharmony_ci        based_day = 11
5934514f5e3Sopenharmony_ci    else:
5944514f5e3Sopenharmony_ci        based_day = 1
5954514f5e3Sopenharmony_ci
5964514f5e3Sopenharmony_ci    based_date = year_str + month_str + str(based_day)
5974514f5e3Sopenharmony_ci    base_date_file = based_date + '.xlsx'
5984514f5e3Sopenharmony_ci    based_report_name = '_'.join([Constants.REPORT_NAME_HEAD_FIX, base_date_file])
5994514f5e3Sopenharmony_ci    report_file_path = os.path.join(OUTPUT_PATH, based_report_name)
6004514f5e3Sopenharmony_ci    return report_file_path
6014514f5e3Sopenharmony_ci
6024514f5e3Sopenharmony_ci
6034514f5e3Sopenharmony_cidef get_given_date_report_name(date_input):
6044514f5e3Sopenharmony_ci    report_name_head = append_date_label(Constants.REPORT_NAME_HEAD_FIX, date_input)
6054514f5e3Sopenharmony_ci    return report_name_head + ".xlsx"
6064514f5e3Sopenharmony_ci
6074514f5e3Sopenharmony_ci
6084514f5e3Sopenharmony_cidef get_given_date_report_path(date_input):
6094514f5e3Sopenharmony_ci    report_file_name = get_given_date_report_name(date_input)
6104514f5e3Sopenharmony_ci    report_file_path = os.path.join(OUTPUT_PATH, report_file_name)
6114514f5e3Sopenharmony_ci    return report_file_path
6124514f5e3Sopenharmony_ci
6134514f5e3Sopenharmony_ci
6144514f5e3Sopenharmony_cidef get_yesterday_excute_times(yesterday_report):
6154514f5e3Sopenharmony_ci    if not os.path.exists(yesterday_report) or not os.path.isfile(yesterday_report):
6164514f5e3Sopenharmony_ci        return
6174514f5e3Sopenharmony_ci
6184514f5e3Sopenharmony_ci    wb = load_workbook(yesterday_report)
6194514f5e3Sopenharmony_ci    ws = wb.worksheets[0]
6204514f5e3Sopenharmony_ci    for row_num in range(2, ws.max_row + 1):
6214514f5e3Sopenharmony_ci        js_case = ws.cell(row=row_num, column=1).value
6224514f5e3Sopenharmony_ci        scene = ws.cell(row=row_num, column=2).value
6234514f5e3Sopenharmony_ci        exec_status = ws.cell(row=row_num, column=3).value
6244514f5e3Sopenharmony_ci        if exec_status == Constants.PASS or exec_status == Constants.FAIL:
6254514f5e3Sopenharmony_ci            main_key = '/'.join([js_case, scene]).lower()
6264514f5e3Sopenharmony_ci            excute_time = ws.cell(row=row_num, column=4).value
6274514f5e3Sopenharmony_ci            Constants.YESTERDAY_EXCUTE_TIME_DICT[main_key] = excute_time
6284514f5e3Sopenharmony_ci
6294514f5e3Sopenharmony_ci
6304514f5e3Sopenharmony_cidef update_data_by_log(data: dict, log_path: str, js_name: str) -> dict:
6314514f5e3Sopenharmony_ci    """Update execution time data by log file"""
6324514f5e3Sopenharmony_ci    with open(log_path, 'r') as f:
6334514f5e3Sopenharmony_ci        for line in f:
6344514f5e3Sopenharmony_ci            if "scene_output" not in line:
6354514f5e3Sopenharmony_ci                continue
6364514f5e3Sopenharmony_ci            str_array = line.split(':')
6374514f5e3Sopenharmony_ci            mid_str = str_array[1].strip()
6384514f5e3Sopenharmony_ci            scene = mid_str.split()[2]
6394514f5e3Sopenharmony_ci            exec_time = str_array[2]
6404514f5e3Sopenharmony_ci            key_str = '/'.join([js_name + '.js', scene]).lower()
6414514f5e3Sopenharmony_ci            if key_str not in data:
6424514f5e3Sopenharmony_ci                data[key_str] = float(exec_time)
6434514f5e3Sopenharmony_ci            else:
6444514f5e3Sopenharmony_ci                data[key_str] += float(exec_time)
6454514f5e3Sopenharmony_ci    return data
6464514f5e3Sopenharmony_ci
6474514f5e3Sopenharmony_ci
6484514f5e3Sopenharmony_cidef get_v_8_cmd(parameter: str, js_file_path: str) -> List[str]:
6494514f5e3Sopenharmony_ci    """Get command for v 8"""
6504514f5e3Sopenharmony_ci    cmd: List[str] = []
6514514f5e3Sopenharmony_ci    if Constants.VER_PLATFORM.find("arm64") != -1:
6524514f5e3Sopenharmony_ci        cmd = [Constants.HDC_PATH, "shell"]
6534514f5e3Sopenharmony_ci    if len(Constants.TASKSET_MASK) != 0:
6544514f5e3Sopenharmony_ci        cmd += ["taskset", "-a", Constants.TASKSET_MASK]
6554514f5e3Sopenharmony_ci    if len(parameter) == 0:
6564514f5e3Sopenharmony_ci        cmd += [Constants.V_8_ENGINED_PATH, js_file_path]
6574514f5e3Sopenharmony_ci    else:
6584514f5e3Sopenharmony_ci        cmd += [Constants.V_8_ENGINED_PATH, parameter, js_file_path]
6594514f5e3Sopenharmony_ci    return cmd
6604514f5e3Sopenharmony_ci
6614514f5e3Sopenharmony_ci
6624514f5e3Sopenharmony_cidef run_v_8_single_js_case(js_file_path, cmd_para, js_case_name, iterations: int):
6634514f5e3Sopenharmony_ci    """Run single js case for v 8 based with parameters"""
6644514f5e3Sopenharmony_ci    v_8_exec_time_dict = {}
6654514f5e3Sopenharmony_ci    scenes = get_js_file_class_api_scenes(js_file_path)
6664514f5e3Sopenharmony_ci
6674514f5e3Sopenharmony_ci    v_8_log_path = os.path.join(Constants.CUR_PATH, "v_8.log")
6684514f5e3Sopenharmony_ci
6694514f5e3Sopenharmony_ci    flags = os.O_WRONLY | os.O_CREAT | os.O_EXCL
6704514f5e3Sopenharmony_ci    modes = stat.S_IWUSR | stat.S_IRUSR
6714514f5e3Sopenharmony_ci    used_js_file = js_file_path
6724514f5e3Sopenharmony_ci
6734514f5e3Sopenharmony_ci    if Constants.VER_PLATFORM.find("arm64") != -1:
6744514f5e3Sopenharmony_ci        js_file_path_device = os.path.join(Constants.DEVICE_WORKDIR,
6754514f5e3Sopenharmony_ci                                           os.path.basename(js_case_name + '.js'))
6764514f5e3Sopenharmony_ci        used_js_file = js_file_path_device
6774514f5e3Sopenharmony_ci        if hdc_send(js_file_path, js_file_path_device) != 0:
6784514f5e3Sopenharmony_ci            for elem in enumerate(scenes):
6794514f5e3Sopenharmony_ci                v_8_exec_time_dict[elem] = 0
6804514f5e3Sopenharmony_ci            logger.error("Couldn't send file %s to device", js_file_path)
6814514f5e3Sopenharmony_ci            return v_8_exec_time_dict
6824514f5e3Sopenharmony_ci
6834514f5e3Sopenharmony_ci    cmd = get_v_8_cmd(cmd_para, used_js_file)
6844514f5e3Sopenharmony_ci    logger.info("run cmd:%s", cmd)
6854514f5e3Sopenharmony_ci    data = {}
6864514f5e3Sopenharmony_ci    for _ in range(iterations):
6874514f5e3Sopenharmony_ci        if os.path.exists(v_8_log_path):
6884514f5e3Sopenharmony_ci            os.remove(v_8_log_path)
6894514f5e3Sopenharmony_ci        with os.fdopen(os.open(v_8_log_path, flags, modes), 'wb') as outfile:
6904514f5e3Sopenharmony_ci            ret = subprocess.run(cmd, stdout=outfile, check=False)
6914514f5e3Sopenharmony_ci        if ret.returncode != 0:
6924514f5e3Sopenharmony_ci            for elem in enumerate(scenes):
6934514f5e3Sopenharmony_ci                v_8_exec_time_dict[elem] = 0
6944514f5e3Sopenharmony_ci            logger.error("execute cmd failed. cmd: %s", cmd)
6954514f5e3Sopenharmony_ci            return v_8_exec_time_dict
6964514f5e3Sopenharmony_ci        data = update_data_by_log(data, v_8_log_path, js_case_name)
6974514f5e3Sopenharmony_ci        os.remove(v_8_log_path)
6984514f5e3Sopenharmony_ci
6994514f5e3Sopenharmony_ci    for k, time_value in data.items():
7004514f5e3Sopenharmony_ci        v_8_exec_time_dict[k] = str(time_value / iterations)
7014514f5e3Sopenharmony_ci    logger.info("v 8 excute %s successfully. cmd: %s", js_file_path, cmd)
7024514f5e3Sopenharmony_ci    return v_8_exec_time_dict
7034514f5e3Sopenharmony_ci
7044514f5e3Sopenharmony_ci
7054514f5e3Sopenharmony_cidef get_given_column_data(report_file, column_index):
7064514f5e3Sopenharmony_ci    column_data = {}
7074514f5e3Sopenharmony_ci    if os.path.exists(report_file) and report_file.endswith('.xlsx'):
7084514f5e3Sopenharmony_ci        wb = load_workbook(report_file)
7094514f5e3Sopenharmony_ci        ws = wb.worksheets[0]
7104514f5e3Sopenharmony_ci
7114514f5e3Sopenharmony_ci        for row_num in range(2, ws.max_row + 1):
7124514f5e3Sopenharmony_ci            js_case_name = str(ws.cell(row=row_num, column=1).value)
7134514f5e3Sopenharmony_ci            scene = str(ws.cell(row=row_num, column=2).value)
7144514f5e3Sopenharmony_ci            exec_status = str(ws.cell(row=row_num, column=3).value)
7154514f5e3Sopenharmony_ci            time = str(ws.cell(row=row_num, column=column_index).value)
7164514f5e3Sopenharmony_ci            if exec_status == Constants.PASS or exec_status == Constants.FAIL:
7174514f5e3Sopenharmony_ci                main_key = '/'.join([js_case_name, scene])
7184514f5e3Sopenharmony_ci                column_data[main_key] = time
7194514f5e3Sopenharmony_ci
7204514f5e3Sopenharmony_ci    return column_data
7214514f5e3Sopenharmony_ci
7224514f5e3Sopenharmony_ci
7234514f5e3Sopenharmony_cidef get_v_8_excute_times(jspath, v_8_based_report_file, iterations):
7244514f5e3Sopenharmony_ci    if os.path.exists(v_8_based_report_file) and os.path.isfile(v_8_based_report_file):
7254514f5e3Sopenharmony_ci        # Generate v 8 benchmark data on the 1st, 11th, and 21st of each month.The testing at other times refers to
7264514f5e3Sopenharmony_ci        # these V 8 benchmark data
7274514f5e3Sopenharmony_ci        v_8_exec_time_dict = get_given_column_data(v_8_based_report_file, 7)
7284514f5e3Sopenharmony_ci        for key in v_8_exec_time_dict.keys():
7294514f5e3Sopenharmony_ci            Constants.V_8_EXCUTE_TIME_DICT[key] = v_8_exec_time_dict[key]
7304514f5e3Sopenharmony_ci        return Constants.RET_OK
7314514f5e3Sopenharmony_ci
7324514f5e3Sopenharmony_ci    file_list = []
7334514f5e3Sopenharmony_ci    for root, _, files in os.walk(jspath):
7344514f5e3Sopenharmony_ci        for file in files:
7354514f5e3Sopenharmony_ci            if not file.endswith('.js'):
7364514f5e3Sopenharmony_ci                continue
7374514f5e3Sopenharmony_ci            file_path = os.path.join(root, file)
7384514f5e3Sopenharmony_ci            file_list.append(file_path)
7394514f5e3Sopenharmony_ci    for _, file_path in enumerate(file_list):
7404514f5e3Sopenharmony_ci        results = file_path.split("/")
7414514f5e3Sopenharmony_ci        class_name = results[-2]
7424514f5e3Sopenharmony_ci        api_name = results[-1].split(".")[0]
7434514f5e3Sopenharmony_ci        js_case_name = '/'.join([class_name, api_name])
7444514f5e3Sopenharmony_ci
7454514f5e3Sopenharmony_ci        v_8_exec_time_dict = run_v_8_single_js_case(file_path, '', js_case_name, iterations)
7464514f5e3Sopenharmony_ci        for key in v_8_exec_time_dict.keys():
7474514f5e3Sopenharmony_ci            Constants.V_8_EXCUTE_TIME_DICT[key] = v_8_exec_time_dict[key]
7484514f5e3Sopenharmony_ci
7494514f5e3Sopenharmony_ci    return Constants.RET_OK
7504514f5e3Sopenharmony_ci
7514514f5e3Sopenharmony_ci
7524514f5e3Sopenharmony_cidef get_v_8_jitless_excute_times(jspath, v_8_based_report_file_path, iterations):
7534514f5e3Sopenharmony_ci    if os.path.exists(v_8_based_report_file_path) and os.path.isfile(v_8_based_report_file_path):
7544514f5e3Sopenharmony_ci        # Generate v 8 benchmark data on the 1st, 11th, and 21st of each month.The testing at other times refers to
7554514f5e3Sopenharmony_ci        # these V 8 benchmark data
7564514f5e3Sopenharmony_ci        v_8_exec_time_dict = get_given_column_data(v_8_based_report_file_path, 8)
7574514f5e3Sopenharmony_ci        for key in v_8_exec_time_dict.keys():
7584514f5e3Sopenharmony_ci            Constants.V_8_JITLESS_EXCUTE_TIME_DICT[key] = v_8_exec_time_dict[key]
7594514f5e3Sopenharmony_ci        return Constants.RET_OK
7604514f5e3Sopenharmony_ci
7614514f5e3Sopenharmony_ci    file_list = []
7624514f5e3Sopenharmony_ci    for root, _, files in os.walk(jspath):
7634514f5e3Sopenharmony_ci        for file in files:
7644514f5e3Sopenharmony_ci            if not file.endswith('.js'):
7654514f5e3Sopenharmony_ci                continue
7664514f5e3Sopenharmony_ci            file_path = os.path.join(root, file)
7674514f5e3Sopenharmony_ci            file_list.append(file_path)
7684514f5e3Sopenharmony_ci
7694514f5e3Sopenharmony_ci    for _, file_path in enumerate(file_list):
7704514f5e3Sopenharmony_ci        results = file_path.split("/")
7714514f5e3Sopenharmony_ci        class_name = results[-2]
7724514f5e3Sopenharmony_ci        api_name = results[-1].split(".")[0]
7734514f5e3Sopenharmony_ci        js_case_name = '/'.join([class_name, api_name])
7744514f5e3Sopenharmony_ci
7754514f5e3Sopenharmony_ci        v_8_exec_time_dict = run_v_8_single_js_case(file_path, '--jitless', js_case_name, iterations)
7764514f5e3Sopenharmony_ci        for key in v_8_exec_time_dict.keys():
7774514f5e3Sopenharmony_ci            Constants.V_8_JITLESS_EXCUTE_TIME_DICT[key] = v_8_exec_time_dict[key]
7784514f5e3Sopenharmony_ci
7794514f5e3Sopenharmony_ci    return Constants.RET_OK
7804514f5e3Sopenharmony_ci
7814514f5e3Sopenharmony_ci
7824514f5e3Sopenharmony_cidef hdc_send(source: str, destination: str) -> int:
7834514f5e3Sopenharmony_ci    """Run hdc send command"""
7844514f5e3Sopenharmony_ci    hdc_cmd: List[str] = [Constants.HDC_PATH, "file", "send"]
7854514f5e3Sopenharmony_ci    hdc_cmd += [source, destination]
7864514f5e3Sopenharmony_ci    logger.info("run cmd: %s", hdc_cmd)
7874514f5e3Sopenharmony_ci    return subprocess.run(hdc_cmd, check=False).returncode
7884514f5e3Sopenharmony_ci
7894514f5e3Sopenharmony_ci
7904514f5e3Sopenharmony_cidef hdc_run(cmd: List[str]) -> int:
7914514f5e3Sopenharmony_ci    """Run command on device via hdc shell"""
7924514f5e3Sopenharmony_ci    hdc_cmd = [Constants.HDC_PATH, "shell"] + cmd
7934514f5e3Sopenharmony_ci    return subprocess.run(hdc_cmd).returncode
7944514f5e3Sopenharmony_ci
7954514f5e3Sopenharmony_ci
7964514f5e3Sopenharmony_cidef prepare_device():
7974514f5e3Sopenharmony_ci    """Preapare device workdir for js perf testing"""
7984514f5e3Sopenharmony_ci    if hdc_send(Constants.ARK_JS_VM_PATH, Constants.DEVICE_WORKDIR) != 0:
7994514f5e3Sopenharmony_ci        logger.error("Couldn't send ark_js_vm to device")
8004514f5e3Sopenharmony_ci        sys.exit(1)
8014514f5e3Sopenharmony_ci    hdc_run(["chmod", "u+x", os.path.join(Constants.DEVICE_WORKDIR, "ark_js_vm")])
8024514f5e3Sopenharmony_ci    arkjsvm_lib = os.path.join(Constants.ETS_RUNTIME, "libark_jsruntime.so")
8034514f5e3Sopenharmony_ci    if hdc_send(arkjsvm_lib, os.path.join(Constants.DEVICE_WORKDIR, "lib")) != 0:
8044514f5e3Sopenharmony_ci        logger.error("Couldn't send libark_jsruntime.so to device")
8054514f5e3Sopenharmony_ci        sys.exit(1)
8064514f5e3Sopenharmony_ci    if hdc_send(ICU_DATA_PATH, Constants.DEVICE_WORKDIR) != 0:
8074514f5e3Sopenharmony_ci        logger.error("Couldn't send icu data to device")
8084514f5e3Sopenharmony_ci        sys.exit(1)
8094514f5e3Sopenharmony_ci    thirdparty_path = os.path.join(Constants.DEVICE_WORKDIR, "thirdparty")
8104514f5e3Sopenharmony_ci    for lib in Constants.LIBS_LIST:
8114514f5e3Sopenharmony_ci        if not os.path.isdir(lib):
8124514f5e3Sopenharmony_ci            logger.error("Couldn't find lib from config %s", lib)
8134514f5e3Sopenharmony_ci            sys.exit(1)
8144514f5e3Sopenharmony_ci        if hdc_send(lib, thirdparty_path) != 0:
8154514f5e3Sopenharmony_ci            logger.error("Couldn't send %s lib to device", lib)
8164514f5e3Sopenharmony_ci            sys.exit(1)
8174514f5e3Sopenharmony_ci    if hdc_send(Constants.STUB_AN, os.path.join(Constants.DEVICE_WORKDIR, "lib")) != 0:
8184514f5e3Sopenharmony_ci        logger.error("Couldn't send %s file to device", Constants.STUB_AN)
8194514f5e3Sopenharmony_ci        sys.exit(1)
8204514f5e3Sopenharmony_ci
8214514f5e3Sopenharmony_ci
8224514f5e3Sopenharmony_cidef get_config(parameters: argparse.Namespace):
8234514f5e3Sopenharmony_ci    """Get config from arguments and json file"""
8244514f5e3Sopenharmony_ci    Constants.V_8_ENGINED_PATH = parameters.d_8_binary_path
8254514f5e3Sopenharmony_ci    Constants.VER_PLATFORM = parameters.ver_platform
8264514f5e3Sopenharmony_ci    Constants.HDC_PATH = parameters.hdc
8274514f5e3Sopenharmony_ci    Constants.TASKSET_MASK = parameters.taskset
8284514f5e3Sopenharmony_ci    with open(parameters.config, 'r', encoding='UTF-8') as f:
8294514f5e3Sopenharmony_ci        json_data = json.load(f)
8304514f5e3Sopenharmony_ci
8314514f5e3Sopenharmony_ci    Constants.ES2ABC_PATH = os.path.join(BINARY_PATH, json_data[Constants.VER_PLATFORM]["ES2ABC"])
8324514f5e3Sopenharmony_ci    Constants.ETS_RUNTIME = os.path.join(BINARY_PATH,
8334514f5e3Sopenharmony_ci                                    json_data[Constants.VER_PLATFORM]["ETS_RUNTIME_PATH"])
8344514f5e3Sopenharmony_ci    Constants.ARK_JS_VM_PATH = os.path.join(Constants.ETS_RUNTIME, "ark_js_vm")
8354514f5e3Sopenharmony_ci    Constants.STUB_AN = os.path.join(BINARY_PATH, json_data[Constants.VER_PLATFORM]["STUB_AN"])
8364514f5e3Sopenharmony_ci    libs = json_data[Constants.VER_PLATFORM]["LIBS_LIST"]
8374514f5e3Sopenharmony_ci    for lib in libs:
8384514f5e3Sopenharmony_ci        Constants.LIBS_LIST.append(os.path.normpath(os.path.join(BINARY_PATH, lib)))
8394514f5e3Sopenharmony_ci    if Constants.VER_PLATFORM.find("x86_64") != -1:
8404514f5e3Sopenharmony_ci        old_ld_library_path = os.environ.get('LD_LIBRARY_PATH', '')
8414514f5e3Sopenharmony_ci        Constants.LD_LIBRARY_PATH = Constants.ETS_RUNTIME + ":"
8424514f5e3Sopenharmony_ci        if len(Constants.LIBS_LIST) != 0:
8434514f5e3Sopenharmony_ci            Constants.LD_LIBRARY_PATH += ":".join(Constants.LIBS_LIST)
8444514f5e3Sopenharmony_ci        if len(old_ld_library_path) != 0:
8454514f5e3Sopenharmony_ci            Constants.LD_LIBRARY_PATH += f":{old_ld_library_path}"
8464514f5e3Sopenharmony_ci        os.environ['LD_LIBRARY_PATH'] = Constants.LD_LIBRARY_PATH
8474514f5e3Sopenharmony_ci    elif Constants.VER_PLATFORM.find("arm64") != -1:
8484514f5e3Sopenharmony_ci        Constants.LD_LIBRARY_PATH = os.path.join(Constants.DEVICE_WORKDIR, "lib")
8494514f5e3Sopenharmony_ci        for lib in Constants.LIBS_LIST:
8504514f5e3Sopenharmony_ci            lib = os.path.normpath(lib)
8514514f5e3Sopenharmony_ci            Constants.LD_LIBRARY_PATH += ":" +\
8524514f5e3Sopenharmony_ci                os.path.join(Constants.DEVICE_WORKDIR, "thirdparty", os.path.basename(lib))
8534514f5e3Sopenharmony_ci
8544514f5e3Sopenharmony_ci
8554514f5e3Sopenharmony_ciif __name__ == "__main__":
8564514f5e3Sopenharmony_ci    LOG_PATH = os.path.join(Constants.TMP_PATH, "test.log")
8574514f5e3Sopenharmony_ci    if os.path.exists(LOG_PATH):
8584514f5e3Sopenharmony_ci        os.remove(LOG_PATH)
8594514f5e3Sopenharmony_ci    logger = get_logger("jstest", LOG_PATH)
8604514f5e3Sopenharmony_ci
8614514f5e3Sopenharmony_ci    paras = get_args()
8624514f5e3Sopenharmony_ci    logger.info("execute arguments: %s", paras)
8634514f5e3Sopenharmony_ci
8644514f5e3Sopenharmony_ci    DETERIORATION_BOUNDARY_VALUE = paras.deterioration_boundary_value
8654514f5e3Sopenharmony_ci    BINARY_PATH = paras.binarypath
8664514f5e3Sopenharmony_ci    ICU_DATA_PATH = os.path.join(BINARY_PATH, "third_party/icu/ohos_icu4j/data")
8674514f5e3Sopenharmony_ci    OUTPUT_PATH = Constants.CUR_PATH
8684514f5e3Sopenharmony_ci    get_config(paras)
8694514f5e3Sopenharmony_ci    if not os.path.exists(Constants.ARK_JS_VM_PATH):
8704514f5e3Sopenharmony_ci        logger.error("%s does not exist", Constants.ARK_JS_VM_PATH)
8714514f5e3Sopenharmony_ci        sys.exit(1)
8724514f5e3Sopenharmony_ci    if Constants.VER_PLATFORM.find("arm64") != -1:
8734514f5e3Sopenharmony_ci        prepare_device()
8744514f5e3Sopenharmony_ci
8754514f5e3Sopenharmony_ci    if paras.output_folder_path is not None:
8764514f5e3Sopenharmony_ci        OUTPUT_PATH = paras.output_folder_path
8774514f5e3Sopenharmony_ci
8784514f5e3Sopenharmony_ci    if not os.path.exists(OUTPUT_PATH):
8794514f5e3Sopenharmony_ci        os.makedirs(OUTPUT_PATH)
8804514f5e3Sopenharmony_ci
8814514f5e3Sopenharmony_ci    today = datetime.date.today()
8824514f5e3Sopenharmony_ci    yesterday = today - datetime.timedelta(days=1)
8834514f5e3Sopenharmony_ci    TODAY_EXCEL_PATH = get_given_date_report_path(today)
8844514f5e3Sopenharmony_ci    YESTERDAY_EXCEL_PATH = get_given_date_report_path(yesterday)
8854514f5e3Sopenharmony_ci
8864514f5e3Sopenharmony_ci    if os.path.exists(TODAY_EXCEL_PATH):
8874514f5e3Sopenharmony_ci        os.remove(TODAY_EXCEL_PATH)
8884514f5e3Sopenharmony_ci
8894514f5e3Sopenharmony_ci    get_js_case_super_link_data(paras.jspath)
8904514f5e3Sopenharmony_ci    start_time = datetime.datetime.now(tz=datetime.timezone.utc)
8914514f5e3Sopenharmony_ci    init_report(TODAY_EXCEL_PATH)
8924514f5e3Sopenharmony_ci    get_yesterday_excute_times(YESTERDAY_EXCEL_PATH)
8934514f5e3Sopenharmony_ci    v_8_based_report_path = get_v_8_benchmark_daily_report_path()
8944514f5e3Sopenharmony_ci    get_v_8_excute_times(paras.jspath, v_8_based_report_path, paras.iterations)
8954514f5e3Sopenharmony_ci    get_v_8_jitless_excute_times(paras.jspath, v_8_based_report_path, paras.iterations)
8964514f5e3Sopenharmony_ci
8974514f5e3Sopenharmony_ci    run_via_ark(paras.jspath, TODAY_EXCEL_PATH, paras.iterations)
8984514f5e3Sopenharmony_ci    end_time = datetime.datetime.now(tz=datetime.timezone.utc)
8994514f5e3Sopenharmony_ci
9004514f5e3Sopenharmony_ci    totol_time = u"%s" % (end_time - start_time)
9014514f5e3Sopenharmony_ci    append_summary_info(TODAY_EXCEL_PATH, totol_time)
9024514f5e3Sopenharmony_ci
9034514f5e3Sopenharmony_ci    logger.info("run js perf test finished. Please check details in report.")
9044514f5e3Sopenharmony_ci    shutil.rmtree(Constants.TMP_PATH)
905