blob: 55985b0b2453da7ff5bf7e3e46931b437537441a [file] [log] [blame]
Brad Bishop6e60e8b2018-02-01 10:27:11 -05001#!/usr/bin/env python3
2
3# OpenEmbedded test tool
4#
5# Copyright (C) 2016 Intel Corporation
Brad Bishopc342db32019-05-15 21:57:59 -04006#
7# SPDX-License-Identifier: MIT
8#
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009
10import os
11import sys
12import argparse
Brad Bishop6e60e8b2018-02-01 10:27:11 -050013import 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
Brad Bishopd7bf8c12018-02-25 22:55:05 -050029from oeqa.utils import load_test_components
30from oeqa.core.exception import OEQAPreRun
Brad Bishop6e60e8b2018-02-01 10:27:11 -050031
Brad Bishopd7bf8c12018-02-25 22:55:05 -050032logger = scriptutils.logger_create('oe-test', stream=sys.stdout)
Brad Bishop6e60e8b2018-02-01 10:27:11 -050033
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
Brad Bishopd7bf8c12018-02-25 22:55:05 -050052 components = load_test_components(logger, 'oe-test')
Brad Bishop6e60e8b2018-02-01 10:27:11 -050053
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 Bishopd7bf8c12018-02-25 22:55:05 -050071 except OEQAPreRun as pr:
72 ret = 1
Brad Bishop6e60e8b2018-02-01 10:27:11 -050073
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)