[dpdk-dev] [RFC PATCH 4/7] app/test: add basic dmadev copy tests

Jerin Jacob jerinjacobk at gmail.com
Fri Aug 27 09:14:17 CEST 2021


On Fri, Aug 27, 2021 at 12:03 AM Bruce Richardson
<bruce.richardson at intel.com> wrote:
>
> For each dmadev instance, perform some basic copy tests to validate that
> functionality.
>
> Signed-off-by: Bruce Richardson <bruce.richardson at intel.com>
> ---
>  app/test/test_dmadev.c | 157 +++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 157 insertions(+)
>
> diff --git a/app/test/test_dmadev.c b/app/test/test_dmadev.c
> index f895556d29..a9f7d34a94 100644
> --- a/app/test/test_dmadev.c
> +++ b/app/test/test_dmadev.c
> @@ -1,11 +1,14 @@
>  /* SPDX-License-Identifier: BSD-3-Clause
>   * Copyright(c) 2021 HiSilicon Limited.
>   */
> +#include <unistd.h>
>
>  #include <rte_common.h>
>  #include <rte_dev.h>
>  #include <rte_dmadev.h>
>  #include <rte_bus_vdev.h>
> +#include <rte_mbuf.h>
> +#include <rte_random.h>
>
>  #include "test.h"
>
> @@ -14,6 +17,11 @@ extern int test_dmadev_api(uint16_t dev_id);
>
>  #define PRINT_ERR(...) print_err(__func__, __LINE__, __VA_ARGS__)
>
> +#define COPY_LEN 1024
> +
> +static struct rte_mempool *pool;
> +static uint16_t id_count;
> +
>  static inline int
>  __rte_format_printf(3, 4)
>  print_err(const char *func, int lineno, const char *format, ...)
> @@ -29,10 +37,123 @@ print_err(const char *func, int lineno, const char *format, ...)
>         return ret;
>  }
>
> +static int
> +test_enqueue_copies(int dev_id, uint16_t vchan)
> +{
> +       unsigned int i;
> +       uint16_t id;
> +
> +       /* test doing a single copy */
> +       do {
> +               struct rte_mbuf *src, *dst;
> +               char *src_data, *dst_data;
> +
> +               src = rte_pktmbuf_alloc(pool);
> +               dst = rte_pktmbuf_alloc(pool);
> +               src_data = rte_pktmbuf_mtod(src, char *);
> +               dst_data = rte_pktmbuf_mtod(dst, char *);
> +
> +               for (i = 0; i < COPY_LEN; i++)
> +                       src_data[i] = rte_rand() & 0xFF;
> +
> +               id = rte_dmadev_copy(dev_id, vchan, src->buf_iova + src->data_off,
> +                               dst->buf_iova + dst->data_off, COPY_LEN, RTE_DMA_OP_FLAG_SUBMIT);
> +               if (id != id_count) {
> +                       PRINT_ERR("Error with rte_dmadev_copy, got %u, expected %u\n",
> +                                       id, id_count);
> +                       return -1;
> +               }
> +
> +               /* give time for copy to finish, then check it was done */
> +               usleep(10);

Across series, We have this pattern. IMHO, It is not portable.
Can we have a helper function either common lib code or test code to
busy poll for completion with timeout? and in test code, we have a much bigger
timeout to accommodate all the devices. That way if the driver completes
early it can continue to execute and makes it portable.


> +
> +               for (i = 0; i < COPY_LEN; i++) {
> +                       if (dst_data[i] != src_data[i]) {
> +                               PRINT_ERR("Data mismatch at char %u [Got %02x not %02x]\n", i,
> +                                               dst_data[i], src_data[i]);
> +                               rte_dmadev_dump(dev_id, stderr);
> +                               return -1;
> +                       }
> +               }
> +
> +               /* now check completion works */
> +               if (rte_dmadev_completed(dev_id, vchan, 1, &id, NULL) != 1) {
> +                       PRINT_ERR("Error with rte_dmadev_completed\n");
> +                       return -1;
> +               }
> +               if (id != id_count) {
> +                       PRINT_ERR("Error:incorrect job id received, %u [expected %u]\n",
> +                                       id, id_count);
> +                       return -1;
> +               }
> +


More information about the dev mailing list