From 5646849b59fecb53ce4eadcec64fa2c9535e610b Mon Sep 17 00:00:00 2001 From: Umang Jain Date: Thu, 21 Jul 2022 19:15:31 +0530 Subject: test: gstreamer: Check availability of cameras before running Move the logic for checking the availability of cameras from multi_stream_test to gstreamer test base class. Since single_stream_class always assumes that a camera is available on the system (which is not always the case for e.g. RPi in CI/CD environments) it makes sense to have the availability check in the base class. If no cameras are available, the behaviour should be to skip instead of a failure. We currently have 2 tests for gstreamer differing based on number of streams supported by the camera. Hence, the camera availability is checked in conjunction with the number of the streams required by the derived class. Signed-off-by: Umang Jain Reviewed-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- test/gstreamer/gstreamer_test.cpp | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'test/gstreamer/gstreamer_test.cpp') diff --git a/test/gstreamer/gstreamer_test.cpp b/test/gstreamer/gstreamer_test.cpp index cfb8afc6..4947b7bb 100644 --- a/test/gstreamer/gstreamer_test.cpp +++ b/test/gstreamer/gstreamer_test.cpp @@ -5,6 +5,8 @@ * libcamera Gstreamer element API tests */ +#include + #include #include "gstreamer_test.h" @@ -25,7 +27,7 @@ const char *__asan_default_options() } } -GstreamerTest::GstreamerTest() +GstreamerTest::GstreamerTest(unsigned int numStreams) : pipeline_(nullptr), libcameraSrc_(nullptr) { /* @@ -67,9 +69,38 @@ GstreamerTest::GstreamerTest() return; } + /* + * Atleast one camera should be available with numStreams streams, + * otherwise skip the test entirely. + */ + if (!checkMinCameraStreams(numStreams)) { + status_ = TestSkip; + return; + } + status_ = TestPass; } +bool GstreamerTest::checkMinCameraStreams(unsigned int numStreams) +{ + libcamera::CameraManager cm; + bool cameraFound = false; + + cm.start(); + + for (auto &camera : cm.cameras()) { + if (camera->streams().size() < numStreams) + continue; + + cameraFound = true; + break; + } + + cm.stop(); + + return cameraFound; +} + GstreamerTest::~GstreamerTest() { g_clear_object(&pipeline_); -- cgit v1.2.1