1# Copyright 2014 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"""CameraITS test for sensor events.""" 15 16import logging 17import time 18 19from mobly import test_runner 20 21import its_base_test 22import camera_properties_utils 23import its_session_utils 24 25 26class SensorEventTest(its_base_test.ItsBaseTest): 27 """Basic test to query and print out sensor events. 28 29 Test will only work if the screen is on (i.e.) the device isn't in standby. 30 Pass if some of each event are received. 31 """ 32 33 def test_sensor_events(self): 34 with its_session_utils.ItsSession( 35 device_id=self.dut.serial, 36 camera_id=self.camera_id, 37 hidden_physical_id=self.hidden_physical_id) as cam: 38 props = cam.get_camera_properties() 39 props = cam.override_with_hidden_physical_camera_props(props) 40 # Only run test if the appropriate caps are claimed. 41 camera_properties_utils.skip_unless( 42 camera_properties_utils.sensor_fusion(props)) 43 44 sensors = cam.get_sensors() 45 cam.start_sensor_events() 46 time.sleep(1) 47 events = cam.get_sensor_events() 48 logging.debug('Events over 1s: %d gyro, %d accel, %d mag', 49 len(events['gyro']), len(events['accel']), 50 len(events['mag'])) 51 for key, existing in sensors.items(): 52 # Vibrator does not return any sensor event. b/142653973 53 if existing and key != 'vibrator': 54 # Check len(events[key]) > 0 55 if not events[key]: 56 raise AssertionError(f'Sensor {key} has no events!') 57 58 59if __name__ == '__main__': 60 test_runner.main() 61