1# Copyright 2021 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"""Verify camera startup is < 600ms for both front and back primary cameras.
15"""
16
17from mobly import test_runner
18
19import its_base_test
20import camera_properties_utils
21import its_session_utils
22
23# This must match MPC12_CAMERA_LAUNCH_THRESHOLD in ItsTestActivity.java
24_CAMERA_LAUNCH_S_PERFORMANCE_CLASS_THRESHOLD = 600  # ms
25
26
27class CameraLaunchSPerfClassTest(its_base_test.ItsBaseTest):
28  """Test camera launch latency for S performance class as specified in CDD.
29
30  [2.2.7.2/7.5/H-1-6] MUST have camera2 startup latency (open camera to first
31  preview frame) < 600ms as measured by the CTS camera PerformanceTest under
32  ITS lighting conditions (3000K) for both primary cameras.
33  """
34
35  def test_camera_launch(self):
36    # Open camera with "with" semantics to check skip condition and load chart
37    #
38    with its_session_utils.ItsSession(
39        device_id=self.dut.serial,
40        camera_id=self.camera_id) as cam:
41
42      camera_properties_utils.skip_unless(
43          cam.is_primary_camera())
44
45      # Load chart for scene.
46      props = cam.get_camera_properties()
47      its_session_utils.load_scene(
48          cam, props, self.scene, self.tablet, self.chart_distance)
49
50    # Create an its session without opening the camera to test camera launch
51    # latency
52    cam = its_session_utils.ItsSession(
53        device_id=self.dut.serial,
54        camera_id=self.camera_id)
55
56    launch_ms = cam.measure_camera_launch_ms()
57
58    # Assert launch time if device claims performance class
59    if (cam.is_performance_class() and
60        launch_ms >= _CAMERA_LAUNCH_S_PERFORMANCE_CLASS_THRESHOLD):
61      raise AssertionError(f'camera_launch_time_ms: {launch_ms}, THRESH: '
62                           f'{_CAMERA_LAUNCH_S_PERFORMANCE_CLASS_THRESHOLD}')
63
64    # Log launch time, so that the corresponding MPC level can be written to
65    # report log. Text must match MPC12_CAMERA_LAUNCH_PATTERN in
66    # ItsTestActivity.java.
67    print(f'camera_launch_time_ms:{launch_ms}')
68
69if __name__ == '__main__':
70  test_runner.main()
71