1# Copyright 2021 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"""Verify camera startup is < 600ms for both front and back primary cameras. 15""" 16 17import logging 18 19from mobly import test_runner 20 21import camera_properties_utils 22import its_base_test 23import its_session_utils 24 25CAMERA_LAUNCH_S_PERFORMANCE_CLASS_THRESHOLD = 600 # ms 26 27 28class CameraLaunchSPerfClassTest(its_base_test.ItsBaseTest): 29 """Test camera launch latency for S performance class as specified in CDD. 30 31 [7.5/H-1-7] MUST have camera2 startup latency (open camera to first preview 32 frame) < 600ms as measured by the CTS camera PerformanceTest under ITS 33 lighting conditions (3000K) for both primary cameras. 34 """ 35 36 def test_camera_launch(self): 37 # Open camera with "with" semantics to check skip condition and load chart 38 # 39 with its_session_utils.ItsSession( 40 device_id=self.dut.serial, 41 camera_id=self.camera_id) as cam: 42 43 camera_properties_utils.skip_unless( 44 cam.is_performance_class_primary_camera()) 45 46 # Load chart for scene. 47 props = cam.get_camera_properties() 48 its_session_utils.load_scene( 49 cam, props, self.scene, self.tablet, self.chart_distance) 50 51 # Create an its session without opening the camera to test camera launch 52 # latency 53 cam = its_session_utils.ItsSession( 54 device_id=self.dut.serial, 55 camera_id=self.camera_id) 56 57 launch_ms = cam.measure_camera_launch_ms() 58 if launch_ms >= CAMERA_LAUNCH_S_PERFORMANCE_CLASS_THRESHOLD: 59 raise AssertionError(f'camera launch time: {launch_ms} ms, THRESH: ' 60 f'{CAMERA_LAUNCH_S_PERFORMANCE_CLASS_THRESHOLD} ms') 61 else: 62 logging.debug('camera launch time: %.1f ms', launch_ms) 63 64if __name__ == '__main__': 65 test_runner.main() 66