From patchwork Sat Jan 12 14:14:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 213 Return-Path: Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7581F60C69 for ; Sat, 12 Jan 2019 15:14:35 +0100 (CET) X-Originating-IP: 2.224.242.101 Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay2-d.mail.gandi.net (Postfix) with ESMTPSA id CB68140004; Sat, 12 Jan 2019 14:14:34 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Sat, 12 Jan 2019 15:14:34 +0100 Message-Id: <20190112141436.1562-2-jacopo@jmondi.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190112141436.1562-1-jacopo@jmondi.org> References: <20190112141436.1562-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 1/3] test: media_device: Convert to foreach X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 12 Jan 2019 14:14:35 -0000 From: Kieran Bingham Prevent duplication of boilerplate code as the suite grows by establishing the foreach pattern in the media_device test suite. Signed-off-by: Kieran Bingham Signed-off-by: Jacopo Mondi --- test/media_device/meson.build | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/test/media_device/meson.build b/test/media_device/meson.build index a7ebed1..40f9ffa 100644 --- a/test/media_device/meson.build +++ b/test/media_device/meson.build @@ -1,5 +1,11 @@ -media_device_test = executable('media_device_test', 'media_device_test.cpp', - link_with : test_libraries, - include_directories : test_includes_internal) +media_device_tests = [ + ['media_device_test', 'media_device_test.cpp'], +] -test('Media Device Test', media_device_test) +foreach t : media_device_tests + exe = executable(t[0], t[1], + link_with : test_libraries, + include_directories : test_includes_internal) + + test(t[0], exe, suite: 'media_device', is_parallel: false) +endforeach From patchwork Sat Jan 12 14:14:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 214 Return-Path: Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4CD6060C6A for ; Sat, 12 Jan 2019 15:14:36 +0100 (CET) X-Originating-IP: 2.224.242.101 Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay2-d.mail.gandi.net (Postfix) with ESMTPSA id A2D8140003; Sat, 12 Jan 2019 14:14:35 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Sat, 12 Jan 2019 15:14:35 +0100 Message-Id: <20190112141436.1562-3-jacopo@jmondi.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190112141436.1562-1-jacopo@jmondi.org> References: <20190112141436.1562-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 2/3] test: media_device: Make MediaDeviceTest a MediaDevicePrintTest X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 12 Jan 2019 14:14:36 -0000 As a new class for test link handling will be added as a separate test, it makes no sense to have a generic "MediaDeviceTest" class. Rename it in "MediaDevicePrintTest", and make it run only printing test. Reviewed-by: Laurent Pinchart Signed-off-by: Jacopo Mondi --- ...e_test.cpp => media_device_print_test.cpp} | 31 +++++++++---------- test/media_device/meson.build | 2 +- 2 files changed, 15 insertions(+), 18 deletions(-) rename test/media_device/{media_device_test.cpp => media_device_print_test.cpp} (79%) diff --git a/test/media_device/media_device_test.cpp b/test/media_device/media_device_print_test.cpp similarity index 79% rename from test/media_device/media_device_test.cpp rename to test/media_device/media_device_print_test.cpp index c482b2e..13af722 100644 --- a/test/media_device/media_device_test.cpp +++ b/test/media_device/media_device_print_test.cpp @@ -1,10 +1,8 @@ /* SPDX-License-Identifier: GPL-2.0-or-later */ /* - * Copyright (C) 2018, Google Inc. + * Copyright (C) 2018-2019, Google Inc. * - * media_device_test.cpp - Tests for the media device class. - * - * Test library for the media device class. + * media_device_print_test.cpp - Print out media devices */ #include @@ -20,16 +18,16 @@ using namespace libcamera; using namespace std; /* - * MediaDeviceTest object: runs a sequence of tests on all media - * devices found in the system. + * MediaDevicePrintTest takes all media devices found in the system and print + * them out to verify correctness. * * If no accessible media device is found, the test is skipped. */ -class MediaDeviceTest : public Test +class MediaDevicePrintTest : public Test { public: - MediaDeviceTest() { } - ~MediaDeviceTest() { } + MediaDevicePrintTest() { } + ~MediaDevicePrintTest() { } protected: int init() { return 0; } @@ -44,7 +42,7 @@ private: void printNode(const MediaPad *pad, ostream &os); }; -void MediaDeviceTest::printNode(const MediaPad *pad, ostream &os) +void MediaDevicePrintTest::printNode(const MediaPad *pad, ostream &os) { const MediaEntity *entity = pad->entity(); @@ -52,7 +50,7 @@ void MediaDeviceTest::printNode(const MediaPad *pad, ostream &os) << pad->index() << "]"; } -void MediaDeviceTest::printLinkFlags(const MediaLink *link, ostream &os) +void MediaDevicePrintTest::printLinkFlags(const MediaLink *link, ostream &os) { unsigned int flags = link->flags(); @@ -68,7 +66,7 @@ void MediaDeviceTest::printLinkFlags(const MediaLink *link, ostream &os) * For each entity in the media graph, printout links directed to its sinks * and source pads. */ -void MediaDeviceTest::printMediaGraph(const MediaDevice &media, ostream &os) +void MediaDevicePrintTest::printMediaGraph(const MediaDevice &media, ostream &os) { os << "\n" << media.driver() << " - " << media.devnode() << "\n\n"; @@ -110,7 +108,7 @@ void MediaDeviceTest::printMediaGraph(const MediaDevice &media, ostream &os) } /* Test a single media device. */ -int MediaDeviceTest::testMediaDevice(const string devnode) +int MediaDevicePrintTest::testMediaDevice(const string devnode) { MediaDevice dev(devnode); int ret; @@ -134,9 +132,8 @@ int MediaDeviceTest::testMediaDevice(const string devnode) if (ret) return ret; - /* Run tests in sequence. */ + /* Print out the media graph. */ printMediaGraph(dev, cerr); - /* TODO: add more tests here. */ dev.close(); @@ -145,7 +142,7 @@ int MediaDeviceTest::testMediaDevice(const string devnode) /* Run tests on all media devices. */ #define MAX_MEDIA_DEV 256 -int MediaDeviceTest::run() +int MediaDevicePrintTest::run() { const string devnode("/dev/media"); unsigned int i; @@ -171,4 +168,4 @@ int MediaDeviceTest::run() return ret; } -TEST_REGISTER(MediaDeviceTest); +TEST_REGISTER(MediaDevicePrintTest); diff --git a/test/media_device/meson.build b/test/media_device/meson.build index 40f9ffa..e4bedb7 100644 --- a/test/media_device/meson.build +++ b/test/media_device/meson.build @@ -1,5 +1,5 @@ media_device_tests = [ - ['media_device_test', 'media_device_test.cpp'], + ['media_device_print_test', 'media_device_print_test.cpp'], ] foreach t : media_device_tests From patchwork Sat Jan 12 14:14:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 215 Return-Path: Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2D29560C6A for ; Sat, 12 Jan 2019 15:14:37 +0100 (CET) X-Originating-IP: 2.224.242.101 Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay2-d.mail.gandi.net (Postfix) with ESMTPSA id 7367A40004; Sat, 12 Jan 2019 14:14:36 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Sat, 12 Jan 2019 15:14:36 +0100 Message-Id: <20190112141436.1562-4-jacopo@jmondi.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190112141436.1562-1-jacopo@jmondi.org> References: <20190112141436.1562-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 3/3] test: media_device: Add link handling test X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 12 Jan 2019 14:14:37 -0000 Add a test unit that exercise link handling on the VIMC media graph. Reviewed-by: Niklas Söderlund Signed-off-by: Jacopo Mondi --- test/media_device/media_device_link_test.cpp | 246 +++++++++++++++++++ test/media_device/meson.build | 1 + 2 files changed, 247 insertions(+) create mode 100644 test/media_device/media_device_link_test.cpp diff --git a/test/media_device/media_device_link_test.cpp b/test/media_device/media_device_link_test.cpp new file mode 100644 index 0000000..2297e33 --- /dev/null +++ b/test/media_device/media_device_link_test.cpp @@ -0,0 +1,246 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2019, Google Inc. + * + * media_device_link_test.cpp - Tests link handling on VIMC media device + */ +#include +#include + +#include "device_enumerator.h" +#include "media_device.h" + +#include "test.h" + +using namespace libcamera; +using namespace std; + +/* + * This link test requires a vimc device in order to exercise the + * MediaObject link handling API on a graph with a predetermined topology. + * + * vimc is a Media Controller kernel driver that creates virtual devices. + * From a userspace point of view they appear as normal media controller + * devices, but are not backed by any particular piece of hardware. They can + * thus be used for testing purpose without depending on a particular hardware + * platform. + * + * If no vimc device is found (most likely because the vimc driver is not + * loaded) the test is skipped. + */ + +class MediaDeviceLinkTest : public Test +{ + int init() + { + enumerator = unique_ptr(DeviceEnumerator::create()); + if (!enumerator) { + cerr << "Failed to create device enumerator" << endl; + return TestFail; + } + + if (enumerator->enumerate()) { + cerr << "Failed to enumerate media devices" << endl; + return TestFail; + } + + DeviceMatch dm("vimc"); + dev_ = enumerator->search(dm); + if (!dev_) { + cerr << "No VIMC media device found: skip test" << endl; + return TestSkip; + } + + dev_->acquire(); + + if (dev_->open()) { + cerr << "Failed to open media device at " + << dev_->devnode() << endl; + return TestFail; + } + + return 0; + } + + int run() + { + /* + * First of all disable all links in the media graph to + * ensure we start from a known state. + */ + if (dev_->disableLinks()) { + cerr << "Failed to disable all links in the media graph"; + return TestFail; + } + + /* + * Test if link can be consistently retrieved through the + * different methods the media device offers. + */ + string linkName("'Debayer A':[1] -> 'Scaler':[0]'"); + MediaLink *link = dev_->link("Debayer A", 1, "Scaler", 0); + if (!link) { + cerr << "Unable to find link: " << linkName + << " using lookup by name" << endl; + return TestFail; + } + + MediaEntity *source = dev_->getEntityByName("Debayer A"); + if (!source) { + cerr << "Unable to find entity: 'Debayer A'" << endl; + return TestFail; + } + + MediaEntity *sink = dev_->getEntityByName("Scaler"); + if (!sink) { + cerr << "Unable to find entity: 'Scaler'" << endl; + return TestFail; + } + + MediaLink *link2 = dev_->link(source, 1, sink, 0); + if (!link2) { + cerr << "Unable to find link: " << linkName + << " using lookup by entity" << endl; + return TestFail; + } + + if (link != link2) { + cerr << "Link lookup by name and by entity don't match" + << endl; + return TestFail; + } + + link2 = dev_->link(source->getPadByIndex(1), + sink->getPadByIndex(0)); + if (!link2) { + cerr << "Unable to find link: " << linkName + << " using lookup by pad" << endl; + return TestFail; + } + + if (link != link2) { + cerr << "Link lookup by name and by pad don't match" + << endl; + return TestFail; + } + + /* After reset the link shall not be enabled. */ + if (link->flags() & MEDIA_LNK_FL_ENABLED) { + cerr << "Link " << linkName + << " should not be enabled after a device reset" + << endl; + return TestFail; + } + + /* Enable the link and test if enabling was successful. */ + if (link->setEnabled(true)) { + cerr << "Failed to enable link: " << linkName + << endl; + return TestFail; + } + + if (!(link->flags() & MEDIA_LNK_FL_ENABLED)) { + cerr << "Link " << linkName + << " was enabled but it is reported as disabled" + << endl; + return TestFail; + } + + /* Disable the link and test if disabling was successful. */ + if (link->setEnabled(false)) { + cerr << "Failed to disable link: " << linkName + << endl; + return TestFail; + } + + if (link->flags() & MEDIA_LNK_FL_ENABLED) { + cerr << "Link " << linkName + << " was disabled but it is reported as enabled" + << endl; + return TestFail; + } + + /* Try to get a non existing link. */ + linkName = "'Sensor A':[1] -> 'Scaler':[0]"; + link = dev_->link("Sensor A", 1, "Scaler", 0); + if (link) { + cerr << "Link lookup for " << linkName + << " succeeded but link does not exist" + << endl; + return TestFail; + } + + /* Now get an immutable link and try to disable it. */ + linkName = "'Sensor A':[0] -> 'Raw Capture 0':[0]"; + link = dev_->link("Sensor A", 0, "Raw Capture 0", 0); + if (!link) { + cerr << "Unable to find link: " << linkName + << " using lookup by name" << endl; + return TestFail; + } + + if (!(link->flags() & MEDIA_LNK_FL_IMMUTABLE)) { + cerr << "Link " << linkName + << " should be 'IMMUTABLE'" << endl; + return TestFail; + } + + /* Disabling an immutable link shall fail. */ + if (!link->setEnabled(false)) { + cerr << "Disabling immutable link " << linkName + << " succeeded but should have failed" << endl; + return TestFail; + } + + /* + * Enable an disabled link, and verify it is disabled again + * after disabling all links in the media graph. + */ + linkName = "'Debayer B':[1] -> 'Scaler':[0]'"; + link = dev_->link("Debayer B", 1, "Scaler", 0); + if (!link) { + cerr << "Unable to find link: " << linkName + << " using lookup by name" << endl; + return TestFail; + } + + if (link->setEnabled(true)) { + cerr << "Failed to enable link: " << linkName + << endl; + return TestFail; + } + + if (!(link->flags() & MEDIA_LNK_FL_ENABLED)) { + cerr << "Link " << linkName + << " was enabled but it is reported as disabled" + << endl; + return TestFail; + } + + if (dev_->disableLinks()) { + cerr << "Failed to disable all links in the media graph"; + return TestFail; + } + + if (link->flags() & MEDIA_LNK_FL_ENABLED) { + cerr << "All links in the media graph have been disabled" + << " but link " << linkName + << " is still reported as enabled" << endl; + return TestFail; + } + + return 0; + } + + void cleanup() + { + dev_->close(); + dev_->release(); + } + +private: + unique_ptr enumerator; + MediaDevice *dev_; +}; + +TEST_REGISTER(MediaDeviceLinkTest); diff --git a/test/media_device/meson.build b/test/media_device/meson.build index e4bedb7..d91a022 100644 --- a/test/media_device/meson.build +++ b/test/media_device/meson.build @@ -1,5 +1,6 @@ media_device_tests = [ ['media_device_print_test', 'media_device_print_test.cpp'], + ['media_device_link_test', 'media_device_link_test.cpp'], ] foreach t : media_device_tests