Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/littlefs-project/littlefs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Haster <geky@geky.net>2022-11-12 23:31:52 +0300
committerChristopher Haster <geky@geky.net>2023-09-12 09:14:39 +0300
commit127d84b68146490730c2648bff533a3969add267 (patch)
treeeacfae05f56b4fcdd80cd008139bb67497d035d1
parent027331b2f094d1327b23c25054ddaae652d30ea2 (diff)
Added a couple mixed/unknown block_count tests
These were cherry-picked from some previous work on a related feature.
-rw-r--r--tests/test_superblocks.toml147
1 files changed, 147 insertions, 0 deletions
diff --git a/tests/test_superblocks.toml b/tests/test_superblocks.toml
index 99e1dad..a99a5a4 100644
--- a/tests/test_superblocks.toml
+++ b/tests/test_superblocks.toml
@@ -212,3 +212,150 @@ code = '''
assert(info.type == LFS_TYPE_REG);
lfs_unmount(&lfs) => 0;
'''
+
+# mount with unknown block_count
+[cases.test_superblocks_unknown_blocks]
+code = '''
+ lfs_t lfs;
+ lfs_format(&lfs, cfg) => 0;
+
+ // known block_size/block_count
+ cfg->block_size = BLOCK_SIZE;
+ cfg->block_count = BLOCK_COUNT;
+ lfs_mount(&lfs, cfg) => 0;
+ struct lfs_fsinfo fsinfo;
+ lfs_fs_stat(&lfs, &fsinfo) => 0;
+ assert(fsinfo.block_size == BLOCK_SIZE);
+ assert(fsinfo.block_count == BLOCK_COUNT);
+ lfs_unmount(&lfs) => 0;
+
+ // unknown block_count
+ cfg->block_size = BLOCK_SIZE;
+ cfg->block_count = 0;
+ lfs_mount(&lfs, cfg) => 0;
+ lfs_fs_stat(&lfs, &fsinfo) => 0;
+ assert(fsinfo.block_size == BLOCK_SIZE);
+ assert(fsinfo.block_count == BLOCK_COUNT);
+ lfs_unmount(&lfs) => 0;
+
+ // do some work
+ lfs_mount(&lfs, cfg) => 0;
+ lfs_fs_stat(&lfs, &fsinfo) => 0;
+ assert(fsinfo.block_size == BLOCK_SIZE);
+ assert(fsinfo.block_count == BLOCK_COUNT);
+ lfs_file_t file;
+ lfs_file_open(&lfs, &file, "test",
+ LFS_O_CREAT | LFS_O_EXCL | LFS_O_WRONLY) => 0;
+ lfs_file_write(&lfs, &file, "hello!", 6) => 6;
+ lfs_file_close(&lfs, &file) => 0;
+ lfs_unmount(&lfs) => 0;
+
+ lfs_mount(&lfs, cfg) => 0;
+ lfs_fs_stat(&lfs, &fsinfo) => 0;
+ assert(fsinfo.block_size == BLOCK_SIZE);
+ assert(fsinfo.block_count == BLOCK_COUNT);
+ lfs_file_open(&lfs, &file, "test", LFS_O_RDONLY) => 0;
+ uint8_t buffer[256];
+ lfs_file_read(&lfs, &file, buffer, sizeof(buffer)) => 6;
+ lfs_file_close(&lfs, &file) => 0;
+ assert(memcmp(buffer, "hello!", 6) == 0);
+ lfs_unmount(&lfs) => 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 = '''
+ lfs_t lfs;
+ lfs_format(&lfs, cfg) => 0;
+
+ // known block_size/block_count
+ cfg->block_size = BLOCK_SIZE;
+ cfg->block_count = BLOCK_COUNT;
+ lfs_mount(&lfs, cfg) => 0;
+ struct lfs_fsinfo fsinfo;
+ lfs_fs_stat(&lfs, &fsinfo) => 0;
+ assert(fsinfo.block_size == BLOCK_SIZE);
+ assert(fsinfo.block_count == BLOCK_COUNT);
+ lfs_unmount(&lfs) => 0;
+
+ // incorrect block_count
+ cfg->block_size = BLOCK_SIZE;
+ cfg->block_count = ERASE_COUNT;
+ lfs_mount(&lfs, cfg) => LFS_ERR_INVAL;
+
+ // unknown block_count
+ cfg->block_size = BLOCK_SIZE;
+ cfg->block_count = 0;
+ lfs_mount(&lfs, cfg) => 0;
+ lfs_fs_stat(&lfs, &fsinfo) => 0;
+ assert(fsinfo.block_size == BLOCK_SIZE);
+ assert(fsinfo.block_count == BLOCK_COUNT);
+ lfs_unmount(&lfs) => 0;
+
+ // do some work
+ lfs_mount(&lfs, cfg) => 0;
+ lfs_fs_stat(&lfs, &fsinfo) => 0;
+ assert(fsinfo.block_size == BLOCK_SIZE);
+ assert(fsinfo.block_count == BLOCK_COUNT);
+ lfs_file_t file;
+ lfs_file_open(&lfs, &file, "test",
+ LFS_O_CREAT | LFS_O_EXCL | LFS_O_WRONLY) => 0;
+ lfs_file_write(&lfs, &file, "hello!", 6) => 6;
+ lfs_file_close(&lfs, &file) => 0;
+ lfs_unmount(&lfs) => 0;
+
+ lfs_mount(&lfs, cfg) => 0;
+ lfs_fs_stat(&lfs, &fsinfo) => 0;
+ assert(fsinfo.block_size == BLOCK_SIZE);
+ assert(fsinfo.block_count == BLOCK_COUNT);
+ lfs_file_open(&lfs, &file, "test", LFS_O_RDONLY) => 0;
+ uint8_t buffer[256];
+ lfs_file_read(&lfs, &file, buffer, sizeof(buffer)) => 6;
+ lfs_file_close(&lfs, &file) => 0;
+ assert(memcmp(buffer, "hello!", 6) == 0);
+ lfs_unmount(&lfs) => 0;
+'''
+
+# mount with more blocks than the erase_count
+[cases.test_superblocks_more_blocks]
+defines.FORMAT_BLOCK_COUNT = '2*ERASE_COUNT'
+in = 'lfs.c'
+code = '''
+ lfs_t lfs;
+ lfs_init(&lfs, cfg) => 0;
+ lfs.block_count = BLOCK_COUNT;
+
+ lfs_mdir_t root = {
+ .pair = {0, 0}, // make sure this goes into block 0
+ .rev = 0,
+ .off = sizeof(uint32_t),
+ .etag = 0xffffffff,
+ .count = 0,
+ .tail = {LFS_BLOCK_NULL, LFS_BLOCK_NULL},
+ .erased = false,
+ .split = false,
+ };
+
+ lfs_superblock_t superblock = {
+ .version = LFS_DISK_VERSION,
+ .block_size = BLOCK_SIZE,
+ .block_count = FORMAT_BLOCK_COUNT,
+ .name_max = LFS_NAME_MAX,
+ .file_max = LFS_FILE_MAX,
+ .attr_max = LFS_ATTR_MAX,
+ };
+
+ lfs_superblock_tole32(&superblock);
+ lfs_dir_commit(&lfs, &root, LFS_MKATTRS(
+ {LFS_MKTAG(LFS_TYPE_CREATE, 0, 0), NULL},
+ {LFS_MKTAG(LFS_TYPE_SUPERBLOCK, 0, 8), "littlefs"},
+ {LFS_MKTAG(LFS_TYPE_INLINESTRUCT, 0, sizeof(superblock)),
+ &superblock})) => 0;
+ lfs_deinit(&lfs) => 0;
+
+ // known block_size/block_count
+ cfg->block_size = BLOCK_SIZE;
+ cfg->block_count = BLOCK_COUNT;
+ lfs_mount(&lfs, cfg) => LFS_ERR_INVAL;
+'''