diff options
author | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2024-01-21 05:13:04 +0200 |
---|---|---|
committer | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2024-01-25 02:39:02 +0200 |
commit | d47fa37c2e22c0ef13be69c00950fe39f257e2bb (patch) | |
tree | 5562cd22956e0cd724e1f10b8b7b362b58a5d78a /test | |
parent | d5c9b726bd86c44eac17dfec461d02771c22e101 (diff) |
test: object-delete: Test deferred delete just before thread stops
The Object::deleteLater() function is expected to not race with stopping
the thread the object is bound to. Add a test for this.
The test currently fails, demonstrating a bug in libcamera.
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Milan Zamazal <mzamazal@redhat.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/object-delete.cpp | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/test/object-delete.cpp b/test/object-delete.cpp index eabefe93..80b7dc41 100644 --- a/test/object-delete.cpp +++ b/test/object-delete.cpp @@ -33,10 +33,10 @@ public: unsigned int *deleteCount_; }; -class NewThread : public Thread +class DeleterThread : public Thread { public: - NewThread(Object *obj) + DeleterThread(Object *obj) : object_(obj) { } @@ -63,9 +63,9 @@ protected: unsigned int count = 0; TestObject *obj = new TestObject(&count); - NewThread thread(obj); - thread.start(); - thread.wait(); + DeleterThread delThread(obj); + delThread.start(); + delThread.wait(); Thread::current()->dispatchMessages(Message::Type::DeferredDelete); @@ -89,6 +89,26 @@ protected: return TestFail; } + /* + * Test that deleteLater() works properly when called just + * before the object's thread exits. + */ + Thread boundThread; + boundThread.start(); + + count = 0; + obj = new TestObject(&count); + obj->moveToThread(&boundThread); + + obj->deleteLater(); + boundThread.exit(); + boundThread.wait(); + + if (count != 1) { + cout << "Object deletion right before thread exit failed (" << count << ")" << endl; + return TestFail; + } + return TestPass; } }; |