Btrfs: separate out tests into their own directory
PATCH 1/1 Btrfs: separate out tests into their own directory
The plan is to have a bunch of unit tests that run when btrfs is loaded when you build with the appropriate config option. My ultimate goal is to have a test for every non-static function we have, but at first I'm going to focus on the things that cause us the most problems. To start out with this just adds a tests/ directory and moves the existing free space cache tests into that directory and sets up all of the infrastructure. Thanks,
--- fs/btrfs/Makefile | 3 + fs/btrfs/free-space-cache.c | 488 +++++-------------------------------- fs/btrfs/free-space-cache.h | 8 +- fs/btrfs/super.c | 13 +- fs/btrfs/tests/Makefile | 3 + fs/btrfs/tests/btrfs-tests.h | 13 + fs/btrfs/tests/free-space-tests.c | 378 ++++++++++++++++++++++++++++ 7 files changed, 474 insertions(+), 432 deletions(-) create mode 100644 fs/btrfs/tests/Makefile create mode 100644 fs/btrfs/tests/btrfs-tests.h create mode 100644 fs/btrfs/tests/free-space-tests.c
fs/btrfs/Makefile +3 -0
@@ -12,3 +12,6 @@ btrfs-y += super.o ctree.o extent-tree.o print-tree.o root-tree.o dir-item.o \ btrfs-$(CONFIG_BTRFS_FS_POSIX_ACL) += acl.o btrfs-$(CONFIG_BTRFS_FS_CHECK_INTEGRITY) += check-integrity.o + +obj-$(CONFIG_BTRFS_FS_RUN_SANITY_TESTS) := tests/ +btrfs-$(CONFIG_BTRFS_FS_RUN_SANITY_TESTS) += tests/btrfs-tests.o
fs/btrfs/free-space-cache.c +58 -430
510 lines not on this page · raw message
fs/btrfs/free-space-cache.h +7 -1
@@ -112,6 +112,12 @@ int btrfs_return_cluster_to_free_space(int btrfs_trim_block_group (struct btrfs_block_group_cache *block_group,u64 *trimmed,u64 start,u64 end,u64 minlen); -void btrfs_test_free_space_cache (void ); +/* Support functions for runnint our sanity tests */ +#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS +int test_add_free_space_entry (struct btrfs_block_group_cache *cache, +u64 offset,u64 bytes,bool bitmap); +int test_check_exists (struct btrfs_block_group_cache *cache, +u64 offset,u64 bytes); +#endif #endif
fs/btrfs/super.c +12 -1
@@ -57,6 +57,10 @@#include "dev-replace.h" #include "free-space-cache.h" +#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS +#include "tests/btrfs-tests.h" +#endif +#define CREATE_TRACE_POINTS #include <trace/events/btrfs.h>
@@ -1762,6 +1766,11 @@ static void btrfs_print_info(void) "\n"); } +static int btrfs_run_sanity_tests (void ) +{ +return btrfs_test_free_space_cache (); +} +static int __init init_btrfs_fs (void ) {int err;
@@ -1811,8 +1820,10 @@ static int __init init_btrfs_fs(void)btrfs_init_lockdep ();btrfs_print_info (); -btrfs_test_free_space_cache (); + err =btrfs_run_sanity_tests (); +if (err) + goto unregister_ioctl;return 0 ; unregister_ioctl:
fs/btrfs/tests/Makefile new file +3 -0
@@ -0,0 +1,3 @@ +obj-$(CONFIG_BTRFS_FS_RUN_SANITY_TESTS) += btrfs-tests.o + +btrfs-tests-y += free-space-tests.o
fs/btrfs/tests/btrfs-tests.h new file +13 -0
@@ -0,0 +1,13 @@ +#ifndef __BTRFS_TESTS +#define __BTRFS_TESTS + +#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS +int btrfs_test_free_space_cache (void ); +#else +static inline int btrfs_test_free_space_cache (void ) +{ +return 0 ; +} +#endif + +#endif
fs/btrfs/tests/free-space-tests.c new file +378 -0
378 lines not on this page · raw message
Signature · 1 line
1.7.7.6
Quoted 8 lines · Josef Bacik
The plan is to have a bunch of unit tests that run when btrfs is loaded when you build with the appropriate config option. My ultimate goal is to have a test for every non-static function we have, but at first I'm going to focus on the things that cause us the most problems. To start out with this just adds a tests/ directory and moves the existing free space cache tests into that directory and sets up all of the infrastructure. Thanks,
Signed-off-by Josef Bacik <[email protected]>
Josef this seems to have broke compilation when sanity checks are not enabled. The following patch fixes it for me at least. Thanks.
Quoted 1 line
From
d35b256737dd53245c223692a4c16165a0196a5eMon Sep 17 00:00:00 2001
From: Filipe David Borba Manana <[email protected]>
Date: Thu, 15 Aug 2013 01:19:53 +0100
Subject: [PATCH] Btrfs: fix compilation when sanity tests aren't enabled
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Error was:
CC [M] fs/btrfs/super.o CC [M] fs/btrfs/ctree.o CC [M] fs/btrfs/extent-tree.o CC [M] fs/btrfs/print-tree.o
fs/btrfs/super.c: In function ‘btrfs_run_sanity_tests’:fs/btrfs/super.c:1771:2: error: implicit declaration of function ‘btrfs_test_free_space_cache’ [-Werror=implicit-function-declaration]
cc1: some warnings being treated as errors
make[2]: *** [fs/btrfs/super.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [fs/btrfs] Error 2
make[1]: *** Waiting for unfinished jobs....
make: *** [fs] Error 2
make: *** Waiting for unfinished jobs....
--- fs/btrfs/super.c | 2 -- 1 file changed, 2 deletions(-)
fs/btrfs/super.c +0 -2
@@ -57,9 +57,7 @@#include "dev-replace.h" #include "free-space-cache.h" -#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS #include "tests/btrfs-tests.h" -#endif #define CREATE_TRACE_POINTS #include <trace/events/btrfs.h>
Signature · 1 line
1.7.9.5
Quoted 8 lines · Filipe David Manana
Quoted 7 lines · Josef Bacik
The plan is to have a bunch of unit tests that run when btrfs is loaded when you build with the appropriate config option. My ultimate goal is to have a test for every non-static function we have, but at first I'm going to focus on the things that cause us the most problems. To start out with this just adds a tests/ directory and moves the existing free space cache tests into that directory and sets up all of the infrastructure. Thanks,
Quoted 5 lines
Quoted 1 line
Signed-off-by Josef Bacik <[email protected]>Josef this seems to have broke compilation when sanity checks are not enabled. The following patch fixes it for me at least. Thanks.
Weird that's what I committed but not what I sent to the list, sorry about that. Thanks,
Josef
Quoted 9 lines · Josef Bacik
Quoted 8 lines · Filipe David Manana
Quoted 7 lines · Josef Bacik
The plan is to have a bunch of unit tests that run when btrfs is loaded when you build with the appropriate config option. My ultimate goal is to have a test for every non-static function we have, but at first I'm going to focus on the things that cause us the most problems. To start out with this just adds a tests/ directory and moves the existing free space cache tests into that directory and sets up all of the infrastructure. Thanks,
Quoted 9 lines
Quoted 5 lines
Quoted 1 line
Signed-off-by Josef Bacik <[email protected]>Josef this seems to have broke compilation when sanity checks are not enabled. The following patch fixes it for me at least. Thanks.
Weird that's what I committed but not what I sent to the list, sorry about that. Thanks,
Oh I see, I didn't actually commit it, oops.
Josef