Commit dc11dd5d authored by Josef Bacik's avatar Josef Bacik Committed by Chris Mason

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,
Signed-off-by: default avatarJosef Bacik <jbacik@fusionio.com>
Signed-off-by: default avatarChris Mason <chris.mason@fusionio.com>
parent 00361589
...@@ -12,3 +12,5 @@ btrfs-y += super.o ctree.o extent-tree.o print-tree.o root-tree.o dir-item.o \ ...@@ -12,3 +12,5 @@ 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_POSIX_ACL) += acl.o
btrfs-$(CONFIG_BTRFS_FS_CHECK_INTEGRITY) += check-integrity.o btrfs-$(CONFIG_BTRFS_FS_CHECK_INTEGRITY) += check-integrity.o
btrfs-$(CONFIG_BTRFS_FS_RUN_SANITY_TESTS) += tests/free-space-tests.o
This diff is collapsed.
...@@ -112,6 +112,12 @@ int btrfs_return_cluster_to_free_space( ...@@ -112,6 +112,12 @@ int btrfs_return_cluster_to_free_space(
int btrfs_trim_block_group(struct btrfs_block_group_cache *block_group, int btrfs_trim_block_group(struct btrfs_block_group_cache *block_group,
u64 *trimmed, u64 start, u64 end, u64 minlen); 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 #endif
...@@ -56,6 +56,7 @@ ...@@ -56,6 +56,7 @@
#include "rcu-string.h" #include "rcu-string.h"
#include "dev-replace.h" #include "dev-replace.h"
#include "free-space-cache.h" #include "free-space-cache.h"
#include "tests/btrfs-tests.h"
#define CREATE_TRACE_POINTS #define CREATE_TRACE_POINTS
#include <trace/events/btrfs.h> #include <trace/events/btrfs.h>
...@@ -1762,6 +1763,11 @@ static void btrfs_print_info(void) ...@@ -1762,6 +1763,11 @@ static void btrfs_print_info(void)
"\n"); "\n");
} }
static int btrfs_run_sanity_tests(void)
{
return btrfs_test_free_space_cache();
}
static int __init init_btrfs_fs(void) static int __init init_btrfs_fs(void)
{ {
int err; int err;
...@@ -1804,14 +1810,17 @@ static int __init init_btrfs_fs(void) ...@@ -1804,14 +1810,17 @@ static int __init init_btrfs_fs(void)
if (err) if (err)
goto free_delayed_ref; goto free_delayed_ref;
err = register_filesystem(&btrfs_fs_type);
if (err)
goto unregister_ioctl;
btrfs_init_lockdep(); btrfs_init_lockdep();
btrfs_print_info(); btrfs_print_info();
btrfs_test_free_space_cache();
err = btrfs_run_sanity_tests();
if (err)
goto unregister_ioctl;
err = register_filesystem(&btrfs_fs_type);
if (err)
goto unregister_ioctl;
return 0; return 0;
......
/*
* Copyright (C) 2013 Fusion IO. All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License v2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 021110-1307, USA.
*/
#ifndef __BTRFS_TESTS
#define __BTRFS_TESTS
#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
#define test_msg(fmt, ...) pr_info("btrfs: selftest: " fmt, ##__VA_ARGS__)
int btrfs_test_free_space_cache(void);
#else
static inline int btrfs_test_free_space_cache(void)
{
return 0;
}
#endif
#endif
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment