1import os, re, logging 2from autotest_lib.client.bin import test, utils 3from autotest_lib.client.common_lib import error 4 5class tsc(test.test): 6 version = 3 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, args = '-t 650'): 20 result = utils.run(self.srcdir + '/checktsc ' + args, 21 stdout_tee=open(os.path.join(self.resultsdir, 22 'checktsc.log'), 'w'), 23 ignore_status=True) 24 if result.exit_status != 0: 25 logging.error('Program checktsc exit status is %s', 26 result.exit_status) 27 default_reason = ("UNKNOWN FAILURE: rc=%d from %s" % 28 (result.exit_status, result.command)) 29 ## Analyze result.stdout to see if it is possible to form qualified 30 ## reason of failure and to raise an appropriate exception. 31 ## For this test we qualify the reason of failure if the 32 ## following conditions are met: 33 ## (i) result.exit_status = 1 34 ## (ii) result.stdout ends with 'FAIL' 35 ## (iii) "FAIL" is preceeded by one or more 36 ## lines in the following format: 37 ## CPU x - CPU y = <delta> 38 ## Set as a reason the line that contains max abs(delta) 39 if result.exit_status == 1: 40 if result.stdout.strip('\n').endswith('FAIL'): 41 ## find all lines 42 ## CPU x - CPU y = <delta> 43 ## and parse out delta of max abs value 44 max_delta = 0 45 reason = '' 46 threshold = int(args.split()[1]) 47 latencies = re.findall("CPU \d+ - CPU \d+ =\s+-*\d+", 48 result.stdout) 49 for ln in latencies: 50 cur_delta = int(ln.split('=', 2)[1]) 51 if abs(cur_delta) > max_delta: 52 max_delta = abs(cur_delta) 53 reason = ln 54 if max_delta > threshold: 55 reason = "Latency %s exceeds threshold %d" % (reason, 56 threshold) 57 raise error.TestFail(reason) 58 59 ## If we are here, we failed to qualify the reason of test failre 60 ## Consider it as a test error 61 raise error.TestError(default_reason) 62