1#!/usr/bin/env python 2# 3# Copyright (C) 2016 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 test_runner 23from vts.testcases.template.hal_hidl_host_test import hal_hidl_host_test 24 25 26class VibratorHidlTest(hal_hidl_host_test.HalHidlHostTest): 27 """A simple testcase for the VIBRATOR HIDL HAL.""" 28 29 TEST_HAL_SERVICES = {"android.hardware.vibrator@1.0::IVibrator"} 30 def setUpClass(self): 31 """Creates a mirror and turns on the framework-layer VIBRATOR service.""" 32 super(VibratorHidlTest, self).setUpClass() 33 34 self.dut.hal.InitHidlHal( 35 target_type="vibrator", 36 target_basepaths=self.dut.libPaths, 37 target_version=1.0, 38 target_package="android.hardware.vibrator", 39 target_component_name="IVibrator", 40 bits=int(self.abi_bitness)) 41 42 def testVibratorBasic(self): 43 """A simple test case which just calls each registered function.""" 44 vibrator_types = self.dut.hal.vibrator.GetHidlTypeInterface("types") 45 logging.info("vibrator_types: %s", vibrator_types) 46 logging.info("OK: %s", vibrator_types.Status.OK) 47 logging.info("UNKNOWN_ERROR: %s", vibrator_types.Status.UNKNOWN_ERROR) 48 logging.info("BAD_VALUE: %s", vibrator_types.Status.BAD_VALUE) 49 logging.info("UNSUPPORTED_OPERATION: %s", 50 vibrator_types.Status.UNSUPPORTED_OPERATION) 51 52 result = self.dut.hal.vibrator.on(10000) 53 logging.info("on result: %s", result) 54 asserts.assertEqual(vibrator_types.Status.OK, result) 55 56 time.sleep(1) 57 58 result = self.dut.hal.vibrator.off() 59 logging.info("off result: %s", result) 60 asserts.assertEqual(vibrator_types.Status.OK, result) 61 62if __name__ == "__main__": 63 test_runner.main() 64