OSDN Git Service

da70474e426ece419f884fd5f2bc3e4252f96e73
[android-x86/hardware-interfaces.git] / vibrator / 1.0 / vts / functional / vts / testcases / hal / vibrator / hidl / host / VibratorHidlTest.py
1 #!/usr/bin/env python3.4
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
18 import logging
19 import time
20
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
26
27
28 class VibratorHidlTest(base_test_with_webdb.BaseTestWithWebDbClass):
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
38         # Test using the binderized mode
39         self.dut.shell.one.Execute(
40             "setprop vts.hal.vts.hidl.get_stub true")
41
42         if self.enable_profiling:
43             profiling_utils.EnableVTSProfiling(self.dut.shell.one)
44
45         self.dut.hal.InitHidlHal(
46             target_type="vibrator",
47             target_basepaths=self.dut.libPaths,
48             target_version=1.0,
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)
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 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)
63
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)
70
71         result = self.dut.hal.vibrator.on(10000)
72         logging.info("on result: %s", result)
73         asserts.assertEqual(vibrator_types.OK, result)
74
75         time.sleep(1)
76
77         result = self.dut.hal.vibrator.off()
78         logging.info("off result: %s", result)
79         asserts.assertEqual(vibrator_types.OK, result)
80
81 if __name__ == "__main__":
82     test_runner.main()