Skip to contentSkip to conversation

decoupling the ext4 test module

PATCH Applied Ye Bin 5 participants 8 messages Mar 14 – Mar 28 ext4 file system

lore
Share & tools
lore

Ye Bin

author
#0 lore raw

v2 cover decoupling the ext4 test module

From: Ye Bin <[email protected]>

This patchset is split out from the "Fix some issues about ext4-test" patchset. It decouples mballoc-test.c and extents-test.c from the ext4 module, resolving the issue where these two tests could not be run when EXT4_KUNIT_TESTS is set to M.

Ye Bin (3):
ext4: introduce EXPORT_SYMBOL_FOR_EXT4_TEST() helper
ext4: fix mballoc-test.c is not compiled when EXT4_KUNIT_TESTS=M
ext4: fix extents-test.c is not compiled when EXT4_KUNIT_TESTS=M

 fs/ext4/Makefile       |   5 +-
 fs/ext4/ext4.h         |   5 ++
 fs/ext4/ext4_extents.h |  12 +++++
 fs/ext4/extents-test.c |   8 ++--
 fs/ext4/extents.c      |  39 +++++++++++++---
 fs/ext4/mballoc-test.c |  81 ++++++++++++++++----------------
 fs/ext4/mballoc.c      | 102 +++++++++++++++++++++++++++++++++++++++--
 fs/ext4/mballoc.h      |  30 ++++++++++++
 8 files changed, 227 insertions(+), 55 deletions(-)
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH v2 1/3 ext4: introduce EXPORT_SYMBOL_FOR_EXT4_TEST() helper

From: Ye Bin <[email protected]>

Introduce EXPORT_SYMBOL_FOR_EXT4_TEST() helper for kuint test.

---
 fs/ext4/ext4.h | 5 +++++
 1 file changed, 5 insertions(+)
fs/ext4/ext4.h +5 -0
index 9552d154ea8d..b60b334b7693 100644
@@ -3945,6 +3945,11 @@ static inline bool ext4_inode_can_atomic_write(struct inode *inode)
 extern int ext4_block_write_begin(handle_t *handle, struct folio *folio,
 				  loff_t pos, unsigned len,
 				  get_block_t *get_block);
+
+#if IS_ENABLED(CONFIG_EXT4_KUNIT_TESTS)
+#define EXPORT_SYMBOL_FOR_EXT4_TEST(sym) \
+	EXPORT_SYMBOL_FOR_MODULES(sym, "ext4-test")
+#endif
 #endif	/* __KERNEL__ */
 
 #endif	/* _EXT4_H */
Signature · 1 line
2.34.1
author
#2 lore raw

PATCH v2 2/3 ext4: fix mballoc-test.c is not compiled when EXT4_KUNIT_TESTS=M

In reply to Ye Bin

From: Ye Bin <[email protected]>

Now, only EXT4_KUNIT_TESTS=Y testcase will be compiled in 'mballoc.c'. To solve this issue, the ext4 test code needs to be decoupled. The ext4 test module is compiled into a separate module.

Fixes 7c9fa399a369 ("ext4: add first unit test for ext4_mb_new_blocks_simple in mballoc")
---
 fs/ext4/Makefile       |   4 +-
 fs/ext4/mballoc-test.c |  81 ++++++++++++++++----------------
 fs/ext4/mballoc.c      | 102 +++++++++++++++++++++++++++++++++++++++--
 fs/ext4/mballoc.h      |  30 ++++++++++++
 4 files changed, 172 insertions(+), 45 deletions(-)
fs/ext4/Makefile +2 -2
index 72206a292676..d836c3fe311b 100644
@@ -14,7 +14,7 @@ ext4-y	:= balloc.o bitmap.o block_validity.o dir.o ext4_jbd2.o extents.o \
 
 ext4-$(CONFIG_EXT4_FS_POSIX_ACL)	+= acl.o
 ext4-$(CONFIG_EXT4_FS_SECURITY)		+= xattr_security.o
