<div dir="ltr"><div>Hi Laurent,<br></div><div>I was unable to reproduce the issue with address sanitizer.</div><div><br></div><div>Steps I followed:</div><div>1) meson --reconfigure build -Db_sanitize=address</div><div>2) ninja -C build test</div><div><br></div><div>Regards,</div><div>Vedant<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Aug 13, 2021 at 8:07 PM Laurent Pinchart <<a href="mailto:laurent.pinchart@ideasonboard.com">laurent.pinchart@ideasonboard.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Fri, Aug 13, 2021 at 05:04:01PM +0300, Laurent Pinchart wrote:<br>
> On Fri, Aug 13, 2021 at 03:57:22PM +0300, Laurent Pinchart wrote:<br>
> > Hi Vedant,<br>
> > <br>
> > Thank you for the patch.<br>
> > <br>
> > On Fri, Aug 13, 2021 at 04:13:02PM +0530, Vedant Paranjape wrote:<br>
> > > This patch adds a test to test if single stream using<br>
> > > libcamera's gstreamer element works.<br>
> > > <br>
> > > Signed-off-by: Vedant Paranjape <<a href="mailto:vedantparanjape160201@gmail.com" target="_blank">vedantparanjape160201@gmail.com</a>><br>
> > > Reviewed-by: Paul Elder <<a href="mailto:paul.elder@ideasonboard.com" target="_blank">paul.elder@ideasonboard.com</a>><br>
> > > Reviewed-by: Kieran Bingham <<a href="mailto:kieran.bingham@ideasonboard.com" target="_blank">kieran.bingham@ideasonboard.com</a>><br>
> > > ---<br>
> > >  .../gstreamer_single_stream_test.cpp          | 153 ++++++++++++++++++<br>
> > >  test/gstreamer/meson.build                    |  19 +++<br>
> > >  test/meson.build                              |   1 +<br>
> > >  3 files changed, 173 insertions(+)<br>
> > >  create mode 100644 test/gstreamer/gstreamer_single_stream_test.cpp<br>
> > >  create mode 100644 test/gstreamer/meson.build<br>
> > > <br>
> > > diff --git a/test/gstreamer/gstreamer_single_stream_test.cpp b/test/gstreamer/gstreamer_single_stream_test.cpp<br>
> > > new file mode 100644<br>
> > > index 00000000..eecd3274<br>
> > > --- /dev/null<br>
> > > +++ b/test/gstreamer/gstreamer_single_stream_test.cpp<br>
> > > @@ -0,0 +1,153 @@<br>
> > > +/* SPDX-License-Identifier: GPL-2.0-or-later */<br>
> > > +/*<br>
> > > + * Copyright (C) 2021, Vedant Paranjape<br>
> > > + *<br>
> > > + * ipa_interface_test.cpp - Test the IPA interface<br>
> > > + */<br>
> > > +<br>
> > > +#include <iostream><br>
> > > +<br>
> > > +#include <libcamera/base/utils.h><br>
> > > +<br>
> > > +#include <gst/gst.h><br>
> > > +<br>
> > > +#include "test.h"<br>
> > > +<br>
> > > +using namespace std;<br>
> > > +<br>
> > > +class GstreamerSingleStreamTest : public Test<br>
> > > +{<br>
> > > +protected:<br>
> > > + int init() override<br>
> > > + {<br>
> > > +         /* Initialize GStreamer */<br>
> > > +         GError *errInit = nullptr;<br>
> > > +         if (!gst_init_check(nullptr, nullptr, &errInit)) {<br>
> > > +                 g_printerr("Could not initialize GStreamer: %s\n",<br>
> > > +                            errInit ? errInit->message : "unknown error");<br>
> > > +                 if (errInit)<br>
> > > +                         g_error_free(errInit);<br>
> > > +<br>
> > > +                 return TestFail;<br>
> > > +         }<br>
> > > +<br>
> > > +         /*<br>
> > > +         * Remove the system libcamera plugin, if any, and add the<br>
> > > +         * plugin from the build directory.<br>
> > > +         */<br>
> > <br>
> > Missing space before *<br>
> > <br>
> > > +         GstRegistry *registry = gst_registry_get();<br>
> > > +         GstPlugin *plugin = gst_registry_lookup(registry, "libgstlibcamera.so");<br>
> > > +         if (plugin) {<br>
> > > +                 gst_registry_remove_plugin(registry, plugin);<br>
> > > +                 gst_object_unref(plugin);<br>
> > > +         }<br>
> > > +         <br>
> > <br>
> > Extra blank spaces at the end of the line.<br>
> > <br>
> > > +         std::string path = std::string(libcamera::utils::libcameraBuildPath()<br>
> > > +                                 + "src/gstreamer");<br>
> > <br>
> > No need for calling the std::string constructor explictly,<br>
> > libcamera::utils::libcameraBuildPath() returns an std::string and the<br>
> > result of the operator+() call is also an std::string.<br>
> > <br>
> > You should #include "libcamera/internal/source_paths.h"" for<br>
> > libcamera::utils::libcameraBuildPath().<br>
> > <br>
> > I'll fix these small issues when applying.<br>
> > <br>
> > > +         if (!gst_registry_scan_path(registry, path.c_str())) {<br>
> > > +                 g_printerr("Failed to add plugin to registry\n");<br>
> > > +                 gst_deinit();<br>
> > > +                 return TestFail;<br>
> > > +         }<br>
> > > +<br>
> > > +         /* Create the elements */<br>
> > > +         libcameraSrc_ = gst_element_factory_make("libcamerasrc", "libcamera");<br>
<br>
And now I'm getting a failure here :-( When compiling with gcc, and with<br>
the meson b_sanitize option set to 'address', this call returns null.<br>
<br>
10/64 libcamera:gstreamer / single_stream_test                           FAIL            0.48s   exit status 1<br>
>>> MALLOC_PERTURB_=101 build/x86-gcc-11.1.0/test/gstreamer/single_stream_test<br>
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― ✀  ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――<br>
stderr:<br>
==14992==ASan runtime does not come first in initial library list; you should either link runtime to your application or manually preload it with LD_PRELOAD.<br>
==14993==ASan runtime does not come first in initial library list; you should either link runtime to your application or manually preload it with LD_PRELOAD.<br>
Not all elements could be created. 0x6290000241f0.0x61a000019950.0x61a00001a670.(nil)<br>
<br>
=================================================================<br>
==14990==ERROR: LeakSanitizer: detected memory leaks<br>
<br>
Direct leak of 16384 byte(s) in 1 object(s) allocated from:<br>
    #0 0x7f9daade1ac7 in __interceptor_malloc /var/tmp/portage/sys-devel/gcc-11.1.0-r2/work/gcc-11.1.0/libsanitizer/asan/asan_malloc_linux.cpp:145<br>
    #1 0x7f9da776a938 in g_malloc ../glib-2.68.3/glib/gmem.c:106<br>
<br>
SUMMARY: AddressSanitizer: 16384 byte(s) leaked in 1 allocation(s).<br>
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――<br>
<br>
11/64 libcamera:ipa / ipa_module_test                                    OK              0.08s<br>
<br>
Interestingly, if I run the test with<br>
<br>
LD_PRELOAD=/usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/libasan.so.6 ./test/gstreamer/single_stream_test<br>
<br>
then is runs fine:<br>
<br>
[25:59:46.412146534] [18711]  INFO IPAManager ipa_manager.cpp:138 libcamera is not installed. Adding '[...]/build/x86-gcc-11.1.0/src/ipa' to the IPA search path<br>
[25:59:46.413634330] [18711]  INFO Camera camera_manager.cpp:294 libcamera v0.0.0+2881-24c1e91b-dirty (2021-08-13T17:24:37+03:00)<br>
[25:59:46.663097368] [18714]  WARN CameraSensorProperties camera_sensor_properties.cpp:123 No static properties available for 'Sensor B'<br>
[25:59:46.663129122] [18714]  WARN CameraSensorProperties camera_sensor_properties.cpp:125 Please consider updating the camera sensor properties database<br>
[25:59:46.663156409] [18714]  WARN CameraSensor camera_sensor.cpp:403 'Sensor B': Failed to retrieve the camera location<br>
[25:59:46.664891182] [18714]  INFO IPAProxy ipa_proxy.cpp:130 libcamera is not installed. Loading IPA configuration from '[...]/src/ipa/vimc/data'<br>
[25:59:46.680563655] [18715]  INFO Camera camera.cpp:870 configuring streams: (0) 160x120-YUYV<br>
<br>
=================================================================<br>
==18711==ERROR: LeakSanitizer: detected memory leaks<br>
<br>
Direct leak of 16384 byte(s) in 1 object(s) allocated from:<br>
    #0 0x7effa6393ac7 in __interceptor_malloc /var/tmp/portage/sys-devel/gcc-11.1.0-r2/work/gcc-11.1.0/libsanitizer/asan/asan_malloc_linux.cpp:145<br>
    #1 0x7effa57be938 in g_malloc ../glib-2.68.3/glib/gmem.c:106<br>
<br>
SUMMARY: AddressSanitizer: 16384 byte(s) leaked in 1 allocation(s).<br>
<br>
The leak is a known glib issue, caught by valgrind too, so I'm not<br>
worried about it. The test failing to run is however a blocker.<br>
<br>
Vedant, can you reproduce the failure with the address sanitizer ?<br>
<br>
> > > +         convert0_ = gst_element_factory_make("videoconvert", "convert0");<br>
> > > +         sink0_ = gst_element_factory_make("fakesink", "sink0");<br>
> > > +<br>
> > > +         /* Create the empty pipeline_ */<br>
> > > +         pipeline_ = gst_pipeline_new("test-pipeline");<br>
> > > +<br>
> > > +         if (!pipeline_ || !convert0_ || !sink0_ || !libcameraSrc_) {<br>
> > > +                 g_printerr("Not all elements could be created. %p.%p.%p.%p\n",<br>
> > > +                            pipeline_, convert0_, sink0_, libcameraSrc_);<br>
> > > +                 if (pipeline_)<br>
> > > +                         gst_object_unref(pipeline_);<br>
> > > +                 if (convert0_)<br>
> > > +                         gst_object_unref(convert0_);<br>
> > > +                 if (sink0_)<br>
> > > +                         gst_object_unref(sink0_);<br>
> > > +                 if (libcameraSrc_)<br>
> > > +                         gst_object_unref(libcameraSrc_);<br>
> > > +                 gst_deinit();<br>
> > > +<br>
> > > +                 return TestFail;<br>
> > > +         }<br>
> > > +<br>
> > > +         return TestPass;<br>
> > > + }<br>
> > > +<br>
> > > + void cleanup() override<br>
> > > + {<br>
> > > +         gst_object_unref(pipeline_);<br>
> > > +         gst_deinit();<br>
> > > + }<br>
> > > +<br>
> > > + int run() override<br>
> > > + {<br>
> > > +         GstStateChangeReturn ret;<br>
> > > +         g_autoptr(GstBus) bus;<br>
> > > +         g_autoptr(GstMessage) msg;<br>
> <br>
> I've also had to initialize those two variables to nullptr, to fix<br>
> <br>
> In file included from /usr/lib/glib-2.0/include/glibconfig.h:9,<br>
>                  from /usr/include/glib-2.0/glib/gtypes.h:32,<br>
>                  from /usr/include/glib-2.0/glib/galloca.h:32,<br>
>                  from /usr/include/glib-2.0/glib.h:30,<br>
>                  from /usr/include/gstreamer-1.0/gst/gst.h:27,<br>
>                  from ../../test/gstreamer/gstreamer_single_stream_test.cpp:14:<br>
> /usr/include/glib-2.0/glib/gmacros.h: In member function ‘virtual int GstreamerSingleStreamTest::run()’:<br>
> /usr/include/glib-2.0/glib/gmacros.h:1045:7: error: ‘msg’ may be used uninitialized in this function [-Werror=maybe-uninitialized]<br>
>  1045 |     { if (_ptr) (cleanup) ((ParentName *) _ptr); }                                                              \<br>
>       |       ^~<br>
> ../../test/gstreamer/gstreamer_single_stream_test.cpp:108:25: note: ‘msg’ was declared here<br>
>   108 |   g_autoptr(GstMessage) msg;<br>
>       |                         ^~~<br>
> <br>
> when cross-compiling for ARM.<br>
> <br>
> > > +<br>
> > > +         /* Build the pipeline */<br>
> > > +         gst_bin_add_many(GST_BIN(pipeline_), libcameraSrc_, convert0_, sink0_, NULL);<br>
> > > +         if (gst_element_link_many(libcameraSrc_, convert0_, sink0_, NULL) != TRUE) {<br>
> > > +                 g_printerr("Elements could not be linked.\n");<br>
> > > +                 return TestFail;<br>
> > > +         }<br>
> > > +<br>
> > > +         /* Start playing */<br>
> > > +         ret = gst_element_set_state(pipeline_, GST_STATE_PLAYING);<br>
> > > +         if (ret == GST_STATE_CHANGE_FAILURE) {<br>
> > > +                 g_printerr("Unable to set the pipeline to the playing state.\n");<br>
> > > +                 return TestFail;<br>
> > > +         }<br>
> > > +<br>
> > > +         /* Wait until error or EOS or timeout after 2 seconds */<br>
> > > +         GstClockTime timeout = 2000000000;<br>
> > > +         bus = gst_element_get_bus(pipeline_);<br>
> > > +         msg = gst_bus_timed_pop_filtered(bus, timeout,<br>
> > > +                                          GstMessageType((uint)GST_MESSAGE_ERROR | (uint)GST_MESSAGE_EOS));<br>
> > > +         gst_element_set_state(pipeline_, GST_STATE_NULL);<br>
> > > +<br>
> > > +         /* Parse error message */<br>
> > > +         if (msg == NULL)<br>
> > > +                 return TestPass;<br>
> > > +<br>
> > > +         switch (GST_MESSAGE_TYPE(msg)) {<br>
> > > +         case GST_MESSAGE_ERROR:<br>
> > > +                 gstreamer_print_error(msg);<br>
> > > +                 break;<br>
> > > +         case GST_MESSAGE_EOS:<br>
> > > +                 g_print("End-Of-Stream reached.\n");<br>
> > > +                 break;<br>
> > > +         default:<br>
> > > +                 g_printerr("Unexpected message received.\n");<br>
> > > +                 break;<br>
> > > +         }<br>
> > > +<br>
> > > +         return TestFail;<br>
> > > + }<br>
> > > +<br>
> > > +private:<br>
> > > + void gstreamer_print_error(GstMessage *msg)<br>
> > > + {<br>
> > > +         GError *err;<br>
> > > +         gchar *debug_info;<br>
> > > +<br>
> > > +         gst_message_parse_error(msg, &err, &debug_info);<br>
> > > +         g_printerr("Error received from element %s: %s\n",<br>
> > > +                    GST_OBJECT_NAME(msg->src), err->message);<br>
> > > +         g_printerr("Debugging information: %s\n",<br>
> > > +                    debug_info ? debug_info : "none");<br>
> > > +         g_clear_error(&err);<br>
> > > +         g_free(debug_info);<br>
> > > + }<br>
> > > +<br>
> > > + GstElement *pipeline_;<br>
> > > + GstElement *libcameraSrc_;<br>
> > > + GstElement *convert0_;<br>
> > > + GstElement *sink0_;<br>
> > > +};<br>
> > > +<br>
> > > +TEST_REGISTER(GstreamerSingleStreamTest)<br>
> > > diff --git a/test/gstreamer/meson.build b/test/gstreamer/meson.build<br>
> > > new file mode 100644<br>
> > > index 00000000..b99aa0da<br>
> > > --- /dev/null<br>
> > > +++ b/test/gstreamer/meson.build<br>
> > > @@ -0,0 +1,19 @@<br>
> > > +# SPDX-License-Identifier: CC0-1.0<br>
> > > +<br>
> > > +if not gst_enabled<br>
> > > +    subdir_done()<br>
> > > +endif<br>
> > > +<br>
> > > +gstreamer_tests = [<br>
> > > +    ['single_stream_test',   'gstreamer_single_stream_test.cpp'],<br>
> > > +]<br>
> > > +gstreamer_dep = dependency('gstreamer-1.0', required: true)<br>
> > > +<br>
> > > +foreach t : gstreamer_tests<br>
> > > +    exe = executable(t[0], t[1],<br>
> > > +                     dependencies : [libcamera_private, gstreamer_dep],<br>
> > > +                     link_with : test_libraries,<br>
> > > +                     include_directories : test_includes_internal)<br>
> > > +<br>
> > > +    test(t[0], exe, suite : 'gstreamer', is_parallel : false)<br>
> > > +endforeach<br>
> > > diff --git a/test/meson.build b/test/meson.build<br>
> > > index 3bceb5df..d0466f17 100644<br>
> > > --- a/test/meson.build<br>
> > > +++ b/test/meson.build<br>
> > > @@ -11,6 +11,7 @@ subdir('libtest')<br>
> > >  <br>
> > >  subdir('camera')<br>
> > >  subdir('controls')<br>
> > > +subdir('gstreamer')<br>
> > >  subdir('ipa')<br>
> > >  subdir('ipc')<br>
> > >  subdir('log')<br>
<br>
-- <br>
Regards,<br>
<br>
Laurent Pinchart<br>
</blockquote></div>