• 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 os
20
21from vts.runners.host import keys
22from vts.runners.host import test_runner
23from vts.utils.python.controllers import adb
24from vts.utils.python.controllers import android_device
25from vts.utils.python.common import vts_spec_utils
26
27from vts.testcases.fuzz.template.libfuzzer_test import libfuzzer_test_config as config
28from vts.testcases.fuzz.template.libfuzzer_test import libfuzzer_test_case
29from vts.testcases.fuzz.template.func_fuzzer_test import func_fuzzer_test
30
31
32class IfaceFuzzerTest(func_fuzzer_test.FuncFuzzerTest):
33    """Runs iface_fuzzer tests on target.
34
35    Attributes:
36        See func_fuzzer_test.
37    """
38    _VTS_SPEC_DIR_TARGET = os.path.join(config.FUZZER_TEST_DIR, 'spec')
39
40    def _PushVtsResources(self, hal_name, hal_version):
41        """Pushes resources needed for test to target device.
42
43        Args:
44            hal_name: string, name of the hal, e.g. 'vibrator'.
45            hal_version: string, version of the hal, e.g '7.4'
46        """
47        # Push .vts spec files.
48        hal_name_dir = hal_name.replace('.', '/')
49        src_dir = os.path.join(self.data_file_path, 'spec', 'hardware',
50                               'interfaces', hal_name_dir, hal_version, 'vts')
51
52        # Push corresponding VTS drivers.
53        driver_name = 'android.hardware.%s@%s-vts.driver.so' % (hal_name,
54                                                                hal_version)
55        driver32 = os.path.join(self.data_file_path, 'DATA', 'lib', driver_name)
56        driver64 = os.path.join(self.data_file_path, 'DATA', 'lib64',
57                                driver_name)
58        try:
59            self._dut.adb.push(src_dir, self._VTS_SPEC_DIR_TARGET)
60            self._dut.adb.push(driver32, 'data/local/tmp/32')
61            self._dut.adb.push(driver64, 'data/local/tmp/64')
62        except adb.AdbError as e:
63            logging.exception(e)
64
65    # Override
66    def CreateTestCases(self):
67        """See base class."""
68        hal_package = self.hal_hidl_package_name
69        hal_name, hal_version = vts_spec_utils.HalPackageToNameAndVersion(
70            hal_package)
71        self._PushVtsResources(hal_name, hal_version)
72        vts_spec_names = self._vts_spec_parser.VtsSpecNames(hal_name,
73                                                            hal_version)
74        registered_interfaces = self._RegisteredInterfaces(
75            self.hal_hidl_package_name)
76
77        test_cases = []
78        for iface in registered_interfaces:
79            additional_params = {
80                'vts_spec_dir': self._VTS_SPEC_DIR_TARGET,
81                'vts_exec_size': 128,
82                'vts_target_iface': iface,
83            }
84            libfuzzer_params = {
85                'max_len': 65536,
86                'max_total_time': 1,
87            }
88            bin_host_path = os.path.join(self.data_file_path, 'DATA', 'bin',
89                                           'vts_proto_fuzzer')
90            test_case = libfuzzer_test_case.LibFuzzerTestCase(
91                bin_host_path, libfuzzer_params, additional_params)
92            test_case.test_name = iface
93            test_cases.append(test_case)
94
95        return test_cases
96
97
98if __name__ == '__main__':
99    test_runner.main()
100