xref: /OK3568_Linux_fs/yocto/poky/scripts/oe-test (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1#!/usr/bin/env python3
2
3# OpenEmbedded test tool
4#
5# Copyright (C) 2016 Intel Corporation
6#
7# SPDX-License-Identifier: MIT
8#
9
10import os
11import sys
12import argparse
13import logging
14
15scripts_path = os.path.dirname(os.path.realpath(__file__))
16lib_path = scripts_path + '/lib'
17sys.path = sys.path + [lib_path]
18import argparse_oe
19import 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)
23try:
24    import scriptpath
25    scriptpath.add_oe_lib_path()
26except ImportError:
27    pass
28
29from oeqa.utils import load_test_components
30from oeqa.core.exception import OEQAPreRun
31
32logger = scriptutils.logger_create('oe-test', stream=sys.stdout)
33
34def 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
52    components = load_test_components(logger, 'oe-test')
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)
71    except OEQAPreRun as pr:
72        ret = 1
73
74    return ret
75
76if __name__ == '__main__':
77    try:
78        ret = main()
79    except Exception:
80        ret = 1
81        import traceback
82        traceback.print_exc()
83    sys.exit(ret)
84