def test_enable_disable(self): instrument = _instantiate(MockInstrument) instrument2 = _instantiate(MockInstrument2) instrumentation.install(instrument) instrumentation.install(instrument2) instrumentation.disable_all() signal.send(signal.BEFORE_WORKLOAD_EXECUTION, self, context=None) signal.send(signal.AFTER_WORKLOAD_EXECUTION, self, context=None) signal.send(signal.AFTER_WORKLOAD_RESULT_UPDATE, self, context=None) assert_equal(instrument.before, 0) assert_equal(instrument.after, 0) assert_equal(instrument2.before, 0) assert_equal(instrument2.after, 0) assert_equal(instrument2.result, 0) instrumentation.enable(instrument) signal.send(signal.BEFORE_WORKLOAD_EXECUTION, self, context=None) signal.send(signal.AFTER_WORKLOAD_EXECUTION, self, context=None) signal.send(signal.AFTER_WORKLOAD_RESULT_UPDATE, self, context=None) assert_equal(instrument.before, 1) assert_equal(instrument.after, 1) assert_equal(instrument2.before, 0) assert_equal(instrument2.after, 0) assert_equal(instrument2.result, 0) instrumentation.enable_all() signal.send(signal.BEFORE_WORKLOAD_EXECUTION, self, context=None) signal.send(signal.AFTER_WORKLOAD_EXECUTION, self, context=None) signal.send(signal.AFTER_WORKLOAD_RESULT_UPDATE, self, context=None) assert_equal(instrument.before, 2) assert_equal(instrument.after, 2) assert_equal(instrument2.before, 1) assert_equal(instrument2.after, 1) assert_equal(instrument2.result, 1)
def _run_job(self): # pylint: disable=too-many-branches spec = self.current_job.spec if not spec.enabled: self.logger.info('Skipping workload %s (iteration %s)', spec, self.context.current_iteration) self.current_job.result.status = IterationResult.SKIPPED return self.logger.info('Running workload %s (iteration %s)', spec, self.context.current_iteration) if spec.flash: if not self.context.reboot_policy.can_reboot: raise ConfigError('Cannot flash as reboot_policy does not permit rebooting.') if not self.device.can('flash'): raise DeviceError('Device does not support flashing.') self._flash_device(spec.flash) elif not self.completed_jobs: # Never reboot on the very fist job of a run, as we would have done # the initial reboot if a reboot was needed. pass elif self.context.reboot_policy.reboot_on_each_spec and self.spec_changed: self.logger.debug('Rebooting on spec change.') self._reboot_device() elif self.context.reboot_policy.reboot_on_each_iteration: self.logger.debug('Rebooting on iteration.') self._reboot_device() instrumentation.disable_all() instrumentation.enable(spec.instrumentation) self.device.start() if self.spec_changed: self._send(signal.WORKLOAD_SPEC_START) self._send(signal.ITERATION_START) try: setup_ok = False with self._handle_errors('Setting up device parameters'): self.device.set_runtime_parameters(spec.runtime_parameters) setup_ok = True if setup_ok: with self._handle_errors('running {}'.format(spec.workload.name)): self.current_job.result.status = IterationResult.RUNNING self._run_workload_iteration(spec.workload) else: self.logger.info('\tSkipping the rest of the iterations for this spec.') spec.enabled = False except KeyboardInterrupt: self._send(signal.ITERATION_END) self._send(signal.WORKLOAD_SPEC_END) raise else: self._send(signal.ITERATION_END) if self.spec_will_change or not spec.enabled: self._send(signal.WORKLOAD_SPEC_END) finally: self.device.stop()