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 os 19import sys 20from datetime import datetime 21from typing import List 22 23from dotenv import load_dotenv 24 25from runner.logger import Log 26from runner.options.cli_options import get_args 27from runner.options.config import Config 28from runner.plugins_registry import PluginsRegistry 29from runner.runner_base import Runner 30 31 32def main() -> None: 33 dotenv_path = os.path.join(os.path.dirname(__file__), '.env') 34 if os.path.exists(dotenv_path): 35 load_dotenv(dotenv_path) 36 37 args = get_args() 38 config = Config(args) 39 logger = Log.setup(config.general.verbose, config.general.work_dir) 40 Log.summary(logger, f"Loaded configuration: {config}") 41 config.generate_config() 42 43 registry = PluginsRegistry() 44 config.custom.validate() 45 runners: List[Runner] = [] 46 47 if config.general.processes == 1: 48 Log.default(logger, "Attention: tests are going to take only 1 process. The execution can be slow. " 49 "You can set the option `--processes` to wished processes quantity " 50 "or use special value `all` to use all available cores.") 51 start = datetime.now() 52 for test_suite in config.test_suites: 53 plugin = "ets" if test_suite.startswith("ets") else test_suite 54 runner_class = registry.get_runner(plugin) 55 if runner_class is not None: 56 runners.append(runner_class(config)) 57 else: 58 Log.exception_and_raise(logger, f"Plugin {plugin} not registered") 59 60 failed_tests = 0 61 62 if not config.general.generate_only: 63 for runner in runners: 64 Log.all(logger, f"Runner {runner.name} started") 65 runner.run() 66 Log.all(logger, f"Runner {runner.name} finished") 67 failed_tests += runner.summarize() 68 Log.all(logger, f"Runner {runner.name}: {failed_tests} failed tests") 69 if config.general.coverage.use_llvm_cov: 70 runner.create_coverage_html() 71 72 finish = datetime.now() 73 Log.default(logger, f"Runner has been working for {round((finish-start).total_seconds())} sec") 74 75 registry.cleanup() 76 sys.exit(0 if failed_tests == 0 else 1) 77 78 79if __name__ == "__main__": 80 main() 81