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