blob: 1bf860a41555837bb8b35300ce7f1050b5fbc5b7 [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001#!/usr/bin/env python3
2
3# Copyright (c) 2013-2017 Intel Corporation
4#
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
19# This script runs tests defined in meta/lib/oeqa/selftest/
20# 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.
23# 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
26
27
28
29import os
30import sys
31import argparse
32import logging
33
34scripts_path = os.path.dirname(os.path.realpath(__file__))
35lib_path = scripts_path + '/lib'
36sys.path = sys.path + [lib_path]
37import argparse_oe
38import scriptutils
39import scriptpath
40scriptpath.add_oe_lib_path()
41scriptpath.add_bitbake_lib_path()
42
43from oeqa.utils import load_test_components
44from oeqa.core.exception import OEQAPreRun
45
46logger = scriptutils.logger_create('oe-selftest', stream=sys.stdout)
47
48def main():
49 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)
51
52 comp_name, comp = load_test_components(logger, 'oe-selftest').popitem()
53 comp.register_commands(logger, parser)
54
55 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
65
66 return ret
67
68if __name__ == '__main__':
69 try:
70 ret = main()
71 except Exception:
72 ret = 1
73 import traceback
74 traceback.print_exc()
75 sys.exit(ret)