1# Copyright 2014 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import common
6from autotest_lib.client.cros.cellular.mbim_compliance import mbim_constants
7from autotest_lib.client.cros.cellular.mbim_compliance import mbim_errors
8from autotest_lib.client.cros.cellular.mbim_compliance import mbim_test_base
9from autotest_lib.client.cros.cellular.mbim_compliance.sequences \
10        import connect_sequence
11from autotest_lib.client.cros.cellular.mbim_compliance.sequences \
12        import get_descriptors_sequence
13from autotest_lib.client.cros.cellular.mbim_compliance.sequences \
14        import mbim_open_generic_sequence
15
16
17class cellular_MbimComplianceERR03(mbim_test_base.MbimTestBase):
18    """
19    Validation of error message transaction Id.
20
21    This test verifies that transaction Id of an error message with status code
22    MBIM_ERROR_FRAGMENT_OUT_OF_SEQUENCE is the same as transaction Id of the
23    incorrectly fragmented message.
24
25    Reference:
26        [1] Universal Serial Bus Communication Class MBIM Compliance Testing: 45
27        http://www.usb.org/developers/docs/devclass_docs/MBIM-Compliance-1.0.pdf
28
29    """
30    version = 1
31
32    def run_internal(self):
33        """ Run ERR_03 test. """
34        # Precondition
35        descriptors = get_descriptors_sequence.GetDescriptorsSequence(
36                self.device_context).run()
37        self.device_context.update_descriptor_cache(descriptors)
38        open_sequence = mbim_open_generic_sequence.MBIMOpenGenericSequence(
39                self.device_context)
40        open_sequence.run(max_control_transfer_size=64)
41
42        # Step 1
43        request_message, response_message, _ = (
44                connect_sequence.ConnectSequence(self.device_context).run(
45                        introduce_error_in_packets_order=[1, 0, 2],
46                        raise_exception_on_failure=False))
47
48        # Step 2
49        if ((response_message.message_type !=
50             mbim_constants.MBIM_FUNCTION_ERROR_MSG) or
51            (response_message.transaction_id !=
52             request_message.transaction_id) or
53            (response_message.error_status_code !=
54             mbim_constants.MBIM_ERROR_FRAGMENT_OUT_OF_SEQUENCE)):
55            mbim_errors.log_and_raise(mbim_errors.MBIMComplianceAssertionError,
56                                      'mbim1.0:9.3.4.2#2')
57