display.py 11.8 KB
Newer Older
W
wenjun 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#!/usr/bin/env python3
# coding=utf-8

#
# Copyright (c) 2020 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

D
dingpeng 已提交
19 20 21 22
# 执行如下命令 获取到的信息
#    show subsystemlist 通过show subsystemlist得到子系统名称列表
#    show partlist      通过show partlist得到对应子系统下的部件名

W
wenjun 已提交
23 24 25 26 27 28
import sys
import os

from core.constants import ToolCommandType
from core.utils import get_file_list
from core.utils import get_file_list_by_postfix
M
mamingshuai 已提交
29
from core.utils import get_build_output_path
M
mamingshuai 已提交
30
from core.utils import scan_support_product
W
wenjun 已提交
31 32
from core.config.config_manager import UserConfigManager
from core.config.config_manager import FrameworkConfigManager
M
mamingshuai 已提交
33
from core.config.parse_parts_config import ParsePartsConfig
W
wenjun 已提交
34

D
dingpeng 已提交
35 36 37 38 39 40 41 42 43
# 支持的设备名称
#    1. ohos-sdk
#    2. rk3568
#    3. Hi3516DV300
#    4. DAYU
#    5. ohos-arm64
#    6. ipcamera_hispark_aries
#    7. ipcamera_hispark_taurus
#    8. wifiiot_hispark_pegasus
W
wenjun 已提交
44
CMD_KEY_PRODUCTLIST = "productlist"
D
dingpeng 已提交
45 46 47

# 测试用例类型
#     1. UT
48 49 50 51 52 53 54 55 56 57
#     2. ACTS
#     3. MST
#     4. ST
#     5. PERF
#     6. SEC
#     7. FUZZ
#     8. RELI
#     9. DST
#     10. BENCHMARK
#     11. ALL
W
wenjun 已提交
58
CMD_KEY_TYPELIST = "typelist"
D
dingpeng 已提交
59 60

# 子系统名称列表
W
wenjun 已提交
61
CMD_KEY_SUBSYSTEMLIST = "subsystemlist"
D
dingpeng 已提交
62 63

# 子系统下的部件名
M
mamingshuai 已提交
64
CMD_KEY_PARTLIST = "partlist"
D
dingpeng 已提交
65

66 67 68
# acts子系统名称列表
CMD_KEY_SUBSYSTEMLIST_ACTS = "actssubsystemlist"

M
mamingshuai 已提交
69
TOOL_VERSION_INFO = """Welcome to DeveloperTest V1.0.0.
W
wenjun 已提交
70 71 72 73 74 75 76 77
"""

HLEP_COMMAND_INFOMATION = """use help [follow command] for more information:
    """ + \
    "show: " + """Display a list of supported show command.
    """ + \
    "run:  " + """Display a list of supported run command.
    """ + \
M
mamingshuai 已提交
78 79
    "list: " + """Display a list of supported device.
    """ + \
W
wenjun 已提交
80 81 82 83 84 85 86 87 88 89 90
    "quit: " + """Exit the test framework application.
"""

SUPPORT_COMMAND_SHOW = """use show [follow command] for more information:
    """ + \
    "productlist" + """
    """ + \
    "typelist" + """
    """ + \
    "subsystemlist" + """
    """ + \
M
mamingshuai 已提交
91
    "partlist" + """
W
wenjun 已提交
92 93
"""

M
mamingshuai 已提交
94
RUNCASES_INFOMATION = """run:
W
wenjun 已提交
95 96
    This command is used to execute the selected testcases.
    It includes a series of processes such as use case compilation, \
M
mamingshuai 已提交
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
execution, and result collection.

usage: run [-p PRODUCTFORM]
           [-t [TESTTYPE [TESTTYPE ...]]]
           [-ss [SUBSYSTEM [SUBSYSTEM ...]]]
           [-tp [TESTPART [TESTPART ...]]]
           [-ts TESTSUIT]
           [-tc TESTCASE]
           [-tl TESTLEVEL]

optional arguments:
  -p PRODUCTFORM, --productform PRODUCTFORM
                        Specified product form
  -t [TESTTYPE [TESTTYPE ...]], --testtype [TESTTYPE [TESTTYPE ...]]
                        Specify test type(UT,MST,ST,PERF,ALL)
  -ss [SUBSYSTEM [SUBSYSTEM ...]], --subsystem [SUBSYSTEM [SUBSYSTEM ...]]
                        Specify test subsystem
  -tp [TESTPART [TESTPART ...]], --testpart [TESTPART [TESTPART ...]]
                        Specify test testpart
  -ts TESTSUIT, --testsuit TESTSUIT
                        Specify test suit
  -tc TESTCASE, --testcase TESTCASE
                        Specify test case
  -tl TESTLEVEL, --testlevel TESTLEVEL

Examples:
W
wenjun 已提交
123 124
    run -t UT
    run -t UT -ss aafwk
M
mamingshuai 已提交
125 126 127 128 129 130 131
    run -t UT -ss aafwk -tm base_test
    run -t UT -ss aafwk -tm base_test -ts base_test
    run -t UT -ss aafwk -tm base_test -ts base_test -tl 2
    run -t UT -ss aafwk -tm base_test -ts base_test -tc \
AAFwkBaseTest.*
    run -t UT -ss aafwk -tm base_test -ts base_test -tc \
AAFwkBaseTest.object_test_001
W
wenjun 已提交
132 133 134 135 136 137
    run -t MST
    ...
    run -t ALL
    ...
"""

