xref: /OK3568_Linux_fs/yocto/scripts/oe-selftest (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun#!/usr/bin/env python3
2*4882a593Smuzhiyun
3*4882a593Smuzhiyun# Copyright (c) 2013-2017 Intel Corporation
4*4882a593Smuzhiyun#
5*4882a593Smuzhiyun# SPDX-License-Identifier: GPL-2.0-only
6*4882a593Smuzhiyun#
7*4882a593Smuzhiyun
8*4882a593Smuzhiyun# DESCRIPTION
9*4882a593Smuzhiyun# This script runs tests defined in meta/lib/oeqa/selftest/
10*4882a593Smuzhiyun# It's purpose is to automate the testing of different bitbake tools.
11*4882a593Smuzhiyun# To use it you just need to source your build environment setup script and
12*4882a593Smuzhiyun# add the meta-selftest layer to your BBLAYERS.
13*4882a593Smuzhiyun# Call the script as: "oe-selftest -a" to run all the tests in meta/lib/oeqa/selftest/
14*4882a593Smuzhiyun# Call the script as: "oe-selftest -r <module>.<Class>.<method>" to run just a single test
15*4882a593Smuzhiyun# E.g: "oe-selftest -r bblayers.BitbakeLayers" will run just the BitbakeLayers class from meta/lib/oeqa/selftest/bblayers.py
16*4882a593Smuzhiyun
17*4882a593Smuzhiyun
18*4882a593Smuzhiyun
19*4882a593Smuzhiyunimport os
20*4882a593Smuzhiyunimport sys
21*4882a593Smuzhiyunimport argparse
22*4882a593Smuzhiyunimport logging
23*4882a593Smuzhiyun
24*4882a593Smuzhiyunscripts_path = os.path.dirname(os.path.realpath(__file__))
25*4882a593Smuzhiyunlib_path = scripts_path + '/lib'
26*4882a593Smuzhiyunsys.path = sys.path + [lib_path]
27*4882a593Smuzhiyunimport argparse_oe
28*4882a593Smuzhiyunimport scriptutils
29*4882a593Smuzhiyunimport scriptpath
30*4882a593Smuzhiyunscriptpath.add_oe_lib_path()
31*4882a593Smuzhiyunscriptpath.add_bitbake_lib_path()
32*4882a593Smuzhiyun
33*4882a593Smuzhiyunfrom oeqa.utils import load_test_components
34*4882a593Smuzhiyunfrom oeqa.core.exception import OEQAPreRun
35*4882a593Smuzhiyun
36*4882a593Smuzhiyunlogger = scriptutils.logger_create('oe-selftest', stream=sys.stdout, keepalive=True)
37*4882a593Smuzhiyun
38*4882a593Smuzhiyundef main():
39*4882a593Smuzhiyun    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*4882a593Smuzhiyun    parser = argparse_oe.ArgumentParser(description=description)
41*4882a593Smuzhiyun
42*4882a593Smuzhiyun    comp_name, comp = load_test_components(logger, 'oe-selftest').popitem()
43*4882a593Smuzhiyun    comp.register_commands(logger, parser)
44*4882a593Smuzhiyun
45*4882a593Smuzhiyun    try:
46*4882a593Smuzhiyun        args = parser.parse_args()
47*4882a593Smuzhiyun        results = args.func(logger, args)
48*4882a593Smuzhiyun        ret = 0 if results.wasSuccessful() else 1
49*4882a593Smuzhiyun    except SystemExit as err:
50*4882a593Smuzhiyun        if err.code != 0:
51*4882a593Smuzhiyun            raise err
52*4882a593Smuzhiyun        ret = err.code
53*4882a593Smuzhiyun    except OEQAPreRun as pr:
54*4882a593Smuzhiyun        ret = 1
55*4882a593Smuzhiyun
56*4882a593Smuzhiyun    return ret
57*4882a593Smuzhiyun
58*4882a593Smuzhiyunif __name__ == '__main__':
59*4882a593Smuzhiyun    try:
60*4882a593Smuzhiyun        ret = main()
61*4882a593Smuzhiyun    except Exception:
62*4882a593Smuzhiyun        ret = 1
63*4882a593Smuzhiyun        import traceback
64*4882a593Smuzhiyun        traceback.print_exc()
65*4882a593Smuzhiyun    sys.exit(ret)
66