[{"id":18388,"web_url":"https://patchwork.libcamera.org/comment/18388/","msgid":"<YQBJQI1hD5XAs/Q9@pendragon.ideasonboard.com>","date":"2021-07-27T17:58:24","subject":"Re: [libcamera-devel] [PATCH] test: CameraManager: Add start/stop\n\ttests","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Kieran,\n\nThank you for the patch.\n\nOn Tue, Jul 27, 2021 at 01:07:54PM +0100, Kieran Bingham wrote:\n> Validate the CameraManager can start, stop, and restart successfully, as\n> well as highlight that we can not construct a second CameraManager\n> without hitting assertions.\n> \n> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> ---\n> This introduces some basic tests on the lifetime of the CameraManager.\n> \n> Integration is optional, but I'm posting to higlight the investigations\n> I 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\nThat's not expected, and should be fixed.\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\nThis part I'd keep out of the test, as it's an API limitation.\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\n> \n> diff --git a/test/camera-manager.cpp b/test/camera-manager.cpp\n> new file mode 100644\n> index 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\nThere's no guarantee that cameras will be presented in the same order,\nwe only guarantee camera ID stability. Assuming no camera is plugged or\nunplugged while the test is running, which I think is a fair assumption,\nbut should be documeted in a comment here, you could store all the\ncamera IDs in a std::set and compare the two sets.\n\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\nAh, you keep it out :-) We could keep it commented out, but I'm not sure\nwhat value it brings. As an out-of-tree patch, to support work on\naddressing the assertion in the IPA manager constructor, it's useful,\nbut I'm not sure I'd merge it.\n\nYou're leaking cm_ here. I'd store it in a std::unique_ptr<>.\n\n> +\n> +\t\treturn TestPass;\n> +\t}\n> +\n> +private:\n> +\tCameraManager *cm_;\n> +\tstd::string cameraId_;\n> +};\n> +\n> +TEST_REGISTER(CameraManagerTest)\n> diff --git a/test/meson.build b/test/meson.build\n> index 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\nI would have put this in test/camera/\n\n>      ['geometry',                        'geometry.cpp'],\n>      ['public-api',                      'public-api.cpp'],\n>      ['signal',                          'signal.cpp'],","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 3A3BAC322C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 27 Jul 2021 17:58:33 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 9E814687C4;\n\tTue, 27 Jul 2021 19:58:32 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D639360272\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 27 Jul 2021 19:58:30 +0200 (CEST)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 59365EE;\n\tTue, 27 Jul 2021 19:58:30 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"LKMh2DVq\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1627408710;\n\tbh=nfdxasZQAeJxU4ClyPD8+2WYN1/TLrtJHD986bBMdnE=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=LKMh2DVqPWTy369TY2eC0dpZAKGnMOymi5vEFcqE21Tx20WO8qM+KhJHRHT1QQ5Um\n\tTTEsm5ZiMsNYPzylEmL1mHMr//w58ilmBQ9XtZRwMrWo2xGxn/TThYtsApyI1RH1aY\n\tJxNkNOlInRbK9JE4eUuvdcOuzsmlz/YkxKNsoWIE=","Date":"Tue, 27 Jul 2021 20:58:24 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Message-ID":"<YQBJQI1hD5XAs/Q9@pendragon.ideasonboard.com>","References":"<20210727120754.998501-1-kieran.bingham@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20210727120754.998501-1-kieran.bingham@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH] test: CameraManager: Add start/stop\n\ttests","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>","Cc":"libcamera devel <libcamera-devel@lists.libcamera.org>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":18405,"web_url":"https://patchwork.libcamera.org/comment/18405/","msgid":"<375b460b-f1c9-b4b5-d8b9-67b9a51d44db@ideasonboard.com>","date":"2021-07-28T11:17:14","subject":"Re: [libcamera-devel] [PATCH] test: CameraManager: Add start/stop\n\ttests","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Hi Laurent,\n\nOn 27/07/2021 18:58, Laurent Pinchart wrote:\n> Hi Kieran,\n> \n> Thank you for the patch.\n> \n> On Tue, Jul 27, 2021 at 01:07:54PM +0100, Kieran Bingham wrote:\n>> Validate the CameraManager can start, stop, and restart successfully, as\n>> well as highlight that we can not construct a second CameraManager\n>> without hitting assertions.\n>>\n>> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n>> ---\n>> This introduces some basic tests on the lifetime of the CameraManager.\n>>\n>> Integration is optional, but I'm posting to higlight the investigations\n>> I 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> That's not expected, and should be fixed.\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> This part I'd keep out of the test, as it's an API limitation.\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\n>>\n>> diff --git a/test/camera-manager.cpp b/test/camera-manager.cpp\n>> new file mode 100644\n>> index 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> There's no guarantee that cameras will be presented in the same order,\n> we only guarantee camera ID stability. Assuming no camera is plugged or\n> unplugged while the test is running, which I think is a fair assumption,\n> but should be documeted in a comment here, you could store all the\n> camera IDs in a std::set and compare the two sets.\n\nThe aim was mostly to be sure I interacted with the CameraManager and\ncould see that it was working - which was what highlighted the\nstart/stop/start issue.\n\nIf we assume the cameras shouldn't change, a set does make sense, so I\ncan look at that ... if ...\n\n\n> \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> Ah, you keep it out :-) We could keep it commented out, but I'm not sure\n> what value it brings. As an out-of-tree patch, to support work on\n\nCertainly helpful to easily highlight the IPA manager issue.\n\nBut I quite like that it shows in the tests what is and isn't\npossible/expected, much like you have other tests that show expected\ncompilation failure, though I guess this shows an expected runtime failure.\n\nIt's a shame we can't test that something is expected to fire an assert?\n\n\n> addressing the assertion in the IPA manager constructor, it's useful,\n> but I'm not sure I'd merge it.\n> \n> You're leaking cm_ here. I'd store it in a std::unique_ptr<>.\n\nYes, that's worth doing.\n\nI wonder if we should recommend that in the other usages.\n\nFor example the application developer guide just stores the pointer.\n(I now have a local patch to submit later to fix this)\n\n\n>> +\n>> +\t\treturn TestPass;\n>> +\t}\n>> +\n>> +private:\n>> +\tCameraManager *cm_;\n>> +\tstd::string cameraId_;\n>> +};\n>> +\n>> +TEST_REGISTER(CameraManagerTest)\n>> diff --git a/test/meson.build b/test/meson.build\n>> index 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> \n> I would have put this in test/camera/\n\nOk.\n\n> \n>>      ['geometry',                        'geometry.cpp'],\n>>      ['public-api',                      'public-api.cpp'],\n>>      ['signal',                          'signal.cpp'],\n>","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 98672C322E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 28 Jul 2021 11:17:19 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 07E39687BC;\n\tWed, 28 Jul 2021 13:17:19 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 1E88760506\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 28 Jul 2021 13:17:17 +0200 (CEST)","from [192.168.0.20]\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 9CBA73F;\n\tWed, 28 Jul 2021 13:17:16 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"YP0lF7xt\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1627471036;\n\tbh=vp8K1p4QMGVY//wopfTvQ0f23Bkc1I8YOcpAh0VQ6YM=;\n\th=From:To:Cc:References:Subject:Date:In-Reply-To:From;\n\tb=YP0lF7xtN7whpx6b9lav+r4GOsum1fhU4q3bLSrd+kVivw+XUTatZ2XyRCsYHcHRy\n\tCVdb9+s43oTb/K/XZW7lWvNnP5ZO6m6bCQ/rF5g9sR3eP8txadydJBTVu/ZuRSnNSx\n\tmqLkTTFkZo8nhJKmbR0uvIHCz/sggDrp9skqu3uI=","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","References":"<20210727120754.998501-1-kieran.bingham@ideasonboard.com>\n\t<YQBJQI1hD5XAs/Q9@pendragon.ideasonboard.com>","Message-ID":"<375b460b-f1c9-b4b5-d8b9-67b9a51d44db@ideasonboard.com>","Date":"Wed, 28 Jul 2021 12:17:14 +0100","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101\n\tThunderbird/78.11.0","MIME-Version":"1.0","In-Reply-To":"<YQBJQI1hD5XAs/Q9@pendragon.ideasonboard.com>","Content-Type":"text/plain; charset=utf-8","Content-Language":"en-GB","Content-Transfer-Encoding":"8bit","Subject":"Re: [libcamera-devel] [PATCH] test: CameraManager: Add start/stop\n\ttests","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>","Cc":"libcamera devel <libcamera-devel@lists.libcamera.org>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":18407,"web_url":"https://patchwork.libcamera.org/comment/18407/","msgid":"<YQFAo8g4Yaa9+Aq/@pendragon.ideasonboard.com>","date":"2021-07-28T11:33:55","subject":"Re: [libcamera-devel] [PATCH] test: CameraManager: Add start/stop\n\ttests","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Kieran,\n\nOn Wed, Jul 28, 2021 at 12:17:14PM +0100, Kieran Bingham wrote:\n> On 27/07/2021 18:58, Laurent Pinchart wrote:\n> > On Tue, Jul 27, 2021 at 01:07:54PM +0100, Kieran Bingham wrote:\n> >> Validate the CameraManager can start, stop, and restart successfully, as\n> >> well as highlight that we can not construct a second CameraManager\n> >> without hitting assertions.\n> >>\n> >> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> >> ---\n> >> This introduces some basic tests on the lifetime of the CameraManager.\n> >>\n> >> Integration is optional, but I'm posting to higlight the investigations\n> >> I 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> > That's not expected, and should be fixed.\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> > This part I'd keep out of the test, as it's an API limitation.\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\n> >>\n> >> diff --git a/test/camera-manager.cpp b/test/camera-manager.cpp\n> >> new file mode 100644\n> >> index 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> > There's no guarantee that cameras will be presented in the same order,\n> > we only guarantee camera ID stability. Assuming no camera is plugged or\n> > unplugged while the test is running, which I think is a fair assumption,\n> > but should be documeted in a comment here, you could store all the\n> > camera IDs in a std::set and compare the two sets.\n> \n> The aim was mostly to be sure I interacted with the CameraManager and\n> could see that it was working - which was what highlighted the\n> start/stop/start issue.\n\nSure, but the test as done today may fail as there's no guarantee on the\nordering, that part needs to be fixed to avoid false positives.\n\n> If we assume the cameras shouldn't change, a set does make sense, so I\n> can look at that ... if ...\n> \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> > Ah, you keep it out :-) We could keep it commented out, but I'm not sure\n> > what value it brings. As an out-of-tree patch, to support work on\n> \n> Certainly helpful to easily highlight the IPA manager issue.\n> \n> But I quite like that it shows in the tests what is and isn't\n> possible/expected, much like you have other tests that show expected\n> compilation failure, though I guess this shows an expected runtime failure.\n> \n> It's a shame we can't test that something is expected to fire an assert?\n\nIf we really wanted to I think we could, by wrapping the test in another\nprocess, but it will be quite a bit of work.\n\nIf you want to keep the above, let's just fix the comment style with\n/* ... */ instead of //.\n\n> > addressing the assertion in the IPA manager constructor, it's useful,\n> > but I'm not sure I'd merge it.\n> > \n> > You're leaking cm_ here. I'd store it in a std::unique_ptr<>.\n> \n> Yes, that's worth doing.\n> \n> I wonder if we should recommend that in the other usages.\n> \n> For example the application developer guide just stores the pointer.\n> (I now have a local patch to submit later to fix this)\n\nYes I think that's good practice.\n\n> >> +\n> >> +\t\treturn TestPass;\n> >> +\t}\n> >> +\n> >> +private:\n> >> +\tCameraManager *cm_;\n> >> +\tstd::string cameraId_;\n> >> +};\n> >> +\n> >> +TEST_REGISTER(CameraManagerTest)\n> >> diff --git a/test/meson.build b/test/meson.build\n> >> index 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> > \n> > I would have put this in test/camera/\n> \n> Ok.\n> \n> > \n> >>      ['geometry',                        'geometry.cpp'],\n> >>      ['public-api',                      'public-api.cpp'],\n> >>      ['signal',                          'signal.cpp'],","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 F385CC322E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 28 Jul 2021 11:34:03 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5B66D687BE;\n\tWed, 28 Jul 2021 13:34:03 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 33B8160506\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 28 Jul 2021 13:34:02 +0200 (CEST)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 9F3893F;\n\tWed, 28 Jul 2021 13:34:01 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"WWgPkiwS\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1627472041;\n\tbh=jFPHWCvTmaAB0xm7l9HsDgWHmU90m/N95Z3wdKliRyg=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=WWgPkiwSQ/YImCVFcnD2XQmDxAtwVyUlfLcpq+QtXt0LOlJcDfdlBQByiLthReNkp\n\tCbYNdVFoR3N78G6kjUKCl7xp6F7sT7NyNqRUCTsXCVGoihC4HdAGgkAAp3WHz1/Ne8\n\tY0GOvRLM73scysEPfp0PwhFQQLdvHzOjw/QbpjSQ=","Date":"Wed, 28 Jul 2021 14:33:55 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Message-ID":"<YQFAo8g4Yaa9+Aq/@pendragon.ideasonboard.com>","References":"<20210727120754.998501-1-kieran.bingham@ideasonboard.com>\n\t<YQBJQI1hD5XAs/Q9@pendragon.ideasonboard.com>\n\t<375b460b-f1c9-b4b5-d8b9-67b9a51d44db@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<375b460b-f1c9-b4b5-d8b9-67b9a51d44db@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH] test: CameraManager: Add start/stop\n\ttests","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>","Cc":"libcamera devel <libcamera-devel@lists.libcamera.org>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]