M
mamingshuai 已提交
138 139
LIST_INFOMATION = "list\n" + """
    This command is used to display device list.
W
wenjun 已提交
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
"""

QUIT_INFOMATION = "quit\n" + """
    This command is used to exit the test framework application.
"""


#############################################################################
#############################################################################

def select_user_input(data_list):
    data_item_count = len(data_list)
    select_item_value = ""
    select_item_index = -1

    if len(data_list) != 0:
        count = 0
        while True:
            input_data = input("")
            if "" != input_data and input_data.isdigit():
                input_num = int(input_data)
                if input_num > 0 and (input_num <= data_item_count):
                    select_item_index = input_num - 1
                    select_item_value = data_list[input_num - 1]
                    break
                else:
                    print("The data you entered is out of range, \
                        please re-enter:")
                    count += 1
            else:
                if "" == input_data:
                    select_item_index = 0
                    select_item_value = data_list[0]
                    break
                else:
                    print("You entered a non-numeric character, \
                        please re-enter:")
                    count += 1

            if count >= 3:
                print("You entered the error three times in a row, \
                    exit the frame.")
                quit()
                sys.exit(0)
        return select_item_value, select_item_index

D
dingpeng 已提交
186
# 选择productform
W
wenjun 已提交
187 188
def select_productform():
    select_value = "phone"
D
dingpeng 已提交
189 190

    # scan_support_product() = [DAYU,Hi3516,ohos_arm64,ohos_sdk,rk3568]
M
mamingshuai 已提交
191
    scan_product_list = scan_support_product()
D
dingpeng 已提交
192 193

    # 从framework_config.xml里取productform节点的value:ipcamera_hispark_aries、ipcamera_hispark_taurus、wifiiot_hispark_pegasus
M
mamingshuai 已提交
194
    config_product_list = \
W
wenjun 已提交
195
        FrameworkConfigManager().get_framework_config("productform")
D
dingpeng 已提交
196 197 198 199

    # productform_list = [DAYU,Hi3516,ohos_arm64,ohos_sdk,rk3568,
    # ipcamera_hispark_aries、ipcamera_hispark_taurus、wifiiot_hispark_pegasus]

M
mamingshuai 已提交
200
    productform_list = scan_product_list + config_product_list
W
wenjun 已提交
201 202
    if len(productform_list) != 0:
        print("Please select the current tested product form:")
M
mamingshuai 已提交
203 204 205
        for index, element in enumerate(productform_list):
            print("%d. %s" % (index + 1, element))
        print("default is [1] %s" % productform_list[0])
W
wenjun 已提交
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
        select_value, _ = select_user_input(productform_list)
    print(select_value)
    return select_value


def show_wizard_mode():
    wizard_data_dic = {}
    print("+++++++++++++++++++++++++++++++++++++++++++++")

    productform = select_productform()
    if productform == "":
        productform = "phone"
    wizard_data_dic["productform"] = productform

    print("+++++++++++++++++++++++++++++++++++++++++++++")
    print("The environment is ready, please use the run command to test.")
    return wizard_data_dic


#############################################################################
#############################################################################

def display_help_info(para_list):
    if len(para_list) == 0 or para_list[0] != ToolCommandType.TOOLCMD_KEY_HELP:
        print("This command is not support.")
        return

    if len(para_list) > 1:
        display_help_command_info(para_list[1])
    else:
M
mamingshuai 已提交
236
        print(TOOL_VERSION_INFO)
W
wenjun 已提交
237 238 239
        print(HLEP_COMMAND_INFOMATION)


H
hwb0703 已提交
240
def display_show_info(para_list, productform):
W
wenjun 已提交
241 242 243 244 245
    if len(para_list) == 0 or para_list[0] != ToolCommandType.TOOLCMD_KEY_SHOW:
        print("This command is not support.")
        return

    if len(para_list) > 1:
H
hwb0703 已提交
246
        display_show_command_info(para_list[1], productform)
W
wenjun 已提交
247 248 249 250 251 252 253 254 255 256 257 258 259 260
    else:
        print(SUPPORT_COMMAND_SHOW)


#############################################################################
#############################################################################


