• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2015 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 array
6import logging
7import unittest
8
9import common
10from autotest_lib.client.cros.cellular.mbim_compliance import mbim_constants
11from autotest_lib.client.cros.cellular.mbim_compliance import mbim_data_transfer
12
13class TestMbimDeviceContext(object):
14    """ Dummy device context. """
15    pass
16
17class TestMbimDescriptorCache(object):
18    """ Dummy MBIM descriptor cache. """
19    pass
20
21class TestMbimEndpointDescriptor(object):
22    """ Dummy MBIM endpoint descriptor. """
23    pass
24
25class MBIMMessageTestCase(unittest.TestCase):
26    """ Test cases for verifying MBIMDataTransfer class and MBIMNtb class. """
27
28    def test_ntb_generation(self):
29        """ Verifies the NTB frame generation from the given payload. """
30
31        ntb = mbim_data_transfer.MBIMNtb(mbim_constants.NTB_FORMAT_32)
32        payload = [array.array('B', [0x45, 0x00, 0x00, 0x46, 0x00, 0x00, 0x00,
33                                     0x00, 0x00, 0x01, 0xBC, 0xB4, 0x7F, 0x00,
34                                     0x00, 0x01, 0x7F, 0x00, 0x00, 0x02, 0x00,
35                                     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
36                                     0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
37                                     0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E,
38                                     0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75,
39                                     0x76, 0x77, 0x61, 0x62, 0x63, 0x64, 0x65,
40                                     0x66, 0x67, 0x68, 0x69, 0x00, 0x00, 0x00,
41                                     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
42                                     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
43                                     0x00, 0x00, 0x00])]
44        ntb_frame = ntb.generate_ntb(payload, 1024, 32, 0, 1)
45        verify_ntb_frame = array.array('B', [0x6E, 0x63, 0x6D, 0x68, 0x10,
46                                             0x00, 0x00, 0x00, 0x90, 0x00,
47                                             0x00, 0x00, 0x70, 0x00, 0x00,
48                                             0x00, 0x00, 0x00, 0x00, 0x00,
49                                             0x00, 0x00, 0x00, 0x00, 0x00,
50                                             0x00, 0x00, 0x00, 0x00, 0x00,
51                                             0x00, 0x00, 0x45, 0x00, 0x00,
52                                             0x46, 0x00, 0x00, 0x00, 0x00,
53                                             0x00, 0x01, 0xBC, 0xB4, 0x7F,
54                                             0x00, 0x00, 0x01, 0x7F, 0x00,
55                                             0x00, 0x02, 0x00, 0x00, 0x00,
56                                             0x00, 0x00, 0x00, 0x00, 0x01,
57                                             0x61, 0x62, 0x63, 0x64, 0x65,
58                                             0x66, 0x67, 0x68, 0x69, 0x6A,
59                                             0x6B, 0x6C, 0x6D, 0x6E, 0x6F,
60                                             0x70, 0x71, 0x72, 0x73, 0x74,
61                                             0x75, 0x76, 0x77, 0x61, 0x62,
62                                             0x63, 0x64, 0x65, 0x66, 0x67,
63                                             0x68, 0x69, 0x00, 0x00, 0x00,
64                                             0x00, 0x00, 0x00, 0x00, 0x00,
65                                             0x00, 0x00, 0x00, 0x00, 0x00,
66                                             0x00, 0x00, 0x00, 0x00, 0x00,
67                                             0x00, 0x00, 0x69, 0x70, 0x73,
68                                             0x00, 0x20, 0x00, 0x00, 0x00,
69                                             0x00, 0x00, 0x00, 0x00, 0x00,
70                                             0x00, 0x00, 0x00, 0x20, 0x00,
71                                             0x00, 0x00, 0x50, 0x00, 0x00,
72                                             0x00, 0x00, 0x00, 0x00, 0x00,
73                                             0x00, 0x00, 0x00, 0x00])
74        self.assertEqual(ntb_frame, verify_ntb_frame)
75
76
77    def test_ntb_parsing(self):
78        """ Verifies the NTB frame parsing from the given NTB frame. """
79
80        ntb = mbim_data_transfer.MBIMNtb(mbim_constants.NTB_FORMAT_32)
81        ntb_frame = array.array('B', [0x6E, 0x63, 0x6D, 0x68, 0x10,
82                                      0x00, 0x01, 0x00, 0x90, 0x00,
83                                      0x00, 0x00, 0x70, 0x00, 0x00,
84                                      0x00, 0x00, 0x00, 0x00, 0x00,
85                                      0x00, 0x00, 0x00, 0x00, 0x00,
86                                      0x00, 0x00, 0x00, 0x00, 0x00,
87                                      0x00, 0x00, 0x45, 0x00, 0x00,
88                                      0x46, 0x00, 0x00, 0x00, 0x00,
89                                      0x00, 0x01, 0xBC, 0xB4, 0x7F,
90                                      0x00, 0x00, 0x01, 0x7F, 0x00,
91                                      0x00, 0x02, 0x00, 0x00, 0x00,
92                                      0x00, 0x00, 0x00, 0x00, 0x01,
93                                      0x61, 0x62, 0x63, 0x64, 0x65,
94                                      0x66, 0x67, 0x68, 0x69, 0x6A,
95                                      0x6B, 0x6C, 0x6D, 0x6E, 0x6F,
96                                      0x70, 0x71, 0x72, 0x73, 0x74,
97                                      0x75, 0x76, 0x77, 0x61, 0x62,
98                                      0x63, 0x64, 0x65, 0x66, 0x67,
99                                      0x68, 0x69, 0x00, 0x00, 0x00,
100                                      0x00, 0x00, 0x00, 0x00, 0x00,
101                                      0x00, 0x00, 0x00, 0x00, 0x00,
102                                      0x00, 0x00, 0x00, 0x00, 0x00,
103                                      0x00, 0x00, 0x69, 0x70, 0x73,
104                                      0x00, 0x20, 0x00, 0x00, 0x00,
105                                      0x00, 0x00, 0x00, 0x00, 0x00,
106                                      0x00, 0x00, 0x00, 0x20, 0x00,
107                                      0x00, 0x00, 0x50, 0x00, 0x00,
108                                      0x00, 0x00, 0x00, 0x00, 0x00,
109                                      0x00, 0x00, 0x00, 0x00])
110        nth, ndp, ndp_entries, payload = ntb.parse_ntb(ntb_frame)
111        verify_payload = [array.array('B', [0x45, 0x00, 0x00, 0x46, 0x00, 0x00,
112                                            0x00, 0x00, 0x00, 0x01, 0xBC, 0xB4,
113                                            0x7F, 0x00, 0x00, 0x01, 0x7F, 0x00,
114                                            0x00, 0x02, 0x00, 0x00, 0x00, 0x00,
115                                            0x00, 0x00, 0x00, 0x01, 0x61, 0x62,
116                                            0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
117                                            0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E,
118                                            0x6F, 0x70, 0x71, 0x72, 0x73, 0x74,
119                                            0x75, 0x76, 0x77, 0x61, 0x62, 0x63,
120                                            0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
121                                            0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
122                                            0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
123                                            0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
124                                            0x00, 0x00])]
125        # Verify the fields of the headers and payload
126        self.assertEqual(nth.signature, mbim_data_transfer.NTH_SIGNATURE_32)
127        self.assertEqual(nth.header_length, 16)
128        self.assertEqual(nth.sequence_number, 1)
129        self.assertEqual(nth.block_length, 144)
130        self.assertEqual(nth.fp_index, 112)
131        self.assertEqual(ndp.signature, mbim_data_transfer.NDP_SIGNATURE_IPS_32)
132        self.assertEqual(ndp.length, 32)
133        self.assertEqual(ndp.next_ndp_index, 0)
134        self.assertEqual(ndp_entries[0].datagram_index, 32)
135        self.assertEqual(ndp_entries[0].datagram_length, 80)
136        self.assertEqual(ndp_entries[1].datagram_index, 0)
137        self.assertEqual(ndp_entries[1].datagram_length, 0)
138        self.assertEqual(payload, verify_payload)
139
140
141    def test_data_transfer_object_creation(self):
142        """ Verifies the Data transfer object creation. """
143        device_context = TestMbimDeviceContext()
144        device_context.device = 1
145        device_context.max_out_data_transfer_size = 100
146        device_context.max_in_data_transfer_size = 100
147        device_context.out_data_transfer_divisor = 32
148        device_context.out_data_transfer_payload_remainder = 0
149        device_context.descriptor_cache = TestMbimDescriptorCache()
150        device_context.descriptor_cache.mbim_data_interface = (
151                TestMbimDescriptorCache())
152        device_context.descriptor_cache.bulk_in_endpoint = (
153                TestMbimDescriptorCache())
154        device_context.descriptor_cache.bulk_out_endpoint = (
155                TestMbimDescriptorCache())
156        device_context.descriptor_cache.mbim_data_interface.bInterfaceNumber = 0
157        device_context.descriptor_cache.bulk_in_endpoint.bEndpointAddress = 0
158        device_context.descriptor_cache.bulk_out_endpoint.bEndpointAddress = 0
159        data_transfer = mbim_data_transfer.MBIMDataTransfer(device_context)
160
161
162    def test_data_transfer_send(self):
163        """ Verifies the send_data_packets API in data transfer. """
164        #TODO(rpius): Need to come up with a way to unittest the data transfer
165
166
167    def test_data_transfer_received(self):
168        """ Verifies the receive_data_packets API in data transfer. """
169        #TODO(rpius): Need to come up with a way to unittest the data transfer
170
171
172if __name__ == '__main__':
173    logging.basicConfig(level=logging.DEBUG)
174    unittest.main()
175