• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2# coding=utf-8
3
4#
5# Copyright (c) 2020 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
19from xdevice import platform_logger
20from core.utils import scan_support_product
21from core.config.config_manager import FrameworkConfigManager
22
23LOG = platform_logger("Console")
24
25
26class Parameter(object):
27    @classmethod
28    def get_valid_test_level_string(cls, test_level):
29        if test_level == "":
30            return ""
31
32        level_key_list = ["0", "1", "2", "3", "4"]
33        level_list = test_level.strip(",").split(",")
34
35        check_flag = True
36        for item in level_list:
37            item = item.strip(" ")
38            if not item.isdigit():
39                check_flag = False
40                LOG.warning("The testlevel you entered is incorrect.")
41                break
42
43            if item not in level_key_list:
44                LOG.warning("The testlevel you entered is incorrect.")
45                check_flag = False
46                break
47
48        test_level_string = ""
49        if check_flag:
50            for item in level_list:
51                item = item.strip(" ")
52                test_level_string += (item + ",")
53            test_level_string = test_level_string.strip(",")
54        return test_level_string
55
56    @classmethod
57    def get_testtype_list(cls, type_list):
58        test_type_list = []
59        if "ALL" not in type_list:
60            test_category_dic = \
61                FrameworkConfigManager().get_test_category_info()
62            for item in type_list:
63                item = item.upper()
64                data = test_category_dic.get(item, None)
65                if data is None:
66                    LOG.warning("data is None.")
67                    test_type_list = []
68                    break
69                test_type_list.append(data[0])
70        else:
71            test_type_list = FrameworkConfigManager().get_all_category_info()
72        return test_type_list
73
74    def check_run_parameter(self, options):
75        if options.productform is None or options.productform == "":
76            LOG.warning("The productform is incorrect.")
77            return False
78
79        if "" != options.testcase and "" != options.testlevel:
80            LOG.warning("The -l and -c parameters cannot exist at the \
81                        same time.")
82            return False
83
84        level_string = self.get_valid_test_level_string(options.testlevel)
85        if options.testlevel != "" and level_string == "":
86            LOG.warning("The testlevel you entered is incorrect.")
87            return False
88
89        return True
90