コード例 #1
0
    def bt_find_device(self, remote_device_info):
        """
        Looks for a Bluetooth device.

        :type remote_device_info: str
        :param remote_device_info: Name or address of the device

        :rtype: boolean
        :return: True if found , False otherwise
        """
        bt_found = False
        bt_devices_list = self.bt_scan_devices()

        if NetworkingUtil.is_valid_mac_address(remote_device_info):
            # remote_device_info is a bd address
            for device in bt_devices_list:
                if (str(device.address).upper()
                        == str(remote_device_info).upper()
                        or str(device.name).upper()
                        == str(remote_device_info).upper()):
                    bt_found = True
                    self._logger.info("Device %s found" % remote_device_info)
                    break
        else:
            # remote_device_info is not a valid bd address, maybe a name !
            for device in bt_devices_list:
                if str(device.name) == str(remote_device_info):
                    bt_found = True
                    self._logger.info("Device %s found" % remote_device_info)
                    break

        if not bt_found:
            self._logger.info("Device " + remote_device_info +
                              " is not in range !")
        return bt_found
コード例 #2
0
    def _check_ipv6_address(self):
        """
        Set and check scope link IPV6 address is well allocated

        :rtype: int
        :return: Global.FAILURE (-1) if Failed

        :rtype: str
        :return: Error Message in case of failure
        """
        # Check scope link IPV6 address is well allocated
        ip_v6_local = self._networking_api.get_interface_ipv6_scopelink_address(
            self._device.get_cellular_network_interface())
        # check if IPV6 allocated to the device is a valid IP address
        if NetworkingUtil.is_valid_ipv6_address(ip_v6_local):
            # check if IPV6 allocated to the device is a valid IP address
            self._logger.info(
                "The local IPv6 address assigned to the DUT is %s " %
                ip_v6_local)
            Code = Global.SUCCESS
            Msg = "The local IPv6 address assigned to the DUT is %s " % ip_v6_local
        else:
            Code = Global.FAILURE
            Msg = "DUT does not have a local IPv6 assigned"
            self._logger.info(Msg)
        return Code, Msg
コード例 #3
0
ファイル: Networking.py プロジェクト: zenghui0-0/tempfile
    def _get_bssid_from_ssid(self, ssid, interface="wlan0"):
        """
        Get BSSID from SSID
        :type ssid: str
        :param ssid: The access point's SSID

        :rtype: str
        :return: The access point's mac address (BSSID)

        :type interface: str
        :param interface: interface name (wlan0/wlan1 etc...)

        """
        if (not ssid):
            raise AcsConfigException(AcsConfigException.INVALID_PARAMETER,
                                     ssid)

        cmd = "adb shell wpa_cli IFNAME=%s scan_result" % interface
        results = self._exec(cmd, timeout=5, wait_for_response=True)
        # Align all the carriage returns to \n to make it work on all OS and all adb connect method
        results = results.replace('\r', '\n')
        bssid = ''
        for line in results.split('\n'):
            if line.endswith(ssid):
                bssid = str(line).split()[0]
                break

        if (not NetworkingUtil.is_valid_mac_address(bssid)):
            msg = "Unable to get BSSID from SSID '%s' (result = %s)" % (ssid,
                                                                        bssid)
            self._logger.error(msg)
            raise DeviceException(DeviceException.OPERATION_FAILED, msg)
        return bssid
コード例 #4
0
 def _validate_bt_address(self, remote_device_addr):
     """
     Validate bt address
     """
     # Check address format
     remote_device_addr = str(remote_device_addr).upper()
     if not NetworkingUtil.is_valid_mac_address(remote_device_addr):
         raise AcsConfigException(AcsConfigException.INVALID_PARAMETER, "BD address \'%s\' has a bad format!" \
                                  % remote_device_addr)
