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 base_test 23from vts.runners.host import test_runner 24from vts.utils.python.controllers import android_device 25from vts.utils.python.precondition import precondition_utils 26 27 28class VibratorHidlTest(base_test.BaseTestClass): 29 """A simple testcase for the VIBRATOR HIDL HAL.""" 30 31 def setUpClass(self): 32 """Creates a mirror and turns on the framework-layer VIBRATOR service.""" 33 self.dut = self.registerController(android_device)[0] 34 35 self.dut.shell.InvokeTerminal("one") 36 self.dut.shell.one.Execute("setenforce 0") # SELinux permissive mode 37 if not precondition_utils.CanRunHidlHalTest( 38 self, self.dut, self.dut.shell.one): 39 self._skip_all_testcases = True 40 return 41 42 # Test using the binderized mode 43 self.dut.shell.one.Execute( 44 "setprop vts.hal.vts.hidl.get_stub true") 45 46 self.dut.hal.InitHidlHal( 47 target_type="vibrator", 48 target_basepaths=self.dut.libPaths, 49 target_version=1.0, 50 target_package="android.hardware.vibrator", 51 target_component_name="IVibrator", 52 bits=int(self.abi_bitness)) 53 54 def tearDownClass(self): 55 """ If profiling is enabled for the test, collect the profiling data 56 and disable profiling after the test is done. 57 """ 58 if not self._skip_all_testcases and self.profiling.enabled: 59 self.profiling.ProcessAndUploadTraceData() 60 61 def setUp(self): 62 if self.profiling.enabled: 63 self.profiling.EnableVTSProfiling(self.dut.shell.one) 64 65 def tearDown(self): 66 if self.profiling.enabled: 67 self.profiling.ProcessTraceDataForTestCase(self.dut) 68 self.profiling.DisableVTSProfiling(self.dut.shell.one) 69 70 def testVibratorBasic(self): 71 """A simple test case which just calls each registered function.""" 72 vibrator_types = self.dut.hal.vibrator.GetHidlTypeInterface("types") 73 logging.info("vibrator_types: %s", vibrator_types) 74 logging.info("OK: %s", vibrator_types.Status.OK) 75 logging.info("UNKNOWN_ERROR: %s", vibrator_types.Status.UNKNOWN_ERROR) 76 logging.info("BAD_VALUE: %s", vibrator_types.Status.BAD_VALUE) 77 logging.info("UNSUPPORTED_OPERATION: %s", 78 vibrator_types.Status.UNSUPPORTED_OPERATION) 79 80 result = self.dut.hal.vibrator.on(10000) 81 logging.info("on result: %s", result) 82 asserts.assertEqual(vibrator_types.Status.OK, result) 83 84 time.sleep(1) 85 86 result = self.dut.hal.vibrator.off() 87 logging.info("off result: %s", result) 88 asserts.assertEqual(vibrator_types.Status.OK, result) 89 90if __name__ == "__main__": 91 test_runner.main() 92