[libcamera-devel,v2,3/3] test: thread: Test waiting on a thread that is not running

Message ID 20200213124538.21556-3-laurent.pinchart@ideasonboard.com
State Accepted
Commit a9b83617d27891853888a0eebb6702d02677090d
Headers show
Series
  • [libcamera-devel,v2,1/3] libcamera: thread: Support timeout in wait() function
Related show

Commit Message

Laurent Pinchart Feb. 13, 2020, 12:45 p.m. UTC
Test that Thread::wait() on a thread that hasn't been started, or on a
thread that is known to have completed, returns without a timeout.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 test/threads.cpp | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

Comments

Kieran Bingham Feb. 14, 2020, 12:44 p.m. UTC | #1
Hi Laurent,

On 13/02/2020 12:45, Laurent Pinchart wrote:
> Test that Thread::wait() on a thread that hasn't been started, or on a
> thread that is known to have completed, returns without a timeout.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Thanks, Hopefully we'll never hit issues with these edge cases anyway
but now we have tests for them :-)

Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>


> ---
>  test/threads.cpp | 19 +++++++++++++++++++
>  1 file changed, 19 insertions(+)
> 
> diff --git a/test/threads.cpp b/test/threads.cpp
> index 1fa26020ce5c..0454761de12c 100644
> --- a/test/threads.cpp
> +++ b/test/threads.cpp
> @@ -101,6 +101,25 @@ protected:
>  
>  		delete thread;
>  
> +		/* Test waiting on a thread that isn't running. */
> +		thread = new Thread();
> +
> +		timeout = !thread->wait();
> +		if (timeout) {
> +			cout << "Waiting for non-started thread timed out" << endl;
> +			return TestFail;
> +		}
> +
> +		thread->start();
> +		thread->exit(0);
> +		thread->wait();
> +
> +		timeout = !thread->wait();
> +		if (timeout) {
> +			cout << "Waiting for already stopped thread timed out" << endl;
> +			return TestFail;
> +		}
> +
>  		return TestPass;
>  	}
>  
>

Patch

diff --git a/test/threads.cpp b/test/threads.cpp
index 1fa26020ce5c..0454761de12c 100644
--- a/test/threads.cpp
+++ b/test/threads.cpp
@@ -101,6 +101,25 @@  protected:
 
 		delete thread;
 
+		/* Test waiting on a thread that isn't running. */
+		thread = new Thread();
+
+		timeout = !thread->wait();
+		if (timeout) {
+			cout << "Waiting for non-started thread timed out" << endl;
+			return TestFail;
+		}
+
+		thread->start();
+		thread->exit(0);
+		thread->wait();
+
+		timeout = !thread->wait();
+		if (timeout) {
+			cout << "Waiting for already stopped thread timed out" << endl;
+			return TestFail;
+		}
+
 		return TestPass;
 	}