blob: 1bf860a41555837bb8b35300ce7f1050b5fbc5b7 [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#
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License version 2 as
7# published by the Free Software Foundation.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License along
15# with this program; if not, write to the Free Software Foundation, Inc.,
16# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18# DESCRIPTION
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050019# This script runs tests defined in meta/lib/oeqa/selftest/
Patrick Williamsc124f4f2015-09-15 14:41:29 -050020# It's purpose is to automate the testing of different bitbake tools.
21# To use it you just need to source your build environment setup script and
22# add the meta-selftest layer to your BBLAYERS.
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050023# Call the script as: "oe-selftest -a" to run all the tests in meta/lib/oeqa/selftest/
24# Call the script as: "oe-selftest -r <module>.<Class>.<method>" to run just a single test
25# 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 -050026
27
Brad Bishopd7bf8c12018-02-25 22:55:05 -050028
Patrick Williamsc124f4f2015-09-15 14:41:29 -050029import os
30import sys
Patrick Williamsc124f4f2015-09-15 14:41:29 -050031import argparse
Brad Bishopd7bf8c12018-02-25 22:55:05 -050032import logging
Patrick Williamsc124f4f2015-09-15 14:41:29 -050033
Brad Bishopd7bf8c12018-02-25 22:55:05 -050034scripts_path = os.path.dirname(os.path.realpath(__file__))
35lib_path = scripts_path + '/lib'
36sys.path = sys.path + [lib_path]
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050037import argparse_oe
Brad Bishopd7bf8c12018-02-25 22:55:05 -050038import scriptutils
39import scriptpath
40scriptpath.add_oe_lib_path()
41scriptpath.add_bitbake_lib_path()
Patrick Williamsc124f4f2015-09-15 14:41:29 -050042
Brad Bishopd7bf8c12018-02-25 22:55:05 -050043from oeqa.utils import load_test_components
44from oeqa.core.exception import OEQAPreRun
Patrick Williamsc124f4f2015-09-15 14:41:29 -050045
Brad Bishopd7bf8c12018-02-25 22:55:05 -050046logger = scriptutils.logger_create('oe-selftest', stream=sys.stdout)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050047
48def main():
Brad Bishopd7bf8c12018-02-25 22:55:05 -050049 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."
50 parser = argparse_oe.ArgumentParser(description=description)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050051
Brad Bishopd7bf8c12018-02-25 22:55:05 -050052 comp_name, comp = load_test_components(logger, 'oe-selftest').popitem()
53 comp.register_commands(logger, parser)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050054
Brad Bishopd7bf8c12018-02-25 22:55:05 -050055 try:
56 args = parser.parse_args()
57 results = args.func(logger, args)
58 ret = 0 if results.wasSuccessful() else 1
59 except SystemExit as err:
60 if err.code != 0:
61 raise err
62 ret = err.code
63 except OEQAPreRun as pr:
64 ret = 1
Brad Bishop6e60e8b2018-02-01 10:27:11 -050065
Brad Bishopd7bf8c12018-02-25 22:55:05 -050066 return ret
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050067
Brad Bishopd7bf8c12018-02-25 22:55:05 -050068if __name__ == '__main__':
Patrick Williamsc124f4f2015-09-15 14:41:29 -050069 try:
70 ret = main()
71 except Exception:
72 ret = 1
73 import traceback
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050074 traceback.print_exc()
Patrick Williamsc124f4f2015-09-15 14:41:29 -050075 sys.exit(ret)