[{"id":28583,"web_url":"https://patchwork.libcamera.org/comment/28583/","msgid":"<87ede8b71c.fsf@redhat.com>","date":"2024-01-23T11:53:03","subject":"Re: [PATCH v2 03/12] test: object-delete: Test deferred delete just\n\tbefore thread stops","submitter":{"id":177,"url":"https://patchwork.libcamera.org/api/people/177/","name":"Milan Zamazal","email":"mzamazal@redhat.com"},"content":"Laurent Pinchart <laurent.pinchart@ideasonboard.com> writes:\n\n> The Object::deleteLater() function is expected to not race with stopping\n> the thread the object is bound to. Add a test for this.\n>\n> The test currently fails, demonstrating a bug in libcamera.\n>\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nReviewed-by: Milan Zamazal <mzamazal@redhat.com>\n\n> ---\n> Changes since v1:\n>\n> - Fix typo in commit message\n> ---\n>  test/object-delete.cpp | 30 +++++++++++++++++++++++++-----\n>  1 file changed, 25 insertions(+), 5 deletions(-)\n>\n> diff --git a/test/object-delete.cpp b/test/object-delete.cpp\n> index eabefe935974..80b7dc41cd37 100644\n> --- a/test/object-delete.cpp\n> +++ b/test/object-delete.cpp\n> @@ -33,10 +33,10 @@ public:\n>  \tunsigned int *deleteCount_;\n>  };\n>  \n> -class NewThread : public Thread\n> +class DeleterThread : public Thread\n>  {\n>  public:\n> -\tNewThread(Object *obj)\n> +\tDeleterThread(Object *obj)\n>  \t\t: object_(obj)\n>  \t{\n>  \t}\n> @@ -63,9 +63,9 @@ protected:\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> +\t\tDeleterThread delThread(obj);\n> +\t\tdelThread.start();\n> +\t\tdelThread.wait();\n>  \n>  \t\tThread::current()->dispatchMessages(Message::Type::DeferredDelete);\n>  \n> @@ -89,6 +89,26 @@ protected:\n>  \t\t\treturn TestFail;\n>  \t\t}\n>  \n> +\t\t/*\n> +\t\t * Test that deleteLater() works properly when called just\n> +\t\t * before the object's thread exits.\n> +\t\t */\n> +\t\tThread boundThread;\n> +\t\tboundThread.start();\n> +\n> +\t\tcount = 0;\n> +\t\tobj = new TestObject(&count);\n> +\t\tobj->moveToThread(&boundThread);\n> +\n> +\t\tobj->deleteLater();\n> +\t\tboundThread.exit();\n> +\t\tboundThread.wait();\n> +\n> +\t\tif (count != 1) {\n> +\t\t\tcout << \"Object deletion right before thread exit failed (\" << count << \")\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n>  \t\treturn TestPass;\n>  \t}\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 1E1F8C323E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 23 Jan 2024 11:53:12 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 53EFE62944;\n\tTue, 23 Jan 2024 12:53:11 +0100 (CET)","from us-smtp-delivery-124.mimecast.com\n\t(us-smtp-delivery-124.mimecast.com [170.10.133.124])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 05BB5628E9\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 23 Jan 2024 12:53:08 +0100 (CET)","from mail-wm1-f70.google.com (mail-wm1-f70.google.com\n\t[209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS\n\t(version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n\tus-mta-384-cwa6P6ouN2Ge4Z35mCIcDg-1; Tue, 23 Jan 2024 06:53:06 -0500","by mail-wm1-f70.google.com with SMTP id\n\t5b1f17b1804b1-40e74860cb0so19713965e9.3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 23 Jan 2024 03:53:06 -0800 (PST)","from nuthatch (nat-pool-brq-t.redhat.com. [213.175.37.10])\n\tby smtp.gmail.com with ESMTPSA id\n\tu21-20020a05600c139500b0040e4a7a7ca3sm42311973wmf.43.2024.01.23.03.53.03\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tTue, 23 Jan 2024 03:53:03 -0800 (PST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=redhat.com header.i=@redhat.com\n\theader.b=\"VUK+1wUK\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1706010787;\n\th=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n\tto:to:cc:cc:mime-version:mime-version:content-type:content-type:\n\tin-reply-to:in-reply-to:references:references;\n\tbh=B3hQ/YvvSsVRPRdig700B+lt2LkAYyXK36p8G4PsssU=;\n\tb=VUK+1wUK6v8Bm3CwCQz3U3z7tn4oSY7/Q+yI0Dow4c+bpwDjk/aynId1YS2guJ0e5BVeZ5\n\tpvjUfvzxBsWMi7ijo+r7Cqh9PHUyWqy4RiN7qR5DNaaIeDp3W909Ab5fuY/lW5IRr19Ti8\n\tnCxe93XJA+pPo3Cp4YUoaat4xEHREEg=","X-MC-Unique":"cwa6P6ouN2Ge4Z35mCIcDg-1","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1706010784; x=1706615584;\n\th=mime-version:user-agent:message-id:date:references:in-reply-to\n\t:subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=B3hQ/YvvSsVRPRdig700B+lt2LkAYyXK36p8G4PsssU=;\n\tb=E+K4ZZo0pOrxvOXeQIjmjOn56Ky+pWkWZkVqhsqOGe3M0LDFQCGE0NYMm09s7hv033\n\tk2Qm9m4WgkLEVabWlcirHuAPghUnXvbYNq9IDaMk7SYmkDlJHqTqubQLYuGJRJcZWjJL\n\t1gxgA6wKpJ6BGCgSy91OR5VBD7kbD7M6LSMOmCeu/KFCBcdDxSLlgwi8MWP4WFooFuY4\n\txwagWKCNOIApPOsQv69pc7pKaR2jTfQhjJyVtE8absLtizwVxL1E0WOCclzTpesnSqz5\n\t5M8+M7EZGjayNZz041cDXT79XNoVuuc/JuujCP3d/Dq/xMBC+No/0VP4a8l/fsDzGraP\n\t84Qw==","X-Gm-Message-State":"AOJu0YyOsfW1243xI554guCz/fkGoyKEObEtW6owCEMLcAVU1rJqVOMK\n\tlFfem3h3mardyeeBsVHIju3bVwvGZ8/1QH5MldUqSVNB1dPceBxt6AKobABMzFLmabCb8MYqTKI\n\tKCXg7F0GmKgSGfPVClI6kq6oJ1s1ZVtrH4WyxZk53mMIfqf3mCI9KDsL1gGUegtVIKBj4dUvBC+\n\tgdt8ObRg0dBZDHlIIngWZjikOAQUNiuH1d/vnuhqNZI2Xqj1VIFXF/9DA=","X-Received":["by 2002:a05:600c:4f51:b0:40e:66a5:574 with SMTP id\n\tm17-20020a05600c4f5100b0040e66a50574mr51885wmq.120.1706010784503; \n\tTue, 23 Jan 2024 03:53:04 -0800 (PST)","by 2002:a05:600c:4f51:b0:40e:66a5:574 with SMTP id\n\tm17-20020a05600c4f5100b0040e66a50574mr51879wmq.120.1706010784171; \n\tTue, 23 Jan 2024 03:53:04 -0800 (PST)"],"X-Google-Smtp-Source":"AGHT+IF8JZxTk0pa4nc3rT8TTYCRVcam36C59deXC5In3tVZyp/WH/XPnPuqmsxtxNa/tX92xkfIVw==","From":"Milan Zamazal <mzamazal@redhat.com>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Subject":"Re: [PATCH v2 03/12] test: object-delete: Test deferred delete just\n\tbefore thread stops","In-Reply-To":"<20240123011249.22716-4-laurent.pinchart@ideasonboard.com>\n\t(Laurent Pinchart's message of \"Tue, 23 Jan 2024 03:12:40 +0200\")","References":"<20240123011249.22716-1-laurent.pinchart@ideasonboard.com>\n\t<20240123011249.22716-4-laurent.pinchart@ideasonboard.com>","Date":"Tue, 23 Jan 2024 12:53:03 +0100","Message-ID":"<87ede8b71c.fsf@redhat.com>","User-Agent":"Gnus/5.13 (Gnus v5.13)","MIME-Version":"1.0","X-Mimecast-Spam-Score":"0","X-Mimecast-Originator":"redhat.com","Content-Type":"text/plain","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@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]