{"id":11028,"url":"https://patchwork.libcamera.org/api/1.1/patches/11028/?format=json","web_url":"https://patchwork.libcamera.org/patch/11028/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20210126184854.46156-6-sebastian.fricke@posteo.net>","date":"2021-01-26T18:48:54","name":"[libcamera-devel,v3,5/5] test: Add unit tests for the BayerFormat class","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"0bcfde4da2594701dac829f99ce2fca593852283","submitter":{"id":78,"url":"https://patchwork.libcamera.org/api/1.1/people/78/?format=json","name":"Sebastian Fricke","email":"sebastian.fricke@posteo.net"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/11028/mbox/","series":[{"id":1613,"url":"https://patchwork.libcamera.org/api/1.1/series/1613/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1613","date":"2021-01-26T18:48:49","name":"Improve BayerFormat class","version":3,"mbox":"https://patchwork.libcamera.org/series/1613/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/11028/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/11028/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 15EF5C0F2B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 26 Jan 2021 18:49:18 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id DABB468328;\n\tTue, 26 Jan 2021 19:49:17 +0100 (CET)","from mout02.posteo.de (mout02.posteo.de [185.67.36.66])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 9C98668318\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 26 Jan 2021 19:49:15 +0100 (CET)","from submission (posteo.de [89.146.220.130]) \n\tby mout02.posteo.de (Postfix) with ESMTPS id 42A552400FC\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 26 Jan 2021 19:49:15 +0100 (CET)","from customer (localhost [127.0.0.1])\n\tby submission (posteo.de) with ESMTPSA id 4DQG3t4NLQz6tm8;\n\tTue, 26 Jan 2021 19:49:14 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=posteo.net header.i=@posteo.net\n\theader.b=\"XoOomGw8\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017;\n\tt=1611686955; bh=p4guerxYT6XCR8Sx1YJ/pZQdRHxcrsGsZMPxWlJTB7E=;\n\th=From:To:Cc:Subject:Date:From;\n\tb=XoOomGw8moDgWdcWP1KlhYywUzccySEYP/oFPFZXQhdsSmG4Q2+Z6IqqobGxiDhsD\n\tuUQkLZl8EJmMhRj0z3+fStZqqsjpDr3vRJB6hyavhVSWbIdOQ633fYFGlwRG9S0b8V\n\tW6OH7vGquv7z+bIlWwt/mE/siZyMk1nJnIYeay7Ys3plyGV72hlIlDQBBrGeGmmnn0\n\t1yLRZj2LsS11SMHgGL42MfCzO/l5I1ez/9n5M9xCYB0TKNI6hfuacLJ0WiEIgaBJLa\n\tE1LwMEy1c16MSyoBtvAm4QjAgfOI6WVEeDl2tV+gpuKkz0crkR7gzGjNc7t0Oc8mMz\n\t+vYDzBKsorIUw==","From":"Sebastian Fricke <sebastian.fricke@posteo.net>","To":"libcamera-devel@lists.libcamera.org","Date":"Tue, 26 Jan 2021 19:48:54 +0100","Message-Id":"<20210126184854.46156-6-sebastian.fricke@posteo.net>","X-Mailer":"git-send-email 2.25.1","In-Reply-To":"<20210126184854.46156-1-sebastian.fricke@posteo.net>","References":"<20210126184854.46156-1-sebastian.fricke@posteo.net>","MIME-Version":"1.0","Subject":"[libcamera-devel] [PATCH v3 5/5] test: Add unit tests for the\n\tBayerFormat class","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Test all of the present methods including the newly implemented\n`fromV4L2PixelFormat`, as well as the new operators `==/!=`.\n\nReviewed-by: Jacopo Mondi <jacopo@jmondi.org>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nReviewed-by: David Plowman <david.plowman@raspberrypi.com>\nSigned-off-by: Sebastian Fricke <sebastian.fricke@posteo.net>\n---\n test/bayer_format.cpp | 210 ++++++++++++++++++++++++++++++++++++++++++\n test/meson.build      |   1 +\n 2 files changed, 211 insertions(+)\n create mode 100644 test/bayer_format.cpp","diff":"diff --git a/test/bayer_format.cpp b/test/bayer_format.cpp\nnew file mode 100644\nindex 00000000..f763500f\n--- /dev/null\n+++ b/test/bayer_format.cpp\n@@ -0,0 +1,210 @@\n+/* SPDX-License-Identifier: GPL-2.0-or-later */\n+/*\n+ * Copyright (C) 2020, Sebastian Fricke\n+ *\n+ * bayer_format.cpp - BayerFormat class tests\n+ */\n+\n+#include <iostream>\n+\n+#include <libcamera/internal/bayer_format.h>\n+#include <libcamera/transform.h>\n+\n+#include \"test.h\"\n+\n+using namespace std;\n+using namespace libcamera;\n+\n+class BayerFormatTest : public Test\n+{\n+protected:\n+\tint run()\n+\t{\n+\t\t/* An empty Bayer format has to be invalid. */\n+\t\tBayerFormat bayerFmt;\n+\t\tif (bayerFmt.isValid()) {\n+\t\t\tcerr << \"An empty BayerFormat has to be invalid.\"\n+\t\t\t     << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\t/* A correct Bayer format has to be valid. */\n+\t\tbayerFmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::None);\n+\t\tif (!bayerFmt.isValid()) {\n+\t\t\tcerr << \"A correct BayerFormat has to be valid.\"\n+\t\t\t     << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\t/*\n+\t\t * Two bayer formats created with the same order and bit depth\n+\t\t * have to be equal.\n+\t\t */\n+\t\tbayerFmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::None);\n+\t\tBayerFormat bayerFmtExpect = BayerFormat(BayerFormat::BGGR, 8,\n+\t\t\t\t\t\t\t BayerFormat::None);\n+\t\tif (bayerFmt != bayerFmtExpect) {\n+\t\t\tcerr << \"Comparison of identical formats failed.\"\n+\t\t\t     << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\t/*\n+\t\t * Two Bayer formats created with the same order but with a\n+\t\t * different bitDepth are not equal.\n+\t\t */\n+\t\tbayerFmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::None);\n+\t\tbayerFmtExpect = BayerFormat(BayerFormat::BGGR, 12,\n+\t\t\t\t\t     BayerFormat::None);\n+\t\tif (bayerFmt == bayerFmtExpect) {\n+\t\t\tcerr << \"Comparison of divergent formats failed.\"\n+\t\t\t     << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\t/*\n+\t\t * Create a Bayer format with a V4L2PixelFormat and check if we\n+\t\t * get the same format after converting back to the V4L2 Format.\n+\t\t */\n+\t\tV4L2PixelFormat v4l2FmtExpect = V4L2PixelFormat(\n+\t\t\tV4L2_PIX_FMT_SBGGR8);\n+\t\tbayerFmt = BayerFormat::fromV4L2PixelFormat(v4l2FmtExpect);\n+\t\tV4L2PixelFormat v4l2Fmt = bayerFmt.toV4L2PixelFormat();\n+\t\tif (v4l2Fmt != v4l2FmtExpect) {\n+\t\t\tcerr << \"Expected: '\" << v4l2FmtExpect.toString()\n+\t\t\t     << \"' got: '\" << v4l2Fmt.toString() << \"'\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\t/*\n+\t\t * Use an empty Bayer format and verify that no matching\n+\t\t * V4L2PixelFormat is found.\n+\t\t */\n+\t\tv4l2FmtExpect = V4L2PixelFormat();\n+\t\tbayerFmt = BayerFormat();\n+\t\tv4l2Fmt = bayerFmt.toV4L2PixelFormat();\n+\t\tif (v4l2Fmt != v4l2FmtExpect) {\n+\t\t\tcerr << \"Expected: empty V4L2PixelFormat got: '\"\n+\t\t\t     << v4l2Fmt.toString() << \"'\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\t/*\n+\t\t * Check if we get the expected Bayer format BGGR8\n+\t\t * when we convert the V4L2PixelFormat (V4L2_PIX_FMT_SBGGR8)\n+\t\t * to a Bayer format.\n+\t\t */\n+\t\tbayerFmtExpect = BayerFormat(BayerFormat::BGGR, 8,\n+\t\t\t\t\t     BayerFormat::None);\n+\t\tv4l2Fmt = V4L2PixelFormat(V4L2_PIX_FMT_SBGGR8);\n+\t\tbayerFmt = BayerFormat::fromV4L2PixelFormat(v4l2Fmt);\n+\t\tif (bayerFmt != bayerFmtExpect) {\n+\t\t\tcerr << \"Expected BayerFormat '\"\n+\t\t\t     << bayerFmtExpect.toString() << \"', got: '\"\n+\t\t\t     << bayerFmt.toString() << \"'\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\t/*\n+\t\t * Confirm that a V4L2PixelFormat that is not found in\n+\t\t * the conversion table, doesn't yield a Bayer format.\n+\t\t */\n+\t\tV4L2PixelFormat v4l2FmtUnknown = V4L2PixelFormat(\n+\t\t\tV4L2_PIX_FMT_BGRA444);\n+\t\tbayerFmt = BayerFormat::fromV4L2PixelFormat(v4l2FmtUnknown);\n+\t\tif (bayerFmt.isValid()) {\n+\t\t\tcerr << \"Expected empty BayerFormat got: '\"\n+\t\t\t     << bayerFmt.toString() << \"'\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\t/*\n+\t\t * Test if a valid Bayer format can be converted to a\n+\t\t * string representation.\n+\t\t */\n+\t\tbayerFmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::None);\n+\t\tif (bayerFmt.toString() != \"BGGR-8\") {\n+\t\t\tcerr << \"String representation != 'BGGR-8' (got: '\"\n+\t\t\t     << bayerFmt.toString() << \"' ) \" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\t/*\n+\t\t * Determine if an empty Bayer format results in no\n+\t\t * string representation.\n+\t\t */\n+\t\tbayerFmt = BayerFormat();\n+\t\tif (bayerFmt.toString() != \"INVALID\") {\n+\t\t\tcerr << \"String representation != 'INVALID' (got: '\"\n+\t\t\t     << bayerFmt.toString() << \"' ) \" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\t/*\n+\t\t * Perform a horizontal Flip and make sure that the\n+\t\t * order is adjusted accordingly.\n+\t\t */\n+\t\tbayerFmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::None);\n+\t\tbayerFmtExpect = BayerFormat(BayerFormat::GBRG, 8,\n+\t\t\t\t\t     BayerFormat::None);\n+\t\tBayerFormat hFlipFmt = bayerFmt.transform(Transform::HFlip);\n+\t\tif (hFlipFmt != bayerFmtExpect) {\n+\t\t\tcerr << \"Horizontal flip of 'BGGR-8' should result in '\"\n+\t\t\t     << bayerFmtExpect.toString() << \"', got: '\"\n+\t\t\t     << hFlipFmt.toString() << \"'\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\t/*\n+\t\t * Perform a vertical Flip and make sure that\n+\t\t * the order is adjusted accordingly.\n+\t\t */\n+\t\tbayerFmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::None);\n+\t\tbayerFmtExpect = BayerFormat(BayerFormat::GRBG, 8,\n+\t\t\t\t\t     BayerFormat::None);\n+\t\tBayerFormat vFlipFmt = bayerFmt.transform(Transform::VFlip);\n+\t\tif (vFlipFmt != bayerFmtExpect) {\n+\t\t\tcerr << \"Vertical flip of 'BGGR-8' should result in '\"\n+\t\t\t     << bayerFmtExpect.toString() << \"', got: '\"\n+\t\t\t     << vFlipFmt.toString() << \"'\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\t/*\n+\t\t * Perform a transposition on a pixel order with both green\n+\t\t * pixels on the bottom left to top right diagonal and make\n+\t\t * sure, that it doesn't change.\n+\t\t */\n+\t\tbayerFmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::None);\n+\t\tBayerFormat transposeFmt = bayerFmt.transform(\n+\t\t\tTransform::Transpose);\n+\t\tif (transposeFmt != bayerFmt) {\n+\t\t\tcerr << \"Transpose with both green pixels on the \"\n+\t\t\t     << \"antidiagonal, should not change the order \"\n+\t\t\t     << \" result: '\" << transposeFmt.toString() << \"'\"\n+\t\t\t     << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\t/*\n+\t\t * Perform a transposition on an pixel order with red and blue\n+\t\t * on the bottom left to top right diagonal and make sure\n+\t\t * that their positions are switched.\n+\t\t */\n+\t\tbayerFmt = BayerFormat(BayerFormat::GBRG, 8, BayerFormat::None);\n+\t\tbayerFmtExpect = BayerFormat(BayerFormat::GRBG, 8,\n+\t\t\t\t\t     BayerFormat::None);\n+\t\ttransposeFmt = bayerFmt.transform(Transform::Transpose);\n+\t\tif (transposeFmt != bayerFmtExpect) {\n+\t\t\tcerr << \"Transpose with the red & blue pixels on the \"\n+\t\t\t     << \"antidiagonal, should switch their position \"\n+\t\t\t     << \" result: '\" << transposeFmt.toString() << \"'\"\n+\t\t\t     << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\treturn TestPass;\n+\t}\n+};\n+\n+TEST_REGISTER(BayerFormatTest);\ndiff --git a/test/meson.build b/test/meson.build\nindex 7f0682ad..709b47aa 100644\n--- a/test/meson.build\n+++ b/test/meson.build\n@@ -27,6 +27,7 @@ public_tests = [\n ]\n \n internal_tests = [\n+    ['bayer-format',                    'bayer_format.cpp'],\n     ['byte-stream-buffer',              'byte-stream-buffer.cpp'],\n     ['camera-sensor',                   'camera-sensor.cpp'],\n     ['event',                           'event.cpp'],\n","prefixes":["libcamera-devel","v3","5/5"]}