[5/5] ext4: Add unit test for ext4_mb_mark_diskspace_used
Commit Message
Add unit test for ext4_mb_mark_diskspace_used
Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
---
fs/ext4/mballoc-test.c | 54 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 54 insertions(+)
Comments
Hi Kemeng,
kernel test robot noticed the following build warnings:
[auto build test WARNING on tytso-ext4/dev]
[also build test WARNING on linus/master v6.7-rc2 next-20231124]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Kemeng-Shi/ext4-Add-unit-test-for-test_free_blocks_simple/20231125-154444
base: https://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4.git dev
patch link: https://lore.kernel.org/r/20231125154144.3943442-6-shikemeng%40huaweicloud.com
patch subject: [PATCH 5/5] ext4: Add unit test for ext4_mb_mark_diskspace_used
config: i386-buildonly-randconfig-004-20231125 (https://download.01.org/0day-ci/archive/20231125/202311252009.Z6vrLAjg-lkp@intel.com/config)
compiler: gcc-11 (Debian 11.3.0-12) 11.3.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231125/202311252009.Z6vrLAjg-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202311252009.Z6vrLAjg-lkp@intel.com/
All warnings (new ones prefixed by >>):
In file included from fs/ext4/mballoc.c:6996:
fs/ext4/mballoc-test.c: In function 'test_mark_diskspace_used':
>> fs/ext4/mballoc-test.c:510:23: warning: variable 'max' set but not used [-Wunused-but-set-variable]
510 | ext4_grpblk_t max;
| ^~~
vim +/max +510 fs/ext4/mballoc-test.c
505
506 static void test_mark_diskspace_used(struct kunit *test)
507 {
508 struct super_block *sb = (struct super_block *)test->priv;
509 struct inode inode = { .i_sb = sb, };
> 510 ext4_grpblk_t max;
511 struct ext4_allocation_context ac;
512 struct test_range ranges[TEST_RANGE_COUNT];
513 int i;
514
515 mbt_generate_test_ranges(sb, ranges, TEST_RANGE_COUNT);
516
517 ac.ac_status = AC_STATUS_FOUND;
518 ac.ac_sb = sb;
519 ac.ac_inode = &inode;
520 max = EXT4_CLUSTERS_PER_GROUP(sb);
521 for (i = 0; i < TEST_RANGE_COUNT; i++)
522 test_mark_diskspace_used_range(test, &ac, ranges[i].start,
523 ranges[i].len);
524 }
525
Hi Kemeng,
kernel test robot noticed the following build warnings:
[auto build test WARNING on tytso-ext4/dev]
[also build test WARNING on linus/master v6.7-rc2 next-20231124]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Kemeng-Shi/ext4-Add-unit-test-for-test_free_blocks_simple/20231125-154444
base: https://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4.git dev
patch link: https://lore.kernel.org/r/20231125154144.3943442-6-shikemeng%40huaweicloud.com
patch subject: [PATCH 5/5] ext4: Add unit test for ext4_mb_mark_diskspace_used
config: i386-allyesconfig (https://download.01.org/0day-ci/archive/20231126/202311260042.kMxL6DnL-lkp@intel.com/config)
compiler: clang version 16.0.4 (https://github.com/llvm/llvm-project.git ae42196bc493ffe877a7e3dff8be32035dea4d07)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231126/202311260042.kMxL6DnL-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202311260042.kMxL6DnL-lkp@intel.com/
All warnings (new ones prefixed by >>):
In file included from fs/ext4/mballoc.c:6996:
fs/ext4/mballoc-test.c:510:16: warning: variable 'max' set but not used [-Wunused-but-set-variable]
ext4_grpblk_t max;
^
>> fs/ext4/mballoc-test.c:506:13: warning: stack frame size (1036) exceeds limit (1024) in 'test_mark_diskspace_used' [-Wframe-larger-than]
static void test_mark_diskspace_used(struct kunit *test)
^
39/1036 (3.76%) spills, 997/1036 (96.24%) variables
2 warnings generated.
vim +/test_mark_diskspace_used +506 fs/ext4/mballoc-test.c
505
> 506 static void test_mark_diskspace_used(struct kunit *test)
507 {
508 struct super_block *sb = (struct super_block *)test->priv;
509 struct inode inode = { .i_sb = sb, };
510 ext4_grpblk_t max;
511 struct ext4_allocation_context ac;
512 struct test_range ranges[TEST_RANGE_COUNT];
513 int i;
514
515 mbt_generate_test_ranges(sb, ranges, TEST_RANGE_COUNT);
516
517 ac.ac_status = AC_STATUS_FOUND;
518 ac.ac_sb = sb;
519 ac.ac_inode = &inode;
520 max = EXT4_CLUSTERS_PER_GROUP(sb);
521 for (i = 0; i < TEST_RANGE_COUNT; i++)
522 test_mark_diskspace_used_range(test, &ac, ranges[i].start,
523 ranges[i].len);
524 }
525
@@ -470,6 +470,59 @@ static void test_free_blocks_simple(struct kunit *test)
ranges[i].start, ranges[i].len);
}
+static void
+test_mark_diskspace_used_range(struct kunit *test,
+ struct ext4_allocation_context *ac,
+ ext4_grpblk_t start,
+ ext4_grpblk_t len)
+{
+ struct super_block *sb = (struct super_block *)test->priv;
+ int ret;
+ void *bitmap;
+ ext4_grpblk_t i, max;
+
+ /* ext4_mb_mark_diskspace_used will BUG if len is 0 */
+ if (len == 0)
+ return;
+
+ ac->ac_b_ex.fe_group = TEST_GOAL_GROUP;
+ ac->ac_b_ex.fe_start = start;
+ ac->ac_b_ex.fe_len = len;
+
+ bitmap = mbt_ctx_bitmap(sb, TEST_GOAL_GROUP);
+ memset(bitmap, 0, sb->s_blocksize);
+ ret = ext4_mb_mark_diskspace_used(ac, NULL, 0);
+ KUNIT_ASSERT_EQ(test, ret, 0);
+
+ max = EXT4_CLUSTERS_PER_GROUP(sb);
+ i = mb_find_next_bit(bitmap, max, 0);
+ KUNIT_ASSERT_EQ(test, i, start);
+ i = mb_find_next_zero_bit(bitmap, max, i + 1);
+ KUNIT_ASSERT_EQ(test, i, start + len);
+ i = mb_find_next_bit(bitmap, max, i + 1);
+ KUNIT_ASSERT_EQ(test, max, i);
+}
+
+static void test_mark_diskspace_used(struct kunit *test)
+{
+ struct super_block *sb = (struct super_block *)test->priv;
+ struct inode inode = { .i_sb = sb, };
+ ext4_grpblk_t max;
+ struct ext4_allocation_context ac;
+ struct test_range ranges[TEST_RANGE_COUNT];
+ int i;
+
+ mbt_generate_test_ranges(sb, ranges, TEST_RANGE_COUNT);
+
+ ac.ac_status = AC_STATUS_FOUND;
+ ac.ac_sb = sb;
+ ac.ac_inode = &inode;
+ max = EXT4_CLUSTERS_PER_GROUP(sb);
+ for (i = 0; i < TEST_RANGE_COUNT; i++)
+ test_mark_diskspace_used_range(test, &ac, ranges[i].start,
+ ranges[i].len);
+}
+
static void mbt_generate_buddy(struct super_block *sb, void *buddy,
void *bitmap, struct ext4_group_info *grp)
{
@@ -784,6 +837,7 @@ static struct kunit_case mbt_test_cases[] = {
KUNIT_CASE_PARAM(test_mb_generate_buddy, mbt_layouts_gen_params),
KUNIT_CASE_PARAM(test_mb_mark_used, mbt_layouts_gen_params),
KUNIT_CASE_PARAM(test_mb_free_blocks, mbt_layouts_gen_params),
+ KUNIT_CASE_PARAM(test_mark_diskspace_used, mbt_layouts_gen_params),
{}
};