コード例 #5
0
    def get_default_addr(self):
        """
        Get the default BD address (persistant address)

        :rtype: str
        :return: default BD address. format: 12:34:56:78:9A:BC
                 otherwise return empty str
        """

        BDADDR_PATH_PROPERTY = "ro.bt.bdaddr_path"
        PERSIST_BDROID_ADDR = "persist.service.bdroid.bdaddr"

        device_properties = DeviceManager().get_device_properties(
            self._device.get_name())

        # 1. Default from bd_addr.conf file if it exists and not null
        if BDADDR_PATH_PROPERTY in device_properties:
            bdconf_path = device_properties.get(BDADDR_PATH_PROPERTY)
            cmd = "adb shell cat %s" % bdconf_path
            bdconf = self._exec(cmd)
            bdconf = str(bdconf).upper().strip()
            if bdconf.find("NO SUCH FILE OR DIRECTORY"):
                bdconf = ""
            if bdconf not in ["", "00:00:00:00:00:00"]:
                self._logger.debug("Default BD Address from %s is <%s>" %
                                   (bdconf_path, bdconf))
                if NetworkingUtil.is_valid_mac_address(bdconf):
                    return bdconf
                else:
                    return ""

        # 2. Default from persist.service.bdroid.bdaddr property
        if PERSIST_BDROID_ADDR in device_properties:
            bdaddr = device_properties.get(PERSIST_BDROID_ADDR)
        else:
            bdaddr = ""
        bdaddr = str(bdaddr).upper().strip()
        self._logger.debug(
            "Default BD Address from persist.service.bdroid.bdaddr is <%s>" %
            bdaddr)
        if NetworkingUtil.is_valid_mac_address(bdaddr):
            return bdaddr
        else:
            return ""
コード例 #6
0
    def _pingv4only(self):
        # Ping IPV6
        packet_lossv6 = self._networking_api.\
            ping6(self._server_ip_v6_address,
                  self._packet_size,
                  self._nb_pings,
                  blocking=False)

        # Check if IP V6 Fails
        if packet_lossv6.value == -1:
            # Check if DUT have an address IP V6 allocated
            self.ip_v6 = self._ns_data_4g.get_ip_address("IPV6",
                                                         blocking=False)

            if NetworkingUtil.is_valid_ipv6_address(str(self.ip_v6)):
                self._error.Code = Global.FAILURE
                self._error.Msg = "DUT have a valid IPV6 address when NW is set to IPV4 only"
                self._logger.info(self._error.Msg)
                return self._error.Code, self._error.Msg

            else:
                msg = "PING IPV6: FAILED (as expected) because DUT does not have an IPV6 address allocated"
                self._logger.info(msg)
                self._error.Msg = msg
        else:
            self._error.Code = Global.FAILURE
            self._error.Msg = "ERROR :PING with IPV6 SHOULD FAIL, Measured IPV6 Packet Loss: %.0f%s (Target: %.0f%s)"\
                % (packet_lossv6.value,
                   packet_lossv6.units,
                   self._target_ping_packet_loss_rate,
                   packet_lossv6.units)
            self._logger.error(self._error.Msg)

        # Ping IPV4
        packet_lossv4 = self._networking_api.\
            ping(self._server_ip_address,
                 self._packet_size,
                 self._nb_pings)

        # Compute verdict depending on % of packet loss
        if packet_lossv4.value > self._target_ping_packet_loss_rate:
            self._error.Code = Global.FAILURE
        else:
            self._error.Code = Global.SUCCESS

        msg = "Ping IPV4: SUCCEEDED with Measured Packet Loss: %.0f%s (Target: %.0f%s)"\
            % (packet_lossv4.value,
               packet_lossv4.units,
               self._target_ping_packet_loss_rate,
               packet_lossv4.units)

        self._logger.info(msg)

        self._error.Msg += " & " + msg

        return self._error.Code, self._error.Msg
コード例 #7
0
    def set_external_ip_address(self, ip):
        """
        This function sets the external IP address
        :type ip: str
        :param ip: The external IP address to set
        :raise TestEquipmentException: failed to call SetExternalIpAddress driver function
        """
        if not NetworkingUtil.is_valid_ipv4_address(ip):
            msg = "Invalid external IP address passed to the equipment: %s" % ip
            self.get_logger().error(msg)
            raise TestEquipmentException(TestEquipmentException.INVALID_PARAMETER, msg)

        (err, msg) = W.SetExternalIpAddress(self, ip)
        self.__error_check(err, msg)
