From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id E4BFA42AE1; Wed, 17 May 2023 12:55:37 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 79EE24114A; Wed, 17 May 2023 12:55:37 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id EEC924067B for ; Wed, 17 May 2023 12:55:35 +0200 (CEST) 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 34H1VQEJ027003; Wed, 17 May 2023 03:55:34 -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=Me57AnTVGm8AyKtRK2DqFWzIVcYZFVBgWDtAwhTv6nQ=; b=Xm95Q7o+V4gkRDbZGZwzxd9iWhtga3om2o7m1CNMVLIs3IfmNXlLtdgj+YrH56jY+IO9 X76aF2hDwaN7ZgUgJ9mFarEONvEEBRWYVtjy0Uv4fxmHV4iUZZa2a63rtMB6vZDg9VVE J7iaumMCymTvzjmtMAie0DdQ7D/IorarfocWjJ5tG473wLnDwQ4B1SHT3cuMLm1IQ3hS eJGZsXXryk+4A0B6Dp1Srr+ZD9M0agMbb+PhnH96eCN1ImZGm/8/2t97kilAZM7NOprh +hMQnEfRRhUchDvwm7dkiQa+1zyB6vww6KIwKtponxb1Woe2dwLawUZ29RaS74NpE4ZE kA== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3qmnba1ucm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Wed, 17 May 2023 03:55:34 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Wed, 17 May 2023 03:55:32 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.48 via Frontend Transport; Wed, 17 May 2023 03:55:32 -0700 Received: from BG-LT92004.corp.innovium.com (unknown [10.28.161.183]) by maili.marvell.com (Postfix) with ESMTP id B0C913F7043; Wed, 17 May 2023 03:55:29 -0700 (PDT) From: Anoob Joseph To: Akhil Goyal , Fan Zhang , Ciara Power CC: Hemant Agrawal , Jerin Jacob , Tejasree Kondoj , Subject: [PATCH v2] test/crypto: free memory in error and skip paths Date: Wed, 17 May 2023 16:25:29 +0530 Message-ID: <20230517105529.405-1-anoobj@marvell.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230512140946.195-1-anoobj@marvell.com> References: <20230512140946.195-1-anoobj@marvell.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-GUID: HLXi9l95CRzrgyed7FS5orw8GbngpMCF X-Proofpoint-ORIG-GUID: HLXi9l95CRzrgyed7FS5orw8GbngpMCF X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-05-17_02,2023-05-17_02,2023-02-09_01 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 In multi session tests, multiple sessions get created. So the handling in ut_teardown won't guard against any memory that is not freed by the test case. Test case should free sessions as well as local memory that was used to save session pointers both in case of unsupported cases as well as operation failures. Signed-off-by: Anoob Joseph --- v2: * Moved 'ASSERT' to the end to allow cleanup in all cases. --- app/test/test_cryptodev.c | 59 ++++++++++++++++++++++++++++----------- 1 file changed, 43 insertions(+), 16 deletions(-) diff --git a/app/test/test_cryptodev.c b/app/test/test_cryptodev.c index aaa2ce428d..77187e1fd3 100644 --- a/app/test/test_cryptodev.c +++ b/app/test/test_cryptodev.c @@ -12753,8 +12753,8 @@ test_multi_session(void) struct crypto_testsuite_params *ts_params = &testsuite_params; struct crypto_unittest_params *ut_params = &unittest_params; struct rte_cryptodev_info dev_info; + int i, nb_sess, ret = TEST_SUCCESS; void **sessions; - uint16_t i; /* Verify the capabilities */ struct rte_cryptodev_sym_capability_idx cap_idx; @@ -12784,21 +12784,25 @@ test_multi_session(void) sessions[i] = rte_cryptodev_sym_session_create( ts_params->valid_devs[0], &ut_params->auth_xform, ts_params->session_mpool); - if (sessions[i] == NULL && rte_errno == ENOTSUP) - return TEST_SKIPPED; + if (sessions[i] == NULL && rte_errno == ENOTSUP) { + nb_sess = i; + ret = TEST_SKIPPED; + break; + } TEST_ASSERT_NOT_NULL(sessions[i], "Session creation failed at session number %u", i); + /* Attempt to send a request on each session */ - TEST_ASSERT_SUCCESS( test_AES_CBC_HMAC_SHA512_decrypt_perform( + ret = test_AES_CBC_HMAC_SHA512_decrypt_perform( sessions[i], ut_params, ts_params, catch_22_quote_2_512_bytes_AES_CBC_ciphertext, catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest, - aes_cbc_iv), - "Failed to perform decrypt on request number %u.", i); + aes_cbc_iv); + /* free crypto operation structure */ rte_crypto_op_free(ut_params->op); @@ -12817,16 +12821,26 @@ test_multi_session(void) rte_pktmbuf_free(ut_params->ibuf); ut_params->ibuf = 0; } + + if (ret != TEST_SUCCESS) { + i++; + break; + } } - for (i = 0; i < MAX_NB_SESSIONS; i++) { + nb_sess = i; + + for (i = 0; i < nb_sess; i++) { rte_cryptodev_sym_session_free(ts_params->valid_devs[0], sessions[i]); } rte_free(sessions); - return TEST_SUCCESS; + if (ret != TEST_SKIPPED) + TEST_ASSERT_SUCCESS(ret, "Failed to perform decrypt on request number %u.", i - 1); + + return ret; } struct multi_session_params { @@ -12845,8 +12859,9 @@ test_multi_session_random_usage(void) { struct crypto_testsuite_params *ts_params = &testsuite_params; struct rte_cryptodev_info dev_info; + int index = 0, ret = TEST_SUCCESS; + uint32_t nb_sess, i, j; void **sessions; - uint32_t i, j; struct multi_session_params ut_paramz[] = { { @@ -12905,27 +12920,30 @@ test_multi_session_random_usage(void) ts_params->valid_devs[0], &ut_paramz[i].ut_params.auth_xform, ts_params->session_mpool); - if (sessions[i] == NULL && rte_errno == ENOTSUP) - return TEST_SKIPPED; + if (sessions[i] == NULL && rte_errno == ENOTSUP) { + nb_sess = i; + ret = TEST_SKIPPED; + goto session_clear; + } TEST_ASSERT_NOT_NULL(sessions[i], "Session creation failed at session number %u", i); } + nb_sess = i; + srand(time(NULL)); for (i = 0; i < 40000; i++) { j = rand() % MB_SESSION_NUMBER; - TEST_ASSERT_SUCCESS( - test_AES_CBC_HMAC_SHA512_decrypt_perform( + ret = test_AES_CBC_HMAC_SHA512_decrypt_perform( sessions[j], &ut_paramz[j].ut_params, ts_params, ut_paramz[j].cipher, ut_paramz[j].digest, - ut_paramz[j].iv), - "Failed to perform decrypt on request number %u.", i); + ut_paramz[j].iv); rte_crypto_op_free(ut_paramz[j].ut_params.op); @@ -12945,15 +12963,24 @@ test_multi_session_random_usage(void) rte_pktmbuf_free(ut_paramz[j].ut_params.ibuf); ut_paramz[j].ut_params.ibuf = 0; } + + if (ret != TEST_SKIPPED) { + index = i; + break; + } } - for (i = 0; i < MB_SESSION_NUMBER; i++) { +session_clear: + for (i = 0; i < nb_sess; i++) { rte_cryptodev_sym_session_free(ts_params->valid_devs[0], sessions[i]); } rte_free(sessions); + if (ret != TEST_SKIPPED) + TEST_ASSERT_SUCCESS(ret, "Failed to perform decrypt on request number %u.", index); + return TEST_SUCCESS; } -- 2.25.1