blob: b6d398f96d1495e3fb95ff90d17362b733131276 [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
Yin-Chia Yeh76dd1432015-04-27 16:42:03 -0700136def raw12(props):
137 """Returns whether a device supports RAW12 output.
138
139 Args:
140 props: Camera properties object.
141
142 Returns:
143 Boolean.
144 """
145 return len(its.objects.get_available_output_sizes("raw12", props)) > 0
146
Ruben Brunk370e2432014-10-14 18:33:23 -0700147def sensor_fusion(props):
148 """Returns whether the camera and motion sensor timestamps for the device
Chien-Yu Chen682faa22014-10-22 17:34:44 -0700149 are in the same time domain and can be compared directly.
Ruben Brunk370e2432014-10-14 18:33:23 -0700150
151 Args:
152 props: Camera properties object.
153
154 Returns:
155 Boolean.
156 """
157 return props.has_key("android.sensor.info.timestampSource") and \
158 props["android.sensor.info.timestampSource"] == 1
159
160def read_3a(props):
161 """Return whether a device supports reading out the following 3A settings:
162 sensitivity
163 exposure time
164 awb gain
165 awb cct
166 focus distance
167
168 Args:
169 props: Camera properties object.
170
171 Returns:
172 Boolean.
173 """
174 # TODO: check available result keys explicitly
175 return manual_sensor(props) and manual_post_proc(props)
176
177def compute_target_exposure(props):
178 """Return whether a device supports target exposure computation in its.target module.
179
180 Args:
181 props: Camera properties object.
182
183 Returns:
184 Boolean.
185 """
186 return manual_sensor(props) and manual_post_proc(props)
187
Chien-Yu Chen0feea4a2014-10-20 11:04:11 -0700188def freeform_crop(props):
189 """Returns whether a device supports freefrom cropping.
190
191 Args:
192 props: Camera properties object.
193
194 Return:
195 Boolean.
196 """
197 return props.has_key("android.scaler.croppingType") and \
198 props["android.scaler.croppingType"] == 1
199
Chien-Yu Chen82739112014-10-21 13:33:42 -0700200def flash(props):
201 """Returns whether a device supports flash control.
202
203 Args:
204 props: Camera properties object.
205
206 Return:
207 Boolean.
208 """
209 return props.has_key("android.flash.info.available") and \
210 props["android.flash.info.available"] == 1
211
Chien-Yu Chen34fa85d2014-10-22 16:58:08 -0700212def per_frame_control(props):
213 """Returns whether a device supports per frame control
214
215 Args:
216 props: Camera properties object.
217
218 Return:
219 Boolean.
220 """
221 return props.has_key("android.sync.maxLatency") and \
222 props["android.sync.maxLatency"] == 0
223
Zhijun He503da802015-02-04 14:35:38 -0800224def ev_compensation(props):
225 """Returns whether a device supports ev compensation
226
227 Args:
228 props: Camera properties object.
229
230 Return:
231 Boolean.
232 """
233 return props.has_key("android.control.aeCompensationRange") and \
234 props["android.control.aeCompensationRange"] != [0, 0]
235
Yin-Chia Yeh9c0d9262015-04-03 17:02:13 -0700236def ae_lock(props):
237 """Returns whether a device supports AE lock
238
239 Args:
240 props: Camera properties object.
241
242 Return:
243 Boolean.
244 """
245 return props.has_key("android.control.aeLockAvailable") and \
246 props["android.control.aeLockAvailable"] == 1
247
248def awb_lock(props):
249 """Returns whether a device supports AWB lock
250
251 Args:
252 props: Camera properties object.
253
254 Return:
255 Boolean.
256 """
257 return props.has_key("android.control.awbLockAvailable") and \
258 props["android.control.awbLockAvailable"] == 1
259
Yin-Chia Yeh934d8002015-05-26 14:34:39 -0700260def lsc_map(props):
261 """Returns whether a device supports lens shading map output
262
263 Args:
264 props: Camera properties object.
265
266 Return:
267 Boolean.
268 """
269 return props.has_key(
270 "android.statistics.info.availableLensShadingMapModes") and \
271 1 in props["android.statistics.info.availableLensShadingMapModes"]
272
273def lsc_off(props):
274 """Returns whether a device supports disabling lens shading correction
275
276 Args:
277 props: Camera properties object.
278
279 Return:
280 Boolean.
281 """
282 return props.has_key(
283 "android.shading.availableModes") and \
284 0 in props["android.shading.availableModes"]
285
Chien-Yu Chen4e1e2cc2015-06-08 17:46:52 -0700286def yuv_reprocess(props):
287 """Returns whether a device supports YUV reprocessing.
288
289 Args:
290 props: Camera properties object.
291
292 Returns:
293 Boolean.
294 """
295 return props.has_key("android.request.availableCapabilities") and \
296 7 in props["android.request.availableCapabilities"]
297
298def private_reprocess(props):
299 """Returns whether a device supports PRIVATE reprocessing.
300
301 Args:
302 props: Camera properties object.
303
304 Returns:
305 Boolean.
306 """
307 return props.has_key("android.request.availableCapabilities") and \
308 4 in props["android.request.availableCapabilities"]
309
Ruben Brunk370e2432014-10-14 18:33:23 -0700310class __UnitTest(unittest.TestCase):
311 """Run a suite of unit tests on this module.
312 """
313 # TODO: Add more unit tests.
314
315if __name__ == '__main__':
316 unittest.main()
317