1# Copyright 2013 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"""Verifies 3A converges with gray chart scene.""" 15 16 17import logging 18import os.path 19from mobly import test_runner 20import numpy as np 21 22import its_base_test 23import camera_properties_utils 24import its_session_utils 25 26_AWB_GAINS_LENGTH = 4 27_AWB_XFORM_LENGTH = 9 28_NAME = os.path.splitext(os.path.basename(__file__))[0] 29 30 31def assert_is_number(x): 32 if np.isnan(x): 33 raise AssertionError(f'{x} is not a number!') 34 35 36class ThreeATest(its_base_test.ItsBaseTest): 37 """Test basic camera 3A behavior. 38 39 To pass, 3A must converge. Check that returned 3A values are valid. 40 """ 41 42 def test_3a(self): 43 logging.debug('Starting %s', _NAME) 44 with its_session_utils.ItsSession( 45 device_id=self.dut.serial, 46 camera_id=self.camera_id, 47 hidden_physical_id=self.hidden_physical_id) as cam: 48 props = cam.get_camera_properties() 49 props = cam.override_with_hidden_physical_camera_props(props) 50 camera_properties_utils.skip_unless( 51 camera_properties_utils.read_3a(props)) 52 mono_camera = camera_properties_utils.mono_camera(props) 53 54 # Load chart for scene 55 its_session_utils.load_scene( 56 cam, props, self.scene, self.tablet, self.chart_distance) 57 58 # Do 3A and evaluate outputs 59 s, e, awb_gains, awb_xform, focus = cam.do_3a( 60 get_results=True, mono_camera=mono_camera) 61 logging.debug('AWB: gains %s, xform %s', str(awb_gains), str(awb_xform)) 62 logging.debug('AE: sensitivity %d, exposure %dns', s, e) 63 logging.debug('AF: distance %.3f', focus) 64 65 if len(awb_gains) != _AWB_GAINS_LENGTH: 66 raise AssertionError( 67 f'AWB gains has unexpected # of terms! {awb_gains}') 68 for g in awb_gains: 69 assert_is_number(g) 70 if len(awb_xform) != _AWB_XFORM_LENGTH: 71 raise AssertionError( 72 f'AWB transform has unexpected # of terms! {awb_xform}') 73 for x in awb_xform: 74 assert_is_number(x) 75 if s <= 0: 76 raise AssertionError(f'sensitivity {s} <= 0!') 77 if e <= 0: 78 raise AssertionError(f'exposure {e} <= 0!') 79 if focus < 0: 80 raise AssertionError(f'focus distance {focus} < 0!') 81 82if __name__ == '__main__': 83 test_runner.main() 84