8
8
from commands import getstatusoutput
9
9
from datetime import datetime
10
from uuid import uuid1
11
12
from abrek.config import get_config
12
13
from abrek.utils import geturl, write_file
14
from abrek import hwprofile
15
from abrek import swprofile
14
17
class AbrekTest(object):
15
18
"""Base class for defining tests.
72
75
shutil.rmtree(path)
74
77
def _savetestdata(self):
78
TIMEFORMAT = '%Y-%m-%dT%H:%M:%SZ'
76
80
filename = os.path.join(self.resultsdir, 'testdata.json')
77
testdata['testname'] = self.testname
78
testdata['version'] = self.version
79
testdata['starttime'] = time.mktime(self.runner.starttime.timetuple())
80
testdata['endtime'] = time.mktime(self.runner.endtime.timetuple())
81
testdata['test_id'] = self.testname
82
testdata['analyzer_assigned_uuid'] = str(uuid1())
83
testdata['time_check_performed'] = False
84
testdata['analyzer_assigned_date'] = datetime.strftime(
85
self.runner.starttime,TIMEFORMAT)
86
hw = hwprofile.get_hw_context()
87
testdata['hw_context'] = hw
88
sw = swprofile.get_sw_context()
89
testdata['sw_context'] = sw
81
90
write_file(json.dumps(testdata), filename)
199
208
"test01: PASS", then you could use a pattern like this:
200
209
"^(?P<testid>\w+):\W+(?P<result>\w+)"
201
210
This would result in identifying "test01" as testid and "PASS"
202
as result. Once parse() has been called, self.results.testlist[]
211
as result. Once parse() has been called, self.results.test_results[]
203
212
contains a list of dicts of all the key,value pairs found for
205
214
fixupdict - dict of strings to convert test results to standard strings
206
215
For example: if you want to standardize on having pass/fail results
207
216
in lower case, but your test outputs them in upper case, you could
208
217
use a fixupdict of something like: {'PASS':'pass','FAIL':'fail'}
209
appendall - Append a dict to the testlist entry for each result.
218
appendall - Append a dict to the test_results entry for each result.
210
219
For example: if you would like to add units="MB/s" to each result:
211
220
appendall={'units':'MB/s'}
213
222
def __init__(self, pattern=None, fixupdict=None, appendall={}):
214
223
self.pattern = pattern
215
224
self.fixupdict = fixupdict
216
self.results = {'testlist':[]}
225
self.results = {'test_results':[]}
217
226
self.appendall = appendall
219
228
def _find_testid(self, id):
220
for x in self.results['testlist']:
229
for x in self.results['test_results']:
221
230
if x['testid'] == id:
222
return self.results['testlist'].index(x)
231
return self.results['test_results'].index(x)
225
234
"""Parse test output to gather results
235
244
for line in fd.readlines():
236
245
match = pat.search(line)
238
self.results['testlist'].append(match.groupdict())
247
self.results['test_results'].append(match.groupdict())
239
248
if self.fixupdict:
240
249
self.fixresults(self.fixupdict)
241
250
if self.appendall:
242
251
self.appendtoall(self.appendall)
244
253
def append(self, testid, entry):
245
"""Appends a dict to the testlist entry for a specified testid
254
"""Appends a dict to the test_results entry for a specified testid
247
256
This lets you add a dict to the entry for a specific testid
248
257
entry should be a dict, updates it in place
250
259
index = self._find_testid(testid)
251
self.results['testlist'][index].update(entry)
260
self.results['test_results'][index].update(entry)
253
262
def appendtoall(self, entry):
254
"""Append entry to each item in the testlist.
263
"""Append entry to each item in the test_results.
256
entry - dict of key,value pairs to add to each item in the testlist
265
entry - dict of key,value pairs to add to each item in the test_results
258
for t in self.results['testlist']:
267
for t in self.results['test_results']:
261
270
def fixresults(self, fixupdict):
266
275
{"TPASS":"pass", "TFAIL":"fail"}
267
276
This is really only used for qualitative tests
269
for t in self.results['testlist']:
278
for t in self.results['test_results']:
270
279
if t.has_key("result"):
271
280
t['result'] = fixupdict[t['result']]