• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
205# 选择productform
206def select_productform():
207    select_value = "phone"
208
209    # 列表注释 scan_support_product() = [DAYU,Hi3516,ohos_arm64,ohos_sdk,rk3568]
210    scan_product_list = scan_support_product()
211
212    # 从framework_config.xml里取productform节点的value:ipcamera_hispark_aries、ipcamera_hispark_taurus、wifiiot_hispark_pegasus
213    config_product_list = \
214        FrameworkConfigManager().get_framework_config("productform")
215
216    # 列表注释 productform_list = [DAYU,Hi3516,ohos_arm64,ohos_sdk,rk3568,
217    # 列表注释 ipcamera_hispark_aries、ipcamera_hispark_taurus、wifiiot_hispark_pegasus]
218
219    productform_list = scan_product_list + config_product_list
220    if len(productform_list) != 0:
221        print("Please select the current tested product form:")
222        for index, element in enumerate(productform_list):
223            print("%d. %s" % (index + 1, element))
224        print("default is [1] %s" % productform_list[0])
225        select_value, _ = select_user_input(productform_list)
226    print(select_value)
227    return select_value
228
229
230def show_wizard_mode():
231    wizard_data_dic = {}
232    print("+++++++++++++++++++++++++++++++++++++++++++++")
233
234    productform = select_productform()
235    if productform == "":
236        productform = "phone"
237    wizard_data_dic["productform"] = productform
238
239    print("+++++++++++++++++++++++++++++++++++++++++++++")
240    print("The environment is ready, please use the run command to test.")
241    return wizard_data_dic
242
243
244#############################################################################
245#############################################################################
246
247def display_help_info(para_list):
248    if len(para_list) == 0 or para_list[0] != ToolCommandType.TOOLCMD_KEY_HELP:
249        print("This command is not support.")
250        return
251
252    if len(para_list) > 1:
253        display_help_command_info(para_list[1])
254    else:
255        print(TOOL_VERSION_INFO)
256        print(HLEP_COMMAND_INFOMATION)
257
258
259def display_show_info(para_list, productform):
260    if len(para_list) == 0 or para_list[0] != ToolCommandType.TOOLCMD_KEY_SHOW:
261        print("This command is not support.")
262        return
263
264    if len(para_list) > 1:
265        display_show_command_info(para_list[1], productform)
266    else:
267        print(SUPPORT_COMMAND_SHOW)
268
269
270def display_version_info(para_list):
271    print(TOOL_VERSION_INFO)
272
273
274#############################################################################
275#############################################################################
276
277
278#############################################################################
279#############################################################################
280
281
282def show_product_list():
283    print("List of currently supported productform:")
284    scan_product_list = scan_support_product()
285    config_product_list = \
286        FrameworkConfigManager().get_framework_config("productform")
287    productform_list = scan_product_list + config_product_list
288    if 0 != len(productform_list):
289        for index, element in enumerate(productform_list):
290            print("    %d. %s" % (index + 1, element))
291    else:
292        print("No category specified.")
293
294
295def show_testtype_list():
296    print("List of currently supported test types:")
297    testtype_list = FrameworkConfigManager().get_framework_config(
298        "test_category")
299    if 0 != len(testtype_list):
300        for index, element in enumerate(testtype_list):
301            print("    %d. %s" % (index + 1, element))
302    else:
303        print("No category specified.")
304
305
306# 从OpenHarmony/out/rk3568/build_configs/infos_for_testfwk.json里的subsystem_infos中subsystem_infos下获取subsystemlist
307def show_subsystem_list(product_form):
308    print("List of currently supported subsystem names:")
309    parser = ParsePartsConfig(product_form)
310    subsystem_name_list = parser.get_subsystem_name_list()
311    if len(subsystem_name_list) == 0:
312        return
313
314    subsystem_name_list.sort()
315    for index, element in enumerate(subsystem_name_list):
316        print("    %d. %s" % (index + 1, element))
317
318
319def show_acts_subsystem_list():
320    print("List of currently supported acts subsystem names:")
321    sub_list = ['global', 'security', 'useriam', 'multimedia', 'appexecfwk', 'account', 'communication', 'notification',
322                'ability', 'miscservices', 'powermgr', 'startup', 'sensor', 'distributeddatamgr', 'update', 'graphic',
323                'arkui',
324                'storage', 'compileruntime', 'usb', 'multimodalinput', 'resourceschedule',
325                'telephony', 'hiviewdfx', 'location', 'barrierfree', 'customization']
326    sub_list.sort()
327    for index, element in enumerate(sub_list):
328        print("    %d. %s" % (index + 1, element.strip()))
329
330
331KEY = '"${HATS_ROOT}/'
332
333
334def get_hats_subsystem(path):
335    ret = []
336    with open(path) as file_desc:
337        all_lines = file_desc.readlines()
338        for line in all_lines:
339            line_t = line.strip()
340            if line_t.startswith(KEY):
341                ret.append(line_t[len(KEY):line_t.find(':')])
342    return ret
343
344
345def show_hats_subsystem_list():
346    print("List of currently supported hats subsystem names:")
347    path = os.path.join(sys.source_code_root_path,
348                        "test",
349                        "xts",
350                        "hats",
351                        "test_packages.gni")
352    sub_list = get_hats_subsystem(path)
353    sub_list.sort()
354    for index, element in enumerate(sub_list):
355        print("    %d. %s" % (index + 1, element.strip()))
356    print("end")
357
358
359# 从OpenHarmony/out/rk3568/build_configs/infos_for_testfwk.json里的subsystem_infos中subsystem_infos下获取partlist
360def show_partname_list(product_form):
361    print("List of currently supported part names:")
362    parser = ParsePartsConfig(product_form)
363    subsystem_name_list = parser.get_subsystem_name_list()
364
365    if len(subsystem_name_list) == 0:
366        return
367
368    subsystem_name_list.sort()
369    subsystem_infos = parser.get_subsystem_infos()
370    for subsystem in subsystem_name_list:
371        print("%s:" % subsystem)
372        part_name_list = subsystem_infos[subsystem]
373        part_name_list.sort()
374        for index, element in enumerate(part_name_list):
375            print("    %d. %s" % (index + 1, element))
376
377
378def display_help_command_info(command):
379    if command == ToolCommandType.TOOLCMD_KEY_SHOW:
380        print(SUPPORT_COMMAND_SHOW)
381    elif command == ToolCommandType.TOOLCMD_KEY_RUN:
382        print(RUNCASES_INFOMATION)
383    elif command == ToolCommandType.TOOLCMD_KEY_LIST:
384        print(LIST_INFOMATION)
385    elif command == ToolCommandType.TOOLCMD_KEY_QUIT:
386        print(QUIT_INFOMATION)
387    else:
388        print("'%s' command no help information." % command)
389
390
391def display_show_command_info(command, product_form="phone"):
392    if command == CMD_KEY_PRODUCTLIST:
393        show_product_list()
394    elif command == CMD_KEY_TYPELIST:
395        show_testtype_list()
396    elif command == CMD_KEY_SUBSYSTEMLIST:
397        show_subsystem_list(product_form)
398    elif command == CMD_KEY_PARTLIST:
399        show_partname_list(product_form)
400    elif command == CMD_KEY_SUBSYSTEMLIST_ACTS:
401        show_acts_subsystem_list()
402    elif command == CMD_KEY_SUBSYSTEMLIST_HATS:
403        show_hats_subsystem_list()
404    else:
405        print("This command is not support.")
406
407#############################################################################
408#############################################################################
409