[libcamera-devel,v3,17/30] py: unittests: Fix test_sleep()
diff mbox series

Message ID 20220527144447.94891-18-tomi.valkeinen@ideasonboard.com
State Accepted
Headers show
Series
  • More misc Python patches
Related show

Commit Message

Tomi Valkeinen May 27, 2022, 2:44 p.m. UTC
Waiting for 0.5 secs and expecting that the requests have been completed
is... bad. Fix the test case by using cam.read_event() as a blocking
wait, and wait until we have received all the requests that we queued.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
---
 test/py/unittests.py | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

Comments

Laurent Pinchart May 27, 2022, 7:06 p.m. UTC | #1
Hi Tomi,

Thank you for the patch.

On Fri, May 27, 2022 at 05:44:34PM +0300, Tomi Valkeinen wrote:
> Waiting for 0.5 secs and expecting that the requests have been completed
> is... bad. Fix the test case by using cam.read_event() as a blocking
> wait, and wait until we have received all the requests that we queued.
> 
> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  test/py/unittests.py | 14 ++++++++++----
>  1 file changed, 10 insertions(+), 4 deletions(-)
> 
> diff --git a/test/py/unittests.py b/test/py/unittests.py
> index 426efb06..45b35223 100755
> --- a/test/py/unittests.py
> +++ b/test/py/unittests.py
> @@ -161,7 +161,7 @@ class AllocatorTestMethods(CameraTesterBase):
>  
>  
>  class SimpleCaptureMethods(CameraTesterBase):
> -    def test_sleep(self):
> +    def test_blocking(self):
>          cm = self.cm
>          cam = self.cam
>  
> @@ -207,11 +207,17 @@ class SimpleCaptureMethods(CameraTesterBase):
>          reqs = None
>          gc.collect()
>  
> -        time.sleep(0.5)
> +        reqs = []
>  
> -        reqs = cm.get_ready_requests()
> +        while True:
> +            cm.read_event()
>  
> -        self.assertTrue(len(reqs) == num_bufs)
> +            ready_reqs = cm.get_ready_requests()
> +
> +            reqs += ready_reqs
> +
> +            if len(reqs) == num_bufs:
> +                break
>  
>          for i, req in enumerate(reqs):
>              self.assertTrue(i == req.cookie)

Patch
diff mbox series

diff --git a/test/py/unittests.py b/test/py/unittests.py
index 426efb06..45b35223 100755
--- a/test/py/unittests.py
+++ b/test/py/unittests.py
@@ -161,7 +161,7 @@  class AllocatorTestMethods(CameraTesterBase):
 
 
 class SimpleCaptureMethods(CameraTesterBase):
-    def test_sleep(self):
+    def test_blocking(self):
         cm = self.cm
         cam = self.cam
 
@@ -207,11 +207,17 @@  class SimpleCaptureMethods(CameraTesterBase):
         reqs = None
         gc.collect()
 
-        time.sleep(0.5)
+        reqs = []
 
-        reqs = cm.get_ready_requests()
+        while True:
+            cm.read_event()
 
-        self.assertTrue(len(reqs) == num_bufs)
+            ready_reqs = cm.get_ready_requests()
+
+            reqs += ready_reqs
+
+            if len(reqs) == num_bufs:
+                break
 
         for i, req in enumerate(reqs):
             self.assertTrue(i == req.cookie)