From patchwork Thu Jan 17 15:05: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: 255 Return-Path: Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2E84C60B1D for ; Thu, 17 Jan 2019 16:05: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 relay5-d.mail.gandi.net (Postfix) with ESMTPSA id A107A1C0013; Thu, 17 Jan 2019 15:05:35 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Thu, 17 Jan 2019 16:05:34 +0100 Message-Id: <20190117150534.14424-1-jacopo@jmondi.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] test: pipeline: IPU3: Add IPU3 pipeline 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, 17 Jan 2019 15:05:36 -0000 Add test for the Intel IPU3 pipeline that lists all the cameras registered in the system and verifies the result matches the expected. This test is meant to be run on IPU3 platforms, it gets skipped otherwise. Signed-off-by: Jacopo Mondi --- This test will be the first pipeline specific one that makes possible to make a utility out of test/list-cameras. Tested on Soraka # ./test/pipeline/ipu3/ipu3_pipeline_test [6:45:07.633868891] DBG pipeline_handler.cpp:119 Registered pipeline handler "VIMC virtual driver pipeline handler" [6:45:07.634117644] DBG pipeline_handler.cpp:119 Registered pipeline handler "Intel IPU3 pipeline handler" [6:45:07.635352959] DBG device_enumerator.cpp:214 New media device "ipu3-imgu" created from /dev/media1 [6:45:07.635902044] DBG device_enumerator.cpp:214 New media device "ipu3-cio2" created from /dev/media0 [6:45:07.636375573] DBG device_enumerator.cpp:255 Successful match for media device "ipu3-cio2" [6:45:07.636391321] DBG device_enumerator.cpp:255 Successful match for media device "ipu3-imgu" [6:45:07.636416091] DBG media_device.cpp:672 ov13858 2-0010[0] -> ipu3-csi2 0[0]: 0 [6:45:07.636424396] DBG media_device.cpp:672 ov5670 4-0036[0] -> ipu3-csi2 1[0]: 0 [6:45:07.636457246] DBG media_device.cpp:672 ov13858 2-0010[0] -> ipu3-csi2 0[0]: 1 [6:45:07.636489583] INFO ipu3.cpp:249 Registered Camera[0] "ov13858 0" connected to CSI-2 receiver 0 [6:45:07.636500653] DBG media_device.cpp:672 ov5670 4-0036[0] -> ipu3-csi2 1[0]: 1 [6:45:07.636513116] INFO ipu3.cpp:249 Registered Camera[1] "ov5670 1" connected to CSI-2 receiver 1 [6:45:07.636522281] DBG ipu3.cpp:147 "Intel IPU3" pipeline handler initialized with 2 cameras registered [6:45:07.636540024] DBG pipeline_handler.cpp:150 Pipeline handler "Intel IPU3 pipeline handler" matched Found camera 'ov13858 0' Found camera 'ov5670 1' --- test/meson.build | 1 + test/pipeline/ipu3/ipu3_pipeline_test.cpp | 147 ++++++++++++++++++++++ test/pipeline/ipu3/meson.build | 11 ++ test/pipeline/meson.build | 1 + 4 files changed, 160 insertions(+) create mode 100644 test/pipeline/ipu3/ipu3_pipeline_test.cpp create mode 100644 test/pipeline/ipu3/meson.build create mode 100644 test/pipeline/meson.build -- 2.20.1 diff --git a/test/meson.build b/test/meson.build index 3215288..e168991 100644 --- a/test/meson.build +++ b/test/meson.build @@ -1,6 +1,7 @@ subdir('libtest') subdir('media_device') +subdir('pipeline') public_tests = [ ['event', 'event.cpp'], diff --git a/test/pipeline/ipu3/ipu3_pipeline_test.cpp b/test/pipeline/ipu3/ipu3_pipeline_test.cpp new file mode 100644 index 0000000..fc4c2a2 --- /dev/null +++ b/test/pipeline/ipu3/ipu3_pipeline_test.cpp @@ -0,0 +1,147 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2018, Google Inc. + * + * ipu3_pipeline_test.cpp - Intel IPU3 pipeline test + */ + +#include + +#include +#include +#include + +#include +#include + +#include "media_device.h" +#include "media_object.h" +#include "test.h" + +using namespace std; +using namespace libcamera; + +/* + * Verify that the Intel IPU3 pipeline handler gets matched and cameras + * are enumerated correctly. + * + * The test is supposed to be run on an IPU3 platform, otherwise it gets + * skipped. + * + * The test lists all cameras registered in the system, if any camera is + * available at all. + */ +class IPU3PipelineTest : public Test +{ +protected: + int init(); + int run(); + void cleanup(); + +private: + CameraManager *cameraManager_; + unsigned int sensors_; +}; + +int IPU3PipelineTest::init() +{ + const string devnode("/dev/media"); + bool cio2 = false; + bool imgu = false; + unsigned int i; + int ret; + + sensors_ = 0; + + /* + * Test all media devices from /dev/media0 to /dev/media256. + * Media device numbering might not be continue, and we cannot stop + * as soon as we hit a non accessible media device. + */ + for (i = 0; i < 256; i++) { + string mediadev = devnode + to_string(i); + struct stat pstat = { }; + + if (stat(mediadev.c_str(), &pstat)) + continue; + + MediaDevice dev(mediadev); + if (dev.open()) { + cerr << "Failed to open media device " << mediadev << endl; + return TestFail; + } + + if (dev.driver() == "ipu3-imgu") { + imgu = true; + } else if (dev.driver() == "ipu3-cio2") { + /* + * Camera sensor are connected to the CIO2 unit. + * Count how many sensors are connected in the system + * and later verify this matches the number of registered + * cameras. + */ + ret = dev.populate(); + if (ret) { + cerr << "Failed to populate media device " << dev.devnode() << endl; + return TestFail; + } + + vector entities = dev.entities(); + for (MediaEntity *entity : entities) { + if (entity->function() == MEDIA_ENT_F_CAM_SENSOR) + sensors_++; + } + + cio2 = true; + } + + dev.close(); + + if (imgu && cio2) + break; + } + + /* Not running on an IPU3 system: skip test. */ + if (!(imgu && cio2)) + return TestSkip; + + cameraManager_ = CameraManager::instance(); + ret = cameraManager_->start(); + if (ret) { + cerr << "Failed to start the CameraManager" << endl; + return TestFail; + } + + return 0; +} + +int IPU3PipelineTest::run() +{ + unsigned int cameras = 0; + vector cameraList = cameraManager_->list(); + for (auto name : cameraList) { + Camera *cam = cameraManager_->get(name); + if (!cam) { + cerr << "Failed to get camera '" << name << "' by name" << endl; + return TestFail; + } + + cout << "Found camera '" << cam->name() << "'" << endl; + cameras++; + } + + if (cameras != sensors_) { + cerr << cameras << " cameras registered, but " << sensors_ + << " were expected" << endl; + return TestFail; + } + + return TestPass; +} + +void IPU3PipelineTest::cleanup() +{ + cameraManager_->stop(); +} + +TEST_REGISTER(IPU3PipelineTest) diff --git a/test/pipeline/ipu3/meson.build b/test/pipeline/ipu3/meson.build new file mode 100644 index 0000000..caba5c7 --- /dev/null +++ b/test/pipeline/ipu3/meson.build @@ -0,0 +1,11 @@ +ipu3_test = [ + ['ipu3_pipeline_test', 'ipu3_pipeline_test.cpp'], +] + +foreach t : ipu3_test + exe = executable(t[0], t[1], + link_with : test_libraries, + include_directories : test_includes_internal) + + test(t[0], exe, suite: 'ipu3', is_parallel: false) +endforeach diff --git a/test/pipeline/meson.build b/test/pipeline/meson.build new file mode 100644 index 0000000..f434c79 --- /dev/null +++ b/test/pipeline/meson.build @@ -0,0 +1 @@ +subdir('ipu3')