• 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. MST
50#     4. ST
51#     5. PERF
52#     6. SEC
53#     7. FUZZ
54#     8. RELI
55#     9. DST
56#     10. BENCHMARK
57#     11. ALL
58CMD_KEY_TYPELIST = "typelist"
59
60# 子系统名称列表
61CMD_KEY_SUBSYSTEMLIST = "subsystemlist"
62
63# 子系统下的部件名
64CMD_KEY_PARTLIST = "partlist"
65
66# acts子系统名称列表
67CMD_KEY_SUBSYSTEMLIST_ACTS = "actssubsystemlist"
68
69TOOL_VERSION_INFO = """Welcome to DeveloperTest V3.2.2.0
70"""
71
72HLEP_COMMAND_INFOMATION = """use help [follow command] for more information:
73    """ + \
74    "show: " + """Display a list of supported show command.
75    """ + \
76    "run:  " + """Display a list of supported run command.
77    """ + \
78    "list: " + """Display a list of supported device.
79    """ + \
80    "quit: " + """Exit the test framework application.
81"""
82
83SUPPORT_COMMAND_SHOW = """use show [follow command] for more information:
84    """ + \
85    "productlist" + """
86    """ + \
87    "typelist" + """
88    """ + \
89    "subsystemlist" + """
90    """ + \
91    "partlist" + """
92"""
93
94RUNCASES_INFOMATION = """run:
95    This command is used to execute the selected testcases.
96    It includes a series of processes such as use case compilation, \
97execution, and result collection.
98
99usage: run [-p PRODUCTFORM]
100           [-t [TESTTYPE [TESTTYPE ...]]]
101           [-ss [SUBSYSTEM [SUBSYSTEM ...]]]
102           [-tp [TESTPART [TESTPART ...]]]
103           [-ts TESTSUIT]
104           [-tc TESTCASE]
105           [-tl TESTLEVEL]
106           [-repeat NUMBER]
107           [-hl]
108           [-rh HISCOMMAND-INDEX]
109           [-retry]
110
111optional arguments:
112  -p PRODUCTFORM, --productform PRODUCTFORM
113                        Specified product form
114  -t [TESTTYPE [TESTTYPE ...]], --testtype [TESTTYPE [TESTTYPE ...]]
115                        Specify test type(UT,MST,ST,PERF,ALL)
116  -ss [SUBSYSTEM [SUBSYSTEM ...]], --subsystem [SUBSYSTEM [SUBSYSTEM ...]]
117                        Specify test subsystem
118  -tp [TESTPART [TESTPART ...]], --testpart [TESTPART [TESTPART ...]]
119                        Specify test testpart
120  -ts TESTSUIT, --testsuit TESTSUIT
121                        Specify test suit
122  -tc TESTCASE, --testcase TESTCASE
123                        Specify test case
124  -tl TESTLEVEL, --testlevel TESTLEVEL
125  --repeat NUMBER
126  -hl, --hisotrylist
127  -rh INDEX, --runhistory INDEX
128  --retry
129
130Examples:
131    run -t UT
132    run -t UT -ss aafwk
133    run -t UT -ss aafwk -tm base_test
134    run -t UT -ss aafwk -tm base_test -ts base_test
135    run -t UT -ss aafwk -tm base_test -ts base_test -tl 2
136    run -t UT -ss aafwk -tm base_test -ts base_test -tc \
137AAFwkBaseTest.*
138    run -t UT -ss aafwk -tm base_test -ts base_test -tc \
139AAFwkBaseTest.object_test_001
140    run -t UT -ss aafwk -tm base_test --repeat 3
141    run -t MST
142    ...
143    run -t ALL
144    ...
145    run -hl
146    run -rh 1
147    run --retry
148    run -t ACTS -ss arkui,ability -ts ActsAceEtsTest;ActsAceEtsStTest;ActsApiTest
149"""
150
151LIST_INFOMATION = "list\n" + """
152    This command is used to display device list.
153"""
154
155QUIT_INFOMATION = "quit\n" + """
156    This command is used to exit the test framework application.
157"""
158
159
160#############################################################################
161#############################################################################
162
163def select_user_input(data_list):
164    data_item_count = len(data_list)
165    select_item_value = ""
166    select_item_index = -1
167
168    if len(data_list) != 0:
169        count = 0
170        while True:
171            input_data = input("")
172            if "" != input_data and input_data.isdigit():
173                input_num = int(input_data)
174                if input_num > 0 and (input_num <= data_item_count):
175                    select_item_index = input_num - 1
176                    select_item_value = data_list[input_num - 1]
177                    break
178                else:
179                    print("The data you entered is out of range, \
180                        please re-enter:")
181                    count += 1
182            else:
183                if "" == input_data:
184                    select_item_index = 0
185                    select_item_value = data_list[0]
186                    break
187                else:
188                    print("You entered a non-numeric character, \
189                        please re-enter:")
190                    count += 1
191
192            if count >= 3:
193                print("You entered the error three times in a row, \
194                    exit the frame.")
195                quit()
196                sys.exit(0)
197        return select_item_value, select_item_index
198
199
200# 选择productform
201def select_productform():
202    select_value = "phone"
203
204    # 列表注释 scan_support_product() = [DAYU,Hi3516,ohos_arm64,ohos_sdk,rk3568]
205    scan_product_list = scan_support_product()
206
207    # 从framework_config.xml里取productform节点的value:ipcamera_hispark_aries、ipcamera_hispark_taurus、wifiiot_hispark_pegasus
208    config_product_list = \
209        FrameworkConfigManager().get_framework_config("productform")
210
211    # 列表注释 productform_list = [DAYU,Hi3516,ohos_arm64,ohos_sdk,rk3568,
212    # 列表注释 ipcamera_hispark_aries、ipcamera_hispark_taurus、wifiiot_hispark_pegasus]
213
214    productform_list = scan_product_list + config_product_list
215    if len(productform_list) != 0:
216        print("Please select the current tested product form:")
217        for index, element in enumerate(productform_list):
218            print("%d. %s" % (index + 1, element))
219        print("default is [1] %s" % productform_list[0])
220        select_value, _ = select_user_input(productform_list)
221    print(select_value)
222    return select_value
223
224
225def show_wizard_mode():
226    wizard_data_dic = {}
227    print("+++++++++++++++++++++++++++++++++++++++++++++")
228
229    productform = select_productform()
230    if productform == "":
231        productform = "phone"
232    wizard_data_dic["productform"] = productform
233
234    print("+++++++++++++++++++++++++++++++++++++++++++++")
235    print("The environment is ready, please use the run command to test.")
236    return wizard_data_dic
237
238
239#############################################################################
240#############################################################################
241
242def display_help_info(para_list):
243    if len(para_list) == 0 or para_list[0] != ToolCommandType.TOOLCMD_KEY_HELP:
244        print("This command is not support.")
245        return
246
247    if len(para_list) > 1:
248        display_help_command_info(para_list[1])
249    else:
250        print(TOOL_VERSION_INFO)
251        print(HLEP_COMMAND_INFOMATION)
252
253
254def display_show_info(para_list, productform):
255    if len(para_list) == 0 or para_list[0] != ToolCommandType.TOOLCMD_KEY_SHOW:
256        print("This command is not support.")
257        return
258
259    if len(para_list) > 1:
260        display_show_command_info(para_list[1], productform)
261    else:
262        print(SUPPORT_COMMAND_SHOW)
263
264
265def display_version_info(para_list):
266    print(TOOL_VERSION_INFO)
267
268
269#############################################################################
270#############################################################################
271
272
273#############################################################################
274#############################################################################
275
276
277def show_product_list():
278    print("List of currently supported productform:")
279    scan_product_list = scan_support_product()
280    config_product_list = \
281        FrameworkConfigManager().get_framework_config("productform")
282    productform_list = scan_product_list + config_product_list
283    if 0 != len(productform_list):
284        for index, element in enumerate(productform_list):
285            print("    %d. %s" % (index + 1, element))
286    else:
287        print("No category specified.")
288
289
290def show_testtype_list():
291    print("List of currently supported test types:")
292    testtype_list = FrameworkConfigManager().get_framework_config(
293        "test_category")
294    if 0 != len(testtype_list):
295        for index, element in enumerate(testtype_list):
296            print("    %d. %s" % (index + 1, element))
297    else:
298        print("No category specified.")
299
300
301# 从OpenHarmony/out/rk3568/build_configs/infos_for_testfwk.json里的subsystem_infos中subsystem_infos下获取subsystemlist
302def show_subsystem_list(product_form):
303    print("List of currently supported subsystem names:")
304    parser = ParsePartsConfig(product_form)
305    subsystem_name_list = parser.get_subsystem_name_list()
306    if len(subsystem_name_list) == 0:
307        return
308
309    subsystem_name_list.sort()
310    for index, element in enumerate(subsystem_name_list):
311        print("    %d. %s" % (index + 1, element))
312
313
314def show_acts_subsystem_list():
315    print("List of currently supported acts subsystem names:")
316    sub_list = ['global', 'security', 'useriam', 'multimedia', 'appexecfwk', 'account', 'communication', 'notification',
317    'ability', 'miscservices', 'powermgr', 'startup', 'sensor', 'distributeddatamgr', 'update', 'graphic', 'arkui',
318    'storage', 'compileruntime', 'usb', 'multimodalinput', 'resourceschedule',
319    'telephony', 'hiviewdfx', 'location', 'barrierfree', 'customization']
320    sub_list.sort()
321    for index, element in enumerate(sub_list):
322        print("    %d. %s" % (index + 1, element.strip()))
323    print("end")
324
325
326# 从OpenHarmony/out/rk3568/build_configs/infos_for_testfwk.json里的subsystem_infos中subsystem_infos下获取partlist
327def show_partname_list(product_form):
328    print("List of currently supported part names:")
329    parser = ParsePartsConfig(product_form)
330    subsystem_name_list = parser.get_subsystem_name_list()
331
332    if len(subsystem_name_list) == 0:
333        return
334
335    subsystem_name_list.sort()
336    subsystem_infos = parser.get_subsystem_infos()
337    for subsystem in subsystem_name_list:
338        print("%s:" % subsystem)
339        part_name_list = subsystem_infos[subsystem]
340        part_name_list.sort()
341        for index, element in enumerate(part_name_list):
342            print("    %d. %s" % (index + 1, element))
343
344
345def display_help_command_info(command):
346    if command == ToolCommandType.TOOLCMD_KEY_SHOW:
347        print(SUPPORT_COMMAND_SHOW)
348    elif command == ToolCommandType.TOOLCMD_KEY_RUN:
349        print(RUNCASES_INFOMATION)
350    elif command == ToolCommandType.TOOLCMD_KEY_LIST:
351        print(LIST_INFOMATION)
352    elif command == ToolCommandType.TOOLCMD_KEY_QUIT:
353        print(QUIT_INFOMATION)
354    else:
355        print("'%s' command no help information." % command)
356
357
358def display_show_command_info(command, product_form="phone"):
359    if command == CMD_KEY_PRODUCTLIST:
360        show_product_list()
361    elif command == CMD_KEY_TYPELIST:
362        show_testtype_list()
363    elif command == CMD_KEY_SUBSYSTEMLIST:
364        show_subsystem_list(product_form)
365    elif command == CMD_KEY_PARTLIST:
366        show_partname_list(product_form)
367    elif command == CMD_KEY_SUBSYSTEMLIST_ACTS:
368        show_acts_subsystem_list()
369    else:
370        print("This command is not support.")
371
372
373#############################################################################
374#############################################################################
375