1########################################################################## 2# Copyright (c) 2013, ETH Zurich. 3# All rights reserved. 4# 5# This file is distributed under the terms in the attached LICENSE file. 6# If you do not find this file, copies can be found by writing to: 7# ETH Zurich D-INFK, CAB F.78, Universitaetstr 6, CH-8092 Zurich. 8########################################################################## 9 10import re 11import tests 12import debug 13 14from common import TestCommon, TimeoutError 15from results import PassFailResult 16 17MATCH = 'spantest.*Done.*cycles' 18 19@tests.add_test 20class SpanTest(TestCommon): 21 '''Span a program on the twice each on the first and second core''' 22 name = "spantest" 23 24 def setup(self, build, machine, testdir): 25 super(SpanTest, self).setup(build, machine, testdir) 26 27 def get_modules(self, build, machine): 28 modules = super(SpanTest, self).get_modules(build, machine) 29 # span on all cores other than 0 -- matches spantest code 30 modules.add_module("spantest", [ machine.get_ncores() - 1 ]) 31 return modules 32 33 def is_finished(self, line): 34 return re.match(MATCH, line) or super(SpanTest, self).is_finished(line) 35 36 def process_data(self, testdir, rawiter): 37 result = False 38 for line in rawiter: 39 if re.match(MATCH, line): 40 result = True 41 return PassFailResult(result) 42 43@tests.add_test 44class SpanTestInterleaved(TestCommon): 45 '''Interleave span and thread create''' 46 name = "spantest_interleaved" 47 48 def setup(self, build, machine, testdir): 49 super(SpanTestInterleaved, self).setup(build, machine, testdir) 50 51 def get_modules(self, build, machine): 52 modules = super(SpanTestInterleaved, self).get_modules(build, machine) 53 # span on all cores other than 0 -- matches spantest code 54 modules.add_module("tests/span-interleaved", [ machine.get_ncores() ]) 55 return modules 56 57 def get_finish_string(self): 58 return 'SPAN_TEST_SUCCESS.' 59 60 def process_data(self, testdir, rawiter): 61 result = False 62 for line in rawiter: 63 if re.search('SPAN_TEST_SUCCESS.', line) : 64 result = True 65 return PassFailResult(result) 66 67@tests.add_test 68class SpanTestExit(TestCommon): 69 '''Span a program then exit and see if other dispatchers cleanup''' 70 name = "spantest_exit" 71 72 is_done = False 73 74 def setup(self, build, machine, testdir): 75 super(SpanTestExit, self).setup(build, machine, testdir) 76 77 def get_modules(self, build, machine): 78 modules = super(SpanTestExit, self).get_modules(build, machine) 79 # span on all cores other than 0 -- matches spantest code 80 modules.add_module("tests/span-exit", [ machine.get_ncores() ]) 81 return modules 82 83 def is_finished(self, line): 84 if re.search('SPAN_TEST_DONE.', line) : 85 self.is_done = True 86 return re.match('kernel [0-9]*: user page fault WHILE DISABLED', line) or \ 87 super(SpanTestExit, self).is_finished(line) 88 89 def process_data(self, testdir, rawiter): 90 result = True 91 for line in rawiter: 92 if re.match('kernel [0-9]*: user page fault WHILE DISABLED', line): 93 result = False 94 return PassFailResult(result) 95 96 def collect_data(self, machine): 97 fh = machine.get_output() 98 while True: 99 try: 100 line = self._readline(fh) 101 except TimeoutError as e: 102 if self.boot_phase: 103 if self.boot_attempts < MAX_BOOT_ATTEMPTS: 104 yield '[Error: boot timed out, retry]\n' 105 self.reboot(machine) 106 continue 107 else: 108 yield '[Error: boot timed out, retry limit reached]\n' 109 else: 110 yield '[Error: test timed out]\n' 111 debug.verbose("timeout encountered in collect_data"); 112 self.has_timeout = True 113 if self.is_done : 114 break 115 raise e 116 117 yield line 118 119 if not self.boot_phase: 120 self.process_line(line) 121 if self.is_finished(line): 122 debug.verbose("is_finished returned true for line %s" % line) 123 break 124 elif self.is_booted(line): 125 self.boot_phase = False 126 self.set_timeout(self.test_timeout_delta) 127 self.process_line(line) 128