-ext4-inode-test-objs			+= inode-test.o
-obj-$(CONFIG_EXT4_KUNIT_TESTS)		+= ext4-inode-test.o
+ext4-test-objs				+= inode-test.o mballoc-test.o
+obj-$(CONFIG_EXT4_KUNIT_TESTS)		+= ext4-test.o
 ext4-$(CONFIG_FS_VERITY)		+= verity.o
 ext4-$(CONFIG_FS_ENCRYPTION)		+= crypto.o
fs/ext4/mballoc-test.c +41 -40

281 lines not on this page · raw message

fs/ext4/mballoc.c +99 -3

112 lines not on this page · raw message

fs/ext4/mballoc.h +30 -0
index 15a049f05d04..39333ce72cbd 100644
@@ -270,4 +270,34 @@ ext4_mballoc_query_range(
 	ext4_mballoc_query_range_fn	formatter,
 	void				*priv);
 
+extern int ext4_mb_mark_context(handle_t *handle,
+		struct super_block *sb, bool state,
+		ext4_group_t group, ext4_grpblk_t blkoff,
+		ext4_grpblk_t len, int flags,
+		ext4_grpblk_t *ret_changed);
+#if IS_ENABLED(CONFIG_EXT4_KUNIT_TESTS)
+extern void mb_clear_bits_test(void *bm, int cur, int len);
+extern ext4_fsblk_t
+ext4_mb_new_blocks_simple_test(struct ext4_allocation_request *ar,
+			       int *errp);
+extern int mb_find_next_zero_bit_test(void *addr, int max, int start);
+extern int mb_find_next_bit_test(void *addr, int max, int start);
+extern void mb_clear_bit_test(int bit, void *addr);
+extern int mb_test_bit_test(int bit, void *addr);
+extern int
+ext4_mb_mark_diskspace_used_test(struct ext4_allocation_context *ac,
+				 handle_t *handle);
+extern int mb_mark_used_test(struct ext4_buddy *e4b,
+			     struct ext4_free_extent *ex);
+extern void ext4_mb_generate_buddy_test(struct super_block *sb,
+		void *buddy, void *bitmap, ext4_group_t group,
+		struct ext4_group_info *grp);
+extern int ext4_mb_load_buddy_test(struct super_block *sb,
+		ext4_group_t group, struct ext4_buddy *e4b);
+extern void ext4_mb_unload_buddy_test(struct ext4_buddy *e4b);
+extern void mb_free_blocks_test(struct inode *inode,
+		struct ext4_buddy *e4b, int first, int count);
+extern void ext4_free_blocks_simple_test(struct inode *inode,
+		ext4_fsblk_t block, unsigned long count);
+#endif
 #endif
Signature · 1 line
2.34.1
author
#3 lore raw

PATCH v2 3/3 ext4: fix extents-test.c is not compiled when EXT4_KUNIT_TESTS=M

In reply to Ye Bin

From: Ye Bin <[email protected]>

Now, only EXT4_KUNIT_TESTS=Y testcase will be compiled in 'extents.c'. To solve this issue, the ext4 test code needs to be decoupled. The 'extents-test' module is compiled into 'ext4-test' module.

Fixes cb1e0c1d1fad ("ext4: kunit tests for extent splitting and conversion")
---
 fs/ext4/Makefile       |  3 ++-
 fs/ext4/ext4_extents.h | 12 ++++++++++++
 fs/ext4/extents-test.c |  8 ++++----
 fs/ext4/extents.c      | 39 +++++++++++++++++++++++++++++++++------
 4 files changed, 51 insertions(+), 11 deletions(-)
fs/ext4/Makefile +2 -1
index d836c3fe311b..3baee4e7c1cf 100644
@@ -14,7 +14,8 @@ ext4-y	:= balloc.o bitmap.o block_validity.o dir.o ext4_jbd2.o extents.o \
 
 ext4-$(CONFIG_EXT4_FS_POSIX_ACL)	+= acl.o
 ext4-$(CONFIG_EXT4_FS_SECURITY)		+= xattr_security.o
