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

Commit 8b33ba08 authored by Hansong Zhang's avatar Hansong Zhang
Browse files

L2capTest: Add missing tests for L2CAP 2/2

Add the following for L2CAP 2/2:
L2CAP/COS/CFD/BV-11-C
L2CAP/COS/CFD/BV-14-C

Test: cert/run --host
Change-Id: I2d4e85b9f4f0202b93ffcf267de350c09dce5532
parent f65e2930
Loading
Loading
Loading
Loading
+18 −3
Original line number Original line Diff line number Diff line
@@ -87,6 +87,12 @@ class CertL2capChannel(IEventStream):
            self._dcid, s, p, f, req_seq)
            self._dcid, s, p, f, req_seq)
        self._acl.send(frame.Serialize())
        self._acl.send(frame.Serialize())


    def send_configure_request(self, cert_channel, options):
        assertThat(self._scid).isEqualTo(1)
        request = l2cap_packets.ConfigurationRequestBuilder(
            2, cert_channel._dcid, l2cap_packets.Continuation.END, options)
        self.send(request)

    def send_information_request(self, type):
    def send_information_request(self, type):
        assertThat(self._scid).isEqualTo(1)
        assertThat(self._scid).isEqualTo(1)
        signal_id = 3
        signal_id = 3
@@ -251,9 +257,18 @@ class CertL2cap(Closable):
        self.fcs_enabled = True
        self.fcs_enabled = True


    # more of a hack for the moment
    # more of a hack for the moment
    def ignore_config_and_connections(self):
    def dont_send_configuration_req(self):
        self.control_table[CommandCode.CONFIGURATION_REQUEST] = lambda _: True
        self.control_table[CommandCode.CONNECTION_RESPONSE] =\
        self.control_table[CommandCode.CONNECTION_RESPONSE] = lambda _: True
            self.on_connection_response_dont_send_configuration_req

    def on_connection_response_dont_send_configuration_req(
            self, l2cap_control_view):
        connection_response_view = l2cap_packets.ConnectionResponseView(
            l2cap_control_view)
        sid = connection_response_view.GetIdentifier()
        scid = connection_response_view.GetSourceCid()
        dcid = connection_response_view.GetDestinationCid()
        self.scid_to_dcid[scid] = dcid


    # more of a hack for the moment
    # more of a hack for the moment
    def ignore_config_request(self):
    def ignore_config_request(self):
+87 −1
Original line number Original line Diff line number Diff line
@@ -210,7 +210,8 @@ class L2capTest(GdBaseTestClass):
        channel if no response occurs
        channel if no response occurs
        """
        """
        self._setup_link_from_cert()
        self._setup_link_from_cert()
        self.cert_l2cap.ignore_config_and_connections()
        self.cert_l2cap.ignore_config_request()
        self.cert_l2cap.dont_send_configuration_req()


        self._open_unvalidated_channel(scid=0x41, psm=0x33)
        self._open_unvalidated_channel(scid=0x41, psm=0x33)


@@ -308,6 +309,32 @@ class L2capTest(GdBaseTestClass):
        dut_channel.send(b"a" * 44)
        dut_channel.send(b"a" * 44)
        assertThat(cert_channel).emits(L2capMatchers.Data(b"a" * 44))
        assertThat(cert_channel).emits(L2capMatchers.Data(b"a" * 44))


    @metadata(
        pts_test_id="L2CAP/COS/CFD/BV-11-C",
        pts_test_name="Negotiation of Unsupported Parameter")
    def test_negotiation_of_unsupported_parameter(self):
        """
        Verify that the IUT can negotiate when the Lower Tester proposes an unsupported configuration
        parameter value.
        """
        self._setup_link_from_cert()
        self.cert_l2cap.ignore_config_request()
        self.cert_l2cap.dont_send_configuration_req()

        (dut_channel, cert_channel) = self._open_unvalidated_channel(
            scid=0x41, psm=0x33)

        mtu_opt = l2cap_packets.MtuConfigurationOption()
        mtu_opt.mtu = 20  # Invalid because minimum is 48

        self.cert_l2cap.get_control_channel().send_configure_request(
            cert_channel, [mtu_opt])

        assertThat(self.cert_l2cap.get_control_channel()).emits(
            L2capMatchers.ConfigurationResponse(
                result=l2cap_packets.ConfigurationResponseResult.
                UNACCEPTABLE_PARAMETERS))

    @metadata(
    @metadata(
        pts_test_id="L2CAP/COS/CFD/BV-12-C",
        pts_test_id="L2CAP/COS/CFD/BV-12-C",
        pts_test_name="Unknown Option Response")
        pts_test_name="Unknown Option Response")
