• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3
4# Copyright (c) 2021-2024 Huawei Device Co., Ltd.
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
17
18from functools import cached_property
19from typing import Dict, Optional
20
21from runner.enum_types.configuration_kind import ArchitectureKind, SanitizerKind, OSKind, BuildTypeKind
22from runner.options.decorator_value import value, _to_bool, _to_enum, _to_str
23from runner.options.options_groups import GroupsOptions
24
25
26class TestListsOptions:
27    __DEFAULT_ARCH = ArchitectureKind.AMD64
28    __DEFAULT_SAN = SanitizerKind.NONE
29    __DEFAULT_OS = OSKind.LIN
30    __DEFAULT_BUILD_TYPE = BuildTypeKind.FAST_VERIFY
31    __DEFAULT_FILTER = "*"
32
33    def __str__(self) -> str:
34        return _to_str(self, 1)
35
36    def to_dict(self) -> Dict[str, object]:
37        return {
38            "architecture": self.architecture.value.upper(),
39            "sanitizer": self.sanitizer.value.upper(),
40            "explicit-file": self.explicit_file,
41            "explicit-list": self.explicit_list,
42            "filter": self.filter,
43            "skip-test-lists": self.skip_test_lists,
44            "update-excluded": self.update_excluded,
45            "update-expected": self.update_expected,
46            "groups": self.groups.to_dict(),
47        }
48
49    groups = GroupsOptions()
50
51    @cached_property
52    @value(
53        yaml_path="test-lists.architecture",
54        cli_name="test_list_arch",
55        cast_to_type=lambda x: _to_enum(x, ArchitectureKind)
56    )
57    def architecture(self) -> ArchitectureKind:
58        return TestListsOptions.__DEFAULT_ARCH
59
60    @cached_property
61    @value(
62        yaml_path="test-lists.sanitizer",
63        cli_name="test_list_san",
64        cast_to_type=lambda x: _to_enum(x, SanitizerKind)
65    )
66    def sanitizer(self) -> SanitizerKind:
67        return TestListsOptions.__DEFAULT_SAN
68
69    @cached_property
70    @value(
71        yaml_path="test-lists.os",
72        cli_name="test_list_os",
73        cast_to_type=lambda x: _to_enum(x, OSKind)
74    )
75    def operating_system(self) -> OSKind:
76        return TestListsOptions.__DEFAULT_OS
77
78    @cached_property
79    @value(
80        yaml_path="test-lists.build-type",
81        cli_name="test_list_build",
82        cast_to_type=lambda x: _to_enum(x, BuildTypeKind)
83    )
84    def build_type(self) -> BuildTypeKind:
85        return TestListsOptions.__DEFAULT_BUILD_TYPE
86
87    @cached_property
88    @value(yaml_path="test-lists.explicit-file", cli_name="test_file")
89    def explicit_file(self) -> Optional[str]:
90        return None
91
92    @cached_property
93    @value(yaml_path="test-lists.explicit-list", cli_name="test_list")
94    def explicit_list(self) -> Optional[str]:
95        return None
96
97    @cached_property
98    @value(yaml_path="test-lists.filter", cli_name="filter")
99    def filter(self) -> str:
100        return TestListsOptions.__DEFAULT_FILTER
101
102    @cached_property
103    @value(yaml_path="test-lists.skip-test-lists", cli_name="skip_test_lists", cast_to_type=_to_bool)
104    def skip_test_lists(self) -> bool:
105        return False
106
107    @cached_property
108    @value(yaml_path="test-lists.update-excluded", cli_name="update_excluded", cast_to_type=_to_bool)
109    def update_excluded(self) -> bool:
110        return False
111
112    @cached_property
113    @value(yaml_path="test-lists.update-expected", cli_name="update_expected", cast_to_type=_to_bool)
114    def update_expected(self) -> bool:
115        return False
116
117    def get_command_line(self) -> str:
118        options = [
119            f'--test-list-arch={self.architecture.value}'
120            if self.architecture != TestListsOptions.__DEFAULT_ARCH else '',
121            f'--test-list-san={self.sanitizer.value}'
122            if self.sanitizer != TestListsOptions.__DEFAULT_SAN else '',
123            f'--test-file="{self.explicit_file}"' if self.explicit_file is not None else '',
124            f'--test-list="{self.explicit_list}"' if self.explicit_list is not None else '',
125            f'--filter="{self.filter}"' if self.filter != TestListsOptions.__DEFAULT_FILTER else '',
126            '--skip-test-lists' if self.skip_test_lists else '',
127            '--update-excluded' if self.update_excluded else '',
128            '--update-expected' if self.update_expected else ''
129        ]
130        return ' '.join(options)
131