-ext4-test-objs				+= inode-test.o mballoc-test.o
+ext4-test-objs				+= inode-test.o mballoc-test.o \
+					   extents-test.o
 obj-$(CONFIG_EXT4_KUNIT_TESTS)		+= ext4-test.o
 ext4-$(CONFIG_FS_VERITY)		+= verity.o
 ext4-$(CONFIG_FS_ENCRYPTION)		+= crypto.o
fs/ext4/ext4_extents.h +12 -0
index c484125d963f..ebaf7cc42430 100644
@@ -264,5 +264,17 @@ static inline void ext4_idx_store_pblock(struct ext4_extent_idx *ix,
 				     0xffff);
 }
 
+extern int __ext4_ext_dirty(const char *where, unsigned int line,
+			    handle_t *handle, struct inode *inode,
+			    struct ext4_ext_path *path);
+extern int ext4_ext_zeroout(struct inode *inode, struct ext4_extent *ex);
+#if IS_ENABLED(CONFIG_EXT4_KUNIT_TESTS)
+extern int ext4_ext_space_root_idx_test(struct inode *inode, int check);
+extern struct ext4_ext_path *ext4_split_convert_extents_test(
+				handle_t *handle, struct inode *inode,
+				struct ext4_map_blocks *map,
+				struct ext4_ext_path *path,
+				int flags, unsigned int *allocated);
+#endif
 #endif /* _EXT4_EXTENTS */
 
fs/ext4/extents-test.c +4 -4
index a6b3e6b592a5..5496b2c8e2cd 100644
@@ -282,8 +282,8 @@ static int extents_kunit_init(struct kunit *test)
 	eh->eh_depth = 0;
 	eh->eh_entries = cpu_to_le16(1);
 	eh->eh_magic = EXT4_EXT_MAGIC;
-	eh->eh_max =
-		cpu_to_le16(ext4_ext_space_root_idx(&k_ctx.k_ei->vfs_inode, 0));
+	eh->eh_max = cpu_to_le16(ext4_ext_space_root_idx_test(
+					&k_ctx.k_ei->vfs_inode, 0));
 	eh->eh_generation = 0;
 
 	/*
@@ -386,8 +386,8 @@ static void test_split_convert(struct kunit *test)
 
 	switch (param->type) {
 	case TEST_SPLIT_CONVERT:
-		path = ext4_split_convert_extents(NULL, inode, &map, path,
-						  param->split_flags, NULL);
+		path = ext4_split_convert_extents_test(NULL, inode, &map,
+					path, param->split_flags, NULL);
 		break;
 	case TEST_CREATE_BLOCKS:
 		ext4_map_create_blocks_helper(test, inode, &map, param->split_flags);
fs/ext4/extents.c +33 -6
index 042e1555a674..5ca90f356c92 100644
@@ -184,9 +184,9 @@ static int ext4_ext_get_access(handle_t *handle, struct inode *inode,
  *  - ENOMEM
  *  - EIO
  */
-static int __ext4_ext_dirty(const char *where, unsigned int line,
-			    handle_t *handle, struct inode *inode,
-			    struct ext4_ext_path *path)
+int __ext4_ext_dirty(const char *where, unsigned int line,
+		     handle_t *handle, struct inode *inode,
+		     struct ext4_ext_path *path)
 {
 	int err;
 
@@ -3144,7 +3144,7 @@ static void ext4_zeroout_es(struct inode *inode, struct ext4_extent *ex)
 }
 
 /* FIXME!! we need to try to merge to left or right after zero-out  */
-static int ext4_ext_zeroout(struct inode *inode, struct ext4_extent *ex)
+int ext4_ext_zeroout(struct inode *inode, struct ext4_extent *ex)
 {
 	ext4_fsblk_t ee_pblock;
 	unsigned int ee_len;
@@ -6238,6 +6238,33 @@ int ext4_ext_clear_bb(struct inode *inode)
 	return 0;
 }
 
