1#!/usr/bin/env python 2# 3# Copyright (C) 2019 The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16# 17 18import copy 19import logging 20import time 21import argparse 22 23from vts.runners.host import asserts 24from vts.runners.host import keys 25from vts.runners.host import test_runner 26from vts.testcases.template.hal_hidl_gtest import hal_hidl_gtest 27from vts.utils.python.hal import hal_service_name_utils 28 29class VtsHalMediaC2V1_0Host(hal_hidl_gtest.HidlHalGTest): 30 """Host test class to run the Media_C2 HAL.""" 31 32 COMPONENT_TEST = "Codec2Component" 33 AUDIO_ENC_TEST = "Codec2AudioEnc" 34 AUDIO_DEC_TEST = "Codec2AudioDec" 35 VIDEO_ENC_TEST = "Codec2VideoEnc" 36 VIDEO_DEC_TEST = "Codec2VideoDec" 37 38 def CreateTestCases(self): 39 """Get all registered test components and create test case objects.""" 40 # Retrieve all available IComponentStore instances 41 testable, self.service_names = \ 42 hal_service_name_utils.GetHalServiceName( 43 self.shell, 44 "android.hardware.media.c2@1.0::IComponentStore", 45 "64" if self._dut.is64Bit else "32") 46 self.components = []; 47 48 if testable: 49 for service_name in self.service_names: 50 self._dut.hal.InitHidlHal( 51 target_type="media_c2", 52 target_basepaths=self._dut.libPaths, 53 target_version=1.0, 54 target_package="android.hardware.media.c2", 55 target_component_name="IComponentStore", 56 hw_binder_service_name=service_name.encode("utf8"), 57 bits=64 if self._dut.is64Bit else 32) 58 self.vtypes = self._dut.hal.media_c2.GetHidlTypeInterface("types") 59 status, traitsList = self._dut.hal.media_c2.listComponents() 60 asserts.assertEqual(self.vtypes.Status.OK, status) 61 for traits in traitsList: 62 self.components.append({ 63 'owner' : service_name, 64 'name' : traits['name'], 65 'domain' : traits['domain'], 66 'kind' : traits['kind'], 67 'mediaType' : traits['mediaType'], 68 'aliases' : traits['aliases'] 69 }) 70 else: 71 self.skipAllTests('There are no HAL services presenting ' + \ 72 'android.hardware.media.c2@1.0::IComponentStore. ' + \ 73 'Tests skipped.') 74 75 super(VtsHalMediaC2V1_0Host, self).CreateTestCases() 76 77 # @Override 78 def CreateTestCase(self, path, tag=''): 79 """Create a list of VtsHalMediaC2V1_0testCase objects. 80 81 For each target side gtest test case, create a set of new test cases 82 argumented with different component and role values. 83 84 Args: 85 path: string, absolute path of a gtest binary on device 86 tag: string, a tag that will be appended to the end of test name 87 88 Returns: 89 A list of VtsHalMediaC2V1_0TestCase objects 90 """ 91 gtest_cases = super(VtsHalMediaC2V1_0Host, self).CreateTestCase(path, 92 tag) 93 test_cases = [] 94 95 instance_parser = argparse.ArgumentParser() 96 instance_parser.add_argument('--hal_service_instance', type=str) 97 98 for gtest_case in gtest_cases: 99 test_suite = gtest_case.full_name 100 args = instance_parser.parse_args(gtest_case.args.split()) 101 if args.hal_service_instance: 102 instance_name = args.hal_service_instance[args.hal_service_instance.rfind('/')+1:] 103 else: 104 continue 105 for component in self.components: 106 if instance_name != component['owner']: 107 continue 108 if self.AUDIO_ENC_TEST in test_suite and \ 109 (component['domain'] != 2 or component['kind'] != 2): 110 continue 111 if self.AUDIO_DEC_TEST in test_suite and \ 112 (component['domain'] != 2 or component['kind'] != 1): 113 continue 114 if self.VIDEO_ENC_TEST in test_suite and \ 115 (component['domain'] != 1 or component['kind'] != 2): 116 continue 117 if self.VIDEO_DEC_TEST in test_suite and \ 118 (component['domain'] != 1 or component['kind'] != 1): 119 continue 120 121 test_case = copy.copy(gtest_case) 122 test_case.args += " -I " + component['owner'] 123 test_case.args += " -C " + component['name'] 124 test_case.name_appendix = '_' + component['owner'] + \ 125 '_' + component['name'] + test_case.name_appendix 126 test_cases.append(test_case) 127 128 logging.info("num of test_testcases: %s", len(test_cases)) 129 return test_cases 130 131if __name__ == "__main__": 132 test_runner.main() 133