diff options
Diffstat (limited to 'libbcachefs/tests.c')
-rw-r--r-- | libbcachefs/tests.c | 90 |
1 files changed, 76 insertions, 14 deletions
diff --git a/libbcachefs/tests.c b/libbcachefs/tests.c index 31847a94..f06eb2d8 100644 --- a/libbcachefs/tests.c +++ b/libbcachefs/tests.c @@ -14,12 +14,12 @@ static void delete_test_keys(struct bch_fs *c) ret = bch2_btree_delete_range(c, BTREE_ID_EXTENTS, POS(0, 0), POS(0, U64_MAX), - ZERO_VERSION, NULL, NULL, NULL); + NULL); BUG_ON(ret); ret = bch2_btree_delete_range(c, BTREE_ID_DIRENTS, POS(0, 0), POS(0, U64_MAX), - ZERO_VERSION, NULL, NULL, NULL); + NULL); BUG_ON(ret); } @@ -39,7 +39,7 @@ static void test_delete(struct bch_fs *c, u64 nr) ret = bch2_btree_iter_traverse(&iter); BUG_ON(ret); - ret = bch2_btree_insert_at(c, NULL, NULL, NULL, 0, + ret = bch2_btree_insert_at(c, NULL, NULL, 0, BTREE_INSERT_ENTRY(&iter, &k.k_i)); BUG_ON(ret); @@ -68,7 +68,7 @@ static void test_delete_written(struct bch_fs *c, u64 nr) ret = bch2_btree_iter_traverse(&iter); BUG_ON(ret); - ret = bch2_btree_insert_at(c, NULL, NULL, NULL, 0, + ret = bch2_btree_insert_at(c, NULL, NULL, 0, BTREE_INSERT_ENTRY(&iter, &k.k_i)); BUG_ON(ret); @@ -98,7 +98,7 @@ static void test_iterate(struct bch_fs *c, u64 nr) k.k.p.offset = i; ret = bch2_btree_insert(c, BTREE_ID_DIRENTS, &k.k_i, - NULL, NULL, NULL, 0); + NULL, NULL, 0); BUG_ON(ret); } @@ -140,7 +140,7 @@ static void test_iterate_extents(struct bch_fs *c, u64 nr) k.k.size = 8; ret = bch2_btree_insert(c, BTREE_ID_EXTENTS, &k.k_i, - NULL, NULL, NULL, 0); + NULL, NULL, 0); BUG_ON(ret); } @@ -185,7 +185,7 @@ static void test_iterate_slots(struct bch_fs *c, u64 nr) k.k.p.offset = i * 2; ret = bch2_btree_insert(c, BTREE_ID_DIRENTS, &k.k_i, - NULL, NULL, NULL, 0); + NULL, NULL, 0); BUG_ON(ret); } @@ -235,7 +235,7 @@ static void test_iterate_slots_extents(struct bch_fs *c, u64 nr) k.k.size = 8; ret = bch2_btree_insert(c, BTREE_ID_EXTENTS, &k.k_i, - NULL, NULL, NULL, 0); + NULL, NULL, 0); BUG_ON(ret); } @@ -270,6 +270,63 @@ static void test_iterate_slots_extents(struct bch_fs *c, u64 nr) bch2_btree_iter_unlock(&iter); } +/* extent unit tests */ + +u64 test_version; + +static void insert_test_extent(struct bch_fs *c, + u64 start, u64 end) +{ + struct bkey_i_cookie k; + int ret; + + //pr_info("inserting %llu-%llu v %llu", start, end, test_version); + + bkey_cookie_init(&k.k_i); + k.k_i.k.p.offset = end; + k.k_i.k.size = end - start; + k.k_i.k.version.lo = test_version++; + + ret = bch2_btree_insert(c, BTREE_ID_EXTENTS, &k.k_i, + NULL, NULL, 0); + BUG_ON(ret); +} + +static void __test_extent_overwrite(struct bch_fs *c, + u64 e1_start, u64 e1_end, + u64 e2_start, u64 e2_end) +{ + insert_test_extent(c, e1_start, e1_end); + insert_test_extent(c, e2_start, e2_end); + + delete_test_keys(c); +} + +static void test_extent_overwrite_front(struct bch_fs *c, u64 nr) +{ + __test_extent_overwrite(c, 0, 64, 0, 32); + __test_extent_overwrite(c, 8, 64, 0, 32); +} + +static void test_extent_overwrite_back(struct bch_fs *c, u64 nr) +{ + __test_extent_overwrite(c, 0, 64, 32, 64); + __test_extent_overwrite(c, 0, 64, 32, 72); +} + +static void test_extent_overwrite_middle(struct bch_fs *c, u64 nr) +{ + __test_extent_overwrite(c, 0, 64, 32, 40); +} + +static void test_extent_overwrite_all(struct bch_fs *c, u64 nr) +{ + __test_extent_overwrite(c, 32, 64, 0, 64); + __test_extent_overwrite(c, 32, 64, 0, 128); + __test_extent_overwrite(c, 32, 64, 32, 64); + __test_extent_overwrite(c, 32, 64, 32, 128); +} + /* perf tests */ static u64 test_rand(void) @@ -294,7 +351,7 @@ static void rand_insert(struct bch_fs *c, u64 nr) k.k.p.offset = test_rand(); ret = bch2_btree_insert(c, BTREE_ID_DIRENTS, &k.k_i, - NULL, NULL, NULL, 0); + NULL, NULL, 0); BUG_ON(ret); } } @@ -335,7 +392,7 @@ static void rand_mixed(struct bch_fs *c, u64 nr) bkey_cookie_init(&k.k_i); k.k.p = iter.pos; - ret = bch2_btree_insert_at(c, NULL, NULL, NULL, 0, + ret = bch2_btree_insert_at(c, NULL, NULL, 0, BTREE_INSERT_ENTRY(&iter, &k.k_i)); BUG_ON(ret); } @@ -356,7 +413,7 @@ static void rand_delete(struct bch_fs *c, u64 nr) k.k.p.offset = test_rand(); ret = bch2_btree_insert(c, BTREE_ID_DIRENTS, &k, - NULL, NULL, NULL, 0); + NULL, NULL, 0); BUG_ON(ret); } } @@ -375,7 +432,7 @@ static void seq_insert(struct bch_fs *c, u64 nr) BTREE_ITER_SLOTS|BTREE_ITER_INTENT, k) { insert.k.p = iter.pos; - ret = bch2_btree_insert_at(c, NULL, NULL, NULL, 0, + ret = bch2_btree_insert_at(c, NULL, NULL, 0, BTREE_INSERT_ENTRY(&iter, &insert.k_i)); BUG_ON(ret); @@ -407,7 +464,7 @@ static void seq_overwrite(struct bch_fs *c, u64 nr) bkey_reassemble(&u.k_i, k); - ret = bch2_btree_insert_at(c, NULL, NULL, NULL, 0, + ret = bch2_btree_insert_at(c, NULL, NULL, 0, BTREE_INSERT_ENTRY(&iter, &u.k_i)); BUG_ON(ret); } @@ -420,7 +477,7 @@ static void seq_delete(struct bch_fs *c, u64 nr) ret = bch2_btree_delete_range(c, BTREE_ID_DIRENTS, POS(0, 0), POS(0, U64_MAX), - ZERO_VERSION, NULL, NULL, NULL); + NULL); BUG_ON(ret); } @@ -498,6 +555,11 @@ void bch2_btree_perf_test(struct bch_fs *c, const char *testname, perf_test(test_iterate_slots); perf_test(test_iterate_slots_extents); + perf_test(test_extent_overwrite_front); + perf_test(test_extent_overwrite_back); + perf_test(test_extent_overwrite_middle); + perf_test(test_extent_overwrite_all); + if (!j.fn) { pr_err("unknown test %s", testname); return; |