def _handle_phase(self, phase): """Handle execution of a single test phase.""" # Make sure we initialize any plugs, this will ignore any that have already # been initialized. self.plug_manager.InitializePlugs(plug.cls for plug in phase.plugs if plug.cls not in self.mock_plugs) for plug_type, plug_value in self.mock_plugs.iteritems(): self.plug_manager.OverridePlug(plug_type, plug_value) # Cobble together a fake phase data to pass to the test phase. We use the # root logger as a logger, our stub plug manager, and a dummy test record # that has None for dut_id and station_id. phasedata = phase_data.PhaseData(logging.getLogger(), self.plug_manager, test_record.TestRecord(None, None)) phase_record = test_record.PhaseRecord(phase.name, phase.code_info) # Actually execute the phase, saving the result in our return value. with phasedata.RecordPhaseTiming(phase, phase_record): try: phase_record.result = phase_executor.PhaseOutcome( phase(phasedata)) except Exception as exc: logging.exception('Exception executing phase %s', phase.name) phase_record.result = phase_executor.PhaseOutcome(exc) return phase_record
def _ExecuteOnePhase(self, phase): """Executes the given phase, returning a PhaseOutcome.""" phase_data = self.test_state.phase_data # Check this as early as possible. if phase.options.run_if and not phase.options.run_if(phase_data): _LOG.info('Phase %s skipped due to run_if returning falsey.', phase.name) self.test_state.pending_phases.pop(0) return _LOG.info('Executing phase %s with plugs %s', phase.name, phase_data.plugs) self.test_state.running_phase_record = test_record.PhaseRecord( phase.name, phase.code_info) with phase_data.RecordPhaseTiming(phase, self.test_state) as outcome_wrapper: phase_thread = PhaseExecutorThread(phase, phase_data) phase_thread.start() self._current_phase_thread = phase_thread outcome_wrapper.SetOutcome(phase_thread.JoinOrDie()) if outcome_wrapper.outcome.phase_result == openhtf.PhaseResult.CONTINUE: self.test_state.pending_phases.pop(0) _LOG.debug('Phase finished with outcome %s', outcome_wrapper.outcome) return outcome_wrapper.outcome
def _ExecuteOnePhase(self, phase): """Executes the given phase, returning a PhaseOutcome.""" phase_data = self.test_state.phase_data # Check this as early as possible. if phase.options.run_if and not phase.options.run_if(phase_data): _LOG.info('Phase %s skipped due to run_if returning falsey.', phase.name) if self.test_state.pending_phases: self.test_state.pending_phases.pop(0) return _LOG.info('Executing phase %s', phase.name) phase_record = test_record.PhaseRecord(phase.name, phase.code_info) self.test_state.running_phase_record = phase_record with phase_data.RecordPhaseTiming(phase, phase_record): phase_thread = PhaseExecutorThread(phase, phase_data) phase_thread.start() self._current_phase_thread = phase_thread phase_outcome = phase_thread.JoinOrDie() # Save the outcome of the phase and do some cleanup. phase_record.result = phase_outcome self.test_state.record.phases.append(phase_record) self.test_state.running_phase_record = None # We're done with this phase, pop it from the pending phases. if (phase_outcome.phase_result is openhtf.PhaseResult.CONTINUE and self.test_state.pending_phases): self.test_state.pending_phases.pop(0) _LOG.debug('Phase finished with outcome %s', phase_outcome) return phase_outcome
def _ExecuteOnePhase(self, phase): """Executes the given phase.""" data = self._test_state.phase_data # Check this as early as possible. if phase.options.run_if and not phase.options.run_if(data): _LOG.info('Phase %s skipped due to run_if returning falsey.', phase.func.__name__) self._test_state.pending_phases.pop(0) return _LOG.info('Executing phase %s with plugs %s', phase.func.__name__, data.plugs) self._test_state.running_phase = test_record.PhaseRecord( phase.func.__name__, phase.source, docstring=phase.func.__doc__) with data.RecordPhaseTiming(phase, self._test_state) as result_wrapper: phase_thread = PhaseExecutorThread(phase, data) phase_thread.start() self._current_phase = phase_thread result_wrapper.SetResult(phase_thread.JoinOrDie()) if result_wrapper.result.phase_result == phase_data.PhaseResults.CONTINUE: self._test_state.pending_phases.pop(0) _LOG.debug('Phase finished with state %s', result_wrapper.result) return result_wrapper.result
def _ExecuteOnePhase(self, phase): """Executes the given phase.""" # Check this as early as possible. if hasattr(phase, 'run_if') and not phase.run_if(self._phase_data): _LOG.info('Phase %s skipped due to run_if returning falsey.', phase.__name__) self._test_state.pending_phases.pop(0) return _LOG.info('Executing phase %s with plugs %s', phase.__name__, self._phase_data.plugs) root_phase = phase while hasattr(root_phase, 'wraps'): root_phase = root_phase.wraps self._test_state.running_phase = test_record.PhaseRecord( phase.__name__, inspect.getsource(root_phase), docstring=phase.__doc__) with self._phase_data.RecordPhaseTiming( phase, self._test_state) as result_wrapper: phase_thread = PhaseExecutorThread(phase, self._phase_data) phase_thread.start() self._current_phase = phase_thread result_wrapper.SetResult(phase_thread.JoinOrDie()) if result_wrapper.result.phase_result == phase_data.PhaseResults.CONTINUE: self._test_state.pending_phases.pop(0) _LOG.debug('Phase finished with state %s', result_wrapper.result) return result_wrapper.result