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 as np
20
21GGAIN_TOL = 0.1
22FD_TOL = 0.1
23SENS_TOL = 0.1
24EXP_TOL = 0.1
25NUM_TEST_ITERATIONS = 3
26
27
28def main():
29    """Basic test for 3A consistency.
30
31    To pass, 3A must converge for exp, gain, awb, fd within TOL.
32    """
33
34    with its.device.ItsSession() as cam:
35        props = cam.get_camera_properties()
36        its.caps.skip_unless(its.caps.read_3a(props))
37
38        exps = []
39        senses = []
40        g_gains = []
41        fds = []
42        for _ in range(NUM_TEST_ITERATIONS):
43            try:
44                s, e, g, xform, fd = cam.do_3a(get_results=True)
45                print ' sensitivity', s, 'exposure', e
46                print ' gains', g, 'transform', xform
47                print ' fd', fd
48                print ''
49                exps.append(e)
50                senses.append(s)
51                g_gains.append(g[2])
52                fds.append(fd)
53            except its.error.Error:
54                print ' FAIL\n'
55        assert len(exps) == NUM_TEST_ITERATIONS
56        assert np.isclose(np.amax(exps), np.amin(exps), EXP_TOL)
57        assert np.isclose(np.amax(senses), np.amin(senses), SENS_TOL)
58        assert np.isclose(np.amax(g_gains), np.amin(g_gains), GGAIN_TOL)
59        assert np.isclose(np.amax(fds), np.amin(fds), FD_TOL)
60
61if __name__ == '__main__':
62    main()
63
64