From: Anoob Joseph <anoobj@marvell.com>
To: Akhil Goyal <gakhil@marvell.com>,
Declan Doherty <declan.doherty@intel.com>,
Fan Zhang <roy.fan.zhang@intel.com>
Cc: Anoob Joseph <anoobj@marvell.com>,
Jerin Jacob <jerinj@marvell.com>,
Archana Muniganti <marchana@marvell.com>,
Tejasree Kondoj <ktejasree@marvell.com>,
Hemant Agrawal <hemant.agrawal@nxp.com>,
"Radu Nicolau" <radu.nicolau@intel.com>,
Ciara Power <ciara.power@intel.com>,
Gagandeep Singh <g.singh@nxp.com>, <dev@dpdk.org>,
<slawomirx.mrozowicz@intel.com>
Subject: [dpdk-dev] [PATCH] test/crypto: fix missing return checks
Date: Mon, 8 Nov 2021 20:43:46 +0530 [thread overview]
Message-ID: <1636384426-95-1-git-send-email-anoobj@marvell.com> (raw)
The API could return errors. Add error checking for the same.
Fixes: b3bbd9e5f265 ("cryptodev: support device independent sessions")
Cc: slawomirx.mrozowicz@intel.com
Signed-off-by: Anoob Joseph <anoobj@marvell.com>
---
app/test/test_cryptodev.c | 116 ++++++++++++++++++++++++++++++++--------------
1 file changed, 80 insertions(+), 36 deletions(-)
diff --git a/app/test/test_cryptodev.c b/app/test/test_cryptodev.c
index cd5c3dc..e54a1a9 100644
--- a/app/test/test_cryptodev.c
+++ b/app/test/test_cryptodev.c
@@ -2138,6 +2138,7 @@ test_AES_CBC_HMAC_SHA1_encrypt_digest(void)
{
struct crypto_testsuite_params *ts_params = &testsuite_params;
struct crypto_unittest_params *ut_params = &unittest_params;
+ int status;
/* Verify the capabilities */
struct rte_cryptodev_sym_capability_idx cap_idx;
@@ -2184,12 +2185,17 @@ test_AES_CBC_HMAC_SHA1_encrypt_digest(void)
ut_params->sess = rte_cryptodev_sym_session_create(
ts_params->session_mpool);
+ TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
/* Create crypto session*/
- rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
+ status = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
ut_params->sess, &ut_params->cipher_xform,
ts_params->session_priv_mpool);
- TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
+
+ if (status == -ENOTSUP)
+ return TEST_SKIPPED;
+
+ TEST_ASSERT_EQUAL(status, 0, "Session init failed");
/* Generate crypto op data structure */
ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
@@ -7965,6 +7971,7 @@ create_aead_session(uint8_t dev_id, enum rte_crypto_aead_algorithm algo,
uint8_t iv_len)
{
uint8_t aead_key[key_len];
+ int status;
struct crypto_testsuite_params *ts_params = &testsuite_params;
struct crypto_unittest_params *ut_params = &unittest_params;
@@ -7988,14 +7995,13 @@ create_aead_session(uint8_t dev_id, enum rte_crypto_aead_algorithm algo,
/* Create Crypto session*/
ut_params->sess = rte_cryptodev_sym_session_create(
ts_params->session_mpool);
+ TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
- rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
+ status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
&ut_params->aead_xform,
ts_params->session_priv_mpool);
- TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
-
- return 0;
+ return status;
}
static int
@@ -11113,6 +11119,7 @@ static int MD5_HMAC_create_session(struct crypto_testsuite_params *ts_params,
const struct HMAC_MD5_vector *test_case)
{
uint8_t key[64];
+ int status;
memcpy(key, test_case->key.data, test_case->key.len);
@@ -11128,13 +11135,15 @@ static int MD5_HMAC_create_session(struct crypto_testsuite_params *ts_params,
ut_params->sess = rte_cryptodev_sym_session_create(
ts_params->session_mpool);
+ TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
+ if (ut_params->sess == NULL)
+ return TEST_FAILED;
- rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
+ status = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
ut_params->sess, &ut_params->auth_xform,
ts_params->session_priv_mpool);
-
- if (ut_params->sess == NULL)
- return TEST_FAILED;
+ if (status == -ENOTSUP)
+ return TEST_SKIPPED;
ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
@@ -11347,6 +11356,7 @@ test_multi_session(void)
struct rte_cryptodev_sym_session **sessions;
uint16_t i;
+ int status;
/* Verify the capabilities */
struct rte_cryptodev_sym_capability_idx cap_idx;
@@ -11376,14 +11386,17 @@ test_multi_session(void)
sessions[i] = rte_cryptodev_sym_session_create(
ts_params->session_mpool);
-
- rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
- sessions[i], &ut_params->auth_xform,
- ts_params->session_priv_mpool);
TEST_ASSERT_NOT_NULL(sessions[i],
"Session creation failed at session number %u",
i);
+ status = rte_cryptodev_sym_session_init(
+ ts_params->valid_devs[0],
+ sessions[i], &ut_params->auth_xform,
+ ts_params->session_priv_mpool);
+ if (status == -ENOTSUP)
+ return TEST_SKIPPED;
+
/* Attempt to send a request on each session */
TEST_ASSERT_SUCCESS( test_AES_CBC_HMAC_SHA512_decrypt_perform(
sessions[i],
@@ -11476,6 +11489,7 @@ test_multi_session_random_usage(void)
},
};
+ int status;
/* Verify the capabilities */
struct rte_cryptodev_sym_capability_idx cap_idx;
@@ -11499,6 +11513,9 @@ test_multi_session_random_usage(void)
for (i = 0; i < MB_SESSION_NUMBER; i++) {
sessions[i] = rte_cryptodev_sym_session_create(
ts_params->session_mpool);
+ TEST_ASSERT_NOT_NULL(sessions[i],
+ "Session creation failed at session number %u",
+ i);
rte_memcpy(&ut_paramz[i].ut_params, &unittest_params,
sizeof(struct crypto_unittest_params));
@@ -11508,16 +11525,16 @@ test_multi_session_random_usage(void)
ut_paramz[i].cipher_key, ut_paramz[i].hmac_key);
/* Create multiple crypto sessions*/
- rte_cryptodev_sym_session_init(
+ status = rte_cryptodev_sym_session_init(
ts_params->valid_devs[0],
sessions[i],
&ut_paramz[i].ut_params.auth_xform,
ts_params->session_priv_mpool);
- TEST_ASSERT_NOT_NULL(sessions[i],
- "Session creation failed at session number %u",
- i);
+ if (status == -ENOTSUP)
+ return TEST_SKIPPED;
+ TEST_ASSERT_EQUAL(status, 0, "Session init failed");
}
srand(time(NULL));
@@ -11629,6 +11646,7 @@ test_null_burst_operation(void)
{
struct crypto_testsuite_params *ts_params = &testsuite_params;
struct crypto_unittest_params *ut_params = &unittest_params;
+ int status;
unsigned i, burst_len = NULL_BURST_LENGTH;
@@ -11656,12 +11674,17 @@ test_null_burst_operation(void)
ut_params->sess = rte_cryptodev_sym_session_create(
ts_params->session_mpool);
+ TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
/* Create Crypto session*/
- rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
+ status = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
ut_params->sess, &ut_params->cipher_xform,
ts_params->session_priv_mpool);
- TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
+
+ if (status == -ENOTSUP)
+ return TEST_SKIPPED;
+
+ TEST_ASSERT_EQUAL(status, 0, "Session init failed");
TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool,
RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len),
@@ -12059,6 +12082,7 @@ static int create_gmac_session(uint8_t dev_id,
enum rte_crypto_auth_operation auth_op)
{
uint8_t auth_key[tdata->key.len];
+ int status;
struct crypto_testsuite_params *ts_params = &testsuite_params;
struct crypto_unittest_params *ut_params = &unittest_params;
@@ -12079,14 +12103,13 @@ static int create_gmac_session(uint8_t dev_id,
ut_params->sess = rte_cryptodev_sym_session_create(
ts_params->session_mpool);
+ TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
- rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
+ status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
&ut_params->auth_xform,
ts_params->session_priv_mpool);
- TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
-
- return 0;
+ return status;
}
static int
@@ -12124,6 +12147,8 @@ test_AES_GMAC_authentication(const struct gmac_test_data *tdata)
retval = create_gmac_session(ts_params->valid_devs[0],
tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
+ if (retval == -ENOTSUP)
+ return TEST_SKIPPED;
if (retval < 0)
return retval;
@@ -12253,6 +12278,8 @@ test_AES_GMAC_authentication_verify(const struct gmac_test_data *tdata)
retval = create_gmac_session(ts_params->valid_devs[0],
tdata, RTE_CRYPTO_AUTH_OP_VERIFY);
+ if (retval == -ENOTSUP)
+ return TEST_SKIPPED;
if (retval < 0)
return retval;
@@ -12380,6 +12407,8 @@ test_AES_GMAC_authentication_SGL(const struct gmac_test_data *tdata,
retval = create_gmac_session(ts_params->valid_devs[0],
tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
+ if (retval == -ENOTSUP)
+ return TEST_SKIPPED;
if (retval < 0)
return retval;
@@ -12709,6 +12738,7 @@ create_auth_session(struct crypto_unittest_params *ut_params,
{
struct crypto_testsuite_params *ts_params = &testsuite_params;
uint8_t auth_key[reference->auth_key.len + 1];
+ int status;
memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
@@ -12724,14 +12754,13 @@ create_auth_session(struct crypto_unittest_params *ut_params,
/* Create Crypto session*/
ut_params->sess = rte_cryptodev_sym_session_create(
ts_params->session_mpool);
+ TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
- rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
+ status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
&ut_params->auth_xform,
ts_params->session_priv_mpool);
- TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
-
- return 0;
+ return status;
}
static int
@@ -12744,6 +12773,7 @@ create_auth_cipher_session(struct crypto_unittest_params *ut_params,
struct crypto_testsuite_params *ts_params = &testsuite_params;
uint8_t cipher_key[reference->cipher_key.len + 1];
uint8_t auth_key[reference->auth_key.len + 1];
+ int status;
memcpy(cipher_key, reference->cipher_key.data,
reference->cipher_key.len);
@@ -12777,14 +12807,13 @@ create_auth_cipher_session(struct crypto_unittest_params *ut_params,
/* Create Crypto session*/
ut_params->sess = rte_cryptodev_sym_session_create(
ts_params->session_mpool);
+ TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
- rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
+ status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
&ut_params->auth_xform,
ts_params->session_priv_mpool);
- TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
-
- return 0;
+ return status;
}
static int
@@ -13000,6 +13029,9 @@ test_authentication_verify_fail_when_data_corruption(
ts_params->valid_devs[0],
reference,
RTE_CRYPTO_AUTH_OP_VERIFY);
+
+ if (retval == -ENOTSUP)
+ return TEST_SKIPPED;
if (retval < 0)
return retval;
@@ -13175,6 +13207,9 @@ test_authenticated_decryption_fail_when_corruption(
reference,
RTE_CRYPTO_AUTH_OP_VERIFY,
RTE_CRYPTO_CIPHER_OP_DECRYPT);
+
+ if (retval == -ENOTSUP)
+ return TEST_SKIPPED;
if (retval < 0)
return retval;
@@ -13236,6 +13271,7 @@ test_authenticated_encrypt_with_esn(
uint8_t cipher_key[reference->cipher_key.len + 1];
uint8_t auth_key[reference->auth_key.len + 1];
struct rte_cryptodev_info dev_info;
+ int status;
rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
uint64_t feat_flags = dev_info.feature_flags;
@@ -13287,13 +13323,17 @@ test_authenticated_encrypt_with_esn(
/* Create Crypto session*/
ut_params->sess = rte_cryptodev_sym_session_create(
ts_params->session_mpool);
+ TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
- rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
+ status = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
ut_params->sess,
&ut_params->cipher_xform,
ts_params->session_priv_mpool);
- TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
+ if (status == -ENOTSUP)
+ return TEST_SKIPPED;
+
+ TEST_ASSERT_EQUAL(status, 0, "Session init failed");
ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
TEST_ASSERT_NOT_NULL(ut_params->ibuf,
@@ -13419,13 +13459,17 @@ test_authenticated_decrypt_with_esn(
/* Create Crypto session*/
ut_params->sess = rte_cryptodev_sym_session_create(
ts_params->session_mpool);
+ TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
- rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
+ retval = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
ut_params->sess,
&ut_params->auth_xform,
ts_params->session_priv_mpool);
- TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
+ if (retval == -ENOTSUP)
+ return TEST_SKIPPED;
+
+ TEST_ASSERT_EQUAL(retval, 0, "Session init failed");
ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
TEST_ASSERT_NOT_NULL(ut_params->ibuf,
--
2.7.4
next reply other threads:[~2021-11-08 15:14 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-08 15:13 Anoob Joseph [this message]
2021-11-11 11:26 ` Akhil Goyal
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1636384426-95-1-git-send-email-anoobj@marvell.com \
--to=anoobj@marvell.com \
--cc=ciara.power@intel.com \
--cc=declan.doherty@intel.com \
--cc=dev@dpdk.org \
--cc=g.singh@nxp.com \
--cc=gakhil@marvell.com \
--cc=hemant.agrawal@nxp.com \
--cc=jerinj@marvell.com \
--cc=ktejasree@marvell.com \
--cc=marchana@marvell.com \
--cc=radu.nicolau@intel.com \
--cc=roy.fan.zhang@intel.com \
--cc=slawomirx.mrozowicz@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).