[v7,06/13] app/test: add basic dmadev instance tests

Message ID 20211013151736.762378-7-bruce.richardson@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series add test suite for DMA drivers |

Checks

Context Check Description
ci/checkpatch warning coding style issues

Commit Message

Bruce Richardson Oct. 13, 2021, 3:17 p.m. UTC
  Run basic sanity tests for configuring, starting and stopping a dmadev
instance to help validate drivers. This also provides the framework for
future tests for data-path operation.

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
Reviewed-by: Conor Walsh <conor.walsh@intel.com>
Reviewed-by: Kevin Laatz <kevin.laatz@intel.com>
---
 app/test/test_dmadev.c | 74 +++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 73 insertions(+), 1 deletion(-)
  

Patch

diff --git a/app/test/test_dmadev.c b/app/test/test_dmadev.c
index 45da6b76fe..e974936f25 100644
--- a/app/test/test_dmadev.c
+++ b/app/test/test_dmadev.c
@@ -3,12 +3,75 @@ 
  * Copyright(c) 2021 Intel Corporation
  */
 
+#include <inttypes.h>
+
 #include <rte_dmadev.h>
 #include <rte_bus_vdev.h>
+#include <rte_dmadev_pmd.h>
 
 #include "test.h"
 #include "test_dmadev_api.h"
 
+#define ERR_RETURN(...) do { print_err(__func__, __LINE__, __VA_ARGS__); return -1; } while (0)
+
+static void
+__rte_format_printf(3, 4)
+print_err(const char *func, int lineno, const char *format, ...)
+{
+	va_list ap;
+
+	fprintf(stderr, "In %s:%d - ", func, lineno);
+	va_start(ap, format);
+	vfprintf(stderr, format, ap);
+	va_end(ap);
+}
+
+static int
+test_dmadev_instance(int16_t dev_id)
+{
+#define TEST_RINGSIZE 512
+	struct rte_dma_stats stats;
+	struct rte_dma_info info;
+	const struct rte_dma_conf conf = { .nb_vchans = 1};
+	const struct rte_dma_vchan_conf qconf = {
+			.direction = RTE_DMA_DIR_MEM_TO_MEM,
+			.nb_desc = TEST_RINGSIZE,
+	};
+	const int vchan = 0;
+
+	printf("\n### Test dmadev instance %u [%s]\n",
+			dev_id, rte_dma_devices[dev_id].data->dev_name);
+
+	rte_dma_info_get(dev_id, &info);
+	if (info.max_vchans < 1)
+		ERR_RETURN("Error, no channels available on device id %u\n", dev_id);
+
+	if (rte_dma_configure(dev_id, &conf) != 0)
+		ERR_RETURN("Error with rte_dma_configure()\n");
+
+	if (rte_dma_vchan_setup(dev_id, vchan, &qconf) < 0)
+		ERR_RETURN("Error with queue configuration\n");
+
+	rte_dma_info_get(dev_id, &info);
+	if (info.nb_vchans != 1)
+		ERR_RETURN("Error, no configured queues reported on device id %u\n", dev_id);
+
+	if (rte_dma_start(dev_id) != 0)
+		ERR_RETURN("Error with rte_dma_start()\n");
+
+	if (rte_dma_stats_get(dev_id, vchan, &stats) != 0)
+		ERR_RETURN("Error with rte_dma_stats_get()\n");
+
+	if (stats.completed != 0 || stats.submitted != 0 || stats.errors != 0)
+		ERR_RETURN("Error device stats are not all zero: completed = %"PRIu64", "
+				"submitted = %"PRIu64", errors = %"PRIu64"\n",
+				stats.completed, stats.submitted, stats.errors);
+
+	rte_dma_stop(dev_id);
+	rte_dma_stats_reset(dev_id, vchan);
+	return 0;
+}
+
 static int
 test_apis(void)
 {
@@ -31,9 +94,18 @@  test_apis(void)
 static int
 test_dma(void)
 {
+	int i;
+
 	/* basic sanity on dmadev infrastructure */
 	if (test_apis() < 0)
-		return -1;
+		ERR_RETURN("Error performing API tests\n");
+
+	if (rte_dma_count_avail() == 0)
+		return TEST_SKIPPED;
+
+	RTE_DMA_FOREACH_DEV(i)
+		if (test_dmadev_instance(i) < 0)
+			ERR_RETURN("Error, test failure for device %d\n", i);
 
 	return 0;
 }