1import os, re, logging 2from autotest_lib.client.bin import test, utils 3from autotest_lib.client.common_lib import error 4 5class monotonic_time(test.test): 6 version = 1 7 8 preserve_srcdir = True 9 10 def setup(self): 11 os.chdir(self.srcdir) 12 utils.make() 13 14 15 def initialize(self): 16 self.job.require_gcc() 17 18 19 def run_once(self, test_type = None, duration = 300, threshold = None): 20 if not test_type: 21 raise error.TestError('missing test type') 22 23 cmd = self.srcdir + '/time_test' 24 cmd += ' --duration ' + str(duration) 25 if threshold: 26 cmd += ' --threshold ' + str(threshold) 27 cmd += ' ' + test_type 28 29 self.results = utils.run(cmd, ignore_status=True) 30 logging.info('Time test command exit status: %s', 31 self.results.exit_status) 32 if self.results.exit_status != 0: 33 for line in self.results.stdout.splitlines(): 34 if line.startswith('ERROR:'): 35 raise error.TestError(line) 36 if line.startswith('FAIL:'): 37 raise error.TestFail(line) 38 raise error.TestError('unknown test failure') 39