From patchwork Mon Jun 3 12:53:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 20191 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 7190BBD87C for ; Mon, 3 Jun 2024 12:53:42 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8B9AB634CA; Mon, 3 Jun 2024 14:53:41 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="ZT1PZi7L"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5977F61A3B for ; Mon, 3 Jun 2024 14:53:39 +0200 (CEST) Received: from neptunite.hamster-moth.ts.net (h175-177-049-156.catv02.itscom.jp [175.177.49.156]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id AA54EA38; Mon, 3 Jun 2024 14:53:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1717419212; bh=dzJITavxX6PJQrAsh/RNpGl+aej7PPmyypWSn7oFdV8=; h=From:To:Cc:Subject:Date:From; b=ZT1PZi7LNOrafUh6YbiHNH5lXg3IwtlYTsOnlv4lN7U4+99F4AxtUwCIWhSflXn7t idYgLW1gMaCJ8Ta3S/R5Rs0Brry4qNB7HC3pb7+NqxRp4oYNq+lRqfkQniHC5x0pza sL/tPdbHiKRgyN1GapHGHU+e25EJBmTHPCj1bBDY= From: Paul Elder To: libcamera-devel@lists.libcamera.org Cc: Laurent Pinchart , pobrn@protonmail.com, Paul Elder Subject: [PATCH] test: ipa: rkisp1: utils: Fix floating and fixed point conversion test Date: Mon, 3 Jun 2024 21:53:24 +0900 Message-Id: <20240603125324.3472888-1-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 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" There was an issue where using map to store the test cases meant that the test for ignoring unused bits was skipped because of clashing keys. Fix this by changing the test to an array of tuples. While at it, reorganize the tests so that it's possible to test only reverse conversion, which was the case here to test that multiple fixed point numbers (due to unused bits) would result in the same floating point number. While at it, also change the arbitrary floating comparison precision to be more precise. Also fix a missing documentation brief. Fixes: 9d152e9c6 ipa: rkisp1: Add a helper to convert floating-point to fixed-point Signed-off-by: Paul Elder Reviewed-by: Stefan Klug --- src/ipa/rkisp1/utils.cpp | 1 + test/ipa/rkisp1/rkisp1-utils.cpp | 97 +++++++++++++++++++++++--------- 2 files changed, 70 insertions(+), 28 deletions(-) diff --git a/src/ipa/rkisp1/utils.cpp b/src/ipa/rkisp1/utils.cpp index 960ec64e9..8edcf5bf7 100644 --- a/src/ipa/rkisp1/utils.cpp +++ b/src/ipa/rkisp1/utils.cpp @@ -9,6 +9,7 @@ /** * \file utils.h + * \brief Utility functions for rkisp1 */ namespace libcamera { diff --git a/test/ipa/rkisp1/rkisp1-utils.cpp b/test/ipa/rkisp1/rkisp1-utils.cpp index e48f8d362..4757ca069 100644 --- a/test/ipa/rkisp1/rkisp1-utils.cpp +++ b/test/ipa/rkisp1/rkisp1-utils.cpp @@ -7,8 +7,8 @@ #include #include -#include #include +#include #include "../src/ipa/rkisp1/utils.h" @@ -21,53 +21,94 @@ using namespace ipa::rkisp1; class RkISP1UtilsTest : public Test { protected: - template - int testSingleFixedPoint(double input, T expected) + /* R for real, I for integer */ + template + int testFixedToFloat(I input, R expected, R *output = nullptr) { - T ret = utils::floatingToFixedPoint(input); - if (ret != expected) { - cerr << "Expected " << input << " to convert to " - << expected << ", got " << ret << std::endl; + R out = utils::fixedToFloatingPoint(input); + if (output) + *output = out; + R prec = 1.0 / (1 << FracPrec); + if (std::abs(out - expected) > prec) { + cerr << "Reverse conversion expected " << input + << " to convert to " << expected + << ", got " << out << std::endl; return TestFail; } - /* - * The precision check is fairly arbitrary but is based on what - * the rkisp1 is capable of in the crosstalk module. - */ - double f = utils::fixedToFloatingPoint(ret); - if (std::abs(f - input) > 0.005) { - cerr << "Reverse conversion expected " << ret - << " to convert to " << input - << ", got " << f << std::endl; + return TestPass; + } + + /* R for real, I for integer */ + template + int testFloatToFixed(R input, I expected, I *output = nullptr) + { + I out = utils::floatingToFixedPoint(input); + if (output) + *output = out; + if (out != expected) { + cerr << "Expected " << input << " to convert to " + << expected << ", got " << out << std::endl; return TestFail; } return TestPass; } + /* R for real, I for integer */ + template + int testFullConversion(R input, I expected) + { + I outInt; + R outReal; + int status; + + status = testFloatToFixed(input, expected, &outInt); + if (status != TestPass) + return status; + + status = testFixedToFloat(outInt, input, &outReal); + if (status != TestPass) + return status; + + return TestPass; + } + + int testFixedPoint() { /* * The second 7.992 test is to test that unused bits don't * affect the result. + * + * Third parameter is for testing forward, fourth parameter is + * for testing reverse. */ - std::map testCases = { - { 7.992, 0x3ff }, - { 7.992, 0xbff }, - { 0.2, 0x01a }, - { -0.2, 0x7e6 }, - { -0.8, 0x79a }, - { -0.4, 0x7cd }, - { -1.4, 0x74d }, - { -8, 0x400 }, - { 0, 0 }, + static const std::tuple testCases[] = { + { 7.992, 0x3ff, true, true }, + { 7.992, 0xbff, false, true }, + { 0.2, 0x01a, true, true }, + { -0.2, 0x7e6, true, true }, + { -0.8, 0x79a, true, true }, + { -0.4, 0x7cd, true, true }, + { -1.4, 0x74d, true, true }, + { -8, 0x400, true, true }, + { 0, 0, true, true }, }; int ret; for (const auto &testCase : testCases) { - ret = testSingleFixedPoint<4, 7, uint16_t>(testCase.first, - testCase.second); + double floating; + uint16_t fixed; + bool forward, backward; + std::tie(floating, fixed, forward, backward) = testCase; + if (forward && backward) + ret = testFullConversion<4, 7, double, uint16_t>(floating, fixed); + else if (forward) + ret = testFloatToFixed<4, 7, double, uint16_t>(floating, fixed); + else if (backward) + ret = testFixedToFloat<4, 7, uint16_t, double>(fixed, floating); + if (ret != TestPass) return ret; }