blob: 34d9012d14311b6e7c83fcc535c4a83e08ff4f64 [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
6# Released under the MIT license (see COPYING.MIT)
7
8import os
9import sys
10import argparse
Brad Bishop6e60e8b2018-02-01 10:27:11 -050011import logging
12
13scripts_path = os.path.dirname(os.path.realpath(__file__))
14lib_path = scripts_path + '/lib'
15sys.path = sys.path + [lib_path]
16import argparse_oe
17import 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)
21try:
22 import scriptpath
23 scriptpath.add_oe_lib_path()
24except ImportError:
25 pass
26
Brad Bishopd7bf8c12018-02-25 22:55:05 -050027from oeqa.utils import load_test_components
28from oeqa.core.exception import OEQAPreRun
Brad Bishop6e60e8b2018-02-01 10:27:11 -050029
Brad Bishopd7bf8c12018-02-25 22:55:05 -050030logger = scriptutils.logger_create('oe-test', stream=sys.stdout)
Brad Bishop6e60e8b2018-02-01 10:27:11 -050031
32def 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 Bishopd7bf8c12018-02-25 22:55:05 -050050 components = load_test_components(logger, 'oe-test')
Brad Bishop6e60e8b2018-02-01 10:27:11 -050051
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 Bishopd7bf8c12018-02-25 22:55:05 -050069 except OEQAPreRun as pr:
70 ret = 1
Brad Bishop6e60e8b2018-02-01 10:27:11 -050071
72 return ret
73
74if __name__ == '__main__':
75 try:
76 ret = main()
77 except Exception:
78 ret = 1
79 import traceback
80 traceback.print_exc()
81 sys.exit(ret)