Skip to contentSkip to conversation

Self test cleanups, error handling fixes

PATCH New David Sterba 1 participant 23 messages Mar 18, 2019 Btrfs file system

lore
Share & tools
lore

David Sterba

author maintainer
#0 lore raw

cover Self test cleanups, error handling fixes

Add missing error handling, unify test structure and error messages.

David Sterba (22):
btrfs: tests: handle fs_info allocation failure in extent_io tests
btrfs: tests: don't leak fs_info in extent_io bitmap tests
btrfs: tests: print file:line for error messages
btrfs: tests: add table of most common errors
btrfs: tests: use standard error message after fs_info allocation
failure
btrfs: tests: use standard error message after root allocation failure
btrfs: tests: use standard error message after extent buffer
allocation failure
btrfs: tests: use standard error message after path allocation failure
btrfs: tests: use standard error message after inode allocation
failure
btrfs: tests: use standard error message after block group allocation
failure
btrfs: tests: properly initialize fs_info of extent buffer
btrfs: tests: return errors from extent map tests
btrfs: tests: return errors from extent map test case 1
btrfs: tests: return errors from extent map test case 2
btrfs: tests: return errors from extent map test case 3
btrfs: tests: return errors from extent map test case 4
btrfs: tests: return error from all extent map test cases
btrfs: tests: use standard error message after extent map allocation
failure
btrfs: tests: use SZ_ constants everywhere
btrfs: tests: fix comments about tested extent map ranges
btrfs: tests: drop messages when some tests finish
btrfs: tests: unify messages when tests start

 fs/btrfs/tests/btrfs-tests.c           |  10 ++
 fs/btrfs/tests/btrfs-tests.h           |  17 +-
 fs/btrfs/tests/extent-buffer-tests.c   |   8 +-
 fs/btrfs/tests/extent-io-tests.c       |  29 ++--
 fs/btrfs/tests/extent-map-tests.c      | 213 +++++++++++++++++--------
 fs/btrfs/tests/free-space-tests.c      |  11 +-
 fs/btrfs/tests/free-space-tree-tests.c |  10 +-
 fs/btrfs/tests/inode-tests.c           |  33 ++--
 fs/btrfs/tests/qgroup-tests.c          |  20 +--
 9 files changed, 237 insertions(+), 114 deletions(-)
Signature · 1 line
2.21.0
author maintainer
#1 lore raw

PATCH 1/22 btrfs: tests: handle fs_info allocation failure in extent_io tests

---
 fs/btrfs/tests/extent-io-tests.c | 4 ++++
 1 file changed, 4 insertions(+)
fs/btrfs/tests/extent-io-tests.c +4 -0
index 3c46d7f23456..c444243f3fdd 100644
@@ -388,6 +388,10 @@ static int test_eb_bitmaps(u32 sectorsize, u32 nodesize)
 		? sectorsize * 4 : sectorsize;
 
 	fs_info = btrfs_alloc_dummy_fs_info(len, len);
