def test_rfcomm_longev_read_write_large_message(self):
        """Longevity test an RFCOMM connection's I/O with a large message

        Test the longevity of RFCOMM with a basic read/write
        connect/disconnect sequence. The data being transfered is 990 chars
        in size.

        Steps:
        1. Establish a bonding between two Android devices.
        2. Write data to RFCOMM from the client droid.
        3. Read data from RFCOMM from the server droid.
        4. Verify data written matches data read.
        5. Repeat steps 2-4 5000 times.
        6. Disconnect RFCOMM connection.
        7. Repeat steps 1-6 1000 times.

        Expected Result:
        Each iteration should read and write to the RFCOMM connection
        successfully. Each connect and disconnect should be successful.

        Returns:
          Pass if True
          Fail if False

        TAGS: Classic, Longevity, RFCOMM
        Priority: 2
        """
        server_mac = self.server_ad.droid.bluetoothGetLocalAddress()
        message = "x" * 990  #largest message size till sl4a fixed
        write_iterations = 5000
        for i in range(self.longev_iterations):
            self.log.info("iteration {} connection".format(i))
            self.orchestrate_rfcomm_connect(server_mac)
            for n in range(write_iterations):
                self.log.info("iteration {} data".format(
                    ((n + 1) + (i * write_iterations))))
                if not write_read_verify_data(self.client_ad, self.server_ad,
                                              message, False):
                    return False
                self.log.info("Iteration {} completed".format(n))
            self.client_ad.droid.bluetoothRfcommStop()
            self.server_ad.droid.bluetoothRfcommStop()
        for t in self.thread_list:
            t.join()
        self.thread_list.clear()
        return True
Exemple #2
0
    def test_rfcomm_longev_read_write_small_message(self):
        """Longevity test an RFCOMM connection's I/O with a small message

        Test the longevity of RFCOMM with a basic read/write
        connect/disconnect sequence. The data being transfered is only
        one character in size.

        Steps:
        1. Establish a bonding between two Android devices.
        2. Write data to RFCOMM from the client droid.
        3. Read data from RFCOMM from the server droid.
        4. Verify data written matches data read.
        5. Repeat steps 2-4 5000 times.
        6. Disconnect RFCOMM connection.
        7. Repeat steps 1-6 1000 times.

        Expected Result:
        Each iteration should read and write to the RFCOMM connection
        successfully. Each connect and disconnect should be successful.

        Returns:
          Pass if True
          Fail if False

        TAGS: Classic, Longevity, RFCOMM
        Priority: 2
        """
        message = "x"
        for i in range(self.longev_iterations):
            self.log.info("iteration {} connection".format(i + 1))
            if not orchestrate_rfcomm_connection(self.client_ad,
                                                 self.server_ad):
                return False
            for n in range(self.write_iterations):
                self.log.info("iteration {} data".format(
                    ((n + 1) + (i * self.write_iterations))))
                if not write_read_verify_data(self.client_ad, self.server_ad,
                                              message, False):
                    return False
                self.log.info("Iteration {} completed".format(n))
            self.client_ad.droid.bluetoothRfcommStop()
            self.server_ad.droid.bluetoothRfcommStop()
        return True
Exemple #3
0
    def test_coc_insecured_connection_write_ascii(self):
        """Test LE CoC insecured connection writing and reading ascii data

        Test LE CoC though establishing a connection.

        Steps:
        1. Get the mac address of the server device.
        2. Establish an LE CoC connection from the client to the server AD. The security of
        connection is FALSE.
        3. Verify that the LE CoC connection is active from both the client and
        server.
        4. Write data from the client and read received data from the server.
        5. Verify data matches from client and server
        6. Disconnect the LE CoC connection.

        Expected Result:
        LE CoC connection is established then disconnected succcessfully.

        Returns:
          Pass if True
          Fail if False

        TAGS: BLE, CoC
        Priority: 1
        """
        is_secured = False
        self.log.info(
            "test_coc_secured_connection_write_ascii: calling "
            "orchestrate_coc_connection. is_secured={}".format(is_secured))
        status, client_conn_id, server_conn_id = orchestrate_coc_connection(
            self.client_ad, self.server_ad, True, is_secured)
        if not status:
            return False
        if not write_read_verify_data(self.client_ad, self.server_ad,
                                      self.message, False):
            return False
        if not verify_server_and_client_connected(self.client_ad,
                                                  self.server_ad):
            return False

        return True
