[PATCH v2] test/member: fix incorrect expression

Leyi Rong leyi.rong at intel.com
Tue Oct 25 11:00:21 CEST 2022


Fix incorrect expression by cast division operand to type double
to match ceil() and fabs() definitions.

Coverity issue: 381398, 381401, 381402
Fixes: db354bd2e1f8 ("member: add NitroSketch mode")

Signed-off-by: Leyi Rong <leyi.rong at intel.com>

---
v2:
- resubmit as v1 performance CI fail maybe false-positive.

---
 app/test/test_member.c      | 16 ++++++++--------
 app/test/test_member_perf.c |  3 ++-
 2 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/app/test/test_member.c b/app/test/test_member.c
index 8266e6437b..c1b6a7d8b9 100644
--- a/app/test/test_member.c
+++ b/app/test/test_member.c
@@ -712,19 +712,19 @@ print_out_sketch_results(uint64_t *count_result, member_set_t *heavy_set,
 			printf("key %2u, count %8"PRIu64", real count %8u, "
 				"heavy_set %u, deviation rate [%.04f]\n",
 				i, count_result[i],
-				(unsigned int)ceil(SKETCH_LARGEST_KEY_SIZE / (i + 1)) *
+				(unsigned int)ceil((double)SKETCH_LARGEST_KEY_SIZE / (i + 1)) *
 				HH_PKT_SIZE,
 				heavy_set[i],
-				fabs((float)count_result[i] - (float)NUM_OF_KEY(i) * HH_PKT_SIZE) /
-				((float)NUM_OF_KEY(i) * HH_PKT_SIZE));
+				fabs((double)count_result[i] - (double)NUM_OF_KEY(i) * HH_PKT_SIZE) /
+				((double)NUM_OF_KEY(i) * HH_PKT_SIZE));
 		else
 			printf("key %2u, count %8"PRIu64", real count %8u, "
 				"heavy_set %u, deviation rate [%.04f]\n",
 				i, count_result[i],
-				(unsigned int)ceil(SKETCH_LARGEST_KEY_SIZE / (i + 1)),
+				(unsigned int)ceil((double)SKETCH_LARGEST_KEY_SIZE / (i + 1)),
 				heavy_set[i],
-				fabs((float)count_result[i] - (float)NUM_OF_KEY(i)) /
-				(float)NUM_OF_KEY(i));
+				fabs((double)count_result[i] - (double)NUM_OF_KEY(i)) /
+				(double)NUM_OF_KEY(i));
 	}
 }
 
@@ -879,7 +879,7 @@ test_member_sketch(void)
 	int count_byte = 0;
 
 	for (i = 0; i < SKETCH_TOTAL_KEY; i++)
-		total_pkt += ceil(SKETCH_LARGEST_KEY_SIZE / (i + 1));
+		total_pkt += ceil((double)SKETCH_LARGEST_KEY_SIZE / (i + 1));
 
 	printf("\nTotal key count [%u] in Sketch Autotest\n", total_pkt);
 
@@ -892,7 +892,7 @@ test_member_sketch(void)
 
 	index = 0;
 	for (i = 0; i < SKETCH_TOTAL_KEY; i++) {
-		for (j = 0; j < ceil(SKETCH_LARGEST_KEY_SIZE / (i + 1)); j++)
+		for (j = 0; j < ceil((double)SKETCH_LARGEST_KEY_SIZE / (i + 1)); j++)
 			keys[index++] = i;
 	}
 
diff --git a/app/test/test_member_perf.c b/app/test/test_member_perf.c
index b7eb3e4c66..7b6adf913e 100644
--- a/app/test/test_member_perf.c
+++ b/app/test/test_member_perf.c
@@ -196,7 +196,8 @@ setup_keys_and_data(struct member_perf_params *params, unsigned int cycle,
 	for (i = 0; i < KEYS_TO_ADD; i++) {
 		if (count_down == 0) {
 			distinct_key++;
-			count_down = ceil(SKETCH_LARGEST_KEY_SIZE / (distinct_key + 1));
+			count_down = ceil((double)SKETCH_LARGEST_KEY_SIZE /
+					(distinct_key + 1));
 		}
 		memcpy(hh_keys[i], keys[distinct_key], params->key_size);
 		count_down--;
-- 
2.25.1



More information about the dev mailing list