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