-#ifdef CONFIG_EXT4_KUNIT_TESTS
-#include "extents-test.c"
+#if IS_ENABLED(CONFIG_EXT4_KUNIT_TESTS)
+int ext4_ext_space_root_idx_test(struct inode *inode, int check)
+{
+	return ext4_ext_space_root_idx(inode, check);
+}
+EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_ext_space_root_idx_test);
+
+struct ext4_ext_path *ext4_split_convert_extents_test(handle_t *handle,
+			struct inode *inode, struct ext4_map_blocks *map,
+			struct ext4_ext_path *path, int flags,
+			unsigned int *allocated)
+{
+	return ext4_split_convert_extents(handle, inode, map, path,
+					  flags, allocated);
+}
+EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_split_convert_extents_test);
+
+EXPORT_SYMBOL_FOR_EXT4_TEST(__ext4_ext_dirty);
+EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_ext_zeroout);
+EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_register_shrinker);
+EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_unregister_shrinker);
+EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_map_create_blocks);
+EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_init_tree);
+EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_lookup_extent);
+EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_insert_extent);
+EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_ext_insert_extent);
+EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_find_extent);
+EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_issue_zeroout);
+EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_map_query_blocks);
 #endif
Signature · 1 line
2.34.1
reviewer
#4 lore raw
In reply to Ye Bin
Quoted 11 lines · Ye Bin

From: Ye Bin <[email protected]>

This patchset is split out from the "Fix some issues about ext4-test" patchset. It decouples mballoc-test.c and extents-test.c from the ext4 module, resolving the issue where these two tests could not be run when EXT4_KUNIT_TESTS is set to M.

Ye Bin (3):
ext4: introduce EXPORT_SYMBOL_FOR_EXT4_TEST() helper
ext4: fix mballoc-test.c is not compiled when EXT4_KUNIT_TESTS=M
ext4: fix extents-test.c is not compiled when EXT4_KUNIT_TESTS=M

Hi Ye,

So thinking about this a bit more, is there any reason we are not using the VISIBLE_IF_KUNIT and EXPORT_SYMBOL_IF_KUNIT macros directly? Is there any case that they don't handle?

[1] https://docs.kernel.org/dev-tools/kunit/usage.html#testing-static-functions

Quoted 14 lines
 fs/ext4/Makefile       |   5 +-
 fs/ext4/ext4.h         |   5 ++
 fs/ext4/ext4_extents.h |  12 +++++
 fs/ext4/extents-test.c |   8 ++--
 fs/ext4/extents.c      |  39 +++++++++++++---
 fs/ext4/mballoc-test.c |  81 ++++++++++++++++----------------
 fs/ext4/mballoc.c      | 102 +++++++++++++++++++++++++++++++++++++++--
 fs/ext4/mballoc.h      |  30 ++++++++++++
 8 files changed, 227 insertions(+), 55 deletions(-)
Signature · 1 line
2.34.1
#5 lore raw
Quoted 13 lines · Ojaswin Mujoo
Quoted 11 lines · Ye Bin

From: Ye Bin <[email protected]>

This patchset is split out from the "Fix some issues about ext4-test" patchset. It decouples mballoc-test.c and extents-test.c from the ext4 module, resolving the issue where these two tests could not be run when EXT4_KUNIT_TESTS is set to M.

Ye Bin (3):
ext4: introduce EXPORT_SYMBOL_FOR_EXT4_TEST() helper
ext4: fix mballoc-test.c is not compiled when EXT4_KUNIT_TESTS=M
ext4: fix extents-test.c is not compiled when EXT4_KUNIT_TESTS=M

Quoted 6 lines

Hi Ye,

So thinking about this a bit more, is there any reason we are not using the VISIBLE_IF_KUNIT and EXPORT_SYMBOL_IF_KUNIT macros directly? Is there any case that they don't handle?

