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 VehicleHidlTest(base_test_with_webdb.BaseTestWithWebDbClass):
29 """A simple testcase for the VEHICLE HIDL HAL."""
32 """Creates a mirror and init vehicle hal."""
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 if self.enable_profiling:
39 profiling_utils.EnableVTSProfiling(self.dut.shell.one)
41 self.dut.hal.InitHidlHal(
42 target_type="vehicle",
43 target_basepaths=self.dut.libPaths,
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)
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)
54 def tearDownClass(self):
55 """Disables the profiling.
57 If profiling is enabled for the test, collect the profiling data
58 and disable profiling after the test is done.
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)
66 def testListProperties(self):
67 """Checks whether some PropConfigs are returned.
69 Verifies that call to getAllPropConfigs is not failing and
70 it returns at least 1 vehicle property config.
72 allConfigs = self.vehicle.getAllPropConfigs()
73 logging.info("all supported properties: %s", allConfigs)
74 asserts.assertLess(0, len(allConfigs))
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()
82 for config in allConfigs:
83 mandatoryProps.discard(config['prop'])
85 asserts.assertEqual(0, len(mandatoryProps))
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:
98 return isLiveSupported, isFreezeSupported
100 def testObd2SensorProperties(self):
101 """Test reading the live and freeze OBD2 frame properties.
103 OBD2 (On-Board Diagnostics 2) is the industry standard protocol
104 for retrieving diagnostic sensor information from vehicles.
106 def checkLiveFrameRead():
107 """Validates reading the OBD2_LIVE_FRAME (if available)."""
108 logging.info("checkLiveFrameRead no-op pass")
110 def checkFreezeFrameRead():
111 """Validates reading the OBD2_FREEZE_FRAME (if available)."""
112 logging.info("checkLiveFrameRead no-op pass")
114 isLiveSupported, isFreezeSupported = self.getSupportInfo()
115 logging.info("isLiveSupported = %s, isFreezeSupported = %s",
116 isLiveSupported, isFreezeSupported)
119 if isFreezeSupported:
120 checkFreezeFrameRead()
122 if __name__ == "__main__":