[libcamera-devel,v2,05/13] py: unittests: verify that cam and cm are freed
diff mbox series

Message ID 20220517143325.71784-6-tomi.valkeinen@ideasonboard.com
State Superseded
Headers show
Series
  • Misc Python bindings patches
Related show

Commit Message

Tomi Valkeinen May 17, 2022, 2:33 p.m. UTC
Add checks to CameraTesterBase to verify that both the Camera and the
CameraManager gets freed.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 test/py/unittests.py | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Kieran Bingham May 17, 2022, 4:29 p.m. UTC | #1
Quoting Tomi Valkeinen (2022-05-17 15:33:17)
> Add checks to CameraTesterBase to verify that both the Camera and the
> CameraManager gets freed.
> 
> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>


> ---
>  test/py/unittests.py | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/test/py/unittests.py b/test/py/unittests.py
> index 9326358d..4c214f0a 100755
> --- a/test/py/unittests.py
> +++ b/test/py/unittests.py
> @@ -83,6 +83,9 @@ class CameraTesterBase(BaseTestCase):
>              self.cm = None
>              raise Exception('Failed to acquire camera')
>  
> +        self.wr_cam = weakref.ref(self.cam)
> +        self.wr_cm = weakref.ref(self.cm)
> +
>      def tearDown(self):
>          # If a test fails, the camera may be in running state. So always stop.
>          self.cam.stop()
> @@ -94,6 +97,9 @@ class CameraTesterBase(BaseTestCase):
>          self.cam = None
>          self.cm = None
>  
> +        self.assertIsNone(self.wr_cm())
> +        self.assertIsNone(self.wr_cam())

This seems a bit extreme testing that something is None right after
setting it to None? But perhaps there are going to be further expansions
that make this worth checking?

Does this test something that I'm not seeing?

<Edit> Turns out this really is checking that there were no extra
references keeping those objects alive with an extra reference, so this
is fine by me.


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


> +
>  
>  class AllocatorTestMethods(CameraTesterBase):
>      def test_allocator(self):
> -- 
> 2.34.1
>

Patch
diff mbox series

diff --git a/test/py/unittests.py b/test/py/unittests.py
index 9326358d..4c214f0a 100755
--- a/test/py/unittests.py
+++ b/test/py/unittests.py
@@ -83,6 +83,9 @@  class CameraTesterBase(BaseTestCase):
             self.cm = None
             raise Exception('Failed to acquire camera')
 
+        self.wr_cam = weakref.ref(self.cam)
+        self.wr_cm = weakref.ref(self.cm)
+
     def tearDown(self):
         # If a test fails, the camera may be in running state. So always stop.
         self.cam.stop()
@@ -94,6 +97,9 @@  class CameraTesterBase(BaseTestCase):
         self.cam = None
         self.cm = None
 
+        self.assertIsNone(self.wr_cm())
+        self.assertIsNone(self.wr_cam())
+
 
 class AllocatorTestMethods(CameraTesterBase):
     def test_allocator(self):