1#!/usr/bin/env python3 2# -*- coding: utf-8 -*- 3 4# Copyright (c) 2021-2025 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 18import argparse 19import logging 20import re 21from functools import cached_property 22from typing import Set, Dict 23 24from runner.logger import Log 25from runner.options.cli_args_wrapper import CliArgsWrapper 26from runner.options.config_keeper import ConfigKeeper 27from runner.options.decorator_value import value, _to_test_suites, _to_str 28from runner.options.options_ark import ArkOptions 29from runner.options.options_ark_aot import ArkAotOptions 30from runner.options.options_custom import CustomSuiteOptions 31from runner.options.options_es2panda import Es2PandaOptions 32from runner.options.options_ets import ETSOptions 33from runner.options.options_general import GeneralOptions 34from runner.options.options_report import ReportOptions 35from runner.options.options_quick import QuickOptions 36from runner.options.options_test_lists import TestListsOptions 37from runner.options.options_time_report import TimeReportOptions 38from runner.options.options_verifier import VerifierOptions 39 40_LOGGER = logging.getLogger("runner.options.config") 41 42 43class Config: 44 def __init__(self, args: argparse.Namespace): 45 CliArgsWrapper.setup(args) 46 ConfigKeeper.get().load_configs(args.configs) 47 48 def __str__(self) -> str: 49 return _to_str(self, 0) 50 51 @staticmethod 52 def log_warnings() -> None: 53 for warning in ConfigKeeper.get().warnings(): 54 Log.summary(_LOGGER, warning) 55 56 @cached_property 57 @value( 58 yaml_path="test-suites", 59 cli_name=[ 60 "test_suites", 61 "test262", 62 "parser", 63 "declgenparser", 64 "hermes", 65 "system", 66 "astchecker", 67 "srcdumper", 68 "ets_func_tests", 69 "ets_runtime", 70 "ets_cts", 71 "ets_gc_stress", 72 "ets_es_checked", 73 "ets_custom", 74 "ets_ts_subset", 75 "declgen_ets2ts_cts", 76 "declgen_ets2ts_func_tests", 77 "declgen_ets2ts_runtime", 78 "ets_sdk", 79 "declgen_ts2ets_cts", 80 "recheck", 81 "declgen_ets2ets", 82 "declgen_ets2etsisolated", 83 ], 84 cast_to_type=_to_test_suites, 85 required=True, 86 ) 87 def test_suites(self) -> Set[str]: 88 return set([]) 89 90 general = GeneralOptions() 91 report = ReportOptions() 92 custom = CustomSuiteOptions() 93 es2panda = Es2PandaOptions() 94 verifier = VerifierOptions() 95 quick = QuickOptions() 96 ark_aot = ArkAotOptions() 97 ark = ArkOptions() 98 time_report = TimeReportOptions() 99 test_lists = TestListsOptions() 100 ets = ETSOptions() 101 102 def generate_config(self) -> None: 103 if self.general.generate_config is None: 104 return 105 data = self._to_dict() 106 ConfigKeeper.get().save(self.general.generate_config, data) 107 108 def get_command_line(self) -> str: 109 _test_suites = ["--" + suite.replace("_", "-") for suite in self.test_suites] 110 options = " ".join( 111 [ 112 " ".join(_test_suites), 113 self.general.get_command_line(), 114 self.report.get_command_line(), 115 self.es2panda.get_command_line(), 116 self.verifier.get_command_line(), 117 self.quick.get_command_line(), 118 self.ark_aot.get_command_line(), 119 self.ark.get_command_line(), 120 self.time_report.get_command_line(), 121 self.test_lists.get_command_line(), 122 self.ets.get_command_line(), 123 ] 124 ) 125 options_str = re.sub(r"\s+", " ", options, re.IGNORECASE | re.DOTALL) 126 127 return options_str 128 129 def _to_dict(self) -> Dict[str, object]: 130 return { 131 "test-suites": list(self.test_suites), 132 "custom": self.custom.to_dict(), 133 "general": self.general.to_dict(), 134 "report": self.report.to_dict(), 135 "es2panda": self.es2panda.to_dict(), 136 "verifier": self.verifier.to_dict(), 137 "quick": self.quick.to_dict(), 138 "ark_aot": self.ark_aot.to_dict(), 139 "ark": self.ark.to_dict(), 140 "time-report": self.time_report.to_dict(), 141 "test-lists": self.test_lists.to_dict(), 142 "ets": self.ets.to_dict(), 143 } 144