OSDN Git Service

Update profiling code for host-side tests.
[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         self.dut.hal.InitHidlHal(
43             target_type="vibrator",
44             target_basepaths=self.dut.libPaths,
45             target_version=1.0,
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)
50
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.
54         """
55         if self.enable_profiling:
56             self.ProcessAndUploadTraceData()
57
58     def setUpTest(self):
59         if self.enable_profiling:
60             profiling_utils.EnableVTSProfiling(self.dut.shell.one)
61
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)
68
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)
75
76         result = self.dut.hal.vibrator.on(10000)
77         logging.info("on result: %s", result)
78         asserts.assertEqual(vibrator_types.OK, result)
79
80         time.sleep(1)
81
82         result = self.dut.hal.vibrator.off()
83         logging.info("off result: %s", result)
84         asserts.assertEqual(vibrator_types.OK, result)
85
86 if __name__ == "__main__":
87     test_runner.main()