[v3,04/14] test: cryptodev use rte_pktmbuf_mtod_offset

Message ID 20230706175938.62721-5-stephen@networkplumber.org (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series Use rte_pktmbuf_mtod_offset() where possible |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Stephen Hemminger July 6, 2023, 5:59 p.m. UTC
  Based off patch generated by cocci/mtod-offset.cocci.
With some cleanup to shorten lines by using conditional
with omitted operand.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 app/test/test_cryptodev.c | 66 +++++++++++++++++++++------------------
 1 file changed, 36 insertions(+), 30 deletions(-)
  

Comments

Ferruh Yigit July 7, 2023, 12:46 p.m. UTC | #1
On 7/6/2023 6:59 PM, Stephen Hemminger wrote:
> Based off patch generated by cocci/mtod-offset.cocci.
> With some cleanup to shorten lines by using conditional
> with omitted operand.
> 
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>

<...>

> @@ -5163,9 +5169,9 @@ test_snow3g_auth_cipher(const struct snow3g_test_data *tdata,
>  		debug_hexdump(stdout, "ciphertext expected:",
>  			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
>  
> -		ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
> -			+ (tdata->digest.offset_bytes == 0 ?
> -		plaintext_pad_len : tdata->digest.offset_bytes);
> +		ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf,
> +					uint8_t *,
> +					tdata->digest.offset_bytes ? : plaintext_pad_len);
>  

As far as I know "x ?: y" support is gcc extention, what about sticking
to standard syntax?
  
Stephen Hemminger July 7, 2023, 8:32 p.m. UTC | #2
On Fri, 7 Jul 2023 13:46:07 +0100
Ferruh Yigit <ferruh.yigit@amd.com> wrote:

> On 7/6/2023 6:59 PM, Stephen Hemminger wrote:
> > Based off patch generated by cocci/mtod-offset.cocci.
> > With some cleanup to shorten lines by using conditional
> > with omitted operand.
> > 
> > Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>  
> 
> <...>
> 
> > @@ -5163,9 +5169,9 @@ test_snow3g_auth_cipher(const struct snow3g_test_data *tdata,
> >  		debug_hexdump(stdout, "ciphertext expected:",
> >  			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
> >  
> > -		ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
> > -			+ (tdata->digest.offset_bytes == 0 ?
> > -		plaintext_pad_len : tdata->digest.offset_bytes);
> > +		ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf,
> > +					uint8_t *,
> > +					tdata->digest.offset_bytes ? : plaintext_pad_len);
> >    
> 
> As far as I know "x ?: y" support is gcc extention, what about sticking
> to standard syntax?

Already used five places in DPDK, so didn't seem like a problem.
  

Patch

diff --git a/app/test/test_cryptodev.c b/app/test/test_cryptodev.c
index fb2af40b99ee..5072b3b6ece5 100644
--- a/app/test/test_cryptodev.c
+++ b/app/test/test_cryptodev.c
@@ -3153,8 +3153,9 @@  test_snow3g_authentication(const struct snow3g_hash_test_data *tdata)
 				ut_params->op);
 	ut_params->obuf = ut_params->op->sym->m_src;
 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
-	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
-			+ plaintext_pad_len;
+	ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf,
+						    uint8_t *,
+						    plaintext_pad_len);
 
 	/* Validate obuf */
 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
@@ -3247,8 +3248,9 @@  test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata)
 				ut_params->op);
 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
 	ut_params->obuf = ut_params->op->sym->m_src;
-	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
-				+ plaintext_pad_len;
+	ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf,
+						    uint8_t *,
+						    plaintext_pad_len);
 
 	/* Validate obuf */
 	if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
@@ -3337,8 +3339,9 @@  test_kasumi_authentication(const struct kasumi_hash_test_data *tdata)
 
 	ut_params->obuf = ut_params->op->sym->m_src;
 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
-	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
-			+ plaintext_pad_len;
+	ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf,
+						    uint8_t *,
+						    plaintext_pad_len);
 
 	/* Validate obuf */
 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
@@ -3425,8 +3428,9 @@  test_kasumi_authentication_verify(const struct kasumi_hash_test_data *tdata)
 				ut_params->op);
 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
 	ut_params->obuf = ut_params->op->sym->m_src;
-	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
-				+ plaintext_pad_len;
+	ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf,
+						    uint8_t *,
+						    plaintext_pad_len);
 
 	/* Validate obuf */
 	if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
