From patchwork Tue Aug 10 07:40:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vedant Paranjape X-Patchwork-Id: 13271 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id BB354BD87D for ; Tue, 10 Aug 2021 07:40:23 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3E533687FA; Tue, 10 Aug 2021 09:40:23 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="WLPJsSiS"; dkim-atps=neutral Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0678E687DE for ; Tue, 10 Aug 2021 09:40:21 +0200 (CEST) Received: by mail-pj1-x1034.google.com with SMTP id u21-20020a17090a8915b02901782c36f543so3075348pjn.4 for ; Tue, 10 Aug 2021 00:40:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ohIHYh+hvPin3VR5tt+Zzz2wT/loe4y8VkJXfVe1m6E=; b=WLPJsSiSVj4RZlodnb2FL6/VQlwPEqQsdRNjmyhp1OyHuEWOg3O7nGdVbKB43ZXkcu 7kGY/U/KWsPcDMKCVSQfiTJ4QEoPnq2BM1BQwVhVEcvpP/3LJv2tYHKAXYhmcqbV9ftd GhNuMT3DybOSRVdlPk8fsbhHdhPLuhx7E40AtoPdhvTZfnqTQBN4JYF0U4teNSWOOyr7 qd8C49AGrkPWdFsgqEFR6syCR6RAfVdRrtGlrtic0UDu/+oFxYS8mKP3Pm+TPsmJi2sq nkDWUx98zXtIybiAxORmK5Bjr5vIwAtigP0jqi7oGguKVntQgy/TcfR9GHPhP3HJKO7o 6A0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ohIHYh+hvPin3VR5tt+Zzz2wT/loe4y8VkJXfVe1m6E=; b=e92VRfbPLA0+MpNi3/r5gSSv3sRr+m31BhsJNiB5z8rrk9iFiV7boWtd7US6G43wrP lFfLa3mCBFzTArAojmpQf1Z67uICUTevefCaOel+KHXyDF498+fGLwSAfFPub0fWrRZ8 w/Qb3mib9VEM29u9IVToE7poIv8O501VqB/ZQe7vGLo5depCSoAbr7I7PJdnDIs/bvWX CsZEB4dN0uVOs8ihKbHOp4n8yX7BniEvOaIjmALVX1y9JwxpnSUBjTs2r9PXlWdW5Nga fFV407GxMqGnFkVrgF1gpp5yhAJX89tBzccHob/FhagJZTlAjA9t1h8uihlX3cIHtKm6 EhdA== X-Gm-Message-State: AOAM531jQ5Gq1kHxvcDotZUUAvUm++lHFTnjv/YKl2iSRspmf7WHUfnd yy1kDgzOEwjCjcKL2QqlxHIvVLBsJFeCww== X-Google-Smtp-Source: ABdhPJxm43mgEE80icDnaU/d7YI8+en/4ElnA5aBCe3UTvnsqmQZx0Zk1Bc+BSTSNBFPZh9e29XU9g== X-Received: by 2002:a63:2585:: with SMTP id l127mr10669pgl.318.1628581220245; Tue, 10 Aug 2021 00:40:20 -0700 (PDT) Received: from localhost.localdomain ([1.186.167.156]) by smtp.googlemail.com with ESMTPSA id x13sm21283912pjh.30.2021.08.10.00.40.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Aug 2021 00:40:19 -0700 (PDT) From: Vedant Paranjape 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 Subject: [libcamera-devel] [PATCH v2] test: gstreamer: Add unit test to test gstreamer single stream working X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vedant Paranjape Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" This patch adds unit test to test if single stream using libcamera's gstreamer element works. Signed-off-by: Vedant Paranjape --- .../gstreamer_single_stream_test.cpp | 118 ++++++++++++++++++ test/gstreamer/meson.build | 15 +++ test/meson.build | 1 + 3 files changed, 134 insertions(+) create mode 100644 test/gstreamer/gstreamer_single_stream_test.cpp create mode 100644 test/gstreamer/meson.build diff --git a/test/gstreamer/gstreamer_single_stream_test.cpp b/test/gstreamer/gstreamer_single_stream_test.cpp new file mode 100644 index 00000000..c249a048 --- /dev/null +++ b/test/gstreamer/gstreamer_single_stream_test.cpp @@ -0,0 +1,118 @@ +#include +#include + +#include "test.h" + +using namespace std; + +class GstreamerSingleStreamTest: public Test +{ +protected: + GstElement *pipeline, *libcamera_src, *convert0, *sink0; + GstBus *bus; + GstMessage *msg; + GstStateChangeReturn ret; + + int GstreamerPrintError(GstMessage *msg_) + { + int TestResult = TestPass; + + if (msg_ != NULL) { + GError *err; + gchar *debug_info; + + switch (GST_MESSAGE_TYPE(msg_)) { + case GST_MESSAGE_ERROR: + gst_message_parse_error(msg_, &err, &debug_info); + g_printerr("Error received from element %s: %s\n", GST_OBJECT_NAME(msg_->src), err->message); + g_printerr("Debugging information: %s\n", debug_info ? debug_info : "none"); + g_clear_error(&err); + g_free(debug_info); + TestResult = TestFail; + break; + case GST_MESSAGE_EOS: + g_printerr("End-Of-Stream reached.\n"); + TestResult = TestFail; + break; + default: + /* We should not reach here because we only asked for ERRORs and EOS */ + g_printerr("Unexpected message received.\n"); + TestResult = TestFail; + break; + } + } + + return TestResult; + } + + int init() override + { + /* Initialize GStreamer */ + GError *err_init = nullptr; + if (!gst_init_check(nullptr, nullptr, &err_init)) { + g_printerr ("Could not initialize GStreamer: %s\n", err_init ? err_init->message : "unknown error occurred"); + if (err_init) { + g_error_free(err_init); + } + + return TestFail; + } + + /* Create the elements */ + libcamera_src = gst_element_factory_make("libcamerasrc", "libcamera"); + convert0 = gst_element_factory_make("videoconvert", "convert0"); + sink0 = gst_element_factory_make("autovideosink", "sink0"); + + /* Create the empty pipeline */ + pipeline = gst_pipeline_new("test-pipeline"); + + if (!pipeline || !convert0 || !sink0 || !libcamera_src) { + g_printerr("Not all elements could be created.\n"); + return TestFail; + } + + return TestPass; + } + + void cleanup() override + { + gst_message_unref(msg); + gst_object_unref(bus); + gst_element_set_state(pipeline, GST_STATE_NULL); + gst_object_unref(pipeline); + } + + int run() override + { + /* Build the pipeline */ + gst_bin_add_many(GST_BIN(pipeline), libcamera_src, convert0, sink0, NULL); + if (gst_element_link_many(libcamera_src, convert0, sink0, NULL) != TRUE) { + g_printerr("Elements could not be linked (1).\n"); + gst_object_unref(pipeline); + return TestFail; + } + + /* Start playing */ + ret = gst_element_set_state(pipeline, GST_STATE_PLAYING); + if (ret == GST_STATE_CHANGE_FAILURE) { + g_printerr("Unable to set the pipeline to the playing state.\n"); + gst_object_unref(pipeline); + return TestFail; + } + + /* Wait until error or EOS or timeout after 2 seconds*/ + GstClockTime timeout = 2000000000; + bus = gst_element_get_bus(pipeline); + msg = gst_bus_timed_pop_filtered(bus, timeout, + GstMessageType((uint)GST_MESSAGE_ERROR | (uint)GST_MESSAGE_EOS)); + + /* Parse error message */ + if (GstreamerPrintError(msg) == TestFail) { + return TestFail; + } + + return TestPass; + } +}; + +TEST_REGISTER(GstreamerSingleStreamTest) diff --git a/test/gstreamer/meson.build b/test/gstreamer/meson.build new file mode 100644 index 00000000..36643d4a --- /dev/null +++ b/test/gstreamer/meson.build @@ -0,0 +1,15 @@ +# SPDX-License-Identifier: CC0-1.0 + +gstreamer_tests = [ + ['single_stream_test', 'gstreamer_single_stream_test.cpp'], +] +gstreamer_dep = dependency('gstreamer-1.0', required: true) + +foreach t : gstreamer_tests + exe = executable(t[0], t[1], + dependencies : [libcamera_private, gstreamer_dep], + link_with : test_libraries, + include_directories : test_includes_internal) + + test(t[0], exe, suite : 'gstreamer', is_parallel : false) +endforeach diff --git a/test/meson.build b/test/meson.build index 3bceb5df..d0466f17 100644 --- a/test/meson.build +++ b/test/meson.build @@ -11,6 +11,7 @@ subdir('libtest') subdir('camera') subdir('controls') +subdir('gstreamer') subdir('ipa') subdir('ipc') subdir('log')