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 self.dut.hal.InitHidlHal(
43 target_type="vibrator",
44 target_basepaths=self.dut.libPaths,
46 target_package="android.hardware.vibrator",
47 target_component_name="IVibrator",
48 hw_binder_service_name="vibrator",
49 bits=64 if self.dut.is64Bit else 32)
51 def tearDownClass(self):
52 """ If profiling is enabled for the test, collect the profiling data
53 and disable profiling after the test is done.
55 if self.enable_profiling:
56 self.ProcessAndUploadTraceData()
59 if self.enable_profiling:
60 profiling_utils.EnableVTSProfiling(self.dut.shell.one)
62 def tearDownTest(self):
63 if self.enable_profiling:
64 profiling_trace_path = getattr(
65 self, self.VTS_PROFILING_TRACING_PATH, "")
66 self.ProcessTraceDataForTestCase(self.dut, profiling_trace_path)
67 profiling_utils.DisableVTSProfiling(self.dut.shell.one)
69 def testVibratorBasic(self):
70 """A simple test case which just calls each registered function."""
71 vibrator_types = self.dut.hal.vibrator.GetHidlTypeInterface("types")
72 logging.info("vibrator_types: %s", vibrator_types)
73 logging.info("OK: %s", vibrator_types.OK)
74 logging.info("ERR: %s", vibrator_types.ERR)
76 result = self.dut.hal.vibrator.on(10000)
77 logging.info("on result: %s", result)
78 asserts.assertEqual(vibrator_types.OK, result)
82 result = self.dut.hal.vibrator.off()
83 logging.info("off result: %s", result)
84 asserts.assertEqual(vibrator_types.OK, result)
86 if __name__ == "__main__":