diff mbox series

multipath-tools tests: use assert_true/false instead of assert()

Message ID 20230315164813.2939-1-mwilck@suse.com (mailing list archive)
State Not Applicable, archived
Delegated to: christophe varoqui
Headers show
Series multipath-tools tests: use assert_true/false instead of assert() | expand

Commit Message

Martin Wilck March 15, 2023, 4:48 p.m. UTC
From: Dirk Müller <dirk@dmllr.de>

Otherwise the build fails with userspace-rcu 0.14 with

   error: implicit declaration of function 'assert' [-Werror=implicit-function-declaration]
   note: 'assert' is defined in header '<assert.h>'; did you forget to '#include <assert.h>'?

Until liburcu 0.13.0, this didn't show up as a compile error, because
"assert.h" was pulled in via config.h -> urcu.h.

But these assert() calls should have been cmocka assert macros
in the first place.

Signed-off-by: Dirk Müller <dirk@dmllr.de>
Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 tests/util.c | 44 +++++++++++++++++++++-----------------------
 tests/vpd.c  |  2 +-
 2 files changed, 22 insertions(+), 24 deletions(-)

Comments

Benjamin Marzinski March 15, 2023, 9:32 p.m. UTC | #1
On Wed, Mar 15, 2023 at 05:48:12PM +0100, mwilck@suse.com wrote:
> From: Dirk Müller <dirk@dmllr.de>
> 
> Otherwise the build fails with userspace-rcu 0.14 with
> 
>    error: implicit declaration of function 'assert' [-Werror=implicit-function-declaration]
>    note: 'assert' is defined in header '<assert.h>'; did you forget to '#include <assert.h>'?
> 
> Until liburcu 0.13.0, this didn't show up as a compile error, because
> "assert.h" was pulled in via config.h -> urcu.h.
> 
> But these assert() calls should have been cmocka assert macros
> in the first place.
> 
> Signed-off-by: Dirk Müller <dirk@dmllr.de>
> Signed-off-by: Martin Wilck <mwilck@suse.com>


Reviewed-by: Benjamin Marzinski <bmarzins@redhat.com>

