{"id":9097,"url":"https://patchwork.libcamera.org/api/1.1/patches/9097/?format=json","web_url":"https://patchwork.libcamera.org/patch/9097/","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":"<20200731151424.28003-1-laurent.pinchart@ideasonboard.com>","date":"2020-07-31T15:14:24","name":"[libcamera-devel,v3.1,4/3] test: Add Object::deleteLater() test","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"c89a963be272a87bfbd10ee41fb825a1eb710dd8","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/1.1/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":{"id":14,"url":"https://patchwork.libcamera.org/api/1.1/users/14/?format=json","username":"pinchartl","first_name":"Laurent","last_name":"Pinchart","email":"laurent.pinchart@ideasonboard.com"},"mbox":"https://patchwork.libcamera.org/patch/9097/mbox/","series":[{"id":1168,"url":"https://patchwork.libcamera.org/api/1.1/series/1168/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1168","date":"2020-07-31T13:39:52","name":"Add Object::deleteLater() support","version":3,"mbox":"https://patchwork.libcamera.org/series/1168/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/9097/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/9097/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 1EAE7BD878\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 31 Jul 2020 15:15:42 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id A11E561DE1;\n\tFri, 31 Jul 2020 17:15:41 +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 84AC160398\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 31 Jul 2020 17:15:40 +0200 (CEST)","from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id AEFB353C;\n\tFri, 31 Jul 2020 17:15:39 +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=\"ADvE19ji\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1596208539;\n\tbh=jsaOI15SXIosTpJEs0q1SE8kaVTm+N7BCr3ISUpBs6o=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=ADvE19jiDI835kuYkOx4SZ8xV9mpCN/bZlR6Ajg2CunFQ1W1T4fXsXUm2ZPr6F+Qk\n\t2GmGfs6dldZd8I1uXN099bqZl6SzI8KDFuGiC4xW1iwfKRF+virhGSX0sOICi8RwNb\n\tuA/LWq/kUpz47rMh5TD2NKUHfWARNv7pGfdSnAgQ=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Fri, 31 Jul 2020 18:14:24 +0300","Message-Id":"<20200731151424.28003-1-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.27.0","In-Reply-To":"<20200731133947.84258-1-email@uajain.com>","References":"<20200731133947.84258-1-email@uajain.com>","MIME-Version":"1.0","Subject":"[libcamera-devel] [PATCH v3.1 4/3] test: Add Object::deleteLater()\n\ttest","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>","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"From: Umang Jain <email@uajain.com>\n\nAdd a test case for the Object::deleteLater() API, to verify that\n\n- the object is deleted from the correct thread\n- multiple deleteLater() calls delete the object once only\n\nSigned-off-by: Umang Jain <email@uajain.com>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n test/meson.build       |  1 +\n test/object-delete.cpp | 97 ++++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 98 insertions(+)\n create mode 100644 test/object-delete.cpp","diff":"diff --git a/test/meson.build b/test/meson.build\nindex c0fb9bdfac17..775187159dec 100644\n--- a/test/meson.build\n+++ b/test/meson.build\n@@ -33,6 +33,7 @@ internal_tests = [\n     ['hotplug-cameras',                 'hotplug-cameras.cpp'],\n     ['message',                         'message.cpp'],\n     ['object',                          'object.cpp'],\n+    ['object-delete',                   'object-delete.cpp'],\n     ['object-invoke',                   'object-invoke.cpp'],\n     ['pixel-format',                    'pixel-format.cpp'],\n     ['signal-threads',                  'signal-threads.cpp'],\ndiff --git a/test/object-delete.cpp b/test/object-delete.cpp\nnew file mode 100644\nindex 000000000000..a1a6f5ccefd5\n--- /dev/null\n+++ b/test/object-delete.cpp\n@@ -0,0 +1,97 @@\n+/* SPDX-License-Identifier: GPL-2.0-or-later */\n+/*\n+ * Copyright (C) 2020, Google Inc.\n+ *\n+ * object.cpp - Object deletion tests\n+ */\n+\n+#include <iostream>\n+\n+#include <libcamera/object.h>\n+\n+#include \"libcamera/internal/thread.h\"\n+\n+#include \"test.h\"\n+\n+using namespace std;\n+using namespace libcamera;\n+\n+class TestObject : public Object\n+{\n+public:\n+\tTestObject(unsigned int *count)\n+\t\t: deleteCount_(count)\n+\t{\n+\t}\n+\n+\t~TestObject()\n+\t{\n+\t\t/* Count the deletions from the correct thread. */\n+\t\tif (thread() == Thread::current())\n+\t\t\t(*deleteCount_)++;\n+\t}\n+\n+\tunsigned int *deleteCount_;\n+};\n+\n+class NewThread : public Thread\n+{\n+public:\n+\tNewThread(Object *obj)\n+\t\t: object_(obj)\n+\t{\n+\t}\n+\n+protected:\n+\tvoid run()\n+\t{\n+\t\tobject_->deleteLater();\n+\t}\n+\n+private:\n+\tObject *object_;\n+};\n+\n+class ObjectDeleteTest : public Test\n+{\n+protected:\n+\tint run()\n+\t{\n+\t\t/*\n+\t\t * Test that deferred deletion is executed from the object's\n+\t\t * thread, not the caller's thread.\n+\t\t */\n+\t\tunsigned int count = 0;\n+\t\tTestObject *obj = new TestObject(&count);\n+\n+\t\tNewThread thread(obj);\n+\t\tthread.start();\n+\t\tthread.wait();\n+\n+\t\tThread::current()->dispatchMessages(Message::Type::DeferredDelete);\n+\n+\t\tif (count != 1) {\n+\t\t\tcout << \"Failed to dispatch DeferredDelete (\" << count << \")\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\t/*\n+\t\t * Test that multiple calls to deleteLater() delete the object\n+\t\t * once only.\n+\t\t */\n+\t\tcount = 0;\n+\t\tobj = new TestObject(&count);\n+\t\tobj->deleteLater();\n+\t\tobj->deleteLater();\n+\n+\t\tThread::current()->dispatchMessages(Message::Type::DeferredDelete);\n+\t\tif (count != 1) {\n+\t\t\tcout << \"Multiple deleteLater() failed (\" << count << \")\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\treturn TestPass;\n+\t}\n+};\n+\n+TEST_REGISTER(ObjectDeleteTest)\n","prefixes":["libcamera-devel","v3.1","4/3"]}