Revision control

1
import logging
2
import os
3
4
from mozrunner import FirefoxRunner
5
6
logging.getLogger(__name__).addHandler(logging.NullHandler())
7
8
TIMEOUT = 60
9
10
11
class TPS(object):
12
logger = logging.getLogger()
13
14
def __init__(self, firefox, firefox_log, tps_log, profile):
15
self.firefox = firefox
16
self.firefox_log = open(firefox_log, 'w')
17
self.tps_log = tps_log
18
self.profile = profile
19
20
def _log(self, line):
21
self.firefox_log.write(line + '\n')
22
23
def run(self, test, phase='phase1', ignore_unused_engines=True):
24
self.profile.set_preferences({
25
'testing.tps.testFile': os.path.abspath(test),
26
'testing.tps.testPhase': phase,
27
'testing.tps.ignoreUnusedEngines': ignore_unused_engines,
28
})
29
args = ['-marionette']
30
process_args = {'processOutputLine': [self._log]}
31
self.logger.info('Running: {} {}'.format(self.firefox, ' '.join(args)))
32
self.logger.info('Using profile at: {}'.format(self.profile.profile))
33
runner = FirefoxRunner(
34
binary=self.firefox,
35
cmdargs=args,
36
profile=self.profile,
37
process_args=process_args)
38
runner.start(timeout=TIMEOUT)
39
runner.wait(timeout=TIMEOUT)
40
self.firefox_log.close()
41
42
with open(self.tps_log) as f:
43
for line in f.readlines():
44
if 'CROSSWEAVE ERROR: ' in line:
45
raise TPSError(line.partition('CROSSWEAVE ERROR: ')[-1])
46
47
with open(self.tps_log) as f:
48
assert 'test phase {}: PASS'.format(phase) in f.read()
49
50
51
class TPSError(Exception):
52
pass