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
26AWB_GAINS_LENGTH = 4
27AWB_XFORM_LENGTH = 9
28NAME = os.path.splitext(os.path.basename(__file__))[0]
29
30
31class ThreeATest(its_base_test.ItsBaseTest):
32  """Test basic camera 3A behavior.
33
34  To pass, 3A must converge. Check that returned 3A values are valid.
35  """
36
37  def test_3a(self):
38    logging.debug('Starting %s', NAME)
39    with its_session_utils.ItsSession(
40        device_id=self.dut.serial,
41        camera_id=self.camera_id,
42        hidden_physical_id=self.hidden_physical_id) as cam:
43      props = cam.get_camera_properties()
44      props = cam.override_with_hidden_physical_camera_props(props)
45      camera_properties_utils.skip_unless(
46          camera_properties_utils.read_3a(props))
47      mono_camera = camera_properties_utils.mono_camera(props)
48
49      # Load chart for scene
50      its_session_utils.load_scene(
51          cam, props, self.scene, self.tablet, self.chart_distance)
52
53      # Do 3A and evaluate outputs
54      s, e, awb_gains, awb_xform, focus = cam.do_3a(
55          get_results=True, mono_camera=mono_camera)
56      logging.debug('AWB: gains %s, xform %s', str(awb_gains), str(awb_xform))
57      logging.debug('AE: sensitivity %d, exposure %dns', s, e)
58      logging.debug('AF: distance %.3f', focus)
59
60      assert len(awb_gains) == AWB_GAINS_LENGTH
61      for g in awb_gains:
62        assert not np.isnan(g)
63      assert len(awb_xform) == AWB_XFORM_LENGTH
64      for x in awb_xform:
65        assert not np.isnan(x)
66      assert s > 0
67      assert e > 0
68      assert focus >= 0
69
70if __name__ == '__main__':
71  test_runner.main()
72