OSDN Git Service

be070e34894bd0c207fed566765124d574bef8b6
[android-x86/hardware-interfaces.git] / vehicle / 2.0 / vts / functional / vts / testcases / hal / vehicle / hidl / host / VehicleHidlTest.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 VehicleHidlTest(base_test_with_webdb.BaseTestWithWebDbClass):
29     """A simple testcase for the VEHICLE HIDL HAL."""
30
31     def setUpClass(self):
32         """Creates a mirror and init vehicle hal."""
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         if self.enable_profiling:
39             profiling_utils.EnableVTSProfiling(self.dut.shell.one)
40
41         self.dut.hal.InitHidlHal(
42             target_type="vehicle",
43             target_basepaths=self.dut.libPaths,
44             target_version=2.0,
45             target_package="android.hardware.vehicle",
46             target_component_name="IVehicle",
47             hw_binder_service_name="Vehicle",
48             bits=64 if self.dut.is64Bit else 32)
49
50         self.vehicle = self.dut.hal.vehicle  # shortcut
51         self.vtypes = self.dut.hal.vehicle.GetHidlTypeInterface("types")
52         logging.info("vehicle types: %s", self.vtypes)
53
54     def tearDownClass(self):
55         """Disables the profiling.
56
57         If profiling is enabled for the test, collect the profiling data
58         and disable profiling after the test is done.
59         """
60         if self.enable_profiling:
61             profiling_trace_path = getattr(
62                 self, self.VTS_PROFILING_TRACING_PATH, "")
63             self.ProcessAndUploadTraceData(self.dut, profiling_trace_path)
64             profiling_utils.DisableVTSProfiling(self.dut.shell.one)
65
66     def testListProperties(self):
67         """Checks whether some PropConfigs are returned.
68
69         Verifies that call to getAllPropConfigs is not failing and
70         it returns at least 1 vehicle property config.
71         """
72         allConfigs = self.vehicle.getAllPropConfigs()
73         logging.info("all supported properties: %s", allConfigs)
74         asserts.assertLess(0, len(allConfigs))
75
76     def testMandatoryProperties(self):
77         """Verifies that all mandatory properties are supported."""
78         mandatoryProps = set([self.vtypes.DRIVING_STATUS])  # 1 property so far
79         logging.info(self.vtypes.DRIVING_STATUS)
80         allConfigs = self.dut.hal.vehicle.getAllPropConfigs()
81
82         for config in allConfigs:
83             mandatoryProps.discard(config['prop'])
84
85         asserts.assertEqual(0, len(mandatoryProps))
86
87     def getSupportInfo(self):
88         """Check whether OBD2_{LIVE|FREEZE}_FRAME is supported."""
89         isLiveSupported, isFreezeSupported = False, False
90         allConfigs = self.vehicle.getAllPropConfigs()
91         for config in allConfigs:
92             if config['prop'] == self.vtypes.OBD2_LIVE_FRAME:
93                 isLiveSupported = True
94             elif config['prop'] == self.vtypes.OBD2_FREEZE_FRAME:
95                 isFreezeSupported = True
96             if isLiveSupported and isFreezeSupported:
97                 break
98         return isLiveSupported, isFreezeSupported
99
100     def testObd2SensorProperties(self):
101         """Test reading the live and freeze OBD2 frame properties.
102
103         OBD2 (On-Board Diagnostics 2) is the industry standard protocol
104         for retrieving diagnostic sensor information from vehicles.
105         """
106         def checkLiveFrameRead():
107             """Validates reading the OBD2_LIVE_FRAME (if available)."""
108             logging.info("checkLiveFrameRead no-op pass")
109
110         def checkFreezeFrameRead():
111             """Validates reading the OBD2_FREEZE_FRAME (if available)."""
112             logging.info("checkLiveFrameRead no-op pass")
113
114         isLiveSupported, isFreezeSupported = self.getSupportInfo()
115         logging.info("isLiveSupported = %s, isFreezeSupported = %s",
116                      isLiveSupported, isFreezeSupported)
117         if isLiveSupported:
118             checkLiveFrameRead()
119         if isFreezeSupported:
120             checkFreezeFrameRead()
121
122 if __name__ == "__main__":
123     test_runner.main()