コード例 #8
0
    def set_up(self):
        """
        Initialize the test
        """
        # pylint: disable=E1101
        UseCaseBase.set_up(self)

        # Check sw release in DUT is engineering build
        if "eng" not in str(self._device.device_properties.sw_release):
            msg = "TC blocked by userdebug sw release"
            self._logger.error(msg)
            raise AcsConfigException(AcsConfigException.INVALID_PARAMETER, msg)

        # Check prov_mode value
        self._prov_mode = str(self._prov_mode).lower()
        if self._prov_mode not in ["no_prov", "prov"]:
            msg = "PROV_MODE value <%s> is not supported" % str(
                self._prov_mode)
            self._logger.error(msg)
            raise AcsConfigException(AcsConfigException.INVALID_PARAMETER, msg)

        # turn on bluetooth
        self._logger.info("Turn on Bluetooth adapters")
        self._bt_api.set_bt_power("on")
        time.sleep(self._wait_btwn_cmd)
        if self._bt_api.get_bt_power_status() != str(BT_STATE.STATE_ON):
            msg = "set BT ON failure"
            self._logger.error(msg)
            raise DeviceException(DeviceException.OPERATION_FAILED, msg)

        # Check address format
        if self._prov_mode == "prov":
            self._original_addr = self._original_addr.upper().strip()
            bdaddr_z = self._original_addr.replace('X', '0')
            if not NetworkingUtil.is_valid_mac_address(bdaddr_z):
                new_msg = "BAD format of NEW_ADDR parameter: <%s>" % self._original_addr
                raise AcsConfigException(AcsConfigException.INVALID_PARAMETER,
                                         new_msg)
        else:
            # Check default BD_address after BT is ON
            self._default_addr = self._bt_api.get_default_addr()
            if self._default_addr == "":
                new_msg = "Unable to get default BD address <%s>" % self._default_addr
                raise AcsConfigException(AcsConfigException.INVALID_PARAMETER,
                                         new_msg)

        return Global.SUCCESS, "No errors"
コード例 #9
0
    def ble_scan_filter_address(self, remote_device_address, scan_mode,
                                timeout):
        """
        BLE Filtered scanning for a device address.

        :rtype: str
        :return: Found Bluetooth Device
        """
        bt_found = False
        btdev = BluetoothDevice()

        method = "filterLeAddress"
        args = "--es address %s --ei scanMode %s --ei cmdTimeout %s" % (
            remote_device_address, scan_mode, timeout)

        output = self._internal_exec_v2(
            self._BLUETOOTH_LE_MODULE,
            method,
            args,
            timeout=self.millis_to_seconds(int(timeout)) + 5,
            is_system=True)

        if NetworkingUtil.is_valid_mac_address(remote_device_address):
            # remote_device_info is a bd address
            for device in output:
                if (str(device.address).upper()
                        == str(remote_device_address).upper()
                        or str(device.name).upper()
                        == str(remote_device_address).upper()):
                    bt_found = True
                    self._logger.info("Device %s found" %
                                      remote_device_address)

        if "Address" in output:
            btdev.address = output["Address"]
        if "Name" in output:
            btdev.name = output["Name"]

        self._logger.info("Device name: " + btdev.name + " address: " +
                          btdev.address)

        if not bt_found:
            self._logger.info("Device " + remote_device_address +
                              " is not in range or could not be filtered!")
            return False
        else:
            return btdev
コード例 #10
0
    def ble_gatt_client_connect_to_server(self, address):
        """

        :param address:
        :return:
        """
        method = "connectGatt"
        args = "--es address %s" % address
        if not NetworkingUtil.is_valid_mac_address(address):
            return

        output = self._internal_exec_v2(self._BLUETOOTH_LE_MODULE,
                                        method,
                                        args,
                                        is_system=True)

        # check that the result is success
        return output
コード例 #11
0
    def ble_gatt_client_discover_services(self, address):
        """

        :return:
        """
        method = "discoverGattServices"
        args = "--es address %s" % address

        if not NetworkingUtil.is_valid_mac_address(address):
            return

        output = self._internal_exec_v2(self._BLUETOOTH_LE_MODULE,
                                        method,
                                        args,
                                        is_system=True)

        # check that the result is success
        return output