> ---
>  tests/util.c | 44 +++++++++++++++++++++-----------------------
>  tests/vpd.c  |  2 +-
>  2 files changed, 22 insertions(+), 24 deletions(-)
> 
> diff --git a/tests/util.c b/tests/util.c
> index 9affb0e..d6083dc 100644
> --- a/tests/util.c
> +++ b/tests/util.c
> @@ -193,7 +193,7 @@ static void test_bitmask_1(void **state)
>  	for (j = 0; j < BITARR_SZ; j++) {
>  		for (i = 0; i < 64; i++) {
>  			b = 64 * j + i;
> -			assert(!is_bit_set_in_bitfield(b, bf));
> +			assert_false(is_bit_set_in_bitfield(b, bf));
>  			set_bit_in_bitfield(b, bf);
>  			for (k = 0; k < BITARR_SZ; k++) {
>  #if 0
> @@ -207,13 +207,13 @@ static void test_bitmask_1(void **state)
>  			}
>  			for (m = 0; m < 64; m++)
>  				if (i == m)
> -					assert(is_bit_set_in_bitfield(64 * j + m,
> -								      bf));
> +					assert_true(is_bit_set_in_bitfield(64 * j + m,
> +									   bf));
>  				else
> -					assert(!is_bit_set_in_bitfield(64 * j + m,
> -								       bf));
> +					assert_false(is_bit_set_in_bitfield(64 * j + m,
> +									   bf));
>  			clear_bit_in_bitfield(b, bf);
> -			assert(!is_bit_set_in_bitfield(b, bf));
> +			assert_false(is_bit_set_in_bitfield(b, bf));
>  			for (k = 0; k < BITARR_SZ; k++)
>  				assert_int_equal(arr[k], 0ULL);
>  		}
> @@ -235,16 +235,16 @@ static void test_bitmask_2(void **state)
>  	for (j = 0; j < BITARR_SZ; j++) {
>  		for (i = 0; i < 64; i++) {
>  			b = 64 * j + i;
> -			assert(!is_bit_set_in_bitfield(b, bf));
> +			assert_false(is_bit_set_in_bitfield(b, bf));
>  			set_bit_in_bitfield(b, bf);
>  			for (m = 0; m < 64; m++)
>  				if (m <= i)
> -					assert(is_bit_set_in_bitfield(64 * j + m,
> -								      bf));
> +					assert_true(is_bit_set_in_bitfield(64 * j + m,
> +									   bf));
>  				else
> -					assert(!is_bit_set_in_bitfield(64 * j + m,
> -								       bf));
> -			assert(is_bit_set_in_bitfield(b, bf));
> +					assert_false(is_bit_set_in_bitfield(64 * j + m,
> +									    bf));
> +			assert_true(is_bit_set_in_bitfield(b, bf));
>  			for (k = 0; k < BITARR_SZ; k++) {
>  				if (k < j || (k == j && i == 63))
>  					assert_int_equal(arr[k], ~0ULL);
> @@ -260,16 +260,16 @@ static void test_bitmask_2(void **state)
>  	for (j = 0; j < BITARR_SZ; j++) {
>  		for (i = 0; i < 64; i++) {
>  			b = 64 * j + i;
> -			assert(is_bit_set_in_bitfield(b, bf));
> +			assert_true(is_bit_set_in_bitfield(b, bf));
>  			clear_bit_in_bitfield(b, bf);
>  			for (m = 0; m < 64; m++)
>  				if (m <= i)
> -					assert(!is_bit_set_in_bitfield(64 * j + m,
> -								       bf));
> +					assert_false(is_bit_set_in_bitfield(64 * j + m,
> +									    bf));
>  				else
> -					assert(is_bit_set_in_bitfield(64 * j + m,
> -								      bf));
> -			assert(!is_bit_set_in_bitfield(b, bf));
> +					assert_true(is_bit_set_in_bitfield(64 * j + m,
> +									   bf));
> +			assert_false(is_bit_set_in_bitfield(b, bf));
>  			for (k = 0; k < BITARR_SZ; k++) {
>  				if (k < j || (k == j && i == 63))
>  					assert_int_equal(arr[k], 0ULL);
> @@ -316,9 +316,8 @@ static void _test_bitmask_small(unsigned int n)
>  	uint32_t *arr;
>  	unsigned int size = maybe_swap_idx((n - 1) / 32) + 1, i;
>  
> -	assert(sizeof(bitfield_t) == 4 || sizeof(bitfield_t) == 8);
> -	assert(n <= 64);
> -	assert(n >= 1);
> +	assert_true(sizeof(bitfield_t) == 4 || sizeof(bitfield_t) == 8);
> +	assert_in_range(n, 1, 64);
>  
>  	bf = alloc_bitfield(n);
>  	assert_non_null(bf);
> @@ -366,8 +365,7 @@ static void _test_bitmask_small_2(unsigned int n)
>  	uint32_t *arr;
>  	unsigned int size = maybe_swap_idx((n - 1) / 32) + 1, i;
>  
> -	assert(n <= 128);
> -	assert(n >= 65);
> +	assert_in_range(n, 65, 128);
>  
>  	bf = alloc_bitfield(n);
>  	assert_non_null(bf);
> diff --git a/tests/vpd.c b/tests/vpd.c
> index a7d2092..1b2d62d 100644
> --- a/tests/vpd.c
> +++ b/tests/vpd.c
> @@ -119,7 +119,7 @@ static void hex2bin(unsigned char *dst, const char *src,
>  	const char *sc;
>  	unsigned char *ds;
>  
> -	assert(srclen % 2 == 0);
> +	assert_true(srclen % 2 == 0);
>  	for (sc = src, ds = dst;
>  	     sc < src + srclen &&  ds < dst + dstlen;
>  	     sc += 2, ++ds)
> -- 
> 2.39.2
--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel
diff mbox series

Patch

diff --git a/tests/util.c b/tests/util.c
index 9affb0e..d6083dc 100644
--- a/tests/util.c
+++ b/tests/util.c
@@ -193,7 +193,7 @@  static void test_bitmask_1(void **state)
 	for (j = 0; j < BITARR_SZ; j++) {
 		for (i = 0; i < 64; i++) {
 			b = 64 * j + i;
-			assert(!is_bit_set_in_bitfield(b, bf));
+			assert_false(is_bit_set_in_bitfield(b, bf));
 			set_bit_in_bitfield(b, bf);
 			for (k = 0; k < BITARR_SZ; k++) {
 #if 0
@@ -207,13 +207,13 @@  static void test_bitmask_1(void **state)
 			}
 			for (m = 0; m < 64; m++)
 				if (i == m)
-					assert(is_bit_set_in_bitfield(64 * j + m,
-								      bf));
+					assert_true(is_bit_set_in_bitfield(64 * j + m,
+									   bf));
 				else
-					assert(!is_bit_set_in_bitfield(64 * j + m,
-								       bf));
+					assert_false(is_bit_set_in_bitfield(64 * j + m,
+									   bf));
 			clear_bit_in_bitfield(b, bf);
-			assert(!is_bit_set_in_bitfield(b, bf));
+			assert_false(is_bit_set_in_bitfield(b, bf));
 			for (k = 0; k < BITARR_SZ; k++)
 				assert_int_equal(arr[k], 0ULL);
 		}
@@ -235,16 +235,16 @@  static void test_bitmask_2(void **state)
 	for (j = 0; j < BITARR_SZ; j++) {
 		for (i = 0; i < 64; i++) {
 			b = 64 * j + i;
-			assert(!is_bit_set_in_bitfield(b, bf));
+			assert_false(is_bit_set_in_bitfield(b, bf));
 			set_bit_in_bitfield(b, bf);
 			for (m = 0; m < 64; m++)
 				if (m <= i)
-					assert(is_bit_set_in_bitfield(64 * j + m,
-								      bf));
+					assert_true(is_bit_set_in_bitfield(64 * j + m,
+									   bf));
 				else
-					assert(!is_bit_set_in_bitfield(64 * j + m,
-								       bf));
-			assert(is_bit_set_in_bitfield(b, bf));
+					assert_false(is_bit_set_in_bitfield(64 * j + m,
+									    bf));
+			assert_true(is_bit_set_in_bitfield(b, bf));
 			for (k = 0; k < BITARR_SZ; k++) {
 				if (k < j || (k == j && i == 63))
 					assert_int_equal(arr[k], ~0ULL);
@@ -260,16 +260,16 @@  static void test_bitmask_2(void **state)
 	for (j = 0; j < BITARR_SZ; j++) {
 		for (i = 0; i < 64; i++) {
 			b = 64 * j + i;
-			assert(is_bit_set_in_bitfield(b, bf));
+			assert_true(is_bit_set_in_bitfield(b, bf));
 			clear_bit_in_bitfield(b, bf);
 			for (m = 0; m < 64; m++)
 				if (m <= i)
-					assert(!is_bit_set_in_bitfield(64 * j + m,
-								       bf));
+					assert_false(is_bit_set_in_bitfield(64 * j + m,
+									    bf));
 				else
-					assert(is_bit_set_in_bitfield(64 * j + m,
-								      bf));
-			assert(!is_bit_set_in_bitfield(b, bf));
+					assert_true(is_bit_set_in_bitfield(64 * j + m,
+									   bf));
+			assert_false(is_bit_set_in_bitfield(b, bf));
 			for (k = 0; k < BITARR_SZ; k++) {
 				if (k < j || (k == j && i == 63))
 					assert_int_equal(arr[k], 0ULL);
@@ -316,9 +316,8 @@  static void _test_bitmask_small(unsigned int n)
 	uint32_t *arr;
 	unsigned int size = maybe_swap_idx((n - 1) / 32) + 1, i;
 
-	assert(sizeof(bitfield_t) == 4 || sizeof(bitfield_t) == 8);
-	assert(n <= 64);
-	assert(n >= 1);
+	assert_true(sizeof(bitfield_t) == 4 || sizeof(bitfield_t) == 8);
+	assert_in_range(n, 1, 64);
 
 	bf = alloc_bitfield(n);
 	assert_non_null(bf);
@@ -366,8 +365,7 @@  static void _test_bitmask_small_2(unsigned int n)
 	uint32_t *arr;
 	unsigned int size = maybe_swap_idx((n - 1) / 32) + 1, i;
 
-	assert(n <= 128);
-	assert(n >= 65);
+	assert_in_range(n, 65, 128);
 
 	bf = alloc_bitfield(n);
 	assert_non_null(bf);
diff --git a/tests/vpd.c b/tests/vpd.c
index a7d2092..1b2d62d 100644
--- a/tests/vpd.c
+++ b/tests/vpd.c
@@ -119,7 +119,7 @@  static void hex2bin(unsigned char *dst, const char *src,
 	const char *sc;
 	unsigned char *ds;
 
-	assert(srclen % 2 == 0);
+	assert_true(srclen % 2 == 0);
 	for (sc = src, ds = dst;
 	     sc < src + srclen &&  ds < dst + dstlen;
 	     sc += 2, ++ds)