@@ -4879,8 +4883,9 @@  test_zuc_cipher_auth(const struct wireless_test_data *tdata)
 			tdata->validDataLenInBits.len,
 			"ZUC Ciphertext data not as expected");
 
-	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
-	    + plaintext_pad_len;
+	ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf,
+						    uint8_t *,
+						    plaintext_pad_len);
 
 	/* Validate obuf */
 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
@@ -4994,8 +4999,9 @@  test_snow3g_cipher_auth(const struct snow3g_test_data *tdata)
 			tdata->validDataLenInBits.len,
 			"SNOW 3G Ciphertext data not as expected");
 
-	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
-	    + plaintext_pad_len;
+	ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf,
+						    uint8_t *,
+						    plaintext_pad_len);
 
 	/* Validate obuf */
 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
@@ -5163,9 +5169,9 @@  test_snow3g_auth_cipher(const struct snow3g_test_data *tdata,
 		debug_hexdump(stdout, "ciphertext expected:",
 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
 
-		ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
-			+ (tdata->digest.offset_bytes == 0 ?
-		plaintext_pad_len : tdata->digest.offset_bytes);
+		ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf,
+					uint8_t *,
+					tdata->digest.offset_bytes ? : plaintext_pad_len);
 
 		debug_hexdump(stdout, "digest:", ut_params->digest,
 			tdata->digest.len);
@@ -5577,10 +5583,9 @@  test_kasumi_auth_cipher(const struct kasumi_test_data *tdata,
 		debug_hexdump(stdout, "ciphertext expected:",
 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
 
-		ut_params->digest = rte_pktmbuf_mtod(
-			ut_params->obuf, uint8_t *) +
-			(tdata->digest.offset_bytes == 0 ?
-			plaintext_pad_len : tdata->digest.offset_bytes);
+		ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf,
+					uint8_t *,
+					tdata->digest.offset_bytes ? : plaintext_pad_len);
 
 		debug_hexdump(stdout, "digest:", ut_params->digest,
 			tdata->digest.len);
@@ -5924,8 +5929,9 @@  test_kasumi_cipher_auth(const struct kasumi_test_data *tdata)
 	ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
 				tdata->validCipherOffsetInBits.len >> 3);
 
-	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
-			+ plaintext_pad_len;
+	ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf,
+						    uint8_t *,
+						    plaintext_pad_len);
 
 	const uint8_t *reference_ciphertext = tdata->ciphertext.data +
 				(tdata->validCipherOffsetInBits.len >> 3);
@@ -6344,8 +6350,9 @@  test_zuc_authentication(const struct wireless_test_data *tdata,
 				ut_params->op);
 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
 	ut_params->obuf = ut_params->op->sym->m_src;
-	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
-			+ plaintext_pad_len;
+	ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf,
+						    uint8_t *,
+						    plaintext_pad_len);
 
 	if (auth_op != RTE_CRYPTO_AUTH_OP_VERIFY) {
 		/* Validate obuf */
@@ -6531,10 +6538,9 @@  test_zuc_auth_cipher(const struct wireless_test_data *tdata,
 		debug_hexdump(stdout, "ciphertext expected:",
 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
 
-		ut_params->digest = rte_pktmbuf_mtod(
-			ut_params->obuf, uint8_t *) +
-			(tdata->digest.offset_bytes == 0 ?
-			plaintext_pad_len : tdata->digest.offset_bytes);
+		ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf,
+					uint8_t *,
+					tdata->digest.offset_bytes ? : plaintext_pad_len);
 
 		debug_hexdump(stdout, "digest:", ut_params->digest,
 			tdata->digest.len);
@@ -7959,9 +7965,9 @@  test_mixed_auth_cipher(const struct mixed_cipher_auth_test_data *tdata,
 				tdata->ciphertext.data,
 				tdata->ciphertext.len_bits >> 3);
 
-		ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
-				+ (tdata->digest_enc.offset == 0 ?
-		plaintext_pad_len : tdata->digest_enc.offset);
+		ut_params->digest = rte_pktmbuf_mtod_offset(ut_params->obuf,
+					uint8_t *,
+					tdata->digest_enc.offset ? : plaintext_pad_len);
 
 		debug_hexdump(stdout, "digest:", ut_params->digest,
 				tdata->digest_enc.len);