Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | |
| 3 | # OpenEmbedded test tool |
| 4 | # |
| 5 | # Copyright (C) 2016 Intel Corporation |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 6 | # |
| 7 | # SPDX-License-Identifier: MIT |
| 8 | # |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 9 | |
| 10 | import os |
| 11 | import sys |
| 12 | import argparse |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 13 | import logging |
| 14 | |
| 15 | scripts_path = os.path.dirname(os.path.realpath(__file__)) |
| 16 | lib_path = scripts_path + '/lib' |
| 17 | sys.path = sys.path + [lib_path] |
| 18 | import argparse_oe |
| 19 | import scriptutils |
| 20 | |
| 21 | # oe-test is used for testexport and it doesn't have oe lib |
| 22 | # so we just skip adding these libraries (not used in testexport) |
| 23 | try: |
| 24 | import scriptpath |
| 25 | scriptpath.add_oe_lib_path() |
| 26 | except ImportError: |
| 27 | pass |
| 28 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 29 | from oeqa.utils import load_test_components |
| 30 | from oeqa.core.exception import OEQAPreRun |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 31 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 32 | logger = scriptutils.logger_create('oe-test', stream=sys.stdout) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 33 | |
| 34 | def main(): |
| 35 | parser = argparse_oe.ArgumentParser(description="OpenEmbedded test tool", |
| 36 | add_help=False, |
| 37 | epilog="Use %(prog)s <subcommand> --help to get help on a specific command") |
| 38 | parser.add_argument('-d', '--debug', help='Enable debug output', action='store_true') |
| 39 | parser.add_argument('-q', '--quiet', help='Print only errors', action='store_true') |
| 40 | global_args, unparsed_args = parser.parse_known_args() |
| 41 | |
| 42 | # Help is added here rather than via add_help=True, as we don't want it to |
| 43 | # be handled by parse_known_args() |
| 44 | parser.add_argument('-h', '--help', action='help', default=argparse.SUPPRESS, |
| 45 | help='show this help message and exit') |
| 46 | |
| 47 | if global_args.debug: |
| 48 | logger.setLevel(logging.DEBUG) |
| 49 | elif global_args.quiet: |
| 50 | logger.setLevel(logging.ERROR) |
| 51 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 52 | components = load_test_components(logger, 'oe-test') |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 53 | |
| 54 | subparsers = parser.add_subparsers(dest="subparser_name", title='subcommands', metavar='<subcommand>') |
| 55 | subparsers.add_subparser_group('components', 'Test components') |
| 56 | subparsers.required = True |
| 57 | for comp_name in sorted(components.keys()): |
| 58 | comp = components[comp_name] |
| 59 | comp.register_commands(logger, subparsers) |
| 60 | |
| 61 | try: |
| 62 | args = parser.parse_args(unparsed_args, namespace=global_args) |
| 63 | results = args.func(logger, args) |
| 64 | ret = 0 if results.wasSuccessful() else 1 |
| 65 | except SystemExit as err: |
| 66 | if err.code != 0: |
| 67 | raise err |
| 68 | ret = err.code |
| 69 | except argparse_oe.ArgumentUsageError as ae: |
| 70 | parser.error_subcommand(ae.message, ae.subcommand) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 71 | except OEQAPreRun as pr: |
| 72 | ret = 1 |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 73 | |
| 74 | return ret |
| 75 | |
| 76 | if __name__ == '__main__': |
| 77 | try: |
| 78 | ret = main() |
| 79 | except Exception: |
| 80 | ret = 1 |
| 81 | import traceback |
| 82 | traceback.print_exc() |
| 83 | sys.exit(ret) |