From patchwork Fri Oct 25 21:32:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 2223 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8878761375 for ; Fri, 25 Oct 2019 23:33:07 +0200 (CEST) Received: from pendragon.ideasonboard.com (143.121.2.93.rev.sfr.net [93.2.121.143]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 0AF7C813 for ; Fri, 25 Oct 2019 23:33:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1572039187; bh=aJCNH2u5jO0bFjeNJYWHSM24201u2AkbphOSMmt40Ss=; h=From:To:Subject:Date:From; b=O/+hajqgJ7CDRExF2bZjzZnt9/AoyyJS+uREEh+BG9YwbzAWV8j18EeYgqvING4j6 vbv3d5/iq1MtXFFbEgr19msd9GS5HV2mrjtwTVScLKCnHsdagzMJZ681Y1FYnRqrA2 F5tEOfyTxKVGUxn2KXhoJrjVt/Gbsrc20lxAFVLk= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Sat, 26 Oct 2019 00:32:54 +0300 Message-Id: <20191025213255.2751-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/2] test: controls: Add ControlInfoMap test 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: , X-List-Received-Date: Fri, 25 Oct 2019 21:33:07 -0000 Add a test to exercise the ControlInfoMap API. This currently tests at(), count(), find() and end(). Signed-off-by: Laurent Pinchart --- test/controls/control_info.cpp | 102 +++++++++++++++++++++++++++++++++ test/controls/meson.build | 1 + 2 files changed, 103 insertions(+) create mode 100644 test/controls/control_info.cpp diff --git a/test/controls/control_info.cpp b/test/controls/control_info.cpp new file mode 100644 index 000000000000..f5ba1caec7bf --- /dev/null +++ b/test/controls/control_info.cpp @@ -0,0 +1,102 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2019, Google Inc. + * + * control_info.cpp - ControlInfoMap tests + */ + +#include + +#include +#include +#include +#include + +#include "camera_controls.h" +#include "test.h" + +using namespace std; +using namespace libcamera; + +class ControlInfoMapTest : public Test +{ +protected: + int init() + { + cm_ = new CameraManager(); + + if (cm_->start()) { + cout << "Failed to start camera manager" << endl; + return TestFail; + } + + camera_ = cm_->get("VIMC Sensor B"); + if (!camera_) { + cout << "Can not find VIMC camera" << endl; + return TestSkip; + } + + return TestPass; + } + + int run() + { + const ControlInfoMap &info = camera_->controls(); + + /* Test looking up a valid control by ControlId. */ + if (info.count(&controls::Brightness) != 1) { + cout << "count() on valid control failed" << endl; + return TestFail; + } + + if (info.find(&controls::Brightness) == info.end()) { + cout << "find() on valid control failed" << endl; + return TestFail; + } + + info.at(&controls::Brightness); + + /* Test looking up a valid control by numerical ID. */ + if (info.count(controls::Brightness.id()) != 1) { + cout << "count() on valid ID failed" << endl; + return TestFail; + } + + if (info.find(controls::Brightness.id()) == info.end()) { + cout << "find() on valid ID failed" << endl; + return TestFail; + } + + info.at(controls::Brightness.id()); + + /* Test looking up an invalid control by numerical ID. */ + if (info.count(12345) != 0) { + cout << "count() on invalid ID failed" << endl; + return TestFail; + } + + if (info.find(12345) != info.end()) { + cout << "find() on invalid ID failed" << endl; + return TestFail; + } + + return TestPass; + } + + void cleanup() + { + if (camera_) { + camera_->release(); + camera_.reset(); + } + + cm_->stop(); + delete cm_; + } + +private: + CameraManager *cm_; + std::shared_ptr camera_; +}; + +TEST_REGISTER(ControlInfoMapTest) diff --git a/test/controls/meson.build b/test/controls/meson.build index 9f0f005a2759..f0850df28c8a 100644 --- a/test/controls/meson.build +++ b/test/controls/meson.build @@ -1,4 +1,5 @@ control_tests = [ + [ 'control_info', 'control_info.cpp' ], [ 'control_list', 'control_list.cpp' ], [ 'control_range', 'control_range.cpp' ], [ 'control_value', 'control_value.cpp' ], From patchwork Fri Oct 25 21:32:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 2224 X-Patchwork-Delegate: laurent.pinchart@ideasonboard.com Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9BD5F614FF for ; Fri, 25 Oct 2019 23:33:07 +0200 (CEST) Received: from pendragon.ideasonboard.com (143.121.2.93.rev.sfr.net [93.2.121.143]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 3DE9099A for ; Fri, 25 Oct 2019 23:33:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1572039187; bh=Wb7kncZOf6ol9m4hG99xyRfJ9ENctf05jp1fANDSsJg=; h=From:To:Subject:Date:In-Reply-To:References:From; b=oI2kAF51mIzkrmsE/shiXej99/Liae0gDE6ahEe3BSMspQG1vdk8Krvn/dQx5RB3z DJoCJMru348kpTdbZqI8pPC9DwElkcUHD92tevQFK7f1bcF3hdlfC9RRN9fD+t4emQ QE2yb9jFrmjDO850pfBZ/zJtGpVNFLJn9h1SuvWs= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Sat, 26 Oct 2019 00:32:55 +0300 Message-Id: <20191025213255.2751-2-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191025213255.2751-1-laurent.pinchart@ideasonboard.com> References: <20191025213255.2751-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/2] libcamera: controls: Avoid exception in ControlList count() and find() 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: , X-List-Received-Date: Fri, 25 Oct 2019 21:33:07 -0000 The ControlList count() and find() methods use at() to lookup the control numerical ID in the idmap_. This causes an exception to be thrown if the ID doesn't exist in the map. Fix it by using the find() method instead. Signed-off-by: Laurent Pinchart --- src/libcamera/controls.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp index 93ad2fc6a276..0c7cd449ad64 100644 --- a/src/libcamera/controls.cpp +++ b/src/libcamera/controls.cpp @@ -491,7 +491,11 @@ const ControlInfoMap::mapped_type &ControlInfoMap::at(unsigned int id) const */ ControlInfoMap::size_type ControlInfoMap::count(unsigned int id) const { - return count(idmap_.at(id)); + auto iter = idmap_.find(id); + if (iter == idmap_.end()) + return 0; + + return count(iter->second); } /** @@ -502,7 +506,11 @@ ControlInfoMap::size_type ControlInfoMap::count(unsigned int id) const */ ControlInfoMap::iterator ControlInfoMap::find(unsigned int id) { - return find(idmap_.at(id)); + auto iter = idmap_.find(id); + if (iter == idmap_.end()) + return end(); + + return find(iter->second); } /** @@ -513,7 +521,11 @@ ControlInfoMap::iterator ControlInfoMap::find(unsigned int id) */ ControlInfoMap::const_iterator ControlInfoMap::find(unsigned int id) const { - return find(idmap_.at(id)); + auto iter = idmap_.find(id); + if (iter == idmap_.end()) + return end(); + + return find(iter->second); } /**