def main(): options = ParseOptions() test_classes = TestRunner.GetTestClasses(TestDefinitions) if options.list_tests: for test_name in sorted(c.__name__ for c in test_classes): print test_name sys.exit(0) SetupLogging(options) logging.info('OLA Responder Tests Version %s' % Version.version) pid_store = PidStore.GetStore(options.pid_location, ('pids.proto', 'draft_pids.proto', 'manufacturer_names.proto')) wrapper = ClientWrapper() global uid_ok uid_ok = False def UIDList(state, uids): wrapper.Stop() global uid_ok if not state.Succeeded(): logging.error('Fetch failed: %s' % state.message) return for uid in uids: if uid == options.uid: logging.debug('Found UID %s' % options.uid) uid_ok = True if not uid_ok: logging.error('UID %s not found in universe %d' % (options.uid, options.universe)) return if len(uids) > 1: logging.info( 'The following devices were detected and will be reconfigured') for uid in uids: logging.info(' %s' % uid) if not options.skip_check: logging.info('Continue ? [Y/n]') response = raw_input().strip().lower() uid_ok = response == 'y' or response == '' logging.debug('Fetching UID list from server') wrapper.Client().FetchUIDList(options.universe, UIDList) wrapper.Run() wrapper.Reset() if not uid_ok: sys.exit() test_filter = None if options.tests is not None: logging.info('Restricting tests to %s' % options.tests) test_filter = set(options.tests.split(',')) logging.info( 'Starting tests, universe %d, UID %s, broadcast write delay %dms, ' 'inter-test delay %dms' % (options.universe, options.uid, options.broadcast_write_delay, options.inter_test_delay)) runner = TestRunner.TestRunner(options.universe, options.uid, options.broadcast_write_delay, options.inter_test_delay, pid_store, wrapper, options.timestamp) for test_class in test_classes: runner.RegisterTest(test_class) DMXSender(wrapper, options.universe, options.dmx_frame_rate, options.slot_count) tests, device = runner.RunTests(test_filter, options.no_factory_defaults) DisplaySummary(options, runner, tests, device, pid_store)
def _RunTests(self, universe, uid, test_filter, broadcast_write_delay, inter_test_delay, dmx_frame_rate, slot_count): self._test_state_lock.acquire() self._test_state = { 'action': self.TESTS, 'tests_completed': 0, 'total_tests': None, 'state': self.RUNNING, 'duration': 0, } start_time = datetime.now() self._test_state_lock.release() runner = TestRunner.TestRunner(universe, uid, broadcast_write_delay, inter_test_delay, self._pid_store, self._wrapper) for test in TestRunner.GetTestClasses(TestDefinitions): runner.RegisterTest(test) dmx_sender = None if dmx_frame_rate > 0 and slot_count > 0: logging.info( 'Starting DMXSender with slot count %d and FPS of %d' % (slot_count, dmx_frame_rate)) dmx_sender = DMXSender(self._wrapper, universe, dmx_frame_rate, slot_count) try: tests, device = runner.RunTests(test_filter, False, self._UpdateStats) except Exception as e: self._test_state_lock.acquire() self._test_state['state'] = self.ERROR self._test_state['exception'] = str(e) self._test_state['traceback'] = traceback.format_exc() self._test_state_lock.release() return finally: if dmx_sender is not None: dmx_sender.Stop() timestamp = int(time()) end_time = datetime.now() test_parameters = { 'broadcast_write_delay': broadcast_write_delay, 'inter_test_delay': inter_test_delay, 'dmx_frame_rate': dmx_frame_rate, 'dmx_slot_count': slot_count, } log_saver = TestLogger.TestLogger(self._logs_directory) logs_saved = True try: log_saver.SaveLog(uid, timestamp, end_time, tests, device, test_parameters) except TestLogger.TestLoggerException: logs_saved = False self._test_state_lock.acquire() # We can't use total_seconds() since it requires Python 2.7 time_delta = end_time - start_time self._test_state['duration'] = (time_delta.seconds + time_delta.days * 24 * 3600) self._test_state['state'] = self.COMPLETED self._test_state['tests'] = tests self._test_state['logs_saved'] = logs_saved self._test_state['timestamp'] = timestamp self._test_state['uid'] = uid self._test_state_lock.release()