[{"id":2746,"web_url":"https://patchwork.libcamera.org/comment/2746/","msgid":"<20191003183409.GB4737@pendragon.ideasonboard.com>","date":"2019-10-03T18:34:09","subject":"Re: [libcamera-devel] [PATCH 4/5] test: ipa: Add test for the IPA\n\tInterface","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Jacopo,\n\nThank you for the patch.\n\nOn Thu, Oct 03, 2019 at 05:20:36PM +0200, Jacopo Mondi wrote:\n> Implementing a basic test for IPA Interface using the VIMC dummy IPA\n> module. The test implements a communication channel between the test and\n> the dummy IPA module to verify the success of the IPA interactions.\n> \n> Test the only available operation defined by the IPA interface by\n> receiving a confirmation code on the fifo communication channel.\n> \n> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n> ---\n>  test/ipa/ipa_interface_test.cpp | 147 ++++++++++++++++++++++++++++++++\n>  test/ipa/meson.build            |   3 +-\n>  2 files changed, 149 insertions(+), 1 deletion(-)\n>  create mode 100644 test/ipa/ipa_interface_test.cpp\n> \n> diff --git a/test/ipa/ipa_interface_test.cpp b/test/ipa/ipa_interface_test.cpp\n> new file mode 100644\n> index 000000000000..83eef7440fa4\n> --- /dev/null\n> +++ b/test/ipa/ipa_interface_test.cpp\n> @@ -0,0 +1,147 @@\n> +/* SPDX-License-Identifier: GPL-2.0-or-later */\n> +/*\n> + * Copyright (C) 2019, Google Inc.\n> + *\n> + * ipa_interface_test.cpp - Test the IPA interface communication using the VIMC\n> + *\t\t\t    dummy IPA module\n\nThat's getting a bit long for a short description. How about \"Test the\nIPA interface\" ?\n\n> + */\n> +\n> +#include <iostream>\n> +\n\nNo need for a blank line.\n\n> +#include <fcntl.h>\n> +#include <string.h>\n> +#include <sys/types.h>\n> +#include <sys/stat.h>\n\nstat comes before types.\n\n> +#include <unistd.h>\n> +\n> +#include <libcamera/event_dispatcher.h>\n> +#include <libcamera/event_notifier.h>\n> +#include <libcamera/timer.h>\n> +\n> +#include \"ipa_module.h\"\n> +\n> +#include \"test.h\"\n> +#include \"thread.h\"\n> +\n> +using namespace std;\n> +using namespace libcamera;\n> +\n> +/* Keep with in sync with the VIMC IPA module. */\n\ns/Keep with/Keep/\n\n> +static const char *ipaFifoPath = \"/tmp/vimc_ipa_fifo\";\n> +#define IPA_INIT_CODE 0x01\n> +\n> +static const char *vimcModulePath = \"src/ipa/ipa_vimc.so\";\n> +\n> +class IPAInterfaceTest : public Test, public Object\n> +{\n> +public:\n> +\tIPAInterfaceTest()\n> +\t\t: fd_(0), data_(0)\n\nYou should initialise ipaModule_ and notifier_ to nullptr.\n\n> +\t{\n> +\t}\n> +\n> +\t~IPAInterfaceTest()\n> +\t{\n> +\t\t/*\n> +\t\t * Delete the IPA Interface instance -before- deleting the\n> +\t\t * module used to create it, as the IPAModule destructor closes\n> +\t\t * the IPA shared object, resulting in segfault at interface\n> +\t\t * deletion time.\n> +\t\t */\n> +\t\tIPAInterface *ipa = ipa_.release();\n> +\t\tdelete ipa;\n\nYou can write this\n\n\t\tipa_.reset();\n\n> +\n> +\t\tif (ipaModule_)\n> +\t\t\tdelete ipaModule_;\n> +\n> +\t\tdelete notifier_;\n\nShouldn't this be moved to cleanup() ?\n\n> +\t}\n> +\n> +protected:\n> +\tint init() override\n> +\t{\n> +\t\tint ret = mkfifo(ipaFifoPath, S_IRUSR | S_IWUSR);\n> +\t\tif (ret) {\n> +\t\t\tcerr << \"Failed to create IPA test fifo at: \"\n> +\t\t\t     << ipaFifoPath << \": \" << strerror(errno) << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tret = open(ipaFifoPath, O_RDONLY | O_NONBLOCK);\n> +\t\tif (ret < 0) {\n> +\t\t\tcerr << \"Failed to open IPA test fifo at: \"\n> +\t\t\t     << ipaFifoPath << \": \" << strerror(errno) << endl;\n> +\t\t\tunlink(ipaFifoPath);\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\t\tfd_ = ret;\n> +\n> +\t\tnotifier_ = new EventNotifier(fd_, EventNotifier::Read, this);\n> +\t\tnotifier_->activated.connect(this, &IPAInterfaceTest::readFifo);\n> +\n> +\t\treturn TestPass;\n> +\t}\n> +\n> +\tint run() override\n> +\t{\n> +\t\tEventDispatcher *dispatcher = thread()->eventDispatcher();\n> +\t\tTimer timer;\n> +\n> +\t\tipaModule_ = new IPAModule(vimcModulePath);\n> +\t\tif (!ipaModule_ || !ipaModule_->isValid()) {\n> +\t\t\tcerr << \"Failed to create VIMC IPA module at: \"\n> +\t\t\t     << vimcModulePath << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tif (!ipaModule_->load()) {\n> +\t\t\tcerr << \"Failed to load VIMC IPA module\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tipa_ = ipaModule_->createInstance();\n> +\t\tif (!ipa_) {\n> +\t\t\tcerr << \"Failed to create VIMC IPA interface\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n\nI think we should use the IPA manager to create the instance, in order\nto pull in IPC and proxy. Otherwise you will end up with a plain\nIPAInterface that will directly call the IPA, emptying the init() call\ntest below from its substance.\n\n> +\n> +\t\t/* Test initialization of IPA module. */\n> +\t\tipa_->init();\n> +\t\ttimer.start(1000);\n> +\t\twhile (timer.isRunning() && data_ != IPA_INIT_CODE)\n> +\t\t\tdispatcher->processEvents();\n> +\n> +\t\tif (data_ != IPA_INIT_CODE) {\n> +\t\t\tcerr << \"Failed to test IPA initialization sequence\"\n> +\t\t\t     << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\treturn TestPass;\n> +\t}\n> +\n> +\tvoid cleanup() override\n> +\t{\n> +\t\tclose(fd_);\n> +\t\tunlink(ipaFifoPath);\n> +\t}\n> +\n> +private:\n> +\tvoid readFifo(EventNotifier *notifier)\n> +\t{\n> +\t\tsize_t s = read(notifier->fd(), &data_, 1);\n> +\t\tif (s < 0) {\n> +\t\t\tcerr << \"Failed to to read from IPA test fifo at: \"\n\ns/to to/to/\ns/fifo/FIFO/\n\n> +\t\t\t     << ipaFifoPath << strerror(errno) << endl;\n\nI think It's remove the FIFO path.\n\n> +\t\t\tdata_ = -1;\n> +\t\t}\n> +\t}\n> +\n> +\tstd::unique_ptr<IPAInterface> ipa_;\n> +\tEventNotifier *notifier_;\n> +\tIPAModule *ipaModule_;\n> +\tunsigned int fd_;\n> +\tint8_t data_;\n\nHow about naming this status_ and making it an enum ?\n\n> +};\n> +\n> +TEST_REGISTER(IPAInterfaceTest)\n> diff --git a/test/ipa/meson.build b/test/ipa/meson.build\n> index e174671d05e1..c501fcf99aed 100644\n> --- a/test/ipa/meson.build\n> +++ b/test/ipa/meson.build\n> @@ -1,5 +1,6 @@\n>  ipa_test = [\n> -    ['ipa_module_test', 'ipa_module_test.cpp'],\n> +    ['ipa_module_test',     'ipa_module_test.cpp'],\n> +    ['ipa_interface_test',  'ipa_interface_test.cpp'],\n>  ]\n>  \n>  foreach t : ipa_test","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["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 E32E460BE9\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  3 Oct 2019 20:34:22 +0200 (CEST)","from pendragon.ideasonboard.com (unknown [132.205.230.12])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 26C5C2E5;\n\tThu,  3 Oct 2019 20:34:22 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1570127662;\n\tbh=ssr2JUtXkaG6yd5YEHI99mmuUhVf8wEZS5goK/dhLTY=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=N/nRbDHra59j4iNz5Q2jZTdYrtCLAMe5DK82a7mJyWlBrZJ+slYraZImNw/bKIdJJ\n\t6HeXOEy+IiqmLIEmN11jfb5PO5sYz96vL3viGZeIEQMSigdSLq0652ZBO4gdFgmX0n\n\tTh0AC0YNIHE6cPWciKAMK5YiBWDuXOGZ4RBk7WRo=","Date":"Thu, 3 Oct 2019 21:34:09 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Jacopo Mondi <jacopo@jmondi.org>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20191003183409.GB4737@pendragon.ideasonboard.com>","References":"<20191003152037.74617-1-jacopo@jmondi.org>\n\t<20191003152037.74617-5-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20191003152037.74617-5-jacopo@jmondi.org>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH 4/5] test: ipa: Add test for the IPA\n\tInterface","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>","X-List-Received-Date":"Thu, 03 Oct 2019 18:34:23 -0000"}},{"id":2748,"web_url":"https://patchwork.libcamera.org/comment/2748/","msgid":"<20191003185417.GD4737@pendragon.ideasonboard.com>","date":"2019-10-03T18:54:17","subject":"Re: [libcamera-devel] [PATCH 4/5] test: ipa: Add test for the IPA\n\tInterface","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Jacopo,\n\nAnother comment.\n\nOn Thu, Oct 03, 2019 at 09:34:09PM +0300, Laurent Pinchart wrote:\n> On Thu, Oct 03, 2019 at 05:20:36PM +0200, Jacopo Mondi wrote:\n> > Implementing a basic test for IPA Interface using the VIMC dummy IPA\n> > module. The test implements a communication channel between the test and\n> > the dummy IPA module to verify the success of the IPA interactions.\n> > \n> > Test the only available operation defined by the IPA interface by\n> > receiving a confirmation code on the fifo communication channel.\n> > \n> > Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n> > ---\n> >  test/ipa/ipa_interface_test.cpp | 147 ++++++++++++++++++++++++++++++++\n> >  test/ipa/meson.build            |   3 +-\n> >  2 files changed, 149 insertions(+), 1 deletion(-)\n> >  create mode 100644 test/ipa/ipa_interface_test.cpp\n> > \n> > diff --git a/test/ipa/ipa_interface_test.cpp b/test/ipa/ipa_interface_test.cpp\n> > new file mode 100644\n> > index 000000000000..83eef7440fa4\n> > --- /dev/null\n> > +++ b/test/ipa/ipa_interface_test.cpp\n> > @@ -0,0 +1,147 @@\n> > +/* SPDX-License-Identifier: GPL-2.0-or-later */\n> > +/*\n> > + * Copyright (C) 2019, Google Inc.\n> > + *\n> > + * ipa_interface_test.cpp - Test the IPA interface communication using the VIMC\n> > + *\t\t\t    dummy IPA module\n> \n> That's getting a bit long for a short description. How about \"Test the\n> IPA interface\" ?\n> \n> > + */\n> > +\n> > +#include <iostream>\n> > +\n> \n> No need for a blank line.\n> \n> > +#include <fcntl.h>\n> > +#include <string.h>\n> > +#include <sys/types.h>\n> > +#include <sys/stat.h>\n> \n> stat comes before types.\n> \n> > +#include <unistd.h>\n> > +\n> > +#include <libcamera/event_dispatcher.h>\n> > +#include <libcamera/event_notifier.h>\n> > +#include <libcamera/timer.h>\n> > +\n> > +#include \"ipa_module.h\"\n> > +\n> > +#include \"test.h\"\n> > +#include \"thread.h\"\n> > +\n> > +using namespace std;\n> > +using namespace libcamera;\n> > +\n> > +/* Keep with in sync with the VIMC IPA module. */\n> \n> s/Keep with/Keep/\n> \n> > +static const char *ipaFifoPath = \"/tmp/vimc_ipa_fifo\";\n> > +#define IPA_INIT_CODE 0x01\n> > +\n> > +static const char *vimcModulePath = \"src/ipa/ipa_vimc.so\";\n> > +\n> > +class IPAInterfaceTest : public Test, public Object\n> > +{\n> > +public:\n> > +\tIPAInterfaceTest()\n> > +\t\t: fd_(0), data_(0)\n> \n> You should initialise ipaModule_ and notifier_ to nullptr.\n> \n> > +\t{\n> > +\t}\n> > +\n> > +\t~IPAInterfaceTest()\n> > +\t{\n> > +\t\t/*\n> > +\t\t * Delete the IPA Interface instance -before- deleting the\n> > +\t\t * module used to create it, as the IPAModule destructor closes\n> > +\t\t * the IPA shared object, resulting in segfault at interface\n> > +\t\t * deletion time.\n> > +\t\t */\n> > +\t\tIPAInterface *ipa = ipa_.release();\n> > +\t\tdelete ipa;\n> \n> You can write this\n> \n> \t\tipa_.reset();\n> \n> > +\n> > +\t\tif (ipaModule_)\n> > +\t\t\tdelete ipaModule_;\n> > +\n> > +\t\tdelete notifier_;\n> \n> Shouldn't this be moved to cleanup() ?\n> \n> > +\t}\n> > +\n> > +protected:\n> > +\tint init() override\n> > +\t{\n> > +\t\tint ret = mkfifo(ipaFifoPath, S_IRUSR | S_IWUSR);\n> > +\t\tif (ret) {\n> > +\t\t\tcerr << \"Failed to create IPA test fifo at: \"\n> > +\t\t\t     << ipaFifoPath << \": \" << strerror(errno) << endl;\n> > +\t\t\treturn TestFail;\n> > +\t\t}\n> > +\n> > +\t\tret = open(ipaFifoPath, O_RDONLY | O_NONBLOCK);\n> > +\t\tif (ret < 0) {\n> > +\t\t\tcerr << \"Failed to open IPA test fifo at: \"\n> > +\t\t\t     << ipaFifoPath << \": \" << strerror(errno) << endl;\n> > +\t\t\tunlink(ipaFifoPath);\n> > +\t\t\treturn TestFail;\n> > +\t\t}\n> > +\t\tfd_ = ret;\n> > +\n> > +\t\tnotifier_ = new EventNotifier(fd_, EventNotifier::Read, this);\n> > +\t\tnotifier_->activated.connect(this, &IPAInterfaceTest::readFifo);\n> > +\n> > +\t\treturn TestPass;\n> > +\t}\n> > +\n> > +\tint run() override\n> > +\t{\n> > +\t\tEventDispatcher *dispatcher = thread()->eventDispatcher();\n> > +\t\tTimer timer;\n> > +\n> > +\t\tipaModule_ = new IPAModule(vimcModulePath);\n> > +\t\tif (!ipaModule_ || !ipaModule_->isValid()) {\n> > +\t\t\tcerr << \"Failed to create VIMC IPA module at: \"\n> > +\t\t\t     << vimcModulePath << endl;\n> > +\t\t\treturn TestFail;\n> > +\t\t}\n> > +\n> > +\t\tif (!ipaModule_->load()) {\n> > +\t\t\tcerr << \"Failed to load VIMC IPA module\" << endl;\n> > +\t\t\treturn TestFail;\n> > +\t\t}\n> > +\n> > +\t\tipa_ = ipaModule_->createInstance();\n> > +\t\tif (!ipa_) {\n> > +\t\t\tcerr << \"Failed to create VIMC IPA interface\" << endl;\n> > +\t\t\treturn TestFail;\n> > +\t\t}\n> \n> I think we should use the IPA manager to create the instance, in order\n> to pull in IPC and proxy. Otherwise you will end up with a plain\n> IPAInterface that will directly call the IPA, emptying the init() call\n> test below from its substance.\n> \n> > +\n> > +\t\t/* Test initialization of IPA module. */\n> > +\t\tipa_->init();\n> > +\t\ttimer.start(1000);\n> > +\t\twhile (timer.isRunning() && data_ != IPA_INIT_CODE)\n> > +\t\t\tdispatcher->processEvents();\n> > +\n> > +\t\tif (data_ != IPA_INIT_CODE) {\n> > +\t\t\tcerr << \"Failed to test IPA initialization sequence\"\n> > +\t\t\t     << endl;\n> > +\t\t\treturn TestFail;\n> > +\t\t}\n> > +\n> > +\t\treturn TestPass;\n> > +\t}\n> > +\n> > +\tvoid cleanup() override\n> > +\t{\n> > +\t\tclose(fd_);\n> > +\t\tunlink(ipaFifoPath);\n> > +\t}\n> > +\n> > +private:\n> > +\tvoid readFifo(EventNotifier *notifier)\n> > +\t{\n> > +\t\tsize_t s = read(notifier->fd(), &data_, 1);\n> > +\t\tif (s < 0) {\n\nsize_t is always positive. You should use ssize_t.\n\n> > +\t\t\tcerr << \"Failed to to read from IPA test fifo at: \"\n> \n> s/to to/to/\n> s/fifo/FIFO/\n> \n> > +\t\t\t     << ipaFifoPath << strerror(errno) << endl;\n> \n> I think It's remove the FIFO path.\n> \n> > +\t\t\tdata_ = -1;\n> > +\t\t}\n> > +\t}\n> > +\n> > +\tstd::unique_ptr<IPAInterface> ipa_;\n> > +\tEventNotifier *notifier_;\n> > +\tIPAModule *ipaModule_;\n> > +\tunsigned int fd_;\n> > +\tint8_t data_;\n> \n> How about naming this status_ and making it an enum ?\n> \n> > +};\n> > +\n> > +TEST_REGISTER(IPAInterfaceTest)\n> > diff --git a/test/ipa/meson.build b/test/ipa/meson.build\n> > index e174671d05e1..c501fcf99aed 100644\n> > --- a/test/ipa/meson.build\n> > +++ b/test/ipa/meson.build\n> > @@ -1,5 +1,6 @@\n> >  ipa_test = [\n> > -    ['ipa_module_test', 'ipa_module_test.cpp'],\n> > +    ['ipa_module_test',     'ipa_module_test.cpp'],\n> > +    ['ipa_interface_test',  'ipa_interface_test.cpp'],\n> >  ]\n> >  \n> >  foreach t : ipa_test","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 1492C60BE8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  3 Oct 2019 20:54:32 +0200 (CEST)","from pendragon.ideasonboard.com (unknown [132.205.230.12])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 0513A2E5;\n\tThu,  3 Oct 2019 20:54:30 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1570128871;\n\tbh=KIw/KwJ8FHVpWjP5DonYS3oKwxJk8L6ApkUCWrGDVRU=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=i0CfLWiQ5gIhmQovnnqsDk+cv7OLjqGTZPMAEtxRq9spgA6kbuYFlp0BWAp2BCLbG\n\tRsM90VHVF8RQd5FW9fAM6L0pouv6fvd4Ei7FNTdqp9zMeGmlnX+a/B89hEefARvzyY\n\tKDm0EqIEhU7ubrvN35AqijXP00BbAUz3CGdM4OyA=","Date":"Thu, 3 Oct 2019 21:54:17 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Jacopo Mondi <jacopo@jmondi.org>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20191003185417.GD4737@pendragon.ideasonboard.com>","References":"<20191003152037.74617-1-jacopo@jmondi.org>\n\t<20191003152037.74617-5-jacopo@jmondi.org>\n\t<20191003183409.GB4737@pendragon.ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20191003183409.GB4737@pendragon.ideasonboard.com>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH 4/5] test: ipa: Add test for the IPA\n\tInterface","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>","X-List-Received-Date":"Thu, 03 Oct 2019 18:54:32 -0000"}}]