Skip to contentSkip to conversation

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

PATCH In review [email protected] 2 participants 2 messages Mar 15, 2023 Device mapper

lore
Share & tools
lore
#0 lore raw

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

From: Dirk Müller <[email protected]>

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.

---
 tests/util.c | 44 +++++++++++++++++++++-----------------------
 tests/vpd.c  |  2 +-
 2 files changed, 22 insertions(+), 24 deletions(-)
tests/util.c +21 -23
index 9affb0e..d6083dc 100644
@@ -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);
tests/vpd.c +1 -1
index a7d2092..1b2d62d 100644
@@ -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)
Signature · 6 lines
2.39.2

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · On Wed, Mar 15, 2023 at 05:48:12PM +0100, [email protected] wrote:

From: Dirk Müller <[email protected]>

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>'?

Quoted 8 lines

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.

Quoted 120 lines
---
 tests/util.c | 44 +++++++++++++++++++++-----------------------
 tests/vpd.c  |  2 +-
 2 files changed, 22 insertions(+), 24 deletions(-)
tests/util.c +21 -23
index 9affb0e..d6083dc 100644
@@ -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);
tests/vpd.c +1 -1
index a7d2092..1b2d62d 100644
@@ -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)
Signature · 1 line
2.39.2

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel