Generated v2 prefixes
This commit is contained in:
+181
-28
@@ -1,9 +1,10 @@
|
||||
[[case]] # orphan test
|
||||
[cases.test_orphans_normal]
|
||||
in = "lfs2.c"
|
||||
if = 'LFS2_PROG_SIZE <= 0x3fe' # only works with one crc per commit
|
||||
if = 'PROG_SIZE <= 0x3fe' # only works with one crc per commit
|
||||
code = '''
|
||||
lfs2_format(&lfs2, &cfg) => 0;
|
||||
lfs2_mount(&lfs2, &cfg) => 0;
|
||||
lfs2_t lfs2;
|
||||
lfs2_format(&lfs2, cfg) => 0;
|
||||
lfs2_mount(&lfs2, cfg) => 0;
|
||||
lfs2_mkdir(&lfs2, "parent") => 0;
|
||||
lfs2_mkdir(&lfs2, "parent/orphan") => 0;
|
||||
lfs2_mkdir(&lfs2, "parent/child") => 0;
|
||||
@@ -13,29 +14,31 @@ code = '''
|
||||
// corrupt the child's most recent commit, this should be the update
|
||||
// to the linked-list entry, which should orphan the orphan. Note this
|
||||
// makes a lot of assumptions about the remove operation.
|
||||
lfs2_mount(&lfs2, &cfg) => 0;
|
||||
lfs2_mount(&lfs2, cfg) => 0;
|
||||
lfs2_dir_t dir;
|
||||
lfs2_dir_open(&lfs2, &dir, "parent/child") => 0;
|
||||
lfs2_block_t block = dir.m.pair[0];
|
||||
lfs2_dir_close(&lfs2, &dir) => 0;
|
||||
lfs2_unmount(&lfs2) => 0;
|
||||
uint8_t bbuffer[LFS2_BLOCK_SIZE];
|
||||
cfg.read(&cfg, block, 0, bbuffer, LFS2_BLOCK_SIZE) => 0;
|
||||
int off = LFS2_BLOCK_SIZE-1;
|
||||
while (off >= 0 && bbuffer[off] == LFS2_ERASE_VALUE) {
|
||||
uint8_t buffer[BLOCK_SIZE];
|
||||
cfg->read(cfg, block, 0, buffer, BLOCK_SIZE) => 0;
|
||||
int off = BLOCK_SIZE-1;
|
||||
while (off >= 0 && buffer[off] == ERASE_VALUE) {
|
||||
off -= 1;
|
||||
}
|
||||
memset(&bbuffer[off-3], LFS2_BLOCK_SIZE, 3);
|
||||
cfg.erase(&cfg, block) => 0;
|
||||
cfg.prog(&cfg, block, 0, bbuffer, LFS2_BLOCK_SIZE) => 0;
|
||||
cfg.sync(&cfg) => 0;
|
||||
memset(&buffer[off-3], BLOCK_SIZE, 3);
|
||||
cfg->erase(cfg, block) => 0;
|
||||
cfg->prog(cfg, block, 0, buffer, BLOCK_SIZE) => 0;
|
||||
cfg->sync(cfg) => 0;
|
||||
|
||||
lfs2_mount(&lfs2, &cfg) => 0;
|
||||
lfs2_mount(&lfs2, cfg) => 0;
|
||||
struct lfs2_info info;
|
||||
lfs2_stat(&lfs2, "parent/orphan", &info) => LFS2_ERR_NOENT;
|
||||
lfs2_stat(&lfs2, "parent/child", &info) => 0;
|
||||
lfs2_fs_size(&lfs2) => 8;
|
||||
lfs2_unmount(&lfs2) => 0;
|
||||
|
||||
lfs2_mount(&lfs2, &cfg) => 0;
|
||||
lfs2_mount(&lfs2, cfg) => 0;
|
||||
lfs2_stat(&lfs2, "parent/orphan", &info) => LFS2_ERR_NOENT;
|
||||
lfs2_stat(&lfs2, "parent/child", &info) => 0;
|
||||
lfs2_fs_size(&lfs2) => 8;
|
||||
@@ -48,7 +51,7 @@ code = '''
|
||||
lfs2_fs_size(&lfs2) => 8;
|
||||
lfs2_unmount(&lfs2) => 0;
|
||||
|
||||
lfs2_mount(&lfs2, &cfg) => 0;
|
||||
lfs2_mount(&lfs2, cfg) => 0;
|
||||
lfs2_stat(&lfs2, "parent/orphan", &info) => LFS2_ERR_NOENT;
|
||||
lfs2_stat(&lfs2, "parent/child", &info) => 0;
|
||||
lfs2_stat(&lfs2, "parent/otherchild", &info) => 0;
|
||||
@@ -56,43 +59,192 @@ code = '''
|
||||
lfs2_unmount(&lfs2) => 0;
|
||||
'''
|
||||
|
||||
[[case]] # reentrant testing for orphans, basically just spam mkdir/remove
|
||||
# test that we only run deorphan once per power-cycle
|
||||
[cases.test_orphans_no_orphans]
|
||||
in = 'lfs2.c'
|
||||
code = '''
|
||||
lfs2_t lfs2;
|
||||
lfs2_format(&lfs2, cfg) => 0;
|
||||
|
||||
lfs2_mount(&lfs2, cfg) => 0;
|
||||
// mark the filesystem as having orphans
|
||||
lfs2_fs_preporphans(&lfs2, +1) => 0;
|
||||
lfs2_mdir_t mdir;
|
||||
lfs2_dir_fetch(&lfs2, &mdir, (lfs2_block_t[2]){0, 1}) => 0;
|
||||
lfs2_dir_commit(&lfs2, &mdir, NULL, 0) => 0;
|
||||
|
||||
// we should have orphans at this state
|
||||
assert(lfs2_gstate_hasorphans(&lfs2.gstate));
|
||||
lfs2_unmount(&lfs2) => 0;
|
||||
|
||||
// mount
|
||||
lfs2_mount(&lfs2, cfg) => 0;
|
||||
// we should detect orphans
|
||||
assert(lfs2_gstate_hasorphans(&lfs2.gstate));
|
||||
// force consistency
|
||||
lfs2_fs_forceconsistency(&lfs2) => 0;
|
||||
// we should no longer have orphans
|
||||
assert(!lfs2_gstate_hasorphans(&lfs2.gstate));
|
||||
|
||||
lfs2_unmount(&lfs2) => 0;
|
||||
'''
|
||||
|
||||
[cases.test_orphans_one_orphan]
|
||||
in = 'lfs2.c'
|
||||
code = '''
|
||||
lfs2_t lfs2;
|
||||
lfs2_format(&lfs2, cfg) => 0;
|
||||
|
||||
lfs2_mount(&lfs2, cfg) => 0;
|
||||
// create an orphan
|
||||
lfs2_mdir_t orphan;
|
||||
lfs2_alloc_ack(&lfs2);
|
||||
lfs2_dir_alloc(&lfs2, &orphan) => 0;
|
||||
lfs2_dir_commit(&lfs2, &orphan, NULL, 0) => 0;
|
||||
|
||||
// append our orphan and mark the filesystem as having orphans
|
||||
lfs2_fs_preporphans(&lfs2, +1) => 0;
|
||||
lfs2_mdir_t mdir;
|
||||
lfs2_dir_fetch(&lfs2, &mdir, (lfs2_block_t[2]){0, 1}) => 0;
|
||||
lfs2_pair_tole32(orphan.pair);
|
||||
lfs2_dir_commit(&lfs2, &mdir, LFS2_MKATTRS(
|
||||
{LFS2_MKTAG(LFS2_TYPE_SOFTTAIL, 0x3ff, 8), orphan.pair})) => 0;
|
||||
|
||||
// we should have orphans at this state
|
||||
assert(lfs2_gstate_hasorphans(&lfs2.gstate));
|
||||
lfs2_unmount(&lfs2) => 0;
|
||||
|
||||
// mount
|
||||
lfs2_mount(&lfs2, cfg) => 0;
|
||||
// we should detect orphans
|
||||
assert(lfs2_gstate_hasorphans(&lfs2.gstate));
|
||||
// force consistency
|
||||
lfs2_fs_forceconsistency(&lfs2) => 0;
|
||||
// we should no longer have orphans
|
||||
assert(!lfs2_gstate_hasorphans(&lfs2.gstate));
|
||||
|
||||
lfs2_unmount(&lfs2) => 0;
|
||||
'''
|
||||
|
||||
# test that we can persist gstate with lfs2_fs_mkconsistent
|
||||
[cases.test_orphans_mkconsistent_no_orphans]
|
||||
in = 'lfs2.c'
|
||||
code = '''
|
||||
lfs2_t lfs2;
|
||||
lfs2_format(&lfs2, cfg) => 0;
|
||||
|
||||
lfs2_mount(&lfs2, cfg) => 0;
|
||||
// mark the filesystem as having orphans
|
||||
lfs2_fs_preporphans(&lfs2, +1) => 0;
|
||||
lfs2_mdir_t mdir;
|
||||
lfs2_dir_fetch(&lfs2, &mdir, (lfs2_block_t[2]){0, 1}) => 0;
|
||||
lfs2_dir_commit(&lfs2, &mdir, NULL, 0) => 0;
|
||||
|
||||
// we should have orphans at this state
|
||||
assert(lfs2_gstate_hasorphans(&lfs2.gstate));
|
||||
lfs2_unmount(&lfs2) => 0;
|
||||
|
||||
// mount
|
||||
lfs2_mount(&lfs2, cfg) => 0;
|
||||
// we should detect orphans
|
||||
assert(lfs2_gstate_hasorphans(&lfs2.gstate));
|
||||
// force consistency
|
||||
lfs2_fs_mkconsistent(&lfs2) => 0;
|
||||
// we should no longer have orphans
|
||||
assert(!lfs2_gstate_hasorphans(&lfs2.gstate));
|
||||
|
||||
// remount
|
||||
lfs2_unmount(&lfs2) => 0;
|
||||
lfs2_mount(&lfs2, cfg) => 0;
|
||||
// we should still have no orphans
|
||||
assert(!lfs2_gstate_hasorphans(&lfs2.gstate));
|
||||
lfs2_unmount(&lfs2) => 0;
|
||||
'''
|
||||
|
||||
[cases.test_orphans_mkconsistent_one_orphan]
|
||||
in = 'lfs2.c'
|
||||
code = '''
|
||||
lfs2_t lfs2;
|
||||
lfs2_format(&lfs2, cfg) => 0;
|
||||
|
||||
lfs2_mount(&lfs2, cfg) => 0;
|
||||
// create an orphan
|
||||
lfs2_mdir_t orphan;
|
||||
lfs2_alloc_ack(&lfs2);
|
||||
lfs2_dir_alloc(&lfs2, &orphan) => 0;
|
||||
lfs2_dir_commit(&lfs2, &orphan, NULL, 0) => 0;
|
||||
|
||||
// append our orphan and mark the filesystem as having orphans
|
||||
lfs2_fs_preporphans(&lfs2, +1) => 0;
|
||||
lfs2_mdir_t mdir;
|
||||
lfs2_dir_fetch(&lfs2, &mdir, (lfs2_block_t[2]){0, 1}) => 0;
|
||||
lfs2_pair_tole32(orphan.pair);
|
||||
lfs2_dir_commit(&lfs2, &mdir, LFS2_MKATTRS(
|
||||
{LFS2_MKTAG(LFS2_TYPE_SOFTTAIL, 0x3ff, 8), orphan.pair})) => 0;
|
||||
|
||||
// we should have orphans at this state
|
||||
assert(lfs2_gstate_hasorphans(&lfs2.gstate));
|
||||
lfs2_unmount(&lfs2) => 0;
|
||||
|
||||
// mount
|
||||
lfs2_mount(&lfs2, cfg) => 0;
|
||||
// we should detect orphans
|
||||
assert(lfs2_gstate_hasorphans(&lfs2.gstate));
|
||||
// force consistency
|
||||
lfs2_fs_mkconsistent(&lfs2) => 0;
|
||||
// we should no longer have orphans
|
||||
assert(!lfs2_gstate_hasorphans(&lfs2.gstate));
|
||||
|
||||
// remount
|
||||
lfs2_unmount(&lfs2) => 0;
|
||||
lfs2_mount(&lfs2, cfg) => 0;
|
||||
// we should still have no orphans
|
||||
assert(!lfs2_gstate_hasorphans(&lfs2.gstate));
|
||||
lfs2_unmount(&lfs2) => 0;
|
||||
'''
|
||||
|
||||
# reentrant testing for orphans, basically just spam mkdir/remove
|
||||
[cases.test_orphans_reentrant]
|
||||
reentrant = true
|
||||
# TODO fix this case, caused by non-DAG trees
|
||||
if = '!(DEPTH == 3 && LFS2_CACHE_SIZE != 64)'
|
||||
define = [
|
||||
if = '!(DEPTH == 3 && CACHE_SIZE != 64)'
|
||||
defines = [
|
||||
{FILES=6, DEPTH=1, CYCLES=20},
|
||||
{FILES=26, DEPTH=1, CYCLES=20},
|
||||
{FILES=3, DEPTH=3, CYCLES=20},
|
||||
]
|
||||
code = '''
|
||||
err = lfs2_mount(&lfs2, &cfg);
|
||||
lfs2_t lfs2;
|
||||
int err = lfs2_mount(&lfs2, cfg);
|
||||
if (err) {
|
||||
lfs2_format(&lfs2, &cfg) => 0;
|
||||
lfs2_mount(&lfs2, &cfg) => 0;
|
||||
lfs2_format(&lfs2, cfg) => 0;
|
||||
lfs2_mount(&lfs2, cfg) => 0;
|
||||
}
|
||||
|
||||
srand(1);
|
||||
uint32_t prng = 1;
|
||||
const char alpha[] = "abcdefghijklmnopqrstuvwxyz";
|
||||
for (int i = 0; i < CYCLES; i++) {
|
||||
for (unsigned i = 0; i < CYCLES; i++) {
|
||||
// create random path
|
||||
char full_path[256];
|
||||
for (int d = 0; d < DEPTH; d++) {
|
||||
sprintf(&full_path[2*d], "/%c", alpha[rand() % FILES]);
|
||||
for (unsigned d = 0; d < DEPTH; d++) {
|
||||
sprintf(&full_path[2*d], "/%c", alpha[TEST_PRNG(&prng) % FILES]);
|
||||
}
|
||||
|
||||
// if it does not exist, we create it, else we destroy
|
||||
struct lfs2_info info;
|
||||
int res = lfs2_stat(&lfs2, full_path, &info);
|
||||
if (res == LFS2_ERR_NOENT) {
|
||||
// create each directory in turn, ignore if dir already exists
|
||||
for (int d = 0; d < DEPTH; d++) {
|
||||
for (unsigned d = 0; d < DEPTH; d++) {
|
||||
char path[1024];
|
||||
strcpy(path, full_path);
|
||||
path[2*d+2] = '\0';
|
||||
err = lfs2_mkdir(&lfs2, path);
|
||||
assert(!err || err == LFS2_ERR_EXIST);
|
||||
}
|
||||
|
||||
for (int d = 0; d < DEPTH; d++) {
|
||||
for (unsigned d = 0; d < DEPTH; d++) {
|
||||
char path[1024];
|
||||
strcpy(path, full_path);
|
||||
path[2*d+2] = '\0';
|
||||
lfs2_stat(&lfs2, path, &info) => 0;
|
||||
@@ -106,6 +258,7 @@ code = '''
|
||||
|
||||
// try to delete path in reverse order, ignore if dir is not empty
|
||||
for (int d = DEPTH-1; d >= 0; d--) {
|
||||
char path[1024];
|
||||
strcpy(path, full_path);
|
||||
path[2*d+2] = '\0';
|
||||
err = lfs2_remove(&lfs2, path);
|
||||
|
||||
Reference in New Issue
Block a user