{"id":8738,"url":"https://patchwork.libcamera.org/api/patches/8738/?format=json","web_url":"https://patchwork.libcamera.org/patch/8738/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20200709132835.112593-24-paul.elder@ideasonboard.com>","date":"2020-07-09T13:28:35","name":"[libcamera-devel,v5,23/23] tests: v4l2_compat: Add test for v4l2_compat","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"458f310c447aef668b2fe31de7ce354452672fec","submitter":{"id":17,"url":"https://patchwork.libcamera.org/api/people/17/?format=json","name":"Paul Elder","email":"paul.elder@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/8738/mbox/","series":[{"id":1093,"url":"https://patchwork.libcamera.org/api/series/1093/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1093","date":"2020-07-09T13:28:12","name":"Clean up formats in v4l2-compat and pipeline handlers","version":5,"mbox":"https://patchwork.libcamera.org/series/1093/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/8738/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/8738/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 83816BD792\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  9 Jul 2020 13:29:48 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 51121611BA;\n\tThu,  9 Jul 2020 15:29:48 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id C163E611B2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  9 Jul 2020 15:29:46 +0200 (CEST)","from pyrite.rasen.tech (unknown\n\t[IPv6:2400:4051:61:600:2c71:1b79:d06d:5032])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id EB49E525;\n\tThu,  9 Jul 2020 15:29:44 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"qVeLRk4l\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1594301386;\n\tbh=snaqUun6n9obVuM8zCpQZ8/093P7lRU+gTulHWcuI/8=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=qVeLRk4lVqnYuV1ycvCVXUsPumnw+fDk795OjRTeswd/h9cDyK0V7rSmSQLScqMCG\n\taYFoHzvcdKUoOHw64prleQscXi6lmjeAuCKUhpMzZQACvyl/WlxypvZaxGhvdtzXK7\n\tCKdJ6E5CfukhhnYqsbJ7VrqZkFfuygU95Vp3P0O8=","From":"Paul Elder <paul.elder@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Thu,  9 Jul 2020 22:28:35 +0900","Message-Id":"<20200709132835.112593-24-paul.elder@ideasonboard.com>","X-Mailer":"git-send-email 2.27.0","In-Reply-To":"<20200709132835.112593-1-paul.elder@ideasonboard.com>","References":"<20200709132835.112593-1-paul.elder@ideasonboard.com>","MIME-Version":"1.0","Subject":"[libcamera-devel] [PATCH v5 23/23] tests: v4l2_compat: Add test for\n\tv4l2_compat","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Test the V4L2 compatibility layer by running v4l2-compliance -s on every\n/dev/video* device.\n\nSigned-off-by: Paul Elder <paul.elder@ideasonboard.com>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n---\nChanges in v5\n- add raspi to supported pipelines\n\nChanges in v4:\n- fail the test if v4l2-ctl fails (for example, if libcamera dies\n  fatally)\n\nChanges in v3:\n- use argparse\n- add argument to test all cameras, and test only one camera per driver\n  by default\n- print the devices that we're testing and if each succeeded or failed\n\nChanges in v2:\n- change all strings to single-quote\n- simplify meson.build\n- get path to v4l2-compat.so from cli arg, rather than running custom find()\n  - remove find_file()\n- extend test timeout to 60 seconds (from default of 30)\n- don't run v4l2-compliance subprocesses in shell\n- check if v4l2-compliance runs are killed by signal (eg. the known\n  SIGABRT due to floating point exception)\n- move the check to see if libcamera supports the camera to v4l2-ctl\n  instead of v4l2-compliance (in v1 we only checked if the pipeline was\n  supported with v4l2-ctl)\n---\n test/meson.build                     |   1 +\n test/v4l2_compat/meson.build         |  10 ++\n test/v4l2_compat/v4l2_compat_test.py | 152 +++++++++++++++++++++++++++\n 3 files changed, 163 insertions(+)\n create mode 100644 test/v4l2_compat/meson.build\n create mode 100755 test/v4l2_compat/v4l2_compat_test.py","diff":"diff --git a/test/meson.build b/test/meson.build\nindex 7808a26..f41d6e7 100644\n--- a/test/meson.build\n+++ b/test/meson.build\n@@ -12,6 +12,7 @@ subdir('pipeline')\n subdir('process')\n subdir('serialization')\n subdir('stream')\n+subdir('v4l2_compat')\n subdir('v4l2_subdevice')\n subdir('v4l2_videodevice')\n \ndiff --git a/test/v4l2_compat/meson.build b/test/v4l2_compat/meson.build\nnew file mode 100644\nindex 0000000..5b29de7\n--- /dev/null\n+++ b/test/v4l2_compat/meson.build\n@@ -0,0 +1,10 @@\n+# SPDX-License-Identifier: CC0-1.0\n+\n+if is_variable('v4l2_compat')\n+    v4l2_compat_test = files('v4l2_compat_test.py')\n+\n+    test('v4l2_compat_test', v4l2_compat_test,\n+         args : v4l2_compat,\n+         suite : 'v4l2_compat',\n+         timeout : 60)\n+endif\ndiff --git a/test/v4l2_compat/v4l2_compat_test.py b/test/v4l2_compat/v4l2_compat_test.py\nnew file mode 100755\nindex 0000000..99b3d5a\n--- /dev/null\n+++ b/test/v4l2_compat/v4l2_compat_test.py\n@@ -0,0 +1,152 @@\n+#!/usr/bin/env python3\n+# SPDX-License-Identifier: GPL-2.0-or-later\n+# Copyright (C) 2020, Google Inc.\n+#\n+# Author: Paul Elder <paul.elder@ideasonboard.com>\n+#\n+# v4l2_compat_test.py - Test the V4L2 compatibility layer\n+\n+import argparse\n+import glob\n+import os\n+import re\n+import shutil\n+import signal\n+import subprocess\n+import sys\n+\n+TestPass = 0\n+TestFail = -1\n+TestSkip = 77\n+\n+\n+supported_pipelines = [\n+    'bcm2835-isp',\n+    'uvcvideo',\n+    'vimc',\n+]\n+\n+\n+def grep(exp, arr):\n+    return [s for s in arr if re.search(exp, s)]\n+\n+\n+def run_with_stdout(*args, env={}):\n+    try:\n+        with open(os.devnull, 'w') as devnull:\n+            output = subprocess.check_output(args, env=env, stderr=devnull)\n+        ret = 0\n+    except subprocess.CalledProcessError as err:\n+        output = err.output\n+        ret = err.returncode\n+    return ret, output.decode('utf-8').split('\\n')\n+\n+\n+def extract_result(result):\n+    res = result.split(', ')\n+    ret = {}\n+    ret['total']     = int(res[0].split(': ')[-1])\n+    ret['succeeded'] = int(res[1].split(': ')[-1])\n+    ret['failed']    = int(res[2].split(': ')[-1])\n+    ret['warnings']  = int(res[3].split(': ')[-1])\n+    ret['device']    = res[0].split()[4].strip(':')\n+    ret['driver']    = res[0].split()[2]\n+    return ret\n+\n+\n+def print_output_arr(output_arr):\n+    print('\\n'.join(output_arr))\n+\n+\n+def test_v4l2_compliance(v4l2_compliance, v4l2_compat, device, base_driver):\n+    ret, output = run_with_stdout(v4l2_compliance, '-s', '-d', device, env={'LD_PRELOAD': v4l2_compat})\n+    if ret < 0:\n+        print_output_arr(output)\n+        print(f'Test for {device} terminated due to signal {signal.Signals(-ret).name}')\n+        return TestFail\n+\n+    result = extract_result(output[-2])\n+    if result['failed'] == 0:\n+        return TestPass\n+\n+    # vimc will fail s_fmt because it only supports framesizes that are\n+    # multiples of 3\n+    if base_driver == 'vimc' and result['failed'] == 1:\n+        failures = grep('fail', output)\n+        if re.search('S_FMT cannot handle an invalid format', failures[0]) is None:\n+            print_output_arr(output)\n+            return TestFail\n+        return TestPass\n+\n+    print_output_arr(output)\n+    return TestFail\n+\n+\n+def main(argv):\n+    parser = argparse.ArgumentParser()\n+    parser.add_argument('-a', '--all', action='store_true',\n+                        help='Test all available cameras')\n+    parser.add_argument('v4l2_compat', type=str,\n+                        help='Path to v4l2-compat.so')\n+    args = parser.parse_args(argv[1:])\n+\n+    v4l2_compat = args.v4l2_compat\n+\n+    v4l2_compliance = shutil.which('v4l2-compliance')\n+    if v4l2_compliance is None:\n+        print('v4l2-compliance is not available')\n+        return TestSkip\n+\n+    v4l2_ctl = shutil.which('v4l2-ctl')\n+    if v4l2_ctl is None:\n+        print('v4l2-ctl is not available')\n+        return TestSkip\n+\n+    dev_nodes = glob.glob('/dev/video*')\n+    if len(dev_nodes) == 0:\n+        print('no video nodes available to test with')\n+        return TestSkip\n+\n+    failed = []\n+    drivers_tested = {}\n+    for device in dev_nodes:\n+        ret, out = run_with_stdout(v4l2_ctl, '-D', '-d', device, env={'LD_PRELOAD': v4l2_compat})\n+        if ret < 0:\n+            failed.append(device)\n+            print(f'v4l2-ctl failed on {device} with v4l2-compat')\n+            continue\n+        driver = grep('Driver name', out)[0].split(':')[-1].strip()\n+        if driver != \"libcamera\":\n+            continue\n+\n+        ret, out = run_with_stdout(v4l2_ctl, '-D', '-d', device)\n+        if ret < 0:\n+            failed.append(device)\n+            print(f'v4l2-ctl failed on {device} without v4l2-compat')\n+            continue\n+        driver = grep('Driver name', out)[0].split(':')[-1].strip()\n+        if driver not in supported_pipelines:\n+            continue\n+\n+        if not args.all and driver in drivers_tested:\n+            continue\n+\n+        print(f'Testing {device} with {driver} driver... ', end='')\n+        ret = test_v4l2_compliance(v4l2_compliance, v4l2_compat, device, driver)\n+        if ret == TestFail:\n+            failed.append(device)\n+            print('failed')\n+        else:\n+            print('success')\n+        drivers_tested[driver] = True\n+\n+    if len(failed) > 0:\n+        print(f'Failed {len(failed)} tests:')\n+        for device in failed:\n+            print(f'- {device}')\n+\n+    return TestPass if not failed else TestFail\n+\n+\n+if __name__ == '__main__':\n+    sys.exit(main(sys.argv))\n","prefixes":["libcamera-devel","v5","23/23"]}