Home | History | Annotate | Download | only in mbim_compliance
      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 """
      5 Module to be included by the main test executor file within each test area
      6 of MBIM compliance suite. This harness is responsible for loading the
      7 required test within an area and invoking it.
      8 
      9 """
     10 
     11 import imp
     12 import os
     13 
     14 import common
     15 from autotest_lib.client.bin import test
     16 from autotest_lib.client.cros.cellular.mbim_compliance import mbim_errors
     17 
     18 
     19 class MbimTestRunner(test.test):
     20     """
     21     Main test class which hooks up the MBIM compliance suite to autotest.
     22     It invokes the MBIM tests within an area of the MBIM compliance test suite.
     23 
     24     """
     25     _TEST_AREA_FOLDER = None
     26 
     27     version = 1
     28 
     29     def run_once(self, subtest_name, **kwargs):
     30         """
     31         Method invoked by autotest framework to start a test from the
     32         corresponding control file.
     33 
     34         @param subtest_name: Name of the compliance test to be invoked.
     35                 The test has to be in the same folder as the control file and
     36                 should have file_name and class_name as |subtest_name|.
     37         @param kwargs: Optional arguments which are passed to the actual test
     38                 being run.
     39 
     40         """
     41         module_name = os.path.join(self._TEST_AREA_FOLDER, subtest_name + ".py")
     42         try:
     43             test_module = imp.load_source(subtest_name, module_name)
     44         except ImportError:
     45             mbim_errors.log_and_raise(mbim_errors.MBIMComplianceFrameworkError,
     46                                       'Test module %s not found', module_name)
     47         try:
     48             test_class = getattr(test_module, subtest_name)
     49         except AttributeError:
     50             mbim_errors.log_and_raise(mbim_errors.MBIMComplianceFrameworkError,
     51                                       'Test class %s not found', subtest_name)
     52         test = test_class()
     53         test.run_test(**kwargs)
     54