jadmanski | e80d471 | 2008-10-03 16:15:59 +0000 | [diff] [blame^] | 1 | import os, re |
mbligh | 9f85792 | 2008-06-05 16:19:07 +0000 | [diff] [blame] | 2 | from autotest_lib.client.bin import test, autotest_utils |
mbligh | a8fe637 | 2008-08-28 20:55:43 +0000 | [diff] [blame] | 3 | from autotest_lib.client.common_lib import utils, error |
mbligh | 50f4b3c | 2007-03-14 16:42:41 +0000 | [diff] [blame] | 4 | |
| 5 | class tsc(test.test): |
mbligh | 9f0d48b | 2008-08-25 19:12:54 +0000 | [diff] [blame] | 6 | version = 2 |
mbligh | a8fe637 | 2008-08-28 20:55:43 +0000 | [diff] [blame] | 7 | |
mbligh | 9f0d48b | 2008-08-25 19:12:54 +0000 | [diff] [blame] | 8 | preserve_srcdir = True |
mbligh | 50f4b3c | 2007-03-14 16:42:41 +0000 | [diff] [blame] | 9 | |
mbligh | 9f0d48b | 2008-08-25 19:12:54 +0000 | [diff] [blame] | 10 | def setup(self): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 11 | os.chdir(self.srcdir) |
| 12 | utils.system('make') |
mbligh | 50f4b3c | 2007-03-14 16:42:41 +0000 | [diff] [blame] | 13 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 14 | |
mbligh | c5ddfd1 | 2008-08-04 17:15:00 +0000 | [diff] [blame] | 15 | def initialize(self): |
| 16 | self.job.require_gcc() |
| 17 | |
| 18 | |
mbligh | 9f0d48b | 2008-08-25 19:12:54 +0000 | [diff] [blame] | 19 | def run_once(self, args = '-t 650'): |
mbligh | a8fe637 | 2008-08-28 20:55:43 +0000 | [diff] [blame] | 20 | result = utils.run(self.srcdir + '/checktsc ' + args, |
| 21 | ignore_status=True) |
| 22 | print 'result.exit_status', result.exit_status |
| 23 | if result.exit_status != 0: |
| 24 | default_reason = ("UNKNOWN FAILURE: rc=%d from %s" % |
| 25 | (result.exit_status, result.command)) |
| 26 | ## Analyze result.stdout to see if it is possible to form qualified |
| 27 | ## reason of failure and to raise an appropriate exception. |
| 28 | ## For this test we qualify the reason of failure if the |
| 29 | ## following conditions are met: |
| 30 | ## (i) result.exit_status = 1 |
| 31 | ## (ii) result.stdout ends with 'FAIL' |
| 32 | ## (iii) "FAIL" is preceeded by one or more |
| 33 | ## lines in the following format: |
| 34 | ## CPU x - CPU y = <delta> |
| 35 | ## Set as a reason the line that contains max abs(delta) |
| 36 | if result.exit_status == 1: |
| 37 | if result.stdout.strip('\n').endswith('FAIL'): |
| 38 | ## find all lines |
| 39 | ## CPU x - CPU y = <delta> |
| 40 | ## and parse out delta of max abs value |
| 41 | max_delta = 0 |
| 42 | reason = '' |
| 43 | threshold = int(args.split()[1]) |
| 44 | latencies = re.findall("CPU \d+ - CPU \d+ =\s+-*\d+", |
| 45 | result.stdout) |
| 46 | for ln in latencies: |
| 47 | cur_delta = int(ln.split('=', 2)[1]) |
| 48 | if abs(cur_delta) > max_delta: |
| 49 | max_delta = abs(cur_delta) |
| 50 | reason = ln |
| 51 | if max_delta > threshold: |
| 52 | reason = "Latency %s exceeds threshold %d" % (reason, |
| 53 | threshold) |
| 54 | raise error.TestFail(reason) |
| 55 | |
| 56 | ## If we are here, we failed to qualify the reason of test failre |
| 57 | ## Consider it as a test error |
| 58 | raise error.TestError(default_reason) |
| 59 | |
| 60 | |