From patchwork Wed Dec 23 12:10:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Fricke X-Patchwork-Id: 10699 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 0AB5DC0F1A for ; Wed, 23 Dec 2020 12:11:19 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C9A1A615D2; Wed, 23 Dec 2020 13:11:18 +0100 (CET) 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="ojRcBXpa"; dkim-atps=neutral Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 17F8F60527 for ; Wed, 23 Dec 2020 13:11:18 +0100 (CET) Received: by mail-wr1-x42a.google.com with SMTP id y17so18399732wrr.10 for ; Wed, 23 Dec 2020 04:11:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Qg0t00pVXRsV+cmgeCBaO1VXuxMMdE09WxMARf1DwwU=; b=ojRcBXpa8RM+JhC4d44S65X2iWxP95sUsnjyLWFvgzweBGp3HpIfwvZxrJezjkfVE2 06+TachmrHYyXAVYe84lL5uxLiTQ8GtACsoDllCu++Q2LYW0QH9/weubZ7Ebust/vh4n 7RDs5YvB1esJg0qynWkmp5JfvjzU4bQoMl/cdMkEsVB+AksnUyju3sL//XMIofhC2Sqk B1YGmsPgeS3amnncEZPOu9wiq2lrZ+g0nJ6ktIP9ljF9AeZD4NX9zeiOq+EOI3a8jWci pqrFlw/2CZsd0KWw6m2CzuLOiGXYmtVASe5mKWCNSqiNPLMxRV0dBARI1oN59IzBoI6z tetg== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=Qg0t00pVXRsV+cmgeCBaO1VXuxMMdE09WxMARf1DwwU=; b=Wy+tf7XJg0DGiUKyCvAX83khwyTuR/nNs0s6upt4/0Idx72fLAQSUIxAy2tVneokpm C0S/CUrnwxgP1KJ1tZaILsWR7PS1Tyu5rcnRb9Sz2Kr+k9ik9VuMgdkp7tznaJJxOCnn 8lYlL7Owl+3r6uNPS6mIQzfgFQYM4Fzs/nWElZUK6IW2kGyYEgCC4qz7FpZagPsiEHjW ik3DHFvh0Au/y32qQWQTnZpFnXB0MUemrma55N7nVU9shdpYbVLHaEiyHWwy4SBHwa1l mLQrw7hhvbwalHpN9aODpl1AzwcYkFgrikA/hjio2z5zRzRWbD7rMT/qacumMIM/y9if WwcA== X-Gm-Message-State: AOAM531iPHHG85sgMlCcqFsyhz3mCVY2V2ur4x20WhIp9ODUw650vJOA tuYAkvVuFRgmNMZLGnGWf+gFHl2F6549xQ== X-Google-Smtp-Source: ABdhPJywjHGXpSOEjNX5bwNgGXrukB9TkqnKJUz9zDAtrD8+pNsuRiarKcmwW/GPbOd9WrruG15dZw== X-Received: by 2002:adf:e54a:: with SMTP id z10mr29462944wrm.1.1608725477848; Wed, 23 Dec 2020 04:11:17 -0800 (PST) Received: from basti.fritz.box (p200300d1ff2be200e1a8f8b471c12212.dip0.t-ipconnect.de. [2003:d1:ff2b:e200:e1a8:f8b4:71c1:2212]) by smtp.gmail.com with ESMTPSA id u6sm36787733wrm.90.2020.12.23.04.11.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Dec 2020 04:11:17 -0800 (PST) From: Sebastian Fricke To: libcamera-devel@lists.libcamera.org Date: Wed, 23 Dec 2020 13:10:55 +0100 Message-Id: <20201223121055.14178-3-sebastian.fricke.linux@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201223121055.14178-1-sebastian.fricke.linux@gmail.com> References: <20201223121055.14178-1-sebastian.fricke.linux@gmail.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/2] test: Add unit tests for the BayerFormat class 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Test all of the present methods including the newly implemented `fromV4L2PixelFormat`. Signed-off-by: Sebastian Fricke --- test/bayer_format.cpp | 154 ++++++++++++++++++++++++++++++++++++++++++ test/meson.build | 1 + 2 files changed, 155 insertions(+) create mode 100644 test/bayer_format.cpp diff --git a/test/bayer_format.cpp b/test/bayer_format.cpp new file mode 100644 index 00000000..4d7c7ca1 --- /dev/null +++ b/test/bayer_format.cpp @@ -0,0 +1,154 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2020, Sebastian Fricke + * + * bayer_format.cpp - BayerFormat class tests + */ +#include +#include +#include + +#include "test.h" + +using namespace std; +using namespace libcamera; + +class BayerFormatTest : public Test +{ +protected: + int run() + { + /* + * TEST 1: A empty bayer format has to be invalid. + */ + BayerFormat bay_fmt = BayerFormat(); + if (bay_fmt.isValid()) { + cout << "TEST 1: FAIL: An empty bayer format " + << "has to be invalid." << endl; + return TestFail; + } + + /* + * TEST 2: A correct bayer format has to be valid. + */ + bay_fmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::None); + if (!bay_fmt.isValid()) { + cout << "TEST 2: FAIL: A correct bayer format " + << "has to be valid." << endl; + return TestFail; + } + + /* + * TEST 3: Create a bayer format with a V4L2PixelFormat and + * check if we get the same format after converting + * back to the V4L2 Format. + */ + V4L2PixelFormat pix_fmt = V4L2PixelFormat(V4L2_PIX_FMT_SBGGR8); + bay_fmt = BayerFormat(pix_fmt); + V4L2PixelFormat found_pix_fmt = bay_fmt.toV4L2PixelFormat(); + if (found_pix_fmt != pix_fmt) { + cout << "TEST 3: FAIL: expected: " + << pix_fmt.toString() << " got: " + << found_pix_fmt.toString() << endl; + return TestFail; + } + + /* + * TEST 4: Check if we get the expected bayer format BGGR8 + * when we convert the V4L2PixelFormat + * (V4L2_PIX_FMT_SBGGR8) to a bayer format. + */ + BayerFormat exp_bay_fmt = BayerFormat(BayerFormat::BGGR, 8, + BayerFormat::None); + BayerFormat found_bay_fmt = bay_fmt.fromV4L2PixelFormat( + pix_fmt); + if (found_bay_fmt.order != exp_bay_fmt.order || + found_bay_fmt.bitDepth != exp_bay_fmt.bitDepth || + found_bay_fmt.packing != exp_bay_fmt.packing) { + cout << "TEST 4: FAIL: Expected bayer format 'BGGR8'," + << "got: " << found_bay_fmt.toString() << endl; + return TestFail; + } + + /* TEST 5: Confirm that a V4L2PixelFormat that is not found in + * the conversion table, doesn't yield a bayer format. + */ + exp_bay_fmt = BayerFormat(); + found_bay_fmt = BayerFormat(); + V4L2PixelFormat unknownn_pix_fmt = V4L2PixelFormat( + V4L2_PIX_FMT_BGRA444); + found_bay_fmt = bay_fmt.fromV4L2PixelFormat(unknownn_pix_fmt); + if (found_bay_fmt.order != exp_bay_fmt.order || + found_bay_fmt.bitDepth != exp_bay_fmt.bitDepth || + found_bay_fmt.packing != exp_bay_fmt.packing) { + cout << "TEST 5: FAIL: expected empty bayer format got: " + << found_bay_fmt.toString() << endl; + return TestFail; + } + + /* + * TEST 6: Test if a valid bayer format can be converted to a + * string representation. + */ + if (bay_fmt.toString() != "BGGR-8") { + cout << "TEST 6: FAIL: String representation != 'BGGR8' (is: " + << bay_fmt.toString() << " ) " << endl; + return TestFail; + } + + /* + * TEST 7: Determine if an empty bayer format results in no + * string representation. + */ + bay_fmt = BayerFormat(); + if (bay_fmt.toString() != "INVALID") { + cout << "TEST 7: FAIL: String representation != 'INVALID' (is: " + << bay_fmt.toString() << " ) " << endl; + return TestFail; + } + + /* + * TEST 8: Perform a horizontal Flip and make sure that the + * order is adjusted accordingly. + */ + bay_fmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::None); + BayerFormat h_flip_fmt = bay_fmt.transform(Transform::HFlip); + if (h_flip_fmt.toString() != "GBRG-8") { + cout << "TEST 8: FAIL: horizontal flip of 'BGGR-8' " + << "should result in 'GBRG-8', got: " + << h_flip_fmt.toString() << endl; + return TestFail; + } + + + /* + * TEST 9: Perform a horizontal Flip and make sure that the + * order is adjusted accordingly. + */ + bay_fmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::None); + BayerFormat v_flip_fmt = bay_fmt.transform(Transform::VFlip); + if (v_flip_fmt.toString() != "GRBG-8") { + cout << "TEST 9: FAIL: vertical flip of 'BGGR-8' should " + << "result in 'GRBG-8', got: " + << v_flip_fmt.toString() << endl; + return TestFail; + } + + /* + * TEST 10: Perform a transposition and make sure that + * nothing changes. + */ + bay_fmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::None); + BayerFormat t_fmt = bay_fmt.transform(Transform::Transpose); + if (t_fmt.toString() != "BGGR-8") { + cout << "TEST 10: FAIL: transposition not supported " + << "format should be 'BGGR-8', got: " + << t_fmt.toString() << endl; + return TestFail; + } + + return TestPass; + } +}; + +TEST_REGISTER(BayerFormatTest); diff --git a/test/meson.build b/test/meson.build index 0a1d434e..e985b0a0 100644 --- a/test/meson.build +++ b/test/meson.build @@ -23,6 +23,7 @@ public_tests = [ ] internal_tests = [ + ['bayer-format', 'bayer_format.cpp'], ['byte-stream-buffer', 'byte-stream-buffer.cpp'], ['camera-sensor', 'camera-sensor.cpp'], ['event', 'event.cpp'],