Skip to content

Commit 5341c98

Browse files
boryaskdave
authored andcommitted
btrfs: tests: add unit tests for pending extent walking functions
I ran into another sort of trivial bug in v1 of the patch and concluded that these functions really ought to be unit tested. These two functions form the core of searching the chunk allocation pending extent bitmap and have relatively easily definable semantics, so unit testing them can help ensure the correctness of chunk allocation. I also made a minor unrelated fix in volumes.h to properly forward declare btrfs_space_info. Because of the order of the includes in the new test, this was actually hitting a latent build warning. Note: This is an early example for me of a commit authored in part by an AI agent, so I wanted to more clear about what I did. I defined a trivial test and explained the set of tests I wanted to the agent and it produced the large set of test cases seen here. I then checked each test case to make sure it matched the description and simplified the constants and numbers until they looked reasonable to me. I then checked the looping logic to make sure it made sense to the original spirit of the trivial test. Finally, carefully combed over all the lines it wrote to loop over the tests it generated to make sure they followed our code style guide. Assisted-by: Claude:claude-opus-4-5 Signed-off-by: Boris Burkov <boris@bur.io> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent b14c5e0 commit 5341c98

6 files changed

Lines changed: 495 additions & 8 deletions

File tree

fs/btrfs/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,5 @@ btrfs-$(CONFIG_BTRFS_FS_RUN_SANITY_TESTS) += tests/free-space-tests.o \
4444
tests/extent-buffer-tests.o tests/btrfs-tests.o \
4545
tests/extent-io-tests.o tests/inode-tests.o tests/qgroup-tests.o \
4646
tests/free-space-tree-tests.o tests/extent-map-tests.o \
47-
tests/raid-stripe-tree-tests.o tests/delayed-refs-tests.o
47+
tests/raid-stripe-tree-tests.o tests/delayed-refs-tests.o \
48+
tests/chunk-allocation-tests.o

fs/btrfs/tests/btrfs-tests.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,9 @@ int btrfs_run_sanity_tests(void)
301301
ret = btrfs_test_delayed_refs(sectorsize, nodesize);
302302
if (ret)
303303
goto out;
304+
ret = btrfs_test_chunk_allocation(sectorsize, nodesize);
305+
if (ret)
306+
goto out;
304307
}
305308
}
306309
ret = btrfs_test_extent_map();

fs/btrfs/tests/btrfs-tests.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ int btrfs_test_free_space_tree(u32 sectorsize, u32 nodesize);
4545
int btrfs_test_raid_stripe_tree(u32 sectorsize, u32 nodesize);
4646
int btrfs_test_extent_map(void);
4747
int btrfs_test_delayed_refs(u32 sectorsize, u32 nodesize);
48+
int btrfs_test_chunk_allocation(u32 sectorsize, u32 nodesize);
4849
struct inode *btrfs_new_test_inode(void);
4950
struct btrfs_fs_info *btrfs_alloc_dummy_fs_info(u32 nodesize, u32 sectorsize);
5051
void btrfs_free_dummy_fs_info(struct btrfs_fs_info *fs_info);

0 commit comments

Comments
 (0)