1# Copyright (c) 2017 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 6import os 7import os.path 8 9from autotest_lib.server import autotest 10from autotest_lib.server import test 11 12 13class telemetry_UnitTestsServer(test.test): 14 """Runs the telemetry_UnitTests client tests with some extra setup.""" 15 version = 1 16 17 # The .boto file needs to be copied into the client (VM) so that the tests 18 # can run. The host boto file 19 LOCAL_BOTO_FILE = os.path.join(os.getenv('HOME'), '.boto') 20 CLIENT_BOTO_FILE = '/home/chromeos-test/.boto' 21 22 def initialize(self, host, copy_boto_file=False): 23 if copy_boto_file: 24 # Copy ~/.boto from the local file system to the client. This is 25 # needed for the telemetry tests to run there. 26 logging.info('Creating client directory %s', 27 os.path.dirname(self.CLIENT_BOTO_FILE)) 28 host.run('mkdir -p %s' % os.path.dirname(self.CLIENT_BOTO_FILE)) 29 30 logging.info('Copying local %s to client %s', self.LOCAL_BOTO_FILE, 31 self.CLIENT_BOTO_FILE) 32 assert(os.path.exists(self.LOCAL_BOTO_FILE)) 33 host.send_file(self.LOCAL_BOTO_FILE, self.CLIENT_BOTO_FILE) 34 35 def cleanup(self, host, copy_boto_file=False): 36 if copy_boto_file: 37 # Clear the copied .boto file from the client, since it should no 38 # longer be useful. 39 logging.info('Clearing client %s', self.CLIENT_BOTO_FILE) 40 host.run('rm %s' % self.CLIENT_BOTO_FILE) 41 42 def run_once(self, host, use_packaging, browser_type, unit_tests, 43 perf_tests): 44 # Otherwise we do nothing but run the client side tests. 45 client_at = autotest.Autotest(host) 46 client_at.run_test( 47 'telemetry_UnitTests', host=host, use_packaging=use_packaging, 48 browser_type=browser_type, unit_tests=unit_tests, 49 perf_tests=perf_tests) 50