コード例 #12
0
    def ble_gatt_client_read_characteristic(self, address):
        """

        :return:
        """
        method = "readGattCharacteristic"
        args = "--es address %s" % address

        if not NetworkingUtil.is_valid_mac_address(address):
            return

        output = self._internal_exec_v2(self._BLUETOOTH_LE_MODULE,
                                        method,
                                        args,
                                        is_system=True)

        # check that the result is success
        return output
コード例 #13
0
    def ble_gatt_client_reliable_write(self, address, reliable_write_value):
        """

        :return:
        """
        method = "gattReliableWrite"
        args = "--es address %s --es reliableWriteValue %s" % (
            address, reliable_write_value)

        if not NetworkingUtil.is_valid_mac_address(address):
            return

        output = self._internal_exec_v2(self._BLUETOOTH_LE_MODULE,
                                        method,
                                        args,
                                        is_system=True)

        # check that the result is success
        return output
コード例 #14
0
    def ble_gatt_client_write_descriptor(self, address,
                                         write_descriptor_value):
        """

        :return:
        """
        method = "writeGattDescriptor"
        args = "--es address %s --es writeDescriptorValue %s" % (
            address, write_descriptor_value)

        if not NetworkingUtil.is_valid_mac_address(address):
            return

        output = self._internal_exec_v2(self._BLUETOOTH_LE_MODULE,
                                        method,
                                        args,
                                        is_system=True)

        # check that the result is success
        return output
コード例 #15
0
    def _pingv6only(self):
        """
        ping with IPV6 address v6 and also verify that ping IPv4 fails

        :rtype: int
        :return: 0 if PASS, -1 if Failed, -2 if Blocked

        :rtype: str
        :return: Error Message in case of failure
        """
        # Ping IPV4
        packet_lossv4 = self._networking_api.\
            ping(self._server_ip_address,
                 self._packet_size,
                 self._nb_pings,
                 blocking=False)
        # Check if IP V4 Fails
        if packet_lossv4.value == -1:
            # Check if DUT have an address IP V4 allocated
            self.ip_v4 = self._ns_data_4g.get_ip_address("IPV4",
                                                         blocking=False)

            if NetworkingUtil.is_valid_ipv4_address(str(self.ip_v4)):
                self._error.Code = Global.FAILURE
                self._error.Msg = "DUT have a valid IPV4 address when NW is set to IPV6 only"
                self._logger.info(self._error.Msg)
                return self._error.Code, self._error.Msg

            else:
                msg = "PING IPV4: FAILED (as expected) because DUT does not have an IPV4 address allocated"
                self._logger.info(msg)
                self._error.Msg = msg
        else:
            self._error.Code = Global.FAILURE
            self._error.Msg = "ERROR :PING with IPV4 SHOULD FAIL, Measured IPV4 Packet Loss: %.0f%s (Target: %.0f%s)"\
                % (packet_lossv4.value,
                   packet_lossv4.units,
                   self._target_ping_packet_loss_rate,
                   packet_lossv4.units)
            self._logger.error(self._error.Msg)
            return self._error.Code, self._error.Msg
        # Ping IPV6
        packet_lossv6 = self._networking_api.\
            ping6(self._server_ip_v6_address,
                  self._packet_size,
                  self._nb_pings)
        # Compute verdict depending on % of packet loss
        if packet_lossv6.value > self._target_ping_packet_loss_rate:
            self._error.Code = Global.FAILURE
        else:
            self._error.Code = Global.SUCCESS

        msg = "Ping IPV6: SUCCEEDED with Measured Packet Loss: %.0f%s (Target: %.0f%s)"\
            % (packet_lossv6.value,
               packet_lossv6.units,
               self._target_ping_packet_loss_rate,
               packet_lossv6.units)
        self._logger.info(msg)
        self._error.Msg += " & " + msg

        return self._error.Code, self._error.Msg
