From patchwork Wed Oct 7 11:25:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 10012 X-Patchwork-Delegate: kieran.bingham@ideasonboard.com Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 679FEBEEDF for ; Wed, 7 Oct 2020 11:25:50 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A25AC605AB; Wed, 7 Oct 2020 13:25:49 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="gFBHBtoK"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E89EE60562 for ; Wed, 7 Oct 2020 13:25:47 +0200 (CEST) Received: from Q.local (cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 71A53BBE; Wed, 7 Oct 2020 13:25:47 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1602069947; bh=qfE3PsO0CDYHLxmO4vrhAHIzSfej8fdPY8Pi0ErdQZw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gFBHBtoKM+eiN+qnWH4kWKDPtWi6616qzn6lXq2uDNVDjN7S7/UMk5X8qNoDWDHTI hmRbGcGdCOPTJHVCI5Ul+DXf8289+3fndRmZiv82zQUrmwagPAODUT/m753nx3alHS Y9G/IQ4Y8M6CdbsRTsMdV3uYFfWcW5hVFBtsWB3E= From: Kieran Bingham To: libcamera devel Date: Wed, 7 Oct 2020 12:25:44 +0100 Message-Id: <20201007112544.3169293-2-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201007112544.3169293-1-kieran.bingham@ideasonboard.com> References: <20201007112544.3169293-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH 1/1] test: cam tool testing with valgrind X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Implement a test which runs cam to capture 10 frames, and validates there are no memory leaks with valgrind. Signed-off-by: Kieran Bingham --- A few points to consider here: Duration -------- Unfortuantely this test adds an extra 13 seconds to the test run on my system. We could reduce the duration of course, but it will still be a reasonably substantial addition. TAP --- This runs a test for mulitiple cameras, and meson now supports 'tap' format tests (multiple tests in one execution). In this patch - the 'protocol : "tap" is disabled, because meson doesn't like the output of the rest of the test being mixed with the tap output. I'm not sure of a good way to handle that. The output is useful, so we want it somewhere, and ideally in the test log - but we also want the tap parsing to work in that case too. Anyway, with the tap protocol disabled, it just falls back to the return status which is also handled here. Still, this is a good opportunity to see how 'tap' could help our tests, and might revive my old patches to use common test helpers across the rest of test/ Valgrind -------- Parsing valgrind is a real pain. This test *only* checks to see if there are any memory leaks, and does not report on any of the other topics valgirind might highlight. (They could be added later of course). Ideally we would want a machine parsable output from valgrind. It can output an xml report ... but ... that's a lot more parsing too ;-) Thoughts/Suggestions? https://github.com/adobe/chromium/blob/master/tools/valgrind/memcheck_analyze.py seems to show an existing tool that parses the valgrind output as one possible path - but I'm happy to hear of any better ideas too. test/cam/capture-test.sh | 71 ++++++++++++++++++++++++++++++++++++++++ test/cam/meson.build | 10 ++++++ test/meson.build | 1 + 3 files changed, 82 insertions(+) create mode 100755 test/cam/capture-test.sh create mode 100644 test/cam/meson.build diff --git a/test/cam/capture-test.sh b/test/cam/capture-test.sh new file mode 100755 index 000000000000..ab808976be72 --- /dev/null +++ b/test/cam/capture-test.sh @@ -0,0 +1,71 @@ +#!/bin/sh + +# SPDX-License-Identifier: GPL-2.0-or-later + +TestPass=0 +TestFail=255 +TestSkip=77 + +# Initialise success, set for failure. +ret=$TestPass + +ok() { + echo "ok $*" +} + +nok() { + echo "not ok $*" + ret=$TestFail +} + +valgrind=$(command -v valgrind) + +if [ x"" = x"$valgrind" ] ; then + echo "skip 1 - Valgrind unavailable ..." + exit $TestSkip +fi + +# Tests expect to be run from the meson.project_build_root() +cam=${1:-src/cam/cam} + +if [ ! -e "$cam" ] ; then + nok "1 - failed to find cam utility." + exit $TestFail +fi + +# Unfortunately, we don't have a 'machine interface', so we rely on parsing the +# output of cam... +num_cameras=$("$cam" -l | grep -v "Available" | wc -l) + +# Enter TAP plan +echo "1..$num_cameras" + +for i in $(seq 1 1 "$num_cameras"); +do + "$cam" -c "$i" -C10 + ret=$? + if [ $ret != 0 ] ; then + nok "$i - $cam returned $ret" + continue + fi + + log_file="valgrind-cam-$i.log" + "$valgrind" "$cam" -c "$i" -C10 > "$log_file" 2>&1 + ret=$? + if [ $ret != 0 ] ; then + nok "$i - $valgrind returned $ret" + continue + fi + + # I'd prefer a better way of checking there are no leaks, as well as reporting + # the different categories from valgrind as distinct tests. + if ! grep "no leaks are possible" "$log_file" > /dev/null; then + nok "$i - Valgrind Errors detected" + cat $log_file > /dev/stderr + continue + fi + + ok "$i - Camera $i reports no leaks" +done; + +exit $ret diff --git a/test/cam/meson.build b/test/cam/meson.build new file mode 100644 index 000000000000..834c9bcf6b86 --- /dev/null +++ b/test/cam/meson.build @@ -0,0 +1,10 @@ +# SPDX-License-Identifier: CC0-1.0 + +cam_capture = files('capture-test.sh') + +test('cam-capture-test', cam_capture, + args : cam, + suite : 'integration', + is_parallel : false, + #protocol : 'tap', + timeout : 60) diff --git a/test/meson.build b/test/meson.build index 0a1d434e3996..d1b24220dc7c 100644 --- a/test/meson.build +++ b/test/meson.build @@ -2,6 +2,7 @@ subdir('libtest') +subdir('cam') subdir('camera') subdir('controls') subdir('ipa')