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
|
#!/usr/bin/python
# Copyright (c) 2012 Linaro
# Author: Linaro Validation Team <linaro-dev@lists.linaro.org>
#
# This file is part of LAVA Android Test.
#
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
import re
import string
import sys
import simplejson as json
if len(sys.argv) < 3:
basename = os.path.basename(sys.argv[0])
print 'Please specified the merge target file and source files like:'
print '\t %s target-result-file source-file1 source-file2 ...'
sys.exit(1)
target_file = sys.argv[1]
test_results = []
for f in sys.argv[2:]:
if not os.path.exists(f):
print "The file(%s) does not exist" % f
continue
with open(f) as stream:
f_basename = os.path.basename(f)
last_hyphen_index = string.rfind(f_basename, '-')
if last_hyphen_index != -1:
file_id = f_basename[:last_hyphen_index]
else:
file_id = ''
jobdata = stream.read()
results_data = json.loads(jobdata)
for res in results_data:
test_case_id = res.get('test_case_id')
average = res.get('average')
avg_dev = res.get('average_deviate')
units = res.get('units')
if file_id and test_case_id == 'summary':
test_case_id = '%s-summary' % file_id
test_case_id = test_case_id.replace('/', '_')
badchars = "[^a-zA-Z0-9\._-]"
test_case_id = re.sub(badchars, "", test_case_id.replace(" ", "_"))
if not units:
units = 'ms'
test_results.append({'test_case_id': '%s_avg' % test_case_id,
'result': 'pass',
'measurement': average,
'units': units})
if avg_dev:
test_results.append({
'test_case_id': '%s_avg_dev' % test_case_id,
'result': 'pass',
'measurement': avg_dev,
'units': '%'})
with open(target_file, 'w') as fd:
indent = ' ' * 2
separators = (', ', ': ')
json.dump(test_results, fd,
use_decimal=True,
indent=indent,
separators=separators,
sort_keys=False)
print "The result has been merged in file: %s" % target_file
sys.exit(0)
|