1 #!/usr/bin/env python3.4
3 # Copyright (C) 2016 The Android Open Source Project
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
9 # http://www.apache.org/licenses/LICENSE-2.0
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.
21 from vts.runners.host import asserts
22 from vts.runners.host import base_test_with_webdb
23 from vts.runners.host import test_runner
24 from vts.utils.python.controllers import android_device
25 from vts.utils.python.profiling import profiling_utils
28 class VibratorHidlTest(base_test_with_webdb.BaseTestWithWebDbClass):
29 """A simple testcase for the VIBRATOR HIDL HAL."""
32 """Creates a mirror and turns on the framework-layer VIBRATOR service."""
33 self.dut = self.registerController(android_device)[0]
35 self.dut.shell.InvokeTerminal("one")
36 self.dut.shell.one.Execute("setenforce 0") # SELinux permissive mode
38 # Test using the binderized mode
39 self.dut.shell.one.Execute(
40 "setprop vts.hal.vts.hidl.get_stub true")
42 if self.enable_profiling:
43 profiling_utils.EnableVTSProfiling(self.dut.shell.one)
45 self.dut.hal.InitHidlHal(
46 target_type="vibrator",
47 target_basepaths=self.dut.libPaths,
49 target_package="android.hardware.vibrator",
50 target_component_name="IVibrator",
51 hw_binder_service_name="vibrator",
52 bits=64 if self.dut.is64Bit else 32)
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.
58 if self.enable_profiling:
59 profiling_trace_path = getattr(
60 self, self.VTS_PROFILING_TRACING_PATH, "")
61 self.ProcessAndUploadTraceData(self.dut, profiling_trace_path)
62 profiling_utils.DisableVTSProfiling(self.dut.shell.one)
64 def testVibratorBasic(self):
65 """A simple test case which just calls each registered function."""
66 vibrator_types = self.dut.hal.vibrator.GetHidlTypeInterface("types")
67 logging.info("vibrator_types: %s", vibrator_types)
68 logging.info("OK: %s", vibrator_types.OK)
69 logging.info("ERR: %s", vibrator_types.ERR)
71 result = self.dut.hal.vibrator.on(10000)
72 logging.info("on result: %s", result)
73 asserts.assertEqual(vibrator_types.OK, result)
77 result = self.dut.hal.vibrator.off()
78 logging.info("off result: %s", result)
79 asserts.assertEqual(vibrator_types.OK, result)
81 if __name__ == "__main__":