@@ -324,6 +351,65 @@ class L2capTest(GdBaseTestClass):
        assertThat(self.cert_l2cap.get_control_channel()).emits(
        assertThat(self.cert_l2cap.get_control_channel()).emits(
            L2capMatchers.ConfigurationResponse())
            L2capMatchers.ConfigurationResponse())


    @metadata(
        pts_test_id="L2CAP/COS/CFD/BV-14-C",
        pts_test_name="Unknown Mandatory Options Request")
    def test_unknown_mandatory_options_request(self):
        """
        Verify that the IUT can give the appropriate error code when the Lower
        Tester proposes any number of unknown options where at least one is
        mandatory.
        Note: GD stack doesn't support extended window size. For other stacks,
              we may need to use some other config option
        """
        self._setup_link_from_cert()
        self.cert_l2cap.dont_send_configuration_req()

        (dut_channel, cert_channel) = self._open_unvalidated_channel(
            scid=0x41, psm=0x33)

        unknown_opt = l2cap_packets.ExtendedWindowSizeOption()
        unknown_opt.max_window_size = 20

        unknown_opt_hint = l2cap_packets.ExtendedWindowSizeOption()
        unknown_opt_hint.max_window_size = 20
        unknown_opt_hint.is_hint = l2cap_packets.ConfigurationOptionIsHint.OPTION_IS_A_HINT

        configuration_option_attempts = [[unknown_opt], [
            unknown_opt, unknown_opt_hint
        ], [unknown_opt, unknown_opt, unknown_opt], [
            unknown_opt, unknown_opt_hint, unknown_opt_hint, unknown_opt
        ], [
            unknown_opt_hint, unknown_opt_hint, unknown_opt_hint,
            unknown_opt_hint, unknown_opt
        ], [
            unknown_opt, unknown_opt_hint, unknown_opt_hint, unknown_opt,
            unknown_opt_hint, unknown_opt_hint
        ], [
            unknown_opt, unknown_opt, unknown_opt, unknown_opt, unknown_opt,
            unknown_opt, unknown_opt
        ], [
            unknown_opt_hint, unknown_opt_hint, unknown_opt_hint,
            unknown_opt_hint, unknown_opt_hint, unknown_opt_hint,
            unknown_opt_hint, unknown_opt
        ], [
            unknown_opt_hint, unknown_opt_hint, unknown_opt_hint,
            unknown_opt_hint, unknown_opt_hint, unknown_opt_hint,
            unknown_opt_hint, unknown_opt, unknown_opt
        ], [
            unknown_opt_hint, unknown_opt_hint, unknown_opt_hint,
            unknown_opt_hint, unknown_opt_hint, unknown_opt_hint,
            unknown_opt_hint, unknown_opt_hint, unknown_opt_hint, unknown_opt
        ]]

        for option_list in configuration_option_attempts:
            self.cert_l2cap.get_control_channel().send_configure_request(
                cert_channel, option_list)
        assertThat(self.cert_l2cap.get_control_channel()).emits(
            L2capMatchers.ConfigurationResponse(
                result=l2cap_packets.ConfigurationResponseResult.UNKNOWN_OPTIONS
            ))

    @metadata(
    @metadata(
        pts_test_id="L2CAP/COS/ECH/BV-01-C",
        pts_test_id="L2CAP/COS/ECH/BV-01-C",
        pts_test_name="Respond to Echo Request")
        pts_test_name="Respond to Echo Request")