[v4,1/2] test/crypto: add capability check

Message ID 20200416090819.1921843-2-pablo.de.lara.guarch@intel.com (mailing list archive)
State Superseded, archived
Delegated to: akhil goyal
Headers
Series Crypto test refactoring (first phase) |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

De Lara Guarch, Pablo April 16, 2020, 9:08 a.m. UTC
  Check if test case is supported by the crypto device,
including algorithm and some of its parameter, such as key length,
IV length, etc, using the capabilities API.
If it is not supported, test case is skipped.

Signed-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
Acked-by: Adam Dybkowski <adamx.dybkowski@intel.com>

---
 app/test/test_cryptodev_blockcipher.c | 58 ++++++++++++++++++++++++++++++++++-
 1 file changed, 57 insertions(+), 1 deletion(-)
  

Comments

Ruifeng Wang April 16, 2020, 3:35 p.m. UTC | #1
> -----Original Message-----
> From: dev <dev-bounces@dpdk.org> On Behalf Of Pablo de Lara
> Sent: Thursday, April 16, 2020 5:08 PM
> To: declan.doherty@intel.com
> Cc: dev@dpdk.org; Akhil.goyal@nxp.com; Pablo de Lara
> <pablo.de.lara.guarch@intel.com>; Adam Dybkowski
> <adamx.dybkowski@intel.com>
> Subject: [dpdk-dev] [PATCH v4 1/2] test/crypto: add capability check
> 
> Check if test case is supported by the crypto device, including algorithm and
> some of its parameter, such as key length, IV length, etc, using the
> capabilities API.
> If it is not supported, test case is skipped.
> 
> Signed-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
> Acked-by: Adam Dybkowski <adamx.dybkowski@intel.com>
> 
> ---
Tested-by: Ruifeng Wang <ruifeng.wang@arm.com>
  
Fiona Trahe April 16, 2020, 4:26 p.m. UTC | #2
Hi Pablo,

> -----Original Message-----
> From: dev <dev-bounces@dpdk.org> On Behalf Of Pablo de Lara
> Sent: Thursday, April 16, 2020 10:08 AM
> To: Doherty, Declan <declan.doherty@intel.com>
> Cc: dev@dpdk.org; akhil.goyal@nxp.com; De Lara Guarch, Pablo <pablo.de.lara.guarch@intel.com>;
> Dybkowski, AdamX <adamx.dybkowski@intel.com>
> Subject: [dpdk-dev] [PATCH v4 1/2] test/crypto: add capability check

