[libcamera-devel] [PATCH v7 05/11] lc-compliance: Move camera setup to CameraHolder class

Laurent Pinchart laurent.pinchart at ideasonboard.com
Mon Aug 2 02:14:54 CEST 2021


Hi Nícolas,

Thank you for the patch.

On Thu, Jul 22, 2021 at 08:28:45PM -0300, Nícolas F. R. A. Prado wrote:
> Different base classes can be used for different setups on tests, but
> all of them will need to setup the camera for the test. To reuse that
> code, move it to a separate CameraHolder class that is inherited by test
> classes.
> 
> Signed-off-by: Nícolas F. R. A. Prado <nfraprado at collabora.com>

Reviewed-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>

> ---
> 
> No changes in v7
> 
> No changes in v6
> 
> Added in v5
> 
>  src/lc-compliance/capture_test.cpp | 41 +++++++++++++++++++++---------
>  1 file changed, 29 insertions(+), 12 deletions(-)
> 
> diff --git a/src/lc-compliance/capture_test.cpp b/src/lc-compliance/capture_test.cpp
> index 6439cbd88f8e..949407d3191e 100644
> --- a/src/lc-compliance/capture_test.cpp
> +++ b/src/lc-compliance/capture_test.cpp
> @@ -18,23 +18,16 @@ using namespace libcamera;
>  const std::vector<int> NUMREQUESTS = { 1, 2, 3, 5, 8, 13, 21, 34, 55, 89 };
>  const std::vector<StreamRole> ROLES = { Raw, StillCapture, VideoRecording, Viewfinder };
>  
> -class SingleStream : public testing::TestWithParam<std::tuple<StreamRole, int>>
> +class CameraHolder
>  {
> -public:
> -	static std::string nameParameters(const testing::TestParamInfo<SingleStream::ParamType> &info);
> -
>  protected:
> -	void SetUp() override;
> -	void TearDown() override;
> +	void acquireCamera();
> +	void releaseCamera();
>  
>  	std::shared_ptr<Camera> camera_;
>  };
>  
> -/*
> - * We use gtest's SetUp() and TearDown() instead of constructor and destructor
> - * in order to be able to assert on them.
> - */
> -void SingleStream::SetUp()
> +void CameraHolder::acquireCamera()
>  {
>  	Environment *env = Environment::get();
>  
> @@ -43,7 +36,7 @@ void SingleStream::SetUp()
>  	ASSERT_EQ(camera_->acquire(), 0);
>  }
>  
> -void SingleStream::TearDown()
> +void CameraHolder::releaseCamera()
>  {
>  	if (!camera_)
>  		return;
> @@ -52,6 +45,30 @@ void SingleStream::TearDown()
>  	camera_.reset();
>  }
>  
> +class SingleStream : public testing::TestWithParam<std::tuple<StreamRole, int>>, public CameraHolder
> +{
> +public:
> +	static std::string nameParameters(const testing::TestParamInfo<SingleStream::ParamType> &info);
> +
> +protected:
> +	void SetUp() override;
> +	void TearDown() override;
> +};
> +
> +/*
> + * We use gtest's SetUp() and TearDown() instead of constructor and destructor
> + * in order to be able to assert on them.
> + */
> +void SingleStream::SetUp()
> +{
> +	acquireCamera();
> +}
> +
> +void SingleStream::TearDown()
> +{
> +	releaseCamera();
> +}
> +
>  std::string SingleStream::nameParameters(const testing::TestParamInfo<SingleStream::ParamType> &info)
>  {
>  	std::map<StreamRole, std::string> rolesMap = { { Raw, "Raw" },

-- 
Regards,

Laurent Pinchart


More information about the libcamera-devel mailing list