xref: /openbmc/openbmc/poky/scripts/resulttool (revision 8460358c3d24c71d9d38fd126c745854a6301564)
140320b10SBrad Bishop#!/usr/bin/env python3
240320b10SBrad Bishop#
340320b10SBrad Bishop# test results tool - tool for manipulating OEQA test result json files
440320b10SBrad Bishop# (merge results, summarise results, regression analysis, generate manual test results file)
540320b10SBrad Bishop#
640320b10SBrad Bishop# To look for help information.
740320b10SBrad Bishop#    $ resulttool
840320b10SBrad Bishop#
940320b10SBrad Bishop# To store test results from oeqa automated tests, execute the below
1040320b10SBrad Bishop#     $ resulttool store <source_dir> <git_branch>
1140320b10SBrad Bishop#
1240320b10SBrad Bishop# To merge test results, execute the below
1340320b10SBrad Bishop#    $ resulttool merge <base_result_file> <target_result_file>
1440320b10SBrad Bishop#
1540320b10SBrad Bishop# To report test report, execute the below
1640320b10SBrad Bishop#     $ resulttool report <source_dir>
1740320b10SBrad Bishop#
18*8460358cSPatrick Williams# To create a unit test report in JUnit XML format, execute the below
19*8460358cSPatrick Williams#     $ resulttool junit <json_file>
20*8460358cSPatrick Williams#
2140320b10SBrad Bishop# To perform regression file analysis, execute the below
2240320b10SBrad Bishop#     $ resulttool regression-file <base_result_file> <target_result_file>
2340320b10SBrad Bishop#
2440320b10SBrad Bishop# To execute manual test cases, execute the below
2540320b10SBrad Bishop#     $ resulttool manualexecution <manualjsonfile>
2640320b10SBrad Bishop#
2740320b10SBrad Bishop# By default testresults.json for manualexecution store in <build>/tmp/log/manual/
2840320b10SBrad Bishop#
2940320b10SBrad Bishop# Copyright (c) 2019, Intel Corporation.
3040320b10SBrad Bishop#
31c342db35SBrad Bishop# SPDX-License-Identifier: GPL-2.0-only
3240320b10SBrad Bishop#
3340320b10SBrad Bishop
3440320b10SBrad Bishopimport os
3540320b10SBrad Bishopimport sys
3640320b10SBrad Bishopimport argparse
3740320b10SBrad Bishopimport logging
3840320b10SBrad Bishopscript_path = os.path.dirname(os.path.realpath(__file__))
3940320b10SBrad Bishoplib_path = script_path + '/lib'
4040320b10SBrad Bishopsys.path = sys.path + [lib_path]
4140320b10SBrad Bishopimport argparse_oe
4240320b10SBrad Bishopimport scriptutils
4340320b10SBrad Bishopimport resulttool.merge
4440320b10SBrad Bishopimport resulttool.store
4540320b10SBrad Bishopimport resulttool.regression
4640320b10SBrad Bishopimport resulttool.report
4740320b10SBrad Bishopimport resulttool.manualexecution
48c342db35SBrad Bishopimport resulttool.log
49*8460358cSPatrick Williamsimport resulttool.junit
5040320b10SBrad Bishoplogger = scriptutils.logger_create('resulttool')
5140320b10SBrad Bishop
5240320b10SBrad Bishopdef main():
5340320b10SBrad Bishop    parser = argparse_oe.ArgumentParser(description="OEQA test result manipulation tool.",
5440320b10SBrad Bishop                                        epilog="Use %(prog)s <subcommand> --help to get help on a specific command")
5540320b10SBrad Bishop    parser.add_argument('-d', '--debug', help='enable debug output', action='store_true')
5640320b10SBrad Bishop    parser.add_argument('-q', '--quiet', help='print only errors', action='store_true')
5740320b10SBrad Bishop    subparsers = parser.add_subparsers(dest="subparser_name", title='subcommands', metavar='<subcommand>')
5840320b10SBrad Bishop    subparsers.required = True
5940320b10SBrad Bishop    subparsers.add_subparser_group('manualexecution', 'manual testcases', 300)
6040320b10SBrad Bishop    resulttool.manualexecution.register_commands(subparsers)
6140320b10SBrad Bishop    subparsers.add_subparser_group('setup', 'setup', 200)
6240320b10SBrad Bishop    resulttool.merge.register_commands(subparsers)
6340320b10SBrad Bishop    resulttool.store.register_commands(subparsers)
6440320b10SBrad Bishop    subparsers.add_subparser_group('analysis', 'analysis', 100)
6540320b10SBrad Bishop    resulttool.regression.register_commands(subparsers)
6640320b10SBrad Bishop    resulttool.report.register_commands(subparsers)
67c342db35SBrad Bishop    resulttool.log.register_commands(subparsers)
68*8460358cSPatrick Williams    resulttool.junit.register_commands(subparsers)
6940320b10SBrad Bishop
7040320b10SBrad Bishop    args = parser.parse_args()
7140320b10SBrad Bishop    if args.debug:
7240320b10SBrad Bishop        logger.setLevel(logging.DEBUG)
7340320b10SBrad Bishop    elif args.quiet:
7440320b10SBrad Bishop        logger.setLevel(logging.ERROR)
7540320b10SBrad Bishop
7640320b10SBrad Bishop    try:
7740320b10SBrad Bishop        ret = args.func(args, logger)
7840320b10SBrad Bishop    except argparse_oe.ArgumentUsageError as ae:
7940320b10SBrad Bishop        parser.error_subcommand(ae.message, ae.subcommand)
8040320b10SBrad Bishop    return ret
8140320b10SBrad Bishop
8240320b10SBrad Bishopif __name__ == "__main__":
8340320b10SBrad Bishop    sys.exit(main())
84