Message ID | 20210824195636.1110845-14-nfraprado@collabora.com |
---|---|
State | Superseded |
Headers | show |
Series |
|
Related | show |
On Tue, Aug 24, 2021 at 04:56:32PM -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@collabora.com> > Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com> > > --- > > Changes in v8: > - Moved CameraHolder to new test_base.{cpp,h} files > > Changes in v5: > - New > > src/lc-compliance/capture_test.cpp | 18 ++++-------------- > src/lc-compliance/meson.build | 1 + > src/lc-compliance/test_base.cpp | 28 ++++++++++++++++++++++++++++ > src/lc-compliance/test_base.h | 24 ++++++++++++++++++++++++ > 4 files changed, 57 insertions(+), 14 deletions(-) > create mode 100644 src/lc-compliance/test_base.cpp > create mode 100644 src/lc-compliance/test_base.h > > diff --git a/src/lc-compliance/capture_test.cpp b/src/lc-compliance/capture_test.cpp > index 6439cbd88f8e..49012048729e 100644 > --- a/src/lc-compliance/capture_test.cpp > +++ b/src/lc-compliance/capture_test.cpp > @@ -10,15 +10,15 @@ > > #include <gtest/gtest.h> > > -#include "environment.h" > #include "simple_capture.h" > +#include "test_base.h" > > 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 SingleStream : public testing::TestWithParam<std::tuple<StreamRole, int>>, public CameraHolder > { > public: > static std::string nameParameters(const testing::TestParamInfo<SingleStream::ParamType> &info); > @@ -26,8 +26,6 @@ public: > protected: > void SetUp() override; > void TearDown() override; > - > - std::shared_ptr<Camera> camera_; > }; > > /* > @@ -36,20 +34,12 @@ protected: > */ > void SingleStream::SetUp() > { > - Environment *env = Environment::get(); > - > - camera_ = env->cm()->get(env->cameraId()); > - > - ASSERT_EQ(camera_->acquire(), 0); > + acquireCamera(); > } > > void SingleStream::TearDown() > { > - if (!camera_) > - return; > - > - camera_->release(); > - camera_.reset(); > + releaseCamera(); > } > > std::string SingleStream::nameParameters(const testing::TestParamInfo<SingleStream::ParamType> &info) > diff --git a/src/lc-compliance/meson.build b/src/lc-compliance/meson.build > index 4be14b694426..db593a6ec201 100644 > --- a/src/lc-compliance/meson.build > +++ b/src/lc-compliance/meson.build > @@ -17,6 +17,7 @@ lc_compliance_sources = files([ > 'environment.cpp', > 'main.cpp', > 'simple_capture.cpp', > + 'test_base.cpp', > ]) > > lc_compliance = executable('lc-compliance', lc_compliance_sources, > diff --git a/src/lc-compliance/test_base.cpp b/src/lc-compliance/test_base.cpp > new file mode 100644 > index 000000000000..c9957b9efd36 > --- /dev/null > +++ b/src/lc-compliance/test_base.cpp > @@ -0,0 +1,28 @@ > +/* SPDX-License-Identifier: GPL-2.0-or-later */ > +/* > + * Copyright (C) 2021, Collabora Ltd. > + * > + * test_base.cpp - Base definitions for tests > + */ > + > +#include "test_base.h" > + > +#include "environment.h" > + > +void CameraHolder::acquireCamera() > +{ > + Environment *env = Environment::get(); > + > + camera_ = env->cm()->get(env->cameraId()); > + > + ASSERT_EQ(camera_->acquire(), 0); > +} > + > +void CameraHolder::releaseCamera() > +{ > + if (!camera_) > + return; > + > + camera_->release(); > + camera_.reset(); > +} > diff --git a/src/lc-compliance/test_base.h b/src/lc-compliance/test_base.h > new file mode 100644 > index 000000000000..52347749ab10 > --- /dev/null > +++ b/src/lc-compliance/test_base.h > @@ -0,0 +1,24 @@ > +/* SPDX-License-Identifier: GPL-2.0-or-later */ > +/* > + * Copyright (C) 2021, Collabora Ltd. > + * > + * test_base.h - Base definitions for tests > + */ > + > +#ifndef __LC_COMPLIANCE_TEST_BASE_H__ > +#define __LC_COMPLIANCE_TEST_BASE_H__ > + > +#include <libcamera/libcamera.h> > + > +#include <gtest/gtest.h> > + > +class CameraHolder > +{ > +protected: > + void acquireCamera(); > + void releaseCamera(); > + > + std::shared_ptr<libcamera::Camera> camera_; > +}; > + > +#endif /* __LC_COMPLIANCE_TEST_BASE_H__ */ > -- > 2.33.0 >
diff --git a/src/lc-compliance/capture_test.cpp b/src/lc-compliance/capture_test.cpp index 6439cbd88f8e..49012048729e 100644 --- a/src/lc-compliance/capture_test.cpp +++ b/src/lc-compliance/capture_test.cpp @@ -10,15 +10,15 @@ #include <gtest/gtest.h> -#include "environment.h" #include "simple_capture.h" +#include "test_base.h" 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 SingleStream : public testing::TestWithParam<std::tuple<StreamRole, int>>, public CameraHolder { public: static std::string nameParameters(const testing::TestParamInfo<SingleStream::ParamType> &info); @@ -26,8 +26,6 @@ public: protected: void SetUp() override; void TearDown() override; - - std::shared_ptr<Camera> camera_; }; /* @@ -36,20 +34,12 @@ protected: */ void SingleStream::SetUp() { - Environment *env = Environment::get(); - - camera_ = env->cm()->get(env->cameraId()); - - ASSERT_EQ(camera_->acquire(), 0); + acquireCamera(); } void SingleStream::TearDown() { - if (!camera_) - return; - - camera_->release(); - camera_.reset(); + releaseCamera(); } std::string SingleStream::nameParameters(const testing::TestParamInfo<SingleStream::ParamType> &info) diff --git a/src/lc-compliance/meson.build b/src/lc-compliance/meson.build index 4be14b694426..db593a6ec201 100644 --- a/src/lc-compliance/meson.build +++ b/src/lc-compliance/meson.build @@ -17,6 +17,7 @@ lc_compliance_sources = files([ 'environment.cpp', 'main.cpp', 'simple_capture.cpp', + 'test_base.cpp', ]) lc_compliance = executable('lc-compliance', lc_compliance_sources, diff --git a/src/lc-compliance/test_base.cpp b/src/lc-compliance/test_base.cpp new file mode 100644 index 000000000000..c9957b9efd36 --- /dev/null +++ b/src/lc-compliance/test_base.cpp @@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2021, Collabora Ltd. + * + * test_base.cpp - Base definitions for tests + */ + +#include "test_base.h" + +#include "environment.h" + +void CameraHolder::acquireCamera() +{ + Environment *env = Environment::get(); + + camera_ = env->cm()->get(env->cameraId()); + + ASSERT_EQ(camera_->acquire(), 0); +} + +void CameraHolder::releaseCamera() +{ + if (!camera_) + return; + + camera_->release(); + camera_.reset(); +} diff --git a/src/lc-compliance/test_base.h b/src/lc-compliance/test_base.h new file mode 100644 index 000000000000..52347749ab10 --- /dev/null +++ b/src/lc-compliance/test_base.h @@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2021, Collabora Ltd. + * + * test_base.h - Base definitions for tests + */ + +#ifndef __LC_COMPLIANCE_TEST_BASE_H__ +#define __LC_COMPLIANCE_TEST_BASE_H__ + +#include <libcamera/libcamera.h> + +#include <gtest/gtest.h> + +class CameraHolder +{ +protected: + void acquireCamera(); + void releaseCamera(); + + std::shared_ptr<libcamera::Camera> camera_; +}; + +#endif /* __LC_COMPLIANCE_TEST_BASE_H__ */