コード例 #16
0
    def set_up(self):
        """
        Initialize the test
        """
        LiveDualPhoneBTBase.set_up(self)

        # Check BT addresses validity
        if not NetworkingUtil.is_valid_mac_address(self._phone1_addr):
            msg = "Wrong MAC address for PHONE1 [%s]" % self._phone1_addr
            raise AcsConfigException(AcsConfigException.INVALID_PARAMETER, msg)
        if not NetworkingUtil.is_valid_mac_address(self._phone2_addr):
            msg = "Wrong MAC address for PHONE2 [%s]" % self._phone2_addr
            raise AcsConfigException(AcsConfigException.INVALID_PARAMETER, msg)

        # Set sender/receiver APIs and variables
        if self._direction == self.UPLOAD:
            self._sender_api = self._bt_api
            self._sender_add = self._phone1_addr
            self._sender_device = self._device
            self._sender_phonesys_api = self._phonesystem_api
            self._receiver_api = self._bt_api2
            self._receiver_add = self._phone2_addr
            self._receiver_device = self._phone2
            self._receiver_phonesys_api = self._phonesystem2_api
            (self._fullpath_filenames, expected_size1) = self \
                ._process_files(self._multimedia_path1, self._file_list, False)

            (self._fp_filename_other_dir, expected_size2) = self \
                ._process_files(self._multimedia_path2, self._file_list, True)
        elif self._direction == self.DOWNLOAD:
            self._sender_api = self._bt_api2
            self._sender_add = self._phone2_addr
            self._sender_device = self._phone2
            self._sender_phonesys_api = self._phonesystem2_api
            self._receiver_api = self._bt_api
            self._receiver_add = self._phone1_addr
            self._receiver_device = self._device
            self._receiver_phonesys_api = self._phonesystem_api
            (self._fullpath_filenames, expected_size1) = self \
                ._process_files(self._multimedia_path2, self._file_list, False)

            (self._fp_filename_other_dir, expected_size2) = self \
                ._process_files(self._multimedia_path1, self._file_list, True)
        else:
            msg = "Invalid DIRECTION parameter [%s]" % self._direction
            self._logger.error(msg)
            raise AcsConfigException(AcsConfigException.INVALID_PARAMETER, msg)

        if expected_size1 != expected_size2:
            # same files, hence must have same size!!
            msg = "Files size are supposed to be the same!!"
            self._logger.error(msg)
            raise DeviceException(DeviceException.OPERATION_FAILED, msg)

        self._timeout1 = int(
            expected_size1 / self.BT_OPP_SPEED_FOR_TIMEOUT) + 20
        self._timeout2 = int(
            expected_size2 / self.BT_OPP_SPEED_FOR_TIMEOUT) + 20

        # Set receiver discoverable by sender
        self._receiver_api.set_bt_discoverable("connectable", 0)
        # First Scan devices around to speed-up run_test
        self._sender_api.bt_scan_devices()

        # unlock screen and set display ON
        # Mandatory prior to use bt_opp_send_file UECmd
        self._sender_phonesys_api.display_on()
        self._sender_phonesys_api.set_phone_lock(0)

        # Process the bidirectional transfer
        if self._is_bidirectional:
            # Set sender discoverable by receiver
            self._sender_api.set_bt_discoverable("connectable", 0)
            self._receiver_api.bt_scan_devices()
            self._receiver_phonesys_api.display_on()
            self._receiver_phonesys_api.set_phone_lock(0)

        # Check throughput data validity
        if self._tp_enable:
            msg = "Throughput measurement is enabled"
            self._logger.info(msg)
            # Read the throughput targets
            self._throughput_targets = ConfigsParser("BT_Throughput_Targets").\
                parse_bt_targets(self._device.get_phone_model(), "OPP")

            # Verify validity of margin parameter
            if self._tp_margin.isdigit():
                self._throughtput_margin = int(self._tp_margin)
            else:
                msg = "ERROR_MARGIN parameter is not valid: <%s>" % self._tp_margin
                self._logger.error(msg)
                raise DeviceException(DeviceException.OPERATION_FAILED, msg)

            # Initialize Average tp measure
            self._reset_tp_meas(self._file_list, self._direction,
                                self._is_bidirectional)

        return Global.SUCCESS, "No errors"
