• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2017 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5"""
6A test which monitors the camera HAL3 performance metrics:
7    1. Time to open device
8    2. Time to start preview
9    3. Time to capture still image
10    4. Shot to shot time
11"""
12
13import os, logging
14from autotest_lib.client.bin import test, utils
15from autotest_lib.client.common_lib import error
16from autotest_lib.client.cros import service_stopper
17from autotest_lib.client.cros.camera import camera_utils
18
19
20class camera_HAL3Perf(test.test):
21    """
22    This test monitors several performance metrics reported by the test binary
23    cros_camera_test.
24    """
25
26    version = 1
27    test_binary = 'cros_camera_test'
28    dep = 'camera_hal3'
29    timeout = 60
30    test_name = 'camera_HAL3Perf'
31    test_log_suffix = 'test.log'
32    cros_camera_service = 'cros-camera'
33
34    def _logperf(self, name, key, value, units, higher_is_better=False):
35        description = '%s.%s' % (name, key)
36        self.output_perf_value(
37            description=description,
38            value=value,
39            units=units,
40            higher_is_better=higher_is_better)
41
42    def _analyze_log(self, log_file):
43        """
44        Analyzes the performance metrics extracted from the log file.
45
46        @param log_file: path of the log file. Sample lines of the log file are
47            as below.
48            Camera: front
49            device_open: 5020 us
50            preview_start: 353285 us
51            still_image_capture: 308166 us
52        """
53        try:
54            with open(log_file, 'r') as f:
55                camera_id = None
56                for line in f:
57                    key, value = line.split(':')
58                    if key == 'Camera':
59                        camera_id = value.strip()
60                    elif camera_id is not None:
61                        self._logperf(self.test_name,
62                                      'camera_%s_%s' % (camera_id, key),
63                                      value.strip().split(' ')[0],
64                                      value.strip().split(' ')[1])
65                    else:
66                        msg = 'Error in parsing the log file (%s)' % log_file
67                        raise error.TestFail(msg)
68        except IOError, err:
69            msg = 'Error in reading the log file (%s): %s' % (log_file, err)
70            raise error.TestFail(msg)
71
72    def setup(self):
73        """
74        Run common setup steps.
75        """
76        self.dep_dir = os.path.join(self.autodir, 'deps', self.dep)
77        self.job.setup_dep([self.dep])
78        logging.debug('mydep is at %s', self.dep_dir)
79
80    def run_once(self):
81        """
82        Entry point of this test.
83        """
84        self.job.install_pkg(self.dep, 'dep', self.dep_dir)
85        binary_path = os.path.join(self.dep_dir, 'bin', self.test_binary)
86        test_log_file = os.path.join(self.resultsdir, '%s_%s' %
87                                     (self.test_name, self.test_log_suffix))
88
89        with service_stopper.ServiceStopper([self.cros_camera_service]):
90            for hal in camera_utils.get_camera_hal_paths_for_test():
91                cmd = [
92                    binary_path,
93                    '--camera_hal_path=%s' % hal,
94                    ('--gtest_filter=Camera3StillCaptureTest/'
95                     'Camera3SimpleStillCaptureTest.PerformanceTest/*'),
96                    '--output_log=%s' % test_log_file
97                ]
98                cmd = ' '.join(map(utils.sh_quote_word, cmd))
99
100                ret = utils.system(
101                    cmd, timeout=self.timeout, ignore_status=True)
102                self._analyze_log(test_log_file)
103                if ret != 0:
104                    raise error.TestFail('Failed to execute command: %s' % cmd)
105