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