• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
21
22from vts.runners.host import asserts
23from vts.runners.host import keys
24from vts.runners.host import test_runner
25from vts.testcases.template.hal_hidl_gtest import hal_hidl_gtest
26from vts.utils.python.hal import hal_service_name_utils
27
28class VtsHalMediaC2V1_0Host(hal_hidl_gtest.HidlHalGTest):
29    """Host test class to run the Media_C2 HAL."""
30
31    COMPONENT_TEST = "Codec2Component"
32    AUDIO_ENC_TEST = "Codec2AudioEnc"
33    AUDIO_DEC_TEST = "Codec2AudioDec"
34    VIDEO_ENC_TEST = "Codec2VideoEnc"
35    VIDEO_DEC_TEST = "Codec2VideoDec"
36
37    def CreateTestCases(self):
38        """Get all registered test components and create test case objects."""
39        # Retrieve all available IComponentStore instances
40        testable, self.service_names = \
41            hal_service_name_utils.GetHalServiceName(
42                self.shell,
43                "android.hardware.media.c2@1.0::IComponentStore",
44                "64" if self._dut.is64Bit else "32")
45        self.components = [];
46
47        if testable:
48            for service_name in self.service_names:
49                self._dut.hal.InitHidlHal(
50                    target_type="media_c2",
51                    target_basepaths=self._dut.libPaths,
52                    target_version=1.0,
53                    target_package="android.hardware.media.c2",
54                    target_component_name="IComponentStore",
55                    hw_binder_service_name=service_name.encode("utf8"),
56                    bits=64 if self._dut.is64Bit else 32)
57                self.vtypes = self._dut.hal.media_c2.GetHidlTypeInterface("types")
58                status, traitsList = self._dut.hal.media_c2.listComponents()
59                asserts.assertEqual(self.vtypes.Status.OK, status)
60                for traits in traitsList:
61                    self.components.append({
62                        'owner' : service_name,
63                        'name' : traits['name'],
64                        'domain' : traits['domain'],
65                        'kind' : traits['kind'],
66                        'mediaType' : traits['mediaType'],
67                        'aliases' : traits['aliases']
68                    })
69        else:
70            self.skipAllTests('There are no HAL services presenting ' + \
71                              'android.hardware.media.c2@1.0::IComponentStore. ' + \
72                              'Tests skipped.')
73
74        super(VtsHalMediaC2V1_0Host, self).CreateTestCases()
75
76    # @Override
77    def CreateTestCase(self, path, tag=''):
78        """Create a list of VtsHalMediaC2V1_0testCase objects.
79
80        For each target side gtest test case, create a set of new test cases
81        argumented with different component and role values.
82
83        Args:
84            path: string, absolute path of a gtest binary on device
85            tag: string, a tag that will be appended to the end of test name
86
87        Returns:
88            A list of VtsHalMediaC2V1_0TestCase objects
89        """
90        gtest_cases = super(VtsHalMediaC2V1_0Host, self).CreateTestCase(path,
91                                                                        tag)
92        test_cases = []
93
94        for gtest_case in gtest_cases:
95            test_suite = gtest_case.full_name
96            for component in self.components:
97                if self.AUDIO_ENC_TEST in test_suite and \
98                    (component['domain'] != 2 or component['kind'] != 2):
99                    continue
100                if self.AUDIO_DEC_TEST in test_suite and \
101                    (component['domain'] != 2 or component['kind'] != 1):
102                    continue
103                if self.VIDEO_ENC_TEST in test_suite and \
104                    (component['domain'] != 1 or component['kind'] != 2):
105                    continue
106                if self.VIDEO_DEC_TEST in test_suite and \
107                    (component['domain'] != 1 or component['kind'] != 1):
108                    continue
109
110                test_case = copy.copy(gtest_case)
111                test_case.args += " -I " + component['owner']
112                test_case.args += " -C " + component['name']
113                test_case.name_appendix = '_' + component['owner'] + \
114                    '_' + component['name'] + test_case.name_appendix
115                test_cases.append(test_case)
116
117        logging.info("num of test_testcases: %s", len(test_cases))
118        return test_cases
119
120if __name__ == "__main__":
121    test_runner.main()
122