• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2010 The Chromium OS 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
5import logging
6import os
7from autotest_lib.client.bin import test, utils
8from autotest_lib.client.common_lib import error
9from autotest_lib.client.cros.video import device_capability
10
11
12class camera_V4L2(test.test):
13    version = 1
14    preserve_srcdir = True
15
16    def run_once(self, capability=None, test_list=None):
17        if capability is not None:
18            device_capability.DeviceCapability().ensure_capability(capability)
19        # Enable USB camera HW timestamp
20        path = "/sys/module/uvcvideo/parameters/hwtimestamps"
21        if os.path.exists(path):
22            utils.system("echo 1 > %s" % path)
23
24        if test_list is None:
25            test_list = "halv3" if self.should_test_halv3() else "default"
26        self.test_list = test_list
27
28        self.find_video_capture_devices()
29
30        for device in self.v4l2_devices:
31            self.run_v4l2_test(device)
32
33    def should_test_halv3(self):
34        has_v3 = os.path.exists('/usr/bin/cros_camera_service')
35        has_v1 = os.path.exists('/usr/bin/arc_camera_service')
36        return has_v3 and not has_v1
37
38    def find_video_capture_devices(self):
39        cmd = ["media_v4l2_test", "--list_usbcam"]
40        stdout = utils.system_output(cmd, retain_output=True)
41        self.v4l2_devices = stdout.splitlines()
42        if not self.v4l2_devices:
43            raise error.TestFail("No V4L2 devices found!")
44
45    def run_v4l2_test(self, device):
46        cmd = [
47                "media_v4l2_test",
48                "--device_path=%s" % device,
49        ]
50        if self.test_list:
51            cmd.append("--test_list=%s" % self.test_list)
52
53        logging.info("Running %s", cmd)
54        stdout = utils.system_output(cmd, retain_output=True)
55