From patchwork Fri Jun 7 10:03:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 20243 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 A9DE6C31E9 for ; Fri, 7 Jun 2024 10:03:39 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CAB31634BA; Fri, 7 Jun 2024 12:03:38 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="bzayfmq3"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0581C633DE for ; Fri, 7 Jun 2024 12:03:36 +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 D0E38720; Fri, 7 Jun 2024 12:03:25 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1717754607; bh=kBjW03Ih6M4ve93M5apBZ0JSISriOuRf5XCXevzIph4=; h=From:To:Cc:Subject:Date:From; b=bzayfmq3hPnm8v6dV2C5SH9bwgT+4dz/qDD8rjE54g4UMYq0iiAN8nKWZACMDfobC yNWQojmOL2S54mZNhUZ/9VLryzxKxIV81cP3ygsNDLnDuW8fIH66ZJ8kTzGLKipB/p HwY5yzpOn+TbP/kPRhiEL2CRuqhlc8LIalhM+tpU= From: Paul Elder To: libcamera-devel@lists.libcamera.org Cc: Paul Elder , Stefan Klug Subject: [PATCH v2] test: ipa: rkisp1: utils: Fix floating and fixed point conversion test Date: Fri, 7 Jun 2024 19:03:23 +0900 Message-Id: <20240607100323.3029238-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 moving the offending test out of the loop. 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 Reviewed-by: Kieran Bingham --- Changes in v2: - remove the added complexity that would've made it clearner to add a larger variety of tests because the variety wasn't there --- test/ipa/rkisp1/rkisp1-utils.cpp | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/test/ipa/rkisp1/rkisp1-utils.cpp b/test/ipa/rkisp1/rkisp1-utils.cpp index e48f8d362..b1863894c 100644 --- a/test/ipa/rkisp1/rkisp1-utils.cpp +++ b/test/ipa/rkisp1/rkisp1-utils.cpp @@ -21,7 +21,23 @@ using namespace ipa::rkisp1; class RkISP1UtilsTest : public Test { protected: - template + /* R for real, I for integer */ + template + int testFixedToFloat(I input, R expected) + { + R out = utils::fixedToFloatingPoint(input); + 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; + } + + return TestPass; + } + + template int testSingleFixedPoint(double input, T expected) { T ret = utils::floatingToFixedPoint(input); @@ -54,7 +70,6 @@ protected: */ std::map testCases = { { 7.992, 0x3ff }, - { 7.992, 0xbff }, { 0.2, 0x01a }, { -0.2, 0x7e6 }, { -0.8, 0x79a }, @@ -72,6 +87,11 @@ protected: return ret; } + /* Special case with a superfluous one in the unused bits */ + ret = testFixedToFloat<4, 7, uint16_t, double>(0xbff, 7.992); + if (ret != TestPass) + return ret; + return TestPass; }