Home | History | Annotate | Download | only in host
      1 #!/usr/bin/env python
      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 
     20 from vts.runners.host import asserts
     21 from vts.runners.host import test_runner
     22 from vts.testcases.template.hal_hidl_host_test import hal_hidl_host_test
     23 
     24 
     25 class SensorsHidlTest(hal_hidl_host_test.HalHidlHostTest):
     26     """Host testcase class for the SENSORS HIDL HAL.
     27 
     28     This class set-up/tear-down the webDB host test framwork and contains host test cases for
     29     sensors HIDL HAL.
     30     """
     31 
     32     TEST_HAL_SERVICES = {"android.hardware.sensors (at] 1.0::ISensors"}
     33     def setUpClass(self):
     34         """Creates a mirror and turns on the framework-layer SENSORS service."""
     35         super(SensorsHidlTest, self).setUpClass()
     36 
     37         self.dut.hal.InitHidlHal(
     38             target_type="sensors",
     39             target_basepaths=self.dut.libPaths,
     40             target_version=1.0,
     41             target_package="android.hardware.sensors",
     42             target_component_name="ISensors",
     43             bits=int(self.abi_bitness))
     44 
     45     def testSensorsBasic(self):
     46         """Test the basic operation of test framework and sensor HIDL HAL
     47 
     48         This test obtains predefined enum values via sensors HIDL HAL host test framework and
     49         compares them to known values as a sanity check to make sure both sensors HAL
     50         and the test framework are working properly.
     51         """
     52         sensors_types = self.dut.hal.sensors.GetHidlTypeInterface("types")
     53         logging.info("sensors_types: %s", sensors_types)
     54         logging.info("OK: %s", sensors_types.Result.OK)
     55         logging.info("BAD_VALUE: %s", sensors_types.Result.BAD_VALUE)
     56         logging.info("NO_MEMORY: %s", sensors_types.Result.NO_MEMORY)
     57         logging.info("PERMISSION_DENIED: %s", sensors_types.Result.PERMISSION_DENIED)
     58         logging.info("INVALID_OPERATION: %s", sensors_types.Result.INVALID_OPERATION)
     59         asserts.assertEqual(sensors_types.Result.OK, 0)
     60         asserts.assertEqual(sensors_types.Result.NO_MEMORY, -12)
     61         asserts.assertEqual(sensors_types.Result.BAD_VALUE, -22)
     62         asserts.assertEqual(sensors_types.Result.INVALID_OPERATION, -38)
     63 
     64         logging.info("sensor types:")
     65         logging.info("ACCELEROMETER: %s", sensors_types.SensorType.ACCELEROMETER)
     66         logging.info("MAGNETIC_FIELD: %s", sensors_types.SensorType.MAGNETIC_FIELD)
     67         logging.info("GYROSCOPE: %s", sensors_types.SensorType.GYROSCOPE)
     68         asserts.assertEqual(sensors_types.SensorType.ACCELEROMETER, 1)
     69         asserts.assertEqual(sensors_types.SensorType.MAGNETIC_FIELD, 2)
     70         asserts.assertEqual(sensors_types.SensorType.GYROSCOPE, 4)
     71 
     72 if __name__ == "__main__":
     73     test_runner.main()
     74