-
Notifications
You must be signed in to change notification settings - Fork 1
/
convert-tradefed-xml2json.py
executable file
·153 lines (119 loc) · 4.71 KB
/
convert-tradefed-xml2json.py
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/usr/bin/python
import sys, getopt
import xml.etree.ElementTree as ET
import json
import ndjson
board = 'HiKey'
android_ver = 'Android-9.0'
def parseXML(xmlfile, vintffile, lab):
# first we need to get the kernel and board information
# make a new empty result list
results = []
# make a run dictionary
runinfo = {}
buildinfo = {}
with open(vintffile, 'r') as f:
vintf_dict = json.load(f)
kernel_version = vintf_dict['kernel_version']
os_release = vintf_dict['os_release']
tree = ET.parse(xmlfile)
root = tree.getroot()
# Result is the root element in VTS
TestSuiteName = root.attrib['suite_name']
TestSuiteVersion = root.attrib['suite_version']
print (TestSuiteName, TestSuiteVersion)
print ('\n')
# make a new empty result list
results = []
# make a run list and then a runinfo dictionary
aRun = []
runinfo = {}
runinfo['testsuite'] = TestSuiteName
runinfo['testsuite_version'] = TestSuiteVersion
runinfo['kernel_version'] = kernel_version
runinfo['full_kernel_version'] = os_release
runinfo['os_release'] = os_release
runinfo['git_repo'] = 'https://github.com/tom-gall/hikey-linaro.git'
runinfo['git_branch'] = 'android-' + kernel_version + '-p-hikey'
runinfo['start_time'] = root.attrib['start_display']
runinfo['end_time'] = root.attrib['end_display']
runinfo['lab'] = lab
aRun.append(runinfo)
buildinfo['compiler'] = 'clang'
buildinfo['compiler_version'] = ''
# runinfo['kernel_config'] = ''
# runinfo['rundate'] = ''
# runinfo['target_hw'] = 'Hikey'
# OS under test
# Host OS
for module in root:
# example : Module name="VtsKernelProcFileApi" abi="arm64-v8a" runtime="144931" done="true" pass="64"
if module.tag == 'Build':
runinfo['target'] = module.attrib['build_board']
runinfo['target_os'] = 'Android ' + module.attrib['build_version_release']
if module.tag == 'Module':
CurrentABI = module.attrib['abi']
CurrentModule = module.attrib['name']
for testcase in module:
for result in testcase:
# make a new dictory per object, include the run info in each object (yes this is weird
# BD databases want this over linking tables with id fields
Test = {}
Test['module'] = CurrentModule
Test['abi'] = CurrentABI
Test['result'] = result.attrib['result']
Test['testsuite'] = runinfo['testsuite']
Test['kernel'] = runinfo['os_release']
if Test['result'] == 'fail':
for failure in result:
Test['message'] = failure.attrib['message']
# for stacktrace in failure:
# Test['stacktrace'] = stacktrace.attrib['StackTrace']
else:
Test['message'] = ""
Test['name'] = result.attrib['name']
# Test['run_info'] = runinfo
print (Test)
results.append(Test)
# example : Module name="VtsKernelProcFileApi" abi="arm64-v8a" runtime="144931" done="true" pass="64"
return results, aRun
def savetoCSV (items, filename):
fields = ['module','abi','result', 'name']
with open(filename, 'w') as csvfile:
writer = csv.DictWriter(csvfile, fieldnames = fields)
writer.writeheader()
writer.writerows(items)
def savetoJSON (items, filename):
with open(filename, 'w') as outfile:
ndjson.dump(items,outfile)
def saveRunInfoToJSON(runinfo):
with open('keystone.json', 'w') as outfile:
ndjson.dump(runinfo,outfile)
def main():
vintffile = ''
xmlresultsfile = ''
lab='unknown'
runinfo = ''
outputfile = 'out.json'
argv = sys.argv[1:]
try:
opts, args = getopt.getopt(argv, "hl:x:v:o:", ["lab=","xmlresults=", "vintffile=", "out="])
except getopt.GetoptError:
print 'convert-tradefed-xml2json.py -x <xml result file> -v <Vint file> -o <output NSJSON>'
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print 'convert-tradefed-xml2json.py -x <xml result file> -v <Vint file> -o <output NSJSON>'
elif opt in ("-l", "lab="):
lab=arg
elif opt in ("-x", "xmlresults="):
xmlresultsfile=arg
elif opt in ("-v", "vintffile="):
vintffile=arg
elif opt in ("-o", "out="):
outputfile = arg
newresults, runinfo = parseXML(xmlresultsfile, vintffile, lab)
savetoJSON(newresults, outputfile)
saveRunInfoToJSON(runinfo)
if __name__ == "__main__":
main()