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 logging
6
7import common
8from autotest_lib.client.cros.cellular.mbim_compliance \
9        import mbim_device_context
10from autotest_lib.client.cros.cellular.mbim_compliance import mbim_errors
11
12
13class MbimTestBase(object):
14    """
15    Base class for all MBIM Compliance Suite tests.
16    This class contains boilerplate code and utility functions for MBIM
17    Compliance Suite. A brief description of non-trivial facilities follows.
18    Test initialization: populates the following members:
19        - device_context: An MBIMTestContext. This class finds the relevant MBIM
20                          device on the DUT and stashes that in this context.
21    Utility functions: None yet.
22    """
23
24    def run_test(self, id_vendor=None, id_product=None, **kwargs):
25        """
26        Run the test.
27
28        To test a specific device based on VID/PID, add id_vendor=0xHHHH,
29        id_product=0xHHHH to the control file invocation of tests.
30
31        @param id_vendor: Specific vendor ID for the modem to be tested.
32        @param id_product: Specific product ID for the modem to be tested.
33        @param kwargs: Optional parameters passed to tests.
34
35        """
36        self.device_context = mbim_device_context.MbimDeviceContext(
37                id_vendor=id_vendor, id_product=id_product)
38        logging.info('Running test on modem with VID: %04X, PID: %04X',
39                     self.device_context.id_vendor,
40                     self.device_context.id_product)
41        self.run_internal(**kwargs)
42
43
44    def run_internal(self):
45        """
46        This method actually implements the core test logic.
47
48        Subclasses should override this method to run their own test.
49
50        """
51        mbim_errors.log_and_raise(NotImplementedError)
52