blob: 2c45368f8c72d76a04f14004843328d24bd0ed60 [file] [log] [blame]
Ruben Brunk370e2432014-10-14 18:33:23 -07001# Copyright 2014 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 unittest
16import its.objects
Chien-Yu Chenbad96ca2014-10-20 17:30:56 -070017import sys
18
19
20def skip_unless(cond):
21 """Skips the test if the condition is false.
22
23 If a test is skipped, then it is exited and returns the special code
24 of 101 to the calling shell, which can be used by an external test
25 harness to differentiate a skip from a pass or fail.
26
27 Args:
28 cond: Boolean, which must be true for the test to not skip.
29
30 Returns:
31 Nothing.
32 """
33 SKIP_RET_CODE = 101
34
35 if not cond:
36 print "Test skipped"
37 sys.exit(SKIP_RET_CODE)
38
Ruben Brunk370e2432014-10-14 18:33:23 -070039
40def full(props):
41 """Returns whether a device is a FULL capability camera2 device.
42
43 Args:
44 props: Camera properties object.
45
46 Returns:
47 Boolean.
48 """
49 return props.has_key("android.info.supportedHardwareLevel") and \
50 props["android.info.supportedHardwareLevel"] == 1
51
52def limited(props):
53 """Returns whether a device is a LIMITED capability camera2 device.
54
55 Args:
56 props: Camera properties object.
57
58 Returns:
59 Boolean.
60 """
61 return props.has_key("android.info.supportedHardwareLevel") and \
62 props["android.info.supportedHardwareLevel"] == 0
63
64def legacy(props):
65 """Returns whether a device is a LEGACY capability camera2 device.
66
67 Args:
68 props: Camera properties object.
69
70 Returns:
71 Boolean.
72 """
73 return props.has_key("android.info.supportedHardwareLevel") and \
74 props["android.info.supportedHardwareLevel"] == 2
75
76def manual_sensor(props):
77 """Returns whether a device supports MANUAL_SENSOR capabilities.
78
79 Args:
80 props: Camera properties object.
81
82 Returns:
83 Boolean.
84 """
85 return props.has_key("android.request.availableCapabilities") and \
86 1 in props["android.request.availableCapabilities"] \
87 or full(props)
88
89def manual_post_proc(props):
90 """Returns whether a device supports MANUAL_POST_PROCESSING capabilities.
91
92 Args:
93 props: Camera properties object.
94
95 Returns:
96 Boolean.
97 """
98 return props.has_key("android.request.availableCapabilities") and \
99 2 in props["android.request.availableCapabilities"] \
100 or full(props)
101
102def raw(props):
103 """Returns whether a device supports RAW capabilities.
104
105 Args:
106 props: Camera properties object.
107
108 Returns:
109 Boolean.
110 """
111 return props.has_key("android.request.availableCapabilities") and \
112 3 in props["android.request.availableCapabilities"]
113
114def raw16(props):
115 """Returns whether a device supports RAW16 output.
116
117 Args:
118 props: Camera properties object.
119
120 Returns:
121 Boolean.
122 """
123 return len(its.objects.get_available_output_sizes("raw", props)) > 0
124
125def raw10(props):
126 """Returns whether a device supports RAW10 output.
127
128 Args:
129 props: Camera properties object.
130
131 Returns:
132 Boolean.
133 """
134 return len(its.objects.get_available_output_sizes("raw10", props)) > 0
135
136def sensor_fusion(props):
137 """Returns whether the camera and motion sensor timestamps for the device
138 are in the same time domain and can be compared direcctly.
139
140 Args:
141 props: Camera properties object.
142
143 Returns:
144 Boolean.
145 """
146 return props.has_key("android.sensor.info.timestampSource") and \
147 props["android.sensor.info.timestampSource"] == 1
148
149def read_3a(props):
150 """Return whether a device supports reading out the following 3A settings:
151 sensitivity
152 exposure time
153 awb gain
154 awb cct
155 focus distance
156
157 Args:
158 props: Camera properties object.
159
160 Returns:
161 Boolean.
162 """
163 # TODO: check available result keys explicitly
164 return manual_sensor(props) and manual_post_proc(props)
165
166def compute_target_exposure(props):
167 """Return whether a device supports target exposure computation in its.target module.
168
169 Args:
170 props: Camera properties object.
171
172 Returns:
173 Boolean.
174 """
175 return manual_sensor(props) and manual_post_proc(props)
176
Chien-Yu Chen0feea4a2014-10-20 11:04:11 -0700177def freeform_crop(props):
178 """Returns whether a device supports freefrom cropping.
179
180 Args:
181 props: Camera properties object.
182
183 Return:
184 Boolean.
185 """
186 return props.has_key("android.scaler.croppingType") and \
187 props["android.scaler.croppingType"] == 1
188
Chien-Yu Chen82739112014-10-21 13:33:42 -0700189def flash(props):
190 """Returns whether a device supports flash control.
191
192 Args:
193 props: Camera properties object.
194
195 Return:
196 Boolean.
197 """
198 return props.has_key("android.flash.info.available") and \
199 props["android.flash.info.available"] == 1
200
Chien-Yu Chen34fa85d2014-10-22 16:58:08 -0700201
202def per_frame_control(props):
203 """Returns whether a device supports per frame control
204
205 Args:
206 props: Camera properties object.
207
208 Return:
209 Boolean.
210 """
211 return props.has_key("android.sync.maxLatency") and \
212 props["android.sync.maxLatency"] == 0
213
Ruben Brunk370e2432014-10-14 18:33:23 -0700214class __UnitTest(unittest.TestCase):
215 """Run a suite of unit tests on this module.
216 """
217 # TODO: Add more unit tests.
218
219if __name__ == '__main__':
220 unittest.main()
221