コード例 #17
0
    def ping(self,
             ip_address,
             packet_size,
             packet_count,
             interval=1,
             flood_mode=False,
             unreach_loss=False):
        """
        Pings a destination address

        :type ip_address: str
        :param ip_address: IP address to ping

        :type packet_size: integer
        :param packet_size: Packet size in bytes

        :type packet_count: integer
        :param packet_count: Number of packets to send

        :type interval: float
        :param interval: Interval in seconds between pings

        :type flood_mode: Boolean
        :param flood_mode: True if you want to use the ping in flood mode, False else.

        :type unreach_loss: Boolean
        :param unreach_loss: True if you want to count Destination host unreachable reply as ping loss, False else.

        :rtype: Measure object
        :return: packet loss
        """

        if int(packet_count) > 0:
            if int(interval) > 0:
                ping_timeout = int(packet_count * interval) + 20
            else:
                ping_timeout = int(packet_count) + 20
        else:
            self._logger.error("'packet count' must be an Integer > 0")
            raise AcsConfigException(AcsConfigException.INVALID_PARAMETER,
                                     "'packet count' must be an Integer > 0")

        if not flood_mode:
            flood_option = ""
            flood_txt = ""
        else:
            flood_option = " -f"
            flood_txt = "(flood mode) "

        self._logger.info("Ping address " + flood_txt + str(ip_address) +
                          " with " + str(packet_count) + " packets of " +
                          str(packet_size) + " bytes...")

        # Compute whether ip_address is V4 or V6 format.
        if NetworkingUtil.is_valid_ipv4_address(str(ip_address)):
            linux_cmd = "ping"
            win_cmd = "ping -4"
        elif NetworkingUtil.is_valid_ipv6_address(str(ip_address)):
            linux_cmd = "ping6"
            win_cmd = "ping -6"
        else:
            raise TestEquipmentException(
                TestEquipmentException.INVALID_PARAMETER,
                "%s is not a valid IP address" % str(ip_address))

        if self._os == self.WINDOWS:
            if packet_count > 1 and interval != 1:
                # no interval option on Windows ping, loop
                temp_ret = 0
                for _count in range(packet_count):
                    start_time = time.time()
                    ret = self.ping(ip_address, packet_size, 1, 1, flood_mode)
                    temp_ret += ret.value
                    end_time = time.time()
                    if end_time - start_time < interval:
                        time.sleep(interval - (end_time - start_time))
                ret.value = temp_ret / packet_count
                return ret
            cmd = str(win_cmd) + " -l " + str(packet_size) + \
                " -n " + str(packet_count) + " " + str(ip_address)
        else:
            cmd = str(linux_cmd) + " -s " + str(packet_size) + flood_option + \
                " -c " + str(packet_count) + " -i " + str(interval) + \
                " " + str(ip_address)

        output = self.run_cmd(cmd, ping_timeout)
        output = output["std"]

        output_lower = output.lower()
        packet_loss = Measure()

        # Search the loss rate
        if unreach_loss:
            # Get number of sent packet in output (here nb sent packet = 4):
            # Packets: Sent = 4, Received = 4, Lost = 0 (0% loss)
            search1 = re.search("packets: sent = ([0-9]+)", output_lower)
            # Get number of valid ping replies, a valid replies looks like:
            # Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
            search2 = re.findall("ttl=([0-9]+)", output_lower)
            if search1 is not None:
                nb_sent_ping = int(search1.group(1))
                nb_good_ping = len(search2)
                packet_loss.units = "%"
                packet_loss.value = (
                    100 * (nb_sent_ping - nb_good_ping)) / nb_sent_ping
            else:
                error = "Ping command returned an error message (Output = %s)" \
                    % output
                self._logger.error(error)
                raise TestEquipmentException(
                    TestEquipmentException.DEFAULT_ERROR_CODE, error)
        else:
            search = re.search("([0-9]+\.?[0-9]*)%[a-zA-Z ]*loss",
                               output_lower)
            if search is not None:
                packet_loss.value = float(search.group(1))
                packet_loss.units = "%"
            else:
                error = "Ping command returned an error message (Output = %s)" \
                    % output
                self._logger.error(error)
                raise TestEquipmentException(
                    TestEquipmentException.DEFAULT_ERROR_CODE, error)
        return packet_loss
