summaryrefslogtreecommitdiffstats
path: root/scripts/test-result-log
blob: a66be0b453e81b35fe8cd1c6444fd5011552eb4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/python3
# As part of the initiative to provide LITE version Test Case Management System
# with command-line and plain-text files (eg. manual test case file, test plan
# file to specify list of test case to be executed, test result and log file)
# to replace Testopia.
# Test-result-log script was designed as part of the helper script for below purpose:
# 1. To store test result & log file inside git repository
# 2. To view text-based test summary report
# 3. To enable planning of test cases for execution and track its completion
#
import os
import sys
import argparse
script_path = os.path.dirname(os.path.realpath(__file__))
lib_path = script_path + '/lib'
sys.path = sys.path + [lib_path]
import argparse_oe
import testresultlog.testplan
import testresultlog.storeauto
import testresultlog.storemanual
import testresultlog.view

def _get_git_dir(git_dir):
    base_path = script_path + '/..'
    if git_dir == 'default':
        git_dir = os.path.join(base_path, 'test-result-log.git')
    return git_dir

def _get_oe_dir(oe_dir):
    base_path = script_path + '/..'
    if oe_dir == 'default':
        oe_dir = base_path
    return oe_dir

def _get_oeqa_case_dir(oe_dir, source):
    if source == 'runtime':
        case_dir = os.path.join(oe_dir, 'meta/lib/oeqa/runtime/cases')
    elif source == 'selftest':
        case_dir = os.path.join(oe_dir, 'meta/lib/oeqa/selftest/cases')
    elif source == 'sdk':
        case_dir = os.path.join(oe_dir, 'meta/lib/oeqa/sdk/cases')
    else:
        case_dir = os.path.join(oe_dir, 'meta/lib/oeqa/sdkext/cases')
    return case_dir

def _get_default_attribute_value(attribute_value):
    if attribute_value == 'default':
        attribute_value = ''
    return attribute_value

def _set_args_attribute_default_value(args):
    if getattr(args, "environment_list", False):
        print('Found environment_list attribute')
        args.environment_list = _get_default_attribute_value(args.environment_list)
    if getattr(args, "git_remote", False):
        print('Found git_remote attribute')
        args.git_remote = _get_default_attribute_value(args.git_remote)
    if getattr(args, "testcase_remove_file", False):
        print('Found testcase_remove_file attribute')
        args.testcase_remove_file = _get_default_attribute_value(args.testcase_remove_file)

def main():
    parser = argparse_oe.ArgumentParser(description="OpenEmbedded testcase management tool, to store test result then to view test summary report.",
                                        add_help=False,
                                        epilog="Use %(prog)s <subcommand> --help to get help on a specific command")
    parser.add_argument('-h', '--help', action='help', default=argparse.SUPPRESS,
                        help='show this help message and exit')
    subparsers = parser.add_subparsers(dest="subparser_name", title='subcommands', metavar='<subcommand>')
    subparsers.required = True
    subparsers.add_subparser_group('store', 'Store test result', 100)
    subparsers.add_subparser_group('view', 'Analyze test result', -1)
    subparsers.add_subparser_group('testplan', 'Plan test', 1000)
    testresultlog.storeauto.register_commands(subparsers)
    testresultlog.storemanual.register_commands(subparsers)
    testresultlog.view.register_commands(subparsers)
    testresultlog.testplan.register_commands(subparsers)
    args = parser.parse_args()
    if getattr(args, "git_repo", False):
        print('Found git_repo attribute')
        args.git_repo = _get_git_dir(args.git_repo)
    if getattr(args, "oe_dir", False):
        print('Found oe_dir attribute')
        args.oe_dir = _get_oe_dir(args.oe_dir)
        args.case_dir = _get_oeqa_case_dir(args.oe_dir, args.source)
    _set_args_attribute_default_value(args)

    try:
        ret = args.func(args)
    except argparse_oe.ArgumentUsageError as ae:
        parser.error_subcommand(ae.message, ae.subcommand)
    return ret

if __name__ == "__main__":
    sys.exit(main())