summaryrefslogtreecommitdiff
path: root/test/threads.cpp
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2020-01-23 04:50:02 +0200
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2020-02-14 15:06:42 +0200
commita6388e494e88b4a284bba7cce8b9cb5c3a558ab6 (patch)
tree889106ed1141a520940818f0f8691069e4412be0 /test/threads.cpp
parent3f207e0b333c6b8f071f6d04cea96eb9c26b0f16 (diff)
test: threads: Add wait() timeout test
Add a test case to wait with a timeout, testing both a too short and a long enough duration. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Diffstat (limited to 'test/threads.cpp')
-rw-r--r--test/threads.cpp33
1 files changed, 26 insertions, 7 deletions
diff --git a/test/threads.cpp b/test/threads.cpp
index 9a2d39df..1fa26020 100644
--- a/test/threads.cpp
+++ b/test/threads.cpp
@@ -15,24 +15,22 @@
using namespace std;
using namespace libcamera;
-class InstrumentedThread : public Thread
+class DelayThread : public Thread
{
public:
- InstrumentedThread(unsigned int iterations)
- : iterations_(iterations)
+ DelayThread(chrono::steady_clock::duration duration)
+ : duration_(duration)
{
}
protected:
void run()
{
- for (unsigned int i = 0; i < iterations_; ++i) {
- this_thread::sleep_for(chrono::milliseconds(50));
- }
+ this_thread::sleep_for(duration_);
}
private:
- unsigned int iterations_;
+ chrono::steady_clock::duration duration_;
};
class ThreadTest : public Test
@@ -82,6 +80,27 @@ protected:
delete thread;
+ /* Test waiting for completion with a timeout. */
+ thread = new DelayThread(chrono::milliseconds(500));
+ thread->start();
+ thread->exit(0);
+
+ bool timeout = !thread->wait(chrono::milliseconds(100));
+
+ if (!timeout) {
+ cout << "Waiting for thread didn't time out" << endl;
+ return TestFail;
+ }
+
+ timeout = !thread->wait(chrono::milliseconds(1000));
+
+ if (timeout) {
+ cout << "Waiting for thread timed out" << endl;
+ return TestFail;
+ }
+
+ delete thread;
+
return TestPass;
}