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