blob: 57662b2f75d0f4ebc02d8d6b41edaabbc132e2e1 [file] [log] [blame]
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001#!/usr/bin/env python3
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002
Brad Bishopd7bf8c12018-02-25 22:55:05 -05003# Copyright (c) 2013-2017 Intel Corporation
Patrick Williamsc124f4f2015-09-15 14:41:29 -05004#
Brad Bishopc342db32019-05-15 21:57:59 -04005# SPDX-License-Identifier: GPL-2.0-only
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006#
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007
8# DESCRIPTION
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05009# This script runs tests defined in meta/lib/oeqa/selftest/
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010# It's purpose is to automate the testing of different bitbake tools.
11# To use it you just need to source your build environment setup script and
12# add the meta-selftest layer to your BBLAYERS.
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050013# Call the script as: "oe-selftest -a" to run all the tests in meta/lib/oeqa/selftest/
14# Call the script as: "oe-selftest -r <module>.<Class>.<method>" to run just a single test
15# E.g: "oe-selftest -r bblayers.BitbakeLayers" will run just the BitbakeLayers class from meta/lib/oeqa/selftest/bblayers.py
Patrick Williamsc124f4f2015-09-15 14:41:29 -050016
17
Brad Bishopd7bf8c12018-02-25 22:55:05 -050018
Patrick Williamsc124f4f2015-09-15 14:41:29 -050019import os
20import sys
Patrick Williamsc124f4f2015-09-15 14:41:29 -050021import argparse
Brad Bishopd7bf8c12018-02-25 22:55:05 -050022import logging
Patrick Williamsc124f4f2015-09-15 14:41:29 -050023
Brad Bishopd7bf8c12018-02-25 22:55:05 -050024scripts_path = os.path.dirname(os.path.realpath(__file__))
25lib_path = scripts_path + '/lib'
26sys.path = sys.path + [lib_path]
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050027import argparse_oe
Brad Bishopd7bf8c12018-02-25 22:55:05 -050028import scriptutils
29import scriptpath
30scriptpath.add_oe_lib_path()
31scriptpath.add_bitbake_lib_path()
Patrick Williamsc124f4f2015-09-15 14:41:29 -050032
Brad Bishopd7bf8c12018-02-25 22:55:05 -050033from oeqa.utils import load_test_components
34from oeqa.core.exception import OEQAPreRun
Patrick Williamsc124f4f2015-09-15 14:41:29 -050035
Brad Bishopd7bf8c12018-02-25 22:55:05 -050036logger = scriptutils.logger_create('oe-selftest', stream=sys.stdout)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050037
38def main():
Brad Bishopd7bf8c12018-02-25 22:55:05 -050039 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."
40 parser = argparse_oe.ArgumentParser(description=description)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050041
Brad Bishopd7bf8c12018-02-25 22:55:05 -050042 comp_name, comp = load_test_components(logger, 'oe-selftest').popitem()
43 comp.register_commands(logger, parser)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050044
Brad Bishopd7bf8c12018-02-25 22:55:05 -050045 try:
46 args = parser.parse_args()
47 results = args.func(logger, args)
48 ret = 0 if results.wasSuccessful() else 1
49 except SystemExit as err:
50 if err.code != 0:
51 raise err
52 ret = err.code
53 except OEQAPreRun as pr:
54 ret = 1
Brad Bishop6e60e8b2018-02-01 10:27:11 -050055
Brad Bishopd7bf8c12018-02-25 22:55:05 -050056 return ret
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050057
Brad Bishopd7bf8c12018-02-25 22:55:05 -050058if __name__ == '__main__':
Patrick Williamsc124f4f2015-09-15 14:41:29 -050059 try:
60 ret = main()
61 except Exception:
62 ret = 1
63 import traceback
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050064 traceback.print_exc()
Patrick Williamsc124f4f2015-09-15 14:41:29 -050065 sys.exit(ret)