{"id":13129,"url":"https://patchwork.libcamera.org/api/1.1/patches/13129/?format=json","web_url":"https://patchwork.libcamera.org/patch/13129/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/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":"<20210727120754.998501-1-kieran.bingham@ideasonboard.com>","date":"2021-07-27T12:07:54","name":"[libcamera-devel] test: CameraManager: Add start/stop tests","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"62f4591b808ecf9b70abac294ab24d5279d6f6dd","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/1.1/people/4/?format=json","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"delegate":{"id":11,"url":"https://patchwork.libcamera.org/api/1.1/users/11/?format=json","username":"kbingham","first_name":"Kieran","last_name":"Bingham","email":"kieran.bingham@ideasonboard.com"},"mbox":"https://patchwork.libcamera.org/patch/13129/mbox/","series":[{"id":2283,"url":"https://patchwork.libcamera.org/api/1.1/series/2283/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2283","date":"2021-07-27T12:07:54","name":"[libcamera-devel] test: CameraManager: Add start/stop tests","version":1,"mbox":"https://patchwork.libcamera.org/series/2283/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/13129/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/13129/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 49480C0109\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 27 Jul 2021 12:08:00 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id A3656687C3;\n\tTue, 27 Jul 2021 14:07:59 +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 565FB60272\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 27 Jul 2021 14:07:58 +0200 (CEST)","from Monstersaurus.local\n\t(cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id DFC95EE;\n\tTue, 27 Jul 2021 14:07:57 +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=\"q1HdKWfU\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1627387678;\n\tbh=fPi8kAdlNpPaDYcR73MWx0p0SdA38UWuCqiz87aD1HQ=;\n\th=From:To:Cc:Subject:Date:From;\n\tb=q1HdKWfUZldw9Coo9gzWcGX0CCCo6yYICSOrRC5a6dprhtqrF36d9H/Ol9oXJObxV\n\t1hLGrR8tf0zF8MO8AbXAjFZwiE5kZS4wB68rIr3/XgQMSCmrjGGkMriD3AtloQ8MAa\n\tTn5IVJvEuWgMl8i/+IGHQcLbGs80ZBD21Oo30V8c=","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","To":"libcamera devel <libcamera-devel@lists.libcamera.org>","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","Content-Transfer-Encoding":"8bit","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":"<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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Validate the CameraManager can start, stop, and restart successfully, as\nwell as highlight that we can not construct a second CameraManager\nwithout hitting assertions.\n\nSigned-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n---\nThis introduces some basic tests on the lifetime of the CameraManager.\n\nIntegration is optional, but I'm posting to higlight the investigations\nI did on this yesterday.\n\n - We can successfully construct, use and destroy a CameraManager\n   and then reconstruct a new one and use that too.\n\n - Construction of a CameraManager, with a start()/stop() cycle will\n   not function using the same CameraManager if we try to re-start()\n   the same instance.\n\n - Construction of two CameraManager instances causes a FATAL assertion\n   though somewhat confusingly, it will face a FATAL assertion on the\n   second IPAManager construction, before the second CameraManager gets\n   to execute its constructor.\n\n\n test/camera-manager.cpp | 106 ++++++++++++++++++++++++++++++++++++++++\n test/meson.build        |   1 +\n 2 files changed, 107 insertions(+)\n create mode 100644 test/camera-manager.cpp","diff":"diff --git a/test/camera-manager.cpp b/test/camera-manager.cpp\nnew file mode 100644\nindex 000000000000..9e9c494af21c\n--- /dev/null\n+++ b/test/camera-manager.cpp\n@@ -0,0 +1,106 @@\n+/* SPDX-License-Identifier: GPL-2.0-or-later */\n+/*\n+ * Copyright (C) 2021, Google Inc.\n+ *\n+ * libcamera Camera Manager API tests\n+ */\n+\n+#include <iostream>\n+#include <memory>\n+\n+#include <libcamera/camera.h>\n+#include <libcamera/camera_manager.h>\n+\n+#include \"test.h\"\n+\n+using namespace libcamera;\n+using namespace std;\n+\n+class CameraManagerTest : public Test\n+{\n+protected:\n+\tint validate()\n+\t{\n+\t\tstd::shared_ptr<Camera> camera;\n+\n+\t\tif (cm_->start()) {\n+\t\t\tcerr << \"Failed to start camera manager\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\tif (cm_->cameras().size() <= 0) {\n+\t\t\tcerr << \"No cameras available\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\tcamera = cm_->cameras()[0];\n+\t\tif (!camera) {\n+\t\t\tcerr << \"Can not obtain a camera at index 0\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\t/* Store the camera id that we get */\n+\t\tcameraId_ = camera->id();\n+\n+\t\treturn TestPass;\n+\t}\n+\n+\tint run()\n+\t{\n+\t\tstd::string firstCamera;\n+\n+\t\t/* Construct and validate the CameraManager */\n+\t\tcm_ = new CameraManager();\n+\t\tif (validate()) {\n+\t\t\tcerr << \"Failed first construction\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\t/* Get camera ID stored by validate */\n+\t\tfirstCamera = cameraId_;\n+\n+\t\t/* Now stop everything and reconstruct the CameraManager */\n+\t\tcm_->stop();\n+\t\tdelete cm_;\n+\n+\t\t/* Restart and assert we can still get a camera */\n+\t\tcm_ = new CameraManager();\n+\t\tif (validate()) {\n+\t\t\tcerr << \"Failed after re-construction\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\tif (firstCamera != cameraId_) {\n+\t\t\tcerr << \"Expected to get the same camera after re-construction\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\t/* Test stop and start (without re-create) */\n+\t\tcm_->stop();\n+\n+\t\t/* validate will call start() */\n+\t\tif (validate()) {\n+\t\t\tcerr << \"Failed after re-starting CameraManager\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\t/*\n+\t\t * Creating a second camera manager is not permitted\n+\t\t *\n+\t\t * This will fail with a FATAL in constructing a second IPA\n+\t\t * Manager, even though we also have a FATAL in the\n+\t\t * CameraManager construction, but the CameraManager tries\n+\t\t * to construct an IPA manager, which fails before the\n+\t\t * CameraManager executes any of it's constructor.\n+\t\t */\n+\t\t//CameraManager *cm2 = new CameraManager();\n+\n+\t\treturn TestPass;\n+\t}\n+\n+private:\n+\tCameraManager *cm_;\n+\tstd::string cameraId_;\n+};\n+\n+TEST_REGISTER(CameraManagerTest)\ndiff --git a/test/meson.build b/test/meson.build\nindex 2c3e76546fbc..cd23c07e1f16 100644\n--- a/test/meson.build\n+++ b/test/meson.build\n@@ -24,6 +24,7 @@ subdir('v4l2_subdevice')\n subdir('v4l2_videodevice')\n \n public_tests = [\n+    ['camera-manager',                  'camera-manager.cpp'],\n     ['geometry',                        'geometry.cpp'],\n     ['public-api',                      'public-api.cpp'],\n     ['signal',                          'signal.cpp'],\n","prefixes":["libcamera-devel"]}