Exemple #4
0
    def test_rfcomm_write_binary(self):
        """Test bluetooth RFCOMM writing and reading binary data

        Test profile though establishing an RFCOMM connection.

        Steps:
        1. Get the mac address of the server device.
        2. Establish an RFCOMM connection from the client to the server AD.
        3. Verify that the RFCOMM connection is active from both the client and
        server.
        4. Write data from the client and read received data from the server.
        5. Verify data matches from client and server
        6. Disconnect the RFCOMM connection.

        Expected Result:
        RFCOMM connection is established then disconnected succcessfully.

        Returns:
          Pass if True
          Fail if False

        TAGS: Classic, RFCOMM
        Priority: 1
        """
        if not orchestrate_rfcomm_connection(self.client_ad, self.server_ad):
            return False
        binary_message = "11010101"
        if not write_read_verify_data(self.client_ad, self.server_ad,
                                      binary_message, True):
            return False

        if not verify_server_and_client_connected(self.client_ad,
                                                  self.server_ad):
            return False

        self.client_ad.droid.bluetoothRfcommStop()
        self.server_ad.droid.bluetoothRfcommStop()
        return True
    def _measure_latency(self):
        """Measures the latency of data transfer over RFCOMM.

        Sends data from the client device that is read by the server device.
        Calculates the latency of the transfer.

        Returns:
            The latency of the transfer milliseconds.
        """

        # Generates a random message to transfer
        message = (''.join(
            random.choice(string.ascii_letters + string.digits)
            for _ in range(6)))

        start_time = time.perf_counter()
        write_read_successful = write_read_verify_data(self.client_device,
                                                       self.server_device,
                                                       message, False)
        end_time = time.perf_counter()
        asserts.assert_true(write_read_successful,
                            'Failed to send/receive message')
        return (end_time - start_time) * 1000
Exemple #6
0
    def test_rfcomm_connection_write_msg_stress(self):
        """Stress test an RFCOMM connection

        Test the integrity of RFCOMM. Verify that file descriptors are cleared
        out properly.

        Steps:
        1. Establish a bonding between two Android devices.
        2. Write data to RFCOMM from the client droid.
        3. Read data from RFCOMM from the server droid.
        4. Stop the RFCOMM connection.
        5. Repeat steps 2-4 1000 times.

        Expected Result:
        Each iteration should read and write to the RFCOMM connection
        successfully.

        Returns:
          Pass if True
          Fail if False0

        TAGS: Classic, Stress, RFCOMM
        Priority: 1
        """
        iterations = 1000
        for n in range(iterations):
            if not orchestrate_rfcomm_connection(self.client_ad,
                                                 self.server_ad):
                return False
            if not write_read_verify_data(self.client_ad, self.server_ad,
                                          self.message, False):
                return False
            self.client_ad.droid.bluetoothRfcommStop()
            self.server_ad.droid.bluetoothRfcommStop()
            self.log.info("Iteration {} completed".format(n))
        return True
