[libcamera-devel] [PATCH] test: v4l2_device: Provide compile time assertions

Kieran Bingham kieran.bingham at ideasonboard.com
Mon Jan 21 11:39:16 CET 2019


Hi Niklas,

On 21/01/2019 10:36, Niklas Söderlund wrote:
> Hi Kieran,
> 
> Nice idea for a test :-)
>
> On 2019-01-21 10:28:26 +0000, Kieran Bingham wrote:
>> 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 <kieran.bingham at ideasonboard.com>
> 
> Reviewed-by: Niklas Söderlund <niklas.soderlund at ragnatech.se>

Thanks,

I hope this alleviates some of your earlier concerns about the method of
implementing the interface to interact kernel structures ...

It's to define what functions can operate on a structure - certainly not
to to extend that structure in any way.

--
Kieran

> 
>> ---
>>  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 <assert.h>
>>  #include <iostream>
>>  #include <sys/stat.h>
>>  
>> @@ -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");
>> -- 
>> 2.17.1
>>
>> _______________________________________________
>> libcamera-devel mailing list
>> libcamera-devel at lists.libcamera.org
>> https://lists.libcamera.org/listinfo/libcamera-devel
> 

-- 
Regards
--
Kieran


More information about the libcamera-devel mailing list