DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH 1/2] raw/skeleton: fix selftest
@ 2023-03-10 14:26 David Marchand
  2023-03-10 14:26 ` [PATCH 2/2] test: add rawdev to fast tests David Marchand
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: David Marchand @ 2023-03-10 14:26 UTC (permalink / raw)
  To: dev; +Cc: stable, Sachin Saxena, Hemant Agrawal, Shreyansh Jain

ASan reported issues in this driver.

rte_rawdev_obj_t context object points at a uint16_t.
skeleton_rawdev_enqueue_bufs() and skeleton_rawdev_dequeue_bufs() were
incorrectly casting to an int.

The enqueue/dequeue selftest had a leak on the enqueued string and was
wrong in passing a rte_rawdev_buf pointer array.
Fix this by allocating buffers on the stack and check that returned
string is the expected one.

Bugzilla ID: 1175
Fixes: 61c592a8d035 ("raw/skeleton: introduce skeleton rawdev driver")
Fixes: 55ca1b0f2151 ("raw/skeleton: add test cases")
Cc: stable@dpdk.org

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 drivers/raw/skeleton/skeleton_rawdev.c      |  4 +-
 drivers/raw/skeleton/skeleton_rawdev_test.c | 46 +++++++++------------
 2 files changed, 22 insertions(+), 28 deletions(-)

diff --git a/drivers/raw/skeleton/skeleton_rawdev.c b/drivers/raw/skeleton/skeleton_rawdev.c
index 53fe49f936..6e99d35536 100644
--- a/drivers/raw/skeleton/skeleton_rawdev.c
+++ b/drivers/raw/skeleton/skeleton_rawdev.c
@@ -428,7 +428,7 @@ static int skeleton_rawdev_enqueue_bufs(struct rte_rawdev *dev,
 	 * help in complex implementation which require more information than
 	 * just an integer - for example, a queue-pair.
 	 */
-	q_id = *((int *)context);
+	q_id = *((uint16_t *)context);
 
 	for (i = 0; i < count; i++)
 		queue_buf[q_id].bufs[i] = buffers[i]->buf_addr;
@@ -450,7 +450,7 @@ static int skeleton_rawdev_dequeue_bufs(struct rte_rawdev *dev,
 	 * help in complex implementation which require more information than
 	 * just an integer - for example, a queue-pair.
 	 */
-	q_id = *((int *)context);
+	q_id = *((uint16_t *)context);
 
 	for (i = 0; i < count; i++)
 		buffers[i]->buf_addr = queue_buf[q_id].bufs[i];
diff --git a/drivers/raw/skeleton/skeleton_rawdev_test.c b/drivers/raw/skeleton/skeleton_rawdev_test.c
index ca15c49990..b7a7f623aa 100644
--- a/drivers/raw/skeleton/skeleton_rawdev_test.c
+++ b/drivers/raw/skeleton/skeleton_rawdev_test.c
@@ -370,40 +370,34 @@ static int
 test_rawdev_enqdeq(void)
 {
 	int ret;
-	unsigned int count = 1;
 	uint16_t queue_id = 0;
-	struct rte_rawdev_buf buffers[1];
-	struct rte_rawdev_buf *deq_buffers = NULL;
-
-	buffers[0].buf_addr = malloc(strlen(TEST_DEV_NAME) + 3);
-	if (!buffers[0].buf_addr)
-		goto cleanup;
-	snprintf(buffers[0].buf_addr, strlen(TEST_DEV_NAME) + 2, "%s%d",
+	struct rte_rawdev_buf buffer;
+	struct rte_rawdev_buf *buffers[1];
+	struct rte_rawdev_buf deq_buffer;
+	struct rte_rawdev_buf *deq_buffers[1];
+
+	buffers[0] = &buffer;
+	buffer.buf_addr = malloc(strlen(TEST_DEV_NAME) + 3);
+	if (!buffer.buf_addr)
+		return TEST_FAILED;
+	snprintf(buffer.buf_addr, strlen(TEST_DEV_NAME) + 2, "%s%d",
 		 TEST_DEV_NAME, 0);
 
-	ret = rte_rawdev_enqueue_buffers(test_dev_id,
-					 (struct rte_rawdev_buf **)&buffers,
-					 count, &queue_id);
-	RTE_TEST_ASSERT_EQUAL((unsigned int)ret, count,
+	ret = rte_rawdev_enqueue_buffers(test_dev_id, buffers,
+					 RTE_DIM(buffers), &queue_id);
+	RTE_TEST_ASSERT_EQUAL((unsigned int)ret, RTE_DIM(buffers),
 			      "Unable to enqueue buffers");
 
-	deq_buffers = malloc(sizeof(struct rte_rawdev_buf) * count);
-	if (!deq_buffers)
-		goto cleanup;
-
-	ret = rte_rawdev_dequeue_buffers(test_dev_id,
-					(struct rte_rawdev_buf **)&deq_buffers,
-					count, &queue_id);
-	RTE_TEST_ASSERT_EQUAL((unsigned int)ret, count,
+	deq_buffers[0] = &deq_buffer;
+	ret = rte_rawdev_dequeue_buffers(test_dev_id, deq_buffers,
+					RTE_DIM(deq_buffers), &queue_id);
+	RTE_TEST_ASSERT_EQUAL((unsigned int)ret, RTE_DIM(buffers),
 			      "Unable to dequeue buffers");
+	RTE_TEST_ASSERT_EQUAL(deq_buffers[0]->buf_addr, buffers[0]->buf_addr,
+			      "Did not retrieve expected object");
 
-	free(deq_buffers);
-
+	free(buffer.buf_addr);
 	return TEST_SUCCESS;
-cleanup:
-	free(buffers[0].buf_addr);
-
-	return TEST_FAILED;
 }
 
 static void skeldev_test_run(int (*setup)(void),
-- 
2.39.2


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-03-16 12:51 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-10 14:26 [PATCH 1/2] raw/skeleton: fix selftest David Marchand
2023-03-10 14:26 ` [PATCH 2/2] test: add rawdev to fast tests David Marchand
2023-03-16  8:27   ` Hemant Agrawal
2023-03-13  2:17 ` [PATCH 1/2] raw/skeleton: fix selftest Jiang, YuX
2023-03-14  8:39 ` David Marchand
2023-03-16  8:26 ` Hemant Agrawal
2023-03-16 12:51 ` David Marchand

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).