DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH] test/member: fix incorrect expression
@ 2022-10-12  7:48 Leyi Rong
  2022-10-25  9:00 ` [PATCH v2] " Leyi Rong
  0 siblings, 1 reply; 3+ messages in thread
From: Leyi Rong @ 2022-10-12  7:48 UTC (permalink / raw)
  To: yipeng1.wang; +Cc: dev, Leyi Rong

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@intel.com>
---
 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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v2] test/member: fix incorrect expression
  2022-10-12  7:48 [PATCH] test/member: fix incorrect expression Leyi Rong
@ 2022-10-25  9:00 ` Leyi Rong
  2022-10-26 15:14   ` Thomas Monjalon
  0 siblings, 1 reply; 3+ messages in thread
From: Leyi Rong @ 2022-10-25  9:00 UTC (permalink / raw)
  To: yipeng1.wang; +Cc: dev, Leyi Rong

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@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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] test/member: fix incorrect expression
  2022-10-25  9:00 ` [PATCH v2] " Leyi Rong
@ 2022-10-26 15:14   ` Thomas Monjalon
  0 siblings, 0 replies; 3+ messages in thread
From: Thomas Monjalon @ 2022-10-26 15:14 UTC (permalink / raw)
  To: Leyi Rong; +Cc: yipeng1.wang, dev

25/10/2022 11:00, Leyi Rong:
> 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@intel.com>

Applied, thanks.




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-10-26 15:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-12  7:48 [PATCH] test/member: fix incorrect expression Leyi Rong
2022-10-25  9:00 ` [PATCH v2] " Leyi Rong
2022-10-26 15:14   ` Thomas Monjalon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).