1#!/usr/bin/env python3 2# coding=utf-8 3 4# 5# Copyright (c) 2022 Huawei Device Co., Ltd. 6# Licensed under the Apache License, Version 2.0 (the "License"); 7# you may not use this file except in compliance with the License. 8# You may obtain a copy of the License at 9# 10# http://www.apache.org/licenses/LICENSE-2.0 11# 12# Unless required by applicable law or agreed to in writing, software 13# distributed under the License is distributed on an "AS IS" BASIS, 14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15# See the License for the specific language governing permissions and 16# limitations under the License. 17# 18 19# 执行如下命令 获取到的信息 20# show subsystemlist 通过show subsystemlist得到子系统名称列表 21# show partlist 通过show partlist得到对应子系统下的部件名 22 23import sys 24import os 25 26from core.constants import ToolCommandType 27from core.utils import get_file_list 28from core.utils import get_file_list_by_postfix 29from core.utils import get_build_output_path 30from core.utils import scan_support_product 31from core.config.config_manager import UserConfigManager 32from core.config.config_manager import FrameworkConfigManager 33from core.config.parse_parts_config import ParsePartsConfig 34 35# 支持的设备名称 36# 1. ohos-sdk 37# 2. rk3568 38# 3. Hi3516DV300 39# 4. DAYU 40# 5. ohos-arm64 41# 6. ipcamera_hispark_aries 42# 7. ipcamera_hispark_taurus 43# 8. wifiiot_hispark_pegasus 44CMD_KEY_PRODUCTLIST = "productlist" 45 46# 测试用例类型 47# 1. UT 48# 2. ACTS 49# 3. HATS 50# 4. MST 51# 5. ST 52# 6. PERF 53# 7. SEC 54# 8. FUZZ 55# 9. RELI 56# 10. DST 57# 11. BENCHMARK 58# 12. ALL 59CMD_KEY_TYPELIST = "typelist" 60 61# 子系统名称列表 62CMD_KEY_SUBSYSTEMLIST = "subsystemlist" 63 64# 子系统下的部件名 65CMD_KEY_PARTLIST = "partlist" 66 67# acts子系统名称列表 68CMD_KEY_SUBSYSTEMLIST_ACTS = "actssubsystemlist" 69 70# hats子系统名称列表 71CMD_KEY_SUBSYSTEMLIST_HATS = "hatssubsystemlist" 72 73TOOL_VERSION_INFO = """Welcome to developer_test V3.2.2.0 74""" 75 76HLEP_COMMAND_INFOMATION = """use help [follow command] for more information: 77 """ + \ 78 "show: " + """Display a list of supported show command. 79 """ + \ 80 "run: " + """Display a list of supported run command. 81 """ + \ 82 "list: " + """Display a list of supported device. 83 """ + \ 84 "quit: " + """Exit the test framework application. 85""" 86 87SUPPORT_COMMAND_SHOW = """use show [follow command] for more information: 88 """ + \ 89 "productlist" + """ 90 """ + \ 91 "typelist" + """ 92 """ + \ 93 "subsystemlist" + """ 94 """ + \ 95 "partlist" + """ 96""" 97 98RUNCASES_INFOMATION = """run: 99 This command is used to execute the selected testcases. 100 It includes a series of processes such as use case compilation, \ 101execution, and result collection. 102 103usage: run [-p PRODUCTFORM] 104 [-t [TESTTYPE [TESTTYPE ...]]] 105 [-ss [SUBSYSTEM [SUBSYSTEM ...]]] 106 [-tp [TESTPART [TESTPART ...]]] 107 [-ts TESTSUIT] 108 [-tc TESTCASE] 109 [-tl TESTLEVEL] 110 [-repeat NUMBER] 111 [-hl] 112 [-rh HISCOMMAND-INDEX] 113 [-retry] 114 115optional arguments: 116 -p PRODUCTFORM, --productform PRODUCTFORM 117 Specified product form 118 -t [TESTTYPE [TESTTYPE ...]], --testtype [TESTTYPE [TESTTYPE ...]] 119 Specify test type(UT,MST,ST,PERF,ALL) 120 -ss [SUBSYSTEM [SUBSYSTEM ...]], --subsystem [SUBSYSTEM [SUBSYSTEM ...]] 121 Specify test subsystem 122 -tp [TESTPART [TESTPART ...]], --testpart [TESTPART [TESTPART ...]] 123 Specify test testpart 124 -ts TESTSUIT, --testsuit TESTSUIT 125 Specify test suit 126 -tc TESTCASE, --testcase TESTCASE 127 Specify test case 128 -tl TESTLEVEL, --testlevel TESTLEVEL 129 --repeat NUMBER 130 -hl, --hisotrylist 131 -rh INDEX, --runhistory INDEX 132 --retry 133 134Examples: 135 run -t UT 136 run -t UT -ss aafwk 137 run -t UT -ss aafwk -tm base_test 138 run -t UT -ss aafwk -tm base_test -ts base_test 139 run -t UT -ss aafwk -tm base_test -ts base_test -tl 2 140 run -t UT -ss aafwk -tm base_test -ts base_test -tc \ 141AAFwkBaseTest.* 142 run -t UT -ss aafwk -tm base_test -ts base_test -tc \ 143AAFwkBaseTest.object_test_001 144 run -t UT -ss aafwk -tm base_test --repeat 3 145 run -t MST 146 ... 147 run -t ALL 148 ... 149 run -hl 150 run -rh 1 151 run --retry 152 run -t ACTS -ss arkui,ability -ts ActsAceEtsTest;ActsAceEtsStTest;ActsApiTest 153""" 154 155LIST_INFOMATION = "list\n" + """ 156 This command is used to display device list. 157""" 158 159QUIT_INFOMATION = "quit\n" + """ 160 This command is used to exit the test framework application. 161""" 162 163 164############################################################################# 165############################################################################# 166 167def select_user_input(data_list): 168 data_item_count = len(data_list) 169 select_item_value = "" 170 select_item_index = -1 171 172 if len(data_list) != 0: 173 count = 0 174 while True: 175 input_data = input("") 176 if "" != input_data and input_data.isdigit(): 177 input_num = int(input_data) 178 if input_num > 0 and (input_num <= data_item_count): 179 select_item_index = input_num - 1 180 select_item_value = data_list[input_num - 1] 181 break 182 else: 183 print("The data you entered is out of range, \ 184 please re-enter:") 185 count += 1 186 else: 187 if "" == input_data: 188 select_item_index = 0 189 select_item_value = data_list[0] 190 break 191 else: 192 print("You entered a non-numeric character, \ 193 please re-enter:") 194 count += 1 195 196 if count >= 3: 197 print("You entered the error three times in a row, \ 198 exit the frame.") 199 quit() 200 sys.exit(0) 201 return select_item_value, select_item_index 202 203 204# 选择productform 205def select_productform(): 206 select_value = "phone" 207 208 # 列表注释 scan_support_product() = [DAYU,Hi3516,ohos_arm64,ohos_sdk,rk3568] 209 scan_product_list = scan_support_product() 210 211 # 从framework_config.xml里取productform节点的value:ipcamera_hispark_aries、ipcamera_hispark_taurus、wifiiot_hispark_pegasus 212 config_product_list = \ 213 FrameworkConfigManager().get_framework_config("productform") 214 215 # 列表注释 productform_list = [DAYU,Hi3516,ohos_arm64,ohos_sdk,rk3568, 216 # 列表注释 ipcamera_hispark_aries、ipcamera_hispark_taurus、wifiiot_hispark_pegasus] 217 218 productform_list = scan_product_list + config_product_list 219 if len(productform_list) != 0: 220 print("Please select the current tested product form:") 221 for index, element in enumerate(productform_list): 222 print("%d. %s" % (index + 1, element)) 223 print("default is [1] %s" % productform_list[0]) 224 select_value, _ = select_user_input(productform_list) 225 print(select_value) 226 return select_value 227 228 229def show_wizard_mode(): 230 wizard_data_dic = {} 231 print("+++++++++++++++++++++++++++++++++++++++++++++") 232 233 productform = select_productform() 234 if productform == "": 235 productform = "phone" 236 wizard_data_dic["productform"] = productform 237 238 print("+++++++++++++++++++++++++++++++++++++++++++++") 239 print("The environment is ready, please use the run command to test.") 240 return wizard_data_dic 241 242 243############################################################################# 244############################################################################# 245 246def display_help_info(para_list): 247 if len(para_list) == 0 or para_list[0] != ToolCommandType.TOOLCMD_KEY_HELP: 248 print("This command is not support.") 249 return 250 251 if len(para_list) > 1: 252 display_help_command_info(para_list[1]) 253 else: 254 print(TOOL_VERSION_INFO) 255 print(HLEP_COMMAND_INFOMATION) 256 257 258def display_show_info(para_list, productform): 259 if len(para_list) == 0 or para_list[0] != ToolCommandType.TOOLCMD_KEY_SHOW: 260 print("This command is not support.") 261 return 262 263 if len(para_list) > 1: 264 display_show_command_info(para_list[1], productform) 265 else: 266 print(SUPPORT_COMMAND_SHOW) 267 268 269def display_version_info(para_list): 270 print(TOOL_VERSION_INFO) 271 272 273############################################################################# 274############################################################################# 275 276 277############################################################################# 278############################################################################# 279 280 281def show_product_list(): 282 print("List of currently supported productform:") 283 scan_product_list = scan_support_product() 284 config_product_list = \ 285 FrameworkConfigManager().get_framework_config("productform") 286 productform_list = scan_product_list + config_product_list 287 if 0 != len(productform_list): 288 for index, element in enumerate(productform_list): 289 print(" %d. %s" % (index + 1, element)) 290 else: 291 print("No category specified.") 292 293 294def show_testtype_list(): 295 print("List of currently supported test types:") 296 testtype_list = FrameworkConfigManager().get_framework_config( 297 "test_category") 298 if 0 != len(testtype_list): 299 for index, element in enumerate(testtype_list): 300 print(" %d. %s" % (index + 1, element)) 301 else: 302 print("No category specified.") 303 304 305# 从OpenHarmony/out/rk3568/build_configs/infos_for_testfwk.json里的subsystem_infos中subsystem_infos下获取subsystemlist 306def show_subsystem_list(product_form): 307 print("List of currently supported subsystem names:") 308 parser = ParsePartsConfig(product_form) 309 subsystem_name_list = parser.get_subsystem_name_list() 310 if len(subsystem_name_list) == 0: 311 return 312 313 subsystem_name_list.sort() 314 for index, element in enumerate(subsystem_name_list): 315 print(" %d. %s" % (index + 1, element)) 316 317 318def show_acts_subsystem_list(): 319 print("List of currently supported acts subsystem names:") 320 sub_list = ['global', 'security', 'useriam', 'multimedia', 'appexecfwk', 'account', 'communication', 'notification', 321 'ability', 'miscservices', 'powermgr', 'startup', 'sensor', 'distributeddatamgr', 'update', 'graphic', 322 'arkui', 323 'storage', 'compileruntime', 'usb', 'multimodalinput', 'resourceschedule', 324 'telephony', 'hiviewdfx', 'location', 'barrierfree', 'customization'] 325 sub_list.sort() 326 for index, element in enumerate(sub_list): 327 print(" %d. %s" % (index + 1, element.strip())) 328 329 330KEY = '"${HATS_ROOT}/' 331 332 333def get_hats_subsystem(path): 334 ret = [] 335 with open(path) as file_desc: 336 all_lines = file_desc.readlines() 337 for line in all_lines: 338 line_t = line.strip() 339 if line_t.startswith(KEY): 340 ret.append(line_t[len(KEY):line_t.find(':')]) 341 return ret 342 343 344def show_hats_subsystem_list(): 345 print("List of currently supported hats subsystem names:") 346 path = os.path.join(sys.source_code_root_path, 347 "test", 348 "xts", 349 "hats", 350 "test_packages.gni") 351 sub_list = get_hats_subsystem(path) 352 sub_list.sort() 353 for index, element in enumerate(sub_list): 354 print(" %d. %s" % (index + 1, element.strip())) 355 print("end") 356 357 358# 从OpenHarmony/out/rk3568/build_configs/infos_for_testfwk.json里的subsystem_infos中subsystem_infos下获取partlist 359def show_partname_list(product_form): 360 print("List of currently supported part names:") 361 parser = ParsePartsConfig(product_form) 362 subsystem_name_list = parser.get_subsystem_name_list() 363 364 if len(subsystem_name_list) == 0: 365 return 366 367 subsystem_name_list.sort() 368 subsystem_infos = parser.get_subsystem_infos() 369 for subsystem in subsystem_name_list: 370 print("%s:" % subsystem) 371 part_name_list = subsystem_infos[subsystem] 372 part_name_list.sort() 373 for index, element in enumerate(part_name_list): 374 print(" %d. %s" % (index + 1, element)) 375 376 377def display_help_command_info(command): 378 if command == ToolCommandType.TOOLCMD_KEY_SHOW: 379 print(SUPPORT_COMMAND_SHOW) 380 elif command == ToolCommandType.TOOLCMD_KEY_RUN: 381 print(RUNCASES_INFOMATION) 382 elif command == ToolCommandType.TOOLCMD_KEY_LIST: 383 print(LIST_INFOMATION) 384 elif command == ToolCommandType.TOOLCMD_KEY_QUIT: 385 print(QUIT_INFOMATION) 386 else: 387 print("'%s' command no help information." % command) 388 389 390def display_show_command_info(command, product_form="phone"): 391 if command == CMD_KEY_PRODUCTLIST: 392 show_product_list() 393 elif command == CMD_KEY_TYPELIST: 394 show_testtype_list() 395 elif command == CMD_KEY_SUBSYSTEMLIST: 396 show_subsystem_list(product_form) 397 elif command == CMD_KEY_PARTLIST: 398 show_partname_list(product_form) 399 elif command == CMD_KEY_SUBSYSTEMLIST_ACTS: 400 show_acts_subsystem_list() 401 elif command == CMD_KEY_SUBSYSTEMLIST_HATS: 402 show_hats_subsystem_list() 403 else: 404 print("This command is not support.") 405 406############################################################################# 407############################################################################# 408