[v2,1/2] app/test-crypto-perf: fix invalid memcmp results

Message ID 20240105000323.903764-1-suanmingm@nvidia.com (mailing list archive)
State Accepted, archived
Delegated to: akhil goyal
Headers
Series [v2,1/2] app/test-crypto-perf: fix invalid memcmp results |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Suanming Mou Jan. 5, 2024, 12:03 a.m. UTC
  The function memcmp() returns an integer less than, equal to,
or greater than zero. In current code, if the first memcmp()
returns less than zero and the second memcmp() returns greater
than zero, the sum of results may still be 0 and indicates
verify succussed.

This commit converts the return value to be zero or greater
than zero. That will make sure the sum of results be correct.

Fixes: df52cb3b6e13 ("app/crypto-perf: move verify as single test type")

Signed-off-by: Suanming Mou <suanmingm@nvidia.com>
Acked-by: Anoob Joseph <anoobj@marvell.com>
---
 app/test-crypto-perf/cperf_test_verify.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
  

Comments

Power, Ciara Jan. 12, 2024, 4:21 p.m. UTC | #1
> -----Original Message-----
> From: Suanming Mou <suanmingm@nvidia.com>
> Sent: Friday, January 5, 2024 12:03 AM
> To: anoobj@marvell.com; Power, Ciara <ciara.power@intel.com>
> Cc: dev@dpdk.org
> Subject: [PATCH v2 1/2] app/test-crypto-perf: fix invalid memcmp results
> 
> The function memcmp() returns an integer less than, equal to, or greater than
> zero. In current code, if the first memcmp() returns less than zero and the
> second memcmp() returns greater than zero, the sum of results may still be 0
> and indicates verify succussed.
> 
> This commit converts the return value to be zero or greater than zero. That will
> make sure the sum of results be correct.
> 
> Fixes: df52cb3b6e13 ("app/crypto-perf: move verify as single test type")
> 
> Signed-off-by: Suanming Mou <suanmingm@nvidia.com>
> Acked-by: Anoob Joseph <anoobj@marvell.com>
> ---
>  app/test-crypto-perf/cperf_test_verify.c | 6 +++---

Acked-by: Ciara Power <ciara.power@intel.com>
  
Akhil Goyal Feb. 1, 2024, 8:47 a.m. UTC | #2
> The function memcmp() returns an integer less than, equal to,
> or greater than zero. In current code, if the first memcmp()
> returns less than zero and the second memcmp() returns greater
> than zero, the sum of results may still be 0 and indicates
> verify succussed.
> 
> This commit converts the return value to be zero or greater
> than zero. That will make sure the sum of results be correct.
> 
> Fixes: df52cb3b6e13 ("app/crypto-perf: move verify as single test type")
> 
> Signed-off-by: Suanming Mou <suanmingm@nvidia.com>
> Acked-by: Anoob Joseph <anoobj@marvell.com>
Cc: stable@dpdk.org
Series
Applied to dpdk-next-crypto
  

Patch

diff --git a/app/test-crypto-perf/cperf_test_verify.c b/app/test-crypto-perf/cperf_test_verify.c
index a6c0ffe813..8aa714b969 100644
--- a/app/test-crypto-perf/cperf_test_verify.c
+++ b/app/test-crypto-perf/cperf_test_verify.c
@@ -186,18 +186,18 @@  cperf_verify_op(struct rte_crypto_op *op,
 
 	if (cipher == 1) {
 		if (options->cipher_op == RTE_CRYPTO_CIPHER_OP_ENCRYPT)
-			res += memcmp(data + cipher_offset,
+			res += !!memcmp(data + cipher_offset,
 					vector->ciphertext.data,
 					options->test_buffer_size);
 		else
-			res += memcmp(data + cipher_offset,
+			res += !!memcmp(data + cipher_offset,
 					vector->plaintext.data,
 					options->test_buffer_size);
 	}
 
 	if (auth == 1) {
 		if (options->auth_op == RTE_CRYPTO_AUTH_OP_GENERATE)
-			res += memcmp(data + auth_offset,
+			res += !!memcmp(data + auth_offset,
 					vector->digest.data,
 					options->digest_sz);
 	}