1# Copyright (c) 2020 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 json 6import logging 7import os 8 9from autotest_lib.client.common_lib import error 10from autotest_lib.server import autotest 11from autotest_lib.server import test 12from autotest_lib.server.cros.crosperf import device_setup_utils 13 14WAIT_TIME_LOG = 'wait_time.log' 15 16class crosperf_Wrapper(test.test): 17 """ 18 Client test wrapper for crosperf. 19 20 This is a class to run client tests under the crosperf script. 21 22 """ 23 version = 1 24 25 def run_once(self, test_name, test_args, dut_config_str, dut=None): 26 """ 27 Run a single telemetry test. 28 29 @param test_name: Name of the client test. 30 @param test_args: Arguments need to be passed to test. 31 @param dut_config_str: A string dumped from json representing DUT 32 configurations. 33 @param dut: The autotest host object representing DUT. 34 35 @returns A result of this execution. 36 37 """ 38 if not test_name: 39 raise RuntimeError('Missing client test name to run.') 40 41 if dut_config_str: 42 dut_config = json.loads(dut_config_str) 43 # Setup device with dut_config arguments before running test. 44 wait_time = device_setup_utils.setup_device(dut, dut_config) 45 # Wait time can be used to accumulate cooldown time in Crosperf. 46 with open(os.path.join(self.resultsdir, WAIT_TIME_LOG), 'w') as f: 47 f.write(str(wait_time)) 48 49 try: 50 # Execute the client side test. 51 client_at = autotest.Autotest(dut) 52 result = client_at.run_test(test_name, args=test_args) 53 except (error.TestFail, error.TestWarn): 54 logging.debug('Test did not succeed while executing client test.') 55 raise 56 except: 57 logging.debug('Unexpected failure on client test %s.', test_name) 58 raise 59 60 return result 61