1# Copyright 2017 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
15import its.caps
16import its.device
17import its.target
18
19import numpy
20
21GAIN_LENGTH = 4
22TRANSFORM_LENGTH = 9
23GREEN_GAIN = 1.0
24GREEN_GAIN_TOL = 0.05
25SINGLE_A = {'ae': [True, False, True], 'af': [False, True, True],
26            'full_3a': [True, True, True]}  # note no AWB solo
27
28
29def main():
30    """Basic test for bring-up of 3A.
31
32    To pass, 3A must converge. Check that the returned 3A values are legal.
33    """
34
35    with its.device.ItsSession() as cam:
36        props = cam.get_camera_properties()
37        its.caps.skip_unless(its.caps.read_3a(props))
38
39        for k, v in sorted(SINGLE_A.items()):
40            print k
41            try:
42                s, e, g, xform, fd = cam.do_3a(get_results=True,
43                                               do_ae=v[0],
44                                               do_af=v[1],
45                                               do_awb=v[2])
46                print ' sensitivity', s, 'exposure', e
47                print ' gains', g, 'transform', xform
48                print ' fd', fd
49                print ''
50            except its.error.Error:
51                print ' FAIL\n'
52            if k == 'full_3a':
53                assert s > 0
54                assert e > 0
55                assert len(g) == 4
56                assert len(xform) == 9
57                assert fd >= 0
58                assert numpy.isclose(g[2], GREEN_GAIN, GREEN_GAIN_TOL)
59
60if __name__ == '__main__':
61    main()
62
63