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

Message ID 1586859760-207446-1-git-send-email-pablo.de.lara.guarch@intel.com (mailing list archive)
State Superseded, archived
Headers
Series [1/2] test/crypto: add capability check |

Checks

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

Commit Message

De Lara Guarch, Pablo April 14, 2020, 10:22 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>
---
 app/test/test_cryptodev_blockcipher.c | 49 +++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)
  

Comments

Dybkowski, AdamX April 15, 2020, 9:16 a.m. UTC | #1
Hi Pablo,

> -----Original Message-----
> From: dev <dev-bounces@dpdk.org> On Behalf Of Pablo de Lara
> Sent: Tuesday, 14 April, 2020 12:23
> To: Doherty, Declan <declan.doherty@intel.com>; akhil.goyal@nxp.com;
> Zhang, Roy Fan <roy.fan.zhang@intel.com>; thomas@monjalon.net
> Cc: dev@dpdk.org; De Lara Guarch, Pablo <pablo.de.lara.guarch@intel.com>
> Subject: [dpdk-dev] [PATCH 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>
> ---
>  app/test/test_cryptodev_blockcipher.c | 49
> +++++++++++++++++++++++++++++++++++
>  1 file changed, 49 insertions(+)
> 
> diff --git a/app/test/test_cryptodev_blockcipher.c
> b/app/test/test_cryptodev_blockcipher.c
> index 2ff7fc9..b0e53ee 100644
> --- a/app/test/test_cryptodev_blockcipher.c
> +++ b/app/test/test_cryptodev_blockcipher.c
> @@ -21,6 +21,47 @@
>  #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;
> +	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;
> +
> +		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;
> +
> +		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,
> @@ -112,6 +153,14 @@ test_blockcipher_one_case(const struct
> blockcipher_test_case *t,
>  		nb_segs = 3;
>  	}
> 
> +        /* Check if PMD is capable of performing that test */
> +        if (verify_algo_support(t, dev_id, digest_len) < 0) {
> +		 RTE_LOG(DEBUG, USER1,
> +			"Device is not capable of performing this algorithm."
> +			"Test Skipped.\n");

[Adam] Maybe add a space after "algorithm." So it's not stuck with the rest of the string.
Or - probably even better - write the whole string in one line. It'll pass the git check (if it's the long text followed by the ')' and ';' characters only). Such long text is easier to find when debugging.

Adam
  
Dybkowski, AdamX April 15, 2020, 9:23 a.m. UTC | #2
One more thing:

> -----Original Message-----
> From: dev <dev-bounces@dpdk.org> On Behalf Of Pablo de Lara
> Sent: Tuesday, 14 April, 2020 12:23
> To: Doherty, Declan <declan.doherty@intel.com>; akhil.goyal@nxp.com;
> Zhang, Roy Fan <roy.fan.zhang@intel.com>; thomas@monjalon.net
> Cc: dev@dpdk.org; De Lara Guarch, Pablo <pablo.de.lara.guarch@intel.com>
> Subject: [dpdk-dev] [PATCH 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>
> ---
>  app/test/test_cryptodev_blockcipher.c | 49
> +++++++++++++++++++++++++++++++++++
>  1 file changed, 49 insertions(+)
> 
> diff --git a/app/test/test_cryptodev_blockcipher.c
> b/app/test/test_cryptodev_blockcipher.c
> index 2ff7fc9..b0e53ee 100644
> --- a/app/test/test_cryptodev_blockcipher.c
> +++ b/app/test/test_cryptodev_blockcipher.c
> @@ -21,6 +21,47 @@
>  #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;
> +	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;
> +
> +		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;
> +
> +		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,
> @@ -112,6 +153,14 @@ test_blockcipher_one_case(const struct
> blockcipher_test_case *t,
>  		nb_segs = 3;
>  	}
> 
> +        /* Check if PMD is capable of performing that test */
> +        if (verify_algo_support(t, dev_id, digest_len) < 0) {
> +		 RTE_LOG(DEBUG, USER1,
> +			"Device is not capable of performing this algorithm."
> +			"Test Skipped.\n");

Pablo, please explain why did you use RTE_LOG here? All strings in this source code file are shown using printf. This is the only place with RTE_LOG call now.

Adam
  
Dybkowski, AdamX April 15, 2020, 10:29 a.m. UTC | #3
> -----Original Message-----
> From: dev <dev-bounces@dpdk.org> On Behalf Of Pablo de Lara
> Sent: Tuesday, 14 April, 2020 12:23
> To: Doherty, Declan <declan.doherty@intel.com>; akhil.goyal@nxp.com;
> Zhang, Roy Fan <roy.fan.zhang@intel.com>; thomas@monjalon.net
> Cc: dev@dpdk.org; De Lara Guarch, Pablo <pablo.de.lara.guarch@intel.com>
> Subject: [dpdk-dev] [PATCH 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>
  

Patch

diff --git a/app/test/test_cryptodev_blockcipher.c b/app/test/test_cryptodev_blockcipher.c
index 2ff7fc9..b0e53ee 100644
--- a/app/test/test_cryptodev_blockcipher.c
+++ b/app/test/test_cryptodev_blockcipher.c
@@ -21,6 +21,47 @@ 
 #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;
+	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;
+
+		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;
+
+		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,
@@ -112,6 +153,14 @@  test_blockcipher_one_case(const struct blockcipher_test_case *t,
 		nb_segs = 3;
 	}
 
+        /* Check if PMD is capable of performing that test */
+        if (verify_algo_support(t, dev_id, digest_len) < 0) {
+		 RTE_LOG(DEBUG, USER1,
+			"Device is not capable of performing this algorithm."
+			"Test Skipped.\n");
+		return 0;
+	}
+
 	if (tdata->cipher_key.len)
 		memcpy(cipher_key, tdata->cipher_key.data,
 			tdata->cipher_key.len);