Commit graph

15 commits

Author SHA1 Message Date
Laurent Pinchart
876730d805 test: py: Fix log level restore in SimpleTestMethods()
The SimpleTestMethods() function tests that incorrect calls to the
Camera.acquire() method raise an exception. Before doing so, it sets the
log level for the Camera category to FATAL, in order to avoid showing
misleading errors in the test log, and then restores the log level to
ERROR after running the test. ERROR is however not the default log
level. Restore the log level to INFO instead, in order to avoid losing
log messages in subsequent tests.

Fixes: 06cb7130c4 ("py: Add unittests.py")
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
2024-11-05 15:28:13 +02:00
Tomi Valkeinen
f44df6f4fa py: unittests.py: Fix type checker warnings
Fix type checker warnings by dropping unused imports and using _ for
variable names that are not used.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2023-06-04 16:10:51 +03:00
Tomi Valkeinen
51dc505d63 py: unittests.py: Add weakref helpers and use del
Add helpers to check if a weakref or a list of weakrefs is alive or
dead.

Also use 'del' for local variables instead of setting the variable to
None. This makes debugging the test easier as the locals will be gone
from locals() dict.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2023-05-30 18:29:10 +03:00
Tomi Valkeinen
1fb31ac4f4 py: Use exceptions instead of returning error codes
We have multiple methods which return an error code, mimicking the C++
API. Using exceptions is more natural in the Python API, so change all
those methods to raise an Exception instead.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2023-05-30 18:29:09 +03:00
Tomi Valkeinen
9506da142b py: Fix CameraManager.version property
The current CameraManager.version doesn't work at all (raises a
TypeError), as that's not how you use expose C++ static methods as
Python class methods.

Fix it.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2023-05-30 18:29:08 +03:00
Tomi Valkeinen
bf3dbaece9 py: Switch to non-blocking eventfd
Blocking wait can be easily implemented on top in Python, so rather than
supporting only blocking reads, or supporting both non-blocking and
blocking reads, let's support only non-blocking reads.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-08-19 15:44:28 +03:00
Tomi Valkeinen
7ef83e0228 py: Merge read_event() and get_ready_requests()
We always call CameraManager.read_event() and
CameraManager.get_ready_requests(), so to simplify the use merge the
read_event() into the get_ready_requests().

This has the side effect that get_ready_requests() will now block if
there is no event ready. If we ever need to call get_ready_requests() in
a polling manner we will need a new function which behaves differently.

However, afaics the only sensible way to manage the event loop is to use
select/poll on the eventfd and then call get_ready_requests() once,
which is the use case what the current merged function supports.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-06-04 02:21:05 +03:00
Tomi Valkeinen
679b73640a py: unittests: Fix test_select()
The test_select() currently uses self.assertTrue(len(ready_reqs) > 0) to
see that cm.get_ready_requests() returns something. This is not always
the case, as there may be two eventfd events queued, and the first call
to cm.get_ready_requests() returns all the requests, and thus the second
call returns none.

Remove the self.assertTrue(len(ready_reqs) > 0) assert.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-06-01 12:08:47 +03:00
Tomi Valkeinen
9f5b790800 py: unittests: Fix test_sleep()
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>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-06-01 12:08:42 +03:00
Tomi Valkeinen
7a0a464dd1 py: Rename 'efd' to 'event_fd'
Perhaps it's better to have a more descriptive name here. I also
considered just renaming 'efd' to 'fd', but 'event_fd' won.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-05-27 22:03:41 +03:00
Tomi Valkeinen
210ce547a4 py: Add CameraManager.read_event()
Add CameraManager.read_event() so that the user does not need to call
os.read().

We use eventfd, and we must always read 8 bytes. Hiding that inside
read_event() makes sense.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-05-27 22:02:31 +03:00
Tomi Valkeinen
7ac7e0e119 py: unittests: Make typechecker happy
Add some annotations and self.assertIsNotNone() calls to remove the
typechecker warnings.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-05-18 17:52:28 +03:00
Tomi Valkeinen
518f46ff0f py: unittests: Verify that cam and cm are freed
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>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-05-18 17:52:28 +03:00
Tomi Valkeinen
9368647555 py: unittests: Fix selector fd use
pyright complains about passing fileobj to os.read. Indeed, the
parameter should be an int, but I guess fileobj gets automatically
converted. In any case, using the fd is better.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-05-18 17:52:28 +03:00
Tomi Valkeinen
06cb7130c4 py: Add unittests.py
Add a simple unittests.py as a base for python unittests.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2022-05-10 13:53:43 +02:00