OSDN Git Service

Update profiling code for host-side tests.
[android-x86/hardware-interfaces.git] / sensors / 1.0 / vts / functional / vts / testcases / hal / sensors / hidl / host / SensorsHidlTest.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 SensorsHidlTest(base_test_with_webdb.BaseTestWithWebDbClass):
29     """Host testcase class for the SENSORS HIDL HAL.
30
31     This class set-up/tear-down the webDB host test framwork and contains host test cases for
32     sensors HIDL HAL.
33     """
34
35     def setUpClass(self):
36         """Creates a mirror and turns on the framework-layer SENSORS service."""
37         self.dut = self.registerController(android_device)[0]
38
39         self.dut.shell.InvokeTerminal("one")
40         self.dut.shell.one.Execute("setenforce 0")  # SELinux permissive mode
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="sensors",
48             target_basepaths=self.dut.libPaths,
49             target_version=1.0,
50             target_package="android.hardware.sensors",
51             target_component_name="ISensors",
52             hw_binder_service_name=None,
53             bits=64 if self.dut.is64Bit else 32)
54
55     def tearDownClass(self):
56         """ If profiling is enabled for the test, collect the profiling data
57             and disable profiling after the test is done.
58         """
59         if self.enable_profiling:
60             self.ProcessAndUploadTraceData()
61
62     def setUpTest(self):
63         if self.enable_profiling:
64             profiling_utils.EnableVTSProfiling(self.dut.shell.one)
65
66     def tearDownTest(self):
67         if self.enable_profiling:
68             profiling_trace_path = getattr(
69                 self, self.VTS_PROFILING_TRACING_PATH, "")
70             self.ProcessTraceDataForTestCase(self.dut, profiling_trace_path)
71             profiling_utils.DisableVTSProfiling(self.dut.shell.one)
72
73     def testSensorsBasic(self):
74         """Test the basic operation of test framework and sensor HIDL HAL
75
76         This test obtains predefined enum values via sensors HIDL HAL host test framework and
77         compares them to known values as a sanity check to make sure both sensors HAL
78         and the test framework are working properly.
79         """
80         sensors_types = self.dut.hal.sensors.GetHidlTypeInterface("types")
81         logging.info("sensors_types: %s", sensors_types)
82         logging.info("OK: %s", sensors_types.OK)
83         logging.info("BAD_VALUE: %s", sensors_types.BAD_VALUE)
84         logging.info("PERMISSION_DENIED: %s", sensors_types.PERMISSION_DENIED)
85         logging.info("INVALID_OPERATION: %s", sensors_types.INVALID_OPERATION)
86         asserts.assertEqual(sensors_types.OK, 0);
87         asserts.assertEqual(sensors_types.BAD_VALUE, 1);
88
89         logging.info("sensor types:")
90         logging.info("SENSOR_TYPE_ACCELEROMETER: %s", sensors_types.SENSOR_TYPE_ACCELEROMETER)
91         logging.info("SENSOR_TYPE_GEOMAGNETIC_FIELD: %s", sensors_types.SENSOR_TYPE_GEOMAGNETIC_FIELD)
92         logging.info("SENSOR_TYPE_GYROSCOPE: %s", sensors_types.SENSOR_TYPE_GYROSCOPE)
93         asserts.assertEqual(sensors_types.SENSOR_TYPE_ACCELEROMETER, 1);
94         asserts.assertEqual(sensors_types.SENSOR_TYPE_GEOMAGNETIC_FIELD, 2);
95         asserts.assertEqual(sensors_types.SENSOR_TYPE_GYROSCOPE, 4);
96
97 if __name__ == "__main__":
98     test_runner.main()