1# Copyright 2018 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"""Base class for power measurement tests with telemetry devices.""" 6 7import os 8 9from autotest_lib.server import test 10from autotest_lib.server.cros.power import wrapper_test_runner 11 12 13class PowerBaseWrapper(test.test): 14 """Base class for a wrapper test around a client test. 15 16 This wrapper test runs 1 client test given by user, and measures DUT power 17 with external power measurement tools. 18 """ 19 version = 1 20 21 def run_once(self, host, config): 22 """Measure power while running the client side test. 23 24 @param host: CrosHost object representing the DUT. 25 @param config: the args argument from test_that in a dict. 26 required data: {'test': 'test_TestName.tag'} 27 """ 28 test_runner = wrapper_test_runner.WrapperTestRunner( 29 config, self.autodir) 30 client_test_name = test_runner.get_tagged_test_name() 31 ptl = self._get_power_telemetry_logger(host, config, self.resultsdir) 32 try: 33 ptl.start_measurement() 34 test_runner.run_test(host) 35 finally: 36 client_test_dir = os.path.join(self.outputdir, client_test_name) 37 # If client test name is not tagged in its own control file. 38 if not os.path.isdir(client_test_dir): 39 client_test_name = client_test_name.split('.', 1)[0] 40 client_test_dir = os.path.join(self.outputdir, client_test_name) 41 ptl.end_measurement(client_test_dir) 42 43 return 44 45 def _get_power_telemetry_logger(self, host, config, resultsdir): 46 """Return the corresponding power telemetry logger. 47 48 @param host: CrosHost object representing the DUT. 49 @param config: the args argument from test_that in a dict. Settings for 50 power telemetry devices. 51 required data: {'test': 'test_TestName.tag'} 52 @param resultsdir: path to directory where current autotest results are 53 stored, e.g. /tmp/test_that_results/ 54 results-1-test_TestName.tag/test_TestName.tag/ 55 results/ 56 """ 57 raise NotImplementedError('Subclasses must implement ' 58 '_get_power_telemetry_logger and return the corresponding ' 59 'power telemetry logger.') 60