• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
18import logging
19import time
20
21from vts.runners.host import asserts
22from vts.runners.host import base_test
23from vts.runners.host import test_runner
24from vts.utils.python.controllers import android_device
25from vts.utils.python.precondition import precondition_utils
26
27
28class SensorsHidlTest(base_test.BaseTestClass):
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        if not precondition_utils.CanRunHidlHalTest(
42            self, self.dut, self.dut.shell.one):
43            self._skip_all_testcases = True
44            return
45
46        # Test using the binderized mode
47        self.dut.shell.one.Execute(
48            "setprop vts.hal.vts.hidl.get_stub true")
49
50        self.dut.hal.InitHidlHal(
51            target_type="sensors",
52            target_basepaths=self.dut.libPaths,
53            target_version=1.0,
54            target_package="android.hardware.sensors",
55            target_component_name="ISensors",
56            hw_binder_service_name=None,
57            bits=int(self.abi_bitness))
58
59    def tearDownClass(self):
60        """ If profiling is enabled for the test, collect the profiling data
61            and disable profiling after the test is done.
62        """
63        if not self._skip_all_testcases and self.profiling.enabled:
64            self.profiling.ProcessAndUploadTraceData()
65
66    def setUp(self):
67        if self.profiling.enabled:
68            self.profiling.EnableVTSProfiling(self.dut.shell.one)
69
70    def tearDown(self):
71        if self.profiling.enabled:
72            self.profiling.ProcessTraceDataForTestCase(self.dut)
73            self.profiling.DisableVTSProfiling(self.dut.shell.one)
74
75    def testSensorsBasic(self):
76        """Test the basic operation of test framework and sensor HIDL HAL
77
78        This test obtains predefined enum values via sensors HIDL HAL host test framework and
79        compares them to known values as a sanity check to make sure both sensors HAL
80        and the test framework are working properly.
81        """
82        sensors_types = self.dut.hal.sensors.GetHidlTypeInterface("types")
83        logging.info("sensors_types: %s", sensors_types)
84        logging.info("OK: %s", sensors_types.Result.OK)
85        logging.info("BAD_VALUE: %s", sensors_types.Result.BAD_VALUE)
86        logging.info("NO_MEMORY: %s", sensors_types.Result.NO_MEMORY)
87        logging.info("PERMISSION_DENIED: %s", sensors_types.Result.PERMISSION_DENIED)
88        logging.info("INVALID_OPERATION: %s", sensors_types.Result.INVALID_OPERATION)
89        asserts.assertEqual(sensors_types.Result.OK, 0)
90        asserts.assertEqual(sensors_types.Result.NO_MEMORY, -12)
91        asserts.assertEqual(sensors_types.Result.BAD_VALUE, -22)
92        asserts.assertEqual(sensors_types.Result.INVALID_OPERATION, -38)
93
94        logging.info("sensor types:")
95        logging.info("ACCELEROMETER: %s", sensors_types.SensorType.ACCELEROMETER)
96        logging.info("MAGNETIC_FIELD: %s", sensors_types.SensorType.MAGNETIC_FIELD)
97        logging.info("GYROSCOPE: %s", sensors_types.SensorType.GYROSCOPE)
98        asserts.assertEqual(sensors_types.SensorType.ACCELEROMETER, 1)
99        asserts.assertEqual(sensors_types.SensorType.MAGNETIC_FIELD, 2)
100        asserts.assertEqual(sensors_types.SensorType.GYROSCOPE, 4)
101
102if __name__ == "__main__":
103    test_runner.main()
104