blob: 9e0e47056050a79c27ae31dfae1f572831fc7969 [file] [log] [blame]
# Copyright (C) 2018 The Android Open Source Project
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# See the License for the specific language governing permissions and
# limitations under the License.
import logging
from import base_test
from import records
from import test_runner
class ParamTestClass(base_test.BaseTestClass):
"""Base class to run a parameterized test.
A parameterized test is a test with a set of parameters and the test will be
run against each parameter. This allows to test logic with different
parameters without without writing multiple copies of the same test.
An example use case of parameterized test is service name aware HAL testing
which we expect to run the same test logic against all service instances
through their corresponding service names. e.g to test graphics.composer HAL
against two different instance: default and vr.
params: list, a list of parameters for test run.
cur_param: the parameter used for the current run.
def __init__(self, configs):
super(ParamTestClass, self).__init__(configs)
def initParams(self):
"""Initialize test parameters. Expected to be overridden by a subclass."""
self._params = []
def getParamTag(self, param):
"""Get the test tag used to attach with test name from the parameter.
expected to be overridden by a subclass.
param: the current test parameter.
return str(param)
def params(self):
"""Get params"""
return self._params
def params(self, params):
"""Set params"""
self._params = params
def cur_param(self):
"""Get cur_param"""
return self._cur_param
def cur_param(self, cur_param):
"""Set cur_param"""
self._cur_param = cur_param
def run(self, test_names=None):
"""Run a parameterized test.
For each parameter initialized for the test, runs test cases within
this test class against that parameter.
test_names: A list of string that are test case names requested in
cmd line.
The test results object of this class.
""""==========> %s <==========", self.test_module_name)
original_tests = self.getTests(test_names)
# Run the set of original tests against each parameter.
for param in self.params:
self.cur_param = param
tests = [(str(test_name + self.getParamTag(param)), test_func)
for (test_name, test_func) in original_tests]
if not self.run_as_vts_self_test:
self.results.requested = [
records.TestResultRecord(test_name, self.test_module_name)
for test_name, _ in tests
return self.results