コード例 #18
0
ファイル: LAB_BT_A2DP.py プロジェクト: zenghui0-0/tempfile
    def set_up(self):
        """
        Initialize the test
        """
        LiveBTBase.set_up(self)

        # Check audio command list is not empty
        if (len(self._audiocmd_list) == 1
                and self._audiocmd_list[0].strip() == ""):
            msg = "MUSIC_CONTROL_SEQUENCE cannot be empty"
            self._logger.error(msg)
            raise AcsConfigException(AcsConfigException.INVALID_PARAMETER, msg)

        # Check CONNECT_INITIATOR value is valid
        self._connector = self._connector.upper()
        if self._connector not in ("DUT", "HEADSET"):
            msg = "BAD CONNECT_INITIATOR value. only DUT or HEADSET expected"
            self._logger.error(msg)
            raise AcsConfigException(AcsConfigException.INVALID_PARAMETER, msg)

        # Get Bluetooth instance
        self._bt_headset = self._em.get_bluetooth_headset("BT_HEADSET")

        # BD address of Headset
        self._hsaddr = self._bt_headset.get_bdaddress()

        if self._hsaddr.lower() in ["none", "", "00:00:00:00:00:00"]:
            msg = "No BD addr defined for BT HEADSET in bench_config"
            self._logger.error(msg)
            raise AcsConfigException(AcsConfigException.INVALID_PARAMETER, msg)

        # Check BT address validity
        if not NetworkingUtil.is_valid_mac_address(self._hsaddr):
            msg = "Wrong BD address for HEADSET [%s]" % self._hsaddr
            raise AcsConfigException(AcsConfigException.INVALID_PARAMETER, msg)

        # Initialize BT headset to OFF state
        self._init_headset_off()
        time.sleep(5)

        # In both case (connector DUT or HEADSET), DUT shall initiates pairing
        # Put HEADSET in pairing mode (HS shall be OFF prior to that step)
        self._logger.info("Set headset in pairable mode")
        self._bt_headset.set_discoverable()
        time.sleep(1)

        # DUT scan to discover remote headset
        if not self._bt_api.bt_find_device(self._hsaddr):
            msg = "Headset <%s> not found" % self._hsaddr
            self._logger.error(msg)
            raise DeviceException(DeviceException.OPERATION_FAILED, msg)
        # DUT initiates pairing to headset
        pair_result = self._bt_api.pair_to_device(self._hsaddr, 1)

        # pylint: disable=E1101
        if pair_result[0] == BT_BOND_STATE.BOND_BONDED:
            msg = "Pairing with headset succeeded"
            self._logger.info(msg)
        elif pair_result[0] == BT_BOND_STATE.BOND_NONE:
            msg = "Pairing with headset failed"
            self._logger.error(msg)
            raise DeviceException(DeviceException.OPERATION_FAILED, msg)
        else:
            msg = "[PHONE1]Unexpected return value %s" % pair_result
            self._logger.error(msg)
            raise DeviceException(DeviceException.OPERATION_FAILED, msg)

        if self._connector == "HEADSET":
            # If Initiator is HEADSET, DUT shall be discoverable
            self._bt_api.set_bt_discoverable("connectable", 0)

        return Global.SUCCESS, "No errors"
