From patchwork Thu Jan 3 17:38:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 149 Return-Path: Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D16D160B3D for ; Thu, 3 Jan 2019 18:39:04 +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 relay9-d.mail.gandi.net (Postfix) with ESMTPSA id 67C0DFF804; Thu, 3 Jan 2019 17:39:04 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Thu, 3 Jan 2019 18:38:59 +0100 Message-Id: <20190103173859.22624-6-jacopo@jmondi.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190103173859.22624-1-jacopo@jmondi.org> References: <20190103173859.22624-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 5/5] test: MediaDevice: Add link exercize 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: Thu, 03 Jan 2019 17:39:05 -0000 Add test function to exercize the link handling abilities of the media device. Signed-off-by: Jacopo Mondi --- test/media_device/media_device_test.cpp | 101 ++++++++++++++++++++++++ 1 file changed, 101 insertions(+) diff --git a/test/media_device/media_device_test.cpp b/test/media_device/media_device_test.cpp index c482b2e..99da3a6 100644 --- a/test/media_device/media_device_test.cpp +++ b/test/media_device/media_device_test.cpp @@ -42,8 +42,104 @@ private: void printMediaGraph(const MediaDevice &media, ostream &os); void printLinkFlags(const MediaLink *link, ostream &os); void printNode(const MediaPad *pad, ostream &os); + + int exercizeLinks(const MediaDevice &media); + int testLink(const MediaDevice &media, MediaLink *link); }; +int MediaDeviceTest::testLink(const MediaDevice &media, MediaLink *link) +{ + MediaPad *sourcePad = link->source(); + MediaEntity *source = sourcePad->entity(); + MediaPad *sinkPad = link->sink(); + MediaEntity *sink = sinkPad->entity(); + + cerr << "Test link handling interface on link: " + << source->name() << ":" << sourcePad->index() + << " -> " << sink->name() << ":" << sinkPad->index() << "\n"; + + /* Test the link() functions to be consistent. */ + MediaLink *alink = media.link(source->name(), sourcePad->index(), + sink->name(), sinkPad->index()); + if (link != alink) + return -EINVAL; + + alink = media.link(source, sourcePad->index(), + sink, sinkPad->index()); + if (link != alink) + return -EINVAL; + + alink = media.link(sourcePad, sinkPad); + if (link != alink) + return -EINVAL; + + /* Fine, we get consisten results... now try to manipulate the link. */ + int ret = link->enable(true); + if (ret) + return ret; + + ret = link->enable(false); + if (ret) { + if (!(link->flags() & MEDIA_LNK_FL_IMMUTABLE)) + return ret; + } + + return 0; + +} + +/* + * Exercize the link handling interface. + * Try to get existing and non-existing links, and try to enable + * disable link. + * + * WARNING: this test will change the link between pads on the media + * device it runs on, potentially modying the behavior of the system + * where the test is run on. + */ +int MediaDeviceTest::exercizeLinks(const MediaDevice &media) +{ + auto entities = media.entities(); + + /* First of all, reset all links in the media graph. */ + for (MediaEntity *ent : entities) { + cerr << "Disable all links in entity: " << ent->name() << "\n"; + + for (MediaPad *pad : ent->pads()) { + if (pad->flags() & MEDIA_PAD_FL_SINK) + continue; + + for (MediaLink *link : pad->links()) { + int ret = link->enable(false); + if (ret) { + if (!(link->flags() & + MEDIA_LNK_FL_IMMUTABLE)) + return ret; + } + } + } + } + + + /* + * Exercize the link handling interface. + */ + for (MediaEntity *ent : entities) { + for (MediaPad *pad : ent->pads()) { + if (pad->flags() & MEDIA_PAD_FL_SINK) + continue; + + for (MediaLink *link : pad->links()) { + int ret = testLink(media, link); + if (ret) + return ret; + } + } + } + + return 0; +} + void MediaDeviceTest::printNode(const MediaPad *pad, ostream &os) { const MediaEntity *entity = pad->entity(); @@ -136,6 +232,11 @@ int MediaDeviceTest::testMediaDevice(const string devnode) /* Run tests in sequence. */ printMediaGraph(dev, cerr); + + ret = exercizeLinks(dev); + if (ret) + return ret; + /* TODO: add more tests here. */ dev.close();