A limitation of directly using the VISIBLE_IF_KUNIT and EXPORT_SYMBOL_IF_KUNIT macros is that they rely entirely on the CONFIG_KUNIT configuration being enabled. However, enabling CONFIG_KUNIT does not necessarily mean that EXT4_KUNIT_TESTS is enabled. If EXT4_KUNIT_TESTS is not enabled, there is no need to export the symbols.

Quoted 19 lines

[1] https://docs.kernel.org/dev-tools/kunit/usage.html#testing-static-functions

Quoted 11 lines
  fs/ext4/Makefile       |   5 +-
  fs/ext4/ext4.h         |   5 ++
  fs/ext4/ext4_extents.h |  12 +++++
  fs/ext4/extents-test.c |   8 ++--
  fs/ext4/extents.c      |  39 +++++++++++++---
  fs/ext4/mballoc-test.c |  81 ++++++++++++++++----------------
  fs/ext4/mballoc.c      | 102 +++++++++++++++++++++++++++++++++++++++--
  fs/ext4/mballoc.h      |  30 ++++++++++++
  8 files changed, 227 insertions(+), 55 deletions(-)
Quoted 3 lines

--
2.34.1

.

reviewer Reviewed-by on the v2 series
#6 lore raw
In reply to Ye Bin
Quoted 11 lines · Ye Bin

From: Ye Bin <[email protected]>

This patchset is split out from the "Fix some issues about ext4-test" patchset. It decouples mballoc-test.c and extents-test.c from the ext4 module, resolving the issue where these two tests could not be run when EXT4_KUNIT_TESTS is set to M.

Ye Bin (3):
ext4: introduce EXPORT_SYMBOL_FOR_EXT4_TEST() helper
ext4: fix mballoc-test.c is not compiled when EXT4_KUNIT_TESTS=M
ext4: fix extents-test.c is not compiled when EXT4_KUNIT_TESTS=M

Looks good to me. Feel free to add:

Honza

Quoted 14 lines
 fs/ext4/Makefile       |   5 +-
 fs/ext4/ext4.h         |   5 ++
 fs/ext4/ext4_extents.h |  12 +++++
 fs/ext4/extents-test.c |   8 ++--
 fs/ext4/extents.c      |  39 +++++++++++++---
 fs/ext4/mballoc-test.c |  81 ++++++++++++++++----------------
 fs/ext4/mballoc.c      | 102 +++++++++++++++++++++++++++++++++++++++--
 fs/ext4/mballoc.h      |  30 ++++++++++++
 8 files changed, 227 insertions(+), 55 deletions(-)
Signature · 1 line
2.34.1
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
maintainer Applied
#7 lore raw
In reply to Ye Bin
Quoted 11 lines · Ye Bin

This patchset is split out from the "Fix some issues about ext4-test" patchset. It decouples mballoc-test.c and extents-test.c from the ext4 module, resolving the issue where these two tests could not be run when EXT4_KUNIT_TESTS is set to M.

Ye Bin (3):
ext4: introduce EXPORT_SYMBOL_FOR_EXT4_TEST() helper
ext4: fix mballoc-test.c is not compiled when EXT4_KUNIT_TESTS=M
ext4: fix extents-test.c is not compiled when EXT4_KUNIT_TESTS=M

[...]

Applied, thanks!

[1/3] ext4: introduce EXPORT_SYMBOL_FOR_EXT4_TEST() helper

      commit: 49504a512587147dd6da3b4b08832ccc157b97dc
[2/3] ext4: fix mballoc-test.c is not compiled when EXT4_KUNIT_TESTS=M
      commit: 519b76ac0b31d86b45784735d4ef964e8efdc56b
[3/3] ext4: fix extents-test.c is not compiled when EXT4_KUNIT_TESTS=M
      commit: 9e1b14320b154094bb2c1bee6d8c6cb851fc3215

Best regards,

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