コード例 #19
0
    def set_up(self):
        """
        Initialize the test
        """
        LiveDualPhoneBTBase.set_up(self)

        # Check BT addresses validity
        if not NetworkingUtil.is_valid_mac_address(self._phone1_addr):
            msg = "Wrong MAC address for PHONE1 [%s]" % self._phone1_addr
            raise AcsConfigException(AcsConfigException.INVALID_PARAMETER, msg)
        if not NetworkingUtil.is_valid_mac_address(self._phone2_addr):
            msg = "Wrong MAC address for PHONE2 [%s]" % self._phone2_addr
            raise AcsConfigException(AcsConfigException.INVALID_PARAMETER, msg)

        # Set sender/receiver APIs and varialbes
        if self._direction.upper() == "UL":
            self._sender_api = self._bt_api
            self._sender_add = self._phone1_addr
            self._sender_device = self._device
            self._sender_phonesys_api = self._phonesystem_api
            self._receiver_api = self._bt_api2
            self._receiver_add = self._phone2_addr
            self._receiver_device = self._phone2
            self._receiver_phonesys_api = self._phonesystem2_api
            self._fullpath_filename = self._multimedia_path1 + "/" \
                + self._filename
            self._filesize = self._phonesystem_api.\
                get_file_size(self._fullpath_filename)
        elif self._direction.upper() == "DL":
            self._sender_api = self._bt_api2
            self._sender_add = self._phone2_addr
            self._sender_device = self._phone2
            self._sender_phonesys_api = self._phonesystem2_api
            self._receiver_api = self._bt_api
            self._receiver_add = self._phone1_addr
            self._receiver_device = self._device
            self._receiver_phonesys_api = self._phonesystem_api
            self._fullpath_filename = self._multimedia_path2 + "/" \
                + self._filename
            self._filesize = self._phonesystem2_api.\
                get_file_size(self._fullpath_filename)
        else:
            msg = "Invalid DIRECTION parameter [%s]" % self._direction
            self._logger.error(msg)
            raise AcsConfigException(AcsConfigException.INVALID_PARAMETER, msg)

        # Control the existence of the file to send and get the file size \
        # in order to determine the timeout duration
        if self._filesize < 0:
            msg = "Filesize is not accessible. " \
                + "File is probably missing on TX device"
            self._logger.error(msg)
            raise AcsConfigException(AcsConfigException.FEATURE_NOT_AVAILABLE,
                                     msg)

        self._timeout = int(
            self._filesize / self.BT_OPP_SPEED_FOR_TIMEOUT) + 20

        # Set receiver discoverable by sender
        self._receiver_api.set_bt_discoverable("connectable", 0)
        # First Scan devices around to speed-up run_test
        self._sender_api.bt_scan_devices()

        # unlock screen and set display ON
        # Mandatory prior to use bt_opp_send_file UECmd
        self._sender_phonesys_api.display_on()
        self._sender_phonesys_api.set_phone_lock(0)

        return Global.SUCCESS, "No errors"
コード例 #20
0
    def ping(self,
             ip_address,
             packet_size,
             packet_count,
             interval=1,
             flood_mode=False):
        """
        Pings a destination address

        :type ip_address: str
        :param ip_address: IP address to ping

        :type packet_size: integer
        :param packet_size: Packet size in bytes

        :type packet_count: integer
        :param packet_count: Number of packets to send

        :type interval: float
        :param interval: Interval in seconds between pings

        :type flood_mode: Boolean
        :param flood_mode: True if you want to use the ping in flood mode

        :rtype: Measure object
        :return: Packet loss in %
        """
        # Compute whether ip_address is V4 or V6 format.
        if NetworkingUtil.is_valid_ipv4_address(str(ip_address)):
            linux_cmd = "ping"
        elif NetworkingUtil.is_valid_ipv6_address(str(ip_address)):
            linux_cmd = "ping6"
        else:
            raise TestEquipmentException(TestEquipmentException.INVALID_PARAMETER,
                                         "%s is not a valid IP address" % str(ip_address))

        if not flood_mode:
            flood_option = ""
            flood_txt = ""
        else:
            flood_option = " -f"
            flood_txt = "(flood mode) "

        cmd = "%s -s " % linux_cmd + str(packet_size) + flood_option + \
            " -c " + str(packet_count) + " -i " + str(interval) + \
            " " + str(ip_address)

        self._logger.info("Ping address " + flood_txt + str(ip_address) +
                          " with " + str(packet_count) + " packets of " +
                          str(packet_size) + " bytes...")
        output = self.ssh_exec(self._host, self._login, cmd)

        output_lower = output.lower()
        packet_loss = Measure()

        # Search the loss rate
        search = re.search("([0-9]+\.?[0-9]*)%[a-zA-Z ]*loss", output_lower)
        if search is not None:
            packet_loss.value = float(search.group(1))
            packet_loss.units = "%"

        else:
            error = "Ping command returned an error message (Output = %s)" \
                % output
            self._logger.error(error)
            raise TestEquipmentException(TestEquipmentException.DEFAULT_ERROR_CODE, error)
        return packet_loss