• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#  Copyright (C) 2025 The Android Open Source Project
2#
3#  Licensed under the Apache License, Version 2.0 (the "License");
4#  you may not use this file except in compliance with the License.
5#  You may obtain a copy of the License at
6#
7#       http://www.apache.org/licenses/LICENSE-2.0
8#
9#  Unless required by applicable law or agreed to in writing, software
10#  distributed under the License is distributed on an "AS IS" BASIS,
11#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12#  See the License for the specific language governing permissions and
13#  limitations under the License.
14
15import logging
16from mobly import base_test
17from mobly import test_runner
18from mobly.controllers import android_device
19from utilities.main_utils import common_main
20
21class VhalValidationTest(base_test.BaseTestClass):
22
23    def setup_class(self):
24        # Registers Android device controllers.
25        self.android_devices = self.register_controller(android_device)
26
27    def check_vhal_properties(self):
28        """Checks if VHAL is listing expected properties.
29
30        Returns:
31            bool: True if the properties are listed as expected, False otherwise.
32        """
33        cmd = 'dumpsys android.hardware.automotive.vehicle.IVehicle/default --list'
34        output_bytes = self.android_devices[0].adb.shell(cmd)
35        output = output_bytes.decode('utf-8')
36        #logging.info('Current VHAL properties: {}'.format(output))
37
38        # Extract property ids from the output.
39        properties_list = []
40        for line in output.splitlines()[1:]:  # Skip the first line which contains "listing xx properties"
41            if ':' in line:
42                try:
43                    property_id = int(line.split(':')[1].strip())
44                    properties_list.append(property_id)
45                except ValueError:
46                    logging.error('Failed to parse property id from line: {}'.format(line))
47
48        # Define expected properties, replace this with the actual list you're expecting.
49        expected_properties = set([356582673,356517131]) # Example, properties 0 through 96.
50
51        # Create a set of properties found in the output.
52        found_properties = set(properties_list)
53
54        # Check if any expected properties are missing.
55        missing_properties = expected_properties - found_properties
56        if missing_properties:
57            logging.error('Missing VHAL properties: {}'.format(missing_properties))
58
59        return not missing_properties
60
61    def test_vhal_properties_validation(self):
62        if not self.check_vhal_properties():
63            raise AssertionError('VHAL properties are not as expected.')
64
65if __name__ == '__main__':
66    common_main()
67