+	if (!fs_info) {
+		test_err("could not allocate fs_info");
+		return -ENOMEM;
+	}
 
 	bitmap = kmalloc(len, GFP_KERNEL);
 	if (!bitmap) {
Signature · 1 line
2.21.0
author maintainer
#2 lore raw

PATCH 2/22 btrfs: tests: don't leak fs_info in extent_io bitmap tests

In reply to David Sterba

The fs_info is not freed at the end of the function and leaks. The function is called twice so there can be up to 2x sizeof(struct btrfs_fs_info) of leaked memory. Fortunatelly this affects only testing builds, the size could be 16k with several debugging features enabled.

---
 fs/btrfs/tests/extent-io-tests.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
fs/btrfs/tests/extent-io-tests.c +9 -7
index c444243f3fdd..af3309e51876 100644
@@ -374,8 +374,8 @@ static int test_eb_bitmaps(u32 sectorsize, u32 nodesize)
 {
 	struct btrfs_fs_info *fs_info;
 	unsigned long len;
-	unsigned long *bitmap;
-	struct extent_buffer *eb;
+	unsigned long *bitmap = NULL;
+	struct extent_buffer *eb = NULL;
 	int ret;
 
 	test_msg("running extent buffer bitmap tests");
@@ -396,14 +396,15 @@ static int test_eb_bitmaps(u32 sectorsize, u32 nodesize)
 	bitmap = kmalloc(len, GFP_KERNEL);
 	if (!bitmap) {
 		test_err("couldn't allocate test bitmap");
-		return -ENOMEM;
+		ret = -ENOMEM;
+		goto out;
 	}
 
 	eb = __alloc_dummy_extent_buffer(fs_info, 0, len);
 	if (!eb) {
 		test_err("couldn't allocate test extent buffer");
-		kfree(bitmap);
-		return -ENOMEM;
+		ret = -ENOMEM;
+		goto out;
 	}
 
 	ret = __test_eb_bitmaps(bitmap, eb, len);
@@ -415,14 +416,15 @@ static int test_eb_bitmaps(u32 sectorsize, u32 nodesize)
 	eb = __alloc_dummy_extent_buffer(NULL, nodesize / 2, len);
 	if (!eb) {
 		test_err("couldn't allocate test extent buffer");
-		kfree(bitmap);
-		return -ENOMEM;
+		ret = -ENOMEM;
+		goto out;
 	}
 
 	ret = __test_eb_bitmaps(bitmap, eb, len);
 out:
 	free_extent_buffer(eb);
 	kfree(bitmap);
+	btrfs_free_dummy_fs_info(fs_info);
 	return ret;
 }
 
Signature · 1 line
2.21.0
author maintainer
#3 lore raw

PATCH 3/22 btrfs: tests: print file:line for error messages

In reply to David Sterba

For better diagnostics print the file name and line to locate the errors. Sample output:

[    9.052924] BTRFS: selftest: fs/btrfs/tests/extent-io-tests.c:283 offset bits do not match
---
 fs/btrfs/tests/btrfs-tests.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/btrfs/tests/btrfs-tests.h +2 -1
index 70ff9f9d86a1..bb9e9c234535 100644
@@ -10,7 +10,8 @@
 int btrfs_run_sanity_tests(void);
 
 #define test_msg(fmt, ...) pr_info("BTRFS: selftest: " fmt "\n", ##__VA_ARGS__)
-#define test_err(fmt, ...) pr_err("BTRFS: selftest: " fmt "\n", ##__VA_ARGS__)
+#define test_err(fmt, ...) pr_err("BTRFS: selftest: %s:%d " fmt "\n",	\
+		__FILE__, __LINE__, ##__VA_ARGS__)
 
 struct btrfs_root;
 struct btrfs_trans_handle;
Signature · 1 line
2.21.0
author maintainer
#4 lore raw

PATCH 4/22 btrfs: tests: add table of most common errors

In reply to David Sterba

Allocation of main objects like fs_info or extent buffers is in each test so let's simplify and unify the error messages to a table and add a convenience helper.

---
 fs/btrfs/tests/btrfs-tests.c | 10 ++++++++++
 fs/btrfs/tests/btrfs-tests.h | 14 ++++++++++++++
 2 files changed, 24 insertions(+)
fs/btrfs/tests/btrfs-tests.c +10 -0
index 8a59597f1883..7c667aa5425f 100644
@@ -17,6 +17,16 @@
 
 static struct vfsmount *test_mnt = NULL;
 
+const char *test_error[] = {
+	[TEST_ALLOC_FS_INFO]	     = "cannot allocate fs_info",
+	[TEST_ALLOC_ROOT]	     = "cannot allocate root",
+	[TEST_ALLOC_EXTENT_BUFFER]   = "cannot extent buffer",
+	[TEST_ALLOC_PATH]	     = "cannot allocate path",
+	[TEST_ALLOC_INODE]	     = "cannot allocate inode",
+	[TEST_ALLOC_BLOCK_GROUP]     = "cannot allocate block group",
+	[TEST_ALLOC_EXTENT_MAP]      = "cannot allocate extent map",
+};
+
 static const struct super_operations btrfs_test_super_ops = {
 	.alloc_inode	= btrfs_alloc_inode,
 	.destroy_inode	= btrfs_test_destroy_inode,
fs/btrfs/tests/btrfs-tests.h +14 -0
index bb9e9c234535..ee277bbd939b 100644
@@ -13,6 +13,20 @@ int btrfs_run_sanity_tests(void);
 #define test_err(fmt, ...) pr_err("BTRFS: selftest: %s:%d " fmt "\n",	\
 		__FILE__, __LINE__, ##__VA_ARGS__)
 
+#define test_std_err(index)	test_err("%s", test_error[index])
+
+enum {
+	TEST_ALLOC_FS_INFO,
+	TEST_ALLOC_ROOT,
+	TEST_ALLOC_EXTENT_BUFFER,
+	TEST_ALLOC_PATH,
+	TEST_ALLOC_INODE,
+	TEST_ALLOC_BLOCK_GROUP,
+	TEST_ALLOC_EXTENT_MAP,
+};
+
+extern const char *test_error[];
+
 struct btrfs_root;
 struct btrfs_trans_handle;
 
Signature · 1 line
2.21.0
author maintainer
#5 lore raw

PATCH 5/22 btrfs: tests: use standard error message after fs_info allocation failure

In reply to David Sterba
---
 fs/btrfs/tests/extent-buffer-tests.c   | 2 +-
 fs/btrfs/tests/extent-io-tests.c       | 2 +-
 fs/btrfs/tests/extent-map-tests.c      | 2 +-
 fs/btrfs/tests/free-space-tests.c      | 5 +++--
 fs/btrfs/tests/free-space-tree-tests.c | 2 +-
 fs/btrfs/tests/inode-tests.c           | 6 +++---
 fs/btrfs/tests/qgroup-tests.c          | 2 +-
 7 files changed, 11 insertions(+), 10 deletions(-)
fs/btrfs/tests/extent-buffer-tests.c +1 -1
index 7d72eab6d32c..74c7975882d1 100644
@@ -30,7 +30,7 @@ static int test_btrfs_split_item(u32 sectorsize, u32 nodesize)
 
 	fs_info = btrfs_alloc_dummy_fs_info(nodesize, sectorsize);
 	if (!fs_info) {
-		test_err("could not allocate fs_info");
+		test_std_err(TEST_ALLOC_FS_INFO);
 		return -ENOMEM;
 	}
 
fs/btrfs/tests/extent-io-tests.c +1 -1
index af3309e51876..52f30c8738e5 100644
@@ -389,7 +389,7 @@ static int test_eb_bitmaps(u32 sectorsize, u32 nodesize)
 
 	fs_info = btrfs_alloc_dummy_fs_info(len, len);
 	if (!fs_info) {
-		test_err("could not allocate fs_info");
+		test_std_err(TEST_ALLOC_FS_INFO);
 		return -ENOMEM;
 	}
 
fs/btrfs/tests/extent-map-tests.c +1 -1
index bf15d3a7f20e..662b718506b9 100644
@@ -349,7 +349,7 @@ int btrfs_test_extent_map(void)
 	 */
 	fs_info = btrfs_alloc_dummy_fs_info(PAGE_SIZE, PAGE_SIZE);
 	if (!fs_info) {
-		test_msg("Couldn't allocate dummy fs info");
+		test_std_err(TEST_ALLOC_FS_INFO);
 		return -ENOMEM;
 	}
 
fs/btrfs/tests/free-space-tests.c +3 -2
index 5c2f77e9439b..2051e1a19104 100644
@@ -834,9 +834,10 @@ int btrfs_test_free_space_cache(u32 sectorsize, u32 nodesize)
 
 	test_msg("running btrfs free space cache tests");
 	fs_info = btrfs_alloc_dummy_fs_info(nodesize, sectorsize);
-	if (!fs_info)
+	if (!fs_info) {
+		test_std_err(TEST_ALLOC_FS_INFO);
 		return -ENOMEM;
-
+	}
 
 	/*
 	 * For ppc64 (with 64k page size), bytes per bitmap might be
fs/btrfs/tests/free-space-tree-tests.c +1 -1
index 89346da890cf..49fbf73c7f2b 100644
@@ -444,7 +444,7 @@ static int run_test(test_func_t test_func, int bitmaps, u32 sectorsize,
 
 	fs_info = btrfs_alloc_dummy_fs_info(nodesize, sectorsize);
 	if (!fs_info) {
-		test_err("couldn't allocate dummy fs info");
+		test_std_err(TEST_ALLOC_FS_INFO);
 		ret = -ENOMEM;
 		goto out;
 	}
fs/btrfs/tests/inode-tests.c +3 -3
index af0c8e30d9e2..510365370d81 100644
@@ -238,7 +238,7 @@ static noinline int test_btrfs_get_extent(u32 sectorsize, u32 nodesize)
 
 	fs_info = btrfs_alloc_dummy_fs_info(nodesize, sectorsize);
 	if (!fs_info) {
-		test_err("couldn't allocate dummy fs info");
+		test_std_err(TEST_ALLOC_FS_INFO);
 		goto out;
 	}
 
@@ -839,7 +839,7 @@ static int test_hole_first(u32 sectorsize, u32 nodesize)
 
 	fs_info = btrfs_alloc_dummy_fs_info(nodesize, sectorsize);
 	if (!fs_info) {
-		test_err("couldn't allocate dummy fs info");
+		test_std_err(TEST_ALLOC_FS_INFO);
 		goto out;
 	}
 
@@ -935,7 +935,7 @@ static int test_extent_accounting(u32 sectorsize, u32 nodesize)
 
 	fs_info = btrfs_alloc_dummy_fs_info(nodesize, sectorsize);
 	if (!fs_info) {
-		test_err("couldn't allocate dummy fs info");
+		test_std_err(TEST_ALLOC_FS_INFO);
 		goto out;
 	}
 
fs/btrfs/tests/qgroup-tests.c +1 -1
index 412b910b04cc..c620f68462be 100644
@@ -457,7 +457,7 @@ int btrfs_test_qgroups(u32 sectorsize, u32 nodesize)
 
 	fs_info = btrfs_alloc_dummy_fs_info(nodesize, sectorsize);
 	if (!fs_info) {
-		test_err("couldn't allocate dummy fs info");
+		test_std_err(TEST_ALLOC_FS_INFO);
 		return -ENOMEM;
 	}
 
Signature · 1 line
2.21.0
author maintainer
#6 lore raw

PATCH 6/22 btrfs: tests: use standard error message after root allocation failure

In reply to David Sterba
---
 fs/btrfs/tests/extent-buffer-tests.c   | 2 +-
 fs/btrfs/tests/free-space-tests.c      | 1 +
 fs/btrfs/tests/free-space-tree-tests.c | 2 +-
 fs/btrfs/tests/inode-tests.c           | 6 +++---
 fs/btrfs/tests/qgroup-tests.c          | 6 +++---
 5 files changed, 9 insertions(+), 8 deletions(-)
fs/btrfs/tests/extent-buffer-tests.c +1 -1
index 74c7975882d1..83814b769bde 100644
@@ -36,7 +36,7 @@ static int test_btrfs_split_item(u32 sectorsize, u32 nodesize)
 
 	root = btrfs_alloc_dummy_root(fs_info);
 	if (IS_ERR(root)) {
-		test_err("could not allocate root");
+		test_std_err(TEST_ALLOC_ROOT);
 		ret = PTR_ERR(root);
 		goto out;
 	}
fs/btrfs/tests/free-space-tests.c +1 -0
index 2051e1a19104..8dcdefab1280 100644
@@ -854,6 +854,7 @@ int btrfs_test_free_space_cache(u32 sectorsize, u32 nodesize)
 
 	root = btrfs_alloc_dummy_root(fs_info);
 	if (IS_ERR(root)) {
+		test_std_err(TEST_ALLOC_ROOT);
 		ret = PTR_ERR(root);
 		goto out;
 	}
fs/btrfs/tests/free-space-tree-tests.c +1 -1
index 49fbf73c7f2b..79b5d0c97b7b 100644
@@ -451,7 +451,7 @@ static int run_test(test_func_t test_func, int bitmaps, u32 sectorsize,
 
 	root = btrfs_alloc_dummy_root(fs_info);
 	if (IS_ERR(root)) {
-		test_err("couldn't allocate dummy root");
+		test_std_err(TEST_ALLOC_ROOT);
 		ret = PTR_ERR(root);
 		goto out;
 	}
fs/btrfs/tests/inode-tests.c +3 -3
index 510365370d81..5803f342c47b 100644
@@ -244,7 +244,7 @@ static noinline int test_btrfs_get_extent(u32 sectorsize, u32 nodesize)
 
 	root = btrfs_alloc_dummy_root(fs_info);
 	if (IS_ERR(root)) {
-		test_err("couldn't allocate root");
+		test_std_err(TEST_ALLOC_ROOT);
 		goto out;
 	}
 
@@ -845,7 +845,7 @@ static int test_hole_first(u32 sectorsize, u32 nodesize)
 
 	root = btrfs_alloc_dummy_root(fs_info);
 	if (IS_ERR(root)) {
-		test_err("couldn't allocate root");
+		test_std_err(TEST_ALLOC_ROOT);
 		goto out;
 	}
 
@@ -941,7 +941,7 @@ static int test_extent_accounting(u32 sectorsize, u32 nodesize)
 
 	root = btrfs_alloc_dummy_root(fs_info);
 	if (IS_ERR(root)) {
-		test_err("couldn't allocate root");
+		test_std_err(TEST_ALLOC_ROOT);
 		goto out;
 	}
 
fs/btrfs/tests/qgroup-tests.c +3 -3
index c620f68462be..7e25a3a9f979 100644
@@ -463,7 +463,7 @@ int btrfs_test_qgroups(u32 sectorsize, u32 nodesize)
 
 	root = btrfs_alloc_dummy_root(fs_info);
 	if (IS_ERR(root)) {
-		test_err("couldn't allocate root");
+		test_std_err(TEST_ALLOC_ROOT);
 		ret = PTR_ERR(root);
 		goto out;
 	}
@@ -495,7 +495,7 @@ int btrfs_test_qgroups(u32 sectorsize, u32 nodesize)
 
 	tmp_root = btrfs_alloc_dummy_root(fs_info);
 	if (IS_ERR(tmp_root)) {
-		test_err("couldn't allocate a fs root");
+		test_std_err(TEST_ALLOC_ROOT);
 		ret = PTR_ERR(tmp_root);
 		goto out;
 	}
@@ -510,7 +510,7 @@ int btrfs_test_qgroups(u32 sectorsize, u32 nodesize)
 
 	tmp_root = btrfs_alloc_dummy_root(fs_info);
 	if (IS_ERR(tmp_root)) {
-		test_err("couldn't allocate a fs root");
+		test_std_err(TEST_ALLOC_ROOT);
 		ret = PTR_ERR(tmp_root);
 		goto out;
 	}
Signature · 1 line
2.21.0
author maintainer
#7 lore raw

PATCH 7/22 btrfs: tests: use standard error message after extent buffer allocation failure

In reply to David Sterba
---
 fs/btrfs/tests/extent-buffer-tests.c   | 2 +-
 fs/btrfs/tests/extent-io-tests.c       | 4 ++--
 fs/btrfs/tests/free-space-tree-tests.c | 2 +-
 fs/btrfs/tests/inode-tests.c           | 4 ++--
 4 files changed, 6 insertions(+), 6 deletions(-)
fs/btrfs/tests/extent-buffer-tests.c +1 -1
index 83814b769bde..dc2582554cf0 100644
@@ -50,7 +50,7 @@ static int test_btrfs_split_item(u32 sectorsize, u32 nodesize)
 
 	path->nodes[0] = eb = alloc_dummy_extent_buffer(fs_info, nodesize);
 	if (!eb) {
-		test_err("could not allocate dummy buffer");
+		test_std_err(TEST_ALLOC_EXTENT_BUFFER);
 		ret = -ENOMEM;
 		goto out;
 	}
fs/btrfs/tests/extent-io-tests.c +2 -2
index 52f30c8738e5..cc9e6c88bcc1 100644
@@ -402,7 +402,7 @@ static int test_eb_bitmaps(u32 sectorsize, u32 nodesize)
 
 	eb = __alloc_dummy_extent_buffer(fs_info, 0, len);
 	if (!eb) {
-		test_err("couldn't allocate test extent buffer");
+		test_std_err(TEST_ALLOC_ROOT);
 		ret = -ENOMEM;
 		goto out;
 	}
@@ -415,7 +415,7 @@ static int test_eb_bitmaps(u32 sectorsize, u32 nodesize)
 	free_extent_buffer(eb);
 	eb = __alloc_dummy_extent_buffer(NULL, nodesize / 2, len);
 	if (!eb) {
-		test_err("couldn't allocate test extent buffer");
+		test_std_err(TEST_ALLOC_ROOT);
 		ret = -ENOMEM;
 		goto out;
 	}
fs/btrfs/tests/free-space-tree-tests.c +1 -1
index 79b5d0c97b7b..58fbca92dd0d 100644
@@ -463,7 +463,7 @@ static int run_test(test_func_t test_func, int bitmaps, u32 sectorsize,
 
 	root->node = alloc_test_extent_buffer(root->fs_info, nodesize);
 	if (!root->node) {
-		test_err("couldn't allocate dummy buffer");
+		test_std_err(TEST_ALLOC_EXTENT_BUFFER);
 		ret = -ENOMEM;
 		goto out;
 	}
fs/btrfs/tests/inode-tests.c +2 -2
index 5803f342c47b..e63c128c741c 100644
@@ -250,7 +250,7 @@ static noinline int test_btrfs_get_extent(u32 sectorsize, u32 nodesize)
 
 	root->node = alloc_dummy_extent_buffer(fs_info, nodesize);
 	if (!root->node) {
-		test_err("couldn't allocate dummy buffer");
+		test_std_err(TEST_ALLOC_ROOT);
 		goto out;
 	}
 
@@ -851,7 +851,7 @@ static int test_hole_first(u32 sectorsize, u32 nodesize)
 
 	root->node = alloc_dummy_extent_buffer(fs_info, nodesize);
 	if (!root->node) {
-		test_err("couldn't allocate dummy buffer");
+		test_std_err(TEST_ALLOC_ROOT);
 		goto out;
 	}
 
Signature · 1 line
2.21.0
author maintainer
#8 lore raw

PATCH 8/22 btrfs: tests: use standard error message after path allocation failure

In reply to David Sterba
---
 fs/btrfs/tests/extent-buffer-tests.c   | 2 +-
 fs/btrfs/tests/free-space-tree-tests.c | 2 +-
 fs/btrfs/tests/qgroup-tests.c          | 8 ++++----
 3 files changed, 6 insertions(+), 6 deletions(-)
fs/btrfs/tests/extent-buffer-tests.c +1 -1
index dc2582554cf0..a1b9f9b5978e 100644
@@ -43,7 +43,7 @@ static int test_btrfs_split_item(u32 sectorsize, u32 nodesize)
 
 	path = btrfs_alloc_path();
 	if (!path) {
-		test_err("could not allocate path");
+		test_std_err(TEST_ALLOC_PATH);
 		ret = -ENOMEM;
 		goto out;
 	}
fs/btrfs/tests/free-space-tree-tests.c +1 -1
index 58fbca92dd0d..22282c16c022 100644
@@ -486,7 +486,7 @@ static int run_test(test_func_t test_func, int bitmaps, u32 sectorsize,
 
 	path = btrfs_alloc_path();
 	if (!path) {
-		test_err("couldn't allocate path");
+		test_std_err(TEST_ALLOC_ROOT);
 		ret = -ENOMEM;
 		goto out;
 	}
fs/btrfs/tests/qgroup-tests.c +4 -4
index 7e25a3a9f979..c85e4b955939 100644
@@ -32,7 +32,7 @@ static int insert_normal_tree_ref(struct btrfs_root *root, u64 bytenr,
 
 	path = btrfs_alloc_path();
 	if (!path) {
-		test_err("couldn't allocate path");
+		test_std_err(TEST_ALLOC_ROOT);
 		return -ENOMEM;
 	}
 
@@ -82,7 +82,7 @@ static int add_tree_ref(struct btrfs_root *root, u64 bytenr, u64 num_bytes,
 
 	path = btrfs_alloc_path();
 	if (!path) {
-		test_err("couldn't allocate path");
+		test_std_err(TEST_ALLOC_ROOT);
 		return -ENOMEM;
 	}
 
@@ -132,7 +132,7 @@ static int remove_extent_item(struct btrfs_root *root, u64 bytenr,
 
 	path = btrfs_alloc_path();
 	if (!path) {
-		test_err("couldn't allocate path");
+		test_std_err(TEST_ALLOC_ROOT);
 		return -ENOMEM;
 	}
 	path->leave_spinning = 1;
@@ -166,7 +166,7 @@ static int remove_extent_ref(struct btrfs_root *root, u64 bytenr,
 
 	path = btrfs_alloc_path();
 	if (!path) {
-		test_err("couldn't allocate path");
+		test_std_err(TEST_ALLOC_ROOT);
 		return -ENOMEM;
 	}
 
Signature · 1 line
2.21.0
author maintainer
#9 lore raw

PATCH 9/22 btrfs: tests: use standard error message after inode allocation failure

In reply to David Sterba
---
 fs/btrfs/tests/extent-io-tests.c | 2 +-
 fs/btrfs/tests/inode-tests.c     | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)
fs/btrfs/tests/extent-io-tests.c +1 -1
index cc9e6c88bcc1..8ded2d9b1ac0 100644
@@ -73,7 +73,7 @@ static int test_find_delalloc(u32 sectorsize)
 
 	inode = btrfs_new_test_inode();
 	if (!inode) {
-		test_err("failed to allocate test inode");
+		test_std_err(TEST_ALLOC_INODE);
 		return -ENOMEM;
 	}
 
fs/btrfs/tests/inode-tests.c +3 -3
index e63c128c741c..46571cd27513 100644
@@ -228,7 +228,7 @@ static noinline int test_btrfs_get_extent(u32 sectorsize, u32 nodesize)
 
 	inode = btrfs_new_test_inode();
 	if (!inode) {
-		test_err("couldn't allocate inode");
+		test_std_err(TEST_ALLOC_INODE);
 		return ret;
 	}
 
@@ -829,7 +829,7 @@ static int test_hole_first(u32 sectorsize, u32 nodesize)
 
 	inode = btrfs_new_test_inode();
 	if (!inode) {
-		test_err("couldn't allocate inode");
+		test_std_err(TEST_ALLOC_INODE);
 		return ret;
 	}
 
@@ -929,7 +929,7 @@ static int test_extent_accounting(u32 sectorsize, u32 nodesize)
 
 	inode = btrfs_new_test_inode();
 	if (!inode) {
-		test_err("couldn't allocate inode");
+		test_std_err(TEST_ALLOC_INODE);
 		return ret;
 	}
 
Signature · 1 line
2.21.0
author maintainer
#10 lore raw

PATCH 10/22 btrfs: tests: use standard error message after block group allocation failure

In reply to David Sterba
---
 fs/btrfs/tests/free-space-tests.c      | 2 +-
 fs/btrfs/tests/free-space-tree-tests.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
fs/btrfs/tests/free-space-tests.c +1 -1
index 8dcdefab1280..dcbe526e5698 100644
@@ -847,7 +847,7 @@ int btrfs_test_free_space_cache(u32 sectorsize, u32 nodesize)
 	cache = btrfs_alloc_dummy_block_group(fs_info,
 				      BITS_PER_BITMAP * sectorsize + PAGE_SIZE);
 	if (!cache) {
-		test_err("couldn't run the tests");
+		test_std_err(TEST_ALLOC_BLOCK_GROUP);
 		btrfs_free_dummy_fs_info(fs_info);
 		return 0;
 	}
fs/btrfs/tests/free-space-tree-tests.c +1 -1
index 22282c16c022..09c27628e305 100644
@@ -473,7 +473,7 @@ static int run_test(test_func_t test_func, int bitmaps, u32 sectorsize,
 
 	cache = btrfs_alloc_dummy_block_group(fs_info, 8 * alignment);
 	if (!cache) {
-		test_err("couldn't allocate dummy block group cache");
+		test_std_err(TEST_ALLOC_BLOCK_GROUP);
 		ret = -ENOMEM;
 		goto out;
 	}
Signature · 1 line
2.21.0
author maintainer
#11 lore raw

PATCH 11/22 btrfs: tests: properly initialize fs_info of extent buffer

In reply to David Sterba

The fs_info is supposed to be valid, even though it's not used right now and the test does not crash.

---
 fs/btrfs/tests/extent-io-tests.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/tests/extent-io-tests.c +1 -1
index 8ded2d9b1ac0..1d223086094a 100644
@@ -413,7 +413,7 @@ static int test_eb_bitmaps(u32 sectorsize, u32 nodesize)
 
 	/* Do it over again with an extent buffer which isn't page-aligned. */
 	free_extent_buffer(eb);
-	eb = __alloc_dummy_extent_buffer(NULL, nodesize / 2, len);
+	eb = __alloc_dummy_extent_buffer(fs_info, nodesize / 2, len);
 	if (!eb) {
 		test_std_err(TEST_ALLOC_ROOT);
 		ret = -ENOMEM;
Signature · 1 line
2.21.0
author maintainer
#13 lore raw

PATCH 13/22 btrfs: tests: return errors from extent map test case 1

In reply to David Sterba

Replace asserts with error messages and return errors.

---
 fs/btrfs/tests/extent-map-tests.c | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)
fs/btrfs/tests/extent-map-tests.c +14 -6
index c31b1ac3bc2d..320c2842347c 100644
@@ -65,7 +65,10 @@ static int test_case_1(struct btrfs_fs_info *fs_info,
 	em->block_start = 0;
 	em->block_len = SZ_16K;
 	ret = add_extent_mapping(em_tree, em, 0);
-	ASSERT(ret == 0);
+	if (ret < 0) {
+		test_err("cannot add extent range [0, 16K)");
+		goto out;
+	}
 	free_extent_map(em);
 
 	/* Add [16K, 20K) following [0, 16K)  */
@@ -80,7 +83,10 @@ static int test_case_1(struct btrfs_fs_info *fs_info,
 	em->block_start = SZ_32K; /* avoid merging */
 	em->block_len = SZ_4K;
 	ret = add_extent_mapping(em_tree, em, 0);
-	ASSERT(ret == 0);
+	if (ret < 0) {
+		test_err("cannot add extent range [16K, 20K)");
+		goto out;
+	}
 	free_extent_map(em);
 
 	em = alloc_extent_map();
@@ -95,19 +101,21 @@ static int test_case_1(struct btrfs_fs_info *fs_info,
 	em->block_start = start;
 	em->block_len = len;
 	ret = btrfs_add_extent_mapping(fs_info, em_tree, &em, em->start, em->len);
-	if (ret)
+	if (ret) {
 		test_err("case1 [%llu %llu]: ret %d", start, start + len, ret);
+		goto out;
+	}
 	if (em &&
 	    (em->start != 0 || extent_map_end(em) != SZ_16K ||
-	     em->block_start != 0 || em->block_len != SZ_16K))
+	     em->block_start != 0 || em->block_len != SZ_16K)) {
 		test_err(
 "case1 [%llu %llu]: ret %d return a wrong em (start %llu len %llu block_start %llu block_len %llu",
 			 start, start + len, ret, em->start, em->len,
 			 em->block_start, em->block_len);
+		ret = -EINVAL;
+	}
 	free_extent_map(em);
-	ret = 0;
 out:
-	/* free memory */
 	free_extent_map_tree(em_tree);
 
 	return ret;
Signature · 1 line
2.21.0
author maintainer
#12 lore raw

PATCH 12/22 btrfs: tests: return errors from extent map tests

In reply to David Sterba

The individual testcases for extent maps do not return an error on allocation failures. This is not a big problem as the allocation don't fail in general but there are functional tests handled with ASSERTS. This makes tests dependent on them and it's not reliable.

This patch adds the allocation failure handling and allows for the conversion of the asserts to proper error handling and reporting.

---
 fs/btrfs/tests/extent-map-tests.c | 68 +++++++++++++++++++++----------
 1 file changed, 46 insertions(+), 22 deletions(-)
fs/btrfs/tests/extent-map-tests.c +46 -22
index 662b718506b9..c31b1ac3bc2d 100644
@@ -47,7 +47,7 @@ static void free_extent_map_tree(struct extent_map_tree *em_tree)
  *                                    ->add_extent_mapping(0, 16K)
  *                                    -> #handle -EEXIST
  */
-static void test_case_1(struct btrfs_fs_info *fs_info,
+static int test_case_1(struct btrfs_fs_info *fs_info,
 		struct extent_map_tree *em_tree)
 {
 	struct extent_map *em;
@@ -57,8 +57,7 @@ static void test_case_1(struct btrfs_fs_info *fs_info,
 
 	em = alloc_extent_map();
 	if (!em)
-		/* Skip the test on error. */
-		return;
+		return -ENOMEM;
 
 	/* Add [0, 16K) */
 	em->start = 0;
@@ -71,8 +70,10 @@ static void test_case_1(struct btrfs_fs_info *fs_info,
 
 	/* Add [16K, 20K) following [0, 16K)  */
 	em = alloc_extent_map();
-	if (!em)
+	if (!em) {
+		ret = -ENOMEM;
 		goto out;
+	}
 
 	em->start = SZ_16K;
 	em->len = SZ_4K;
@@ -83,8 +84,10 @@ static void test_case_1(struct btrfs_fs_info *fs_info,
 	free_extent_map(em);
 
 	em = alloc_extent_map();
-	if (!em)
+	if (!em) {
+		ret = -ENOMEM;
 		goto out;
+	}
 
 	/* Add [0, 8K), should return [0, 16K) instead. */
 	em->start = start;
@@ -102,9 +105,12 @@ static void test_case_1(struct btrfs_fs_info *fs_info,
 			 start, start + len, ret, em->start, em->len,
 			 em->block_start, em->block_len);
 	free_extent_map(em);
+	ret = 0;
 out:
 	/* free memory */
 	free_extent_map_tree(em_tree);
+
+	return ret;
 }
 
 /*
@@ -113,7 +119,7 @@ static void test_case_1(struct btrfs_fs_info *fs_info,
  * Reading the inline ending up with EEXIST, ie. read an inline
  * extent and discard page cache and read it again.
  */
-static void test_case_2(struct btrfs_fs_info *fs_info,
+static int test_case_2(struct btrfs_fs_info *fs_info,
 		struct extent_map_tree *em_tree)
 {
 	struct extent_map *em;
@@ -121,8 +127,7 @@ static void test_case_2(struct btrfs_fs_info *fs_info,
 
 	em = alloc_extent_map();
 	if (!em)
-		/* Skip the test on error. */
-		return;
+		return -ENOMEM;
 
 	/* Add [0, 1K) */
 	em->start = 0;
@@ -135,8 +140,10 @@ static void test_case_2(struct btrfs_fs_info *fs_info,
 
 	/* Add [4K, 4K) following [0, 1K)  */
 	em = alloc_extent_map();
-	if (!em)
+	if (!em) {
+		ret = -ENOMEM;
 		goto out;
+	}
 
 	em->start = SZ_4K;
 	em->len = SZ_4K;
@@ -147,8 +154,10 @@ static void test_case_2(struct btrfs_fs_info *fs_info,
 	free_extent_map(em);
 
 	em = alloc_extent_map();
-	if (!em)
+	if (!em) {
+		ret = -ENOMEM;
 		goto out;
+	}
 
 	/* Add [0, 1K) */
 	em->start = 0;
@@ -166,12 +175,15 @@ static void test_case_2(struct btrfs_fs_info *fs_info,
 			 ret, em->start, em->len, em->block_start,
 			 em->block_len);
 	free_extent_map(em);
+	ret = 0;
 out:
 	/* free memory */
 	free_extent_map_tree(em_tree);
+
+	return ret;
 }
 
-static void __test_case_3(struct btrfs_fs_info *fs_info,
+static int __test_case_3(struct btrfs_fs_info *fs_info,
 		struct extent_map_tree *em_tree, u64 start)
 {
 	struct extent_map *em;
@@ -180,8 +192,7 @@ static void __test_case_3(struct btrfs_fs_info *fs_info,
 
 	em = alloc_extent_map();
 	if (!em)
-		/* Skip this test on error. */
-		return;
+		return -ENOMEM;
 
 	/* Add [4K, 8K) */
 	em->start = SZ_4K;
@@ -193,8 +204,10 @@ static void __test_case_3(struct btrfs_fs_info *fs_info,
 	free_extent_map(em);
 
 	em = alloc_extent_map();
-	if (!em)
+	if (!em) {
+		ret = -ENOMEM;
 		goto out;
+	}
 
 	/* Add [0, 16K) */
 	em->start = 0;
@@ -217,9 +230,12 @@ static void __test_case_3(struct btrfs_fs_info *fs_info,
 			 start, start + len, ret, em->start, em->len,
 			 em->block_start, em->block_len);
 	free_extent_map(em);
+	ret = 0;
 out:
 	/* free memory */
 	free_extent_map_tree(em_tree);
+
+	return ret;
 }
 
 /*
@@ -246,7 +262,7 @@ static void test_case_3(struct btrfs_fs_info *fs_info,
 	__test_case_3(fs_info, em_tree, (12 * 1024ULL));
 }
 
-static void __test_case_4(struct btrfs_fs_info *fs_info,
+static int __test_case_4(struct btrfs_fs_info *fs_info,
 		struct extent_map_tree *em_tree, u64 start)
 {
 	struct extent_map *em;
@@ -255,8 +271,7 @@ static void __test_case_4(struct btrfs_fs_info *fs_info,
 
 	em = alloc_extent_map();
 	if (!em)
-		/* Skip this test on error. */
-		return;
+		return -ENOMEM;
 
 	/* Add [0K, 8K) */
 	em->start = 0;
@@ -268,8 +283,10 @@ static void __test_case_4(struct btrfs_fs_info *fs_info,
 	free_extent_map(em);
 
 	em = alloc_extent_map();
-	if (!em)
+	if (!em) {
+		ret = -ENOMEM;
 		goto out;
+	}
 
 	/* Add [8K, 24K) */
 	em->start = SZ_8K;
@@ -281,8 +298,10 @@ static void __test_case_4(struct btrfs_fs_info *fs_info,
 	free_extent_map(em);
 
 	em = alloc_extent_map();
-	if (!em)
+	if (!em) {
+		ret = -ENOMEM;
 		goto out;
+	}
 	/* Add [0K, 32K) */
 	em->start = 0;
 	em->len = SZ_32K;
@@ -299,9 +318,12 @@ static void __test_case_4(struct btrfs_fs_info *fs_info,
 			 start, len, ret, em->start, em->len, em->block_start,
 			 em->block_len);
 	free_extent_map(em);
+	ret = 0;
 out:
 	/* free memory */
 	free_extent_map_tree(em_tree);
+
+	return ret;
 }
 
 /*
@@ -340,6 +362,7 @@ int btrfs_test_extent_map(void)
 {
 	struct btrfs_fs_info *fs_info = NULL;
 	struct extent_map_tree *em_tree;
+	int ret = 0;
 
 	test_msg("running extent_map tests");
 
@@ -354,9 +377,10 @@ int btrfs_test_extent_map(void)
 	}
 
 	em_tree = kzalloc(sizeof(*em_tree), GFP_KERNEL);
-	if (!em_tree)
-		/* Skip the test on error. */
+	if (!em_tree) {
+		ret = -ENOMEM;
 		goto out;
+	}
 
 	extent_map_tree_init(em_tree);
 
@@ -369,5 +393,5 @@ int btrfs_test_extent_map(void)
 out:
 	btrfs_free_dummy_fs_info(fs_info);
 
-	return 0;
+	return ret;
 }
Signature · 1 line
2.21.0
author maintainer
#14 lore raw

PATCH 14/22 btrfs: tests: return errors from extent map test case 2

In reply to David Sterba

Replace asserts with error messages and return errors.

---
 fs/btrfs/tests/extent-map-tests.c | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)
fs/btrfs/tests/extent-map-tests.c +14 -6
index 320c2842347c..d56d03d6b781 100644
@@ -143,7 +143,10 @@ static int test_case_2(struct btrfs_fs_info *fs_info,
 	em->block_start = EXTENT_MAP_INLINE;
 	em->block_len = (u64)-1;
 	ret = add_extent_mapping(em_tree, em, 0);
-	ASSERT(ret == 0);
+	if (ret < 0) {
+		test_err("cannot add extent range [0, 1K)");
+		goto out;
+	}
 	free_extent_map(em);
 
 	/* Add [4K, 4K) following [0, 1K)  */
@@ -158,7 +161,10 @@ static int test_case_2(struct btrfs_fs_info *fs_info,
 	em->block_start = SZ_4K;
 	em->block_len = SZ_4K;
 	ret = add_extent_mapping(em_tree, em, 0);
-	ASSERT(ret == 0);
+	if (ret < 0) {
+		test_err("cannot add extent range [4K, 8K)");
+		goto out;
+	}
 	free_extent_map(em);
 
 	em = alloc_extent_map();
@@ -173,19 +179,21 @@ static int test_case_2(struct btrfs_fs_info *fs_info,
 	em->block_start = EXTENT_MAP_INLINE;
 	em->block_len = (u64)-1;
 	ret = btrfs_add_extent_mapping(fs_info, em_tree, &em, em->start, em->len);
-	if (ret)
+	if (ret) {
 		test_err("case2 [0 1K]: ret %d", ret);
+		goto out;
+	}
 	if (em &&
 	    (em->start != 0 || extent_map_end(em) != SZ_1K ||
-	     em->block_start != EXTENT_MAP_INLINE || em->block_len != (u64)-1))
+	     em->block_start != EXTENT_MAP_INLINE || em->block_len != (u64)-1)) {
 		test_err(
 "case2 [0 1K]: ret %d return a wrong em (start %llu len %llu block_start %llu block_len %llu",
 			 ret, em->start, em->len, em->block_start,
 			 em->block_len);
+		ret = -EINVAL;
+	}
 	free_extent_map(em);
-	ret = 0;
 out:
-	/* free memory */
 	free_extent_map_tree(em_tree);
 
 	return ret;
Signature · 1 line
2.21.0
author maintainer
#15 lore raw

PATCH 15/22 btrfs: tests: return errors from extent map test case 3

In reply to David Sterba

Replace asserts with error messages and return errors.

---
 fs/btrfs/tests/extent-map-tests.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
fs/btrfs/tests/extent-map-tests.c +10 -5
index d56d03d6b781..17182b14ce9d 100644
@@ -216,7 +216,10 @@ static int __test_case_3(struct btrfs_fs_info *fs_info,
 	em->block_start = SZ_4K;
 	em->block_len = SZ_4K;
 	ret = add_extent_mapping(em_tree, em, 0);
-	ASSERT(ret == 0);
+	if (ret < 0) {
+		test_err("cannot add extent range [4K, 8K)");
+		goto out;
+	}
 	free_extent_map(em);
 
 	em = alloc_extent_map();
@@ -231,24 +234,26 @@ static int __test_case_3(struct btrfs_fs_info *fs_info,
 	em->block_start = 0;
 	em->block_len = SZ_16K;
 	ret = btrfs_add_extent_mapping(fs_info, em_tree, &em, start, len);
-	if (ret)
+	if (ret) {
 		test_err("case3 [0x%llx 0x%llx): ret %d",
 			 start, start + len, ret);
+		goto out;
+	}
 	/*
 	 * Since bytes within em are contiguous, em->block_start is identical to
 	 * em->start.
 	 */
 	if (em &&
 	    (start < em->start || start + len > extent_map_end(em) ||
-	     em->start != em->block_start || em->len != em->block_len))
+	     em->start != em->block_start || em->len != em->block_len)) {
 		test_err(
 "case3 [0x%llx 0x%llx): ret %d em (start 0x%llx len 0x%llx block_start 0x%llx block_len 0x%llx)",
 			 start, start + len, ret, em->start, em->len,
 			 em->block_start, em->block_len);
+		ret = -EINVAL;
+	}
 	free_extent_map(em);
-	ret = 0;
 out:
-	/* free memory */
 	free_extent_map_tree(em_tree);
 
 	return ret;
Signature · 1 line
2.21.0
author maintainer
#16 lore raw

PATCH 16/22 btrfs: tests: return errors from extent map test case 4

In reply to David Sterba

Replace asserts with error messages and return errors.

---
 fs/btrfs/tests/extent-map-tests.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)
fs/btrfs/tests/extent-map-tests.c +14 -7
index 17182b14ce9d..35cfb65f1016 100644
@@ -300,7 +300,10 @@ static int __test_case_4(struct btrfs_fs_info *fs_info,
 	em->block_start = 0;
 	em->block_len = SZ_8K;
 	ret = add_extent_mapping(em_tree, em, 0);
-	ASSERT(ret == 0);
+	if (ret < 0) {
+		test_err("cannot add extent range [0, 8K)");
+		goto out;
+	}
 	free_extent_map(em);
 
 	em = alloc_extent_map();
@@ -315,7 +318,10 @@ static int __test_case_4(struct btrfs_fs_info *fs_info,
 	em->block_start = SZ_16K; /* avoid merging */
 	em->block_len = 24 * 1024ULL;
 	ret = add_extent_mapping(em_tree, em, 0);
-	ASSERT(ret == 0);
+	if (ret < 0) {
+		test_err("cannot add extent range [8K, 32K)");
+		goto out;
+	}
 	free_extent_map(em);
 
 	em = alloc_extent_map();
@@ -329,19 +335,20 @@ static int __test_case_4(struct btrfs_fs_info *fs_info,
 	em->block_start = 0;
 	em->block_len = SZ_32K;
 	ret = btrfs_add_extent_mapping(fs_info, em_tree, &em, start, len);
-	if (ret)
+	if (ret) {
 		test_err("case4 [0x%llx 0x%llx): ret %d",
 			 start, len, ret);
-	if (em &&
-	    (start < em->start || start + len > extent_map_end(em)))
+		goto out;
+	}
+	if (em && (start < em->start || start + len > extent_map_end(em))) {
 		test_err(
 "case4 [0x%llx 0x%llx): ret %d, added wrong em (start 0x%llx len 0x%llx block_start 0x%llx block_len 0x%llx)",
 			 start, len, ret, em->start, em->len, em->block_start,
 			 em->block_len);
+		ret = -EINVAL;
+	}
 	free_extent_map(em);
-	ret = 0;
 out:
-	/* free memory */
 	free_extent_map_tree(em_tree);
 
 	return ret;
Signature · 1 line
2.21.0
author maintainer
#17 lore raw

PATCH 17/22 btrfs: tests: return error from all extent map test cases

In reply to David Sterba

The way the extent map tests handle errors does not conform to the rest of the suite, where the first failure is reported and then it stops. Do the same now that we have the errors returned from all the functions.

---
 fs/btrfs/tests/extent-map-tests.c | 44 ++++++++++++++++++++++---------
 1 file changed, 32 insertions(+), 12 deletions(-)
fs/btrfs/tests/extent-map-tests.c +32 -12
index 35cfb65f1016..5e99c7d40ea1 100644
@@ -275,12 +275,20 @@ static int __test_case_3(struct btrfs_fs_info *fs_info,
  *   -> add_extent_mapping()
  *                            -> add_extent_mapping()
  */
-static void test_case_3(struct btrfs_fs_info *fs_info,
+static int test_case_3(struct btrfs_fs_info *fs_info,
 		struct extent_map_tree *em_tree)
 {
-	__test_case_3(fs_info, em_tree, 0);
-	__test_case_3(fs_info, em_tree, SZ_8K);
-	__test_case_3(fs_info, em_tree, (12 * 1024ULL));
+	int ret;
+
+	ret = __test_case_3(fs_info, em_tree, 0);
+	if (ret)
+		return ret;
+	ret = __test_case_3(fs_info, em_tree, SZ_8K);
+	if (ret)
+		return ret;
+	ret = __test_case_3(fs_info, em_tree, (12 * 1024ULL));
+
+	return ret;
 }
 
 static int __test_case_4(struct btrfs_fs_info *fs_info,
@@ -379,11 +387,17 @@ static int __test_case_4(struct btrfs_fs_info *fs_info,
  *                                             # handle -EEXIST when adding
  *                                             # [0, 32K)
  */
-static void test_case_4(struct btrfs_fs_info *fs_info,
+static int test_case_4(struct btrfs_fs_info *fs_info,
 		struct extent_map_tree *em_tree)
 {
-	__test_case_4(fs_info, em_tree, 0);
-	__test_case_4(fs_info, em_tree, SZ_4K);
+	int ret;
+
+	ret = __test_case_4(fs_info, em_tree, 0);
+	if (ret)
+		return ret;
+	ret = __test_case_4(fs_info, em_tree, SZ_4K);
+
+	return ret;
 }
 
 int btrfs_test_extent_map(void)
@@ -412,13 +426,19 @@ int btrfs_test_extent_map(void)
 
 	extent_map_tree_init(em_tree);
 
-	test_case_1(fs_info, em_tree);
-	test_case_2(fs_info, em_tree);
-	test_case_3(fs_info, em_tree);
-	test_case_4(fs_info, em_tree);
+	ret = test_case_1(fs_info, em_tree);
+	if (ret)
+		goto out;
+	ret = test_case_2(fs_info, em_tree);
+	if (ret)
+		goto out;
+	ret = test_case_3(fs_info, em_tree);
+	if (ret)
+		goto out;
+	ret = test_case_4(fs_info, em_tree);
 
-	kfree(em_tree);
 out:
+	kfree(em_tree);
 	btrfs_free_dummy_fs_info(fs_info);
 
 	return ret;
Signature · 1 line
2.21.0
author maintainer
#18 lore raw

PATCH 18/22 btrfs: tests: use standard error message after extent map allocation failure

In reply to David Sterba
---
 fs/btrfs/tests/extent-map-tests.c | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)
fs/btrfs/tests/extent-map-tests.c +19 -4
index 5e99c7d40ea1..9bf75f7d2c26 100644
@@ -56,8 +56,10 @@ static int test_case_1(struct btrfs_fs_info *fs_info,
 	int ret;
 
 	em = alloc_extent_map();
-	if (!em)
+	if (!em) {
+		test_std_err(TEST_ALLOC_EXTENT_MAP);
 		return -ENOMEM;
+	}
 
 	/* Add [0, 16K) */
 	em->start = 0;
@@ -74,6 +76,7 @@ static int test_case_1(struct btrfs_fs_info *fs_info,
 	/* Add [16K, 20K) following [0, 16K)  */
 	em = alloc_extent_map();
 	if (!em) {
+		test_std_err(TEST_ALLOC_EXTENT_MAP);
 		ret = -ENOMEM;
 		goto out;
 	}
@@ -91,6 +94,7 @@ static int test_case_1(struct btrfs_fs_info *fs_info,
 
 	em = alloc_extent_map();
 	if (!em) {
+		test_std_err(TEST_ALLOC_EXTENT_MAP);
 		ret = -ENOMEM;
 		goto out;
 	}
@@ -134,8 +138,10 @@ static int test_case_2(struct btrfs_fs_info *fs_info,
 	int ret;
 
 	em = alloc_extent_map();
-	if (!em)
+	if (!em) {
+		test_std_err(TEST_ALLOC_EXTENT_MAP);
 		return -ENOMEM;
+	}
 
 	/* Add [0, 1K) */
 	em->start = 0;
@@ -152,6 +158,7 @@ static int test_case_2(struct btrfs_fs_info *fs_info,
 	/* Add [4K, 4K) following [0, 1K)  */
 	em = alloc_extent_map();
 	if (!em) {
+		test_std_err(TEST_ALLOC_EXTENT_MAP);
 		ret = -ENOMEM;
 		goto out;
 	}
@@ -169,6 +176,7 @@ static int test_case_2(struct btrfs_fs_info *fs_info,
 
 	em = alloc_extent_map();
 	if (!em) {
+		test_std_err(TEST_ALLOC_EXTENT_MAP);
 		ret = -ENOMEM;
 		goto out;
 	}
@@ -207,8 +215,10 @@ static int __test_case_3(struct btrfs_fs_info *fs_info,
 	int ret;
 
 	em = alloc_extent_map();
-	if (!em)
+	if (!em) {
+		test_std_err(TEST_ALLOC_EXTENT_MAP);
 		return -ENOMEM;
+	}
 
 	/* Add [4K, 8K) */
 	em->start = SZ_4K;
@@ -224,6 +234,7 @@ static int __test_case_3(struct btrfs_fs_info *fs_info,
 
 	em = alloc_extent_map();
 	if (!em) {
+		test_std_err(TEST_ALLOC_EXTENT_MAP);
 		ret = -ENOMEM;
 		goto out;
 	}
@@ -299,8 +310,10 @@ static int __test_case_4(struct btrfs_fs_info *fs_info,
 	int ret;
 
 	em = alloc_extent_map();
-	if (!em)
+	if (!em) {
+		test_std_err(TEST_ALLOC_EXTENT_MAP);
 		return -ENOMEM;
+	}
 
 	/* Add [0K, 8K) */
 	em->start = 0;
@@ -316,6 +329,7 @@ static int __test_case_4(struct btrfs_fs_info *fs_info,
 
 	em = alloc_extent_map();
 	if (!em) {
+		test_std_err(TEST_ALLOC_EXTENT_MAP);
 		ret = -ENOMEM;
 		goto out;
 	}
@@ -334,6 +348,7 @@ static int __test_case_4(struct btrfs_fs_info *fs_info,
 
 	em = alloc_extent_map();
 	if (!em) {
+		test_std_err(TEST_ALLOC_EXTENT_MAP);
 		ret = -ENOMEM;
 		goto out;
 	}
Signature · 1 line
2.21.0
author maintainer
#19 lore raw

PATCH 19/22 btrfs: tests: use SZ_ constants everywhere

In reply to David Sterba

There are a few unconverted constants that are not powers of two and haven't been converted.

---
 fs/btrfs/tests/extent-map-tests.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
fs/btrfs/tests/extent-map-tests.c +3 -3
index 9bf75f7d2c26..a09783f19011 100644
@@ -297,7 +297,7 @@ static int test_case_3(struct btrfs_fs_info *fs_info,
 	ret = __test_case_3(fs_info, em_tree, SZ_8K);
 	if (ret)
 		return ret;
-	ret = __test_case_3(fs_info, em_tree, (12 * 1024ULL));
+	ret = __test_case_3(fs_info, em_tree, (12 * SZ_1K));
 
 	return ret;
 }
@@ -336,9 +336,9 @@ static int __test_case_4(struct btrfs_fs_info *fs_info,
 
 	/* Add [8K, 24K) */
 	em->start = SZ_8K;
-	em->len = 24 * 1024ULL;
+	em->len = 24 * SZ_1K;
 	em->block_start = SZ_16K; /* avoid merging */
-	em->block_len = 24 * 1024ULL;
+	em->block_len = 24 * SZ_1K;
 	ret = add_extent_mapping(em_tree, em, 0);
 	if (ret < 0) {
 		test_err("cannot add extent range [8K, 32K)");
Signature · 1 line
2.21.0
author maintainer
#20 lore raw

PATCH 20/22 btrfs: tests: fix comments about tested extent map ranges

In reply to David Sterba

Comments about ranges did not match the code, the correct calculation is to use start and start+len as the interval boundaries.

---
 fs/btrfs/tests/extent-map-tests.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/btrfs/tests/extent-map-tests.c +2 -2
index a09783f19011..87aeabe9d610 100644
@@ -155,7 +155,7 @@ static int test_case_2(struct btrfs_fs_info *fs_info,
 	}
 	free_extent_map(em);
 
-	/* Add [4K, 4K) following [0, 1K)  */
+	/* Add [4K, 8K) following [0, 1K)  */
 	em = alloc_extent_map();
 	if (!em) {
 		test_std_err(TEST_ALLOC_EXTENT_MAP);
@@ -334,7 +334,7 @@ static int __test_case_4(struct btrfs_fs_info *fs_info,
 		goto out;
 	}
 
-	/* Add [8K, 24K) */
+	/* Add [8K, 32K) */
 	em->start = SZ_8K;
 	em->len = 24 * SZ_1K;
 	em->block_start = SZ_16K; /* avoid merging */
Signature · 1 line
2.21.0
author maintainer
#21 lore raw

PATCH 21/22 btrfs: tests: drop messages when some tests finish

In reply to David Sterba

The messages like 'extent I/O tests finished' are redundant, if the test fails it's quite obvious in the log and hang is also noticeable. No other then extent_io and free space tree tests print that so make it consistent.

---
 fs/btrfs/tests/extent-io-tests.c  | 1 -
 fs/btrfs/tests/free-space-tests.c | 1 -
 2 files changed, 2 deletions(-)
fs/btrfs/tests/extent-io-tests.c +0 -1
index 1d223086094a..843b53e64528 100644
@@ -440,6 +440,5 @@ int btrfs_test_extent_io(u32 sectorsize, u32 nodesize)
 
 	ret = test_eb_bitmaps(sectorsize, nodesize);
 out:
-	test_msg("extent I/O tests finished");
 	return ret;
 }
fs/btrfs/tests/free-space-tests.c +0 -1
index dcbe526e5698..d0fdc94a5d61 100644
@@ -876,6 +876,5 @@ int btrfs_test_free_space_cache(u32 sectorsize, u32 nodesize)
 	btrfs_free_dummy_block_group(cache);
 	btrfs_free_dummy_root(root);
 	btrfs_free_dummy_fs_info(fs_info);
-	test_msg("free space cache tests finished");
 	return ret;
 }
Signature · 1 line
2.21.0
author maintainer
#22 lore raw

PATCH 22/22 btrfs: tests: unify messages when tests start

In reply to David Sterba

- make the messages more visually consistent and use same format "running ... test", any error or other warning can be easily spotted

- move some message to the test entry function

- add message to the inode tests

Example output:

[    8.187391] Btrfs loaded, crc32c=crc32c-generic, assert=on, integrity-checker=on, ref-verify=on
[    8.189476] BTRFS: selftest: sectorsize: 4096  nodesize: 4096
[    8.190761] BTRFS: selftest: running btrfs free space cache tests
[    8.192245] BTRFS: selftest: running extent only tests
[    8.193573] BTRFS: selftest: running bitmap only tests
[    8.194876] BTRFS: selftest: running bitmap and extent tests
[    8.196166] BTRFS: selftest: running space stealing from bitmap to extent tests
[    8.198026] BTRFS: selftest: running extent buffer operation tests
[    8.199328] BTRFS: selftest: running btrfs_split_item tests
[    8.200653] BTRFS: selftest: running extent I/O tests
[    8.201808] BTRFS: selftest: running find delalloc tests
[    8.320733] BTRFS: selftest: running extent buffer bitmap tests
[    8.340795] BTRFS: selftest: running inode tests
[    8.341766] BTRFS: selftest: running btrfs_get_extent tests
[    8.342981] BTRFS: selftest: running hole first btrfs_get_extent test
[    8.344342] BTRFS: selftest: running outstanding_extents tests
[    8.345575] BTRFS: selftest: running qgroup tests
[    8.346537] BTRFS: selftest: running qgroup add/remove tests
[    8.347725] BTRFS: selftest: running qgroup multiple refs test
[    8.354982] BTRFS: selftest: running free space tree tests
[    8.372175] BTRFS: selftest: sectorsize: 4096  nodesize: 8192
[    8.373539] BTRFS: selftest: running btrfs free space cache tests
[    8.374989] BTRFS: selftest: running extent only tests
[    8.376236] BTRFS: selftest: running bitmap only tests
[    8.377483] BTRFS: selftest: running bitmap and extent tests
[    8.378854] BTRFS: selftest: running space stealing from bitmap to extent tests

...

---
 fs/btrfs/tests/free-space-tests.c |  2 +-
 fs/btrfs/tests/inode-tests.c      | 11 ++++++++---
 fs/btrfs/tests/qgroup-tests.c     |  4 ++--
 3 files changed, 11 insertions(+), 6 deletions(-)
fs/btrfs/tests/free-space-tests.c +1 -1
index d0fdc94a5d61..af89f66f9e63 100644
@@ -404,7 +404,7 @@ test_steal_space_from_bitmap_to_extent(struct btrfs_block_group_cache *cache,
 	};
 	const struct btrfs_free_space_op *orig_free_space_ops;
 
-	test_msg("running space stealing from bitmap to extent");
+	test_msg("running space stealing from bitmap to extent tests");
 
 	/*
 	 * For this test, we want to ensure we end up with an extent entry
fs/btrfs/tests/inode-tests.c +8 -3
index 46571cd27513..3d2c7abda5de 100644
@@ -226,6 +226,8 @@ static noinline int test_btrfs_get_extent(u32 sectorsize, u32 nodesize)
 	u64 offset;
 	int ret = -ENOMEM;
 
+	test_msg("running btrfs_get_extent tests");
+
 	inode = btrfs_new_test_inode();
 	if (!inode) {
 		test_std_err(TEST_ALLOC_INODE);
@@ -827,6 +829,8 @@ static int test_hole_first(u32 sectorsize, u32 nodesize)
 	struct extent_map *em = NULL;
 	int ret = -ENOMEM;
 
+	test_msg("running hole first btrfs_get_extent test");
+
 	inode = btrfs_new_test_inode();
 	if (!inode) {
 		test_std_err(TEST_ALLOC_INODE);
@@ -927,6 +931,8 @@ static int test_extent_accounting(u32 sectorsize, u32 nodesize)
 	struct btrfs_root *root = NULL;
 	int ret = -ENOMEM;
 
+	test_msg("running outstanding_extents tests");
+
 	inode = btrfs_new_test_inode();
 	if (!inode) {
 		test_std_err(TEST_ALLOC_INODE);
@@ -1110,17 +1116,16 @@ int btrfs_test_inodes(u32 sectorsize, u32 nodesize)
 {
 	int ret;
 
+	test_msg("running inode tests");
+
 	set_bit(EXTENT_FLAG_COMPRESSED, &compressed_only);
 	set_bit(EXTENT_FLAG_PREALLOC, &prealloc_only);
 
-	test_msg("running btrfs_get_extent tests");
 	ret = test_btrfs_get_extent(sectorsize, nodesize);
 	if (ret)
 		return ret;
-	test_msg("running hole first btrfs_get_extent test");
 	ret = test_hole_first(sectorsize, nodesize);
 	if (ret)
 		return ret;
-	test_msg("running outstanding_extents tests");
 	return test_extent_accounting(sectorsize, nodesize);
 }
fs/btrfs/tests/qgroup-tests.c +2 -2
index c85e4b955939..09aaca1efd62 100644
@@ -215,7 +215,7 @@ static int test_no_shared_qgroup(struct btrfs_root *root,
 
 	btrfs_init_dummy_trans(&trans, fs_info);
 
-	test_msg("qgroup basic add");
+	test_msg("running qgroup add/remove tests");
 	ret = btrfs_create_qgroup(&trans, BTRFS_FS_TREE_OBJECTID);
 	if (ret) {
 		test_err("couldn't create a qgroup %d", ret);
@@ -316,7 +316,7 @@ static int test_multiple_refs(struct btrfs_root *root,
 
 	btrfs_init_dummy_trans(&trans, fs_info);
 
-	test_msg("qgroup multiple refs test");
+	test_msg("running qgroup multiple refs test");
 
 	/*
 	 * We have BTRFS_FS_TREE_OBJECTID created already from the
Signature · 1 line
2.21.0