summaryrefslogtreecommitdiff
path: root/test/v4l2_videodevice
diff options
context:
space:
mode:
authorNaushir Patuck <naush@raspberrypi.com>2022-03-25 09:09:03 +0000
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2022-03-28 02:18:39 +0300
commit73490312944d5e81f2f7b81c8328f0fb1f74074e (patch)
treee9b2ca8cc37c1ebeda5b232844f5da6b4ab29003 /test/v4l2_videodevice
parent5704856681a0e9fc5eba7dd4af7f153a05e3db1a (diff)
test: Test V4L2BufferCache::isEmpty() member function
Add a test for V4L2BufferCache::isEmpty() for various levels for cache fullness. Signed-off-by: Naushir Patuck <naush@raspberrypi.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'test/v4l2_videodevice')
-rw-r--r--test/v4l2_videodevice/buffer_cache.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/test/v4l2_videodevice/buffer_cache.cpp b/test/v4l2_videodevice/buffer_cache.cpp
index b3f2bec1..5a9aa219 100644
--- a/test/v4l2_videodevice/buffer_cache.cpp
+++ b/test/v4l2_videodevice/buffer_cache.cpp
@@ -126,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;
@@ -204,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;
}