14514f5e3Sopenharmony_ci#!/usr/bin/env python3 24514f5e3Sopenharmony_ci# -*- coding: utf-8 -*- 34514f5e3Sopenharmony_ci 44514f5e3Sopenharmony_ci""" 54514f5e3Sopenharmony_ciCopyright (c) 2021 Huawei Device Co., Ltd. 64514f5e3Sopenharmony_ciLicensed under the Apache License, Version 2.0 (the "License"); 74514f5e3Sopenharmony_ciyou may not use this file except in compliance with the License. 84514f5e3Sopenharmony_ciYou may obtain a copy of the License at 94514f5e3Sopenharmony_ci 104514f5e3Sopenharmony_ci http://www.apache.org/licenses/LICENSE-2.0 114514f5e3Sopenharmony_ci 124514f5e3Sopenharmony_ciUnless required by applicable law or agreed to in writing, software 134514f5e3Sopenharmony_cidistributed under the License is distributed on an "AS IS" BASIS, 144514f5e3Sopenharmony_ciWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 154514f5e3Sopenharmony_ciSee the License for the specific language governing permissions and 164514f5e3Sopenharmony_cilimitations under the License. 174514f5e3Sopenharmony_ci 184514f5e3Sopenharmony_ciDescription: Use ark to execute ts/js files 194514f5e3Sopenharmony_ci""" 204514f5e3Sopenharmony_ci 214514f5e3Sopenharmony_ciimport os 224514f5e3Sopenharmony_ciimport sys 234514f5e3Sopenharmony_ciimport re 244514f5e3Sopenharmony_ciimport glob 254514f5e3Sopenharmony_ciimport argparse 264514f5e3Sopenharmony_ciimport subprocess 274514f5e3Sopenharmony_ciimport signal 284514f5e3Sopenharmony_ciimport time 294514f5e3Sopenharmony_ciimport json 304514f5e3Sopenharmony_ci 314514f5e3Sopenharmony_ciDEFAULT_TIMEOUT = 300 324514f5e3Sopenharmony_ciDEFAULT_PGO_THRESHOLD = 10 334514f5e3Sopenharmony_ciTARGET_PLATFORM = ['x64', 'arm64'] 344514f5e3Sopenharmony_ciPRODUCT_LIST = ['hispark_taurus', 'rk3568', 'baltimore'] 354514f5e3Sopenharmony_ciTARGET_PRODUCT_MAP = {'x64': 0, 'arm64': 1} 364514f5e3Sopenharmony_ci 374514f5e3Sopenharmony_cidef parse_args(): 384514f5e3Sopenharmony_ci parser = argparse.ArgumentParser() 394514f5e3Sopenharmony_ci parser.add_argument('name', metavar='file|path', type=str, help='test case name: file or path') 404514f5e3Sopenharmony_ci parser.add_argument('-a', '--all', action='store_true', help='run all test cases on path') 414514f5e3Sopenharmony_ci parser.add_argument('-p', '--product', metavar='name', 424514f5e3Sopenharmony_ci help='product name, default is hispark_taurus on x64, rk3568 on arm64, baltimore on arm64') 434514f5e3Sopenharmony_ci parser.add_argument('-t', '--tool', metavar='opt', 444514f5e3Sopenharmony_ci help='run tool supported opt: aot, int(c interpreter tool), asmint(asm interpreter tool), node(v8), qjs, hermes') 454514f5e3Sopenharmony_ci parser.add_argument('-f', '--frontend', metavar='opt', 464514f5e3Sopenharmony_ci help='run frontend supported opt: ts2abc (slow), es2abc (quick not released)') 474514f5e3Sopenharmony_ci parser.add_argument('-s', '--step', metavar='opt', 484514f5e3Sopenharmony_ci help='run step supported opt: abc, pack, aot, aotd, run, rund, asmint, asmintd, int, intd') 494514f5e3Sopenharmony_ci parser.add_argument('-d', '--debug', action='store_true', help='run on debug mode') 504514f5e3Sopenharmony_ci parser.add_argument('--arm64', action='store_true', help='run on arm64 platform') 514514f5e3Sopenharmony_ci parser.add_argument('--device', action='store_true', help='run on device') 524514f5e3Sopenharmony_ci parser.add_argument('--copy-path', metavar='path', help='copy bins to device') 534514f5e3Sopenharmony_ci parser.add_argument('-m', '--module', action='store_true', help='frontend compile with module') 544514f5e3Sopenharmony_ci parser.add_argument('--frontend-args', metavar='args', help='pass to frontend args') 554514f5e3Sopenharmony_ci parser.add_argument('--aot-args', metavar='args', help='pass to aot compiler args') 564514f5e3Sopenharmony_ci parser.add_argument('--jsvm-args', metavar='args', help='pass to jsvm args') 574514f5e3Sopenharmony_ci parser.add_argument('-i', '--info', action='store_true', help='add log level of info to args') 584514f5e3Sopenharmony_ci parser.add_argument('-c', '--clean', action='store_true', help='clean output files') 594514f5e3Sopenharmony_ci parser.add_argument('--npm', action='store_true', help='npm install') 604514f5e3Sopenharmony_ci parser.add_argument('--bt', dest='builtin', action='store_true', help='aot compile with lib_ark_builtins.d.ts') 614514f5e3Sopenharmony_ci parser.add_argument('--pgo', action='store_true', 624514f5e3Sopenharmony_ci help=f'aot compile with pgo, default threshold is {DEFAULT_PGO_THRESHOLD}') 634514f5e3Sopenharmony_ci parser.add_argument('--pgo-th', metavar='n', default=DEFAULT_PGO_THRESHOLD, type=int, 644514f5e3Sopenharmony_ci help=f'pgo hotness threshold, default is {DEFAULT_PGO_THRESHOLD}') 654514f5e3Sopenharmony_ci parser.add_argument('--sign', metavar='name', 664514f5e3Sopenharmony_ci help='sign level, default is system_core, other is normal, system_basic') 674514f5e3Sopenharmony_ci parser.add_argument('--timeout', metavar='n', default=DEFAULT_TIMEOUT, type=int, 684514f5e3Sopenharmony_ci help=f'specify seconds of test timeout, default is {DEFAULT_TIMEOUT}') 694514f5e3Sopenharmony_ci parser.add_argument('-e', '--env', action='store_true', help='print LD_LIBRARY_PATH') 704514f5e3Sopenharmony_ci arguments = parser.parse_args() 714514f5e3Sopenharmony_ci return arguments 724514f5e3Sopenharmony_ci 734514f5e3Sopenharmony_cidef run_and_print(cmd): 744514f5e3Sopenharmony_ci print(cmd) 754514f5e3Sopenharmony_ci os.system(cmd) 764514f5e3Sopenharmony_ci 774514f5e3Sopenharmony_cidef run_command(cmd, timeout=DEFAULT_TIMEOUT): 784514f5e3Sopenharmony_ci proc = subprocess.Popen(cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=True) 794514f5e3Sopenharmony_ci code_format = 'UTF-8' 804514f5e3Sopenharmony_ci try: 814514f5e3Sopenharmony_ci (msg, errs) = proc.communicate(timeout=timeout) 824514f5e3Sopenharmony_ci ret_code = proc.poll() 834514f5e3Sopenharmony_ci if errs: 844514f5e3Sopenharmony_ci ret_code = 2 854514f5e3Sopenharmony_ci except subprocess.TimeoutExpired: 864514f5e3Sopenharmony_ci proc.kill() 874514f5e3Sopenharmony_ci proc.terminate() 884514f5e3Sopenharmony_ci os.kill(proc.pid, signal.SIGTERM) 894514f5e3Sopenharmony_ci return (1, '', f'exec command timeout {timeout}s') 904514f5e3Sopenharmony_ci return (ret_code, msg.decode(code_format), errs.decode(code_format)) 914514f5e3Sopenharmony_ci 924514f5e3Sopenharmony_cidef match_list_name(list, name): 934514f5e3Sopenharmony_ci for str in list: 944514f5e3Sopenharmony_ci found = str.find(name) 954514f5e3Sopenharmony_ci if (found == 0): 964514f5e3Sopenharmony_ci return str 974514f5e3Sopenharmony_ci return '' 984514f5e3Sopenharmony_ci 994514f5e3Sopenharmony_cidef get_module_name(hap_dir): 1004514f5e3Sopenharmony_ci with open(f'{hap_dir}/module.json') as f: 1014514f5e3Sopenharmony_ci data = json.load(f) 1024514f5e3Sopenharmony_ci if len(data): 1034514f5e3Sopenharmony_ci return data['module']['name'] 1044514f5e3Sopenharmony_ci else: 1054514f5e3Sopenharmony_ci return 'entry' 1064514f5e3Sopenharmony_ci 1074514f5e3Sopenharmony_cidef get_bundle_name(hap_dir): 1084514f5e3Sopenharmony_ci with open(f'{hap_dir}/module.json') as f: 1094514f5e3Sopenharmony_ci data = json.load(f) 1104514f5e3Sopenharmony_ci if len(data): 1114514f5e3Sopenharmony_ci return data['app']['bundleName'] 1124514f5e3Sopenharmony_ci else: 1134514f5e3Sopenharmony_ci return 'entry' 1144514f5e3Sopenharmony_ci 1154514f5e3Sopenharmony_ciclass ArkTest(): 1164514f5e3Sopenharmony_ci def __init__(self, args): 1174514f5e3Sopenharmony_ci self.args = args 1184514f5e3Sopenharmony_ci self.self_dir = os.path.abspath(sys.argv[0]) 1194514f5e3Sopenharmony_ci self.hap_abc = 'ets/modules.abc' 1204514f5e3Sopenharmony_ci self.place_dir = 'arkcompiler/ets_runtime/test' 1214514f5e3Sopenharmony_ci if not args.device and self.self_dir.find(self.place_dir) < 0: 1224514f5e3Sopenharmony_ci print(f'pls place this script at: {self.place_dir}') 1234514f5e3Sopenharmony_ci sys.exit(1) 1244514f5e3Sopenharmony_ci 1254514f5e3Sopenharmony_ci self.ohdir = os.path.abspath(f'{self.self_dir}/../../../..') 1264514f5e3Sopenharmony_ci self.product = PRODUCT_LIST[TARGET_PRODUCT_MAP['x64']] 1274514f5e3Sopenharmony_ci self.builtin = '' 1284514f5e3Sopenharmony_ci self.arm64 = False 1294514f5e3Sopenharmony_ci if args.step == 'hap': 1304514f5e3Sopenharmony_ci self.arm64 = True 1314514f5e3Sopenharmony_ci if args.arm64: 1324514f5e3Sopenharmony_ci self.product = PRODUCT_LIST[TARGET_PRODUCT_MAP['arm64']] 1334514f5e3Sopenharmony_ci self.arm64 = True 1344514f5e3Sopenharmony_ci if args.product: 1354514f5e3Sopenharmony_ci self.product = match_list_name(PRODUCT_LIST, args.product) 1364514f5e3Sopenharmony_ci self.step = 'all' 1374514f5e3Sopenharmony_ci if args.step: 1384514f5e3Sopenharmony_ci self.step = args.step 1394514f5e3Sopenharmony_ci if args.clean: 1404514f5e3Sopenharmony_ci self.step = 'clean' 1414514f5e3Sopenharmony_ci self.expect = 'expect_output.txt' 1424514f5e3Sopenharmony_ci search_type_list = ['.ts', '.js', '.abc'] 1434514f5e3Sopenharmony_ci self.types = {'all': ['.ts', '.js'], 1444514f5e3Sopenharmony_ci 'abc': ['.ts', '.js'], 1454514f5e3Sopenharmony_ci 'pack': ['.an'], 1464514f5e3Sopenharmony_ci 'aot': search_type_list, 1474514f5e3Sopenharmony_ci 'aotd': search_type_list, 1484514f5e3Sopenharmony_ci 'run': search_type_list, 1494514f5e3Sopenharmony_ci 'rund': search_type_list, 1504514f5e3Sopenharmony_ci 'asmint': search_type_list, 1514514f5e3Sopenharmony_ci 'asmintd': search_type_list, 1524514f5e3Sopenharmony_ci 'int': search_type_list, 1534514f5e3Sopenharmony_ci 'intd': search_type_list, 1544514f5e3Sopenharmony_ci 'clean': search_type_list} 1554514f5e3Sopenharmony_ci 1564514f5e3Sopenharmony_ci product_dir = f'{self.ohdir}/out/{self.product}' 1574514f5e3Sopenharmony_ci libs_dir_x64_release = (f'{self.ohdir}/prebuilts/clang/ohos/linux-x86_64/llvm/lib:' 1584514f5e3Sopenharmony_ci f'{product_dir}/clang_x64/arkcompiler/ets_runtime:' 1594514f5e3Sopenharmony_ci f'{product_dir}/clang_x64/thirdparty/icu:' 1604514f5e3Sopenharmony_ci f'{product_dir}/clang_x64/thirdparty/zlib') 1614514f5e3Sopenharmony_ci libs_dir_x64_debug = (f'{self.ohdir}/prebuilts/clang/ohos/linux-x86_64/llvm/lib:' 1624514f5e3Sopenharmony_ci f'{product_dir}/clang_x64/exe.unstripped/clang_x64/arkcompiler/ets_runtime:' 1634514f5e3Sopenharmony_ci f'{product_dir}/clang_x64/lib.unstripped/clang_x64/arkcompiler/ets_runtime:' 1644514f5e3Sopenharmony_ci f'{product_dir}/clang_x64/lib.unstripped/clang_x64/test/test:' 1654514f5e3Sopenharmony_ci f'{product_dir}/clang_x64/lib.unstripped/clang_x64/thirdparty/icu:' 1664514f5e3Sopenharmony_ci f'{product_dir}/clang_x64/lib.unstripped/clang_x64/thirdparty/zlib') 1674514f5e3Sopenharmony_ci libs_dir_arm64_release = (f'{self.ohdir}/prebuilts/clang/ohos/linux-x86_64/llvm/lib/aarch64-linux-ohos/c++/:' 1684514f5e3Sopenharmony_ci f'{product_dir}/arkcompiler/ets_runtime/:' 1694514f5e3Sopenharmony_ci f'{product_dir}/utils/utils_base/:' 1704514f5e3Sopenharmony_ci f'{product_dir}/thirdparty/icu:' 1714514f5e3Sopenharmony_ci f'{product_dir}/thirdparty/zlib:' 1724514f5e3Sopenharmony_ci f'{product_dir}/common/dsoftbus/:' 1734514f5e3Sopenharmony_ci f'{product_dir}/commonlibrary/c_utils:' 1744514f5e3Sopenharmony_ci f'{product_dir}/systemabilitymgr/samgr:' 1754514f5e3Sopenharmony_ci f'{product_dir}/hiviewdfx/hisysevent_native:' 1764514f5e3Sopenharmony_ci f'{product_dir}/common/common:' 1774514f5e3Sopenharmony_ci f'{product_dir}/securec/thirdparty_bounds_checking_function:' 1784514f5e3Sopenharmony_ci f'{product_dir}/hiviewdfx/faultloggerd:' 1794514f5e3Sopenharmony_ci f'{product_dir}/thirdparty/bounds_checking_function:' 1804514f5e3Sopenharmony_ci f'{product_dir}/hiviewdfx/hilog_native:' 1814514f5e3Sopenharmony_ci f'{product_dir}/startup/init:' 1824514f5e3Sopenharmony_ci f'{product_dir}/thirdparty/cjson:' 1834514f5e3Sopenharmony_ci f'{product_dir}/lib.unstripped/common/dsoftbus:' 1844514f5e3Sopenharmony_ci f'{product_dir}/security/selinux:' 1854514f5e3Sopenharmony_ci f'{product_dir}/hiviewdfx/hitrace_native/:' 1864514f5e3Sopenharmony_ci f'{product_dir}/communication/ipc/:' 1874514f5e3Sopenharmony_ci f'{product_dir}/distributedschedule/samgr_standard:' 1884514f5e3Sopenharmony_ci f'{product_dir}/security/access_token:' 1894514f5e3Sopenharmony_ci f'{product_dir}/communication/dsoftbus:' 1904514f5e3Sopenharmony_ci f'{product_dir}/startup/startup_l2/:' 1914514f5e3Sopenharmony_ci f'{product_dir}/security/huks/:' 1924514f5e3Sopenharmony_ci f'{product_dir}/clang_x64/thirdparty/icu:' 1934514f5e3Sopenharmony_ci f'{product_dir}/clang_x64/thirdparty/zlib:' 1944514f5e3Sopenharmony_ci f'{product_dir}/clang_x64/arkcompiler/ets_runtime') 1954514f5e3Sopenharmony_ci libs_dir_arm64_debug = (f'{self.ohdir}/prebuilts/clang/ohos/linux-x86_64/llvm/lib/aarch64-linux-ohos/c++/:' 1964514f5e3Sopenharmony_ci f'{product_dir}/lib.unstripped/arkcompiler/ets_runtime/:' 1974514f5e3Sopenharmony_ci f'{product_dir}/utils/utils_base/:' 1984514f5e3Sopenharmony_ci f'{product_dir}/thirdparty/icu:' 1994514f5e3Sopenharmony_ci f'{product_dir}/thirdparty/zlib:' 2004514f5e3Sopenharmony_ci f'{product_dir}/common/dsoftbus/:' 2014514f5e3Sopenharmony_ci f'{product_dir}/commonlibrary/c_utils:' 2024514f5e3Sopenharmony_ci f'{product_dir}/systemabilitymgr/samgr:' 2034514f5e3Sopenharmony_ci f'{product_dir}/hiviewdfx/hisysevent_native:' 2044514f5e3Sopenharmony_ci f'{product_dir}/common/common:' 2054514f5e3Sopenharmony_ci f'{product_dir}/securec/thirdparty_bounds_checking_function:' 2064514f5e3Sopenharmony_ci f'{product_dir}/hiviewdfx/faultloggerd:' 2074514f5e3Sopenharmony_ci f'{product_dir}/thirdparty/bounds_checking_function:' 2084514f5e3Sopenharmony_ci f'{product_dir}/hiviewdfx/hilog_native:' 2094514f5e3Sopenharmony_ci f'{product_dir}/startup/init:' 2104514f5e3Sopenharmony_ci f'{product_dir}/thirdparty/cjson:' 2114514f5e3Sopenharmony_ci f'{product_dir}/security/selinux:' 2124514f5e3Sopenharmony_ci f'{product_dir}/hiviewdfx/hitrace_native/:' 2134514f5e3Sopenharmony_ci f'{product_dir}/communication/ipc/:' 2144514f5e3Sopenharmony_ci f'{product_dir}/distributedschedule/samgr_standard:' 2154514f5e3Sopenharmony_ci f'{product_dir}/security/access_token:' 2164514f5e3Sopenharmony_ci f'{product_dir}/communication/dsoftbus:' 2174514f5e3Sopenharmony_ci f'{product_dir}/startup/startup_l2/:' 2184514f5e3Sopenharmony_ci f'{product_dir}/security/huks/:' 2194514f5e3Sopenharmony_ci f'{product_dir}/clang_x64/thirdparty/icu/:' 2204514f5e3Sopenharmony_ci f'{product_dir}/clang_x64/thirdparty/zlib/:' 2214514f5e3Sopenharmony_ci f'{product_dir}/clang_x64/arkcompiler/ets_runtime') 2224514f5e3Sopenharmony_ci libs_dir = [[libs_dir_x64_release, libs_dir_x64_debug], [libs_dir_arm64_release, libs_dir_arm64_debug]] 2234514f5e3Sopenharmony_ci bins_dir = [['clang_x64/arkcompiler', 'clang_x64/exe.unstripped/clang_x64/arkcompiler'], 2244514f5e3Sopenharmony_ci ['arkcompiler', 'exe.unstripped/arkcompiler']] 2254514f5e3Sopenharmony_ci icu_arg = f'--icu-data-path={self.ohdir}/third_party/icu/ohos_icu4j/data' 2264514f5e3Sopenharmony_ci self.libs_dir = libs_dir[self.arm64][args.debug] 2274514f5e3Sopenharmony_ci self.compiler = f'{product_dir}/{bins_dir[0][args.debug]}/ets_runtime/ark_aot_compiler' 2284514f5e3Sopenharmony_ci self.jsvm = f'{product_dir}/{bins_dir[self.arm64][args.debug]}/ets_runtime/ark_js_vm' 2294514f5e3Sopenharmony_ci self.ts2abc = f'node --expose-gc {product_dir}/clang_x64/arkcompiler/ets_frontend/build/src/index.js' 2304514f5e3Sopenharmony_ci self.es2abc = f'{product_dir}/clang_x64/arkcompiler/ets_frontend/es2abc' 2314514f5e3Sopenharmony_ci self.frontend = self.ts2abc 2324514f5e3Sopenharmony_ci if not args.frontend: 2334514f5e3Sopenharmony_ci args.frontend = 'ts2abc' 2344514f5e3Sopenharmony_ci if args.frontend not in ['ts2abc', 'es2abc']: 2354514f5e3Sopenharmony_ci print(f'not supported frontend: {args.frontend}') 2364514f5e3Sopenharmony_ci sys.exit(1) 2374514f5e3Sopenharmony_ci if args.frontend == 'es2abc': 2384514f5e3Sopenharmony_ci self.frontend = self.es2abc 2394514f5e3Sopenharmony_ci abcmode = {'ts2abc': ['--merge-abc', '--merge-abc -m'], 2404514f5e3Sopenharmony_ci 'es2abc': ['--merge-abc', '--merge-abc --module']} 2414514f5e3Sopenharmony_ci self.abcmode = abcmode[args.frontend][args.module] 2424514f5e3Sopenharmony_ci self.frontend_args = '' 2434514f5e3Sopenharmony_ci self.aot_args = '' 2444514f5e3Sopenharmony_ci self.jsvm_args = icu_arg 2454514f5e3Sopenharmony_ci if args.device: 2464514f5e3Sopenharmony_ci self.jsvm_args = '' 2474514f5e3Sopenharmony_ci if self.builtin: 2484514f5e3Sopenharmony_ci self.aot_args = f'{self.aot_args} --builtins-dts={self.builtin}.abc' 2494514f5e3Sopenharmony_ci self.pgo = False 2504514f5e3Sopenharmony_ci if args.pgo: 2514514f5e3Sopenharmony_ci self.pgo = True 2524514f5e3Sopenharmony_ci self.aot_args = (f'{self.aot_args} --enable-pgo-profiler=true --compiler-pgo-hotness-threshold={args.pgo_th}' 2534514f5e3Sopenharmony_ci f' --compiler-pgo-profiler-path=pgo_file_name.ap') 2544514f5e3Sopenharmony_ci if args.frontend_args: 2554514f5e3Sopenharmony_ci self.frontend_args = f'{self.frontend_args} {args.frontend_args}' 2564514f5e3Sopenharmony_ci if args.aot_args: 2574514f5e3Sopenharmony_ci self.aot_args = f'{self.aot_args} {args.aot_args}' 2584514f5e3Sopenharmony_ci if args.jsvm_args: 2594514f5e3Sopenharmony_ci self.jsvm_args = f'{self.jsvm_args} {args.jsvm_args}' 2604514f5e3Sopenharmony_ci if args.info: 2614514f5e3Sopenharmony_ci self.aot_args = f'{self.aot_args} --log-level=info' 2624514f5e3Sopenharmony_ci self.jsvm_args = f'{self.jsvm_args} --log-level=info' 2634514f5e3Sopenharmony_ci self.runner = '' 2644514f5e3Sopenharmony_ci self.runnerd = 'gdb --args' 2654514f5e3Sopenharmony_ci if self.arm64 or args.device: 2664514f5e3Sopenharmony_ci if self.step[:3] != 'aot': 2674514f5e3Sopenharmony_ci self.runner = 'qemu-aarch64' 2684514f5e3Sopenharmony_ci self.runnerd = 'qemu-aarch64 -cpu max,sve=off -g 123456' 2694514f5e3Sopenharmony_ci self.aot_args = f'{self.aot_args} --compiler-target-triple=aarch64-unknown-linux-gnu' 2704514f5e3Sopenharmony_ci self.test_count = 0 2714514f5e3Sopenharmony_ci self.fail_cases = [] 2724514f5e3Sopenharmony_ci os.environ['LD_LIBRARY_PATH'] = self.libs_dir 2734514f5e3Sopenharmony_ci if args.env: 2744514f5e3Sopenharmony_ci print(f'export LD_LIBRARY_PATH={self.libs_dir}') 2754514f5e3Sopenharmony_ci sys.exit(0) 2764514f5e3Sopenharmony_ci if args.copy_path: 2774514f5e3Sopenharmony_ci run_and_print(f'hdc shell mount -o remount,rw /') 2784514f5e3Sopenharmony_ci run_and_print(f'hdc file send {args.copy_path}\\ark_aot_compiler /system/bin/') 2794514f5e3Sopenharmony_ci run_and_print(f'hdc shell chmod a+x /system/bin/ark_aot_compiler') 2804514f5e3Sopenharmony_ci run_and_print(f'hdc file send {args.copy_path}\\ark_js_vm /system/bin/') 2814514f5e3Sopenharmony_ci run_and_print(f'hdc shell chmod a+x /system/bin/ark_js_vm') 2824514f5e3Sopenharmony_ci sys.exit(0) 2834514f5e3Sopenharmony_ci if args.npm: 2844514f5e3Sopenharmony_ci index_dir = f'{product_dir}/clang_x64/arkcompiler/ets_frontend/build/src' 2854514f5e3Sopenharmony_ci os.system(f'cd {index_dir}/.. && npm install') 2864514f5e3Sopenharmony_ci sys.exit(0) 2874514f5e3Sopenharmony_ci if args.sign: 2884514f5e3Sopenharmony_ci self.sign_hap(self.args.name) 2894514f5e3Sopenharmony_ci sys.exit(0) 2904514f5e3Sopenharmony_ci 2914514f5e3Sopenharmony_ci def run_cmd(self, cmd): 2924514f5e3Sopenharmony_ci print(cmd) 2934514f5e3Sopenharmony_ci ret = run_command(cmd, self.args.timeout) 2944514f5e3Sopenharmony_ci if ret[0]: 2954514f5e3Sopenharmony_ci print(ret[2]) 2964514f5e3Sopenharmony_ci return ret 2974514f5e3Sopenharmony_ci 2984514f5e3Sopenharmony_ci def run_test(self, file): 2994514f5e3Sopenharmony_ci self.test_count += 1 3004514f5e3Sopenharmony_ci basename = os.path.basename(f'{file}') 3014514f5e3Sopenharmony_ci type = os.path.splitext(basename)[-1] 3024514f5e3Sopenharmony_ci name = os.path.splitext(basename)[0] 3034514f5e3Sopenharmony_ci dir = os.path.dirname(file) 3044514f5e3Sopenharmony_ci out_case_dir = f'{dir}' 3054514f5e3Sopenharmony_ci hap_dir = 'null' 3064514f5e3Sopenharmony_ci hap_name = 'null' 3074514f5e3Sopenharmony_ci module_name = 'null' 3084514f5e3Sopenharmony_ci if self.step == 'hap' or self.step == 'pack': 3094514f5e3Sopenharmony_ci hap_dir = os.path.abspath(f'{out_case_dir}/..') 3104514f5e3Sopenharmony_ci hap_name = os.path.basename(hap_dir) 3114514f5e3Sopenharmony_ci module_name = get_module_name(hap_dir) 3124514f5e3Sopenharmony_ci abc_file = f'{os.path.splitext(file)[0]}.abc' 3134514f5e3Sopenharmony_ci if self.pgo: 3144514f5e3Sopenharmony_ci pgo_file = f'{hap_dir}/ap/{module_name}' 3154514f5e3Sopenharmony_ci self.aot_args = self.aot_args.replace('pgo_file_name', pgo_file) 3164514f5e3Sopenharmony_ci cmd_map = { 3174514f5e3Sopenharmony_ci 'node': f'node {self.frontend_args} {file}', 3184514f5e3Sopenharmony_ci 'qjs': f'qjs {self.frontend_args} {file}', 3194514f5e3Sopenharmony_ci 'hermes': f'hermes {self.frontend_args} {file}', 3204514f5e3Sopenharmony_ci 'abc': f'{self.frontend} {self.frontend_args} {self.abcmode} --output {abc_file} {file}', 3214514f5e3Sopenharmony_ci 'pack': [f'mkdir -p {out_case_dir}/../an/arm64-v8a', 3224514f5e3Sopenharmony_ci f'mv {out_case_dir}/{name}.an {hap_dir}/an/arm64-v8a/{module_name}.an', 3234514f5e3Sopenharmony_ci f'mv {out_case_dir}/{name}.ai {hap_dir}/an/arm64-v8a/{module_name}.ai', 3244514f5e3Sopenharmony_ci f'cd {out_case_dir}/.. && rm -f ../{hap_name}.hap && zip -r -q ../{hap_name}.hap *', 3254514f5e3Sopenharmony_ci f'mv {hap_dir}/an/arm64-v8a/{module_name}.an {out_case_dir}/{name}.an', 3264514f5e3Sopenharmony_ci f'mv {hap_dir}/an/arm64-v8a/{module_name}.ai {out_case_dir}/{name}.ai', 3274514f5e3Sopenharmony_ci f'rm -rf {hap_dir}/an'], 3284514f5e3Sopenharmony_ci 'aot': f'{self.compiler} {self.aot_args} --aot-file={out_case_dir}/{name} {abc_file}', 3294514f5e3Sopenharmony_ci 'aotd': f'{self.runnerd} {self.compiler} {self.aot_args} --aot-file={out_case_dir}/{name} {abc_file}', 3304514f5e3Sopenharmony_ci 'run': f'{self.runner} {self.jsvm} {self.jsvm_args} --aot-file={out_case_dir}/{name} --entry-point={name} {abc_file}', 3314514f5e3Sopenharmony_ci 'rund': f'{self.runnerd} {self.jsvm} {self.jsvm_args} --aot-file={out_case_dir}/{name} --entry-point={name} {abc_file}', 3324514f5e3Sopenharmony_ci 'asmint': f'{self.runner} {self.jsvm} {self.jsvm_args} --entry-point={name} {abc_file}', 3334514f5e3Sopenharmony_ci 'asmintd': f'{self.runnerd} {self.jsvm} {self.jsvm_args} --entry-point={name} {abc_file}', 3344514f5e3Sopenharmony_ci 'int': f'{self.runner} {self.jsvm} {self.jsvm_args} --asm-interpreter=0 --entry-point={name} {abc_file}', 3354514f5e3Sopenharmony_ci 'intd': f'{self.runnerd} {self.jsvm} {self.jsvm_args} --asm-interpreter=0 --entry-point={name} {abc_file}', 3364514f5e3Sopenharmony_ci 'clean': f'rm -f {out_case_dir}/{name}.abc {out_case_dir}/{name}.an {out_case_dir}/{name}.ai', 3374514f5e3Sopenharmony_ci 'cleanhap': f'rm -rf {hap_dir}/an {out_case_dir}/{name}.an {out_case_dir}/{name}.ai'} 3384514f5e3Sopenharmony_ci if self.builtin: 3394514f5e3Sopenharmony_ci if self.frontend == self.ts2abc: 3404514f5e3Sopenharmony_ci cmd = f'{self.ts2abc} {self.builtin}.ts -m --merge-abc -q -b' 3414514f5e3Sopenharmony_ci elif self.frontend == self.es2abc: 3424514f5e3Sopenharmony_ci cmd = (f'{self.es2abc} --module --merge-abc --extension=ts ' 3434514f5e3Sopenharmony_ci f'--output={self.builtin}.abc {self.builtin}.ts') 3444514f5e3Sopenharmony_ci print(cmd) 3454514f5e3Sopenharmony_ci os.system(cmd) 3464514f5e3Sopenharmony_ci if self.step == 'hap': 3474514f5e3Sopenharmony_ci self.step = 'aot' 3484514f5e3Sopenharmony_ci perf_start = time.perf_counter() 3494514f5e3Sopenharmony_ci cmd = cmd_map[self.step] 3504514f5e3Sopenharmony_ci print(cmd) 3514514f5e3Sopenharmony_ci os.system(cmd) 3524514f5e3Sopenharmony_ci perf_end = time.perf_counter() 3534514f5e3Sopenharmony_ci abc_size = os.path.getsize(file) / 1024 / 1024 3544514f5e3Sopenharmony_ci an_size = os.path.getsize(f'{out_case_dir}/{name}.an') / 1024 / 1024 3554514f5e3Sopenharmony_ci print(f'test: {file} abc_size: {abc_size: .1f}MB an_size: {an_size:.1f}MB ' 3564514f5e3Sopenharmony_ci f'expand: {an_size / abc_size: .1f} time: {perf_end - perf_start: .1f}s') 3574514f5e3Sopenharmony_ci self.step = 'pack' 3584514f5e3Sopenharmony_ci if self.step == 'pack': 3594514f5e3Sopenharmony_ci for cmd in cmd_map[self.step]: 3604514f5e3Sopenharmony_ci print(cmd) 3614514f5e3Sopenharmony_ci os.system(cmd) 3624514f5e3Sopenharmony_ci print(f'packed hap: {hap_name}.hap') 3634514f5e3Sopenharmony_ci print(f'sign --------------------------------------------') 3644514f5e3Sopenharmony_ci self.sign_hap(f'{hap_name}.hap') 3654514f5e3Sopenharmony_ci return 3664514f5e3Sopenharmony_ci if self.step == 'clean': 3674514f5e3Sopenharmony_ci if os.path.isfile(f'{hap_dir}/{self.hap_abc}'): 3684514f5e3Sopenharmony_ci self.step = 'cleanhap' 3694514f5e3Sopenharmony_ci if self.args.tool == 'node': 3704514f5e3Sopenharmony_ci ret = self.run_cmd(cmd_map['node']) 3714514f5e3Sopenharmony_ci self.judge_test(file, ret) 3724514f5e3Sopenharmony_ci return 3734514f5e3Sopenharmony_ci if self.args.tool == 'qjs': 3744514f5e3Sopenharmony_ci ret = self.run_cmd(cmd_map['qjs']) 3754514f5e3Sopenharmony_ci self.judge_test(file, ret) 3764514f5e3Sopenharmony_ci return 3774514f5e3Sopenharmony_ci if self.args.tool == 'hermes': 3784514f5e3Sopenharmony_ci ret = self.run_cmd(cmd_map['hermes']) 3794514f5e3Sopenharmony_ci self.judge_test(file, ret) 3804514f5e3Sopenharmony_ci return 3814514f5e3Sopenharmony_ci if not self.args.tool: 3824514f5e3Sopenharmony_ci self.args.tool = 'aot' 3834514f5e3Sopenharmony_ci if self.args.tool not in ['aot', 'asmint', 'int']: 3844514f5e3Sopenharmony_ci print(f'not supported tool: {self.args.tool}') 3854514f5e3Sopenharmony_ci sys.exit(1) 3864514f5e3Sopenharmony_ci if self.args.device: 3874514f5e3Sopenharmony_ci ret = self.run_test_on_device(file) 3884514f5e3Sopenharmony_ci return 3894514f5e3Sopenharmony_ci if self.step != 'all': 3904514f5e3Sopenharmony_ci # gdb should use the os.system 3914514f5e3Sopenharmony_ci cmd = cmd_map[self.step] 3924514f5e3Sopenharmony_ci print(cmd) 3934514f5e3Sopenharmony_ci if self.arm64 and self.step[-1:] == 'd' and self.step[:3] != 'aot': 3944514f5e3Sopenharmony_ci print(f'gdb-client start: gdb-multiarch {self.jsvm}') 3954514f5e3Sopenharmony_ci print(f'gdb-server connect: target remote:123456') 3964514f5e3Sopenharmony_ci os.system(cmd) 3974514f5e3Sopenharmony_ci return 3984514f5e3Sopenharmony_ci ret = self.run_cmd(cmd_map['abc']) 3994514f5e3Sopenharmony_ci if ret[0]: 4004514f5e3Sopenharmony_ci self.judge_test(file, ret) 4014514f5e3Sopenharmony_ci return 4024514f5e3Sopenharmony_ci if self.args.tool == 'aot': 4034514f5e3Sopenharmony_ci ret = self.run_cmd(cmd_map['aot']) 4044514f5e3Sopenharmony_ci if ret[0] and ret[2].find('aot compile success') < 0: 4054514f5e3Sopenharmony_ci self.judge_test(file, ret) 4064514f5e3Sopenharmony_ci return 4074514f5e3Sopenharmony_ci ret = self.run_cmd(cmd_map['run']) 4084514f5e3Sopenharmony_ci else: 4094514f5e3Sopenharmony_ci ret = self.run_cmd(cmd_map[self.args.tool]) 4104514f5e3Sopenharmony_ci self.judge_test(file, ret) 4114514f5e3Sopenharmony_ci 4124514f5e3Sopenharmony_ci def run_test_on_device(self, file): 4134514f5e3Sopenharmony_ci basename = os.path.basename(f'{file}') 4144514f5e3Sopenharmony_ci name = os.path.splitext(basename)[0] 4154514f5e3Sopenharmony_ci out_case_dir = '/data/test' 4164514f5e3Sopenharmony_ci send_abc_file = f'{os.path.splitext(file)[0]}.abc'.replace('/', '\\') 4174514f5e3Sopenharmony_ci abc_file = f'{out_case_dir}/{name}.abc' 4184514f5e3Sopenharmony_ci cmd_map = {'abc': f'hdc file send {send_abc_file} {out_case_dir}/', 4194514f5e3Sopenharmony_ci 'aot': f'hdc shell ark_aot_compiler {self.aot_args} --aot-file={out_case_dir}/{name} {abc_file}', 4204514f5e3Sopenharmony_ci 'run': f'hdc shell ark_js_vm {self.jsvm_args} --aot-file={out_case_dir}/{name} --entry-point={name} {abc_file}', 4214514f5e3Sopenharmony_ci 'asmint': f'hdc shell ark_js_vm {self.jsvm_args} --entry-point={name} {abc_file}', 4224514f5e3Sopenharmony_ci 'int': f'hdc shell ark_js_vm {self.jsvm_args} --asm-interpreter=0 --entry-point={name} {abc_file}'} 4234514f5e3Sopenharmony_ci if self.step != 'all': 4244514f5e3Sopenharmony_ci run_and_print(cmd_map[self.step]) 4254514f5e3Sopenharmony_ci return 4264514f5e3Sopenharmony_ci run_and_print(cmd_map['abc']) 4274514f5e3Sopenharmony_ci if self.args.tool == 'aot': 4284514f5e3Sopenharmony_ci ret = self.run_cmd(cmd_map['aot']) 4294514f5e3Sopenharmony_ci if ret[0] and ret[2].find('aot compile success') < 0: 4304514f5e3Sopenharmony_ci self.judge_test(file, ret) 4314514f5e3Sopenharmony_ci return 4324514f5e3Sopenharmony_ci ret = self.run_cmd(cmd_map['run']) 4334514f5e3Sopenharmony_ci else: 4344514f5e3Sopenharmony_ci ret = self.run_cmd(cmd_map[self.args.tool]) 4354514f5e3Sopenharmony_ci self.judge_test(file, ret) 4364514f5e3Sopenharmony_ci 4374514f5e3Sopenharmony_ci def judge_test(self, file, out): 4384514f5e3Sopenharmony_ci if out[0]: 4394514f5e3Sopenharmony_ci self.fail_cases.append(file) 4404514f5e3Sopenharmony_ci print_fail(f'FAIL: {file}') 4414514f5e3Sopenharmony_ci return 4424514f5e3Sopenharmony_ci expect_file = f'{os.path.dirname(file)}/{self.expect}' 4434514f5e3Sopenharmony_ci if os.path.exists(expect_file): 4444514f5e3Sopenharmony_ci with open(expect_file, mode='r') as infile: 4454514f5e3Sopenharmony_ci expect = ''.join(infile.readlines()[13:]) 4464514f5e3Sopenharmony_ci if out[1].replace('\r', '') != expect.replace('\r', ''): 4474514f5e3Sopenharmony_ci self.fail_cases.append(file) 4484514f5e3Sopenharmony_ci print(f'expect: [{expect}]\nbut got: [{out[1]}]') 4494514f5e3Sopenharmony_ci print_fail(f'FAIL: {file}') 4504514f5e3Sopenharmony_ci else: 4514514f5e3Sopenharmony_ci print_pass(f'PASS: {file}') 4524514f5e3Sopenharmony_ci else: 4534514f5e3Sopenharmony_ci print_pass(f'PASS: {file}') 4544514f5e3Sopenharmony_ci print(out[1]) 4554514f5e3Sopenharmony_ci 4564514f5e3Sopenharmony_ci def report_test(self): 4574514f5e3Sopenharmony_ci fail_count = len(self.fail_cases) 4584514f5e3Sopenharmony_ci print(f'Ran tests: {self.test_count}') 4594514f5e3Sopenharmony_ci print(f'Ran failed: {fail_count}') 4604514f5e3Sopenharmony_ci if fail_count == 0: 4614514f5e3Sopenharmony_ci print_pass('================================== All tests Run PASSED!') 4624514f5e3Sopenharmony_ci return 4634514f5e3Sopenharmony_ci print_fail('==================================') 4644514f5e3Sopenharmony_ci for case in self.fail_cases: 4654514f5e3Sopenharmony_ci print(case) 4664514f5e3Sopenharmony_ci print_fail('==================================') 4674514f5e3Sopenharmony_ci 4684514f5e3Sopenharmony_ci def find_file(self, dir, postfix_list): 4694514f5e3Sopenharmony_ci result = [] 4704514f5e3Sopenharmony_ci for root, lists, files in os.walk(dir): 4714514f5e3Sopenharmony_ci for file in files: 4724514f5e3Sopenharmony_ci for postfix in postfix_list: 4734514f5e3Sopenharmony_ci path = os.path.join(root, file) 4744514f5e3Sopenharmony_ci found = path.find(postfix) 4754514f5e3Sopenharmony_ci if found == len(path) - len(postfix): 4764514f5e3Sopenharmony_ci result.append(path) 4774514f5e3Sopenharmony_ci if os.path.isfile(dir): 4784514f5e3Sopenharmony_ci for postfix in postfix_list: 4794514f5e3Sopenharmony_ci found = dir.find(postfix) 4804514f5e3Sopenharmony_ci if found == len(dir) - len(postfix): 4814514f5e3Sopenharmony_ci result.append(dir) 4824514f5e3Sopenharmony_ci break 4834514f5e3Sopenharmony_ci return result 4844514f5e3Sopenharmony_ci 4854514f5e3Sopenharmony_ci def test_hap(self): 4864514f5e3Sopenharmony_ci if self.step != 'all': 4874514f5e3Sopenharmony_ci return 1 4884514f5e3Sopenharmony_ci files = self.find_file(self.args.name, [self.hap_abc, '.hap']) 4894514f5e3Sopenharmony_ci if len(files): 4904514f5e3Sopenharmony_ci self.step = 'hap' 4914514f5e3Sopenharmony_ci file = files[0] 4924514f5e3Sopenharmony_ci type = os.path.splitext(file)[-1] 4934514f5e3Sopenharmony_ci if type == '.hap': 4944514f5e3Sopenharmony_ci hap_dir = f'{os.path.splitext(file)[0]}.aot' 4954514f5e3Sopenharmony_ci os.system(f'mkdir -p {hap_dir} && unzip -o -q {file} -d {hap_dir}') 4964514f5e3Sopenharmony_ci file = f'{hap_dir}/{self.hap_abc}' 4974514f5e3Sopenharmony_ci self.run_test(file) 4984514f5e3Sopenharmony_ci return 0 4994514f5e3Sopenharmony_ci return 1 5004514f5e3Sopenharmony_ci 5014514f5e3Sopenharmony_ci def sign_hap(self, hap_name): 5024514f5e3Sopenharmony_ci name = os.path.splitext(hap_name)[0] 5034514f5e3Sopenharmony_ci sign_dir = f'{name}.sign' 5044514f5e3Sopenharmony_ci sign_tool_dir = f'{self.ohdir}/developtools/hapsigner/dist' 5054514f5e3Sopenharmony_ci name = os.path.splitext(sign_dir)[0] 5064514f5e3Sopenharmony_ci self_dir = os.path.abspath(sys.argv[0]) 5074514f5e3Sopenharmony_ci os.system(f'mkdir -p {sign_dir} && unzip -o -q {hap_name} module.json -d {sign_dir}') 5084514f5e3Sopenharmony_ci bundle_name = get_bundle_name(sign_dir) 5094514f5e3Sopenharmony_ci if not self.args.sign or self.args.sign == 'system_core': 5104514f5e3Sopenharmony_ci bundle_apl = 'system_core' 5114514f5e3Sopenharmony_ci bundle_feature = 'hos_system_app' 5124514f5e3Sopenharmony_ci elif self.args.sign == 'system_basic': 5134514f5e3Sopenharmony_ci bundle_apl = self.args.sign 5144514f5e3Sopenharmony_ci bundle_feature = 'hos_system_app' 5154514f5e3Sopenharmony_ci elif self.args.sign == 'normal': 5164514f5e3Sopenharmony_ci bundle_apl = self.args.sign 5174514f5e3Sopenharmony_ci bundle_feature = 'hos_normal_app' 5184514f5e3Sopenharmony_ci else: 5194514f5e3Sopenharmony_ci print(f'sign not supported input: {self.args.sign}') 5204514f5e3Sopenharmony_ci return 1 5214514f5e3Sopenharmony_ci # modify sign config 5224514f5e3Sopenharmony_ci data_load = [] 5234514f5e3Sopenharmony_ci data_save = [] 5244514f5e3Sopenharmony_ci sign_config = 'UnsgnedReleasedProfileTemplate.json' 5254514f5e3Sopenharmony_ci with open(f'{sign_tool_dir}/{sign_config}') as f: 5264514f5e3Sopenharmony_ci data_load = json.load(f) 5274514f5e3Sopenharmony_ci data_load['bundle-info']['bundle-name'] = bundle_name 5284514f5e3Sopenharmony_ci data_load['bundle-info']['apl'] = bundle_apl 5294514f5e3Sopenharmony_ci data_load['bundle-info']['app-feature'] = bundle_feature 5304514f5e3Sopenharmony_ci data_save = json.dumps(data_load) 5314514f5e3Sopenharmony_ci with open(f'{sign_dir}/{sign_config}', 'w+') as f: 5324514f5e3Sopenharmony_ci f.write(data_save) 5334514f5e3Sopenharmony_ci # generate cert and sign 5344514f5e3Sopenharmony_ci gen_cert = f'java -jar {sign_tool_dir}/hap-sign-tool.jar sign-profile -keyAlias "openharmony application profile release" -signAlg "SHA256withECDSA" -mode "localSign" -profileCertFile "{sign_tool_dir}/OpenHarmonyProfileRelease.pem" -inFile "{sign_dir}/{sign_config}" -keystoreFile "{sign_tool_dir}/OpenHarmony.p12" -outFile "{sign_dir}/openharmony.p7b" -keyPwd "123456" -keystorePwd "123456"' 5354514f5e3Sopenharmony_ci sign_hap = f'java -jar {sign_tool_dir}/hap-sign-tool.jar sign-app -keyAlias "openharmony application release" -signAlg "SHA256withECDSA" -mode "localSign" -appCertFile "{sign_tool_dir}/OpenHarmonyApplication.pem" -profileFile "{sign_dir}/openharmony.p7b" -inFile "{hap_name}" -keystoreFile "{sign_tool_dir}/OpenHarmony.p12" -outFile "{name}.sign.hap" -keyPwd "123456" -keystorePwd "123456"' 5364514f5e3Sopenharmony_ci print(gen_cert) 5374514f5e3Sopenharmony_ci print(sign_hap) 5384514f5e3Sopenharmony_ci os.system(gen_cert) 5394514f5e3Sopenharmony_ci os.system(sign_hap) 5404514f5e3Sopenharmony_ci print(f'signed of {bundle_apl} for hap: {name}.sign.hap') 5414514f5e3Sopenharmony_ci 5424514f5e3Sopenharmony_ci def test(self): 5434514f5e3Sopenharmony_ci # run single test by name 5444514f5e3Sopenharmony_ci files = [] 5454514f5e3Sopenharmony_ci if self.step not in self.types: 5464514f5e3Sopenharmony_ci print(f'not supported step: {self.step}') 5474514f5e3Sopenharmony_ci return 1 5484514f5e3Sopenharmony_ci if not self.args.all: 5494514f5e3Sopenharmony_ci files = self.find_file(self.args.name, self.types[self.step]) 5504514f5e3Sopenharmony_ci if len(files): 5514514f5e3Sopenharmony_ci self.run_test(files[0]) 5524514f5e3Sopenharmony_ci elif self.test_hap(): 5534514f5e3Sopenharmony_ci print(f'only support file type: {self.types[self.step]}') 5544514f5e3Sopenharmony_ci print(f'input path no test case: {self.args.name}') 5554514f5e3Sopenharmony_ci return 1 5564514f5e3Sopenharmony_ci return 0 5574514f5e3Sopenharmony_ci 5584514f5e3Sopenharmony_ci # run all test in path 5594514f5e3Sopenharmony_ci if not os.path.isdir(self.args.name): 5604514f5e3Sopenharmony_ci print(f'input path not exists or is file: {self.args.name}') 5614514f5e3Sopenharmony_ci return 1 5624514f5e3Sopenharmony_ci files = self.find_file(self.args.name, self.types[self.step]) 5634514f5e3Sopenharmony_ci for test in files: 5644514f5e3Sopenharmony_ci self.run_test(test) 5654514f5e3Sopenharmony_ci 5664514f5e3Sopenharmony_ci if len(files) == 0: 5674514f5e3Sopenharmony_ci self.test_hap() 5684514f5e3Sopenharmony_ci 5694514f5e3Sopenharmony_ci if self.step == 'clean': 5704514f5e3Sopenharmony_ci print('clean output files finished') 5714514f5e3Sopenharmony_ci return 0 5724514f5e3Sopenharmony_ci 5734514f5e3Sopenharmony_ci if self.test_count == 0: 5744514f5e3Sopenharmony_ci print(f'input path no test case: {self.args.name}') 5754514f5e3Sopenharmony_ci return 1 5764514f5e3Sopenharmony_ci 5774514f5e3Sopenharmony_ci # output report 5784514f5e3Sopenharmony_ci self.report_test() 5794514f5e3Sopenharmony_ci return 0 5804514f5e3Sopenharmony_ci 5814514f5e3Sopenharmony_cidef print_pass(str): 5824514f5e3Sopenharmony_ci print(f'\033[32;2m{str}\033[0m') 5834514f5e3Sopenharmony_ci sys.stdout.flush() 5844514f5e3Sopenharmony_ci 5854514f5e3Sopenharmony_cidef print_fail(str): 5864514f5e3Sopenharmony_ci print(f'\033[31;2m{str}\033[0m') 5874514f5e3Sopenharmony_ci sys.stdout.flush() 5884514f5e3Sopenharmony_ci 5894514f5e3Sopenharmony_cidef main(): 5904514f5e3Sopenharmony_ci args = parse_args() 5914514f5e3Sopenharmony_ci arktest = ArkTest(args) 5924514f5e3Sopenharmony_ci return arktest.test() 5934514f5e3Sopenharmony_ci 5944514f5e3Sopenharmony_ciif __name__ == '__main__': 5954514f5e3Sopenharmony_ci sys.exit(main()) 596