From patchwork Tue Jul 4 21:23:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 18783 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 9FF78BE175 for ; Tue, 4 Jul 2023 21:23:57 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id F04E361E38; Tue, 4 Jul 2023 23:23:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1688505837; bh=ZRxtU64Lq5Z6ozMj9enwYurqidHV6K4Wt3ozvBqOMNU=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=BOb53Ld/biWu9Yr3xdFuiSgxkkOVEfrg4P1n1GOQrFhKcA+KALfSezhj0Tua7f+02 5SsuZWjSF1c5U6RVzMVispYhau5uXhgAn3tkqZEla0m2lBpudwEDBjU2jJTbrs/wFB FgchtVhiQPQr7K++Ffd1lqXXf6mCmp9mkDiPubrzdAnDac8Mnf1TEHAsI9qNKJTsN7 SoXN+zAv2nepkt5UgvKQF1fpiAPMPXhEOVHBvjMM4nfNXtiZG/vyc+oQTEGXYuh3vN Ybdm55hCRuBEVftxgdy3ikZfNK66DsOHVcfGsFIWujVoj/XmMJm8mj64mOOp0XPZQi vGWq+EGxgYbQA== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id DEAD160384 for ; Tue, 4 Jul 2023 23:23:54 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="NzqEAEbZ"; dkim-atps=neutral Received: from umang.jainideasonboard.com (85-160-42-71.reb.o2.cz [85.160.42.71]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 068BD8C1; Tue, 4 Jul 2023 23:23:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1688505790; bh=ZRxtU64Lq5Z6ozMj9enwYurqidHV6K4Wt3ozvBqOMNU=; h=From:To:Cc:Subject:Date:From; b=NzqEAEbZEmcTjWEqcn+gH2/ACauPj1Z9GWMue+uG0frAZVjCmJKRWr1wi1StGNEKx lBvoqmylwEWpnNdtpqSF+/6zZRFNBz/05Zq0QEn77YEcpuvVCorCnk5iy0CYvY8dr1 4YMlfDu6cvvQXSzCA9DPjwKevt8R3jrBUVEIMSY4= To: libcamera-devel@lists.libcamera.org Date: Tue, 4 Jul 2023 23:23:43 +0200 Message-Id: <20230704212343.78465-1-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2] tests: gstreamer: Test cameras' enumeration from GstDeviceProvider 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: , X-Patchwork-Original-From: Umang Jain via libcamera-devel From: Umang Jain Reply-To: Umang Jain Cc: nicolas.dufresne@collabora.com Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Test the enumeration of the cameras through GstDeviceProvider against the libcamera camera manager. Signed-off-by: Umang Jain Reviewed-by: Nicolas Dufresne --- Changes in v2: - Split out to dedicated device provider test - Use gst_device_provider_factory_get_by_name() to find libcameraprovider - Use "camera-name" to compare camera ids with camera-manager instead of gst_device_get_display_name() --- .../gstreamer_device_provider_test.cpp | 77 +++++++++++++++++++ test/gstreamer/meson.build | 1 + 2 files changed, 78 insertions(+) create mode 100644 test/gstreamer/gstreamer_device_provider_test.cpp diff --git a/test/gstreamer/gstreamer_device_provider_test.cpp b/test/gstreamer/gstreamer_device_provider_test.cpp new file mode 100644 index 00000000..69e110c7 --- /dev/null +++ b/test/gstreamer/gstreamer_device_provider_test.cpp @@ -0,0 +1,77 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright 2023 Umang Jain + * + * gstreamer_single_stream_test.cpp - GStreamer single stream capture test + */ + +#include + +#include +#include + +#include "gstreamer_test.h" +#include "test.h" + +using namespace std; + +class GstreamerDeviceProviderTest : public GstreamerTest, public Test +{ +public: + GstreamerDeviceProviderTest() + : GstreamerTest() + { + } + +protected: + int init() override + { + if (status_ != TestPass) + return status_; + + return TestPass; + } + + int run() override + { + g_autoptr(GstDeviceProvider) provider; + GList *devices, *l; + std::vector cameraNames; + std::unique_ptr cm + = std::make_unique(); + + cm->start(); + for (auto &camera : cm->cameras()) + cameraNames.push_back(camera->id()); + cm->stop(); + cm.reset(); + + provider = gst_device_provider_factory_get_by_name("libcameraprovider"); + devices = gst_device_provider_get_devices(provider); + + for (l = devices; l != NULL; l = g_list_next(l)) { + GstDevice *device = GST_DEVICE(l->data); + g_autofree gchar *gst_name; + bool matched = false; + + g_autoptr(GstElement) element = gst_device_create_element(device, NULL); + g_object_get(element, "camera-name", &gst_name, NULL); + + for (auto name : cameraNames) { + if (strcmp(name.c_str(), gst_name) == 0) { + matched = true; + break; + } + } + + if (!matched) + return TestFail; + } + + g_list_free_full(devices, (GDestroyNotify)gst_object_unref); + + return TestPass; + } +}; + +TEST_REGISTER(GstreamerDeviceProviderTest) diff --git a/test/gstreamer/meson.build b/test/gstreamer/meson.build index 74572586..0904ee0d 100644 --- a/test/gstreamer/meson.build +++ b/test/gstreamer/meson.build @@ -7,6 +7,7 @@ endif gstreamer_tests = [ {'name': 'single_stream_test', 'sources': ['gstreamer_single_stream_test.cpp']}, {'name': 'multi_stream_test', 'sources': ['gstreamer_multi_stream_test.cpp']}, + {'name': 'device_provider_test', 'sources': ['gstreamer_device_provider_test.cpp']}, ] gstreamer_dep = dependency('gstreamer-1.0', required: true)