Exemple #7
0
    def test_rfcomm_longev_data_elasticity(self):
        """Longevity test an RFCOMM connection's I/O with changing data size

        Test the longevity of RFCOMM with a basic read/write
        connect/disconnect sequence. The data being transfered changes
        in size after each write/read sequence to increase up to 990
        chars in size and decrease down to 1 in size. This repeats through
        the entire test in order to exercise different size values being
        written.

        Steps:
        1. Establish a bonding between two Android devices.
        2. Write data to RFCOMM from the client droid.
        3. Read data from RFCOMM from the server droid.
        4. Verify data written matches data read.
        5. Change data size according to above description.
        6. Repeat steps 2-5 5000 times.
        7. Disconnect RFCOMM connection.
        8. Repeat steps 1-6 1000 times.

        Expected Result:
        Each iteration should read and write to the RFCOMM connection
        successfully. Each connect and disconnect should be successful.

        Returns:
          Pass if True
          Fail if False

        TAGS: Classic, Longevity, RFCOMM
        Priority: 2
        """
        message = "x"
        resize_toggle = 1
        for i in range(self.longev_iterations):
            try:
                self.log.info("iteration {} connection".format(i + 1))
                if not orchestrate_rfcomm_connection(self.client_ad,
                                                     self.server_ad):
                    return False
                for n in range(self.write_iterations):
                    self.log.info("iteration {} data".format(
                        ((n + 1) + (i * self.write_iterations))))
                    if not write_read_verify_data(
                            self.client_ad, self.server_ad, message, False):
                        return False
                    self.log.info("Iteration {} completed".format(n))
                    size_of_message = len(message)
                    #max size is 990 due to a bug in sl4a.
                    if size_of_message >= 990:
                        resize_toggle = 0
                    elif size_of_message <= 1:
                        resize_toggle = 1
                    if resize_toggle == 0:
                        message = "x" * (size_of_message - 1)
                    else:
                        message = "x" * (size_of_message + 1)
                self.client_ad.droid.bluetoothRfcommStop()
                self.server_ad.droid.bluetoothRfcommStop()
            except Exception as err:
                self.log.info("Error in longevity test: {}".format(err))
                return False
        return True
Exemple #8
0
    def test_rfcomm_longev_connection_interuption(self):
        """Longevity test an RFCOMM connection's with socket interuptions

        Test the longevity of RFCOMM with a basic read/write
        connect/disconnect sequence. Randomly in the sequence of reads and
        writes the socket on the client side will close. There should be
        an exception thrown for writing the next set of data and the
        test should start up a new connection and continue.

        Steps:
        1. Establish a bonding between two Android devices.
        2. Write data to RFCOMM from the client droid.
        3. Read data from RFCOMM from the server droid.
        4. Verify data written matches data read.
        5. Repeat steps 2-4 5000 times or until the random interupt occurs.
        6. Re-establish an RFCOMM connection.
        7. Repeat steps 1-6 1000 times.

        Expected Result:
        Each iteration should read and write to the RFCOMM connection
        successfully. Each connect and disconnect should be successful.
        Devices should recover a new connection after each interruption.

        Returns:
          Pass if True
          Fail if False

        TAGS: Classic, Longevity, RFCOMM
        Priority: 2
        """
        for i in range(self.longev_iterations):
            try:
                self.log.info("iteration {} connection".format(i + 1))
                if not orchestrate_rfcomm_connection(self.client_ad,
                                                     self.server_ad):
                    return False
                random_interup_iteration = randint(0, self.write_iterations)
                for n in range(self.write_iterations):
                    self.log.info("iteration {} data".format(
                        ((n + 1) + (i * self.write_iterations))))
                    if not write_read_verify_data(self.client_ad,
                                                  self.server_ad,
                                                  self.generic_message, False):
                        return False
                    self.log.info("Iteration {} completed".format(n))
                    if n > random_interup_iteration:
                        self.client_ad.droid.bluetoothRfcommCloseSocket()
                self.client_ad.droid.bluetoothRfcommStop()
                self.server_ad.droid.bluetoothRfcommStop()
            except Exception:
                self.log.info("Exception found as expected. Continuing...")
                try:
                    self.client_ad.droid.bluetoothRfcommStop()
                except Exception as err:
                    self.log.error(
                        "Error closing client connection: {}".format(err))
                    return False
                try:
                    self.server_ad.droid.bluetoothRfcommStop()
                except Exception as err:
                    self.log.error(
                        "Error closing server connection: {}".format(err))
                    return False
        return True