#############################################################################
#############################################################################


def show_product_list():
    print("List of currently supported productform:")
M
mamingshuai 已提交
261 262 263 264
    scan_product_list = scan_support_product()
    config_product_list = \
        FrameworkConfigManager().get_framework_config("productform")
    productform_list = scan_product_list + config_product_list
W
wenjun 已提交
265
    if 0 != len(productform_list):
M
mamingshuai 已提交
266 267
        for index, element in enumerate(productform_list):
            print("    %d. %s" % (index + 1, element))
W
wenjun 已提交
268 269 270 271 272 273 274 275
    else:
        print("No category specified.")

def show_testtype_list():
    print("List of currently supported test types:")
    testtype_list = FrameworkConfigManager().get_framework_config(
        "test_category")
    if 0 != len(testtype_list):
M
mamingshuai 已提交
276 277
        for index, element in enumerate(testtype_list):
            print("    %d. %s" % (index + 1, element))
W
wenjun 已提交
278 279 280
    else:
        print("No category specified.")

D
dingpeng 已提交
281
# 从OpenHarmony/out/rk3568/build_configs/infos_for_testfwk.json里的subsystem_infos中subsystem_infos下获取subsystemlist
W
wenjun 已提交
282 283
def show_subsystem_list(product_form):
    print("List of currently supported subsystem names:")
M
mamingshuai 已提交
284 285 286 287
    parser = ParsePartsConfig(product_form)
    subsystem_name_list = parser.get_subsystem_name_list()
    if len(subsystem_name_list) == 0:
        return
W
wenjun 已提交
288

M
mamingshuai 已提交
289 290 291 292
    subsystem_name_list.sort()
    for index, element in enumerate(subsystem_name_list):
        print("    %d. %s" % (index + 1, element))

293 294 295 296 297 298 299 300 301 302
def show_acts_subsystem_list():
    print("List of currently supported acts subsystem names:")
    sub_list = ['global','security','useriam','multimedia','appexecfwk','account','communication','notification',
    'aafwk','miscservices','powermgr','startup','sensor','distributeddatamgr','update','graphic','ace',
    'storage','distributedhardware','compileruntime','usb','multimodalinput','resourceschedule',
    'telephony','hiviewdfx','location','settingsdata','barrierfree','customization']
    sub_list.sort()
    for index, element in enumerate(sub_list):
        print("    %d. %s" % (index + 1, element.strip()))

D
dingpeng 已提交
303
# 从OpenHarmony/out/rk3568/build_configs/infos_for_testfwk.json里的subsystem_infos中subsystem_infos下获取partlist
M
mamingshuai 已提交
304 305 306 307 308 309
def show_partname_list(product_form):
    print("List of currently supported part names:")
    parser = ParsePartsConfig(product_form)
    subsystem_name_list = parser.get_subsystem_name_list()
    if len(subsystem_name_list) == 0:
        return
W
wenjun 已提交
310 311

    subsystem_name_list.sort()
M
mamingshuai 已提交
312 313 314 315 316 317 318
    subsystem_infos = parser.get_subsystem_infos()
    for subsystem in subsystem_name_list:
        print("%s:" % subsystem)
        part_name_list = subsystem_infos[subsystem]
        part_name_list.sort()
        for index, element in enumerate(part_name_list):
            print("    %d. %s" % (index + 1, element))
W
wenjun 已提交
319 320

def display_help_command_info(command):
M
mamingshuai 已提交
321 322 323 324 325 326 327 328
    if command == ToolCommandType.TOOLCMD_KEY_SHOW:
        print(SUPPORT_COMMAND_SHOW)
    elif command == ToolCommandType.TOOLCMD_KEY_RUN:
        print(RUNCASES_INFOMATION)
    elif command == ToolCommandType.TOOLCMD_KEY_LIST:
        print(LIST_INFOMATION)
    elif command == ToolCommandType.TOOLCMD_KEY_QUIT:
        print(QUIT_INFOMATION)
W
wenjun 已提交
329 330 331 332 333 334 335 336 337 338 339
    else:
        print("'%s' command no help information." % command)


def display_show_command_info(command, product_form="phone"):
    if command == CMD_KEY_PRODUCTLIST:
        show_product_list()
    elif command == CMD_KEY_TYPELIST:
        show_testtype_list()
    elif command == CMD_KEY_SUBSYSTEMLIST:
        show_subsystem_list(product_form)
M
mamingshuai 已提交
340 341
    elif command == CMD_KEY_PARTLIST:
        show_partname_list(product_form)
342 343
    elif command == CMD_KEY_SUBSYSTEMLIST_ACTS:
        show_acts_subsystem_list()
W
wenjun 已提交
344 345 346
    else:
        print("This command is not support.")

M
mamingshuai 已提交
347

W
wenjun 已提交
348 349
#############################################################################
#############################################################################