def __init__(self, hostname, port=1234, gpib_address=14, read_timeout_seconds=30, connect_timeout_seconds=5): """Constructs a wrapper for the Prologix TCP<->GPIB bridge : Arguments: hostname: hostname of prologix device port: port number gpib_address: initial GPIB device to connect to read_timeout_seconds: the read time out for the socket to the prologix box connect_timeout_seconds: the read time out for the socket to the prologix box """ logger_name = 'prologix' s = 'IP:%s GPIB:%s: ' % (hostname, gpib_address) formatter_string = '%(asctime)s %(filename)s %(lineno)d ' + s + \ '- %(message)s' self.scpi_logger = cellular_logging.SetupCellularLogging( logger_name, formatter_string) self.connection_key = "%s:%s" % (hostname, port) self.connection_data = {self.connection_key: traceback.format_stack()} if self.connection_key in self.all_open_connections.keys(): raise cellular_system_error.BadState( 'IP network connection to ' 'prologix is already in use. : %s ' % self.all_open_connections) self.all_open_connections[self.connection_key] = self.connection_data self.socket = connect_to_port(hostname, port, connect_timeout_seconds) self.read_timeout_seconds = read_timeout_seconds self.socket.setblocking(0) self.SetAuto(1) self._AddCarrigeReturnsToResponses() self.SetGpibAddress(gpib_address) self.scpi_logger.debug('set read_timeout_seconds: %s ' % self.read_timeout_seconds)
from autotest_lib.client.bin import utils from autotest_lib.client.common_lib import error from autotest_lib.client.cros.cellular import cellular from autotest_lib.client.cros.cellular import cellular_system_error from autotest_lib.client.cros.cellular import mm from autotest_lib.client.cros.cellular import modem from autotest_lib.client.cros import flimflam_test_path import flimflam TIMEOUT = 30 SERVICE_TIMEOUT = 60 import cellular_logging logger = cellular_logging.SetupCellularLogging('cell_tools') def ConnectToCellular(flim, timeout=TIMEOUT): """Attempts to connect to a cell network using FlimFlam. Args: flim: A flimflam object timeout: Timeout (in seconds) before giving up on connect Returns: a tuple of the service and the service state Raises: Error if connection fails or times out """
# Copyright (c) 2013 The Chromium OS Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. import scpi import cellular_logging import unittest import common from autotest_lib.client.cros.cellular import labconfig import base_station_pxt import prologix_scpi_driver log = cellular_logging.SetupCellularLogging('base_station_pxt_test') config = labconfig.Configuration(['--cell', 'mtv', '--technology', 'CDMA']) class test_pxt(unittest.TestCase): """ Test the pxt class. """ def test_BasicInit(self): self._call_box_init() self._call_box_close() def _call_box_init(self): x = config.cell['basestations'][1] adapter = x['gpib_adapter'] scpi_device = scpi.Scpi(prologix_scpi_driver.PrologixScpiDriver( hostname=adapter['address'],
sys.modules['flimflam'] = mock.MagicMock() from autotest_lib.client.cros.cellular import labconfig config = labconfig.Configuration(['--cell', 'mtv', '--technology', 'CDMA']) # Mock out the get_interface_ip and have it return a real DUT. # otherwise is looks up the IP of this machine and tries to find it # in the DUTs section of the lab config. Not useful if this test file # is run on a workstation. dut1_ip = config.cell['duts'][0]['address'] labconfig.get_interface_ip = mock.Mock(return_value=dut1_ip) # Must import after the mocks. import environment import cellular_logging log = cellular_logging.SetupCellularLogging('environment_test') class EnvTest(unittest.TestCase): def test_Env3G(self): """ make an environment """ with environment.DefaultCellularTestContext(config) as c: env = c.env env.StartDefault('Technology:HSDPA') def test_EnvLte(self): """ make an environment """
#!/usr/bin/python # Copyright (c) 2012 The Chromium OS Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. """Implement a modem proxy to talk to a ModemManager1 modem.""" from autotest_lib.client.common_lib import error from autotest_lib.client.cros.cellular import cellular from autotest_lib.client.cros.cellular import mm1 from autotest_lib.client.cros.cellular import mm1_constants import dbus import cellular_logging log = cellular_logging.SetupCellularLogging('modem1') MODEM_TIMEOUT = 60 class Modem(object): """An object which talks to a ModemManager1 modem.""" # MM_MODEM_GSM_ACCESS_TECH (not exported) # From /usr/include/mm/mm-modem.h _MM_MODEM_GSM_ACCESS_TECH_UNKNOWN = 0 _MM_MODEM_GSM_ACCESS_TECH_GSM = 1 << 1 _MM_MODEM_GSM_ACCESS_TECH_GSM_COMPACT = 1 << 2 _MM_MODEM_GSM_ACCESS_TECH_GPRS = 1 << 3 _MM_MODEM_GSM_ACCESS_TECH_EDGE = 1 << 4 _MM_MODEM_GSM_ACCESS_TECH_UMTS = 1 << 5 _MM_MODEM_GSM_ACCESS_TECH_HSDPA = 1 << 6 _MM_MODEM_GSM_ACCESS_TECH_HSUPA = 1 << 7 _MM_MODEM_GSM_ACCESS_TECH_HSPA = 1 << 8
#!/usr/bin/python # Copyright (c) 2013 The Chromium OS Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. import cellular_logging import cellular_system_error log = cellular_logging.SetupCellularLogging('scpi_driver') class _ErrorCheckerContext(object): """Reference-count our error-checking state and only check for errors when we take the first ref or drop the last ref. This way, we can minimize the number of checks; each one takes a bit of time. You will likely want to set always_check to True when debugging new SCPI interactions. On first entry, we check for errors, but do not stop if we find them; these are errors that were accumulated on the device before this test ran. """ def __init__(self, scpi): self.always_check = True # True for serious debugging self.scpi = scpi self.depth = 0 self.raise_on_error = True def __enter__(self): log.debug('ErrorCheckerContext Depth: %s' % self.depth)
#!/usr/bin/python # Copyright (c) 2013 The Chromium OS Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. import copy import mock import prologix_scpi_driver import scpi import unittest import cellular_logging import cellular_system_error log = cellular_logging.SetupCellularLogging('scpi_test') # TODO:(byronk): # a hack for now. Should look this up in labconfig_data. crbug.com/225108 # TODO:(byronk): # replace SystemError with a specific exception crbug.com/225127 scpi_instruments = [ # Agilent 8960 call box {'name_part': "8960", 'gpib_addr': '14', 'ip': '172.22.50.118'}, # PXT is called 6621 {'name_part': "6621", 'gpib_addr': '14', 'ip': "172.22.50.244"} ] class BasicPrologixTest(unittest.TestCase): """
"""Wrapper for an RF switch built on an Elexol EtherIO24. The EtherIO is documented at http://www.elexol.com/IO_Modules/Ether_IO_24_Dip_R.php This file is both a python module and a command line utility to speak to the module """ import cellular_logging import collections import socket import struct import sys log = cellular_logging.SetupCellularLogging('ether_io_rf_switch') class Error(Exception): pass class EtherIo24(object): """Encapsulates an EtherIO24 UDP-GPIO bridge.""" def __init__(self, hostname, port=2424): self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self.socket.bind(('', 0)) self.destination = (hostname, port) self.socket.settimeout(3) # In seconds