1eb8dc403SDave Cobbley#!/usr/bin/env python3 2eb8dc403SDave Cobbley 3eb8dc403SDave Cobbley# Copyright (c) 2013-2017 Intel Corporation 4eb8dc403SDave Cobbley# 5c342db35SBrad Bishop# SPDX-License-Identifier: GPL-2.0-only 6eb8dc403SDave Cobbley# 7eb8dc403SDave Cobbley 8eb8dc403SDave Cobbley# DESCRIPTION 9eb8dc403SDave Cobbley# This script runs tests defined in meta/lib/oeqa/selftest/ 10eb8dc403SDave Cobbley# It's purpose is to automate the testing of different bitbake tools. 11eb8dc403SDave Cobbley# To use it you just need to source your build environment setup script and 12eb8dc403SDave Cobbley# add the meta-selftest layer to your BBLAYERS. 13eb8dc403SDave Cobbley# Call the script as: "oe-selftest -a" to run all the tests in meta/lib/oeqa/selftest/ 14eb8dc403SDave Cobbley# Call the script as: "oe-selftest -r <module>.<Class>.<method>" to run just a single test 15eb8dc403SDave Cobbley# E.g: "oe-selftest -r bblayers.BitbakeLayers" will run just the BitbakeLayers class from meta/lib/oeqa/selftest/bblayers.py 16eb8dc403SDave Cobbley 17eb8dc403SDave Cobbley 18eb8dc403SDave Cobbley 19eb8dc403SDave Cobbleyimport os 20eb8dc403SDave Cobbleyimport sys 21eb8dc403SDave Cobbleyimport argparse 22eb8dc403SDave Cobbleyimport logging 23eb8dc403SDave Cobbley 24eb8dc403SDave Cobbleyscripts_path = os.path.dirname(os.path.realpath(__file__)) 25eb8dc403SDave Cobbleylib_path = scripts_path + '/lib' 26eb8dc403SDave Cobbleysys.path = sys.path + [lib_path] 27eb8dc403SDave Cobbleyimport argparse_oe 28eb8dc403SDave Cobbleyimport scriptutils 29eb8dc403SDave Cobbleyimport scriptpath 30eb8dc403SDave Cobbleyscriptpath.add_oe_lib_path() 31eb8dc403SDave Cobbleyscriptpath.add_bitbake_lib_path() 32eb8dc403SDave Cobbley 33eb8dc403SDave Cobbleyfrom oeqa.utils import load_test_components 34eb8dc403SDave Cobbleyfrom oeqa.core.exception import OEQAPreRun 35eb8dc403SDave Cobbley 36*79641f25SBrad Bishoplogger = scriptutils.logger_create('oe-selftest', stream=sys.stdout, keepalive=True) 37eb8dc403SDave Cobbley 38eb8dc403SDave Cobbleydef main(): 39eb8dc403SDave Cobbley description = "Script that runs unit tests against bitbake and other Yocto related tools. The goal is to validate tools functionality and metadata integrity. Refer to https://wiki.yoctoproject.org/wiki/Oe-selftest for more information." 40eb8dc403SDave Cobbley parser = argparse_oe.ArgumentParser(description=description) 41eb8dc403SDave Cobbley 42eb8dc403SDave Cobbley comp_name, comp = load_test_components(logger, 'oe-selftest').popitem() 43eb8dc403SDave Cobbley comp.register_commands(logger, parser) 44eb8dc403SDave Cobbley 45eb8dc403SDave Cobbley try: 46eb8dc403SDave Cobbley args = parser.parse_args() 47eb8dc403SDave Cobbley results = args.func(logger, args) 48eb8dc403SDave Cobbley ret = 0 if results.wasSuccessful() else 1 49eb8dc403SDave Cobbley except SystemExit as err: 50eb8dc403SDave Cobbley if err.code != 0: 51eb8dc403SDave Cobbley raise err 52eb8dc403SDave Cobbley ret = err.code 53eb8dc403SDave Cobbley except OEQAPreRun as pr: 54eb8dc403SDave Cobbley ret = 1 55eb8dc403SDave Cobbley 56eb8dc403SDave Cobbley return ret 57eb8dc403SDave Cobbley 58eb8dc403SDave Cobbleyif __name__ == '__main__': 59eb8dc403SDave Cobbley try: 60eb8dc403SDave Cobbley ret = main() 61eb8dc403SDave Cobbley except Exception: 62eb8dc403SDave Cobbley ret = 1 63eb8dc403SDave Cobbley import traceback 64eb8dc403SDave Cobbley traceback.print_exc() 65eb8dc403SDave Cobbley sys.exit(ret) 66