def __new__(cls): kwargs = {} if conf.Config().libusb_rsa_key: kwargs['rsa_keys'] = [ adb_device.M2CryptoSigner(conf.Config().libusb_rsa_key) ] device = adb_device.AdbDevice.Connect( _open_usb_handle(interface_class=adb_device.CLASS, interface_subclass=adb_device.SUBCLASS, interface_protocol=adb_device.PROTOCOL), **kwargs) device.TearDown = device.Close # pylint: disable=invalid-name return device
def _open_usb_handle(**kwargs): """Open a UsbHandle subclass, based on configuration. If configuration 'usb_server' is set, use it to connect to remote usb, otherwise attempt to connect locally. Args: **kwargs: Arguments to pass to respective handle's Open() method. Returns: Instance of UsbHandle. """ if conf.Config().usb_server: return None else: return local_usb.LibUsbHandle.Open(**kwargs)
def __init__(self, config, test, plugs, dut_id): station_id = conf.Config().station_id self._state = self.State.CREATED self._config = config self.record = test_record.TestRecord( dut_id=dut_id, station_id=station_id, metadata={ 'code': test.code, 'filename': test.filename, 'docstring': test.docstring }) self.logger = logging.getLogger(test.filename) self.logger.setLevel(logging.DEBUG) # Let the handler do the filtering. self.logger.addHandler(logs.RecordHandler(self.record)) self.phase_data = phase_data.PhaseData(self.logger, config, plugs, self.record) self.running_phase = None self.pending_phases = list(test.phases)
class Test(object): """An object that represents an OpenHTF test. This object encapsulates the static test state including an ordered tuple of phases to execute. Args: *phases: The ordered list of phases to execute for this test. """ def __init__(self, *phases): """Creates a new Test to be executed. Args: *phases: The ordered list of phases to execute for this test. """ self.loop = False self.phases = [TestPhaseInfo.WrapOrReturn(phase) for phase in phases] self.output_callbacks = [] # Pull some metadata from the frame in which this Test was created. frame_record = inspect.stack()[1] self.filename = os.path.basename(frame_record[1]) self.docstring = inspect.getdoc(inspect.getmodule(frame_record[0])) self.code = inspect.getsource(frame_record[0]) @property def plug_type_map(self): """Returns dict mapping name to plug type for all phases.""" plug_type_map = {} for plug, plug_type in itertools.chain.from_iterable( ((plug.name, plug.cls) for plug in phase.plugs) for phase in self.phases): if (plug in plug_type_map and plug_type is not plug_type_map[plug]): raise plugs.DuplicatePlugError( 'Duplicate plug with different type: %s' % plug) plug_type_map[plug] = plug_type return plug_type_map def AddOutputCallback(self, callback): """Add the given function as an output module to this test.""" self.output_callbacks.append(callback) def OutputTestRecord(self, test_record): """Feed the record of this test to all output modules.""" for output_cb in self.output_callbacks: output_cb(test_record) def Execute(self, loop=None, test_start=triggers.AutoStart, test_stop=triggers.AutoStop): """Start the OpenHTF framework running with the given test. Executes this test, iterating over self.phases and executing them. Example: def PhaseOne(test): # Integrate more widgets def PhaseTwo(test): # Analyze widget integration status Test(PhaseOne, PhaseTwo).Execute() Returns: None when the test framework has exited. """ try: FLAGS(sys.argv) # parse flags except gflags.FlagsError, e: # pylint: disable=invalid-name print '%s\nUsage: %s ARGS\n%s' % (e, sys.argv[0], FLAGS) sys.exit(1) logs.setup_logger() if loop is not None: self.loop = loop conf.Load() config = conf.Config() rundata.RunData(config.station_id, self.filename, socket.gethostname(), FLAGS.http_port, os.getpid()).SaveToFile(FLAGS.rundir) _LOG.info('Executing test: %s', self.filename) executor = exe.TestExecutor(config, self, test_start, test_stop) server = http_api.Server(executor) def sigint_handler(*dummy): """Handle SIGINT by stopping running executor and handler.""" print "Received SIGINT. Stopping everything." executor.Stop() server.Stop() signal.signal(signal.SIGINT, sigint_handler) server.Start() executor.Start() executor.Wait() server.Stop() return
def DoChangingStuff(self): """Increment output successive calls.""" config = conf.Config() self.value[0] += config.example_plug_increment return self.value[0]