[libcamera-devel] [PATCH v3 4/7] apps: lc-compliance: Re-organize source directory

Kieran Bingham kieran.bingham at ideasonboard.com
Fri Jan 12 12:41:59 CET 2024


Quoting Jacopo Mondi via libcamera-devel (2023-12-30 16:29:09)
> Before adding more tests and more helper classes to lc-compliance,
> reorganize the source tree to split test and helpers in two separate
> directories.
> 
> While at it, rename the 'SimpleCapture' class and its derived classes to
> just 'Capture'. Rename the source files accordingly.

Sounds reasonable. I expect there might be other 'capture' helpers in
the future too.


Reviewed-by: Kieran Bingham <kieran.bingham at ideasonboard.com>

> 
> Re-sort headers inclusions to please checkstyle.py too.
> 
> Signed-off-by: Jacopo Mondi <jacopo.mondi at ideasonboard.com>
> ---
>  .../capture.cpp}                              | 38 +++++++++----------
>  .../{simple_capture.h => helpers/capture.h}   | 14 +++----
>  src/apps/lc-compliance/meson.build            | 10 ++++-
>  .../{ => tests}/capture_test.cpp              |  9 +++--
>  4 files changed, 39 insertions(+), 32 deletions(-)
>  rename src/apps/lc-compliance/{simple_capture.cpp => helpers/capture.cpp} (81%)
>  rename src/apps/lc-compliance/{simple_capture.h => helpers/capture.h} (76%)
>  rename src/apps/lc-compliance/{ => tests}/capture_test.cpp (95%)
> 
> diff --git a/src/apps/lc-compliance/simple_capture.cpp b/src/apps/lc-compliance/helpers/capture.cpp
> similarity index 81%
> rename from src/apps/lc-compliance/simple_capture.cpp
> rename to src/apps/lc-compliance/helpers/capture.cpp
> index 545b444c2593..5aab973f0392 100644
> --- a/src/apps/lc-compliance/simple_capture.cpp
> +++ b/src/apps/lc-compliance/helpers/capture.cpp
> @@ -5,24 +5,24 @@
>   * simple_capture.cpp - Simple capture helper
>   */
>  
> -#include <gtest/gtest.h>
> +#include "capture.h"
>  
> -#include "simple_capture.h"
> +#include <gtest/gtest.h>
>  
>  using namespace libcamera;
>  
> -SimpleCapture::SimpleCapture(std::shared_ptr<Camera> camera)
> +Capture::Capture(std::shared_ptr<Camera> camera)
>         : loop_(nullptr), camera_(camera),
>           allocator_(std::make_unique<FrameBufferAllocator>(camera))
>  {
>  }
>  
> -SimpleCapture::~SimpleCapture()
> +Capture::~Capture()
>  {
>         stop();
>  }
>  
> -void SimpleCapture::configure(StreamRole role)
> +void Capture::configure(StreamRole role)
>  {
>         config_ = camera_->generateConfiguration({ role });
>  
> @@ -42,7 +42,7 @@ void SimpleCapture::configure(StreamRole role)
>         }
>  }
>  
> -void SimpleCapture::start()
> +void Capture::start()
>  {
>         Stream *stream = config_->at(0).stream();
>         int count = allocator_->allocate(stream);
> @@ -50,12 +50,12 @@ void SimpleCapture::start()
>         ASSERT_GE(count, 0) << "Failed to allocate buffers";
>         EXPECT_EQ(count, config_->at(0).bufferCount) << "Allocated less buffers than expected";
>  
> -       camera_->requestCompleted.connect(this, &SimpleCapture::requestComplete);
> +       camera_->requestCompleted.connect(this, &Capture::requestComplete);
>  
>         ASSERT_EQ(camera_->start(), 0) << "Failed to start camera";
>  }
>  
> -void SimpleCapture::stop()
> +void Capture::stop()
>  {
>         if (!config_ || !allocator_->allocated())
>                 return;
> @@ -69,14 +69,14 @@ void SimpleCapture::stop()
>         allocator_->free(stream);
>  }
>  
> -/* SimpleCaptureBalanced */
> +/* CaptureBalanced */
>  
> -SimpleCaptureBalanced::SimpleCaptureBalanced(std::shared_ptr<Camera> camera)
> -       : SimpleCapture(camera)
> +CaptureBalanced::CaptureBalanced(std::shared_ptr<Camera> camera)
> +       : Capture(camera)
>  {
>  }
>  
> -void SimpleCaptureBalanced::capture(unsigned int numRequests)
> +void CaptureBalanced::capture(unsigned int numRequests)
>  {
>         start();
>  
> @@ -116,7 +116,7 @@ void SimpleCaptureBalanced::capture(unsigned int numRequests)
>         ASSERT_EQ(captureCount_, captureLimit_);
>  }
>  
> -int SimpleCaptureBalanced::queueRequest(Request *request)
> +int CaptureBalanced::queueRequest(Request *request)
>  {
>         queueCount_++;
>         if (queueCount_ > captureLimit_)
> @@ -125,7 +125,7 @@ int SimpleCaptureBalanced::queueRequest(Request *request)
>         return camera_->queueRequest(request);
>  }
>  
> -void SimpleCaptureBalanced::requestComplete(Request *request)
> +void CaptureBalanced::requestComplete(Request *request)
>  {
>         EXPECT_EQ(request->status(), Request::Status::RequestComplete)
>                 << "Request didn't complete successfully";
> @@ -141,14 +141,14 @@ void SimpleCaptureBalanced::requestComplete(Request *request)
>                 loop_->exit(-EINVAL);
>  }
>  
> -/* SimpleCaptureUnbalanced */
> +/* CaptureUnbalanced */
>  
> -SimpleCaptureUnbalanced::SimpleCaptureUnbalanced(std::shared_ptr<Camera> camera)
> -       : SimpleCapture(camera)
> +CaptureUnbalanced::CaptureUnbalanced(std::shared_ptr<Camera> camera)
> +       : Capture(camera)
>  {
>  }
>  
> -void SimpleCaptureUnbalanced::capture(unsigned int numRequests)
> +void CaptureUnbalanced::capture(unsigned int numRequests)
>  {
>         start();
>  
> @@ -179,7 +179,7 @@ void SimpleCaptureUnbalanced::capture(unsigned int numRequests)
>         ASSERT_EQ(status, 0);
>  }
>  
> -void SimpleCaptureUnbalanced::requestComplete(Request *request)
> +void CaptureUnbalanced::requestComplete(Request *request)
>  {
>         captureCount_++;
>         if (captureCount_ >= captureLimit_) {
> diff --git a/src/apps/lc-compliance/simple_capture.h b/src/apps/lc-compliance/helpers/capture.h
> similarity index 76%
> rename from src/apps/lc-compliance/simple_capture.h
> rename to src/apps/lc-compliance/helpers/capture.h
> index 2911d6019923..0574ab1c7ac7 100644
> --- a/src/apps/lc-compliance/simple_capture.h
> +++ b/src/apps/lc-compliance/helpers/capture.h
> @@ -13,14 +13,14 @@
>  
>  #include "../common/event_loop.h"
>  
> -class SimpleCapture
> +class Capture
>  {
>  public:
>         void configure(libcamera::StreamRole role);
>  
>  protected:
> -       SimpleCapture(std::shared_ptr<libcamera::Camera> camera);
> -       virtual ~SimpleCapture();
> +       Capture(std::shared_ptr<libcamera::Camera> camera);
> +       virtual ~Capture();
>  
>         void start();
>         void stop();
> @@ -35,10 +35,10 @@ protected:
>         std::vector<std::unique_ptr<libcamera::Request>> requests_;
>  };
>  
> -class SimpleCaptureBalanced : public SimpleCapture
> +class CaptureBalanced : public Capture
>  {
>  public:
> -       SimpleCaptureBalanced(std::shared_ptr<libcamera::Camera> camera);
> +       CaptureBalanced(std::shared_ptr<libcamera::Camera> camera);
>  
>         void capture(unsigned int numRequests);
>  
> @@ -51,10 +51,10 @@ private:
>         unsigned int captureLimit_;
>  };
>  
> -class SimpleCaptureUnbalanced : public SimpleCapture
> +class CaptureUnbalanced : public Capture
>  {
>  public:
> -       SimpleCaptureUnbalanced(std::shared_ptr<libcamera::Camera> camera);
> +       CaptureUnbalanced(std::shared_ptr<libcamera::Camera> camera);
>  
>         void capture(unsigned int numRequests);
>  
> diff --git a/src/apps/lc-compliance/meson.build b/src/apps/lc-compliance/meson.build
> index 2f07a50f171b..ae8c6f4db51b 100644
> --- a/src/apps/lc-compliance/meson.build
> +++ b/src/apps/lc-compliance/meson.build
> @@ -11,10 +11,15 @@ endif
>  lc_compliance_enabled = true
>  
>  lc_compliance_sources = files([
> -    'capture_test.cpp',
>      'environment.cpp',
> +    'helpers/capture.cpp',
>      'main.cpp',
> -    'simple_capture.cpp',
> +    'tests/capture_test.cpp',
> +])
> +
> +lc_compliance_includes = ([
> +    include_directories('.'),
> +    include_directories('helpers/')
>  ])
>  
>  lc_compliance  = executable('lc-compliance', lc_compliance_sources,
> @@ -26,5 +31,6 @@ lc_compliance  = executable('lc-compliance', lc_compliance_sources,
>                                  libevent,
>                                  libgtest,
>                              ],
> +                            include_directories : lc_compliance_includes,
>                              install : true,
>                              install_tag : 'bin-devel')
> diff --git a/src/apps/lc-compliance/capture_test.cpp b/src/apps/lc-compliance/tests/capture_test.cpp
> similarity index 95%
> rename from src/apps/lc-compliance/capture_test.cpp
> rename to src/apps/lc-compliance/tests/capture_test.cpp
> index 1dcfcf92fc8c..284d36307619 100644
> --- a/src/apps/lc-compliance/capture_test.cpp
> +++ b/src/apps/lc-compliance/tests/capture_test.cpp
> @@ -6,12 +6,13 @@
>   * capture_test.cpp - Test camera capture
>   */
>  
> +#include "capture.h"
> +
>  #include <iostream>
>  
>  #include <gtest/gtest.h>
>  
>  #include "environment.h"
> -#include "simple_capture.h"
>  
>  using namespace libcamera;
>  
> @@ -83,7 +84,7 @@ TEST_P(SingleStream, Capture)
>  {
>         auto [role, numRequests] = GetParam();
>  
> -       SimpleCaptureBalanced capture(camera_);
> +       CaptureBalanced capture(camera_);
>  
>         capture.configure(role);
>  
> @@ -102,7 +103,7 @@ TEST_P(SingleStream, CaptureStartStop)
>         auto [role, numRequests] = GetParam();
>         unsigned int numRepeats = 3;
>  
> -       SimpleCaptureBalanced capture(camera_);
> +       CaptureBalanced capture(camera_);
>  
>         capture.configure(role);
>  
> @@ -121,7 +122,7 @@ TEST_P(SingleStream, UnbalancedStop)
>  {
>         auto [role, numRequests] = GetParam();
>  
> -       SimpleCaptureUnbalanced capture(camera_);
> +       CaptureUnbalanced capture(camera_);
>  
>         capture.configure(role);
>  
> -- 
> 2.41.0
>


More information about the libcamera-devel mailing list