xref: /arkcompiler/toolchain/test/autotest/run.py (revision e509ee18)
1e509ee18Sopenharmony_ci#!/usr/bin/env python3
2e509ee18Sopenharmony_ci# -*- coding: utf-8 -*-
3e509ee18Sopenharmony_ci"""
4e509ee18Sopenharmony_ciCopyright (c) 2024 Huawei Device Co., Ltd.
5e509ee18Sopenharmony_ciLicensed under the Apache License, Version 2.0 (the "License");
6e509ee18Sopenharmony_ciyou may not use this file except in compliance with the License.
7e509ee18Sopenharmony_ciYou may obtain a copy of the License at
8e509ee18Sopenharmony_ci
9e509ee18Sopenharmony_ci    http://www.apache.org/licenses/LICENSE-2.0
10e509ee18Sopenharmony_ci
11e509ee18Sopenharmony_ciUnless required by applicable law or agreed to in writing, software
12e509ee18Sopenharmony_cidistributed under the License is distributed on an "AS IS" BASIS,
13e509ee18Sopenharmony_ciWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14e509ee18Sopenharmony_ciSee the License for the specific language governing permissions and
15e509ee18Sopenharmony_cilimitations under the License.
16e509ee18Sopenharmony_ci
17e509ee18Sopenharmony_ciDescription: Run all test cases.
18e509ee18Sopenharmony_ci"""
19e509ee18Sopenharmony_ci
20e509ee18Sopenharmony_ciimport logging
21e509ee18Sopenharmony_ciimport os
22e509ee18Sopenharmony_ciimport subprocess
23e509ee18Sopenharmony_ciimport sys
24e509ee18Sopenharmony_ci
25e509ee18Sopenharmony_ciimport pytest
26e509ee18Sopenharmony_ci
27e509ee18Sopenharmony_cisys.path.append(os.path.join(os.path.dirname(__file__), '..'))
28e509ee18Sopenharmony_ci
29e509ee18Sopenharmony_ci
30e509ee18Sopenharmony_cidef check_python_version():
31e509ee18Sopenharmony_ci    required_version = (3, 8, 0)
32e509ee18Sopenharmony_ci    current_version = sys.version_info
33e509ee18Sopenharmony_ci
34e509ee18Sopenharmony_ci    if current_version >= required_version:
35e509ee18Sopenharmony_ci        logging.info(f"Python version meets requirements: "
36e509ee18Sopenharmony_ci                     f"{current_version.major}.{current_version.minor}.{current_version.micro}")
37e509ee18Sopenharmony_ci    else:
38e509ee18Sopenharmony_ci        logging.error(f"Python version too low: "
39e509ee18Sopenharmony_ci                      f"{current_version.major}.{current_version.minor}.{current_version.micro}, "
40e509ee18Sopenharmony_ci                      f"needs to be at least 3.8.0")
41e509ee18Sopenharmony_ci        sys.exit(1)
42e509ee18Sopenharmony_ci
43e509ee18Sopenharmony_ci
44e509ee18Sopenharmony_cidef install_requirements(requirements_file=r'.\requirements.txt'):
45e509ee18Sopenharmony_ci    try:
46e509ee18Sopenharmony_ci        subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-r', requirements_file], timeout=10)
47e509ee18Sopenharmony_ci        logging.info(f'Successfully installed dependencies from {requirements_file}')
48e509ee18Sopenharmony_ci    except subprocess.CalledProcessError as e:
49e509ee18Sopenharmony_ci        logging.error(f'Error occurred while installing dependencies: {e}')
50e509ee18Sopenharmony_ci        sys.exit(1)
51e509ee18Sopenharmony_ci
52e509ee18Sopenharmony_ci
53e509ee18Sopenharmony_cidef clear_log_handler():
54e509ee18Sopenharmony_ci    # remove all old handlers of the root logger
55e509ee18Sopenharmony_ci    log = logging.getLogger()
56e509ee18Sopenharmony_ci    for handler in log.handlers[:]:
57e509ee18Sopenharmony_ci        log.removeHandler(handler)
58e509ee18Sopenharmony_ci
59e509ee18Sopenharmony_ci
60e509ee18Sopenharmony_ciif __name__ == '__main__':
61e509ee18Sopenharmony_ci    check_python_version()
62e509ee18Sopenharmony_ci    install_requirements()
63e509ee18Sopenharmony_ci
64e509ee18Sopenharmony_ci    clear_log_handler()
65e509ee18Sopenharmony_ci
66e509ee18Sopenharmony_ci    args = sys.argv[1:]
67e509ee18Sopenharmony_ci
68e509ee18Sopenharmony_ci    pytest.main(args)
69