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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
import unittest
from testresultlog.testresultgitstore import TestResultGitStore
from testresultlog.oeqatestcasecreator import OeqaTestCaseCreator
from testresultlog.testlogparser import TestLogParser
class TestResultUpdator(object):
def _get_testsuite_from_testcase(self, testcase):
testsuite = testcase[0:testcase.rfind(".")]
return testsuite
def _get_testmodule_from_testsuite(self, testsuite):
testmodule = testsuite[0:testsuite.find(".")]
return testmodule
def _remove_testsuite_from_testcase(self, testcase, testsuite):
testsuite = testsuite + '.'
testcase_remove_testsuite = testcase.replace(testsuite, '')
return testcase_remove_testsuite
def _get_testsuite_from_testcase(self, testcase):
testsuite = testcase[0:testcase.rfind(".")]
return testsuite
def _get_testmodule_from_testsuite(self, testsuite):
testmodule = testsuite[0:testsuite.find(".")]
return testmodule
def _add_new_environment_to_environment_list(self, environment_list, new_environment):
if len(new_environment) > 0 and new_environment not in environment_list:
if len(environment_list) == 0:
environment_list = new_environment
else:
environment_list = '%s,%s' % (environment_list, new_environment)
return environment_list
def get_environment_list_for_test_log(self, log_file, log_file_source, environment_list, testlogparser):
print('Getting test environment information from test log at %s' % log_file)
if log_file_source == 'runtime':
runtime_image_env = testlogparser.get_runtime_test_image_environment(log_file)
print('runtime image environment: %s' % runtime_image_env)
runtime_qemu_env = testlogparser.get_runtime_test_qemu_environment(log_file)
print('runtime qemu environment: %s' % runtime_qemu_env)
environment_list = self._add_new_environment_to_environment_list(environment_list, runtime_image_env)
environment_list = self._add_new_environment_to_environment_list(environment_list, runtime_qemu_env)
return environment_list.split(",")
def get_testsuite_testcase_dictionary(self, work_dir, testcase_remove_source_file):
print('Getting testsuite testcase information from oeqa directory at %s' % work_dir)
oeqatestcasecreator = OeqaTestCaseCreator()
testcase_list = oeqatestcasecreator.get_oeqa_testcase_list(work_dir, testcase_remove_source_file)
testsuite_testcase_dict = {}
for testcase in testcase_list:
testsuite = self._get_testsuite_from_testcase(testcase)
if testsuite in testsuite_testcase_dict:
testsuite_testcase_dict[testsuite].append(testcase)
else:
testsuite_testcase_dict[testsuite] = [testcase]
return testsuite_testcase_dict
def get_testmodule_testsuite_dictionary(self, testsuite_testcase_dict):
print('Getting testmodule testsuite information')
testsuite_list = testsuite_testcase_dict.keys()
testmodule_testsuite_dict = {}
for testsuite in testsuite_list:
testmodule = self._get_testmodule_from_testsuite(testsuite)
if testmodule in testmodule_testsuite_dict:
testmodule_testsuite_dict[testmodule].append(testsuite)
else:
testmodule_testsuite_dict[testmodule] = [testsuite]
return testmodule_testsuite_dict
def get_testcase_failed_or_error_logs_dictionary(self, log_file, testcase_status_dict):
print('Getting testcase failed or error log from %s' % log_file)
testlogparser = TestLogParser()
testcase_list = testcase_status_dict.keys()
testcase_failed_or_error_logs_dict = {}
for testcase in testcase_list:
test_status = testcase_status_dict[testcase]
if test_status == 'FAILED' or test_status == 'ERROR':
testsuite = self._get_testsuite_from_testcase(testcase)
testfunction = self._remove_testsuite_from_testcase(testcase, testsuite)
logs = testlogparser.get_test_log(log_file, test_status, testfunction, testsuite)
testcase_failed_or_error_logs_dict[testcase] = logs
return testcase_failed_or_error_logs_dict
def main(args):
testlogparser = TestLogParser()
testcase_status_dict = testlogparser.get_test_status(args.log_file)
testresultupdator = TestResultUpdator()
environment_list = testresultupdator.get_environment_list_for_test_log(args.log_file, args.source, args.environment_list, testlogparser)
testsuite_testcase_dict = testresultupdator.get_testsuite_testcase_dictionary(args.oeqa_dir, args.testcase_remove_source_file)
testmodule_testsuite_dict = testresultupdator.get_testmodule_testsuite_dictionary(testsuite_testcase_dict)
test_logs_dict = testresultupdator.get_testcase_failed_or_error_logs_dictionary(args.log_file, testcase_status_dict)
testresultstore = TestResultGitStore()
testresultstore.smart_update_automated_test_result(args.git_repo, args.git_branch, args.component, environment_list, testmodule_testsuite_dict, testsuite_testcase_dict, testcase_status_dict, test_logs_dict)
if (len(args.git_remote) > 0):
testresultstore.git_remote_fetch_rebase_push(args.git_repo, args.git_branch, args.git_remote)
def register_commands(subparsers):
"""Register subcommands from this plugin"""
parser_build = subparsers.add_parser('update', help='Store OEQA automated test status & log into git repository',
description='Store OEQA automated test status & log into git repository')
parser_build.set_defaults(func=main)
parser_build.add_argument('-c', '--component', required=True, help='Component folder (as the top folder) to store the test status & log')
parser_build.add_argument('-l', '--log_file', required=True, help='Full path to the test log file to be used for test result update')
parser_build.add_argument('-b', '--git_branch', required=True, help='Git branch to store the test status & log')
SOURCE = ('runtime', 'selftest', 'sdk', 'sdkext')
parser_build.add_argument('-s', '--source', required=True, choices=SOURCE,
help='Selected testcase sources to be used for OEQA testcase discovery and testcases discovered will be used as the base testcases for storing test status & log. '
'"runtime" will search testcase available in meta/lib/oeqa/runtime/cases. '
'"selftest" will search testcase available in meta/lib/oeqa/selftest/cases. '
'"sdk" will search testcase available in meta/lib/oeqa/sdk/cases. '
'"sdkext" will search testcase available in meta/lib/oeqa/sdkext/cases. ')
parser_build.add_argument('-g', '--git_repo', required=False, default='default', help='(Optional) Git repository used for storage, default will be <top_dir>/test-result-log.git')
parser_build.add_argument('-e', '--environment_list', required=False, default='', help='(Optional) List of environment seperated by comma (",") used to label the test environments for the stored test status & log')
parser_build.add_argument('-r', '--git_remote', required=False, default='', help='(Optional) Git remote repository used for storage')
parser_build.add_argument('-d', '--poky_dir', required=False, default='default', help='(Optional) Top directory to be used for OEQA testcase discovery, default will use current <top_dir> directory')
parser_build.add_argument('-m', '--testcase_remove_source_file', required=False, default='', help='(Optional) Full path to the file (created during test planning) used to define list of testcases to be excluded from storage')
|