1 Star 0 Fork 163

shirunova_viktoria/urunner

forked from Vadim Afanasyev/urunner 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
main.py 5.69 KB
一键复制 编辑 原始数据 按行查看 历史
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright (c) 2021-2024 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import os
import sys
from datetime import datetime, timedelta
from logging import Logger
from typing import List
from dotenv import load_dotenv
from runner import utils
from runner.logger import Log
from runner.options.cli_options import get_args
from runner.options.config import Config, correct_macro
from runner.plugins_registry import PluginsRegistry
from runner.runner_base import Runner
from runner.utils import expand_file_name
def main() -> None:
dotenv_path = os.path.join(os.path.dirname(__file__), '.env')
if os.path.exists(dotenv_path):
load_dotenv(dotenv_path)
args = get_args()
config = Config(args)
config.generate_config()
config.custom.validate()
__expand_macros_in_work_dir(config)
logger = Log.setup(config.general.verbose, config.general.work_dir)
expand_macros(config)
Log.summary(logger, f"Loaded configuration: {config}")
registry = PluginsRegistry()
runners: List[Runner] = []
if config.general.processes == 1:
Log.default(logger, "Attention: tests are going to take only 1 process. The execution can be slow. "
"You can set the option `--processes` to wished processes quantity "
"or use special value `all` to use all available cores.")
start = datetime.now()
for test_suite in config.test_suites:
plugin = "ets" if test_suite.startswith("ets") else test_suite
runner_class = registry.get_runner(plugin)
if runner_class is not None:
runners.append(runner_class(config))
else:
Log.exception_and_raise(logger, f"Plugin {plugin} not registered")
failed_tests = 0
if not config.general.generate_only:
if config.test_lists.repeats_by_time is None:
for repeat in range(1, config.test_lists.repeats + 1):
repeat_str = f"Run #{repeat} of {config.test_lists.repeats}"
launch_runners(runners, logger, config, repeat, repeat_str)
else:
before = datetime.now()
current = before
end = current + timedelta(seconds=float(config.test_lists.repeats_by_time))
repeat = 1
delta = 0
while current < end:
remains = config.test_lists.repeats_by_time - delta
repeat_str = (f"Run #{repeat} for {config.test_lists.repeats_by_time} sec. "
f"Remains {round(remains)} sec")
launch_runners(runners, logger, config, repeat, repeat_str)
repeat += 1
current = datetime.now()
delta = (current - before).total_seconds()
finish = datetime.now()
Log.default(logger, f"Runner has been working for {round((finish - start).total_seconds())} sec")
registry.cleanup()
sys.exit(0 if failed_tests == 0 else 1)
def launch_runners(runners: List[Runner], logger: Logger, config: Config, repeat: int, repeat_str: str) -> int:
failed_tests = 0
for runner in runners:
Log.all(logger, f"{repeat_str}: Runner {runner.name} started")
runner.before_suite()
runner.run_threads(repeat)
runner.after_suite()
Log.all(logger, f"{repeat_str}: Runner {runner.name} finished")
Log.all(logger, utils.pretty_divider())
failed_tests += runner.summarize()
Log.default(logger, f"{repeat_str}: Runner {runner.name}: {failed_tests} failed tests")
if config.general.coverage.use_llvm_cov:
runner.create_coverage_html()
return failed_tests
def __expand_macros_in_work_dir(config: Config) -> None:
config.general.work_dir = __expand_macros_in_path(config.general.work_dir, config)
def expand_macros(config: Config) -> None:
config.general.build = __expand_macros_in_path(config.general.build, config)
config.general.host_tools = __expand_macros_in_path(config.general.host_tools, config)
config.custom.test_root = __expand_macros_in_path(config.custom.test_root, config)
config.custom.list_root = __expand_macros_in_path(config.custom.list_root, config)
steps = config.steps.steps[:]
for step in steps:
if step.executable_path is not None:
step.executable_path = __expand_macros_in_path(step.executable_path, config)
for item in step.extra:
step.extra[item] = correct_macro(step.extra[item], config)
step.args = __expand_macros_in_list(step.args, config)
for item in step.env:
if isinstance(step.env[item], list):
step.env[item] = __expand_macros_in_list(step.env[item], config)
else:
step.env[item] = correct_macro(step.env[item], config)
config.steps.steps.clear()
config.steps.steps.extend(sorted(steps, key=lambda step_key: step_key.order))
def __expand_macros_in_list(values: List[str], config) -> List[str]:
for index in range(len(values)):
values[index] = correct_macro(values[index], config)
return values
def __expand_macros_in_path(value: str, config: Config) -> str:
return expand_file_name(correct_macro(value, config))
if __name__ == "__main__":
main()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/shirunova_viktoria/urunner.git
git@gitee.com:shirunova_viktoria/urunner.git
shirunova_viktoria
urunner
urunner
master

搜索帮助