Moved lfsr_btree_push/set/pop/split into the tests

These functions are no longer needed in lfs.c. They are still needed for
the tests as they are written, but that's not a reason to pollute the
littlefs source code.

Maybe these tests should be rewritten to use lfsr_btree_commit directly?
Unfortunately with the quantity of tests we have now this adds
non-trivial amount of work with questionable benefit.
This commit is contained in:
Christopher Haster
2023-08-15 02:09:31 -05:00
parent 528f104cb4
commit d09a3646aa
2 changed files with 79 additions and 98 deletions
+79
View File
@@ -5,6 +5,85 @@ after = 'test_rbyd'
# of the disk for these tests
defines.LOOKAHEAD_SIZE = 'lfs_alignup(BLOCK_COUNT / 8, 8)'
# helper functions
in = 'lfs.c'
code = '''
static int lfsr_btree_push(lfs_t *lfs, lfsr_btree_t *btree,
lfs_size_t bid, lfsr_tag_t tag, lfs_size_t weight,
lfsr_data_t data) {
LFS_ASSERT(bid <= lfsr_btree_weight(btree));
return lfsr_btree_commit(lfs, btree, LFSR_ATTRS(
LFSR_ATTR(bid, TAG(tag), +weight, DATA(data))));
}
static int lfsr_btree_set(lfs_t *lfs, lfsr_btree_t *btree,
lfs_size_t bid, lfsr_tag_t tag, lfs_size_t weight,
lfsr_data_t data) {
LFS_ASSERT(bid < lfsr_btree_weight(btree));
LFS_ASSERT(lfsr_btree_weight(btree) > 0);
// lookup weight to compute deltas
lfs_size_t weight_;
int err = lfsr_btree_lookupnext(lfs, btree, bid,
NULL, NULL, &weight_, NULL);
if (err) {
return err;
}
// note we need a second tag here in case our entry has a
// name attributes, the name attribute holds the weight not
// the struct tag
return lfsr_btree_commit(lfs, btree, LFSR_ATTRS(
LFSR_ATTR(bid, WIDE(TAG(tag)), 0, DATA(data)),
LFSR_ATTR(bid, GROW(RM), weight - weight_, NULL)));
}
static int lfsr_btree_pop(lfs_t *lfs, lfsr_btree_t *btree, lfs_size_t bid) {
LFS_ASSERT(bid < lfsr_btree_weight(btree));
LFS_ASSERT(lfsr_btree_weight(btree) > 0);
// lookup weight to compute deltas
lfs_size_t weight_;
int err = lfsr_btree_lookupnext(lfs, btree, bid,
NULL, NULL, &weight_, NULL);
if (err) {
return err;
}
return lfsr_btree_commit(lfs, btree, LFSR_ATTRS(
LFSR_ATTR(bid, RM, -weight_, NULL)));
}
static int lfsr_btree_split(lfs_t *lfs, lfsr_btree_t *btree,
lfs_size_t bid, lfsr_data_t name,
lfsr_tag_t tag1, lfs_size_t weight1, lfsr_data_t data1,
lfsr_tag_t tag2, lfs_size_t weight2, lfsr_data_t data2) {
LFS_ASSERT(bid < lfsr_btree_weight(btree));
LFS_ASSERT(lfsr_btree_weight(btree) > 0);
// lookup weight to compute deltas
lfs_size_t weight_;
int err = lfsr_btree_lookupnext(lfs, btree, bid,
NULL, NULL, &weight_, NULL);
if (err) {
return err;
}
return lfsr_btree_commit(lfs, btree, LFSR_ATTRS(
LFSR_ATTR(bid, GROW(RM), +weight1-weight_, NULL),
LFSR_ATTR(bid-(weight_-1)+weight1-1, TAG(tag1), 0, DATA(data1)),
(lfsr_data_size(&name) > 0
? LFSR_ATTR(bid-(weight_-1)+weight1,
BNAME, +weight2, DATA(name))
: LFSR_ATTR_NOOP),
(lfsr_data_size(&name) > 0
? LFSR_ATTR(bid-(weight_-1)+weight1+weight2-1,
TAG(tag2), 0, DATA(data2))
: LFSR_ATTR(bid-(weight_-1)+weight1,
TAG(tag2), +weight2, DATA(data2)))));
}
'''
# test an empty tree
[cases.test_btree_zero]