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 jpeg capture latency for both front and back primary cameras. 15""" 16 17from mobly import test_runner 18 19import its_base_test 20import camera_properties_utils 21import its_session_utils 22 23# This must match MPC12_JPEG_CAPTURE_THRESHOLD in ItsTestActivity.java 24_JPEG_CAPTURE_S_PERFORMANCE_CLASS_THRESHOLD = 1000 # ms 25 26 27class JpegCaptureSPerfClassTest(its_base_test.ItsBaseTest): 28 """Test jpeg capture latency for S performance class as specified in CDD. 29 30 [2.2.7.2/7.5/H-1-5] MUST have camera2 JPEG capture latency < 1000ms for 1080p 31 resolution as measured by the CTS camera PerformanceTest under ITS lighting 32 conditions (3000K) for both primary cameras. 33 """ 34 35 def test_jpeg_capture(self): 36 # Open camera with "with" semantics to check skip condition and load chart 37 # 38 with its_session_utils.ItsSession( 39 device_id=self.dut.serial, 40 camera_id=self.camera_id) as cam: 41 42 camera_properties_utils.skip_unless( 43 cam.is_primary_camera()) 44 45 # Load chart for scene. 46 props = cam.get_camera_properties() 47 its_session_utils.load_scene( 48 cam, props, self.scene, self.tablet, self.chart_distance) 49 50 # Create an Its session without opening the camera to test camera jpeg 51 # capture latency because the test opens camera internally 52 cam = its_session_utils.ItsSession( 53 device_id=self.dut.serial, 54 camera_id=self.camera_id) 55 56 jpeg_capture_ms = cam.measure_camera_1080p_jpeg_capture_ms() 57 58 # Assert jpeg capture time if device claims performance class 59 if (cam.is_performance_class() and 60 jpeg_capture_ms >= _JPEG_CAPTURE_S_PERFORMANCE_CLASS_THRESHOLD): 61 raise AssertionError(f'1080p_jpeg_capture_time_ms: {jpeg_capture_ms}, ' 62 f'THRESH: ' 63 f'{_JPEG_CAPTURE_S_PERFORMANCE_CLASS_THRESHOLD}') 64 65 # Log jpeg capture time so that the corresponding MPC level can be written 66 # to report log. Text must match MPC12_JPEG_CAPTURE_PATTERN in 67 # ItsTestActivity.java. 68 print(f'1080p_jpeg_capture_time_ms:{jpeg_capture_ms}') 69 70if __name__ == '__main__': 71 test_runner.main() 72