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 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=["test_suites", "test262", "parser", "declgenparser", "hermes", "system", "astchecker", "srcdumper", 60 "ets_func_tests", "ets_runtime", "ets_cts", "ets_gc_stress", "ets_es_checked", "ets_custom", 61 "sts_ts_subset"], 62 cast_to_type=_to_test_suites, 63 required=True 64 ) 65 def test_suites(self) -> Set[str]: 66 return set([]) 67 68 general = GeneralOptions() 69 report = ReportOptions() 70 custom = CustomSuiteOptions() 71 es2panda = Es2PandaOptions() 72 verifier = VerifierOptions() 73 quick = QuickOptions() 74 ark_aot = ArkAotOptions() 75 ark = ArkOptions() 76 time_report = TimeReportOptions() 77 test_lists = TestListsOptions() 78 ets = ETSOptions() 79 80 def generate_config(self) -> None: 81 if self.general.generate_config is None: 82 return 83 data = self._to_dict() 84 ConfigKeeper.get().save(self.general.generate_config, data) 85 86 def get_command_line(self) -> str: 87 _test_suites = ['--' + suite.replace('_', '-') for suite in self.test_suites] 88 options = ' '.join([ 89 ' '.join(_test_suites), 90 self.general.get_command_line(), 91 self.report.get_command_line(), 92 self.es2panda.get_command_line(), 93 self.verifier.get_command_line(), 94 self.quick.get_command_line(), 95 self.ark_aot.get_command_line(), 96 self.ark.get_command_line(), 97 self.time_report.get_command_line(), 98 self.test_lists.get_command_line(), 99 self.ets.get_command_line() 100 ]) 101 options_str = re.sub(r'\s+', ' ', options, re.IGNORECASE | re.DOTALL) 102 103 return options_str 104 105 def _to_dict(self) -> Dict[str, object]: 106 return { 107 "test-suites": list(self.test_suites), 108 "custom": self.custom.to_dict(), 109 "general": self.general.to_dict(), 110 "report": self.report.to_dict(), 111 "es2panda": self.es2panda.to_dict(), 112 "verifier": self.verifier.to_dict(), 113 "quick": self.quick.to_dict(), 114 "ark_aot": self.ark_aot.to_dict(), 115 "ark": self.ark.to_dict(), 116 "time-report": self.time_report.to_dict(), 117 "test-lists": self.test_lists.to_dict(), 118 "ets": self.ets.to_dict(), 119 "sts": self.ets.to_dict() 120 } 121