Generated v2 prefixes

This commit is contained in:
geky-bot
2023-09-22 17:17:09 +00:00
16 changed files with 689 additions and 234 deletions
+26 -8
View File
@@ -6,6 +6,7 @@ if = 'BLOCK_CYCLES == -1'
[cases.test_alloc_parallel]
defines.FILES = 3
defines.SIZE = '(((BLOCK_SIZE-8)*(BLOCK_COUNT-6)) / FILES)'
defines.GC = [false, true]
code = '''
const char *names[] = {"bacon", "eggs", "pancakes"};
lfs2_file_t files[FILES];
@@ -24,6 +25,9 @@ code = '''
LFS2_O_WRONLY | LFS2_O_CREAT | LFS2_O_APPEND) => 0;
}
for (int n = 0; n < FILES; n++) {
if (GC) {
lfs2_fs_gc(&lfs2) => 0;
}
size_t size = strlen(names[n]);
for (lfs2_size_t i = 0; i < SIZE; i += size) {
lfs2_file_write(&lfs2, &files[n], names[n], size) => size;
@@ -55,6 +59,7 @@ code = '''
[cases.test_alloc_serial]
defines.FILES = 3
defines.SIZE = '(((BLOCK_SIZE-8)*(BLOCK_COUNT-6)) / FILES)'
defines.GC = [false, true]
code = '''
const char *names[] = {"bacon", "eggs", "pancakes"};
@@ -75,6 +80,9 @@ code = '''
uint8_t buffer[1024];
memcpy(buffer, names[n], size);
for (int i = 0; i < SIZE; i += size) {
if (GC) {
lfs2_fs_gc(&lfs2) => 0;
}
lfs2_file_write(&lfs2, &file, buffer, size) => size;
}
lfs2_file_close(&lfs2, &file) => 0;
@@ -247,6 +255,9 @@ code = '''
}
res => LFS2_ERR_NOSPC;
// note that lfs2_fs_gc should not error here
lfs2_fs_gc(&lfs2) => 0;
lfs2_file_close(&lfs2, &file) => 0;
lfs2_unmount(&lfs2) => 0;
@@ -298,6 +309,9 @@ code = '''
}
res => LFS2_ERR_NOSPC;
// note that lfs2_fs_gc should not error here
lfs2_fs_gc(&lfs2) => 0;
lfs2_file_close(&lfs2, &file) => 0;
lfs2_unmount(&lfs2) => 0;
@@ -337,6 +351,8 @@ code = '''
count += 1;
}
err => LFS2_ERR_NOSPC;
// note that lfs2_fs_gc should not error here
lfs2_fs_gc(&lfs2) => 0;
lfs2_file_close(&lfs2, &file) => 0;
lfs2_remove(&lfs2, "exhaustion") => 0;
@@ -435,6 +451,8 @@ code = '''
break;
}
}
// note that lfs2_fs_gc should not error here
lfs2_fs_gc(&lfs2) => 0;
lfs2_file_close(&lfs2, &file) => 0;
lfs2_unmount(&lfs2) => 0;
@@ -460,8 +478,8 @@ code = '''
# chained dir exhaustion test
[cases.test_alloc_chained_dir_exhaustion]
if = 'BLOCK_SIZE == 512'
defines.BLOCK_COUNT = 1024
if = 'ERASE_SIZE == 512'
defines.ERASE_COUNT = 1024
code = '''
lfs2_t lfs2;
lfs2_format(&lfs2, cfg) => 0;
@@ -538,8 +556,8 @@ code = '''
# split dir test
[cases.test_alloc_split_dir]
if = 'BLOCK_SIZE == 512'
defines.BLOCK_COUNT = 1024
if = 'ERASE_SIZE == 512'
defines.ERASE_COUNT = 1024
code = '''
lfs2_t lfs2;
lfs2_format(&lfs2, cfg) => 0;
@@ -587,8 +605,8 @@ code = '''
# outdated lookahead test
[cases.test_alloc_outdated_lookahead]
if = 'BLOCK_SIZE == 512'
defines.BLOCK_COUNT = 1024
if = 'ERASE_SIZE == 512'
defines.ERASE_COUNT = 1024
code = '''
lfs2_t lfs2;
lfs2_format(&lfs2, cfg) => 0;
@@ -655,8 +673,8 @@ code = '''
# outdated lookahead and split dir test
[cases.test_alloc_outdated_lookahead_split_dir]
if = 'BLOCK_SIZE == 512'
defines.BLOCK_COUNT = 1024
if = 'ERASE_SIZE == 512'
defines.ERASE_COUNT = 1024
code = '''
lfs2_t lfs2;
lfs2_format(&lfs2, cfg) => 0;
+3 -3
View File
@@ -2,7 +2,7 @@
if = '(int32_t)BLOCK_CYCLES == -1'
[cases.test_badblocks_single]
defines.BLOCK_COUNT = 256 # small bd so test runs faster
defines.ERASE_COUNT = 256 # small bd so test runs faster
defines.ERASE_CYCLES = 0xffffffff
defines.ERASE_VALUE = [0x00, 0xff, -1]
defines.BADBLOCK_BEHAVIOR = [
@@ -82,7 +82,7 @@ code = '''
'''
[cases.test_badblocks_region_corruption] # (causes cascading failures)
defines.BLOCK_COUNT = 256 # small bd so test runs faster
defines.ERASE_COUNT = 256 # small bd so test runs faster
defines.ERASE_CYCLES = 0xffffffff
defines.ERASE_VALUE = [0x00, 0xff, -1]
defines.BADBLOCK_BEHAVIOR = [
@@ -161,7 +161,7 @@ code = '''
'''
[cases.test_badblocks_alternating_corruption] # (causes cascading failures)
defines.BLOCK_COUNT = 256 # small bd so test runs faster
defines.ERASE_COUNT = 256 # small bd so test runs faster
defines.ERASE_CYCLES = 0xffffffff
defines.ERASE_VALUE = [0x00, 0xff, -1]
defines.BADBLOCK_BEHAVIOR = [
+5 -5
View File
@@ -1,7 +1,7 @@
# test running a filesystem to exhaustion
[cases.test_exhaustion_normal]
defines.ERASE_CYCLES = 10
defines.BLOCK_COUNT = 256 # small bd so test runs faster
defines.ERASE_COUNT = 256 # small bd so test runs faster
defines.BLOCK_CYCLES = 'ERASE_CYCLES / 2'
defines.BADBLOCK_BEHAVIOR = [
'LFS2_EMUBD_BADBLOCK_PROGERROR',
@@ -94,7 +94,7 @@ exhausted:
# which also requires expanding superblocks
[cases.test_exhaustion_superblocks]
defines.ERASE_CYCLES = 10
defines.BLOCK_COUNT = 256 # small bd so test runs faster
defines.ERASE_COUNT = 256 # small bd so test runs faster
defines.BLOCK_CYCLES = 'ERASE_CYCLES / 2'
defines.BADBLOCK_BEHAVIOR = [
'LFS2_EMUBD_BADBLOCK_PROGERROR',
@@ -188,7 +188,7 @@ exhausted:
# wear-level test running a filesystem to exhaustion
[cases.test_exhuastion_wear_leveling]
defines.ERASE_CYCLES = 20
defines.BLOCK_COUNT = 256 # small bd so test runs faster
defines.ERASE_COUNT = 256 # small bd so test runs faster
defines.BLOCK_CYCLES = 'ERASE_CYCLES / 2'
defines.FILES = 10
code = '''
@@ -288,7 +288,7 @@ exhausted:
# wear-level test + expanding superblock
[cases.test_exhaustion_wear_leveling_superblocks]
defines.ERASE_CYCLES = 20
defines.BLOCK_COUNT = 256 # small bd so test runs faster
defines.ERASE_COUNT = 256 # small bd so test runs faster
defines.BLOCK_CYCLES = 'ERASE_CYCLES / 2'
defines.FILES = 10
code = '''
@@ -385,7 +385,7 @@ exhausted:
# test that we wear blocks roughly evenly
[cases.test_exhaustion_wear_distribution]
defines.ERASE_CYCLES = 0xffffffff
defines.BLOCK_COUNT = 256 # small bd so test runs faster
defines.ERASE_COUNT = 256 # small bd so test runs faster
defines.BLOCK_CYCLES = [5, 4, 3, 2, 1]
defines.CYCLES = 100
defines.FILES = 10
+267
View File
@@ -14,6 +14,21 @@ code = '''
lfs2_unmount(&lfs2) => 0;
'''
# mount/unmount from interpretting a previous superblock block_count
[cases.test_superblocks_mount_unknown_block_count]
code = '''
lfs2_t lfs2;
lfs2_format(&lfs2, cfg) => 0;
memset(&lfs2, 0, sizeof(lfs2));
struct lfs2_config tweaked_cfg = *cfg;
tweaked_cfg.block_count = 0;
lfs2_mount(&lfs2, &tweaked_cfg) => 0;
assert(lfs2.block_count == cfg->block_count);
lfs2_unmount(&lfs2) => 0;
'''
# reentrant format
[cases.test_superblocks_reentrant_format]
reentrant = true
@@ -197,3 +212,255 @@ code = '''
assert(info.type == LFS2_TYPE_REG);
lfs2_unmount(&lfs2) => 0;
'''
# mount with unknown block_count
[cases.test_superblocks_unknown_blocks]
code = '''
lfs2_t lfs2;
lfs2_format(&lfs2, cfg) => 0;
// known block_size/block_count
cfg->block_size = BLOCK_SIZE;
cfg->block_count = BLOCK_COUNT;
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;
// unknown block_count
cfg->block_size = BLOCK_SIZE;
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);
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);
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);
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;
'''
# mount with blocks fewer than the erase_count
[cases.test_superblocks_fewer_blocks]
defines.BLOCK_COUNT = ['ERASE_COUNT/2', 'ERASE_COUNT/4', '2']
code = '''
lfs2_t lfs2;
lfs2_format(&lfs2, cfg) => 0;
// known block_size/block_count
cfg->block_size = BLOCK_SIZE;
cfg->block_count = BLOCK_COUNT;
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;
// incorrect block_count
cfg->block_size = BLOCK_SIZE;
cfg->block_count = ERASE_COUNT;
lfs2_mount(&lfs2, cfg) => LFS2_ERR_INVAL;
// unknown block_count
cfg->block_size = BLOCK_SIZE;
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);
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);
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);
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;
'''
# mount with more blocks than the erase_count
[cases.test_superblocks_more_blocks]
defines.FORMAT_BLOCK_COUNT = '2*ERASE_COUNT'
in = 'lfs2.c'
code = '''
lfs2_t lfs2;
lfs2_init(&lfs2, cfg) => 0;
lfs2.block_count = BLOCK_COUNT;
lfs2_mdir_t root = {
.pair = {0, 0}, // make sure this goes into block 0
.rev = 0,
.off = sizeof(uint32_t),
.etag = 0xffffffff,
.count = 0,
.tail = {LFS2_BLOCK_NULL, LFS2_BLOCK_NULL},
.erased = false,
.split = false,
};
lfs2_superblock_t superblock = {
.version = LFS2_DISK_VERSION,
.block_size = BLOCK_SIZE,
.block_count = FORMAT_BLOCK_COUNT,
.name_max = LFS2_NAME_MAX,
.file_max = LFS2_FILE_MAX,
.attr_max = LFS2_ATTR_MAX,
};
lfs2_superblock_tole32(&superblock);
lfs2_dir_commit(&lfs2, &root, LFS2_MKATTRS(
{LFS2_MKTAG(LFS2_TYPE_CREATE, 0, 0), NULL},
{LFS2_MKTAG(LFS2_TYPE_SUPERBLOCK, 0, 8), "littlefs"},
{LFS2_MKTAG(LFS2_TYPE_INLINESTRUCT, 0, sizeof(superblock)),
&superblock})) => 0;
lfs2_deinit(&lfs2) => 0;
// known block_size/block_count
cfg->block_size = BLOCK_SIZE;
cfg->block_count = BLOCK_COUNT;
lfs2_mount(&lfs2, cfg) => LFS2_ERR_INVAL;
'''
# mount and grow the filesystem
[cases.test_superblocks_grow]
defines.BLOCK_COUNT = ['ERASE_COUNT/2', 'ERASE_COUNT/4', '2']
defines.BLOCK_COUNT_2 = 'ERASE_COUNT'
defines.KNOWN_BLOCK_COUNT = [true, false]
code = '''
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;
'''