[{"id":2435,"web_url":"https://patchwork.libcamera.org/comment/2435/","msgid":"<20190817145330.GL16603@wyvern>","date":"2019-08-17T14:53:30","subject":"Re: [libcamera-devel] [PATCH 08/18] test: Add\n\tObject::invokeMethod() test","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/people/5/","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"content":"Hi Laurent,\n\nThanks for your work.\n\nOn 2019-08-12 15:46:32 +0300, Laurent Pinchart wrote:\n> The test verifies correct behaviour of asynchronous method invocation\n> for Object instances.\n> \n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n\n> ---\n>  test/meson.build       |   1 +\n>  test/object-invoke.cpp | 137 +++++++++++++++++++++++++++++++++++++++++\n>  2 files changed, 138 insertions(+)\n>  create mode 100644 test/object-invoke.cpp\n> \n> diff --git a/test/meson.build b/test/meson.build\n> index b2f809e60986..7c9abc630230 100644\n> --- a/test/meson.build\n> +++ b/test/meson.build\n> @@ -24,6 +24,7 @@ public_tests = [\n>  internal_tests = [\n>      ['camera-sensor',                   'camera-sensor.cpp'],\n>      ['message',                         'message.cpp'],\n> +    ['object-invoke',                   'object-invoke.cpp'],\n>      ['signal-threads',                  'signal-threads.cpp'],\n>      ['threads',                         'threads.cpp'],\n>  ]\n> diff --git a/test/object-invoke.cpp b/test/object-invoke.cpp\n> new file mode 100644\n> index 000000000000..7221930f4380\n> --- /dev/null\n> +++ b/test/object-invoke.cpp\n> @@ -0,0 +1,137 @@\n> +/* SPDX-License-Identifier: GPL-2.0-or-later */\n> +/*\n> + * Copyright (C) 2019, Google Inc.\n> + *\n> + * object-invoke.cpp - Cross-thread Object method invocation test\n> + */\n> +\n> +#include <chrono>\n> +#include <iostream>\n> +#include <thread>\n> +\n> +#include <libcamera/camera_manager.h>\n> +#include <libcamera/event_dispatcher.h>\n> +#include <libcamera/object.h>\n> +\n> +#include \"thread.h\"\n> +#include \"test.h\"\n> +\n> +using namespace std;\n> +using namespace libcamera;\n> +\n> +class InvokedObject : public Object\n> +{\n> +public:\n> +\tenum Status {\n> +\t\tNoCall,\n> +\t\tInvalidThread,\n> +\t\tCallReceived,\n> +\t};\n> +\n> +\tInvokedObject()\n> +\t\t: status_(NoCall)\n> +\t{\n> +\t}\n> +\n> +\tStatus status() const { return status_; }\n> +\tint value() const { return value_; }\n> +\tvoid reset()\n> +\t{\n> +\t\tstatus_ = NoCall;\n> +\t\tvalue_ = 0;\n> +\t}\n> +\n> +\tvoid method(int value)\n> +\t{\n> +\t\tif (Thread::current() != thread())\n> +\t\t\tstatus_ = InvalidThread;\n> +\t\telse\n> +\t\t\tstatus_ = CallReceived;\n> +\n> +\t\tvalue_ = value;\n> +\t}\n> +\n> +private:\n> +\tStatus status_;\n> +\tint value_;\n> +};\n> +\n> +class ObjectInvokeTest : public Test\n> +{\n> +protected:\n> +\tint run()\n> +\t{\n> +\t\tEventDispatcher *dispatcher = CameraManager::instance()->eventDispatcher();\n> +\t\tInvokedObject object;\n> +\n> +\t\t/*\n> +\t\t * Test that method invocation in the same thread goes through\n> +\t\t * the event dispatcher.\n> +\t\t */\n> +\t\tobject.invokeMethod(&InvokedObject::method, 42);\n> +\n> +\t\tif (object.status() != InvokedObject::NoCall) {\n> +\t\t\tcerr << \"Method not invoked asynchronously\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tdispatcher->processEvents();\n> +\n> +\t\tswitch (object.status()) {\n> +\t\tcase InvokedObject::NoCall:\n> +\t\t\tcout << \"Method not invoked for main thread\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\tcase InvokedObject::InvalidThread:\n> +\t\t\tcout << \"Method invoked in incorrect thread for main thread\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\tdefault:\n> +\t\t\tbreak;\n> +\t\t}\n> +\n> +\t\tif (object.value() != 42) {\n> +\t\t\tcout << \"Method invoked with incorrect value for main thread\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\t/*\n> +\t\t * Move the object to a thread and verify that the method is\n> +\t\t * delivered in the correct thread.\n> +\t\t */\n> +\t\tobject.reset();\n> +\t\tobject.moveToThread(&thread_);\n> +\n> +\t\tthread_.start();\n> +\n> +\t\tobject.invokeMethod(&InvokedObject::method, 42);\n> +\t\tthis_thread::sleep_for(chrono::milliseconds(100));\n> +\n> +\t\tswitch (object.status()) {\n> +\t\tcase InvokedObject::NoCall:\n> +\t\t\tcout << \"Method not invoked for custom thread\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\tcase InvokedObject::InvalidThread:\n> +\t\t\tcout << \"Method invoked in incorrect thread for custom thread\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\tdefault:\n> +\t\t\tbreak;\n> +\t\t}\n> +\n> +\t\tif (object.value() != 42) {\n> +\t\t\tcout << \"Method invoked with incorrect value for custom thread\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\treturn TestPass;\n> +\t}\n> +\n> +\tvoid cleanup()\n> +\t{\n> +\t\tthread_.exit(0);\n> +\t\tthread_.wait();\n> +\t}\n> +\n> +private:\n> +\tThread thread_;\n> +};\n> +\n> +TEST_REGISTER(ObjectInvokeTest)\n> -- \n> Regards,\n> \n> Laurent Pinchart\n> \n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","headers":{"Return-Path":"<niklas.soderlund@ragnatech.se>","Received":["from mail-ed1-x542.google.com (mail-ed1-x542.google.com\n\t[IPv6:2a00:1450:4864:20::542])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 92DD3600F9\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 17 Aug 2019 16:53:35 +0200 (CEST)","by mail-ed1-x542.google.com with SMTP id g8so7522702edm.6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 17 Aug 2019 07:53:35 -0700 (PDT)","from localhost ([185.224.57.161]) by smtp.gmail.com with ESMTPSA id\n\toa21sm1249107ejb.60.2019.08.17.07.53.33\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tSat, 17 Aug 2019 07:53:34 -0700 (PDT)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=ragnatech-se.20150623.gappssmtp.com; s=20150623;\n\th=date:from:to:cc:subject:message-id:references:mime-version\n\t:content-disposition:content-transfer-encoding:in-reply-to\n\t:user-agent; bh=z1tvpiaqME92gkGCKdDTyahTnEFE1jpC3ZaJafe+DPQ=;\n\tb=0r/IRTBwBs/Hkv4M9P8X+9fjRR0HUnt3q2OkUPLGITIkMIEvELG19U3D/Aspf8Q6tz\n\tbO86upBpZPpA+2CzAQ6LR6hlXLVKevvv1bfVxQIdMGChFGgt1RvNIxZ1tVNXoUyXpXnb\n\tckz8qRd5jfsHKt0aglU0XP4QsvcAaOR5grLL6vcwNopHH1UGDTjGgV4TocC/c1nvJ5T1\n\twteHC8gdcDNHJsMPiS61H/2QZFDHvn+sObxc192j+6sPWiZYljiAiQeJRa8U2hqo6juA\n\thTMyuWGGhEk3L++SdmM7sOi/HNhu50lV8+UkiK9RdjjoBq2gfr7XhTXCWtrOkzU1ve+s\n\tKRWA==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:date:from:to:cc:subject:message-id:references\n\t:mime-version:content-disposition:content-transfer-encoding\n\t:in-reply-to:user-agent;\n\tbh=z1tvpiaqME92gkGCKdDTyahTnEFE1jpC3ZaJafe+DPQ=;\n\tb=ipWex9XOt1Gsdd+9o4oWYENQl+RwUWekQ93e55iW3lvKTIuUh1ntRmzjIJK2Cg4EPg\n\tq789tvvB7QKqggEoa6ynNwqSeKHlDBkSTQMspdMXXe8+2NN/a/q5BljsVertPHQpw+si\n\tenv1s5D40LzZ9AxAkvtXbo13BEeAreJrjeq5DbGtqHMwz7YWaZjLSIJGq+xpqfy6y0yL\n\t/x4wF3PfNmykoWKqy0hHsx8tA4PqqgOs7N0zcLINLCNmQr19ib4JoHP5WanoJXxqDUu+\n\tBCTU+KoCEuxUq1ppvQ8EVl/fGYhp9PMfJ7vDkeuOkeQ0XWVvfYT1Jb+88trPwXYggmiU\n\tfhmg==","X-Gm-Message-State":"APjAAAUfF1X0DP6d9pxnRT4NV26nVtHsgC+J8PgiDoHEUQ5mxc778Wxl\n\tN1q18tiYAx1prC2/CAXSeO/zNS4jeOA=","X-Google-Smtp-Source":"APXvYqw9z8Llfp+xRkDAhABZ/Miws1VYTB1/E3F6THnwPG8pypQvRQb+p6bXue2iI/I1QzRC9XneVg==","X-Received":"by 2002:a17:907:447f:: with SMTP id\n\too23mr13617754ejb.193.1566053615250; \n\tSat, 17 Aug 2019 07:53:35 -0700 (PDT)","Date":"Sat, 17 Aug 2019 16:53:30 +0200","From":"Niklas =?iso-8859-1?q?S=F6derlund?= <niklas.soderlund@ragnatech.se>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190817145330.GL16603@wyvern>","References":"<20190812124642.24287-1-laurent.pinchart@ideasonboard.com>\n\t<20190812124642.24287-9-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=iso-8859-1","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20190812124642.24287-9-laurent.pinchart@ideasonboard.com>","User-Agent":"Mutt/1.12.1 (2019-06-15)","Subject":"Re: [libcamera-devel] [PATCH 08/18] test: Add\n\tObject::invokeMethod() test","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.23","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":"Sat, 17 Aug 2019 14:53:35 -0000"}}]