From patchwork Fri Nov 3 15:38:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gowrishankar Muthukrishnan X-Patchwork-Id: 133839 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id F3F2D4327C; Fri, 3 Nov 2023 16:38:18 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id BC90242DBB; Fri, 3 Nov 2023 16:38:16 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id F163842DA7 for ; Fri, 3 Nov 2023 16:38:14 +0100 (CET) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3A3BVqKm028584; Fri, 3 Nov 2023 08:38:14 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=L/HWYpS5lj2WohkBKBYAf/kEFDkfevFqUb4sgNBmINQ=; b=DGAuN4BU4Wc0YpjA5xqFplujJuYcKmrufBd5uVuulZXPX9/hUVAxRkrwTcHhhDVxKtSE bR2LQ7pxiIvuY+9FCs0GW7vsmCCF0SSiwKpr9LKg+AdP6bcQhnAmpM1XaO3lnVn2Vo5I VRnxff4HHgkvM0+o4oRJ5u/aTK7b1WTm1KH4kLVt1xYP0RTjzwC4DKsXV2Ujq4a2VNIJ MvD7HiLSH8IGWDs9d2slGETS0MRojf9mEE3pRs6s7dLn5v9sOmExhKyyL6D6JgFzCxsN 94K3K0gQ1VRe5gXj2DTE/eX3wFmUYj+LOMd/H/CX+0tAGtMTr2N2m3B27kjwkVOYTDBz JQ== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3u4upkhh1j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Fri, 03 Nov 2023 08:38:13 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Fri, 3 Nov 2023 08:38:12 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.48 via Frontend Transport; Fri, 3 Nov 2023 08:38:12 -0700 Received: from BG-LT91401.marvell.com (BG-LT91401.marvell.com [10.28.168.34]) by maili.marvell.com (Postfix) with ESMTP id 586BC3F70B8; Fri, 3 Nov 2023 08:38:09 -0700 (PDT) From: Gowrishankar Muthukrishnan To: CC: , Chengwen Feng , "Vamsi Attunuru" , Amit Prakash Shukla , Vidya Sagar Velumuri , Kevin Laatz , Bruce Richardson , Gowrishankar Muthukrishnan Subject: [PATCH v3 1/3] test/dma: use unit test framework Date: Fri, 3 Nov 2023 21:08:01 +0530 Message-ID: <67a9b287681794a30ef68ee34782a59d6d3e009e.1699025423.git.gmuthukrishn@marvell.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: ea4yuI1pIiIvZSXKYyApqGPXO7kYvwMe X-Proofpoint-GUID: ea4yuI1pIiIvZSXKYyApqGPXO7kYvwMe X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.987,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-11-03_15,2023-11-02_03,2023-05-22_02 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Use unit test framework to execute DMA tests. Signed-off-by: Gowrishankar Muthukrishnan Suggested-by: Chengwen Feng --- app/test/test_dmadev.c | 240 ++++++++++++++++++++++++++++--------- app/test/test_dmadev_api.c | 89 ++++---------- 2 files changed, 212 insertions(+), 117 deletions(-) diff --git a/app/test/test_dmadev.c b/app/test/test_dmadev.c index 216f84b6bb..780941fc1e 100644 --- a/app/test/test_dmadev.c +++ b/app/test/test_dmadev.c @@ -22,7 +22,9 @@ #define COPY_LEN 1024 static struct rte_mempool *pool; +static int16_t test_dev_id; static uint16_t id_count; +static int vchan; enum { TEST_PARAM_REMOTE_ADDR = 0, @@ -61,13 +63,35 @@ print_err(const char *func, int lineno, const char *format, ...) va_end(ap); } +struct runtest_param { + const char *printable; + int (*test_fn)(int16_t dev_id, uint16_t vchan); + int iterations; + int16_t dev_id; + uint16_t vchan; + bool check_err_stats; +}; + static int -runtest(const char *printable, int (*test_fn)(int16_t dev_id, uint16_t vchan), int iterations, - int16_t dev_id, uint16_t vchan, bool check_err_stats) +runtest(const void *args) { + int (*test_fn)(int16_t dev_id, uint16_t vchan); + const struct runtest_param *param = args; struct rte_dma_stats stats; + const char *printable; + bool check_err_stats; + int iterations; + int16_t dev_id; + uint16_t vchan; int i; + printable = param->printable; + iterations = param->iterations; + dev_id = param->dev_id; + vchan = param->vchan; + check_err_stats = param->check_err_stats; + test_fn = param->test_fn; + rte_dma_stats_reset(dev_id, vchan); printf("DMA Dev %d: Running %s Tests %s\n", dev_id, printable, check_err_stats ? " " : "(errors expected)"); @@ -918,9 +942,21 @@ test_m2d_auto_free(int16_t dev_id, uint16_t vchan) } static int -test_dmadev_instance(int16_t dev_id) +test_dmadev_burst_setup(void) { -#define CHECK_ERRS true + if (rte_dma_burst_capacity(test_dev_id, vchan) < 64) { + printf("DMA Dev %u: insufficient burst capacity (64 required), skipping tests\n", + test_dev_id); + return TEST_SKIPPED; + } + + return TEST_SUCCESS; +} + +static int +test_dmadev_setup(void) +{ + int16_t dev_id = test_dev_id; struct rte_dma_stats stats; struct rte_dma_info info; const struct rte_dma_conf conf = { .nb_vchans = 1}; @@ -928,16 +964,12 @@ test_dmadev_instance(int16_t dev_id) .direction = RTE_DMA_DIR_MEM_TO_MEM, .nb_desc = TEST_RINGSIZE, }; - const int vchan = 0; int ret; ret = rte_dma_info_get(dev_id, &info); if (ret != 0) ERR_RETURN("Error with rte_dma_info_get()\n"); - printf("\n### Test dmadev instance %u [%s]\n", - dev_id, info.dev_name); - if (info.max_vchans < 1) ERR_RETURN("Error, no channels available on device id %u\n", dev_id); @@ -976,20 +1008,123 @@ test_dmadev_instance(int16_t dev_id) if (pool == NULL) ERR_RETURN("Error with mempool creation\n"); + return 0; +} + +static void +test_dmadev_teardown(void) +{ + rte_mempool_free(pool); + rte_dma_stop(test_dev_id); + rte_dma_stats_reset(test_dev_id, vchan); + test_dev_id = -EINVAL; +} + +static int +test_dmadev_instance(int16_t dev_id) +{ +#define CHECK_ERRS true + enum { + TEST_COPY = 0, + TEST_START, + TEST_BURST, + TEST_ERR, + TEST_FILL, + TEST_M2D, + TEST_END + }; + + struct runtest_param param[TEST_END]; + struct rte_dma_info dev_info; + struct unit_test_suite *ts; + struct unit_test_case *tc; + int ret; + + if (rte_dma_info_get(dev_id, &dev_info) < 0) + return TEST_SKIPPED; + + test_dev_id = dev_id; + vchan = 0; + + ts = calloc(1, sizeof(struct unit_test_suite) + + sizeof(struct unit_test_case) * (TEST_END + 1)); + + ts->suite_name = "DMA dev instance testsuite"; + ts->setup = test_dmadev_setup; + ts->teardown = test_dmadev_teardown; + + param[TEST_COPY].printable = "copy"; + param[TEST_COPY].test_fn = test_enqueue_copies; + param[TEST_COPY].iterations = 640; + param[TEST_COPY].dev_id = dev_id; + param[TEST_COPY].vchan = vchan; + param[TEST_COPY].check_err_stats = CHECK_ERRS; + + param[TEST_START].printable = "stop-start"; + param[TEST_START].test_fn = test_stop_start; + param[TEST_START].iterations = 1; + param[TEST_START].dev_id = dev_id; + param[TEST_START].vchan = vchan; + param[TEST_START].check_err_stats = CHECK_ERRS; + + param[TEST_BURST].printable = "burst capacity"; + param[TEST_BURST].test_fn = test_burst_capacity; + param[TEST_BURST].iterations = 1; + param[TEST_BURST].dev_id = dev_id; + param[TEST_BURST].vchan = vchan; + param[TEST_BURST].check_err_stats = CHECK_ERRS; + + param[TEST_ERR].printable = "error handling"; + param[TEST_ERR].test_fn = test_completion_handling; + param[TEST_ERR].iterations = 1; + param[TEST_ERR].dev_id = dev_id; + param[TEST_ERR].vchan = vchan; + param[TEST_ERR].check_err_stats = CHECK_ERRS; + + param[TEST_FILL].printable = "fill"; + param[TEST_FILL].test_fn = test_enqueue_fill; + param[TEST_FILL].iterations = 1; + param[TEST_FILL].dev_id = dev_id; + param[TEST_FILL].vchan = vchan; + param[TEST_FILL].check_err_stats = CHECK_ERRS; + + param[TEST_M2D].printable = "m2d_auto_free"; + param[TEST_M2D].test_fn = test_m2d_auto_free; + param[TEST_M2D].iterations = 128; + param[TEST_M2D].dev_id = dev_id; + param[TEST_M2D].vchan = vchan; + param[TEST_M2D].check_err_stats = CHECK_ERRS; + + for (int i = 0; i < TEST_END; i++) { + tc = &ts->unit_test_cases[i]; + tc->setup = NULL; + tc->teardown = NULL; + tc->testcase = NULL; + tc->testcase_with_data = runtest; + tc->data = ¶m[i]; + tc->enabled = 0; + } + + tc = &ts->unit_test_cases[TEST_END]; + tc->setup = NULL; + tc->teardown = NULL; + tc->testcase = NULL; + tc->testcase_with_data = NULL; + tc->data = NULL; + tc->enabled = 0; + + printf("\n### Test dmadev instance %u [%s]\n", + dev_id, dev_info.dev_name); + /* run the test cases, use many iterations to ensure UINT16_MAX id wraparound */ - if (runtest("copy", test_enqueue_copies, 640, dev_id, vchan, CHECK_ERRS) < 0) - goto err; + ts->unit_test_cases[TEST_COPY].enabled = 1; /* run tests stopping/starting devices and check jobs still work after restart */ - if (runtest("stop-start", test_stop_start, 1, dev_id, vchan, CHECK_ERRS) < 0) - goto err; + ts->unit_test_cases[TEST_START].enabled = 1; /* run some burst capacity tests */ - if (rte_dma_burst_capacity(dev_id, vchan) < 64) - printf("DMA Dev %u: insufficient burst capacity (64 required), skipping tests\n", - dev_id); - else if (runtest("burst capacity", test_burst_capacity, 1, dev_id, vchan, CHECK_ERRS) < 0) - goto err; + ts->unit_test_cases[TEST_BURST].setup = test_dmadev_burst_setup; + ts->unit_test_cases[TEST_BURST].enabled = 1; /* to test error handling we can provide null pointers for source or dest in copies. This * requires VA mode in DPDK, since NULL(0) is a valid physical address. @@ -997,55 +1132,40 @@ test_dmadev_instance(int16_t dev_id) */ if (rte_eal_iova_mode() != RTE_IOVA_VA) printf("DMA Dev %u: DPDK not in VA mode, skipping error handling tests\n", dev_id); - else if ((info.dev_capa & RTE_DMA_CAPA_HANDLES_ERRORS) == 0) + else if ((dev_info.dev_capa & RTE_DMA_CAPA_HANDLES_ERRORS) == 0) printf("DMA Dev %u: device does not report errors, skipping error handling tests\n", dev_id); - else if (runtest("error handling", test_completion_handling, 1, - dev_id, vchan, !CHECK_ERRS) < 0) - goto err; + else + ts->unit_test_cases[TEST_ERR].enabled = 1; - if ((info.dev_capa & RTE_DMA_CAPA_OPS_FILL) == 0) + if ((dev_info.dev_capa & RTE_DMA_CAPA_OPS_FILL) == 0) printf("DMA Dev %u: No device fill support, skipping fill tests\n", dev_id); - else if (runtest("fill", test_enqueue_fill, 1, dev_id, vchan, CHECK_ERRS) < 0) - goto err; + else + ts->unit_test_cases[TEST_FILL].enabled = 1; - if ((info.dev_capa & RTE_DMA_CAPA_M2D_AUTO_FREE) && + if ((dev_info.dev_capa & RTE_DMA_CAPA_M2D_AUTO_FREE) && dma_add_test[TEST_M2D_AUTO_FREE].enabled == true) { - if (runtest("m2d_auto_free", test_m2d_auto_free, 128, dev_id, vchan, - CHECK_ERRS) < 0) - goto err; + ts->unit_test_cases[TEST_M2D].enabled = 1; } - rte_mempool_free(pool); - - if (rte_dma_stop(dev_id) < 0) - ERR_RETURN("Error stopping device %u\n", dev_id); - - rte_dma_stats_reset(dev_id, vchan); - return 0; + ret = unit_test_suite_runner(ts); + test_dev_id = -EINVAL; + free(ts); -err: - rte_mempool_free(pool); - rte_dma_stop(dev_id); - return -1; + return ret; } static int -test_apis(void) +test_apis(const void *args) { - const char *pmd = "dma_skeleton"; - int id; - int ret; + const int16_t dev_id = *(const int16_t *)args; + struct rte_dma_info dev_info; - /* attempt to create skeleton instance - ignore errors due to one being already present */ - rte_vdev_init(pmd, NULL); - id = rte_dma_get_dev_id_by_name(pmd); - if (id < 0) + if (rte_dma_info_get(dev_id, &dev_info) < 0) return TEST_SKIPPED; - printf("\n### Test dmadev infrastructure using skeleton driver\n"); - ret = test_dma_api(id); - return ret; + printf("\n### Test dmadev infrastructure using %s\n", dev_info.dev_name); + return test_dma_api(dev_id); } static void @@ -1088,16 +1208,28 @@ parse_dma_env_var(void) static int test_dma(void) { - int i; + const char *pmd = "dma_skeleton"; + int i, avail; parse_dma_env_var(); + /* attempt to create skeleton instance - ignore errors due to one being already present*/ + rte_vdev_init(pmd, NULL); + i = rte_dma_get_dev_id_by_name(pmd); + if (i < 0) + return TEST_SKIPPED; + /* basic sanity on dmadev infrastructure */ - if (test_apis() < 0) + if (test_apis(&i) < 0) ERR_RETURN("Error performing API tests\n"); - if (rte_dma_count_avail() == 0) - return TEST_SKIPPED; + avail = rte_dma_count_avail(); + if (avail == 0) + return 0; + + i = rte_dma_next_dev(0); + if (avail > 1 && test_apis(&i) < 0) + ERR_RETURN("Error performing API tests\n"); RTE_DMA_FOREACH_DEV(i) if (test_dmadev_instance(i) < 0) diff --git a/app/test/test_dmadev_api.c b/app/test/test_dmadev_api.c index 4a181af90a..da8fddb3ca 100644 --- a/app/test/test_dmadev_api.c +++ b/app/test/test_dmadev_api.c @@ -9,31 +9,22 @@ #include #include -extern int test_dma_api(uint16_t dev_id); +#include "test.h" -#define DMA_TEST_API_RUN(test) \ - testsuite_run_test(test, #test) +extern int test_dma_api(uint16_t dev_id); #define TEST_MEMCPY_SIZE 1024 #define TEST_WAIT_US_VAL 50000 -#define TEST_SUCCESS 0 -#define TEST_FAILED -1 - static int16_t test_dev_id; static int16_t invalid_dev_id; static char *src; static char *dst; -static int total; -static int passed; -static int failed; - static int -testsuite_setup(int16_t dev_id) +testsuite_setup(void) { - test_dev_id = dev_id; invalid_dev_id = -1; src = rte_malloc("dmadev_test_src", TEST_MEMCPY_SIZE, 0); @@ -46,10 +37,6 @@ testsuite_setup(int16_t dev_id) return -ENOMEM; } - total = 0; - passed = 0; - failed = 0; - /* Set dmadev log level to critical to suppress unnecessary output * during API tests. */ @@ -71,25 +58,6 @@ testsuite_teardown(void) rte_log_set_level_pattern("lib.dmadev", RTE_LOG_INFO); } -static void -testsuite_run_test(int (*test)(void), const char *name) -{ - int ret = 0; - - if (test) { - ret = test(); - if (ret < 0) { - failed++; - printf("%s Failed\n", name); - } else { - passed++; - printf("%s Passed\n", name); - } - } - - total++; -} - static int test_dma_get_dev_id_by_name(void) { @@ -301,7 +269,7 @@ setup_one_vchan(void) ret = rte_dma_info_get(test_dev_id, &dev_info); RTE_TEST_ASSERT_SUCCESS(ret, "Failed to obtain device info, %d", ret); - dev_conf.nb_vchans = dev_info.max_vchans; + dev_conf.nb_vchans = 1; ret = rte_dma_configure(test_dev_id, &dev_conf); RTE_TEST_ASSERT_SUCCESS(ret, "Failed to configure, %d", ret); vchan_conf.direction = RTE_DMA_DIR_MEM_TO_MEM; @@ -537,38 +505,33 @@ test_dma_completed_status(void) return TEST_SUCCESS; } +static struct unit_test_suite dma_api_testsuite = { + .suite_name = "DMA API Test Suite", + .setup = testsuite_setup, + .teardown = testsuite_teardown, + .unit_test_cases = { + TEST_CASE(test_dma_get_dev_id_by_name), + TEST_CASE(test_dma_is_valid_dev), + TEST_CASE(test_dma_count), + TEST_CASE(test_dma_info_get), + TEST_CASE(test_dma_configure), + TEST_CASE(test_dma_vchan_setup), + TEST_CASE(test_dma_start_stop), + TEST_CASE(test_dma_stats), + TEST_CASE(test_dma_dump), + TEST_CASE(test_dma_completed), + TEST_CASE(test_dma_completed_status), + TEST_CASES_END() + } +}; + int test_dma_api(uint16_t dev_id) { - int ret = testsuite_setup(dev_id); - if (ret) { - printf("testsuite setup fail!\n"); - return -1; - } + test_dev_id = dev_id; /* If the testcase exit successfully, ensure that the test dmadev exist * and the dmadev is in the stopped state. */ - DMA_TEST_API_RUN(test_dma_get_dev_id_by_name); - DMA_TEST_API_RUN(test_dma_is_valid_dev); - DMA_TEST_API_RUN(test_dma_count); - DMA_TEST_API_RUN(test_dma_info_get); - DMA_TEST_API_RUN(test_dma_configure); - DMA_TEST_API_RUN(test_dma_vchan_setup); - DMA_TEST_API_RUN(test_dma_start_stop); - DMA_TEST_API_RUN(test_dma_stats); - DMA_TEST_API_RUN(test_dma_dump); - DMA_TEST_API_RUN(test_dma_completed); - DMA_TEST_API_RUN(test_dma_completed_status); - - testsuite_teardown(); - - printf("Total tests : %d\n", total); - printf("Passed : %d\n", passed); - printf("Failed : %d\n", failed); - - if (failed) - return -1; - - return 0; + return unit_test_suite_runner(&dma_api_testsuite); }; From patchwork Fri Nov 3 15:38:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gowrishankar Muthukrishnan X-Patchwork-Id: 133840 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 576904327C; Fri, 3 Nov 2023 16:38:26 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0DCE542DD1; Fri, 3 Nov 2023 16:38:20 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id 5DC0A42DD0 for ; Fri, 3 Nov 2023 16:38:18 +0100 (CET) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3A3BVgd8010488; Fri, 3 Nov 2023 08:38:17 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=l/G7aoRIJigsPMo2B0IRROZZDkCNsjri+tXp1lPNPaQ=; b=SgoeTxkL+hxiLIMsFLsXD4H5w3zCdCipyMIeMPDhG6ElStQSKuSvYMxAJhTx89Wb7HRw HXGKsnEHAMEv/Hgy5fHhfJNqp3KfyrGhO69UTIXj8BhckWG55dvOLHiummV+aGErR4f1 h6Nm3RzmZk9dHZuAM1AOmKYFW6VtO5W9dvY12lLUbm8YLaY+B+hzLhCHzd3ZTdmtHn4n TC9N2QcojAdH7wIl48AbVcpNppOejXY6uxB82oa9OUx2iibumq/nR9ICpH+Aiv17ynLX p5MAkjQWBY1XEV51rdnUHt9EPvQvKTJefXiGKLw1R24+ulEz+Up4RZS/8qLF1S7qkoKO dQ== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3u4m34awnn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Fri, 03 Nov 2023 08:38:17 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Fri, 3 Nov 2023 08:38:15 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.48 via Frontend Transport; Fri, 3 Nov 2023 08:38:15 -0700 Received: from BG-LT91401.marvell.com (BG-LT91401.marvell.com [10.28.168.34]) by maili.marvell.com (Postfix) with ESMTP id B72973F70B2; Fri, 3 Nov 2023 08:38:12 -0700 (PDT) From: Gowrishankar Muthukrishnan To: CC: , Chengwen Feng , "Vamsi Attunuru" , Amit Prakash Shukla , Vidya Sagar Velumuri , Kevin Laatz , Bruce Richardson , Gowrishankar Muthukrishnan Subject: [PATCH v3 2/3] test/dma: test vchan reconfiguration Date: Fri, 3 Nov 2023 21:08:02 +0530 Message-ID: <2c7f6c7b3bec94325c6b96afbd8e9388a1c14a9d.1699025423.git.gmuthukrishn@marvell.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: pjTMpEiNhHm-0tff5M4lirPaTY0x8_Mz X-Proofpoint-GUID: pjTMpEiNhHm-0tff5M4lirPaTY0x8_Mz X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.987,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-11-03_15,2023-11-02_03,2023-05-22_02 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Reconfigure vchan count and validate if new count is effective. Signed-off-by: Gowrishankar Muthukrishnan --- app/test/test_dmadev_api.c | 63 +++++++++++++++++++++++++++++++++----- 1 file changed, 55 insertions(+), 8 deletions(-) diff --git a/app/test/test_dmadev_api.c b/app/test/test_dmadev_api.c index da8fddb3ca..aa07d2b359 100644 --- a/app/test/test_dmadev_api.c +++ b/app/test/test_dmadev_api.c @@ -260,7 +260,7 @@ test_dma_vchan_setup(void) } static int -setup_one_vchan(void) +setup_vchan(int nb_vchans) { struct rte_dma_vchan_conf vchan_conf = { 0 }; struct rte_dma_info dev_info = { 0 }; @@ -269,13 +269,15 @@ setup_one_vchan(void) ret = rte_dma_info_get(test_dev_id, &dev_info); RTE_TEST_ASSERT_SUCCESS(ret, "Failed to obtain device info, %d", ret); - dev_conf.nb_vchans = 1; + dev_conf.nb_vchans = nb_vchans; ret = rte_dma_configure(test_dev_id, &dev_conf); RTE_TEST_ASSERT_SUCCESS(ret, "Failed to configure, %d", ret); vchan_conf.direction = RTE_DMA_DIR_MEM_TO_MEM; vchan_conf.nb_desc = dev_info.min_desc; - ret = rte_dma_vchan_setup(test_dev_id, 0, &vchan_conf); - RTE_TEST_ASSERT_SUCCESS(ret, "Failed to setup vchan, %d", ret); + for (int i = 0; i < nb_vchans; i++) { + ret = rte_dma_vchan_setup(test_dev_id, i, &vchan_conf); + RTE_TEST_ASSERT_SUCCESS(ret, "Failed to setup vchan %d, %d", i, ret); + } return TEST_SUCCESS; } @@ -294,7 +296,7 @@ test_dma_start_stop(void) RTE_TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret); /* Setup one vchan for later test */ - ret = setup_one_vchan(); + ret = setup_vchan(1); RTE_TEST_ASSERT_SUCCESS(ret, "Failed to setup one vchan, %d", ret); ret = rte_dma_start(test_dev_id); @@ -312,6 +314,50 @@ test_dma_start_stop(void) return TEST_SUCCESS; } +static int +test_dma_reconfigure(void) +{ + struct rte_dma_conf dev_conf = { 0 }; + struct rte_dma_info dev_info = { 0 }; + uint16_t cfg_vchans; + int ret; + + ret = rte_dma_info_get(test_dev_id, &dev_info); + RTE_TEST_ASSERT_SUCCESS(ret, "Failed to obtain device info, %d", ret); + + /* At least two vchans required for the test */ + if (dev_info.max_vchans < 2) + return TEST_SKIPPED; + + /* Setup one vchan for later test */ + ret = setup_vchan(1); + RTE_TEST_ASSERT_SUCCESS(ret, "Failed to setup one vchan, %d", ret); + + ret = rte_dma_start(test_dev_id); + RTE_TEST_ASSERT_SUCCESS(ret, "Failed to start, %d", ret); + + ret = rte_dma_stop(test_dev_id); + RTE_TEST_ASSERT_SUCCESS(ret, "Failed to stop, %d", ret); + + /* Check reconfigure and vchan setup after device stopped */ + cfg_vchans = dev_conf.nb_vchans = (dev_info.max_vchans - 1); + + ret = setup_vchan(cfg_vchans); + RTE_TEST_ASSERT_SUCCESS(ret, "Failed to setup one vchan, %d", ret); + + ret = rte_dma_start(test_dev_id); + RTE_TEST_ASSERT_SUCCESS(ret, "Failed to start, %d", ret); + + ret = rte_dma_info_get(test_dev_id, &dev_info); + RTE_TEST_ASSERT_SUCCESS(ret, "Failed to obtain device info, %d", ret); + RTE_TEST_ASSERT_EQUAL(dev_info.nb_vchans, cfg_vchans, "incorrect reconfiguration"); + + ret = rte_dma_stop(test_dev_id); + RTE_TEST_ASSERT_SUCCESS(ret, "Failed to stop, %d", ret); + + return TEST_SUCCESS; +} + static int test_dma_stats(void) { @@ -328,7 +374,7 @@ test_dma_stats(void) RTE_TEST_ASSERT(ret == -EINVAL, "Expected -EINVAL, %d", ret); /* Setup one vchan for later test */ - ret = setup_one_vchan(); + ret = setup_vchan(1); RTE_TEST_ASSERT_SUCCESS(ret, "Failed to setup one vchan, %d", ret); /* Check for invalid vchan */ @@ -400,7 +446,7 @@ test_dma_completed(void) int ret; /* Setup one vchan for later test */ - ret = setup_one_vchan(); + ret = setup_vchan(1); RTE_TEST_ASSERT_SUCCESS(ret, "Failed to setup one vchan, %d", ret); ret = rte_dma_start(test_dev_id); @@ -459,7 +505,7 @@ test_dma_completed_status(void) int ret; /* Setup one vchan for later test */ - ret = setup_one_vchan(); + ret = setup_vchan(1); RTE_TEST_ASSERT_SUCCESS(ret, "Failed to setup one vchan, %d", ret); ret = rte_dma_start(test_dev_id); @@ -517,6 +563,7 @@ static struct unit_test_suite dma_api_testsuite = { TEST_CASE(test_dma_configure), TEST_CASE(test_dma_vchan_setup), TEST_CASE(test_dma_start_stop), + TEST_CASE(test_dma_reconfigure), TEST_CASE(test_dma_stats), TEST_CASE(test_dma_dump), TEST_CASE(test_dma_completed), From patchwork Fri Nov 3 15:38:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gowrishankar Muthukrishnan X-Patchwork-Id: 133841 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id BF02C4327C; Fri, 3 Nov 2023 16:38:32 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 41BB142DDD; Fri, 3 Nov 2023 16:38:23 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id 0734A42DDC for ; Fri, 3 Nov 2023 16:38:21 +0100 (CET) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3A3BVgxZ010483; Fri, 3 Nov 2023 08:38:21 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=FRobPminORP3A83KhCIe0TfwbdqLDxN3h04uG4X0Lks=; b=Nz9LhKtf51wvM4zJ3t4rc86c9U37KN0Z0eixQiWy3VWjDgAWCbxPBx1iVOyQYcOH55Hg SVEx4Q+32ClCtQXqxrejP79UrUcSGE7MFJn1znlFAZjWcM5t6zAdZQshqdqr+nwEn7tD 8VrvYZarb31pjkkx7soOzmKtq5fP9enQJsSZC8FSnYAgixCA5KrWK0DgYWGAX/oQ7nTx uw6msu6PSFKt9Ox3mF0R2+KUPc7qJ9GHIo3HXt9ncL5GxnG5WM6FsACFyUg+FTQT0yNk IG1SjzRNbTTmsFk11D40sN+23KUTOay9/JjdTjQ9UOeEjZgDwwjHDV+JkO1ZQtbrUFCY hA== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3u4m34awnu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Fri, 03 Nov 2023 08:38:21 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Fri, 3 Nov 2023 08:38:19 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.48 via Frontend Transport; Fri, 3 Nov 2023 08:38:19 -0700 Received: from BG-LT91401.marvell.com (BG-LT91401.marvell.com [10.28.168.34]) by maili.marvell.com (Postfix) with ESMTP id 28C393F70BF; Fri, 3 Nov 2023 08:38:15 -0700 (PDT) From: Gowrishankar Muthukrishnan To: CC: , Chengwen Feng , "Vamsi Attunuru" , Amit Prakash Shukla , Vidya Sagar Velumuri , Kevin Laatz , Bruce Richardson , Gowrishankar Muthukrishnan Subject: [PATCH v3 3/3] test/dma: add SG copy tests Date: Fri, 3 Nov 2023 21:08:03 +0530 Message-ID: <7c61824f1ed1e720c974d1baadfa7c55578c0c4f.1699025423.git.gmuthukrishn@marvell.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: J09bwy4CsUNN7eKZDvpYsztGNWnGPbtz X-Proofpoint-GUID: J09bwy4CsUNN7eKZDvpYsztGNWnGPbtz X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.987,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-11-03_15,2023-11-02_03,2023-05-22_02 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Add scatter-gather copy tests. Signed-off-by: Vidya Sagar Velumuri Signed-off-by: Gowrishankar Muthukrishnan --- app/test/test_dmadev.c | 132 +++++++++++++++++++++++++++++- app/test/test_dmadev_api.c | 163 ++++++++++++++++++++++++++++++++++--- app/test/test_dmadev_api.h | 2 + 3 files changed, 283 insertions(+), 14 deletions(-) diff --git a/app/test/test_dmadev.c b/app/test/test_dmadev.c index 780941fc1e..a2f3a7f999 100644 --- a/app/test/test_dmadev.c +++ b/app/test/test_dmadev.c @@ -19,7 +19,7 @@ #define ERR_RETURN(...) do { print_err(__func__, __LINE__, __VA_ARGS__); return -1; } while (0) #define TEST_RINGSIZE 512 -#define COPY_LEN 1024 +#define COPY_LEN 1032 static struct rte_mempool *pool; static int16_t test_dev_id; @@ -396,6 +396,120 @@ test_stop_start(int16_t dev_id, uint16_t vchan) return 0; } +static int +test_enqueue_sg_copies(int16_t dev_id, uint16_t vchan) +{ + unsigned int src_len, dst_len, n_sge, len, i, j, k; + char orig_src[COPY_LEN], orig_dst[COPY_LEN]; + struct rte_dma_info info = { 0 }; + enum rte_dma_status_code status; + uint16_t id, n_src, n_dst; + + if (rte_dma_info_get(dev_id, &info) < 0) + ERR_RETURN("Failed to get dev info"); + + n_sge = RTE_MIN(info.max_sges, TEST_SG_MAX); + len = COPY_LEN; + + for (n_src = 1; n_src <= n_sge; n_src++) { + src_len = len / n_src; + for (n_dst = 1; n_dst <= n_sge; n_dst++) { + dst_len = len / n_dst; + + struct rte_dma_sge sg_src[n_sge], sg_dst[n_sge]; + struct rte_mbuf *src[n_sge], *dst[n_sge]; + char *src_data[n_sge], *dst_data[n_sge]; + + for (i = 0 ; i < COPY_LEN; i++) + orig_src[i] = rte_rand() & 0xFF; + + memset(orig_dst, 0, COPY_LEN); + + for (i = 0; i < n_src; i++) { + src[i] = rte_pktmbuf_alloc(pool); + RTE_ASSERT(src[i] != NULL); + sg_src[i].addr = rte_pktmbuf_iova(src[i]); + sg_src[i].length = src_len; + src_data[i] = rte_pktmbuf_mtod(src[i], char *); + } + + for (k = 0; k < n_dst; k++) { + dst[k] = rte_pktmbuf_alloc(pool); + RTE_ASSERT(dst[k] != NULL); + sg_dst[k].addr = rte_pktmbuf_iova(dst[k]); + sg_dst[k].length = dst_len; + dst_data[k] = rte_pktmbuf_mtod(dst[k], char *); + } + + for (i = 0; i < n_src; i++) { + for (j = 0; j < src_len; j++) + src_data[i][j] = orig_src[i * src_len + j]; + } + + for (k = 0; k < n_dst; k++) + memset(dst_data[k], 0, dst_len); + + printf("\tsrc segs: %2d [seg len: %4d] - dst segs: %2d [seg len : %4d]\n", + n_src, src_len, n_dst, dst_len); + + id = rte_dma_copy_sg(dev_id, vchan, sg_src, sg_dst, n_src, n_dst, + RTE_DMA_OP_FLAG_SUBMIT); + + if (id != id_count) + ERR_RETURN("Error with rte_dma_copy_sg, got %u, expected %u\n", + id, id_count); + + /* Give time for copy to finish, then check it was done */ + await_hw(dev_id, vchan); + + for (k = 0; k < n_dst; k++) + memcpy((&orig_dst[0] + k * dst_len), dst_data[k], dst_len); + + if (memcmp(orig_src, orig_dst, COPY_LEN)) + ERR_RETURN("Data mismatch"); + + /* Verify completion */ + id = ~id; + if (rte_dma_completed(dev_id, vchan, 1, &id, NULL) != 1) + ERR_RETURN("Error with rte_dma_completed\n"); + + /* Verify expected index(id_count) */ + if (id != id_count) + ERR_RETURN("Error:incorrect job id received, %u [expected %u]\n", + id, id_count); + + /* Check for completed and id when no job done */ + id = ~id; + if (rte_dma_completed(dev_id, vchan, 1, &id, NULL) != 0) + ERR_RETURN("Error with rte_dma_completed when no job done\n"); + + if (id != id_count) + ERR_RETURN("Error:incorrect job id received when no job done, %u [expected %u]\n", + id, id_count); + + /* Check for completed_status and id when no job done */ + id = ~id; + if (rte_dma_completed_status(dev_id, vchan, 1, &id, &status) != 0) + ERR_RETURN("Error with rte_dma_completed_status when no job done\n"); + if (id != id_count) + ERR_RETURN("Error:incorrect job id received when no job done, %u [expected %u]\n", + id, 0); + + for (i = 0; i < n_src; i++) + rte_pktmbuf_free(src[i]); + for (i = 0; i < n_dst; i++) + rte_pktmbuf_free(dst[i]); + + /* Verify that completion returns nothing more */ + if (rte_dma_completed(dev_id, 0, 1, NULL, NULL) != 0) + ERR_RETURN("Error with rte_dma_completed in empty check\n"); + + id_count++; + } + } + return 0; +} + /* Failure handling test cases - global macros and variables for those tests*/ #define COMP_BURST_SZ 16 #define OPT_FENCE(idx) ((fence && idx == 8) ? RTE_DMA_OP_FLAG_FENCE : 0) @@ -1003,7 +1117,7 @@ test_dmadev_setup(void) TEST_RINGSIZE * 2, /* n == num elements */ 32, /* cache size */ 0, /* priv size */ - 2048, /* data room size */ + COPY_LEN + RTE_PKTMBUF_HEADROOM, /* data room size */ info.numa_node); if (pool == NULL) ERR_RETURN("Error with mempool creation\n"); @@ -1026,6 +1140,7 @@ test_dmadev_instance(int16_t dev_id) #define CHECK_ERRS true enum { TEST_COPY = 0, + TEST_COPY_SG, TEST_START, TEST_BURST, TEST_ERR, @@ -1060,6 +1175,13 @@ test_dmadev_instance(int16_t dev_id) param[TEST_COPY].vchan = vchan; param[TEST_COPY].check_err_stats = CHECK_ERRS; + param[TEST_COPY_SG].printable = "copy"; + param[TEST_COPY_SG].test_fn = test_enqueue_sg_copies; + param[TEST_COPY_SG].iterations = 1; + param[TEST_COPY_SG].dev_id = dev_id; + param[TEST_COPY_SG].vchan = vchan; + param[TEST_COPY_SG].check_err_stats = CHECK_ERRS; + param[TEST_START].printable = "stop-start"; param[TEST_START].test_fn = test_stop_start; param[TEST_START].iterations = 1; @@ -1122,6 +1244,12 @@ test_dmadev_instance(int16_t dev_id) /* run tests stopping/starting devices and check jobs still work after restart */ ts->unit_test_cases[TEST_START].enabled = 1; + /* run SG test cases */ + if ((dev_info.dev_capa & RTE_DMA_CAPA_OPS_COPY_SG) == 0) + printf("DMA Dev %u: No SG support, skipping SG copy tests\n", dev_id); + else + ts->unit_test_cases[TEST_COPY_SG].enabled = 1; + /* run some burst capacity tests */ ts->unit_test_cases[TEST_BURST].setup = test_dmadev_burst_setup; ts->unit_test_cases[TEST_BURST].enabled = 1; diff --git a/app/test/test_dmadev_api.c b/app/test/test_dmadev_api.c index aa07d2b359..37e43c9336 100644 --- a/app/test/test_dmadev_api.c +++ b/app/test/test_dmadev_api.c @@ -10,6 +10,7 @@ #include #include "test.h" +#include "test_dmadev_api.h" extern int test_dma_api(uint16_t dev_id); @@ -21,36 +22,62 @@ static int16_t invalid_dev_id; static char *src; static char *dst; +static char *src_sg[TEST_SG_MAX]; +static char *dst_sg[TEST_SG_MAX]; static int testsuite_setup(void) { invalid_dev_id = -1; - - src = rte_malloc("dmadev_test_src", TEST_MEMCPY_SIZE, 0); - if (src == NULL) - return -ENOMEM; - dst = rte_malloc("dmadev_test_dst", TEST_MEMCPY_SIZE, 0); - if (dst == NULL) { - rte_free(src); - src = NULL; - return -ENOMEM; + int i, rc = 0; + + for (i = 0; i < TEST_SG_MAX; i++) { + src_sg[i] = rte_malloc("dmadev_test_src", TEST_MEMCPY_SIZE, 0); + if (src_sg[i] == NULL) { + rc = -ENOMEM; + goto exit; + } + + dst_sg[i] = rte_malloc("dmadev_test_dst", TEST_MEMCPY_SIZE, 0); + if (dst_sg[i] == NULL) { + rte_free(src_sg[i]); + src_sg[i] = NULL; + rc = -ENOMEM; + goto exit; + } } + src = src_sg[0]; + dst = dst_sg[0]; + /* Set dmadev log level to critical to suppress unnecessary output * during API tests. */ rte_log_set_level_pattern("lib.dmadev", RTE_LOG_CRIT); - return 0; + return rc; +exit: + while (--i >= 0) { + rte_free(src_sg[i]); + rte_free(dst_sg[i]); + } + + return rc; } static void testsuite_teardown(void) { - rte_free(src); + int i; + + for (i = 0; i < TEST_SG_MAX; i++) { + rte_free(src_sg[i]); + src_sg[i] = NULL; + rte_free(dst_sg[i]); + dst_sg[i] = NULL; + } + src = NULL; - rte_free(dst); dst = NULL; /* Ensure the dmadev is stopped. */ rte_dma_stop(test_dev_id); @@ -437,6 +464,37 @@ verify_memory(void) return 0; } +static void +sg_memory_setup(int n) +{ + int i, j; + + for (i = 0; i < n; i++) { + for (j = 0; j < TEST_MEMCPY_SIZE; j++) + src_sg[i][j] = (char)j; + + memset(dst_sg[i], 0, TEST_MEMCPY_SIZE); + } +} + +static int +sg_memory_verify(int n) +{ + int i, j; + + for (i = 0; i < n; i++) { + for (j = 0; j < TEST_MEMCPY_SIZE; j++) { + if (src_sg[i][j] == dst_sg[i][j]) + continue; + + RTE_TEST_ASSERT_EQUAL(src_sg[i][j], dst_sg[i][j], "Failed to copy memory, %d %d", + src_sg[i][j], dst_sg[i][j]); + } + } + + return 0; +} + static int test_dma_completed(void) { @@ -551,6 +609,86 @@ test_dma_completed_status(void) return TEST_SUCCESS; } +static int +test_dma_sg(void) +{ + struct rte_dma_sge src_sge[TEST_SG_MAX], dst_sge[TEST_SG_MAX]; + struct rte_dma_info dev_info = { 0 }; + uint16_t last_idx = -1; + bool has_error = true; + int n_sge, i, ret; + uint16_t cpl_ret; + + ret = rte_dma_info_get(test_dev_id, &dev_info); + RTE_TEST_ASSERT_SUCCESS(ret, "Failed to obtain device info, %d", ret); + + if ((dev_info.dev_capa & RTE_DMA_CAPA_OPS_COPY_SG) == 0) + return TEST_SKIPPED; + + n_sge = RTE_MIN(dev_info.max_sges, TEST_SG_MAX); + + ret = setup_vchan(1); + RTE_TEST_ASSERT_SUCCESS(ret, "Failed to setup one vchan, %d", ret); + + ret = rte_dma_start(test_dev_id); + RTE_TEST_ASSERT_SUCCESS(ret, "Failed to start, %d", ret); + + for (i = 0; i < n_sge; i++) { + src_sge[i].addr = rte_malloc_virt2iova(src_sg[i]); + src_sge[i].length = TEST_MEMCPY_SIZE; + dst_sge[i].addr = rte_malloc_virt2iova(dst_sg[i]); + dst_sge[i].length = TEST_MEMCPY_SIZE; + } + + sg_memory_setup(n_sge); + + /* Check enqueue without submit */ + ret = rte_dma_copy_sg(test_dev_id, 0, src_sge, dst_sge, n_sge, n_sge, 0); + RTE_TEST_ASSERT_EQUAL(ret, 0, "Failed to enqueue copy, %d", ret); + + rte_delay_us_sleep(TEST_WAIT_US_VAL); + + cpl_ret = rte_dma_completed(test_dev_id, 0, 1, &last_idx, &has_error); + RTE_TEST_ASSERT_EQUAL(cpl_ret, 0, "Failed to get completed"); + + /* Check DMA submit */ + ret = rte_dma_submit(test_dev_id, 0); + RTE_TEST_ASSERT_SUCCESS(ret, "Failed to submit, %d", ret); + + rte_delay_us_sleep(TEST_WAIT_US_VAL); + + cpl_ret = rte_dma_completed(test_dev_id, 0, 1, &last_idx, &has_error); + RTE_TEST_ASSERT_EQUAL(cpl_ret, 1, "Failed to get completed"); + RTE_TEST_ASSERT_EQUAL(last_idx, 0, "Last idx should be zero, %u", last_idx); + RTE_TEST_ASSERT_EQUAL(has_error, false, "Should have no error"); + + ret = sg_memory_verify(n_sge); + RTE_TEST_ASSERT_SUCCESS(ret, "Failed to verify memory"); + + sg_memory_setup(n_sge); + + /* Check for enqueue with submit */ + ret = rte_dma_copy_sg(test_dev_id, 0, src_sge, dst_sge, n_sge, n_sge, + RTE_DMA_OP_FLAG_SUBMIT); + RTE_TEST_ASSERT_EQUAL(ret, 1, "Failed to enqueue copy, %d", ret); + + rte_delay_us_sleep(TEST_WAIT_US_VAL); + + cpl_ret = rte_dma_completed(test_dev_id, 0, 1, &last_idx, &has_error); + RTE_TEST_ASSERT_EQUAL(cpl_ret, 1, "Failed to get completed"); + RTE_TEST_ASSERT_EQUAL(last_idx, 1, "Last idx should be 1, %u", last_idx); + RTE_TEST_ASSERT_EQUAL(has_error, false, "Should have no error"); + + ret = sg_memory_verify(n_sge); + RTE_TEST_ASSERT_SUCCESS(ret, "Failed to verify memory"); + + /* Stop dmadev to make sure dmadev to a known state */ + ret = rte_dma_stop(test_dev_id); + RTE_TEST_ASSERT_SUCCESS(ret, "Failed to stop, %d", ret); + + return TEST_SUCCESS; +} + static struct unit_test_suite dma_api_testsuite = { .suite_name = "DMA API Test Suite", .setup = testsuite_setup, @@ -568,6 +706,7 @@ static struct unit_test_suite dma_api_testsuite = { TEST_CASE(test_dma_dump), TEST_CASE(test_dma_completed), TEST_CASE(test_dma_completed_status), + TEST_CASE(test_dma_sg), TEST_CASES_END() } }; diff --git a/app/test/test_dmadev_api.h b/app/test/test_dmadev_api.h index 33fbc5bd41..10ab925f80 100644 --- a/app/test/test_dmadev_api.h +++ b/app/test/test_dmadev_api.h @@ -2,4 +2,6 @@ * Copyright(c) 2021 HiSilicon Limited */ +#define TEST_SG_MAX 4 + int test_dma_api(uint16_t dev_id);