Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7d49fe8b authored by Hansong Zhang's avatar Hansong Zhang
Browse files

LeL2capTest PTS Annotation

Test: cert/run --host
Change-Id: Ia0025610532a31c7d3c2670f2659e157de16c008
parent f9da7089
Loading
Loading
Loading
Loading
+116 −39
Original line number Diff line number Diff line
@@ -13,23 +13,13 @@
#   See the License for the specific language governing permissions and
#   limitations under the License.

import time
from datetime import timedelta
from mobly import asserts

from cert.gd_base_test import GdBaseTestClass
from cert.event_stream import EventStream
from cert.truth import assertThat
from cert.closable import safeClose
from cert.py_l2cap import PyLeL2cap
from cert.py_acl_manager import PyAclManager
from cert.matchers import L2capMatchers
from cert.metadata import metadata
from facade import common_pb2 as common
from facade import rootservice_pb2 as facade_rootservice
from google.protobuf import empty_pb2 as empty_proto
from l2cap.le import facade_pb2 as l2cap_facade_pb2
from neighbor.facade import facade_pb2 as neighbor_facade
from hci.facade import acl_manager_facade_pb2 as acl_manager_facade
from hci.facade import le_advertising_manager_facade_pb2 as le_advertising_facade
import bluetooth_packets_python3 as bt_packets
from bluetooth_packets_python3 import hci_packets, l2cap_packets
@@ -172,10 +162,13 @@ class LeL2capTest(GdBaseTestClass):
        """
        self._set_link_from_dut_and_open_channel()

    @metadata(
        pts_test_id="L2CAP/LE/CPU/BV-01-C",
        pts_test_name="Send Connection Parameter Update Request")
    def test_send_connection_parameter_update_request(self):
        """
        L2CAP/LE/CPU/BV-01-C
        NOTE: This is an option feature. Also if both LL master and slave supports 4.1+ connection parameter update, this should happen in LL only, not L2CAP
        Verify that the IUT is able to send the connection parameter update Request to Lower Tester when acting as a slave device.
        NOTE: This is an optional feature. Also if both LL master and slave supports 4.1+ connection parameter update, this should happen in LL only, not L2CAP
        NOTE: Currently we need to establish at least one dynamic channel to allow update.
        """
        self._setup_link_from_cert()
@@ -184,9 +177,12 @@ class LeL2capTest(GdBaseTestClass):
        assertThat(self.cert_l2cap.get_control_channel()).emits(
            L2capMatchers.LeConnectionParameterUpdateRequest())

    @metadata(
        pts_test_id="L2CAP/LE/CPU/BV-02-C",
        pts_test_name="Accept Connection Parameter Update Request")
    def test_accept_connection_parameter_update_request(self):
        """
        L2CAP/LE/CPU/BV-02-C
        Verify that the IUT is able to receive and handle a request for connection parameter update when acting as a master device.
        NOTE: Currently we need to establish at least one dynamic channel to allow update.
        """
        self._set_link_from_dut_and_open_channel()
@@ -197,9 +193,12 @@ class LeL2capTest(GdBaseTestClass):
            L2capMatchers.LeConnectionParameterUpdateResponse(
                l2cap_packets.ConnectionParameterUpdateResponseResult.ACCEPTED))

    @metadata(
        pts_test_id="L2CAP/LE/CPU/BI-01-C",
        pts_test_name="Reject Connection Parameter Update Parameters")
    def test_reject_connection_parameter_update_parameters(self):
        """
        L2CAP/LE/CPU/BI-01-C
        Verify that the IUT is able to reject a request for connection parameter update with illegal parameters.
        NOTE: Currently we need to establish at least one dynamic channel to allow update.
        """
        self._set_link_from_dut_and_open_channel()
@@ -210,9 +209,12 @@ class LeL2capTest(GdBaseTestClass):
            L2capMatchers.LeConnectionParameterUpdateResponse(
                l2cap_packets.ConnectionParameterUpdateResponseResult.REJECTED))

    @metadata(
        pts_test_id="L2CAP/LE/CPU/BI-02-C",
        pts_test_name="Reject Connection Parameter Update Request")
    def test_reject_connection_parameter_update_request(self):
        """
        L2CAP/LE/CPU/BI-02-C
        Verify that the IUT is able to reject a request for connection parameter update in slave mode.
        """
        self._setup_link_from_cert()
        self.cert_l2cap.get_control_channel().send(
@@ -221,9 +223,10 @@ class LeL2capTest(GdBaseTestClass):
        assertThat(self.cert_l2cap.get_control_channel()).emits(
            L2capMatchers.LeCommandReject())

    @metadata(pts_test_id="L2CAP/COS/CFC/BV-01-C", pts_test_name="Segmentation")
    def test_segmentation(self):
        """
        L2CAP/COS/CFC/BV-01-C
        Verify that the IUT can send data segments which are larger than the LE frame size.
        """
        self._setup_link_from_cert()
        (dut_channel, cert_channel) = self._open_channel_from_cert(
@@ -236,9 +239,11 @@ class LeL2capTest(GdBaseTestClass):
            L2capMatchers.FirstLeIFrame(b'hello' * 20, sdu_size=105),
            L2capMatchers.Data(b'world')).inOrder()

    @metadata(
        pts_test_id="L2CAP/COS/CFC/BV-02-C", pts_test_name="No Segmentation")
    def test_no_segmentation(self):
        """
        L2CAP/COS/CFC/BV-02-C
        Verify that the IUT can send data segments which do not require segmentation.
        """
        self._setup_link_from_cert()
        (dut_channel, cert_channel) = self._open_channel_from_cert(
@@ -256,9 +261,10 @@ class LeL2capTest(GdBaseTestClass):
        assertThat(cert_channel).emits(
            L2capMatchers.FirstLeIFrame(b'hello' * 40, sdu_size=200))

    @metadata(pts_test_id="L2CAP/COS/CFC/BV-03-C", pts_test_name="Reassembling")
    def test_reassembling(self):
        """
        L2CAP/COS/CFC/BV-03-C
        Verify that the IUT can correctly reassemble data received from the Lower Tester which is greater than the IUT LE-frame size.
        """
        self._setup_link_from_cert()
        (dut_channel, cert_channel) = self._open_channel_from_cert()
@@ -269,9 +275,11 @@ class LeL2capTest(GdBaseTestClass):
        assertThat(dut_channel).emits(
            L2capMatchers.PacketPayloadRawData(b'\x19\x26\x08\x17' * 2))

    @metadata(
        pts_test_id="L2CAP/COS/CFC/BV-04-C", pts_test_name="Data Receiving")
    def test_data_receiving(self):
        """
        L2CAP/COS/CFC/BV-04-C
        Verify that the IUT can receive unsegmented data correctly.
        """
        self._setup_link_from_cert()
        (dut_channel, cert_channel) = self._open_channel_from_cert()
@@ -280,14 +288,20 @@ class LeL2capTest(GdBaseTestClass):
            L2capMatchers.PacketPayloadRawData(b'\x19\x26\x08\x17'))

    def test_data_receiving_dut_is_master(self):
        """
        L2CAP/COS/CFC/BV-04-C
        """
        (dut_channel, cert_channel) = self._set_link_from_dut_and_open_channel()
        cert_channel.send_first_le_i_frame(4, SAMPLE_PACKET)
        assertThat(dut_channel).emits(
            L2capMatchers.PacketPayloadRawData(b'\x19\x26\x08\x17'))

    @metadata(
        pts_test_id="L2CAP/COS/CFC/BV-05-C",
        pts_test_name="Multiple Channels with Interleaved Data Streams")
    def test_multiple_channels_with_interleaved_data_streams(self):
        """
        L2CAP/COS/CFC/BV-05-C
        Verify that an IUT can create multiple channels and receives data streams on the channels when the streams are interleaved.
        """
        self._setup_link_from_cert()
        (dut_channel_x, cert_channel_x) = self._open_channel_from_cert(
@@ -312,9 +326,12 @@ class LeL2capTest(GdBaseTestClass):
        assertThat(dut_channel_z).emits(
            L2capMatchers.PacketPayloadRawData(b'\x19\x26\x08\x17'))

    @metadata(
        pts_test_id="L2CAP/LE/REJ/BI-01-C",
        pts_test_name="Reject Unknown Command in LE Signaling Channel")
    def test_reject_unknown_command_in_le_sigling_channel(self):
        """
        L2CAP/LE/REJ/BI-01-C
        Verify that the IUT is able to reject unknown command.
        """
        self._setup_link_from_cert()
        self.cert_l2cap.get_control_channel().send(
@@ -324,9 +341,12 @@ class LeL2capTest(GdBaseTestClass):
        assertThat(self.cert_l2cap.get_control_channel()).emits(
            L2capMatchers.LeCommandReject())

    @metadata(
        pts_test_id="L2CAP/LE/REJ/BI-02-C",
        pts_test_name="Command Reject – Reserved PDU Codes")
    def test_command_reject_reserved_pdu_codes(self):
        """
        L2CAP/LE/REJ/BI-02-C
        Verify that an IUT receiving a PDU with a reserved command code sends a command reject.
        """
        self._setup_link_from_cert()
        self.cert_l2cap.get_control_channel().send(
@@ -334,9 +354,12 @@ class LeL2capTest(GdBaseTestClass):
        assertThat(self.cert_l2cap.get_control_channel()).emits(
            L2capMatchers.LeCommandReject())

    @metadata(
        pts_test_id="L2CAP/LE/CFC/BV-01-C",
        pts_test_name="LE Credit Based Connection Request - Legacy Peer")
    def test_le_credit_based_connection_request_legacy_peer(self):
        """
        L2CAP/LE/CFC/BV-01-C
        Verify that an IUT sending an LE Credit Based Connection Request to a legacy peer and receiving a Command Reject does not establish the channel.
        """
        self._setup_link_from_cert()
        response_future = self.dut_l2cap.connect_coc_to_cert(psm=0x33)
@@ -344,9 +367,12 @@ class LeL2capTest(GdBaseTestClass):
        assertThat(response_future.get_status()).isNotEqualTo(
            LeCreditBasedConnectionResponseResult.SUCCESS)

    @metadata(
        pts_test_id="L2CAP/LE/CFC/BV-02-C",
        pts_test_name="LE Credit Based Connection Request on Supported LE_PSM")
    def test_le_credit_based_connection_request_on_supported_le_psm(self):
        """
        L2CAP/LE/CFC/BV-02-C
        Verify that an IUT sending an LE Credit Based Connection Request to a peer will establish the channel upon receiving the LE Credit Based Connection Response.
        """
        self._setup_link_from_cert()
        (dut_channel, cert_channel) = self._open_channel_from_dut()
@@ -354,9 +380,12 @@ class LeL2capTest(GdBaseTestClass):
        assertThat(dut_channel).emits(
            L2capMatchers.PacketPayloadRawData(b'\x19\x26\x08\x17'))

    @metadata(
        pts_test_id="L2CAP/LE/CFC/BV-03-C",
        pts_test_name="LE Credit Based Connection Response on Supported LE_PSM")
    def test_credit_based_connection_response_on_supported_le_psm(self):
        """
        L2CAP/LE/CFC/BV-03-C
        Verify that an IUT receiving a valid LE Credit Based Connection Request from a peer will send an LE Credit Based Connection Response and establish the channel.
        """
        self._setup_link_from_cert()
        (dut_channel, cert_channel) = self._open_channel_from_cert()
@@ -364,9 +393,13 @@ class LeL2capTest(GdBaseTestClass):
        assertThat(cert_channel).emits(
            L2capMatchers.FirstLeIFrame(b'hello', sdu_size=5))

    @metadata(
        pts_test_id="L2CAP/LE/CFC/BV-04-C",
        pts_test_name=
        "LE Credit Based Connection Request on an Unsupported LE_PSM")
    def test_credit_based_connection_request_on_an_unsupported_le_psm(self):
        """
        L2CAP/LE/CFC/BV-04-C
        Verify that an IUT sending an LE Credit Based Connection Request on an unsupported LE_PSM will not establish a channel upon receiving an LE Credit Based Connection Response refusing the connection.
        """
        self._setup_link_from_cert()
        response_future = self.dut_l2cap.connect_coc_to_cert(psm=0x33)
@@ -376,9 +409,12 @@ class LeL2capTest(GdBaseTestClass):
        assertThat(response_future.get_status()).isEqualTo(
            LeCreditBasedConnectionResponseResult.LE_PSM_NOT_SUPPORTED)

    @metadata(
        pts_test_id="L2CAP/LE/CFC/BV-05-C",
        pts_test_name="LE Credit Based Connection Request - unsupported LE_PSM")
    def test_credit_based_connection_request_unsupported_le_psm(self):
        """
        L2CAP/LE/CFC/BV-05-C
        Verify that an IUT receiving an LE Credit Based Connection Request on an unsupported LE_PSM will respond with an LE Credit Based Connection Response refusing the connection.
        """
        self._setup_link_from_cert()
        self.cert_l2cap.get_control_channel().send(
@@ -389,9 +425,12 @@ class LeL2capTest(GdBaseTestClass):
                result=LeCreditBasedConnectionResponseResult.
                LE_PSM_NOT_SUPPORTED))

    @metadata(
        pts_test_id="L2CAP/LE/CFC/BV-06-C",
        pts_test_name="Credit Exchange – Receiving Incremental Credits")
    def test_credit_exchange_receiving_incremental_credits(self):
        """
        L2CAP/LE/CFC/BV-06-C
        Verify the IUT handles flow control correctly, by handling the LE Flow Control Credit sent by the peer.
        """
        self._setup_link_from_cert()
        (dut_channel,
@@ -409,9 +448,12 @@ class LeL2capTest(GdBaseTestClass):
            L2capMatchers.FirstLeIFrame(b'hello', sdu_size=5),
            L2capMatchers.FirstLeIFrame(b'hello', sdu_size=5))

    @metadata(
        pts_test_id="L2CAP/LE/CFC/BV-07-C",
        pts_test_name="Credit Exchange – Sending Credits")
    def test_credit_exchange_sending_credits(self):
        """
        L2CAP/LE/CFC/BV-07-C
        Verify that the IUT sends LE Flow Control Credit to the peer.
        """
        self._setup_link_from_cert()
        (dut_channel, cert_channel) = self._open_channel_from_cert()
@@ -424,26 +466,35 @@ class LeL2capTest(GdBaseTestClass):
            cert_channel.send_first_le_i_frame(4, SAMPLE_PACKET)
        self.cert_l2cap.verify_le_flow_control_credit(cert_channel)

    @metadata(
        pts_test_id="L2CAP/LE/CFC/BV-08-C",
        pts_test_name="Disconnection Request")
    def test_disconnection_request(self):
        """
        L2CAP/LE/CFC/BV-08-C
        Verify that the IUT can disconnect the channel.
        """
        self._setup_link_from_cert()
        (dut_channel, cert_channel) = self._open_channel_from_cert()
        dut_channel.close_channel()
        cert_channel.verify_disconnect_request()

    @metadata(
        pts_test_id="L2CAP/LE/CFC/BV-09-C",
        pts_test_name="Disconnection Response")
    def test_disconnection_response(self):
        """
        L2CAP/LE/CFC/BV-09-C
        Verify that the IUT responds correctly to reception of a Disconnection Request.
        """
        self._setup_link_from_cert()
        (dut_channel, cert_channel) = self._open_channel_from_cert()
        cert_channel.disconnect_and_verify()

    @metadata(
        pts_test_id="L2CAP/LE/CFC/BV-10-C",
        pts_test_name="Security - Insufficient Authentication – Initiator")
    def test_security_insufficient_authentication_initiator(self):
        """
        L2CAP/LE/CFC/BV-10-C
        Verify that the IUT does not establish the channel upon receipt of an LE Credit Based Connection Response indicating the connection was refused with Result “0x0005 – Connection Refused – Insufficient Authentication".
        """
        self._setup_link_from_cert()
        response_future = self.dut_l2cap.connect_coc_to_cert(psm=0x33)
@@ -454,9 +505,12 @@ class LeL2capTest(GdBaseTestClass):
        assertThat(response_future.get_status()).isEqualTo(
            LeCreditBasedConnectionResponseResult.INSUFFICIENT_AUTHENTICATION)

    @metadata(
        pts_test_id="L2CAP/LE/CFC/BV-12-C",
        pts_test_name="Security - Insufficient Authorization – Initiator")
    def test_security_insufficient_authorization_initiator(self):
        """
        L2CAP/LE/CFC/BV-12-C
        Verify that the IUT does not establish the channel upon receipt of an LE Credit Based Connection Response indicating the connection was refused with Result “0x0006 – Connection Refused – Insufficient Authorization”.
        """
        self._setup_link_from_cert()
        response_future = self.dut_l2cap.connect_coc_to_cert(psm=0x33)
@@ -467,9 +521,14 @@ class LeL2capTest(GdBaseTestClass):
        assertThat(response_future.get_status()).isEqualTo(
            LeCreditBasedConnectionResponseResult.INSUFFICIENT_AUTHORIZATION)

    @metadata(
        pts_test_id="L2CAP/LE/CFC/BV-18-C",
        pts_test_name=
        "LE Credit Based Connection Request - refused due to Invalid Source CID - Initiator"
    )
    def test_request_refused_due_to_invalid_source_cid_initiator(self):
        """
        L2CAP/LE/CFC/BV-18-C
        Verify that an IUT sending an LE Credit Based Connection Request does not establish the channel upon receiving an LE Credit Based Connection Response refusing the connection with result "0x0009 – Connection refused – Invalid Source CID".
        """
        self._setup_link_from_cert()
        response_future = self.dut_l2cap.connect_coc_to_cert(psm=0x33)
@@ -479,10 +538,15 @@ class LeL2capTest(GdBaseTestClass):
        assertThat(response_future.get_status()).isEqualTo(
            LeCreditBasedConnectionResponseResult.INVALID_SOURCE_CID)

    @metadata(
        pts_test_id="L2CAP/LE/CFC/BV-19-C",
        pts_test_name=
        "LE Credit Based Connection Request - refused due to source CID already allocated - Initiator"
    )
    def test_request_refused_due_to_source_cid_already_allocated_initiator(
            self):
        """
        L2CAP/LE/CFC/BV-19-C
        Verify that an IUT sending an LE Credit Based Connection Request does not establish the channel upon receiving an LE Credit Based Connection Response refusing the connection with result "0x000A – Connection refused – Source CID already allocated".
        """
        self._setup_link_from_cert()
        response_future = self.dut_l2cap.connect_coc_to_cert(psm=0x33)
@@ -493,10 +557,15 @@ class LeL2capTest(GdBaseTestClass):
        assertThat(response_future.get_status()).isEqualTo(
            LeCreditBasedConnectionResponseResult.SOURCE_CID_ALREADY_ALLOCATED)

    @metadata(
        pts_test_id="L2CAP/LE/CFC/BV-20-C",
        pts_test_name=
        "LE Credit Based Connection Response - refused due to Source CID already allocated - Responder"
    )
    def test_request_refused_due_to_source_cid_already_allocated_responder(
            self):
        """
        L2CAP/LE/CFC/BV-20-C
        Verify that an IUT receiving an LE Credit Based Connection Request for a second channel will refuse the connection with result "0x000A - Connection refused – Source CID already allocated" if it receives a Source CID which is already in use.
        """
        self._setup_link_from_cert()
        (dut_channel, cert_channel) = self._open_channel_from_cert(
@@ -508,9 +577,14 @@ class LeL2capTest(GdBaseTestClass):
        assertThat(self.cert_l2cap.get_control_channel()).emits(
            L2capMatchers.CreditBasedConnectionResponseUsedCid())

    @metadata(
        pts_test_id="L2CAP/LE/CFC/BV-21-C",
        pts_test_name=
        "LE Credit Based Connection Request - refused due to Unacceptable Parameters - Initiator"
    )
    def test_request_refused_due_to_unacceptable_parameters_initiator(self):
        """
        L2CAP/LE/CFC/BV-21-C
        Verify that an IUT sending an LE Credit Based Connection Request does not establish the channel upon receiving an LE Credit Based Connection Response refusing the connection with result "0x000B – Connection refused – Unacceptable Parameters".
        """
        self._setup_link_from_cert()
        response_future = self.dut_l2cap.connect_coc_to_cert(psm=0x33)
@@ -521,9 +595,12 @@ class LeL2capTest(GdBaseTestClass):
        assertThat(response_future.get_status()).isEqualTo(
            LeCreditBasedConnectionResponseResult.UNACCEPTABLE_PARAMETERS)

    @metadata(
        pts_test_id="L2CAP/LE/CFC/BI-01-C",
        pts_test_name="Credit Exchange – Exceed Initial Credits")
    def test_credit_exchange_exceed_initial_credits(self):
        """
        L2CAP/LE/CFC/BI-01-C
        Verify that the IUT disconnects the LE Data Channel when the credit count exceeds 65535.
        """
        self._setup_link_from_cert()
        (dut_channel, cert_channel) = self._open_channel_from_cert()