5181ce66cd
Both test_move and test_orphan needed internal knowledge which comes with the addition of the "in" attribute. This was in the plan for the test-revamp from the beginning as it really opens up the ability to write more unit-style-tests using internal knowledge of how littlefs works. More unit-style-tests should help _fix_ bugs by limiting the scope of the test and where the bug could be hiding. The "in" attribute effectively runs tests _inside_ the .c file specified, giving the test access to all static members without needed to change their visibility.
106 lines
2.7 KiB
TOML
106 lines
2.7 KiB
TOML
[[case]] # simple formatting test
|
|
code = '''
|
|
lfs_format(&lfs, &cfg) => 0;
|
|
'''
|
|
|
|
[[case]] # mount/unmount
|
|
code = '''
|
|
lfs_format(&lfs, &cfg) => 0;
|
|
lfs_mount(&lfs, &cfg) => 0;
|
|
lfs_unmount(&lfs) => 0;
|
|
'''
|
|
|
|
[[case]] # reentrant format
|
|
reentrant = true
|
|
code = '''
|
|
err = lfs_mount(&lfs, &cfg);
|
|
if (err) {
|
|
lfs_format(&lfs, &cfg) => 0;
|
|
lfs_mount(&lfs, &cfg) => 0;
|
|
}
|
|
lfs_unmount(&lfs) => 0;
|
|
'''
|
|
|
|
[[case]] # invalid mount
|
|
code = '''
|
|
lfs_mount(&lfs, &cfg) => LFS_ERR_CORRUPT;
|
|
'''
|
|
|
|
# TODO invalid superblock? (corrupt 1, 0)
|
|
|
|
[[case]] # expanding superblock
|
|
define.BLOCK_CYCLES = [32, 33, 1]
|
|
define.N = [10, 100, 1000]
|
|
code = '''
|
|
lfs_format(&lfs, &cfg) => 0;
|
|
lfs_mount(&lfs, &cfg) => 0;
|
|
for (int i = 0; i < N; i++) {
|
|
lfs_mkdir(&lfs, "dummy") => 0;
|
|
lfs_stat(&lfs, "dummy", &info) => 0;
|
|
assert(strcmp(info.name, "dummy") == 0);
|
|
lfs_remove(&lfs, "dummy") => 0;
|
|
}
|
|
lfs_unmount(&lfs) => 0;
|
|
|
|
// one last check after power-cycle
|
|
lfs_mount(&lfs, &cfg) => 0;
|
|
lfs_mkdir(&lfs, "dummy") => 0;
|
|
lfs_stat(&lfs, "dummy", &info) => 0;
|
|
assert(strcmp(info.name, "dummy") == 0);
|
|
lfs_unmount(&lfs) => 0;
|
|
'''
|
|
|
|
[[case]] # expanding superblock with power cycle
|
|
define.BLOCK_CYCLES = [32, 33, 1]
|
|
define.N = [10, 100, 1000]
|
|
code = '''
|
|
lfs_format(&lfs, &cfg) => 0;
|
|
for (int i = 0; i < N; i++) {
|
|
lfs_mount(&lfs, &cfg) => 0;
|
|
// remove lingering dummy?
|
|
err = lfs_remove(&lfs, "dummy");
|
|
assert(err == 0 || (err == LFS_ERR_NOENT && i == 0));
|
|
|
|
lfs_mkdir(&lfs, "dummy") => 0;
|
|
lfs_stat(&lfs, "dummy", &info) => 0;
|
|
assert(strcmp(info.name, "dummy") == 0);
|
|
lfs_unmount(&lfs) => 0;
|
|
}
|
|
|
|
// one last check after power-cycle
|
|
lfs_mount(&lfs, &cfg) => 0;
|
|
lfs_stat(&lfs, "dummy", &info) => 0;
|
|
assert(strcmp(info.name, "dummy") == 0);
|
|
lfs_unmount(&lfs) => 0;
|
|
'''
|
|
|
|
[[case]] # reentrant expanding superblock
|
|
define.BLOCK_CYCLES = [2, 1]
|
|
define.N = 24
|
|
reentrant = true
|
|
code = '''
|
|
err = lfs_mount(&lfs, &cfg);
|
|
if (err) {
|
|
lfs_format(&lfs, &cfg) => 0;
|
|
lfs_mount(&lfs, &cfg) => 0;
|
|
}
|
|
|
|
for (int i = 0; i < N; i++) {
|
|
// remove lingering dummy?
|
|
err = lfs_remove(&lfs, "dummy");
|
|
assert(err == 0 || (err == LFS_ERR_NOENT && i == 0));
|
|
|
|
lfs_mkdir(&lfs, "dummy") => 0;
|
|
lfs_stat(&lfs, "dummy", &info) => 0;
|
|
assert(strcmp(info.name, "dummy") == 0);
|
|
}
|
|
|
|
lfs_unmount(&lfs) => 0;
|
|
|
|
// one last check after power-cycle
|
|
lfs_mount(&lfs, &cfg) => 0;
|
|
lfs_stat(&lfs, "dummy", &info) => 0;
|
|
assert(strcmp(info.name, "dummy") == 0);
|
|
lfs_unmount(&lfs) => 0;
|
|
'''
|