blob: 632570ab42ed279f475254dd2f2a3785c8a48b91 [file] [log] [blame]
Jie Sunc9781622010-02-18 11:27:03 -08001# 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 Hsu20854f52017-04-11 14:03:27 +09005import logging
6import os
Eric Lic4d8f4a2010-12-10 09:49:23 -08007from autotest_lib.client.bin import test, utils
8from autotest_lib.client.common_lib import error
Hirokazu Hondaff640a12018-03-20 18:59:40 +09009from autotest_lib.client.cros.video import device_capability
Jie Sunc9781622010-02-18 11:27:03 -080010
Jie Sunc9781622010-02-18 11:27:03 -080011
Rohit Makasanaa7fb6cf2013-12-26 16:50:36 -080012class camera_V4L2(test.test):
Jie Sunc9781622010-02-18 11:27:03 -080013 version = 1
Jie Sun54579e82010-02-23 12:35:04 -080014 preserve_srcdir = True
Jie Sun54579e82010-02-23 12:35:04 -080015
Heng-Ruey Hsucfbecb12018-07-26 19:27:16 +080016 def run_once(self, capability=None, test_list=None):
17 if capability is not None:
18 device_capability.DeviceCapability().ensure_capability(capability)
Heng-Ruey Hsu1e919282018-02-07 14:09:57 +080019 # 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 Chendf516092019-01-03 13:53:20 +080024 if test_list is None:
25 test_list = "halv3" if self.should_test_halv3() else "default"
Heng-Ruey Hsue6e80242017-07-10 17:34:35 +080026 self.test_list = test_list
Heng-Ruey Hsu1e919282018-02-07 14:09:57 +080027
Jie Sun54579e82010-02-23 12:35:04 -080028 self.find_video_capture_devices()
Sameer Nandafc413a82010-03-10 15:16:04 -080029
Jie Sun54579e82010-02-23 12:35:04 -080030 for device in self.v4l2_devices:
Shik Chen98e52982019-08-22 11:54:19 +080031 self.run_v4l2_test(device)
Heng-Ruey Hsu80c5f562017-04-10 10:40:56 +090032
Shik Chendf516092019-01-03 13:53:20 +080033 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 Sun54579e82010-02-23 12:35:04 -080038 def find_video_capture_devices(self):
Shik Chen1f10a902020-01-14 11:26:33 +080039 cmd = ["media_v4l2_test", "--list_usbcam"]
40 stdout = utils.system_output(cmd, retain_output=True)
41 self.v4l2_devices = stdout.splitlines()
Jie Sun54579e82010-02-23 12:35:04 -080042 if not self.v4l2_devices:
Jie Sun07826db2010-04-30 11:39:17 -070043 raise error.TestFail("No V4L2 devices found!")
Jie Sun54579e82010-02-23 12:35:04 -080044
Shik Chen98e52982019-08-22 11:54:19 +080045 def run_v4l2_test(self, device):
Shik Chen4a48ea52019-07-03 19:08:36 +080046 cmd = [
47 "media_v4l2_test",
Shik Chen1aa6adc2019-08-14 11:58:44 +080048 "--device_path=%s" % device,
Shik Chen4a48ea52019-07-03 19:08:36 +080049 ]
Heng-Ruey Hsue6e80242017-07-10 17:34:35 +080050 if self.test_list:
Shik Chen1aa6adc2019-08-14 11:58:44 +080051 cmd.append("--test_list=%s" % self.test_list)
Heng-Ruey Hsu9b03f4d2018-01-16 17:05:38 +080052
Shik Chenca2507c2019-01-25 17:15:28 +080053 logging.info("Running %s", cmd)
Heng-Ruey Hsu80c5f562017-04-10 10:40:56 +090054 stdout = utils.system_output(cmd, retain_output=True)