• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2# coding: utf-8
3
4"""
5Copyright (c) 2021 Huawei Device Co., Ltd.
6Licensed under the Apache License, Version 2.0 (the "License");
7you may not use this file except in compliance with the License.
8You may obtain a copy of the License at
9
10    http://www.apache.org/licenses/LICENSE-2.0
11
12Unless required by applicable law or agreed to in writing, software
13distributed under the License is distributed on an "AS IS" BASIS,
14WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15See the License for the specific language governing permissions and
16limitations under the License.
17
18Description: process options and configs for test suite
19"""
20
21import argparse
22import logging
23import os
24from enum import Enum
25
26import yaml
27
28from utils import init_logger
29
30
31arguments = {}
32configs = {}
33
34
35class TaskResult(Enum):
36    undefind = 0
37    passed = 1
38    failed = 2
39
40
41class CompilationInfo:
42    def __init__(self):
43        self.result = TaskResult.undefind
44        self.error_message = ''
45        self.time = 0
46        self.abc_size = 0
47
48
49class FullCompilationInfo:
50    def __init__(self):
51        self.debug_info = CompilationInfo()
52        self.release_info = CompilationInfo()
53
54
55class IncCompilationInfo:
56    def __init__(self):
57        self.debug_info = CompilationInfo()
58        self.release_info = CompilationInfo()
59        self.name = ''
60
61
62class BackupInfo:
63    def __init__(self):
64        self.cache_path = ''
65        self.cache_debug = ''
66        self.cache_release = ''
67        self.output_debug = []
68        self.output_release = []
69
70
71class TestTask:
72    def __init__(self):
73        self.name = ''
74        self.path = ''
75        self.type = ''
76        self.build_path = []
77        self.output_hap_path = ''
78        self.output_app_path = ''
79        self.inc_modify_file = []
80
81        self.full_compilation_info = FullCompilationInfo()
82        self.incre_compilation_info = {}
83        self.other_tests = {}
84
85        self.backup_info = BackupInfo()
86
87
88def parse_args():
89    parser = argparse.ArgumentParser()
90    parser.add_argument('--sdkPath', type=str, dest='sdk_path', default='',
91                        help='specify sdk path if need to update sdk. Default to use sdk specify in config.yaml')
92    parser.add_argument('--buildMode', type=str, dest='build_mode', default='all',
93                        choices=['all', 'assemble', 'preview', 'hotreload', 'hotfix'],
94                        help='specify build mode')
95    parser.add_argument('--hapMode', type=str, dest='hap_mode', default='all',
96                        choices=['all', 'debug', 'release'],
97                        help='specify hap mode')
98    parser.add_argument('--compileMode', type=str, dest='compile_mode', default='all',
99                        choices=['all', 'full', 'incremental'],
100                        help='specify compile mode')
101    parser.add_argument('--testCase', type=str, dest='test_case', default='all',
102                        choices=['all', 'fa', 'stage', 'compatible8', 'js'],
103                        help='specify test cases')
104    parser.add_argument('--testHap', type=str, dest='test_hap', default='all',
105                        help="specify test haps, option can be 'all' or a list of haps seperated by ','")
106    parser.add_argument('--imagePath', type=str, dest='image_path', default='',
107                        help='specify image path if need to update rk/phone images. Default not to update image')
108    parser.add_argument('--runHaps', dest='run_haps', action='store_true', default=False,
109                        help='specify whether to verify by running the haps on board.')
110    parser.add_argument('--logLevel', type=str, dest='log_level', default='error',
111                        choices=['debug', 'info', 'warn', 'error'],
112                        help='specify log level of test suite')
113    parser.add_argument('--logFile', type=str, dest='log_file', default='',
114                        help='specify the file log outputs to, empty string will output to console')
115    parser.add_argument('--compileTimeout', type=int, dest='compile_timeout', default=1800,
116                        help='specify deveco compilation timeout')
117    global arguments
118    arguments = parser.parse_args()
119
120
121def parse_configs():
122    config_yaml = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'config.yaml')
123    with open(config_yaml, 'r') as config_file:
124        global configs
125        configs = yaml.safe_load(config_file)
126
127
128def create_test_tasks():
129    task_list = []
130    haps_list = configs.get('haps')
131    test_cases = 'all' if arguments.test_case == 'all' else []
132    test_haps = 'all' if arguments.test_hap == 'all' else []
133    if test_cases != 'all':
134        test_cases = arguments.test_case.split(',')
135    if test_haps != 'all':
136        test_haps = arguments.test_hap.split(',')
137
138    for hap in haps_list:
139        if test_cases == 'all' or test_haps == 'all' \
140           or (test_cases and (hap['type'][0] in test_cases)) \
141           or (test_haps and (hap['name'] in test_haps)):
142            if not os.path.exists(hap['path']):
143                logging.warning("Path of hap %s dosen't exist: %s", hap['name'], hap['path'])
144                continue
145            task = TestTask()
146            task.name = hap['name']
147            task.path = hap['path']
148            task.type = hap['type']
149            task.build_path = hap['build_path']
150            task.cache_path = hap['cache_path']
151            task.output_hap_path = hap['output_hap_path']
152            task.output_app_path = hap['output_app_path']
153            task.inc_modify_file = hap['inc_modify_file']
154            task.backup_info.cache_path = os.path.join(task.path, 'test_suite_cache')
155
156            task_list.append(task)
157
158    return task_list
159
160
161def process_options():
162    parse_args()
163    init_logger(arguments.log_level, arguments.log_file)
164    parse_configs()
165    return create_test_tasks()