From patchwork Fri Apr 29 19:34:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 15752 X-Patchwork-Delegate: kieran.bingham@ideasonboard.com 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 4495DC326C for ; Fri, 29 Apr 2022 19:34:27 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id EB42B6564C; Fri, 29 Apr 2022 21:34:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1651260866; bh=MEXKjD8dZehuJXB/0YoKuGf/nuPVIYzzNduzLWMkliI=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=YbJSEBBT2jjULFv1xmZzanTeiFyjc2f8YezpBXXYp2EwaZ09HDQO2T4FZGk1qkxWj PJXUjxbG09yeFbRmIjbpa9rdFrXUYoKzmJK/7SFs7cKTrBYFWShOpjJuz+kTxgtM/0 D37lhF9/7UtLJj0duLd7O3JwCE2NV7rXzdcyeHauIXjjOItcRMijNSfZLLlRdGRLT/ 1Wn8tLAwDBSRgC6fZAeX7qXGB3WvPm/E/uEC+D/aIaNRTZtZyIEAeGc9Ga0tntWNQ+ +K0NnkZLOolHaufoBx6K/7qlTHC+Rgcgl/ZAb3tYjJuNjvTgjbV/0U2eYP8b1YjxHu jhNJDYkiKMwzA== 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 91C0765640 for ; Fri, 29 Apr 2022 21:34:23 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="IVpb/14s"; dkim-atps=neutral Received: from Q.ksquared.org.uk.beta.tailscale.net (unknown [178.237.134.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 15A1745F; Fri, 29 Apr 2022 21:34:23 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1651260863; bh=MEXKjD8dZehuJXB/0YoKuGf/nuPVIYzzNduzLWMkliI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IVpb/14sbSgzNZXuEvNNaomf/AUYgBQlYIO23Qa3twMkvvr4iBd6GmwkH+ygdDaHF pj18wL940jpF9UNzt1kkUFCHXPmEsd55ZfT12KmCPUxubcmUoP2//U6Vywqzip1asj +gO+czxn0oQVmNncDLdtw5WuPV73Sv9pokF0FJH0= To: libcamera devel Date: Fri, 29 Apr 2022 21:34:33 +0200 Message-Id: <20220429193434.167990-3-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220429193434.167990-1-kieran.bingham@ideasonboard.com> References: <20220429193434.167990-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/3] test: Add Sequence observer tests 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: , X-Patchwork-Original-From: Kieran Bingham via libcamera-devel From: Kieran Bingham Reply-To: Kieran Bingham Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Validate the Sequence object for a set of possible permutations. Signed-off-by: Kieran Bingham Reviewed-by: Umang Jain --- test/meson.build | 1 + test/sequence.cpp | 80 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 test/sequence.cpp diff --git a/test/meson.build b/test/meson.build index fd4c5ca07c15..7c53fe5d0d76 100644 --- a/test/meson.build +++ b/test/meson.build @@ -47,6 +47,7 @@ internal_tests = [ ['object-delete', 'object-delete.cpp'], ['object-invoke', 'object-invoke.cpp'], ['pixel-format', 'pixel-format.cpp'], + ['sequence', 'sequence.cpp'], ['shared-fd', 'shared-fd.cpp'], ['signal-threads', 'signal-threads.cpp'], ['threads', 'threads.cpp'], diff --git a/test/sequence.cpp b/test/sequence.cpp new file mode 100644 index 000000000000..4afb9998527a --- /dev/null +++ b/test/sequence.cpp @@ -0,0 +1,80 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2022, Ideas on Board Oy. + * + * sequence.cpp - Sequence observer tests + */ + +#include + +#include + +#include "test.h" + +using namespace std; +using namespace libcamera; + +class SequenceTest : public Test +{ +private: + int Fail(std::string m) + { + cout << m << endl; + return TestFail; + } + +protected: + int run() + { + Sequence seq; + int diff; + + /* Validate non-zero initialization */ + diff = seq.update(10); + if (diff) + return Fail("Initialisation test failed"); + + diff = seq.update(11); + if (diff) + return Fail("Sequential sequence failure"); + + /* Validate 1 drop */ + diff = seq.update(13); + if (diff != 1) + return Fail("Sequence gap not detected"); + + /* Validate 10 drops - currently expect sequence 14 */ + diff = seq.update(24); + if (diff != 10) + return Fail("Large sequence gap not detected"); + + /* Validate reset */ + seq.reset(); + diff = seq.update(50); + if (diff) + return Fail("Reset failed"); + + /* Validate reverse sequence detected */ + diff = seq.update(49); + if (diff == 0) + return Fail("Reverse sequence detection error"); + + /* Validate integer wrap around (Shouldn't ever happen but...) */ + seq.reset(); + diff = seq.update(-2); + if (diff) + return Fail("Integer wrap test reset failed"); + + diff = seq.update(-1); + if (diff) + return Fail("Negative sequence failed"); + + diff = seq.update(0); + if (diff) + return Fail("Integer wrap test failed"); + + return TestPass; + } +}; + +TEST_REGISTER(SequenceTest)