~afrantzis/lava-test/x11perf

« back to all changes in this revision

Viewing changes to abrek/testdef.py

  • Committer: Paul Larson
  • Date: 2010-08-10 20:24:26 UTC
  • mfrom: (21.1.3 hwsw)
  • Revision ID: paul.larson@canonical.com-20100810202426-zkz0l42nfp7ztjr4
Add sw/hw profile information to test runs and make abrek more compliant
with what the dashboard will expect

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
import time
8
8
from commands import getstatusoutput
9
9
from datetime import datetime
 
10
from uuid import uuid1
10
11
 
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
13
16
 
14
17
class AbrekTest(object):
15
18
    """Base class for defining tests.
72
75
            shutil.rmtree(path)
73
76
 
74
77
    def _savetestdata(self):
 
78
        TIMEFORMAT = '%Y-%m-%dT%H:%M:%SZ'
75
79
        testdata = {}
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)
82
91
 
83
92
    def run(self):
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
204
213
            each test result
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'}
212
221
    """
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
218
227
 
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)
223
232
 
224
233
    def parse(self):
225
234
        """Parse test output to gather results
235
244
            for line in fd.readlines():
236
245
                match = pat.search(line)
237
246
                if match:
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)
243
252
 
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
246
255
 
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
249
258
        """
250
259
        index = self._find_testid(testid)
251
 
        self.results['testlist'][index].update(entry)
 
260
        self.results['test_results'][index].update(entry)
252
261
 
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.
255
264
 
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
257
266
        """
258
 
        for t in self.results['testlist']:
 
267
        for t in self.results['test_results']:
259
268
            t.update(entry)
260
269
 
261
270
    def fixresults(self, fixupdict):
266
275
            {"TPASS":"pass", "TFAIL":"fail"}
267
276
        This is really only used for qualitative tests
268
277
        """
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']]
272
281