xref: /OK3568_Linux_fs/yocto/scripts/resulttool (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun#!/usr/bin/env python3
2*4882a593Smuzhiyun#
3*4882a593Smuzhiyun# test results tool - tool for manipulating OEQA test result json files
4*4882a593Smuzhiyun# (merge results, summarise results, regression analysis, generate manual test results file)
5*4882a593Smuzhiyun#
6*4882a593Smuzhiyun# To look for help information.
7*4882a593Smuzhiyun#    $ resulttool
8*4882a593Smuzhiyun#
9*4882a593Smuzhiyun# To store test results from oeqa automated tests, execute the below
10*4882a593Smuzhiyun#     $ resulttool store <source_dir> <git_branch>
11*4882a593Smuzhiyun#
12*4882a593Smuzhiyun# To merge test results, execute the below
13*4882a593Smuzhiyun#    $ resulttool merge <base_result_file> <target_result_file>
14*4882a593Smuzhiyun#
15*4882a593Smuzhiyun# To report test report, execute the below
16*4882a593Smuzhiyun#     $ resulttool report <source_dir>
17*4882a593Smuzhiyun#
18*4882a593Smuzhiyun# To perform regression file analysis, execute the below
19*4882a593Smuzhiyun#     $ resulttool regression-file <base_result_file> <target_result_file>
20*4882a593Smuzhiyun#
21*4882a593Smuzhiyun# To execute manual test cases, execute the below
22*4882a593Smuzhiyun#     $ resulttool manualexecution <manualjsonfile>
23*4882a593Smuzhiyun#
24*4882a593Smuzhiyun# By default testresults.json for manualexecution store in <build>/tmp/log/manual/
25*4882a593Smuzhiyun#
26*4882a593Smuzhiyun# Copyright (c) 2019, Intel Corporation.
27*4882a593Smuzhiyun#
28*4882a593Smuzhiyun# SPDX-License-Identifier: GPL-2.0-only
29*4882a593Smuzhiyun#
30*4882a593Smuzhiyun
31*4882a593Smuzhiyunimport os
32*4882a593Smuzhiyunimport sys
33*4882a593Smuzhiyunimport argparse
34*4882a593Smuzhiyunimport logging
35*4882a593Smuzhiyunscript_path = os.path.dirname(os.path.realpath(__file__))
36*4882a593Smuzhiyunlib_path = script_path + '/lib'
37*4882a593Smuzhiyunsys.path = sys.path + [lib_path]
38*4882a593Smuzhiyunimport argparse_oe
39*4882a593Smuzhiyunimport scriptutils
40*4882a593Smuzhiyunimport resulttool.merge
41*4882a593Smuzhiyunimport resulttool.store
42*4882a593Smuzhiyunimport resulttool.regression
43*4882a593Smuzhiyunimport resulttool.report
44*4882a593Smuzhiyunimport resulttool.manualexecution
45*4882a593Smuzhiyunimport resulttool.log
46*4882a593Smuzhiyunlogger = scriptutils.logger_create('resulttool')
47*4882a593Smuzhiyun
48*4882a593Smuzhiyundef main():
49*4882a593Smuzhiyun    parser = argparse_oe.ArgumentParser(description="OEQA test result manipulation tool.",
50*4882a593Smuzhiyun                                        epilog="Use %(prog)s <subcommand> --help to get help on a specific command")
51*4882a593Smuzhiyun    parser.add_argument('-d', '--debug', help='enable debug output', action='store_true')
52*4882a593Smuzhiyun    parser.add_argument('-q', '--quiet', help='print only errors', action='store_true')
53*4882a593Smuzhiyun    subparsers = parser.add_subparsers(dest="subparser_name", title='subcommands', metavar='<subcommand>')
54*4882a593Smuzhiyun    subparsers.required = True
55*4882a593Smuzhiyun    subparsers.add_subparser_group('manualexecution', 'manual testcases', 300)
56*4882a593Smuzhiyun    resulttool.manualexecution.register_commands(subparsers)
57*4882a593Smuzhiyun    subparsers.add_subparser_group('setup', 'setup', 200)
58*4882a593Smuzhiyun    resulttool.merge.register_commands(subparsers)
59*4882a593Smuzhiyun    resulttool.store.register_commands(subparsers)
60*4882a593Smuzhiyun    subparsers.add_subparser_group('analysis', 'analysis', 100)
61*4882a593Smuzhiyun    resulttool.regression.register_commands(subparsers)
62*4882a593Smuzhiyun    resulttool.report.register_commands(subparsers)
63*4882a593Smuzhiyun    resulttool.log.register_commands(subparsers)
64*4882a593Smuzhiyun
65*4882a593Smuzhiyun    args = parser.parse_args()
66*4882a593Smuzhiyun    if args.debug:
67*4882a593Smuzhiyun        logger.setLevel(logging.DEBUG)
68*4882a593Smuzhiyun    elif args.quiet:
69*4882a593Smuzhiyun        logger.setLevel(logging.ERROR)
70*4882a593Smuzhiyun
71*4882a593Smuzhiyun    try:
72*4882a593Smuzhiyun        ret = args.func(args, logger)
73*4882a593Smuzhiyun    except argparse_oe.ArgumentUsageError as ae:
74*4882a593Smuzhiyun        parser.error_subcommand(ae.message, ae.subcommand)
75*4882a593Smuzhiyun    return ret
76*4882a593Smuzhiyun
77*4882a593Smuzhiyunif __name__ == "__main__":
78*4882a593Smuzhiyun    sys.exit(main())
79