xref: /openbmc/openbmc/poky/scripts/oe-selftest (revision 79641f25)
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
21import argparse
22import logging
23
24scripts_path = os.path.dirname(os.path.realpath(__file__))
25lib_path = scripts_path + '/lib'
26sys.path = sys.path + [lib_path]
27import argparse_oe
28import scriptutils
29import scriptpath
30scriptpath.add_oe_lib_path()
31scriptpath.add_bitbake_lib_path()
32
33from oeqa.utils import load_test_components
34from oeqa.core.exception import OEQAPreRun
35
36logger = scriptutils.logger_create('oe-selftest', stream=sys.stdout, keepalive=True)
37
38def main():
39    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)
41
42    comp_name, comp = load_test_components(logger, 'oe-selftest').popitem()
43    comp.register_commands(logger, parser)
44
45    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
55
56    return ret
57
58if __name__ == '__main__':
59    try:
60        ret = main()
61    except Exception:
62        ret = 1
63        import traceback
64        traceback.print_exc()
65    sys.exit(ret)
66