app: add few sanity checks in test-sad app

Message ID b7d06f79141305aa570cbeb2042761b55af8a197.1572608255.git.vladimir.medvedkin@intel.com (mailing list archive)
State Accepted, archived
Delegated to: akhil goyal
Headers
Series app: add few sanity checks in test-sad app |

Checks

Context Check Description
ci/Intel-compilation success Compilation OK
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-compilation success Compile Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/travis-robot success Travis build: passed
ci/checkpatch success coding style OK

Commit Message

Vladimir Medvedkin Nov. 1, 2019, 11:38 a.m. UTC
  Coverity reported about two division by zero:
*** CID 350344:  Incorrect expression  (DIVIDE_BY_ZERO)
Although in fact these dividers will never be equal to 0,
adding explicit checks in lookup() to make coverity happy
will not affect the execution speed.

Signed-off-by: Vladimir Medvedkin <vladimir.medvedkin@intel.com>
Acked-by: Konstantin Ananyev <konstantin.ananyev@intel.com>
---
 app/test-sad/main.c | 4 ++++
 1 file changed, 4 insertions(+)
  

Comments

Akhil Goyal Nov. 5, 2019, 10:51 p.m. UTC | #1
> 
> Coverity reported about two division by zero:
> *** CID 350344:  Incorrect expression  (DIVIDE_BY_ZERO)
> Although in fact these dividers will never be equal to 0,
> adding explicit checks in lookup() to make coverity happy
> will not affect the execution speed.
> 
> Signed-off-by: Vladimir Medvedkin <vladimir.medvedkin@intel.com>
> Acked-by: Konstantin Ananyev <konstantin.ananyev@intel.com>
> ---
Applied to dpdk-next-crypto

Thanks.
  

Patch

diff --git a/app/test-sad/main.c b/app/test-sad/main.c
index bd05638..e61e33f 100644
--- a/app/test-sad/main.c
+++ b/app/test-sad/main.c
@@ -519,6 +519,9 @@  lookup(void *arg)
 	uint32_t burst_sz;
 	struct rte_ipsec_sad *sad = arg;
 
+	if (config.nb_tuples == 0)
+		return 0;
+
 	burst_sz = RTE_MIN(config.burst_sz, config.nb_tuples);
 	for (i = 0; i < config.nb_tuples; i += burst_sz) {
 		for (j = 0; j < burst_sz; j++)
@@ -534,6 +537,7 @@  lookup(void *arg)
 				print_result(keys[j], vals[j]);
 		}
 	}
+	acc = (acc == 0) ? UINT64_MAX : acc;
 	printf("Average lookup cycles %.2Lf, lookups/sec: %.2Lf\n",
 		(long double)acc / config.nb_tuples,
 		(long double)config.nb_tuples * rte_get_tsc_hz() / acc);