rjw | 1f88458 | 2022-01-06 17:20:42 +0800 | [diff] [blame^] | 1 | #!/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 | |
| 29 | import os |
| 30 | import sys |
| 31 | import argparse |
| 32 | import logging |
| 33 | |
| 34 | scripts_path = os.path.dirname(os.path.realpath(__file__)) |
| 35 | lib_path = scripts_path + '/lib' |
| 36 | sys.path = sys.path + [lib_path] |
| 37 | import argparse_oe |
| 38 | import scriptutils |
| 39 | import scriptpath |
| 40 | scriptpath.add_oe_lib_path() |
| 41 | scriptpath.add_bitbake_lib_path() |
| 42 | |
| 43 | from oeqa.utils import load_test_components |
| 44 | from oeqa.core.exception import OEQAPreRun |
| 45 | |
| 46 | logger = scriptutils.logger_create('oe-selftest', stream=sys.stdout) |
| 47 | |
| 48 | def 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 | |
| 68 | if __name__ == '__main__': |
| 69 | try: |
| 70 | ret = main() |
| 71 | except Exception: |
| 72 | ret = 1 |
| 73 | import traceback |
| 74 | traceback.print_exc() |
| 75 | sys.exit(ret) |