Skip to content

Commit 247067f

Browse files
committed
Converge the cts and vts python scripts that munge
tradedfed output into one script that can handle both. Signed-off-by: Tom Gall <tom.gall@linaro.org>
1 parent 0e283c5 commit 247067f

File tree

1 file changed

+153
-0
lines changed

1 file changed

+153
-0
lines changed

convert-tradefed-xml2json.py

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
#!/usr/bin/python
2+
3+
import sys, getopt
4+
import xml.etree.ElementTree as ET
5+
import json
6+
import ndjson
7+
8+
board = 'HiKey'
9+
android_ver = 'Android-9.0'
10+
11+
def parseXML(xmlfile, vintffile, lab):
12+
# first we need to get the kernel and board information
13+
# make a new empty result list
14+
results = []
15+
# make a run dictionary
16+
runinfo = {}
17+
buildinfo = {}
18+
19+
with open(vintffile, 'r') as f:
20+
vintf_dict = json.load(f)
21+
kernel_version = vintf_dict['kernel_version']
22+
os_release = vintf_dict['os_release']
23+
24+
25+
tree = ET.parse(xmlfile)
26+
27+
root = tree.getroot()
28+
29+
# Result is the root element in VTS
30+
TestSuiteName = root.attrib['suite_name']
31+
TestSuiteVersion = root.attrib['suite_version']
32+
print (TestSuiteName, TestSuiteVersion)
33+
print ('\n')
34+
35+
36+
# make a new empty result list
37+
results = []
38+
# make a run list and then a runinfo dictionary
39+
aRun = []
40+
runinfo = {}
41+
runinfo['testsuite'] = TestSuiteName
42+
runinfo['testsuite_version'] = TestSuiteVersion
43+
runinfo['kernel_version'] = kernel_version
44+
runinfo['full_kernel_version'] = os_release
45+
runinfo['os_release'] = os_release
46+
runinfo['git_repo'] = 'https://github.com/tom-gall/hikey-linaro.git'
47+
runinfo['git_branch'] = 'android-' + kernel_version + '-p-hikey'
48+
runinfo['start_time'] = root.attrib['start_display']
49+
runinfo['end_time'] = root.attrib['end_display']
50+
runinfo['lab'] = lab
51+
aRun.append(runinfo)
52+
buildinfo['compiler'] = 'clang'
53+
buildinfo['compiler_version'] = ''
54+
55+
# runinfo['kernel_config'] = ''
56+
# runinfo['rundate'] = ''
57+
# runinfo['target_hw'] = 'Hikey'
58+
# OS under test
59+
# Host OS
60+
61+
for module in root:
62+
# example : Module name="VtsKernelProcFileApi" abi="arm64-v8a" runtime="144931" done="true" pass="64"
63+
64+
if module.tag == 'Build':
65+
runinfo['target'] = module.attrib['build_board']
66+
runinfo['target_os'] = 'Android ' + module.attrib['build_version_release']
67+
68+
if module.tag == 'Module':
69+
CurrentABI = module.attrib['abi']
70+
CurrentModule = module.attrib['name']
71+
72+
for testcase in module:
73+
74+
for result in testcase:
75+
# make a new dictory per object, include the run info in each object (yes this is weird
76+
# BD databases want this over linking tables with id fields
77+
Test = {}
78+
Test['module'] = CurrentModule
79+
Test['abi'] = CurrentABI
80+
Test['result'] = result.attrib['result']
81+
Test['testsuite'] = runinfo['testsuite']
82+
Test['kernel'] = runinfo['os_release']
83+
if Test['result'] == 'fail':
84+
for failure in result:
85+
Test['message'] = failure.attrib['message']
86+
# for stacktrace in failure:
87+
# Test['stacktrace'] = stacktrace.attrib['StackTrace']
88+
else:
89+
Test['message'] = ""
90+
Test['name'] = result.attrib['name']
91+
# Test['run_info'] = runinfo
92+
print (Test)
93+
results.append(Test)
94+
95+
96+
97+
# example : Module name="VtsKernelProcFileApi" abi="arm64-v8a" runtime="144931" done="true" pass="64"
98+
99+
return results, aRun
100+
101+
102+
def savetoCSV (items, filename):
103+
fields = ['module','abi','result', 'name']
104+
105+
with open(filename, 'w') as csvfile:
106+
107+
writer = csv.DictWriter(csvfile, fieldnames = fields)
108+
writer.writeheader()
109+
writer.writerows(items)
110+
111+
112+
def savetoJSON (items, filename):
113+
with open(filename, 'w') as outfile:
114+
ndjson.dump(items,outfile)
115+
116+
def saveRunInfoToJSON(runinfo):
117+
with open('keystone.json', 'w') as outfile:
118+
ndjson.dump(runinfo,outfile)
119+
120+
def main():
121+
vintffile = ''
122+
xmlresultsfile = ''
123+
lab='unknown'
124+
runinfo = ''
125+
outputfile = 'out.json'
126+
127+
128+
argv = sys.argv[1:]
129+
130+
try:
131+
opts, args = getopt.getopt(argv, "hl:x:v:o:", ["lab=","xmlresults=", "vintffile=", "out="])
132+
except getopt.GetoptError:
133+
print 'convert-tradefed-xml2json.py -x <xml result file> -v <Vint file> -o <output NSJSON>'
134+
sys.exit(2)
135+
for opt, arg in opts:
136+
if opt == '-h':
137+
print 'convert-tradefed-xml2json.py -x <xml result file> -v <Vint file> -o <output NSJSON>'
138+
elif opt in ("-l", "lab="):
139+
lab=arg
140+
elif opt in ("-x", "xmlresults="):
141+
xmlresultsfile=arg
142+
elif opt in ("-v", "vintffile="):
143+
vintffile=arg
144+
elif opt in ("-o", "out="):
145+
outputfile = arg
146+
147+
148+
newresults, runinfo = parseXML(xmlresultsfile, vintffile, lab)
149+
savetoJSON(newresults, outputfile)
150+
saveRunInfoToJSON(runinfo)
151+
152+
if __name__ == "__main__":
153+
main()

0 commit comments

Comments
 (0)