[dpdk-dev,v3,2/2] test: update common auto test

Message ID 20180404101606.5156-2-pbhagavatula@caviumnetworks.com (mailing list archive)
State Changes Requested, archived
Delegated to: Thomas Monjalon
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Pavan Nikhilesh April 4, 2018, 10:16 a.m. UTC
  Update common auto test to include test for previous power of 2 for both
32 and 64bit integers.

Signed-off-by: Pavan Nikhilesh <pbhagavatula@caviumnetworks.com>
---
 test/test/test_common.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
  

Comments

Thomas Monjalon April 4, 2018, 12:49 p.m. UTC | #1
04/04/2018 12:16, Pavan Nikhilesh:
> Update common auto test to include test for previous power of 2 for both
> 32 and 64bit integers.

This patch can be merged with previous one (related lib change).

[...]
> +	for (i = 1, p = 1; i <= MAX_NUM; i++) {
> +		if (rte_align32prevpow2(i) != p)
> +			FAIL_ALIGN("rte_align32prevpow2", i, p);
> +		if (rte_is_power_of_2(i + 1))
> +			p = i + 1;
> +	}
> +
> +	for (j = 1, q = 1; j <= MAX_NUM ; j++) {
> +		if (rte_align64pow2(j) != q)

You could create FAIL_ALIGN64 for consistency.

> +			printf("rte_align64pow2() test failed: %lu %lu\n", j,

%lu does not work on 32-bit machines.
Please use PRIu64.

See http://dpdk.org/ml/archives/dev/2018-February/090882.html
  
Pavan Nikhilesh April 4, 2018, 12:54 p.m. UTC | #2
On Wed, Apr 04, 2018 at 02:49:28PM +0200, Thomas Monjalon wrote:
> 04/04/2018 12:16, Pavan Nikhilesh:
> > Update common auto test to include test for previous power of 2 for both
> > 32 and 64bit integers.
>
> This patch can be merged with previous one (related lib change).
>
> [...]
> > +	for (i = 1, p = 1; i <= MAX_NUM; i++) {
> > +		if (rte_align32prevpow2(i) != p)
> > +			FAIL_ALIGN("rte_align32prevpow2", i, p);
> > +		if (rte_is_power_of_2(i + 1))
> > +			p = i + 1;
> > +	}
> > +
> > +	for (j = 1, q = 1; j <= MAX_NUM ; j++) {
> > +		if (rte_align64pow2(j) != q)
>
> You could create FAIL_ALIGN64 for consistency.
>
> > +			printf("rte_align64pow2() test failed: %lu %lu\n", j,
>
> %lu does not work on 32-bit machines.
> Please use PRIu64.
>
> See http://dpdk.org/ml/archives/dev/2018-February/090882.html
>

Thanks for the headsup will send out next version with suggested changes.

Pavan.

>
>
  

Patch

diff --git a/test/test/test_common.c b/test/test/test_common.c
index d0342430f..2115cc78f 100644
--- a/test/test/test_common.c
+++ b/test/test/test_common.c
@@ -80,6 +80,7 @@  test_align(void)
 			val / pow != (i / pow) + 1)		/* if not aligned, hence +1 */
 
 	uint32_t i, p, val;
+	uint64_t j, q;
 
 	for (i = 1, p = 1; i <= MAX_NUM; i ++) {
 		if (rte_align32pow2(i) != p)
@@ -88,6 +89,29 @@  test_align(void)
 			p <<= 1;
 	}
 
+	for (i = 1, p = 1; i <= MAX_NUM; i++) {
+		if (rte_align32prevpow2(i) != p)
+			FAIL_ALIGN("rte_align32prevpow2", i, p);
+		if (rte_is_power_of_2(i + 1))
+			p = i + 1;
+	}
+
+	for (j = 1, q = 1; j <= MAX_NUM ; j++) {
+		if (rte_align64pow2(j) != q)
+			printf("rte_align64pow2() test failed: %lu %lu\n", j,
+					q);
+		if (j == q)
+			q <<= 1;
+	}
+
+	for (j = 1, q = 1; j <= MAX_NUM ; j++) {
+		if (rte_align64prevpow2(j) != q)
+			printf("rte_align64prevpow2() test failed: %lu %lu\n",
+					j, q);
+		if (rte_is_power_of_2(j + 1))
+			q = j + 1;
+	}
+
 	for (p = 2; p <= MAX_NUM; p <<= 1) {
 
 		if (!rte_is_power_of_2(p))