Jie Sun | c978162 | 2010-02-18 11:27:03 -0800 | [diff] [blame] | 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 | |
Heng-Ruey Hsu | 20854f5 | 2017-04-11 14:03:27 +0900 | [diff] [blame] | 5 | import logging |
| 6 | import os |
Eric Li | c4d8f4a | 2010-12-10 09:49:23 -0800 | [diff] [blame] | 7 | from autotest_lib.client.bin import test, utils |
| 8 | from autotest_lib.client.common_lib import error |
Hirokazu Honda | ff640a1 | 2018-03-20 18:59:40 +0900 | [diff] [blame] | 9 | from autotest_lib.client.cros.video import device_capability |
Jie Sun | c978162 | 2010-02-18 11:27:03 -0800 | [diff] [blame] | 10 | |
Jie Sun | c978162 | 2010-02-18 11:27:03 -0800 | [diff] [blame] | 11 | |
Rohit Makasana | a7fb6cf | 2013-12-26 16:50:36 -0800 | [diff] [blame] | 12 | class camera_V4L2(test.test): |
Jie Sun | c978162 | 2010-02-18 11:27:03 -0800 | [diff] [blame] | 13 | version = 1 |
Jie Sun | 54579e8 | 2010-02-23 12:35:04 -0800 | [diff] [blame] | 14 | preserve_srcdir = True |
Jie Sun | 54579e8 | 2010-02-23 12:35:04 -0800 | [diff] [blame] | 15 | |
Heng-Ruey Hsu | cfbecb1 | 2018-07-26 19:27:16 +0800 | [diff] [blame] | 16 | def run_once(self, capability=None, test_list=None): |
| 17 | if capability is not None: |
| 18 | device_capability.DeviceCapability().ensure_capability(capability) |
Heng-Ruey Hsu | 1e91928 | 2018-02-07 14:09:57 +0800 | [diff] [blame] | 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 | |
Shik Chen | df51609 | 2019-01-03 13:53:20 +0800 | [diff] [blame] | 24 | if test_list is None: |
| 25 | test_list = "halv3" if self.should_test_halv3() else "default" |
Heng-Ruey Hsu | e6e8024 | 2017-07-10 17:34:35 +0800 | [diff] [blame] | 26 | self.test_list = test_list |
Heng-Ruey Hsu | 1e91928 | 2018-02-07 14:09:57 +0800 | [diff] [blame] | 27 | |
Jie Sun | 54579e8 | 2010-02-23 12:35:04 -0800 | [diff] [blame] | 28 | self.find_video_capture_devices() |
Sameer Nanda | fc413a8 | 2010-03-10 15:16:04 -0800 | [diff] [blame] | 29 | |
Jie Sun | 54579e8 | 2010-02-23 12:35:04 -0800 | [diff] [blame] | 30 | for device in self.v4l2_devices: |
Shik Chen | 98e5298 | 2019-08-22 11:54:19 +0800 | [diff] [blame] | 31 | self.run_v4l2_test(device) |
Heng-Ruey Hsu | 80c5f56 | 2017-04-10 10:40:56 +0900 | [diff] [blame] | 32 | |
Shik Chen | df51609 | 2019-01-03 13:53:20 +0800 | [diff] [blame] | 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 | |
Jie Sun | 54579e8 | 2010-02-23 12:35:04 -0800 | [diff] [blame] | 38 | def find_video_capture_devices(self): |
Shik Chen | 1f10a90 | 2020-01-14 11:26:33 +0800 | [diff] [blame^] | 39 | cmd = ["media_v4l2_test", "--list_usbcam"] |
| 40 | stdout = utils.system_output(cmd, retain_output=True) |
| 41 | self.v4l2_devices = stdout.splitlines() |
Jie Sun | 54579e8 | 2010-02-23 12:35:04 -0800 | [diff] [blame] | 42 | if not self.v4l2_devices: |
Jie Sun | 07826db | 2010-04-30 11:39:17 -0700 | [diff] [blame] | 43 | raise error.TestFail("No V4L2 devices found!") |
Jie Sun | 54579e8 | 2010-02-23 12:35:04 -0800 | [diff] [blame] | 44 | |
Shik Chen | 98e5298 | 2019-08-22 11:54:19 +0800 | [diff] [blame] | 45 | def run_v4l2_test(self, device): |
Shik Chen | 4a48ea5 | 2019-07-03 19:08:36 +0800 | [diff] [blame] | 46 | cmd = [ |
| 47 | "media_v4l2_test", |
Shik Chen | 1aa6adc | 2019-08-14 11:58:44 +0800 | [diff] [blame] | 48 | "--device_path=%s" % device, |
Shik Chen | 4a48ea5 | 2019-07-03 19:08:36 +0800 | [diff] [blame] | 49 | ] |
Heng-Ruey Hsu | e6e8024 | 2017-07-10 17:34:35 +0800 | [diff] [blame] | 50 | if self.test_list: |
Shik Chen | 1aa6adc | 2019-08-14 11:58:44 +0800 | [diff] [blame] | 51 | cmd.append("--test_list=%s" % self.test_list) |
Heng-Ruey Hsu | 9b03f4d | 2018-01-16 17:05:38 +0800 | [diff] [blame] | 52 | |
Shik Chen | ca2507c | 2019-01-25 17:15:28 +0800 | [diff] [blame] | 53 | logging.info("Running %s", cmd) |
Heng-Ruey Hsu | 80c5f56 | 2017-04-10 10:40:56 +0900 | [diff] [blame] | 54 | stdout = utils.system_output(cmd, retain_output=True) |