Skip to contentSkip to conversation

v4l2-compliance: Add tests for REMOVE_BUFS

PATCH New Benjamin Gaignard 1 participant 3 messages Mar 14, 2024 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

v9 cover v4l2-compliance: Add tests for REMOVE_BUFS

This series add tests for this new field and VIDIOC_REMOVE_BUFS ioctl.

version 9:
- Add tests to check return values when count = 0.
- Add tests to check return values when attempt to remove again buffers.
- Call fail_on_test(q.reqbufs(node, 0)) at the end of the test.
- Do not print WARN if REMOVE_BUFS ioctl isn't supported
- Stop testing if CREATE_BUFS is supported.

version 8:
- Rename structures, function and variables to use 'remove' instead of 'delete.

version 7:
- Remove "v4l2-compliance: Test queue maximum buffers allocation" patches because they have been merged.
- Remove V4L2_BUF_CAP_SUPPORTS_DELETE_BUFS to be aligned with the v18 of the kernel patches
- v4l_queue_querybufs() take care of a range of buffers.

Benjamin Gaignard (2):
v4l2-utils: Add VIDIOC_REMOVE_BUFS ioctl
v4l2-compliance: Add a test for REMOVE_BUFS ioctl

 include/linux/videodev2.h                   |  16 +++
 utils/common/cv4l-helpers.h                 |   4 +
 utils/common/v4l-helpers.h                  |  27 ++++-
 utils/v4l2-compliance/v4l2-compliance.cpp   |   1 +
 utils/v4l2-compliance/v4l2-compliance.h     |   1 +
 utils/v4l2-compliance/v4l2-test-buffers.cpp | 118 ++++++++++++++++++++
 6 files changed, 162 insertions(+), 5 deletions(-)
Signature · 1 line
2.40.1
#1 lore raw

PATCH v9 1/2 v4l2-utils: Add VIDIOC_REMOVE_BUFS ioctl

Add VIDIOC_REMOVE_BUFS ioctl and it associated structure. Define V4L2_BUF_CAP_SUPPORTS_REMOVE_BUFS to signal that queue support feature.

---
 include/linux/videodev2.h | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
