110a65a902cec8c477688311d158cc036f0d6f53aRoshan Pius# Copyright 2014 The Chromium OS Authors. All rights reserved.
210a65a902cec8c477688311d158cc036f0d6f53aRoshan Pius# Use of this source code is governed by a BSD-style license that can be
310a65a902cec8c477688311d158cc036f0d6f53aRoshan Pius# found in the LICENSE file.
410a65a902cec8c477688311d158cc036f0d6f53aRoshan Pius
510a65a902cec8c477688311d158cc036f0d6f53aRoshan Piusimport common
610a65a902cec8c477688311d158cc036f0d6f53aRoshan Piusfrom autotest_lib.client.cros.cellular.mbim_compliance import mbim_constants
710a65a902cec8c477688311d158cc036f0d6f53aRoshan Piusfrom autotest_lib.client.cros.cellular.mbim_compliance import mbim_dts_test_base
810a65a902cec8c477688311d158cc036f0d6f53aRoshan Piusfrom autotest_lib.client.cros.cellular.mbim_compliance import mbim_errors
910a65a902cec8c477688311d158cc036f0d6f53aRoshan Piusfrom autotest_lib.client.cros.cellular.mbim_compliance.sequences \
1010a65a902cec8c477688311d158cc036f0d6f53aRoshan Pius        import loopback_sequence
1110a65a902cec8c477688311d158cc036f0d6f53aRoshan Pius
1210a65a902cec8c477688311d158cc036f0d6f53aRoshan Pius
1310a65a902cec8c477688311d158cc036f0d6f53aRoshan Piusclass cellular_MbimComplianceDTS0511(mbim_dts_test_base.MbimDtsTestBase):
1410a65a902cec8c477688311d158cc036f0d6f53aRoshan Pius    """
1510a65a902cec8c477688311d158cc036f0d6f53aRoshan Pius    Validation of wSequence increment.
1610a65a902cec8c477688311d158cc036f0d6f53aRoshan Pius
1710a65a902cec8c477688311d158cc036f0d6f53aRoshan Pius    This test verifies that the expected increment happens for wSequence.
1810a65a902cec8c477688311d158cc036f0d6f53aRoshan Pius
1910a65a902cec8c477688311d158cc036f0d6f53aRoshan Pius    Reference:
2010a65a902cec8c477688311d158cc036f0d6f53aRoshan Pius        [1] Universal Serial Bus Communication Class MBIM Compliance Testing: 28
2110a65a902cec8c477688311d158cc036f0d6f53aRoshan Pius        http://www.usb.org/developers/docs/devclass_docs/MBIM-Compliance-1.0.pdf
2210a65a902cec8c477688311d158cc036f0d6f53aRoshan Pius
2310a65a902cec8c477688311d158cc036f0d6f53aRoshan Pius    """
2410a65a902cec8c477688311d158cc036f0d6f53aRoshan Pius    version = 1
2510a65a902cec8c477688311d158cc036f0d6f53aRoshan Pius
2610a65a902cec8c477688311d158cc036f0d6f53aRoshan Pius    def run_internal(self, ntb_format):
2710a65a902cec8c477688311d158cc036f0d6f53aRoshan Pius        """
2810a65a902cec8c477688311d158cc036f0d6f53aRoshan Pius        Run DTS_05/DTS_11 test.
2910a65a902cec8c477688311d158cc036f0d6f53aRoshan Pius
3010a65a902cec8c477688311d158cc036f0d6f53aRoshan Pius        @param ntb_format: Whether to send/receive an NTB16 or NTB32 frame.
3110a65a902cec8c477688311d158cc036f0d6f53aRoshan Pius                Possible values: NTB_FORMAT_16, NTB_FORMAT_32 (mbim_constants)
3210a65a902cec8c477688311d158cc036f0d6f53aRoshan Pius
3310a65a902cec8c477688311d158cc036f0d6f53aRoshan Pius        """
3410a65a902cec8c477688311d158cc036f0d6f53aRoshan Pius        # Precondition
3510a65a902cec8c477688311d158cc036f0d6f53aRoshan Pius        _, _, _ = self.run_precondition(ntb_format)
3610a65a902cec8c477688311d158cc036f0d6f53aRoshan Pius
3710a65a902cec8c477688311d158cc036f0d6f53aRoshan Pius        # Step 1
3810a65a902cec8c477688311d158cc036f0d6f53aRoshan Pius        loopback = loopback_sequence.LoopbackSequence(self.device_context)
3910a65a902cec8c477688311d158cc036f0d6f53aRoshan Pius        nth_1, _, _, _ = loopback.run(ntb_format=ntb_format)
4010a65a902cec8c477688311d158cc036f0d6f53aRoshan Pius
4110a65a902cec8c477688311d158cc036f0d6f53aRoshan Pius        # Step 2
4210a65a902cec8c477688311d158cc036f0d6f53aRoshan Pius        nth_2, _, _, _ = loopback.run(ntb_format=ntb_format)
4310a65a902cec8c477688311d158cc036f0d6f53aRoshan Pius
4410a65a902cec8c477688311d158cc036f0d6f53aRoshan Pius        # Step 3
4510a65a902cec8c477688311d158cc036f0d6f53aRoshan Pius        if ntb_format == mbim_constants.NTB_FORMAT_16:
4632694e182daed32e30dbc9d13d8af0154660cf1cRoshan Pius            if nth_2.sequence_number != nth_1.sequence_number + 1:
4710a65a902cec8c477688311d158cc036f0d6f53aRoshan Pius                mbim_errors.log_and_raise(
4810a65a902cec8c477688311d158cc036f0d6f53aRoshan Pius                        mbim_errors.MBIMComplianceAssertionError,
4910a65a902cec8c477688311d158cc036f0d6f53aRoshan Pius                        'ncm1.0:3.2.1#4')
5010a65a902cec8c477688311d158cc036f0d6f53aRoshan Pius        else:
5132694e182daed32e30dbc9d13d8af0154660cf1cRoshan Pius            if nth_2.sequence_number != nth_1.sequence_number + 1:
5210a65a902cec8c477688311d158cc036f0d6f53aRoshan Pius                mbim_errors.log_and_raise(
5310a65a902cec8c477688311d158cc036f0d6f53aRoshan Pius                        mbim_errors.MBIMComplianceAssertionError,
5410a65a902cec8c477688311d158cc036f0d6f53aRoshan Pius                        'ncm1.0:3.2.2#4')
55