{"id":19635,"url":"https://patchwork.libcamera.org/api/1.1/patches/19635/?format=json","web_url":"https://patchwork.libcamera.org/patch/19635/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20240305153058.1761020-4-nicolas@ndufresne.ca>","date":"2024-03-05T15:30:58","name":"[v2,3/3] test: gstreamer: Test memory lifetime","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"dbbac2f36a2be766ecea3b4c165f399b2ec299a6","submitter":{"id":30,"url":"https://patchwork.libcamera.org/api/1.1/people/30/?format=json","name":"Nicolas Dufresne","email":"nicolas@ndufresne.ca"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/19635/mbox/","series":[{"id":4203,"url":"https://patchwork.libcamera.org/api/1.1/series/4203/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=4203","date":"2024-03-05T15:30:55","name":"gstreamer: Fix a crash when memory outlives the pipeline","version":2,"mbox":"https://patchwork.libcamera.org/series/4203/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/19635/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/19635/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 97003C32AF\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  5 Mar 2024 15:31:14 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 1CD2562877;\n\tTue,  5 Mar 2024 16:31:14 +0100 (CET)","from madrid.collaboradmins.com (madrid.collaboradmins.com\n\t[46.235.227.194])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 8566B62878\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  5 Mar 2024 16:31:10 +0100 (CET)","from nicolas-tpx395.lan (cola.collaboradmins.com [195.201.22.229])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\tkey-exchange X25519 server-signature RSA-PSS (4096 bits)\n\tserver-digest SHA256)\n\t(No client certificate requested) (Authenticated sender: nicolas)\n\tby madrid.collaboradmins.com (Postfix) with ESMTPSA id E111037813B5; \n\tTue,  5 Mar 2024 15:31:09 +0000 (UTC)"],"From":"Nicolas Dufresne <nicolas@ndufresne.ca>","To":"libcamera-devel@lists.libcamera.org","Subject":"[PATCH v2 3/3] test: gstreamer: Test memory lifetime","Date":"Tue,  5 Mar 2024 10:30:58 -0500","Message-ID":"<20240305153058.1761020-4-nicolas@ndufresne.ca>","X-Mailer":"git-send-email 2.43.2","In-Reply-To":"<20240305153058.1761020-1-nicolas@ndufresne.ca>","References":"<20240305153058.1761020-1-nicolas@ndufresne.ca>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Cc":"Nicolas Dufresne <nicolas.dufresne@collabora.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"From: Nicolas Dufresne <nicolas.dufresne@collabora.com>\n\nTest that everything works fine if a buffer outlives the pipeline.\n\nSigned-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>\n---\n .../gstreamer_memory_lifetime_test.cpp        | 75 +++++++++++++++++++\n test/gstreamer/meson.build                    |  4 +-\n 2 files changed, 78 insertions(+), 1 deletion(-)\n create mode 100644 test/gstreamer/gstreamer_memory_lifetime_test.cpp","diff":"diff --git a/test/gstreamer/gstreamer_memory_lifetime_test.cpp b/test/gstreamer/gstreamer_memory_lifetime_test.cpp\nnew file mode 100644\nindex 00000000..6d932e9e\n--- /dev/null\n+++ b/test/gstreamer/gstreamer_memory_lifetime_test.cpp\n@@ -0,0 +1,75 @@\n+/* SPDX-License-Identifier: GPL-2.0-or-later */\n+/*\n+ * Copyright (C) 2024, Nicolas Dufresne\n+ *\n+ * gstreamer_memory_lifetime_test.cpp - GStreamer memory lifetime test\n+ */\n+\n+#include <iostream>\n+#include <unistd.h>\n+\n+#include <gst/app/app.h>\n+#include <gst/gst.h>\n+\n+#include \"gstreamer_test.h\"\n+#include \"test.h\"\n+\n+using namespace std;\n+\n+class GstreamerMemoryLifetimeTest : public GstreamerTest, public Test\n+{\n+public:\n+\tGstreamerMemoryLifetimeTest()\n+\t\t: GstreamerTest()\n+\t{\n+\t}\n+\n+protected:\n+\tint init() override\n+\t{\n+\t\tif (status_ != TestPass)\n+\t\t\treturn status_;\n+\n+\t\tappsink_ = gst_element_factory_make(\"appsink\", nullptr);\n+\t\tif (!appsink_) {\n+\t\t\tg_printerr(\"Your installation is missing 'appsink'\\n\");\n+\t\t\treturn TestFail;\n+\t\t}\n+\t\tg_object_ref_sink(appsink_);\n+\n+\t\treturn createPipeline();\n+\t}\n+\n+\tint run() override\n+\t{\n+\t\t/* Build the pipeline */\n+\t\tgst_bin_add_many(GST_BIN(pipeline_), libcameraSrc_, appsink_, nullptr);\n+\t\tif (gst_element_link(libcameraSrc_, appsink_) != TRUE) {\n+\t\t\tg_printerr(\"Elements could not be linked.\\n\");\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\tif (startPipeline() != TestPass)\n+\t\t\treturn TestFail;\n+\n+\t\tsample_ = gst_app_sink_try_pull_sample(GST_APP_SINK(appsink_), GST_SECOND * 5);\n+\t\tgst_element_set_state(pipeline_, GST_STATE_NULL);\n+\n+\t\tif (!sample_)\n+\t\t\treturn TestFail;\n+\n+\t\treturn TestPass;\n+\t}\n+\n+\tvoid cleanup() override\n+\t{\n+\t\tg_clear_pointer(&sample_, gst_sample_unref);\n+\t\tg_clear_object(&appsink_);\n+\t}\n+\n+private:\n+\tGstElement *appsink_;\n+\tGstSample *sample_;\n+};\n+\n+TEST_REGISTER(GstreamerMemoryLifetimeTest)\ndiff --git a/test/gstreamer/meson.build b/test/gstreamer/meson.build\nindex f3ba5a23..70609b88 100644\n--- a/test/gstreamer/meson.build\n+++ b/test/gstreamer/meson.build\n@@ -8,12 +8,14 @@ gstreamer_tests = [\n     {'name': 'single_stream_test', 'sources': ['gstreamer_single_stream_test.cpp']},\n     {'name': 'multi_stream_test', 'sources': ['gstreamer_multi_stream_test.cpp']},\n     {'name': 'device_provider_test', 'sources': ['gstreamer_device_provider_test.cpp']},\n+    {'name': 'memory_lifetime_test', 'sources': ['gstreamer_memory_lifetime_test.cpp']},\n ]\n gstreamer_dep = dependency('gstreamer-1.0', required : true)\n+gstapp_dep = dependency('gstreamer-app-1.0', required : true)\n \n foreach test : gstreamer_tests\n     exe = executable(test['name'], test['sources'], 'gstreamer_test.cpp',\n-                     dependencies : [libcamera_private, gstreamer_dep],\n+                     dependencies : [libcamera_private, gstreamer_dep, gstapp_dep],\n                      link_with : test_libraries,\n                      include_directories : test_includes_internal)\n \n","prefixes":["v2","3/3"]}