1# Copyright 2017, The Android Open Source Project 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15""" 16Base test runner class. 17 18Class that other test runners will instantiate for test runners. 19""" 20 21import logging 22import subprocess 23 24# pylint: disable=import-error 25import atest_error 26 27 28class TestRunnerBase(object): 29 """Base Test Runner class.""" 30 NAME = '' 31 EXECUTABLE = '' 32 33 def __init__(self, results_dir, **kwargs): 34 """Init stuff for base class.""" 35 self.results_dir = results_dir 36 if not self.NAME: 37 raise atest_error.NoTestRunnerName('Class var NAME is not defined.') 38 if not self.EXECUTABLE: 39 raise atest_error.NoTestRunnerExecutable('Class var EXECUTABLE is ' 40 'not defined.') 41 if kwargs: 42 logging.info('ignoring the following args: %s', kwargs) 43 44 @staticmethod 45 def run(cmd): 46 """Shell out and execute command. 47 48 Args: 49 cmd: A string of the command to execute. 50 """ 51 logging.info('Executing command: %s', cmd) 52 subprocess.check_call(cmd, shell=True, stderr=subprocess.STDOUT) 53 54 def run_tests(self, test_infos, extra_args): 55 """Run the list of test_infos. 56 57 Args: 58 test_infos: List of TestInfo. 59 extra_args: Dict of extra args to add to test run. 60 """ 61 raise NotImplementedError 62 63 def host_env_check(self): 64 """Checks that host env has met requirements.""" 65 raise NotImplementedError 66 67 def get_test_runner_build_reqs(self): 68 """Returns a list of build targets required by the test runner.""" 69 raise NotImplementedError 70