• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2#
3# Copyright (C) 2017 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 logging
19import time
20
21from vts.runners.host import asserts
22from vts.runners.host import keys
23from vts.runners.host import test_runner
24from vts.testcases.template.hal_hidl_gtest import hal_hidl_gtest
25import VtsHalMediaOmxV1_0TestCase as omx_test_case
26
27
28class VtsHalMediaOmxV1_0Host(hal_hidl_gtest.HidlHalGTest):
29    """Host test class to run the Media_Omx HAL."""
30
31    COMPONENT_TEST = "ComponentHidlTest"
32    AUDIO_ENC_TEST = "AudioEncHidlTest"
33    AUDIO_DEC_TEST = "AudioDecHidlTest"
34    VIDEO_ENC_TEST = "VideoEncHidlTest"
35    VIDEO_DEC_TEST = "VideoDecHidlTest"
36
37    # Roles we want to test.
38    whitelist_roles = ["audio_encoder.aac",
39                       "audio_encoder.amrnb",
40                       "audio_encoder.amrwb",
41                       "audio_encoder.flac",
42                       "audio_decoder.aac",
43                       "audio_decoder.amrnb",
44                       "audio_decoder.amrwb",
45                       "audio_decoder.g711alaw",
46                       "audio_decoder.g711mlaw",
47                       "audio_decoder.gsm",
48                       "audio_decoder.mp3",
49                       "audio_decoder.opus",
50                       "audio_decoder.raw",
51                       "audio_decoder.vorbis",
52                       "video_encoder.avc",
53                       "video_encoder.h263",
54                       "video_encoder.mpeg4",
55                       "video_encoder.vp8",
56                       "video_encoder.vp9",
57                       "video_decoder.avc",
58                       "video_decoder.h263",
59                       "video_decoder.hevc",
60                       "video_decoder.mpeg4",
61                       "video_decoder.vp8",
62                       "video_decoder.vp9"]
63
64    def CreateTestCases(self):
65        """Get all registered test components and create test case objects."""
66        # Init the IOmx hal.
67        self._dut.hal.InitHidlHal(
68            target_type="media_omx",
69            target_basepaths=self._dut.libPaths,
70            target_version=1.0,
71            target_package="android.hardware.media.omx",
72            target_component_name="IOmx",
73            bits=64 if self._dut.is64Bit else 32)
74
75        # Call listNodes to get all registered components.
76        self.vtypes = self._dut.hal.media_omx.GetHidlTypeInterface("types")
77        status, nodeList = self._dut.hal.media_omx.listNodes()
78        asserts.assertEqual(self.vtypes.Status.OK, status)
79
80        self.components = {}
81        for node in nodeList:
82            self.components[node['mName']] = node['mRoles']
83
84        super(VtsHalMediaOmxV1_0Host, self).CreateTestCases()
85
86    # @Override
87    def CreateTestCase(self, path, tag=''):
88        """Create a list of VtsHalMediaOmxV1_0testCase objects.
89
90        For each target side gtest test case, create a set of new test cases
91        argumented with different component and role values.
92
93        Args:
94            path: string, absolute path of a gtest binary on device
95            tag: string, a tag that will be appended to the end of test name
96
97        Returns:
98            A list of VtsHalMediaOmxV1_0TestCase objects
99        """
100        gtest_cases = super(VtsHalMediaOmxV1_0Host, self).CreateTestCase(path,
101                                                                         tag)
102        test_cases = []
103
104        for gtest_case in gtest_cases:
105            test_suite = gtest_case.GetFullName()
106            for component, roles in self.components.iteritems():
107                for role in roles:
108                    if not self.COMPONENT_TEST in test_suite and not role in self.whitelist_roles:
109                        continue
110                    if self.AUDIO_ENC_TEST in test_suite and not "audio_encoder" in role:
111                        continue
112                    if self.AUDIO_DEC_TEST in test_suite and not "audio_decoder" in role:
113                        continue
114                    if self.VIDEO_ENC_TEST in test_suite and not "video_encoder" in role:
115                        continue
116                    if self.VIDEO_DEC_TEST in test_suite and not "video_decoder" in role:
117                        continue
118                    test_name = component + '_' + role
119                    # TODO (zhuoyao): get instance name using lshal.
120                    instance_name = "default"
121                    test_case = omx_test_case.VtsHalMediaOmxV1_0TestCase(
122                        component, role, instance_name, test_suite, test_name,
123                        path)
124                    test_cases.append(test_case)
125        logging.info("num of test_testcases: %s", len(test_cases))
126        return test_cases
127
128
129if __name__ == "__main__":
130    test_runner.main()
131