From patchwork Mon Jan 21 10:28:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 288 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 61F0760C65 for ; Mon, 21 Jan 2019 11:28:30 +0100 (CET) Received: from localhost.localdomain (cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id E452A53E; Mon, 21 Jan 2019 11:28:29 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1548066510; bh=JHBL8agOBjf75kkRwMWqQemOdK3eSnvIUISAV1XL95I=; h=From:To:Cc:Subject:Date:From; b=Tie3NFIVosxkzI0S0IYnY0igFr6T8rpjh8OLIlx8OTVqdcXh8xF5mShDopi56+QRB Ic2IEuRdqFmsbA0qGLw9JDepc9iRyfH56+6lTmEPRTBTf9gSoy8W9VAitAWANYMd3Z qIJGhFw0cwFC9G6XAnvGpdJ/yJIdVN1eoY2KC160= From: Kieran Bingham To: LibCamera Devel Date: Mon, 21 Jan 2019 10:28:26 +0000 Message-Id: <20190121102826.16873-1-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.17.1 Subject: [libcamera-devel] [PATCH] test: v4l2_device: Provide compile time assertions X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 21 Jan 2019 10:28:30 -0000 The V4L2Capability structure is inherited from struct v4l2_capability only to provide an interface. It must not extend the type or data. Enforce this with a static assertion with sizeof() comparisons. There is no need here for a specific test binary which will always return TEST_PASS when compiled, as this test failure will be caught at compile time. In light of this - the static compile time assertion is added to the V4L2DeviceTest base class. Should there be a large number of static assertions required, they could be moved to their own unit for clarity. Signed-off-by: Kieran Bingham Reviewed-by: Niklas Söderlund --- test/v4l2_device/v4l2_device_test.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/v4l2_device/v4l2_device_test.cpp b/test/v4l2_device/v4l2_device_test.cpp index 362553712caa..97876f8d65db 100644 --- a/test/v4l2_device/v4l2_device_test.cpp +++ b/test/v4l2_device/v4l2_device_test.cpp @@ -5,6 +5,7 @@ * libcamera V4L2 API tests */ +#include #include #include @@ -41,3 +42,8 @@ void V4L2DeviceTest::cleanup() { delete dev_; }; + +/* Static compile time assertion tests */ + +static_assert(sizeof(struct v4l2_capability) == sizeof(struct V4L2Capability), + "V4L2Capability must match v4l2_capability size");