From patchwork Tue Jul 27 12:07:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 13129 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 49480C0109 for ; Tue, 27 Jul 2021 12:08:00 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A3656687C3; Tue, 27 Jul 2021 14:07:59 +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="q1HdKWfU"; dkim-atps=neutral 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 565FB60272 for ; Tue, 27 Jul 2021 14:07:58 +0200 (CEST) Received: from Monstersaurus.local (cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id DFC95EE; Tue, 27 Jul 2021 14:07:57 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1627387678; bh=fPi8kAdlNpPaDYcR73MWx0p0SdA38UWuCqiz87aD1HQ=; h=From:To:Cc:Subject:Date:From; b=q1HdKWfUZldw9Coo9gzWcGX0CCCo6yYICSOrRC5a6dprhtqrF36d9H/Ol9oXJObxV 1hLGrR8tf0zF8MO8AbXAjFZwiE5kZS4wB68rIr3/XgQMSCmrjGGkMriD3AtloQ8MAa Tn5IVJvEuWgMl8i/+IGHQcLbGs80ZBD21Oo30V8c= From: Kieran Bingham To: libcamera devel Date: Tue, 27 Jul 2021 13:07:54 +0100 Message-Id: <20210727120754.998501-1-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] test: CameraManager: Add start/stop tests 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" Validate the CameraManager can start, stop, and restart successfully, as well as highlight that we can not construct a second CameraManager without hitting assertions. Signed-off-by: Kieran Bingham --- This introduces some basic tests on the lifetime of the CameraManager. Integration is optional, but I'm posting to higlight the investigations I did on this yesterday. - We can successfully construct, use and destroy a CameraManager and then reconstruct a new one and use that too. - Construction of a CameraManager, with a start()/stop() cycle will not function using the same CameraManager if we try to re-start() the same instance. - Construction of two CameraManager instances causes a FATAL assertion though somewhat confusingly, it will face a FATAL assertion on the second IPAManager construction, before the second CameraManager gets to execute its constructor. test/camera-manager.cpp | 106 ++++++++++++++++++++++++++++++++++++++++ test/meson.build | 1 + 2 files changed, 107 insertions(+) create mode 100644 test/camera-manager.cpp diff --git a/test/camera-manager.cpp b/test/camera-manager.cpp new file mode 100644 index 000000000000..9e9c494af21c --- /dev/null +++ b/test/camera-manager.cpp @@ -0,0 +1,106 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2021, Google Inc. + * + * libcamera Camera Manager API tests + */ + +#include +#include + +#include +#include + +#include "test.h" + +using namespace libcamera; +using namespace std; + +class CameraManagerTest : public Test +{ +protected: + int validate() + { + std::shared_ptr camera; + + if (cm_->start()) { + cerr << "Failed to start camera manager" << endl; + return TestFail; + } + + if (cm_->cameras().size() <= 0) { + cerr << "No cameras available" << endl; + return TestFail; + } + + camera = cm_->cameras()[0]; + if (!camera) { + cerr << "Can not obtain a camera at index 0" << endl; + return TestFail; + } + + /* Store the camera id that we get */ + cameraId_ = camera->id(); + + return TestPass; + } + + int run() + { + std::string firstCamera; + + /* Construct and validate the CameraManager */ + cm_ = new CameraManager(); + if (validate()) { + cerr << "Failed first construction" << endl; + return TestFail; + } + + /* Get camera ID stored by validate */ + firstCamera = cameraId_; + + /* Now stop everything and reconstruct the CameraManager */ + cm_->stop(); + delete cm_; + + /* Restart and assert we can still get a camera */ + cm_ = new CameraManager(); + if (validate()) { + cerr << "Failed after re-construction" << endl; + return TestFail; + } + + if (firstCamera != cameraId_) { + cerr << "Expected to get the same camera after re-construction" << endl; + return TestFail; + } + + /* Test stop and start (without re-create) */ + cm_->stop(); + + /* validate will call start() */ + if (validate()) { + cerr << "Failed after re-starting CameraManager" << endl; + return TestFail; + } + + /* + * Creating a second camera manager is not permitted + * + * This will fail with a FATAL in constructing a second IPA + * Manager, even though we also have a FATAL in the + * CameraManager construction, but the CameraManager tries + * to construct an IPA manager, which fails before the + * CameraManager executes any of it's constructor. + */ + //CameraManager *cm2 = new CameraManager(); + + return TestPass; + } + +private: + CameraManager *cm_; + std::string cameraId_; +}; + +TEST_REGISTER(CameraManagerTest) diff --git a/test/meson.build b/test/meson.build index 2c3e76546fbc..cd23c07e1f16 100644 --- a/test/meson.build +++ b/test/meson.build @@ -24,6 +24,7 @@ subdir('v4l2_subdevice') subdir('v4l2_videodevice') public_tests = [ + ['camera-manager', 'camera-manager.cpp'], ['geometry', 'geometry.cpp'], ['public-api', 'public-api.cpp'], ['signal', 'signal.cpp'],