### # Make sure we can "see" the i2c bus before attempting to test # attached components, duh. (We're only interested in bus 0.) result, spewage = execute_command('/usr/bin/i2cdetect 0') if not result: self.log('ERROR: Cannot access the I2C bus: %s' % spewage) self._nerrors += 1 else: self._i2crtc.runtest() self._nwarnings += self._i2crtc.nwarnings self._nerrors += self._i2crtc.nerrors return self.passed() def set_hwclock(self, unix_time): unix_time = float(unix_time) time_tuple = time.localtime(unix_time) cmd = 'date -s "%s"' % (time.strftime('%m/%d/%Y %H:%M:%S', time_tuple)) self.log('RTC: Running command - %s' % cmd) result, spewage = execute_command(cmd) if not result: self.log('ERROR: Could not set RTC time: %s' % spewage) return False result, spewage = execute_command('hwclock -wu') if not result: self.log('ERROR: Could not execute hwclock: %s' % spewage) return False return True f = Factory() f.register('I2CTester', (I2CTester,))
from ion import Factory class DallasTester(Test): def __init__(self, **kw): self._num_dallas_busses = 4 if properties.HARDWARE_CODENAME == "Megatron": self._num_dallas_busses = 2 super(DallasTester, self).__init__(**kw) self._test_name = 'DallasTester' self._avr = get_avr() return def runtest(self): self.log('Testing Dallas temperature sensors.') for bus in range(1, (self._num_dallas_busses + 1)): if properties.HARDWARE_CODENAME == "Megatron": a = as_node('/interfaces/dallas%d' % bus).findall()[1][0] else: a = self._avr.dallas_readrom(bus) address = self._avr.tohex(a) if address == 'ffffffffffffffff': self.log('ERROR: Bus %d, bad address.' % bus) self._nerrors += 1 self.log('Dallas temp sensors, found %d errors and %d warnings.' % (self._nerrors, self._nwarnings)) return self.passed() f = Factory() f.register('DallasTester', (DallasTester,))
expected_count = relay1count self.check_counter(1, relay1count) self.check_counter(2, relay1count) self.check_counter(3, relay2count) self.check_counter(4, relay2count) self.log('Counters/relays, found %d errors and %d warnings.' % (self._nerrors, self._nwarnings)) self.reset_counters() return self.passed() def reset_counters(self): for counter in (1, 2, 3, 4): self._avr.reset_counter(counter) return def check_counter(self, counter, expected): val = self._avr.get_counter(counter) if val != expected: self.log('ERROR: Counter %d failed, expected %d, got %d.' % (counter, expected, val)) self._nerrors += 1 return self.passed() f = Factory() f.register('CountersAndRelaysTester', (CountersAndRelaysTester,))
self.log('ERROR: Serial ports (%s:%s) %d errors and %d warnings.' % (self.port1.name, self.port2.name, self._nerrors, self._nwarnings)) return self.passed() class SerialTester(Test): def __init__(self, **kw): super(SerialTester, self).__init__(**kw) self._test_name = 'SerialTester' self._rs232test = _PortTester('com1', 'com2') self._rs485test_a = _PortTester('com3', 'com4') self._rs485test_b = _PortTester('com5', 'com6') return def runtest(self): for serialtest in [self._rs232test, self._rs485test_a, self._rs485test_b]: serialtest.runtest() self._nerrors += serialtest.nerrors self._nwarnings += serialtest.nwarnings self.log('Serial test, found %d errors and %d warnings.\n' % (self._nerrors, self._nwarnings)) return self.passed() f = Factory() f.register('SerialTester', (SerialTester,))
result = BootlogError.ERROR.search(line) if result: result = BootlogIsHDA.ISHDA.match(line) if not result: self.log('ERROR in boot log: %s' % line) self._nerrors += 1 result = BootlogWarning.WARNING.search(line) if result: self.log('WARNING in boot log: %s' % line) self._nwarnings += 1 return def runtest(self): if not os.path.exists(self.filename): raise Exception('Error, missing the dmesg log file [%s]' % self.filename) self.log('Examining system boot log for errors and warnings.') try: f = open(self.filename, "r+") for line in f.xreadlines(): self._parse_line(line) finally: f.close() self.log('Boot log, found %d errors and %d warnings.' % \ (self._nerrors, self._nwarnings)) return self.passed() f = Factory() f.register('BootlogTester', (BootlogTester, ))
# Make sure we can "see" the i2c bus before attempting to test # attached components, duh. (We're only interested in bus 0.) result, spewage = execute_command('/usr/bin/i2cdetect 0') if not result: self.log('ERROR: Cannot access the I2C bus: %s' % spewage) self._nerrors += 1 else: self._i2crtc.runtest() self._nwarnings += self._i2crtc.nwarnings self._nerrors += self._i2crtc.nerrors return self.passed() def set_hwclock(self, unix_time): unix_time = float(unix_time) time_tuple = time.localtime(unix_time) cmd = 'date -s "%s"' % (time.strftime('%m/%d/%Y %H:%M:%S', time_tuple)) self.log('RTC: Running command - %s' % cmd) result, spewage = execute_command(cmd) if not result: self.log('ERROR: Could not set RTC time: %s' % spewage) return False result, spewage = execute_command('hwclock -wu') if not result: self.log('ERROR: Could not execute hwclock: %s' % spewage) return False return True f = Factory() f.register('I2CTester', (I2CTester, ))
class DallasTester(Test): def __init__(self, **kw): self._num_dallas_busses = 4 if properties.HARDWARE_CODENAME == "Megatron": self._num_dallas_busses = 2 super(DallasTester, self).__init__(**kw) self._test_name = 'DallasTester' self._avr = get_avr() return def runtest(self): self.log('Testing Dallas temperature sensors.') for bus in range(1, (self._num_dallas_busses + 1)): if properties.HARDWARE_CODENAME == "Megatron": a = as_node('/interfaces/dallas%d' % bus).findall()[1][0] else: a = self._avr.dallas_readrom(bus) address = self._avr.tohex(a) if address == 'ffffffffffffffff': self.log('ERROR: Bus %d, bad address.' % bus) self._nerrors += 1 self.log('Dallas temp sensors, found %d errors and %d warnings.' % (self._nerrors, self._nwarnings)) return self.passed() f = Factory() f.register('DallasTester', (DallasTester, ))
if result: result = BootlogIsHDA.ISHDA.match(line) if not result: self.log('ERROR in boot log: %s' % line) self._nerrors += 1 result = BootlogWarning.WARNING.search(line) if result: self.log('WARNING in boot log: %s' % line) self._nwarnings += 1 return def runtest(self): if not os.path.exists(self.filename): raise Exception( 'Error, missing the dmesg log file [%s]' % self.filename ) self.log('Examining system boot log for errors and warnings.') try: f = open(self.filename, "r+") for line in f.xreadlines(): self._parse_line(line) finally: f.close() self.log('Boot log, found %d errors and %d warnings.' % \ (self._nerrors, self._nwarnings)) return self.passed() f = Factory() f.register('BootlogTester', (BootlogTester,))
from ion import Factory class MemoryTester(Test): def __init__(self, **kw): self.memory = 256 self.iterations = 1 self.memtester = '/usr/bin/memtester' super(MemoryTester, self).__init__(**kw) self._test_name = 'MemoryTester' return def runtest(self): self.log('Testing system RAM.') result, spewage = execute_command(self.testprog) if not result: self.log('ERROR: Memory test failed: %s' % spewage) self._nerrors += 1 else: self.log('SUCCESS: Memory test passed: %s' % spewage) return self.passed() def _get_test_prog(self): return '%s %d %d' % \ (self.memtester, self.memory, self.iterations) # testprog is a property so that "memory" and "iterations" # can easily be changed at runtime testprog = property(_get_test_prog) f = Factory() f.register('MemoryTester', (MemoryTester,))
expected_count = relay1count self.check_counter(1, relay1count) self.check_counter(2, relay1count) self.check_counter(3, relay2count) self.check_counter(4, relay2count) self.log('Counters/relays, found %d errors and %d warnings.' % (self._nerrors, self._nwarnings)) self.reset_counters() return self.passed() def reset_counters(self): for counter in (1, 2, 3, 4): self._avr.reset_counter(counter) return def check_counter(self, counter, expected): val = self._avr.get_counter(counter) if val != expected: self.log('ERROR: Counter %d failed, expected %d, got %d.' % (counter, expected, val)) self._nerrors += 1 return self.passed() f = Factory() f.register('CountersAndRelaysTester', (CountersAndRelaysTester, ))
self.log( 'ERROR: Serial ports (%s:%s) %d errors and %d warnings.' % (self.port1.name, self.port2.name, self._nerrors, self._nwarnings)) return self.passed() class SerialTester(Test): def __init__(self, **kw): super(SerialTester, self).__init__(**kw) self._test_name = 'SerialTester' self._rs232test = _PortTester('com1', 'com2') self._rs485test_a = _PortTester('com3', 'com4') self._rs485test_b = _PortTester('com5', 'com6') return def runtest(self): for serialtest in [ self._rs232test, self._rs485test_a, self._rs485test_b ]: serialtest.runtest() self._nerrors += serialtest.nerrors self._nwarnings += serialtest.nwarnings self.log('Serial test, found %d errors and %d warnings.\n' % (self._nerrors, self._nwarnings)) return self.passed() f = Factory() f.register('SerialTester', (SerialTester, ))