{"id":13271,"url":"https://patchwork.libcamera.org/api/1.1/patches/13271/?format=json","web_url":"https://patchwork.libcamera.org/patch/13271/","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":"<20210810074004.1743947-1-vedantparanjape160201@gmail.com>","date":"2021-08-10T07:40:04","name":"[libcamera-devel,v2] test: gstreamer: Add unit test to test gstreamer single stream working","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"feae889854fa0142c6c54e489f41dd8972c20049","submitter":{"id":85,"url":"https://patchwork.libcamera.org/api/1.1/people/85/?format=json","name":"Vedant Paranjape","email":"vedantparanjape160201@gmail.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/13271/mbox/","series":[{"id":2327,"url":"https://patchwork.libcamera.org/api/1.1/series/2327/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2327","date":"2021-08-10T07:40:04","name":"[libcamera-devel,v2] test: gstreamer: Add unit test to test gstreamer single stream working","version":2,"mbox":"https://patchwork.libcamera.org/series/2327/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/13271/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/13271/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 BB354BD87D\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 10 Aug 2021 07:40:23 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3E533687FA;\n\tTue, 10 Aug 2021 09:40:23 +0200 (CEST)","from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com\n\t[IPv6:2607:f8b0:4864:20::1034])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0678E687DE\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 10 Aug 2021 09:40:21 +0200 (CEST)","by mail-pj1-x1034.google.com with SMTP id\n\tu21-20020a17090a8915b02901782c36f543so3075348pjn.4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 10 Aug 2021 00:40:21 -0700 (PDT)","from localhost.localdomain ([1.186.167.156])\n\tby smtp.googlemail.com with ESMTPSA id\n\tx13sm21283912pjh.30.2021.08.10.00.40.18\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tTue, 10 Aug 2021 00:40:19 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=gmail.com header.i=@gmail.com\n\theader.b=\"WLPJsSiS\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;\n\th=from:to:cc:subject:date:message-id:mime-version\n\t:content-transfer-encoding;\n\tbh=ohIHYh+hvPin3VR5tt+Zzz2wT/loe4y8VkJXfVe1m6E=;\n\tb=WLPJsSiSVj4RZlodnb2FL6/VQlwPEqQsdRNjmyhp1OyHuEWOg3O7nGdVbKB43ZXkcu\n\t7kGY/U/KWsPcDMKCVSQfiTJ4QEoPnq2BM1BQwVhVEcvpP/3LJv2tYHKAXYhmcqbV9ftd\n\tGhNuMT3DybOSRVdlPk8fsbhHdhPLuhx7E40AtoPdhvTZfnqTQBN4JYF0U4teNSWOOyr7\n\tqd8C49AGrkPWdFsgqEFR6syCR6RAfVdRrtGlrtic0UDu/+oFxYS8mKP3Pm+TPsmJi2sq\n\tnkDWUx98zXtIybiAxORmK5Bjr5vIwAtigP0jqi7oGguKVntQgy/TcfR9GHPhP3HJKO7o\n\t6A0A==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version\n\t:content-transfer-encoding;\n\tbh=ohIHYh+hvPin3VR5tt+Zzz2wT/loe4y8VkJXfVe1m6E=;\n\tb=e92VRfbPLA0+MpNi3/r5gSSv3sRr+m31BhsJNiB5z8rrk9iFiV7boWtd7US6G43wrP\n\tlFfLa3mCBFzTArAojmpQf1Z67uICUTevefCaOel+KHXyDF498+fGLwSAfFPub0fWrRZ8\n\tw/Qb3mib9VEM29u9IVToE7poIv8O501VqB/ZQe7vGLo5depCSoAbr7I7PJdnDIs/bvWX\n\tCsZEB4dN0uVOs8ihKbHOp4n8yX7BniEvOaIjmALVX1y9JwxpnSUBjTs2r9PXlWdW5Nga\n\tfFV407GxMqGnFkVrgF1gpp5yhAJX89tBzccHob/FhagJZTlAjA9t1h8uihlX3cIHtKm6\n\tEhdA==","X-Gm-Message-State":"AOAM531jQ5Gq1kHxvcDotZUUAvUm++lHFTnjv/YKl2iSRspmf7WHUfnd\n\tyy1kDgzOEwjCjcKL2QqlxHIvVLBsJFeCww==","X-Google-Smtp-Source":"ABdhPJxm43mgEE80icDnaU/d7YI8+en/4ElnA5aBCe3UTvnsqmQZx0Zk1Bc+BSTSNBFPZh9e29XU9g==","X-Received":"by 2002:a63:2585:: with SMTP id l127mr10669pgl.318.1628581220245;\n\tTue, 10 Aug 2021 00:40:20 -0700 (PDT)","From":"Vedant Paranjape <vedantparanjape160201@gmail.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Tue, 10 Aug 2021 13:10:04 +0530","Message-Id":"<20210810074004.1743947-1-vedantparanjape160201@gmail.com>","X-Mailer":"git-send-email 2.25.1","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v2] test: gstreamer: Add unit test to test\n\tgstreamer single stream working","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":"Vedant Paranjape <vedantparanjape160201@gmail.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"This patch adds unit test to test if single stream using\nlibcamera's gstreamer element works.\n\nSigned-off-by: Vedant Paranjape <vedantparanjape160201@gmail.com>\n---\n .../gstreamer_single_stream_test.cpp          | 118 ++++++++++++++++++\n test/gstreamer/meson.build                    |  15 +++\n test/meson.build                              |   1 +\n 3 files changed, 134 insertions(+)\n create mode 100644 test/gstreamer/gstreamer_single_stream_test.cpp\n create mode 100644 test/gstreamer/meson.build","diff":"diff --git a/test/gstreamer/gstreamer_single_stream_test.cpp b/test/gstreamer/gstreamer_single_stream_test.cpp\nnew file mode 100644\nindex 00000000..c249a048\n--- /dev/null\n+++ b/test/gstreamer/gstreamer_single_stream_test.cpp\n@@ -0,0 +1,118 @@\n+#include <iostream>\n+#include <gst/gst.h>\n+\n+#include \"test.h\"\n+\n+using namespace std;\n+\n+class GstreamerSingleStreamTest: public Test\n+{\n+protected:\n+    GstElement *pipeline, *libcamera_src, *convert0, *sink0;\n+    GstBus *bus;\n+    GstMessage *msg;\n+    GstStateChangeReturn ret;\n+\n+    int GstreamerPrintError(GstMessage *msg_)\n+    {\n+        int TestResult = TestPass;\n+\n+        if (msg_ != NULL) {\n+            GError *err;\n+            gchar *debug_info;\n+\n+            switch (GST_MESSAGE_TYPE(msg_)) {\n+                case GST_MESSAGE_ERROR:\n+                    gst_message_parse_error(msg_, &err, &debug_info);\n+                    g_printerr(\"Error received from element %s: %s\\n\", GST_OBJECT_NAME(msg_->src), err->message);\n+                    g_printerr(\"Debugging information: %s\\n\", debug_info ? debug_info : \"none\");\n+                    g_clear_error(&err);\n+                    g_free(debug_info);\n+                    TestResult = TestFail;\n+                    break;\n+                case GST_MESSAGE_EOS:\n+                    g_printerr(\"End-Of-Stream reached.\\n\");\n+                    TestResult = TestFail;\n+                    break;\n+                default:\n+                    /* We should not reach here because we only asked for ERRORs and EOS */\n+                    g_printerr(\"Unexpected message received.\\n\");\n+                    TestResult = TestFail;\n+                    break;\n+            }\n+        }\n+\n+        return TestResult;\n+    }\n+\n+    int init() override\n+    {\n+        /* Initialize GStreamer */\n+        GError *err_init = nullptr;\n+        if (!gst_init_check(nullptr, nullptr, &err_init)) {\n+            g_printerr (\"Could not initialize GStreamer: %s\\n\", err_init ? err_init->message : \"unknown error occurred\");\n+            if (err_init) {\n+                g_error_free(err_init);\n+            }\n+\n+            return TestFail;\n+        }\n+\n+        /* Create the elements */\n+        libcamera_src = gst_element_factory_make(\"libcamerasrc\", \"libcamera\");\n+        convert0 = gst_element_factory_make(\"videoconvert\", \"convert0\");\n+        sink0 = gst_element_factory_make(\"autovideosink\", \"sink0\");\n+\n+        /* Create the empty pipeline */\n+        pipeline = gst_pipeline_new(\"test-pipeline\");\n+\n+        if (!pipeline || !convert0 || !sink0 || !libcamera_src) {\n+            g_printerr(\"Not all elements could be created.\\n\");\n+            return TestFail;\n+        }\n+\n+        return TestPass;\n+    }\n+\n+    void cleanup() override\n+    {\n+        gst_message_unref(msg);\n+        gst_object_unref(bus);\n+        gst_element_set_state(pipeline, GST_STATE_NULL);\n+        gst_object_unref(pipeline);\n+    }\n+\n+    int run() override\n+    {\n+        /* Build the pipeline */\n+        gst_bin_add_many(GST_BIN(pipeline), libcamera_src, convert0, sink0, NULL);\n+        if (gst_element_link_many(libcamera_src, convert0, sink0, NULL) != TRUE) {\n+            g_printerr(\"Elements could not be linked (1).\\n\");\n+            gst_object_unref(pipeline);\n+            return TestFail;\n+        }\n+\n+        /* Start playing */\n+        ret = gst_element_set_state(pipeline, GST_STATE_PLAYING);\n+        if (ret == GST_STATE_CHANGE_FAILURE) {\n+            g_printerr(\"Unable to set the pipeline to the playing state.\\n\");\n+            gst_object_unref(pipeline);\n+            return TestFail;\n+        }\n+\n+        /* Wait until error or EOS or timeout after 2 seconds*/\n+        GstClockTime timeout = 2000000000;\n+        bus = gst_element_get_bus(pipeline);\n+        msg = gst_bus_timed_pop_filtered(bus, timeout,\n+                                    GstMessageType((uint)GST_MESSAGE_ERROR | (uint)GST_MESSAGE_EOS));\n+\n+        /* Parse error message */\n+        if (GstreamerPrintError(msg) == TestFail) {\n+            return TestFail;\n+        }\n+\n+        return TestPass;\n+    }\n+};\n+\n+TEST_REGISTER(GstreamerSingleStreamTest)\ndiff --git a/test/gstreamer/meson.build b/test/gstreamer/meson.build\nnew file mode 100644\nindex 00000000..36643d4a\n--- /dev/null\n+++ b/test/gstreamer/meson.build\n@@ -0,0 +1,15 @@\n+# SPDX-License-Identifier: CC0-1.0\n+\n+gstreamer_tests = [\n+    ['single_stream_test',   'gstreamer_single_stream_test.cpp'],\n+]\n+gstreamer_dep = dependency('gstreamer-1.0', required: true)\n+\n+foreach t : gstreamer_tests\n+    exe = executable(t[0], t[1],\n+                     dependencies : [libcamera_private, gstreamer_dep],\n+                     link_with : test_libraries,\n+                     include_directories : test_includes_internal)\n+\n+    test(t[0], exe, suite : 'gstreamer', is_parallel : false)\n+endforeach\ndiff --git a/test/meson.build b/test/meson.build\nindex 3bceb5df..d0466f17 100644\n--- a/test/meson.build\n+++ b/test/meson.build\n@@ -11,6 +11,7 @@ subdir('libtest')\n \n subdir('camera')\n subdir('controls')\n+subdir('gstreamer')\n subdir('ipa')\n subdir('ipc')\n subdir('log')\n","prefixes":["libcamera-devel","v2"]}