include/linux/videodev2.h +16 -0
index 397a99e3..a4eb1afd 100644
@@ -992,6 +992,7 @@ struct v4l2_requestbuffers {
 #define V4L2_BUF_CAP_SUPPORTS_M2M_HOLD_CAPTURE_BUF	(1 << 5)
 #define V4L2_BUF_CAP_SUPPORTS_MMAP_CACHE_HINTS		(1 << 6)
 #define V4L2_BUF_CAP_SUPPORTS_MAX_NUM_BUFFERS		(1 << 7)
+#define V4L2_BUF_CAP_SUPPORTS_REMOVE_BUFS		(1 << 8)
 
 /**
  * struct v4l2_plane - plane info for multi-planar buffers
@@ -2564,6 +2565,20 @@ struct v4l2_create_buffers {
 	__u32			reserved[5];
 };
 
+/**
+ * struct v4l2_remove_buffers - VIDIOC_REMOVE_BUFS argument
+ * @index:	the first buffer to be removed
+ * @count:	number of buffers to removed
+ * @type:	enum v4l2_buf_type
+ * @reserved:	future extensions
+ */
+struct v4l2_remove_buffers {
+	__u32			index;
+	__u32			count;
+	__u32			type;
+	__u32			reserved[13];
+};
+
 /*
  *	I O C T L   C O D E S   F O R   V I D E O   D E V I C E S
  *
@@ -2663,6 +2678,7 @@ struct v4l2_create_buffers {
 #define VIDIOC_DBG_G_CHIP_INFO  _IOWR('V', 102, struct v4l2_dbg_chip_info)
 
 #define VIDIOC_QUERY_EXT_CTRL	_IOWR('V', 103, struct v4l2_query_ext_ctrl)
+#define VIDIOC_REMOVE_BUFS	_IOWR('V', 104, struct v4l2_remove_buffers)
 
 /* Reminder: when adding new ioctls please add support for them to
    drivers/media/v4l2-core/v4l2-compat-ioctl32.c as well! */
Signature · 1 line
2.40.1
#2 lore raw

PATCH v9 2/2 v4l2-compliance: Add a test for REMOVE_BUFS ioctl

In reply to Benjamin Gaignard

Add new test for REMOVE_BUFS ioctl.
It create buffers and check if they could be removed from queue. It also check that removing non existing buffer or a queued buffer failed.
Since using REMOVE_BUFS can create "holes" v4l_queue_querybufs() function needs to be modify to do a range check between [from..from+count-1].

---
version 9:
- Add tests to check return values when count = 0.
- Add tests to check return values when attempt to remove again buffers.
- Call fail_on_test(q.reqbufs(node, 0)) at the end of the test.
- Do not print WARN if REMOVE_BUFS ioctl isn't supported
- Stop testing if CREATE_BUFS is supported.

 utils/common/cv4l-helpers.h                 |   4 +
 utils/common/v4l-helpers.h                  |  27 ++++-
 utils/v4l2-compliance/v4l2-compliance.cpp   |   1 +
 utils/v4l2-compliance/v4l2-compliance.h     |   1 +
 utils/v4l2-compliance/v4l2-test-buffers.cpp | 118 ++++++++++++++++++++
 5 files changed, 146 insertions(+), 5 deletions(-)
utils/common/cv4l-helpers.h +4 -0
index 7299d2fa..ec33da78 100644
@@ -765,6 +765,10 @@ public:
 	{
 		return v4l_queue_reqbufs(fd->g_v4l_fd(), this, count, flags);
 	}
+	int remove_bufs(cv4l_fd *fd, unsigned index = 0, unsigned count = 0)
+	{
+		return v4l_queue_remove_bufs(fd->g_v4l_fd(), this, index, count);
+	}
 	bool has_create_bufs(cv4l_fd *fd) const
 	{
 		return v4l_queue_has_create_bufs(fd->g_v4l_fd(), this);
utils/common/v4l-helpers.h +22 -5
index 5ce3dabc..437a6844 100644
@@ -1547,12 +1547,29 @@ static inline void *v4l_queue_g_dataptr(const struct v4l_queue *q, unsigned inde
 	return v4l_queue_g_mmapping(q, index, plane);
 }
 
-static inline int v4l_queue_querybufs(struct v4l_fd *f, struct v4l_queue *q, unsigned from)
+static inline int v4l_queue_remove_bufs(struct v4l_fd *f, struct v4l_queue *q, unsigned index, unsigned count)
 {
-	unsigned b, p;
+	struct v4l2_remove_buffers removebufs;
 	int ret;
 
-	for (b = from; b < v4l_queue_g_buffers(q); b++) {
+	memset(&removebufs, 0, sizeof(removebufs));
+	removebufs.type = q->type;
+	removebufs.index = index;
+	removebufs.count = count;
+
+	ret = v4l_ioctl(f, VIDIOC_REMOVE_BUFS, &removebufs);
+	if (!ret)
+		q->buffers -= removebufs.count;
+
+	return ret;
+}
+
+static inline int v4l_queue_querybufs(struct v4l_fd *f, struct v4l_queue *q, unsigned from, unsigned count)
+{
+	unsigned b, p, max = from + count;
+	int ret;
+
+	for (b = from; b < max; b++) {
 		struct v4l_buffer buf;
 
 		v4l_buffer_init(&buf, v4l_queue_g_type(q), v4l_queue_g_memory(q), b);
@@ -1605,7 +1622,7 @@ static inline int v4l_queue_reqbufs(struct v4l_fd *f,
 			}
 		}
 	}
-	return v4l_queue_querybufs(f, q, 0);
+	return v4l_queue_querybufs(f, q, 0, reqbufs.count);
 }
 
 static inline bool v4l_queue_has_create_bufs(struct v4l_fd *f, const struct v4l_queue *q)
@@ -1649,7 +1666,7 @@ static inline int v4l_queue_create_bufs(struct v4l_fd *f,
 		}
 	}
 	q->buffers += createbufs.count;
-	return v4l_queue_querybufs(f, q, q->buffers - createbufs.count);
+	return v4l_queue_querybufs(f, q, createbufs.index, createbufs.count);
 }
 
 static inline int v4l_queue_mmap_bufs(struct v4l_fd *f,
utils/v4l2-compliance/v4l2-compliance.cpp +1 -0
index 2f7a5058..c6a685eb 100644
@@ -1466,6 +1466,7 @@ void testNode(struct node &node, struct node &node_m2m_cap, struct node &expbuf_
 		printf("Buffer ioctls%s:\n", suffix);
 		printf("\ttest VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: %s\n", ok(testReqBufs(&node)));
 		printf("\ttest CREATE_BUFS maximum buffers: %s\n", ok(testCreateBufsMax(&node)));
+		printf("\ttest VIDIOC_REMOVE_BUFS: %s\n", ok(testRemoveBufs(&node)));
 		// Reopen after each streaming test to reset the streaming state
 		// in case of any errors in the preceeding test.
 		node.reopen();
utils/v4l2-compliance/v4l2-compliance.h +1 -0
index 0cfc9a37..b6e342f3 100644
@@ -385,6 +385,7 @@ int testReadWrite(struct node *node);
 int testExpBuf(struct node *node);
 int testBlockingWait(struct node *node);
 int testCreateBufsMax(struct node *node);
+int testRemoveBufs(struct node *node);
 
 // 32-bit architecture, 32/64-bit time_t tests
 int testTime32_64(struct node *node);
utils/v4l2-compliance/v4l2-test-buffers.cpp +118 -0

124 lines not on this page · raw message

Signature · 1 line
2.40.1