1#!/usr/bin/env python3 2# -*- coding: utf-8 -*- 3 4# Copyright (c) 2021-2023 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# This file does only contain a selection of the most common options. For a 18# full list see the documentation: 19# http://www.sphinx-doc.org/en/master/config 20 21from functools import cached_property 22from os import path 23from typing import Dict, Optional 24 25from runner.enum_types.qemu import QemuKind 26from runner.enum_types.verbose_format import VerboseKind, VerboseFilter 27from runner.options.decorator_value import value, _to_qemu, _to_bool, _to_enum, _to_str, _to_path, _to_int, \ 28 _to_processes 29from runner.options.options_coverage import CoverageOptions 30from runner.reports.report_format import ReportFormat 31 32 33# pylint: disable=too-many-public-methods 34class GeneralOptions: 35 __DEFAULT_PROCESSES = 1 36 __DEFAULT_CHUNKSIZE = 32 37 __DEFAULT_GC_TYPE = "g1-gc" 38 __DEFAULT_GC_BOMBING_FREQUENCY = 0 39 __DEFAULT_HEAP_VERIFIER = "fail_on_verification" 40 __DEFAULT_REPORT_FORMAT = ReportFormat.LOG 41 __DEFAULT_VERBOSE = VerboseKind.NONE 42 __DEFAULT_VERBOSE_FILTER = VerboseFilter.NEW_FAILURES 43 __DEFAULT_QEMU = QemuKind.NONE 44 45 def __str__(self) -> str: 46 return _to_str(self, 1) 47 48 def to_dict(self) -> Dict[str, object]: 49 return { 50 "build": self.build, 51 "processes": self.processes, 52 "test-root": self.test_root, 53 "list-root": self.list_root, 54 "work-dir": self.work_dir, 55 "ets-stdlib-root": self.ets_stdlib_root, 56 "show-progress": self.show_progress, 57 "gc_type": self.gc_type, 58 "full-gc-bombing-frequency": self.full_gc_bombing_frequency, 59 "run_gc_in_place": self.run_gc_in_place, 60 "heap-verifier": self.heap_verifier, 61 "report-format": self.report_format.value.upper(), 62 "verbose": self.verbose.value.upper(), 63 "verbose-filter": self.verbose_filter.value.upper(), 64 "coverage": self.coverage.to_dict(), 65 "force-download": self.force_download, 66 "bco": self.bco, 67 "qemu": self.qemu.value.upper(), 68 "with-js": self.with_js, 69 "generate_only": self.generate_only, 70 } 71 72 @cached_property 73 @value(yaml_path="general.generate-config", cli_name="generate_config", cast_to_type=_to_path) 74 def generate_config(self) -> Optional[str]: 75 return None 76 77 @cached_property 78 @value(yaml_path="general.processes", cli_name="processes", cast_to_type=_to_processes) 79 def processes(self) -> int: 80 return GeneralOptions.__DEFAULT_PROCESSES 81 82 @cached_property 83 def chunksize(self) -> int: 84 return GeneralOptions.__DEFAULT_CHUNKSIZE 85 86 @cached_property 87 @value(yaml_path="general.build", cli_name="build_dir", cast_to_type=_to_path, required=True) 88 def build(self) -> Optional[str]: 89 return None 90 91 @cached_property 92 def static_core_root(self) -> str: 93 # This file is expected to be located at path: 94 # $PANDA_SOURCE/tests/tests-u-runner/runner/options/options_general.py 95 path_parts = __file__.split(path.sep)[:-5] 96 return path.sep.join(path_parts) 97 98 @cached_property 99 @value(yaml_path="general.test-root", cli_name="test_root", cast_to_type=_to_path) 100 def test_root(self) -> Optional[str]: 101 return None 102 103 @cached_property 104 @value(yaml_path="general.list-root", cli_name="list_root", cast_to_type=_to_path) 105 def list_root(self) -> Optional[str]: 106 return None 107 108 @cached_property 109 @value(yaml_path="general.work-dir", cli_name="work_dir", cast_to_type=_to_path) 110 def work_dir(self) -> Optional[str]: 111 return None 112 113 @cached_property 114 @value(yaml_path="general.ets-stdlib-root", cli_name="ets_stdlib_root", cast_to_type=_to_path) 115 def ets_stdlib_root(self) -> Optional[str]: 116 return None 117 118 @cached_property 119 @value(yaml_path="general.show-progress", cli_name="progress", cast_to_type=_to_bool) 120 def show_progress(self) -> bool: 121 return False 122 123 @cached_property 124 @value(yaml_path="general.gc_type", cli_name="gc_type") 125 def gc_type(self) -> str: 126 return GeneralOptions.__DEFAULT_GC_TYPE 127 128 @cached_property 129 @value(yaml_path="general.full-gc-bombing-frequency", cli_name="full_gc_bombing_frequency", cast_to_type=_to_int) 130 def full_gc_bombing_frequency(self) -> int: 131 return GeneralOptions.__DEFAULT_GC_BOMBING_FREQUENCY 132 133 @cached_property 134 @value(yaml_path="general.run_gc_in_place", cli_name="run_gc_in_place", cast_to_type=_to_bool) 135 def run_gc_in_place(self) -> bool: 136 return False 137 138 @cached_property 139 @value(yaml_path="general.heap-verifier", cli_name="heap_verifier") 140 def heap_verifier(self) -> str: 141 return GeneralOptions.__DEFAULT_HEAP_VERIFIER 142 143 @cached_property 144 @value( 145 yaml_path="general.report-format", 146 cli_name="report_formats", 147 cast_to_type=lambda x: _to_enum(x, ReportFormat) 148 ) 149 def report_format(self) -> ReportFormat: 150 return GeneralOptions.__DEFAULT_REPORT_FORMAT 151 152 @cached_property 153 @value( 154 yaml_path="general.verbose", 155 cli_name="verbose", 156 cast_to_type=lambda x: _to_enum(x, VerboseKind) 157 ) 158 def verbose(self) -> VerboseKind: 159 return GeneralOptions.__DEFAULT_VERBOSE 160 161 @cached_property 162 @value( 163 yaml_path="general.verbose-filter", 164 cli_name="verbose_filter", 165 cast_to_type=lambda x: _to_enum(x, VerboseFilter) 166 ) 167 def verbose_filter(self) -> VerboseFilter: 168 return GeneralOptions.__DEFAULT_VERBOSE_FILTER 169 170 coverage = CoverageOptions() 171 172 @cached_property 173 @value(yaml_path="general.force-download", cli_name="force_download", cast_to_type=_to_bool) 174 def force_download(self) -> bool: 175 return False 176 177 @cached_property 178 @value(yaml_path="general.bco", cli_name="bco", cast_to_type=_to_bool) 179 def bco(self) -> bool: 180 return True 181 182 @cached_property 183 @value(yaml_path="general.with_js", cli_name="with_js", cast_to_type=_to_bool) 184 def with_js(self) -> bool: 185 return True 186 187 @cached_property 188 @value(yaml_path="general.qemu", cli_name=["arm64_qemu", "arm32_qemu"], cast_to_type=_to_qemu) 189 def qemu(self) -> QemuKind: 190 return GeneralOptions.__DEFAULT_QEMU 191 192 @property 193 def qemu_cmd_line(self) -> str: 194 qemu = '' 195 if self.qemu == QemuKind.ARM64: 196 qemu = '--arm64-qemu' 197 elif self.qemu == QemuKind.ARM32: 198 qemu = '--arm32-qemu' 199 return qemu 200 201 @cached_property 202 @value(yaml_path="general.generate-only", cli_name="generate_only", cast_to_type=_to_bool) 203 def generate_only(self) -> bool: 204 return False 205 206 def get_command_line(self) -> str: 207 options = [ 208 f'--generate-config="{self.generate_config}"' if self.generate_config else '', 209 f'--processes={self.processes}' if self.processes != GeneralOptions.__DEFAULT_PROCESSES else '', 210 f'--chunksize={self.chunksize}' if self.chunksize != GeneralOptions.__DEFAULT_CHUNKSIZE else '', 211 f'--build-dir="{self.build}"', 212 f'--test-root="{self.test_root}"' if self.test_root else '', 213 f'--list-root="{self.list_root}"' if self.list_root else '', 214 f'--work-dir="{self.work_dir}"' if self.work_dir else '', 215 f'--ets-stdlib-root="{self.ets_stdlib_root}"' if self.ets_stdlib_root else '', 216 '--show-progress' if self.show_progress else '', 217 f'--gc-type="{self.gc_type}"' if self.gc_type != GeneralOptions.__DEFAULT_GC_TYPE else '', 218 f'--full-gc-bombing-frequency={self.full_gc_bombing_frequency}' 219 if self.full_gc_bombing_frequency != GeneralOptions.__DEFAULT_GC_BOMBING_FREQUENCY else '', 220 '--no-run-gc-in-place' if self.run_gc_in_place else '', 221 f'--heap-verifier="{self.heap_verifier}"' 222 if self.heap_verifier != GeneralOptions.__DEFAULT_HEAP_VERIFIER else '', 223 f'--report-format={self.report_format.value}' 224 if self.report_format != GeneralOptions.__DEFAULT_REPORT_FORMAT else '', 225 f'--verbose={self.verbose.value}' 226 if self.verbose != GeneralOptions.__DEFAULT_VERBOSE else '', 227 f'--verbose-filter={self.verbose_filter.value}' 228 if self.verbose_filter != GeneralOptions.__DEFAULT_VERBOSE_FILTER else '', 229 self.coverage.get_command_line(), 230 '--force-download' if self.force_download else '', 231 '--no-bco' if not self.bco else '', 232 '--no-js' if not self.with_js else '', 233 '--generate-only' if self.generate_only else '', 234 self.qemu_cmd_line, 235 ] 236 return ' '.join(options) 237