xref: /openbmc/openbmc/poky/scripts/oe-selftest (revision c9537f57ab488bf5d90132917b0184e2527970a5)
1#!/usr/bin/env python3
2
3# Copyright (c) 2013-2017 Intel Corporation
4#
5# SPDX-License-Identifier: GPL-2.0-only
6#
7
8# DESCRIPTION
9# This script runs tests defined in meta/lib/oeqa/selftest/
10# 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.
13# 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
16
17
18
19import os
20import sys
21
22scripts_path = os.path.dirname(os.path.realpath(__file__))
23lib_path = scripts_path + '/lib'
24sys.path = sys.path + [lib_path]
25import argparse_oe
26import scriptutils
27import scriptpath
28scriptpath.add_oe_lib_path()
29scriptpath.add_bitbake_lib_path()
30
31from oeqa.utils import load_test_components
32from oeqa.core.exception import OEQAPreRun
33
34logger = scriptutils.logger_create('oe-selftest', stream=sys.stdout, keepalive=True)
35
36def main():
37    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."
38    parser = argparse_oe.ArgumentParser(description=description)
39
40    comp_name, comp = load_test_components(logger, 'oe-selftest').popitem()
41    comp.register_commands(logger, parser)
42
43    try:
44        args = parser.parse_args()
45        results = args.func(logger, args)
46        ret = 0 if results.wasSuccessful() else 1
47    except SystemExit as err:
48        if err.code != 0:
49            raise err
50        ret = err.code
51    except OEQAPreRun as pr:
52        ret = 1
53
54    return ret
55
56if __name__ == '__main__':
57    try:
58        ret = main()
59    except Exception:
60        ret = 1
61        import traceback
62        traceback.print_exc()
63    sys.exit(ret)
64