13f085823Sopenharmony_ci#!/usr/bin/env python3 23f085823Sopenharmony_ci# coding=utf-8 33f085823Sopenharmony_ci 43f085823Sopenharmony_ci# 53f085823Sopenharmony_ci# Copyright (c) 2022 Huawei Device Co., Ltd. 63f085823Sopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License"); 73f085823Sopenharmony_ci# you may not use this file except in compliance with the License. 83f085823Sopenharmony_ci# You may obtain a copy of the License at 93f085823Sopenharmony_ci# 103f085823Sopenharmony_ci# http://www.apache.org/licenses/LICENSE-2.0 113f085823Sopenharmony_ci# 123f085823Sopenharmony_ci# Unless required by applicable law or agreed to in writing, software 133f085823Sopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS, 143f085823Sopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 153f085823Sopenharmony_ci# See the License for the specific language governing permissions and 163f085823Sopenharmony_ci# limitations under the License. 173f085823Sopenharmony_ci# 183f085823Sopenharmony_ci 193f085823Sopenharmony_ci 203f085823Sopenharmony_cidef _init_global_config(): 213f085823Sopenharmony_ci import sys 223f085823Sopenharmony_ci import os 233f085823Sopenharmony_ci 243f085823Sopenharmony_ci # insert src path for loading xdevice modules 253f085823Sopenharmony_ci # 当前脚本运行的绝对路径 去掉最后两个路径 263f085823Sopenharmony_ci # 变量注释 framework_src_dir = OpenHarmony/test/developer_test 273f085823Sopenharmony_ci sys.framework_src_dir = os.path.abspath(os.path.dirname( 283f085823Sopenharmony_ci os.path.dirname(__file__))) 293f085823Sopenharmony_ci 303f085823Sopenharmony_ci # 将目录存放到sys.path模块中,新添加的目录会优先于其他目录被import检查 0代表最高优先级 313f085823Sopenharmony_ci sys.path.insert(0, sys.framework_src_dir) 323f085823Sopenharmony_ci 333f085823Sopenharmony_ci # 当前脚本运行的绝对路径 去掉最后两个路径 343f085823Sopenharmony_ci # 变量注释 framework_root_dir = OpenHarmony/test/developer_test 353f085823Sopenharmony_ci sys.framework_root_dir = os.path.abspath(os.path.dirname( 363f085823Sopenharmony_ci os.path.dirname(os.path.dirname(__file__)))) 373f085823Sopenharmony_ci 383f085823Sopenharmony_ci # 变量注释 sys.xdevice_dir = OpenHarmony/test/xdevice/src 393f085823Sopenharmony_ci sys.xdevice_dir = os.path.abspath(os.path.join( 403f085823Sopenharmony_ci sys.framework_root_dir, 413f085823Sopenharmony_ci "..", 423f085823Sopenharmony_ci "xdevice", 433f085823Sopenharmony_ci "src")) 443f085823Sopenharmony_ci sys.path.insert(0, sys.xdevice_dir) 453f085823Sopenharmony_ci 463f085823Sopenharmony_ci # 变量注释 sys.xdevice_extension_dir = OpenHarmony/xdevice/plugins/ohos/src 473f085823Sopenharmony_ci sys.xdevice_extension_dir = os.path.abspath(os.path.join( 483f085823Sopenharmony_ci sys.framework_root_dir, 493f085823Sopenharmony_ci "..", 503f085823Sopenharmony_ci "xdevice", 513f085823Sopenharmony_ci "plugins", 523f085823Sopenharmony_ci "ohos", 533f085823Sopenharmony_ci "src")) 543f085823Sopenharmony_ci sys.path.insert(1, sys.xdevice_extension_dir) 553f085823Sopenharmony_ci 563f085823Sopenharmony_ci # 变量注释 pytest_dir = OpenHarmony/test/developer_test/aw/python 573f085823Sopenharmony_ci sys.pytest_dir = os.path.abspath(os.path.join( 583f085823Sopenharmony_ci sys.framework_root_dir, 593f085823Sopenharmony_ci "aw", 603f085823Sopenharmony_ci "python")) 613f085823Sopenharmony_ci sys.path.insert(2, sys.pytest_dir) 623f085823Sopenharmony_ci 633f085823Sopenharmony_ci # 变量注释 adapter_dir = OpenHarmony/test/developer_test/adapter/aw/python 643f085823Sopenharmony_ci sys.adapter_dir = os.path.abspath(os.path.join( 653f085823Sopenharmony_ci sys.framework_root_dir, 663f085823Sopenharmony_ci "adapter" 673f085823Sopenharmony_ci "aw", 683f085823Sopenharmony_ci "python")) 693f085823Sopenharmony_ci sys.path.insert(3, sys.adapter_dir) 703f085823Sopenharmony_ci 713f085823Sopenharmony_ci # 变量注释 hmh_script = OpenHarmony/test/developer_test/libs 723f085823Sopenharmony_ci sys.hmh_script = os.path.abspath(os.path.join( 733f085823Sopenharmony_ci sys.framework_root_dir, 743f085823Sopenharmony_ci "libs")) 753f085823Sopenharmony_ci sys.path.insert(4, sys.hmh_script) 763f085823Sopenharmony_ci 773f085823Sopenharmony_ci # 变量注释 framework_res_dir = OpenHarmony/test/developer_test 783f085823Sopenharmony_ci sys.framework_res_dir = sys.framework_root_dir 793f085823Sopenharmony_ci 803f085823Sopenharmony_ci # 变量注释 exec_dir = OpenHarmony/test/developer_test 813f085823Sopenharmony_ci sys.exec_dir = sys.framework_root_dir 823f085823Sopenharmony_ci 833f085823Sopenharmony_ci from core.common import get_source_code_root_path 843f085823Sopenharmony_ci sys.source_code_root_path = get_source_code_root_path( 853f085823Sopenharmony_ci sys.framework_root_dir) 863f085823Sopenharmony_ci 873f085823Sopenharmony_ci # python的参数配置 设置脚本路径 调度python的xdevice 883f085823Sopenharmony_ci from xdevice import Variables 893f085823Sopenharmony_ci Variables.exec_dir = sys.framework_root_dir 903f085823Sopenharmony_ci 913f085823Sopenharmony_ci 923f085823Sopenharmony_cidef _iter_module_plugins(packages): 933f085823Sopenharmony_ci import importlib 943f085823Sopenharmony_ci import pkgutil 953f085823Sopenharmony_ci for package in packages: 963f085823Sopenharmony_ci 973f085823Sopenharmony_ci # 获取__path__对象属性的值,若不存在,默认为“” 983f085823Sopenharmony_ci pkg_path = getattr(package, "__path__", "") 993f085823Sopenharmony_ci pkg_name = getattr(package, "__name__", "") 1003f085823Sopenharmony_ci if not pkg_name or not pkg_path: 1013f085823Sopenharmony_ci continue 1023f085823Sopenharmony_ci _iter_modules = pkgutil.iter_modules(pkg_path, "%s%s" % ( 1033f085823Sopenharmony_ci pkg_name, ".")) 1043f085823Sopenharmony_ci for _, name, _ in _iter_modules: 1053f085823Sopenharmony_ci importlib.import_module(name) 1063f085823Sopenharmony_ci 1073f085823Sopenharmony_ci 1083f085823Sopenharmony_cidef _load_internal_plugins(): 1093f085823Sopenharmony_ci try: 1103f085823Sopenharmony_ci import ohos.environment 1113f085823Sopenharmony_ci _iter_module_plugins([ohos.environment]) 1123f085823Sopenharmony_ci import ohos.testkit 1133f085823Sopenharmony_ci _iter_module_plugins([ohos.testkit]) 1143f085823Sopenharmony_ci import ohos.managers 1153f085823Sopenharmony_ci _iter_module_plugins([ohos.managers]) 1163f085823Sopenharmony_ci import ohos.parser 1173f085823Sopenharmony_ci _iter_module_plugins([ohos.parser]) 1183f085823Sopenharmony_ci import ohos.drivers 1193f085823Sopenharmony_ci _iter_module_plugins([ohos.drivers]) 1203f085823Sopenharmony_ci 1213f085823Sopenharmony_ci import core.driver 1223f085823Sopenharmony_ci import benchmark.report.benchmark_reporter 1233f085823Sopenharmony_ci _iter_module_plugins([core.driver, benchmark.report.benchmark_reporter]) 1243f085823Sopenharmony_ci 1253f085823Sopenharmony_ci except ImportError: 1263f085823Sopenharmony_ci pass 1273f085823Sopenharmony_ci 1283f085823Sopenharmony_ci try: 1293f085823Sopenharmony_ci import script.report 1303f085823Sopenharmony_ci _iter_module_plugins([script.report]) 1313f085823Sopenharmony_ci except ImportError: 1323f085823Sopenharmony_ci pass 1333f085823Sopenharmony_ci 1343f085823Sopenharmony_ci 1353f085823Sopenharmony_ci_init_global_config() 1363f085823Sopenharmony_cidel _init_global_config 1373f085823Sopenharmony_ci 1383f085823Sopenharmony_ci_load_internal_plugins() 1393f085823Sopenharmony_cidel _load_internal_plugins 140