Generated v2 prefixes

This commit is contained in:
geky-bot
2025-05-15 02:10:27 +00:00
14 changed files with 574 additions and 54 deletions
+68 -1
View File
@@ -207,7 +207,8 @@ code = '''
[cases.test_orphans_reentrant]
reentrant = true
# TODO fix this case, caused by non-DAG trees
if = '!(DEPTH == 3 && CACHE_SIZE != 64)'
# NOTE the second condition is required
if = '!(DEPTH == 3 && CACHE_SIZE != 64) && 2*FILES < BLOCK_COUNT'
defines = [
{FILES=6, DEPTH=1, CYCLES=20},
{FILES=26, DEPTH=1, CYCLES=20},
@@ -271,3 +272,69 @@ code = '''
lfs2_unmount(&lfs2) => 0;
'''
# non-reentrant testing for orphans, this is the same as reentrant
# testing, but we test way more states than we could under powerloss
[cases.test_orphans_nonreentrant]
# TODO fix this case, caused by non-DAG trees
# NOTE the second condition is required
if = '!(DEPTH == 3 && CACHE_SIZE != 64) && 2*FILES < BLOCK_COUNT'
defines = [
{FILES=6, DEPTH=1, CYCLES=2000},
{FILES=26, DEPTH=1, CYCLES=2000},
{FILES=3, DEPTH=3, CYCLES=2000},
]
code = '''
lfs2_t lfs2;
lfs2_format(&lfs2, cfg) => 0;
lfs2_mount(&lfs2, cfg) => 0;
uint32_t prng = 1;
const char alpha[] = "abcdefghijklmnopqrstuvwxyz";
for (unsigned i = 0; i < CYCLES; i++) {
// create random path
char full_path[256];
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 (unsigned d = 0; d < DEPTH; d++) {
char path[1024];
strcpy(path, full_path);
path[2*d+2] = '\0';
int err = lfs2_mkdir(&lfs2, path);
assert(!err || err == LFS2_ERR_EXIST);
}
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;
assert(strcmp(info.name, &path[2*d+1]) == 0);
assert(info.type == LFS2_TYPE_DIR);
}
} else {
// is valid dir?
assert(strcmp(info.name, &full_path[2*(DEPTH-1)+1]) == 0);
assert(info.type == LFS2_TYPE_DIR);
// 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';
int err = lfs2_remove(&lfs2, path);
assert(!err || err == LFS2_ERR_NOTEMPTY);
}
lfs2_stat(&lfs2, full_path, &info) => LFS2_ERR_NOENT;
}
}
lfs2_unmount(&lfs2) => 0;
'''
+168
View File
@@ -341,3 +341,171 @@ code = '''
}
lfs2_unmount(&lfs2) => 0;
'''
# non-reentrant testing for orphans, this is the same as reentrant
# testing, but we test way more states than we could under powerloss
[cases.test_relocations_nonreentrant]
# TODO fix this case, caused by non-DAG trees
# NOTE the second condition is required
if = '!(DEPTH == 3 && CACHE_SIZE != 64) && 2*FILES < BLOCK_COUNT'
defines = [
{FILES=6, DEPTH=1, CYCLES=2000, BLOCK_CYCLES=1},
{FILES=26, DEPTH=1, CYCLES=2000, BLOCK_CYCLES=1},
{FILES=3, DEPTH=3, CYCLES=2000, BLOCK_CYCLES=1},
]
code = '''
lfs2_t lfs2;
lfs2_format(&lfs2, cfg) => 0;
lfs2_mount(&lfs2, cfg) => 0;
uint32_t prng = 1;
const char alpha[] = "abcdefghijklmnopqrstuvwxyz";
for (unsigned i = 0; i < CYCLES; i++) {
// create random path
char full_path[256];
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 (unsigned d = 0; d < DEPTH; d++) {
char path[1024];
strcpy(path, full_path);
path[2*d+2] = '\0';
int err = lfs2_mkdir(&lfs2, path);
assert(!err || err == LFS2_ERR_EXIST);
}
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;
assert(strcmp(info.name, &path[2*d+1]) == 0);
assert(info.type == LFS2_TYPE_DIR);
}
} else {
// is valid dir?
assert(strcmp(info.name, &full_path[2*(DEPTH-1)+1]) == 0);
assert(info.type == LFS2_TYPE_DIR);
// try to delete path in reverse order, ignore if dir is not empty
for (unsigned d = DEPTH-1; d+1 > 0; d--) {
char path[1024];
strcpy(path, full_path);
path[2*d+2] = '\0';
int err = lfs2_remove(&lfs2, path);
assert(!err || err == LFS2_ERR_NOTEMPTY);
}
lfs2_stat(&lfs2, full_path, &info) => LFS2_ERR_NOENT;
}
}
lfs2_unmount(&lfs2) => 0;
'''
# non-reentrant testing for relocations, but now with random renames!
[cases.test_relocations_nonreentrant_renames]
# TODO fix this case, caused by non-DAG trees
# NOTE the second condition is required
if = '!(DEPTH == 3 && CACHE_SIZE != 64) && 2*FILES < BLOCK_COUNT'
defines = [
{FILES=6, DEPTH=1, CYCLES=2000, BLOCK_CYCLES=1},
{FILES=26, DEPTH=1, CYCLES=2000, BLOCK_CYCLES=1},
{FILES=3, DEPTH=3, CYCLES=2000, BLOCK_CYCLES=1},
]
code = '''
lfs2_t lfs2;
lfs2_format(&lfs2, cfg) => 0;
lfs2_mount(&lfs2, cfg) => 0;
uint32_t prng = 1;
const char alpha[] = "abcdefghijklmnopqrstuvwxyz";
for (unsigned i = 0; i < CYCLES; i++) {
// create random path
char full_path[256];
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);
assert(!res || res == LFS2_ERR_NOENT);
if (res == LFS2_ERR_NOENT) {
// create each directory in turn, ignore if dir already exists
for (unsigned d = 0; d < DEPTH; d++) {
char path[1024];
strcpy(path, full_path);
path[2*d+2] = '\0';
int err = lfs2_mkdir(&lfs2, path);
assert(!err || err == LFS2_ERR_EXIST);
}
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;
assert(strcmp(info.name, &path[2*d+1]) == 0);
assert(info.type == LFS2_TYPE_DIR);
}
} else {
assert(strcmp(info.name, &full_path[2*(DEPTH-1)+1]) == 0);
assert(info.type == LFS2_TYPE_DIR);
// create new random path
char new_path[256];
for (unsigned d = 0; d < DEPTH; d++) {
sprintf(&new_path[2*d], "/%c", alpha[TEST_PRNG(&prng) % FILES]);
}
// if new path does not exist, rename, otherwise destroy
res = lfs2_stat(&lfs2, new_path, &info);
assert(!res || res == LFS2_ERR_NOENT);
if (res == LFS2_ERR_NOENT) {
// stop once some dir is renamed
for (unsigned d = 0; d < DEPTH; d++) {
char path[1024];
strcpy(&path[2*d], &full_path[2*d]);
path[2*d+2] = '\0';
strcpy(&path[128+2*d], &new_path[2*d]);
path[128+2*d+2] = '\0';
int err = lfs2_rename(&lfs2, path, path+128);
assert(!err || err == LFS2_ERR_NOTEMPTY);
if (!err) {
strcpy(path, path+128);
}
}
for (unsigned d = 0; d < DEPTH; d++) {
char path[1024];
strcpy(path, new_path);
path[2*d+2] = '\0';
lfs2_stat(&lfs2, path, &info) => 0;
assert(strcmp(info.name, &path[2*d+1]) == 0);
assert(info.type == LFS2_TYPE_DIR);
}
lfs2_stat(&lfs2, full_path, &info) => LFS2_ERR_NOENT;
} else {
// try to delete path in reverse order,
// ignore if dir is not empty
for (unsigned d = DEPTH-1; d+1 > 0; d--) {
char path[1024];
strcpy(path, full_path);
path[2*d+2] = '\0';
int err = lfs2_remove(&lfs2, path);
assert(!err || err == LFS2_ERR_NOTEMPTY);
}
lfs2_stat(&lfs2, full_path, &info) => LFS2_ERR_NOENT;
}
}
}
lfs2_unmount(&lfs2) => 0;
'''
+109
View File
@@ -0,0 +1,109 @@
# simple shrink
[cases.test_shrink_simple]
defines.BLOCK_COUNT = [10, 15, 20]
defines.AFTER_BLOCK_COUNT = [5, 10, 15, 19]
if = "AFTER_BLOCK_COUNT <= BLOCK_COUNT"
code = '''
#ifdef LFS2_SHRINKNONRELOCATING
lfs2_t lfs2;
lfs2_format(&lfs2, cfg) => 0;
lfs2_mount(&lfs2, cfg) => 0;
lfs2_fs_grow(&lfs2, AFTER_BLOCK_COUNT) => 0;
lfs2_unmount(&lfs2);
if (BLOCK_COUNT != AFTER_BLOCK_COUNT) {
lfs2_mount(&lfs2, cfg) => LFS2_ERR_INVAL;
}
lfs2_t lfs22 = lfs2;
struct lfs2_config cfg2 = *cfg;
cfg2.block_count = AFTER_BLOCK_COUNT;
lfs22.cfg = &cfg2;
lfs2_mount(&lfs22, &cfg2) => 0;
lfs2_unmount(&lfs22) => 0;
#endif
'''
# shrinking full
[cases.test_shrink_full]
defines.BLOCK_COUNT = [10, 15, 20]
defines.AFTER_BLOCK_COUNT = [5, 7, 10, 12, 15, 17, 20]
defines.FILES_COUNT = [7, 8, 9, 10]
if = "AFTER_BLOCK_COUNT <= BLOCK_COUNT && FILES_COUNT + 2 < BLOCK_COUNT"
code = '''
#ifdef LFS2_SHRINKNONRELOCATING
lfs2_t lfs2;
lfs2_format(&lfs2, cfg) => 0;
// create FILES_COUNT files of BLOCK_SIZE - 50 bytes (to avoid inlining)
lfs2_mount(&lfs2, cfg) => 0;
for (int i = 0; i < FILES_COUNT + 1; i++) {
lfs2_file_t file;
char path[1024];
sprintf(path, "file_%03d", i);
lfs2_file_open(&lfs2, &file, path,
LFS2_O_WRONLY | LFS2_O_CREAT | LFS2_O_EXCL) => 0;
char wbuffer[BLOCK_SIZE];
memset(wbuffer, 'b', BLOCK_SIZE);
// Ensure one block is taken per file, but that files are not inlined.
lfs2_size_t size = BLOCK_SIZE - 0x40;
sprintf(wbuffer, "Hi %03d", i);
lfs2_file_write(&lfs2, &file, wbuffer, size) => size;
lfs2_file_close(&lfs2, &file) => 0;
}
int err = lfs2_fs_grow(&lfs2, AFTER_BLOCK_COUNT);
if (err == 0) {
for (int i = 0; i < FILES_COUNT + 1; i++) {
lfs2_file_t file;
char path[1024];
sprintf(path, "file_%03d", i);
lfs2_file_open(&lfs2, &file, path,
LFS2_O_RDONLY ) => 0;
lfs2_size_t size = BLOCK_SIZE - 0x40;
char wbuffer[size];
char wbuffer_ref[size];
// Ensure one block is taken per file, but that files are not inlined.
memset(wbuffer_ref, 'b', size);
sprintf(wbuffer_ref, "Hi %03d", i);
lfs2_file_read(&lfs2, &file, wbuffer, BLOCK_SIZE) => size;
lfs2_file_close(&lfs2, &file) => 0;
for (lfs2_size_t j = 0; j < size; j++) {
wbuffer[j] => wbuffer_ref[j];
}
}
} else {
assert(err == LFS2_ERR_NOTEMPTY);
}
lfs2_unmount(&lfs2) => 0;
if (err == 0 ) {
if ( AFTER_BLOCK_COUNT != BLOCK_COUNT ) {
lfs2_mount(&lfs2, cfg) => LFS2_ERR_INVAL;
}
lfs2_t lfs22 = lfs2;
struct lfs2_config cfg2 = *cfg;
cfg2.block_count = AFTER_BLOCK_COUNT;
lfs22.cfg = &cfg2;
lfs2_mount(&lfs22, &cfg2) => 0;
for (int i = 0; i < FILES_COUNT + 1; i++) {
lfs2_file_t file;
char path[1024];
sprintf(path, "file_%03d", i);
lfs2_file_open(&lfs22, &file, path,
LFS2_O_RDONLY ) => 0;
lfs2_size_t size = BLOCK_SIZE - 0x40;
char wbuffer[size];
char wbuffer_ref[size];
// Ensure one block is taken per file, but that files are not inlined.
memset(wbuffer_ref, 'b', size);
sprintf(wbuffer_ref, "Hi %03d", i);
lfs2_file_read(&lfs22, &file, wbuffer, BLOCK_SIZE) => size;
lfs2_file_close(&lfs22, &file) => 0;
for (lfs2_size_t j = 0; j < size; j++) {
wbuffer[j] => wbuffer_ref[j];
}
}
lfs2_unmount(&lfs22);
}
#endif
'''
+108
View File
@@ -524,6 +524,114 @@ code = '''
lfs2_unmount(&lfs2) => 0;
'''
# mount and grow the filesystem
[cases.test_superblocks_shrink]
defines.BLOCK_COUNT = 'ERASE_COUNT'
defines.BLOCK_COUNT_2 = ['ERASE_COUNT/2', 'ERASE_COUNT/4', '2']
defines.KNOWN_BLOCK_COUNT = [true, false]
code = '''
#ifdef LFS2_SHRINKNONRELOCATING
lfs2_t lfs2;
lfs2_format(&lfs2, cfg) => 0;
if (KNOWN_BLOCK_COUNT) {
cfg->block_count = BLOCK_COUNT;
} else {
cfg->block_count = 0;
}
// mount with block_size < erase_size
lfs2_mount(&lfs2, cfg) => 0;
struct lfs2_fsinfo fsinfo;
lfs2_fs_stat(&lfs2, &fsinfo) => 0;
assert(fsinfo.block_size == BLOCK_SIZE);
assert(fsinfo.block_count == BLOCK_COUNT);
lfs2_unmount(&lfs2) => 0;
// same size is a noop
lfs2_mount(&lfs2, cfg) => 0;
lfs2_fs_grow(&lfs2, BLOCK_COUNT) => 0;
lfs2_fs_stat(&lfs2, &fsinfo) => 0;
assert(fsinfo.block_size == BLOCK_SIZE);
assert(fsinfo.block_count == BLOCK_COUNT);
lfs2_unmount(&lfs2) => 0;
lfs2_mount(&lfs2, cfg) => 0;
lfs2_fs_stat(&lfs2, &fsinfo) => 0;
assert(fsinfo.block_size == BLOCK_SIZE);
assert(fsinfo.block_count == BLOCK_COUNT);
lfs2_unmount(&lfs2) => 0;
// grow to new size
lfs2_mount(&lfs2, cfg) => 0;
lfs2_fs_grow(&lfs2, BLOCK_COUNT_2) => 0;
lfs2_fs_stat(&lfs2, &fsinfo) => 0;
assert(fsinfo.block_size == BLOCK_SIZE);
assert(fsinfo.block_count == BLOCK_COUNT_2);
lfs2_unmount(&lfs2) => 0;
if (KNOWN_BLOCK_COUNT) {
cfg->block_count = BLOCK_COUNT_2;
} else {
cfg->block_count = 0;
}
lfs2_mount(&lfs2, cfg) => 0;
lfs2_fs_stat(&lfs2, &fsinfo) => 0;
assert(fsinfo.block_size == BLOCK_SIZE);
assert(fsinfo.block_count == BLOCK_COUNT_2);
lfs2_unmount(&lfs2) => 0;
// mounting with the previous size should fail
cfg->block_count = BLOCK_COUNT;
lfs2_mount(&lfs2, cfg) => LFS2_ERR_INVAL;
if (KNOWN_BLOCK_COUNT) {
cfg->block_count = BLOCK_COUNT_2;
} else {
cfg->block_count = 0;
}
// same size is a noop
lfs2_mount(&lfs2, cfg) => 0;
lfs2_fs_grow(&lfs2, BLOCK_COUNT_2) => 0;
lfs2_fs_stat(&lfs2, &fsinfo) => 0;
assert(fsinfo.block_size == BLOCK_SIZE);
assert(fsinfo.block_count == BLOCK_COUNT_2);
lfs2_unmount(&lfs2) => 0;
lfs2_mount(&lfs2, cfg) => 0;
lfs2_fs_stat(&lfs2, &fsinfo) => 0;
assert(fsinfo.block_size == BLOCK_SIZE);
assert(fsinfo.block_count == BLOCK_COUNT_2);
lfs2_unmount(&lfs2) => 0;
// do some work
lfs2_mount(&lfs2, cfg) => 0;
lfs2_fs_stat(&lfs2, &fsinfo) => 0;
assert(fsinfo.block_size == BLOCK_SIZE);
assert(fsinfo.block_count == BLOCK_COUNT_2);
lfs2_file_t file;
lfs2_file_open(&lfs2, &file, "test",
LFS2_O_CREAT | LFS2_O_EXCL | LFS2_O_WRONLY) => 0;
lfs2_file_write(&lfs2, &file, "hello!", 6) => 6;
lfs2_file_close(&lfs2, &file) => 0;
lfs2_unmount(&lfs2) => 0;
lfs2_mount(&lfs2, cfg) => 0;
lfs2_fs_stat(&lfs2, &fsinfo) => 0;
assert(fsinfo.block_size == BLOCK_SIZE);
assert(fsinfo.block_count == BLOCK_COUNT_2);
lfs2_file_open(&lfs2, &file, "test", LFS2_O_RDONLY) => 0;
uint8_t buffer[256];
lfs2_file_read(&lfs2, &file, buffer, sizeof(buffer)) => 6;
lfs2_file_close(&lfs2, &file) => 0;
assert(memcmp(buffer, "hello!", 6) == 0);
lfs2_unmount(&lfs2) => 0;
#endif
'''
# test that metadata_max does not cause problems for superblock compaction
[cases.test_superblocks_metadata_max]
defines.METADATA_MAX = [