diff options
Diffstat (limited to 'test/v4l2_videodevice/buffer_cache.cpp')
-rw-r--r-- | test/v4l2_videodevice/buffer_cache.cpp | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/test/v4l2_videodevice/buffer_cache.cpp b/test/v4l2_videodevice/buffer_cache.cpp index d730e755..5a9aa219 100644 --- a/test/v4l2_videodevice/buffer_cache.cpp +++ b/test/v4l2_videodevice/buffer_cache.cpp @@ -9,6 +9,7 @@ #include <random> #include <vector> +#include <libcamera/formats.h> #include <libcamera/stream.h> #include "buffer_source.h" @@ -125,6 +126,35 @@ public: return TestPass; } + int testIsEmpty(const std::vector<std::unique_ptr<FrameBuffer>> &buffers) + { + V4L2BufferCache cache(buffers.size()); + + if (!cache.isEmpty()) + return TestFail; + + for (auto const &buffer : buffers) { + FrameBuffer &b = *buffer.get(); + cache.get(b); + } + + if (cache.isEmpty()) + return TestFail; + + unsigned int i; + for (i = 0; i < buffers.size() - 1; i++) + cache.put(i); + + if (cache.isEmpty()) + return TestFail; + + cache.put(i); + if (!cache.isEmpty()) + return TestFail; + + return TestPass; + } + int init() override { std::random_device rd; @@ -142,7 +172,7 @@ public: const unsigned int numBuffers = 8; StreamConfiguration cfg; - cfg.pixelFormat = PixelFormat(DRM_FORMAT_YUYV); + cfg.pixelFormat = formats::YUYV; cfg.size = Size(600, 800); cfg.bufferCount = numBuffers; @@ -203,6 +233,13 @@ public: if (testHot(&cacheHalf, buffers, numBuffers / 2) != TestPass) return TestFail; + /* + * Test that the isEmpty function reports the correct result at + * various levels of cache fullness. + */ + if (testIsEmpty(buffers) != TestPass) + return TestFail; + return TestPass; } @@ -212,4 +249,4 @@ private: } /* namespace */ -TEST_REGISTER(BufferCacheTest); +TEST_REGISTER(BufferCacheTest) |