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 \
9        import mbim_test_base
10from autotest_lib.client.cros.cellular.mbim_compliance.sequences \
11        import connect_sequence
12from autotest_lib.client.cros.cellular.mbim_compliance.sequences \
13        import get_descriptors_sequence
14from autotest_lib.client.cros.cellular.mbim_compliance.sequences \
15        import mbim_close_sequence
16from autotest_lib.client.cros.cellular.mbim_compliance.sequences \
17        import mbim_open_generic_sequence
18
19
20class cellular_MbimComplianceCM14(mbim_test_base.MbimTestBase):
21    """
22    CM_14 Validation of not sending data payload in error messages.
23
24    This test verifies that an MBIM_FUNCTION_ERROR_MSG does contain a data
25    payload.
26
27    Reference:
28        [1] Universal Serial Bus Communication Class MBIM Compliance Testing: 43
29        http://www.usb.org/developers/docs/devclass_docs/MBIM-Compliance-1.0.pdf
30
31    """
32    version = 1
33
34    def run_internal(self):
35        """ Run CM_14 test. """
36        # Precondition
37        descriptors = get_descriptors_sequence.GetDescriptorsSequence(
38                self.device_context).run()
39        self.device_context.update_descriptor_cache(descriptors)
40        mbim_open_generic_sequence.MBIMOpenGenericSequence(
41                self.device_context).run()
42        mbim_close_sequence.MBIMCloseSequence(self.device_context).run()
43
44        # Step 1
45        _, response_message, _ = (
46                connect_sequence.ConnectSequence(self.device_context).run(
47                        raise_exception_on_failure=False))
48
49        # Step 2
50        if ((response_message.message_type !=
51             mbim_constants.MBIM_FUNCTION_ERROR_MSG) or
52            (response_message.message_length != 16)):
53            mbim_errors.log_and_raise(mbim_errors.MBIMComplianceAssertionError,
54                                      'mbim1.0:9.3.4#2')
55