Home | History | Annotate | Download | only in its
      1 # 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 
     15 import unittest
     16 import its.objects
     17 import sys
     18 
     19 
     20 def 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 
     39 
     40 def 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 
     52 def 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 
     64 def 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 
     76 def 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 
     89 def 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 
    102 def 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 
    114 def 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 
    125 def 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 
    136 def 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 directly.
    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 
    149 def 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 
    166 def 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 
    177 def 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 
    189 def 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 
    201 def per_frame_control(props):
    202     """Returns whether a device supports per frame control
    203 
    204     Args:
    205         props: Camera properties object.
    206 
    207     Return:
    208         Boolean.
    209     """
    210     return props.has_key("android.sync.maxLatency") and \
    211            props["android.sync.maxLatency"] == 0
    212 
    213 def ev_compensation(props):
    214     """Returns whether a device supports ev compensation
    215 
    216     Args:
    217         props: Camera properties object.
    218 
    219     Return:
    220         Boolean.
    221     """
    222     return props.has_key("android.control.aeCompensationRange") and \
    223            props["android.control.aeCompensationRange"] != [0, 0]
    224 
    225 class __UnitTest(unittest.TestCase):
    226     """Run a suite of unit tests on this module.
    227     """
    228     # TODO: Add more unit tests.
    229 
    230 if __name__ == '__main__':
    231     unittest.main()
    232 
    233