///snip///
> +static int
>  test_blockcipher_one_case(const struct blockcipher_test_case *t,
>  	struct rte_mempool *mbuf_pool,
>  	struct rte_mempool *op_mpool,
> @@ -93,11 +136,13 @@ test_blockcipher_one_case(const struct blockcipher_test_case *t,
>  		uint64_t feat_flags = dev_info.feature_flags;
>  		uint64_t oop_flag = RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT;
> 
> -		if (t->feature_mask && BLOCKCIPHER_TEST_FEATURE_OOP) {
> +		if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_OOP) {
[Fiona] Isn't this a fix which should be a separate patch and should be backported to stable releases?
  
De Lara Guarch, Pablo April 16, 2020, 4:44 p.m. UTC | #3
Hi Fiona,

> -----Original Message-----
> From: Trahe, Fiona <fiona.trahe@intel.com>
> Sent: Thursday, April 16, 2020 5:26 PM
> To: De Lara Guarch, Pablo <pablo.de.lara.guarch@intel.com>; Doherty, Declan
> <declan.doherty@intel.com>
> Cc: dev@dpdk.org; akhil.goyal@nxp.com; De Lara Guarch, Pablo
> <pablo.de.lara.guarch@intel.com>; Dybkowski, AdamX
> <adamx.dybkowski@intel.com>; Trahe, Fiona <fiona.trahe@intel.com>
> Subject: RE: [dpdk-dev] [PATCH v4 1/2] test/crypto: add capability check
> 
> Hi Pablo,
> 
> > -----Original Message-----
> > From: dev <dev-bounces@dpdk.org> On Behalf Of Pablo de Lara
> > Sent: Thursday, April 16, 2020 10:08 AM
> > To: Doherty, Declan <declan.doherty@intel.com>
> > Cc: dev@dpdk.org; akhil.goyal@nxp.com; De Lara Guarch, Pablo
> > <pablo.de.lara.guarch@intel.com>; Dybkowski, AdamX
> > <adamx.dybkowski@intel.com>
> > Subject: [dpdk-dev] [PATCH v4 1/2] test/crypto: add capability check
> 
> ///snip///
> > +static int
> >  test_blockcipher_one_case(const struct blockcipher_test_case *t,
> >  	struct rte_mempool *mbuf_pool,
> >  	struct rte_mempool *op_mpool,
> > @@ -93,11 +136,13 @@ test_blockcipher_one_case(const struct
> blockcipher_test_case *t,
> >  		uint64_t feat_flags = dev_info.feature_flags;
> >  		uint64_t oop_flag =
> RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT;
> >
> > -		if (t->feature_mask && BLOCKCIPHER_TEST_FEATURE_OOP) {
> > +		if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_OOP) {
> [Fiona] Isn't this a fix which should be a separate patch and should be
> backported to stable releases?

Yes, you are right. I will send a separate patch for this then.

Thanks!
Pablo
  

Patch

diff --git a/app/test/test_cryptodev_blockcipher.c b/app/test/test_cryptodev_blockcipher.c
index 2ff7fc9..8453470 100644
--- a/app/test/test_cryptodev_blockcipher.c
+++ b/app/test/test_cryptodev_blockcipher.c
@@ -21,6 +21,49 @@ 
 #include "test_cryptodev_hash_test_vectors.h"
 
 static int
+verify_algo_support(const struct blockcipher_test_case *t,
+		const uint8_t dev_id, const uint32_t digest_len)
+{
+	int ret = 0;
+	const struct blockcipher_test_data *tdata = t->test_data;
+	struct rte_cryptodev_sym_capability_idx cap_idx;
+	const struct rte_cryptodev_symmetric_capability *capability;
+
+	if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER) {
+		cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
+		cap_idx.algo.cipher = tdata->crypto_algo;
+		capability = rte_cryptodev_sym_capability_get(dev_id, &cap_idx);
+		if (capability == NULL)
+			return -1;
+
+		if (cap_idx.algo.cipher != RTE_CRYPTO_CIPHER_NULL)
+			ret = rte_cryptodev_sym_capability_check_cipher(capability,
+							tdata->cipher_key.len,
+							tdata->iv.len);
+		if (ret != 0)
+			return -1;
+	}
+
+	if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH) {
+		cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
+		cap_idx.algo.auth = tdata->auth_algo;
+		capability = rte_cryptodev_sym_capability_get(dev_id, &cap_idx);
+		if (capability == NULL)
+			return -1;
+
+		if (cap_idx.algo.auth != RTE_CRYPTO_AUTH_NULL)
+			ret = rte_cryptodev_sym_capability_check_auth(capability,
+							tdata->auth_key.len,
+							digest_len,
+							0);
+		if (ret != 0)
+			return -1;
+	}
+
+	return 0;
+}
+
+static int
 test_blockcipher_one_case(const struct blockcipher_test_case *t,
 	struct rte_mempool *mbuf_pool,
 	struct rte_mempool *op_mpool,
@@ -93,11 +136,13 @@  test_blockcipher_one_case(const struct blockcipher_test_case *t,
 		uint64_t feat_flags = dev_info.feature_flags;
 		uint64_t oop_flag = RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT;
 
-		if (t->feature_mask && BLOCKCIPHER_TEST_FEATURE_OOP) {
+		if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_OOP) {
 			if (!(feat_flags & oop_flag)) {
 				printf("Device doesn't support out-of-place "
 					"scatter-gather in input mbuf. "
 					"Test Skipped.\n");
+				snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
+					"SKIPPED");
 				return 0;
 			}
 		} else {
@@ -105,6 +150,8 @@  test_blockcipher_one_case(const struct blockcipher_test_case *t,
 				printf("Device doesn't support in-place "
 					"scatter-gather mbufs. "
 					"Test Skipped.\n");
+				snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN,
+					"SKIPPED");
 				return 0;
 			}
 		}
@@ -144,6 +191,15 @@  test_blockcipher_one_case(const struct blockcipher_test_case *t,
 		goto error_exit;
 	}
 
+	/* Check if PMD is capable of performing that test */
+	if (verify_algo_support(t, dev_id, digest_len) < 0) {
+		RTE_LOG(DEBUG, USER1,
+			"Device does not support this algorithm."
+			"Test Skipped.\n");
+		snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "SKIPPED");
+		return 0;
+	}
+
 	/* preparing data */
 	if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH)
 		buf_len += digest_len;