1 # 2 # Copyright (C) 2016 The Android Open Source Project 3 # 4 # Licensed under the Apache License, Version 2.0 (the "License"); 5 # you may not use this file except in compliance with the License. 6 # You may obtain a copy of the License at 7 # 8 # http://www.apache.org/licenses/LICENSE-2.0 9 # 10 # Unless required by applicable law or agreed to in writing, software 11 # distributed under the License is distributed on an "AS IS" BASIS, 12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 # See the License for the specific language governing permissions and 14 # limitations under the License. 15 # 16 17 class LinuxKselftestTestcase(object): 18 """Stores information needed to run the test case. 19 20 Attrubutes: 21 _testname: string, name of the testcase. 22 _testsuite: string, name of suite this testcase belongs to. 23 _test_cmd: string, shell command used to invoke this testcase. 24 _supported_arch: string list, architectures this testcase supports, 25 e.g. ["arm", "x86"]. 26 _supported_bits: int list, bit version (32 or 64) of the testcase that 27 are currently supported, e.g. [32, 64]. 28 """ 29 def __init__(self, testname, supported_arch, supported_bits): 30 items = testname.split("/", 1) 31 self._testname = testname 32 self._testsuite = items[0] 33 self._test_cmd = "./%s" % items[1] 34 self._supported_arch = supported_arch 35 self._supported_bits = supported_bits 36 37 @property 38 def testname(self): 39 """Get test name.""" 40 return self._testname 41 42 @property 43 def testsuite(self): 44 """Get test suite.""" 45 return self._testsuite 46 47 @property 48 def test_cmd(self): 49 """Get test command.""" 50 return self._test_cmd 51 52 @property 53 def supported_arch(self): 54 """Get list of architectures this test can run against.""" 55 return self._supported_arch 56 57 @property 58 def supported_bits(self): 59 """Get list of versions (32 or 64 bit) of the test case that can run.""" 60 return self._supported_bits 61 62 def IsRelevant(self, cpu_abi, n_bit): 63 """Checks whether this test case can run in n_bit against this cpu_abi. 64 65 Returns: 66 True if this testcase can run; False otherwise. 67 """ 68 if cpu_abi is None or n_bit is None: 69 return False 70 71 if not n_bit in self._supported_bits: 72 return False 73 74 for arch in self._supported_arch: 75 if cpu_abi.find(arch) >= 0: 76 return True 77 78 return False 79 80