Skip to contentSkip to conversation

ext4: Replace KUnit tests for memcmp() with KUNIT_ASSERT_MEMEQ()

PATCH Applied Ryota Sakamoto 2 participants 2 messages Jan 27 – May 28 ext4 file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ext4: Replace KUnit tests for memcmp() with KUNIT_ASSERT_MEMEQ()

Replace KUnit tests for memcmp() with KUNIT_ASSERT_MEMEQ() to improve debugging that prints the hex dump of the buffers when the assertion fails, whereas memcmp() only returns an integer difference.

---
 fs/ext4/mballoc-test.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
fs/ext4/mballoc-test.c +3 -6
index a9416b20ff64c930d90fc177d01cd6a4639d8333..85613b1811cd7c7b7410acff6028f0eabf28ef2c 100644
@@ -710,8 +710,7 @@ do_test_generate_buddy(struct kunit *test, struct super_block *sb, void *bitmap,
 	ext4_mb_generate_buddy(sb, ext4_buddy, bitmap, TEST_GOAL_GROUP,
 			       ext4_grp);
 
-	KUNIT_ASSERT_EQ(test, memcmp(mbt_buddy, ext4_buddy, sb->s_blocksize),
-			0);
+	KUNIT_ASSERT_MEMEQ(test, mbt_buddy, ext4_buddy, sb->s_blocksize);
 	mbt_validate_group_info(test, mbt_grp, ext4_grp);
 }
 
@@ -772,8 +771,7 @@ test_mb_mark_used_range(struct kunit *test, struct ext4_buddy *e4b,
 		grp->bb_counters[i] = 0;
 	ext4_mb_generate_buddy(sb, buddy, bitmap, 0, grp);
 
-	KUNIT_ASSERT_EQ(test, memcmp(buddy, e4b->bd_buddy, sb->s_blocksize),
-			0);
+	KUNIT_ASSERT_MEMEQ(test, buddy, e4b->bd_buddy, sb->s_blocksize);
 	mbt_validate_group_info(test, grp, e4b->bd_info);
 }
 
@@ -837,8 +835,7 @@ test_mb_free_blocks_range(struct kunit *test, struct ext4_buddy *e4b,
 		grp->bb_counters[i] = 0;
 	ext4_mb_generate_buddy(sb, buddy, bitmap, 0, grp);
 
-	KUNIT_ASSERT_EQ(test, memcmp(buddy, e4b->bd_buddy, sb->s_blocksize),
-			0);
+	KUNIT_ASSERT_MEMEQ(test, buddy, e4b->bd_buddy, sb->s_blocksize);
 	mbt_validate_group_info(test, grp, e4b->bd_info);
 
 }

---
base-commit: fcb70a56f4d81450114034b2c61f48ce7444a0e2
change-id: 20260127-fix-fs_ext4-memcmp-e8014778cf73

Best regards,

Signature · 1 line
Ryota Sakamoto <[email protected]>
maintainer Applied
#1 lore raw
Quoted 3 lines · Ryota Sakamoto

Replace KUnit tests for memcmp() with KUNIT_ASSERT_MEMEQ() to improve debugging that prints the hex dump of the buffers when the assertion fails, whereas memcmp() only returns an integer difference.

Applied, thanks!

[1/1] ext4: Replace KUnit tests for memcmp() with KUNIT_ASSERT_MEMEQ()

      commit: eef9fb4e19bf99252232339183ee167c63457c57

Best regards,

Signature · 1 line
Theodore Ts'o <[email protected]>