summaryrefslogtreecommitdiff
path: root/test/gstreamer
AgeCommit message (Collapse)Author
2022-07-24test: gstreamer: Check availability of cameras before runningUmang Jain
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 <umang.jain@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-07-24test: gstreamer: Drop internal header from base classUmang Jain
The internal header isn't needed. The needed function libcameraBuildPath() is exposed by libcamera/base/utils.h header. At the same time, move the utils header to .cpp instead of including it in the base class header itself. Signed-off-by: Umang Jain <umang.jain@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2021-12-01test: gstreamer: Avoid call to deprecated gst_element_get_request_pad()Xavier Roumegue
gst_element_get_request_pad() is being replaced by gst_element_request_simple() since 1.19.1, throwing a warning in case of use until its definitive replacement on 1.20. Hence, prefer using gst_element_request_simple() in case gstreamer version is >= 1.19.1 to avoid the compilation error below (tested on f35): [258/391] Compiling C++ object test/gstreamer/multi_stream_test.p/gstreamer_multi_stream_test.cpp.o FAILED: test/gstreamer/multi_stream_test.p/gstreamer_multi_stream_test.cpp.o c++ -Itest/gstreamer/multi_stream_test.p -Itest/gstreamer -I../test/gstreamer -Itest/libtest -I../test/libtest -Iinclude -I../include -Iinclude/libcamera/ipa -Iinclude/libcamera -I/usr/include/gstreamer-1.0 -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/sysprof-4 -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wnon-virtual-dtor -Wextra -Werror -std=c++17 -g -Wshadow -include config.h -pthread -DLIBCAMERA_BASE_PRIVATE -MD -MQ test/gstreamer/multi_stream_test.p/gstreamer_multi_stream_test.cpp.o -MF test/gstreamer/multi_stream_test.p/gstreamer_multi_stream_test.cpp.o.d -o test/gstreamer/multi_stream_test.p/gstreamer_multi_stream_test.cpp.o -c ../test/gstreamer/gstreamer_multi_stream_test.cpp ../test/gstreamer/gstreamer_multi_stream_test.cpp: In member function ‘virtual int GstreamerMultiStreamTest::run()’: ../test/gstreamer/gstreamer_multi_stream_test.cpp:90:76: error: ‘GstPad* gst_element_get_request_pad(GstElement*, const gchar*)’ is deprecated: Use 'gst_element_request_pad_simple' instead [-Werror=deprecated-declarations] 90 | g_autoptr(GstPad) request_pad = gst_element_get_request_pad(libcameraSrc_, "src_%u"); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~ In file included from /usr/include/gstreamer-1.0/gst/gstbin.h:27, from /usr/include/gstreamer-1.0/gst/gst.h:35, from ../test/gstreamer/gstreamer_multi_stream_test.cpp:13: /usr/include/gstreamer-1.0/gst/gstelement.h:1042:25: note: declared here 1042 | GstPad* gst_element_get_request_pad (GstElement *element, const gchar *name); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~ cc1plus: all warnings being treated as errors Signed-off-by: Xavier Roumegue <xavier.roumegue@oss.nxp.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2021-11-24test: Convert to pragma onceKieran Bingham
Remove the verbose #ifndef/#define/#endif pattern for maintaining header idempotency, and replace it with a simple #pragma once. This simplifies the headers, and prevents redundant changes when header files get moved. Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>
2021-10-15test: Remove using namespace in header filesHirokazu Honda
"using namespace" in a header file propagates the namespace to the files including the header file. So it should be avoided. This removes "using namespace" in header files in test. Signed-off-by: Hirokazu Honda <hiroh@chromium.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2021-10-04test: gstreamer: Remove unnecessary header file includesVedant Paranjape
Remove header files which were not being used in the test code. The following headers were removed from the gstreamer_single_stream_test: - libcamera/base/utils.h - libcamera/internal/source_paths.h Signed-off-by: Vedant Paranjape <vedantparanjape160201@gmail.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com> Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
2021-09-24test: gstreamer: Add a test for gstreamer multi streamVedant Paranjape
This patch adds a test to test if multi stream using libcamera's gstreamer element works. Test will run only on devices that support multistream capture, eg., devices that use IPU3 and raspberrypi pipeline. This was tested on a Raspberry Pi 4B+. Signed-off-by: Vedant Paranjape <vedantparanjape160201@gmail.com> Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com> Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
2021-09-23test: gstreamer: Simplify elements' ownershipsVedant Paranjape
In gstreamer, when elements are created, usually a floating [1] reference is returned which simply means, there is no ownership transfer (yet). Once can simply check for NULL and return through an error path, without bothering to clean up. Hence, g_autoptr is not much of help here. If the NULL checks have been passed successfully, elements are ready to use. However, we must claim ownership/reference it before using them via g_object_ref_sink(). This patch build upon this principle and removes the g_autoptr from gstreamer test base class (gstreamer_test.cpp) whereever necessary to tide up the code. [1] https://gstreamer.freedesktop.org/documentation/additional/design/MT-refcounting.html?gi-language=c#refcounting1 Signed-off-by: Vedant Paranjape <vedantparanjape160201@gmail.com> Signed-off-by: Umang Jain <umang.jain@ideasonboard.com> Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com> Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
2021-09-23test: gstreamer: Simplify single stream test using functions from GstUtilsVedant Paranjape
Simplify memory handling and complexity of the test by using gst_parse_bin_from_description_full [1]. [1]: https://gstreamer.freedesktop.org/documentation/gstreamer/gstutils.html?gi-language=c#gst_parse_bin_from_description_full Signed-off-by: Vedant Paranjape <vedantparanjape160201@gmail.com> Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com> Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
2021-09-23test: gstreamer_single_stream_test: Fix memory leakVedant Paranjape
The test hold a valid reference to convert0_ and sink0_ but not released. This results in a memory leak and can be checked via valgrind. Drop the references with test cleanup() virtual function. Valgrind log (glib and gst suppression files were used): ==345380== LEAK SUMMARY: ==345380== definitely lost: 1,688 bytes in 2 blocks ==345380== indirectly lost: 7,069 bytes in 42 blocks The patch fixes the leaks reported by valgrind above to: ==348870== LEAK SUMMARY: ==348870== definitely lost: 0 bytes in 0 blocks ==348870== indirectly lost: 0 bytes in 0 blocks Signed-off-by: Vedant Paranjape <vedantparanjape160201@gmail.com> Signed-off-by: Umang Jain <umang.jain@ideasonboard.com> Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com> Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
2021-09-09test: gstreamer: Fix the destructor of GstreamerTest base classVedant Paranjape
The destructor tried to check if pipeline_ is a parent of libcameraSrc_. This was needed to be checked as if it is, cleanup of libcameraSrc_ would be handled by pipeline itself. Since, the destructor can be called anytime, even when pipeline_ hasn't been created, the use of pipeline_ to check if libcameraSrc_ has an ancestor as pipeline_ caused a segmentation fault. Fixes: f58768092277 ("test: gstreamer: Fix the destructor of GstreamerTest base class") Signed-off-by: Vedant Paranjape <vedantparanjape160201@gmail.com> Reviewed-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com> Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2021-09-08test: gstreamer: Factor out code into a base classVedant Paranjape
A lot of code used in the single stream test is boiler plate and common across every gstreamer test. Factor out this code into a base class called GstreamerTest. Also update the gstreamer_single_stream_test to use the GstreamerTest base class. Signed-off-by: Vedant Paranjape <vedantparanjape160201@gmail.com> Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com> Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
2021-08-26test: gstreamer: Disable gstreamer registry forksVedant Paranjape
ASan needs to be loaded first before gstreamer is loaded. This was not possible, so verify_asan_link_order was disabled. Better way to tackle this issue was disabling forks on the gstreamer side. verify_asan_link_order=0 disables the check on ASan side which checks if ASan was loaded before any other shared objects. Since, gstreamer spawns a child helper process while building the registry, we needed to disable this check. But with gst_registry_fork_set_enabled() it is possible to disable spawning this child helper process, so this ensures that ASan is loaded before any other shared object is loaded. Signed-off-by: Vedant Paranjape <vedantparanjape160201@gmail.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2021-08-26test: gstreamer: Clean up memory managementVedant Paranjape
This patch simplifies memory management, i.e., by replacing bare pointers with g_autoptr or g_autofree according to use case. While at it also update time representation of timeout variable with GST_SECOND. Signed-off-by: Vedant Paranjape <vedantparanjape160201@gmail.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2021-08-14test: gstreamer: Add test for gstreamer single streamVedant Paranjape
This patch adds a test to test if single stream using libcamera's gstreamer element works. We need to work around two distinct issues with ASan when enabled in the build: - glib has a known leak at initialization time. This is covered by the suppression file shipped with glib, but it's not clear how to use it automatically. For now, disable leak detection to avoid test failures. - GStreamer spawns a child process to scan plugins. If GStreamer is compiled without ASan (which is likely) but libcamera is, dlopen()ing the libcamera plugin will cause an ASan link order verification failure. Disable the verification child processes to work around the problem. This requires gcc 8 or newer. Signed-off-by: Vedant Paranjape <vedantparanjape160201@gmail.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Tested-by: Kieran Bingham <kieran.bingham@@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
ss="hl opt">(V4L2_CID_BRIGHTNESS, 1); dev_->setControls(&ctrls); delayed->reset(); /* Trigger the first frame start event */ delayed->applyControls(0); /* Test control without delay are set at once. */ for (unsigned int i = 1; i < 100; i++) { int32_t value = 100 + i; ctrls.set(V4L2_CID_BRIGHTNESS, value); delayed->push(ctrls); delayed->applyControls(i); ControlList result = delayed->get(i); int32_t brightness = result.get(V4L2_CID_BRIGHTNESS).get<int32_t>(); if (brightness != value) { cerr << "Failed single control without delay" << " frame " << i << " expected " << value << " got " << brightness << endl; return TestFail; } } return TestPass; } int singleControlWithDelay() { std::unordered_map<uint32_t, DelayedControls::ControlParams> delays = { { V4L2_CID_BRIGHTNESS, { 1, false } }, }; std::unique_ptr<DelayedControls> delayed = std::make_unique<DelayedControls>(dev_.get(), delays); ControlList ctrls; /* Reset control to value that will be first in test. */ int32_t expected = 4; ctrls.set(V4L2_CID_BRIGHTNESS, expected); dev_->setControls(&ctrls); delayed->reset(); /* Trigger the first frame start event */ delayed->applyControls(0); /* Test single control with delay. */ for (unsigned int i = 1; i < 100; i++) { int32_t value = 10 + i; ctrls.set(V4L2_CID_BRIGHTNESS, value); delayed->push(ctrls); delayed->applyControls(i); ControlList result = delayed->get(i); int32_t brightness = result.get(V4L2_CID_BRIGHTNESS).get<int32_t>(); if (brightness != expected) { cerr << "Failed single control with delay" << " frame " << i << " expected " << expected << " got " << brightness << endl; return TestFail; } expected = value; } return TestPass; } int dualControlsWithDelay(uint32_t startOffset) { static const unsigned int maxDelay = 2; std::unordered_map<uint32_t, DelayedControls::ControlParams> delays = { { V4L2_CID_BRIGHTNESS, { 1, false } }, { V4L2_CID_CONTRAST, { maxDelay, false } }, }; std::unique_ptr<DelayedControls> delayed = std::make_unique<DelayedControls>(dev_.get(), delays); ControlList ctrls; /* Reset control to value that will be first two frames in test. */ int32_t expected = 200; ctrls.set(V4L2_CID_BRIGHTNESS, expected); ctrls.set(V4L2_CID_CONTRAST, expected + 1); dev_->setControls(&ctrls); delayed->reset(); /* Trigger the first frame start event */ delayed->applyControls(startOffset); /* Test dual control with delay. */ for (unsigned int i = 1; i < 100; i++) { uint32_t frame = startOffset + i; int32_t value = 10 + i; ctrls.set(V4L2_CID_BRIGHTNESS, value); ctrls.set(V4L2_CID_CONTRAST, value + 1); delayed->push(ctrls); delayed->applyControls(frame); ControlList result = delayed->get(frame); int32_t brightness = result.get(V4L2_CID_BRIGHTNESS).get<int32_t>(); int32_t contrast = result.get(V4L2_CID_CONTRAST).get<int32_t>(); if (brightness != expected || contrast != expected + 1) { cerr << "Failed dual controls" << " frame " << frame << " brightness " << brightness << " contrast " << contrast << " expected " << expected << endl; return TestFail; } expected = i < maxDelay ? expected : value - 1; } return TestPass; } int dualControlsMultiQueue() { static const unsigned int maxDelay = 2; std::unordered_map<uint32_t, DelayedControls::ControlParams> delays = { { V4L2_CID_BRIGHTNESS, { 1, false } }, { V4L2_CID_CONTRAST, { maxDelay, false } } }; std::unique_ptr<DelayedControls> delayed = std::make_unique<DelayedControls>(dev_.get(), delays); ControlList ctrls; /* Reset control to value that will be first two frames in test. */ int32_t expected = 100; ctrls.set(V4L2_CID_BRIGHTNESS, expected); ctrls.set(V4L2_CID_CONTRAST, expected); dev_->setControls(&ctrls); delayed->reset(); /* Trigger the first frame start event */ delayed->applyControls(0); /* * Queue all controls before any fake frame start. Note we * can't queue up more then the delayed controls history size * which is 16. Where one spot is used by the reset control. */ for (unsigned int i = 0; i < 15; i++) { int32_t value = 10 + i; ctrls.set(V4L2_CID_BRIGHTNESS, value); ctrls.set(V4L2_CID_CONTRAST, value); delayed->push(ctrls); } /* Process all queued controls. */ for (unsigned int i = 1; i < 16; i++) { int32_t value = 10 + i - 1; delayed->applyControls(i); ControlList result = delayed->get(i); int32_t brightness = result.get(V4L2_CID_BRIGHTNESS).get<int32_t>(); int32_t contrast = result.get(V4L2_CID_CONTRAST).get<int32_t>(); if (brightness != expected || contrast != expected) { cerr << "Failed multi queue" << " frame " << i << " brightness " << brightness << " contrast " << contrast << " expected " << expected << endl; return TestFail; } expected = i < maxDelay ? expected : value - 1; } return TestPass; } int run() override { int ret; /* Test single control without delay. */ ret = singleControlNoDelay(); if (ret) return ret; /* Test single control with delay. */ ret = singleControlWithDelay(); if (ret) return ret; /* Test dual controls with different delays. */ ret = dualControlsWithDelay(0); if (ret) return ret; /* Test dual controls with non-zero sequence start. */ ret = dualControlsWithDelay(10000); if (ret) return ret; /* Test dual controls with sequence number wraparound. */ ret = dualControlsWithDelay(UINT32_MAX - 50); if (ret) return ret; /* Test control values produced faster than consumed. */ ret = dualControlsMultiQueue(); if (ret) return ret; return TestPass; } private: std::unique_ptr<DeviceEnumerator> enumerator_; std::shared_ptr<MediaDevice> media_; std::unique_ptr<V4L2VideoDevice> dev_; }; TEST_REGISTER(DelayedControlsTest)