Extended alloc tests to test some properties of lfs_fs_findfreeblocks

- Test that the code actually runs.

- Test that lfs_fs_findfreeblocks does not break block allocations.

- Test that lfs_fs_findfreeblocks does not error when no space is
  available, it should only errors when the block is actually needed.
This commit is contained in:
Christopher Haster
2023-09-11 23:56:49 -05:00
parent dbe4598c12
commit 63e4408f2a
+18
View File
@@ -6,6 +6,7 @@ if = 'BLOCK_CYCLES == -1'
[cases.test_alloc_parallel] [cases.test_alloc_parallel]
defines.FILES = 3 defines.FILES = 3
defines.SIZE = '(((BLOCK_SIZE-8)*(BLOCK_COUNT-6)) / FILES)' defines.SIZE = '(((BLOCK_SIZE-8)*(BLOCK_COUNT-6)) / FILES)'
defines.GC = [false, true]
code = ''' code = '''
const char *names[] = {"bacon", "eggs", "pancakes"}; const char *names[] = {"bacon", "eggs", "pancakes"};
lfs_file_t files[FILES]; lfs_file_t files[FILES];
@@ -24,6 +25,9 @@ code = '''
LFS_O_WRONLY | LFS_O_CREAT | LFS_O_APPEND) => 0; LFS_O_WRONLY | LFS_O_CREAT | LFS_O_APPEND) => 0;
} }
for (int n = 0; n < FILES; n++) { for (int n = 0; n < FILES; n++) {
if (GC) {
lfs_fs_findfreeblocks(&lfs) => 0;
}
size_t size = strlen(names[n]); size_t size = strlen(names[n]);
for (lfs_size_t i = 0; i < SIZE; i += size) { for (lfs_size_t i = 0; i < SIZE; i += size) {
lfs_file_write(&lfs, &files[n], names[n], size) => size; lfs_file_write(&lfs, &files[n], names[n], size) => size;
@@ -55,6 +59,7 @@ code = '''
[cases.test_alloc_serial] [cases.test_alloc_serial]
defines.FILES = 3 defines.FILES = 3
defines.SIZE = '(((BLOCK_SIZE-8)*(BLOCK_COUNT-6)) / FILES)' defines.SIZE = '(((BLOCK_SIZE-8)*(BLOCK_COUNT-6)) / FILES)'
defines.GC = [false, true]
code = ''' code = '''
const char *names[] = {"bacon", "eggs", "pancakes"}; const char *names[] = {"bacon", "eggs", "pancakes"};
@@ -75,6 +80,9 @@ code = '''
uint8_t buffer[1024]; uint8_t buffer[1024];
memcpy(buffer, names[n], size); memcpy(buffer, names[n], size);
for (int i = 0; i < SIZE; i += size) { for (int i = 0; i < SIZE; i += size) {
if (GC) {
lfs_fs_findfreeblocks(&lfs) => 0;
}
lfs_file_write(&lfs, &file, buffer, size) => size; lfs_file_write(&lfs, &file, buffer, size) => size;
} }
lfs_file_close(&lfs, &file) => 0; lfs_file_close(&lfs, &file) => 0;
@@ -247,6 +255,9 @@ code = '''
} }
res => LFS_ERR_NOSPC; res => LFS_ERR_NOSPC;
// note that lfs_fs_findfreeblocks should not error here
lfs_fs_findfreeblocks(&lfs) => 0;
lfs_file_close(&lfs, &file) => 0; lfs_file_close(&lfs, &file) => 0;
lfs_unmount(&lfs) => 0; lfs_unmount(&lfs) => 0;
@@ -298,6 +309,9 @@ code = '''
} }
res => LFS_ERR_NOSPC; res => LFS_ERR_NOSPC;
// note that lfs_fs_findfreeblocks should not error here
lfs_fs_findfreeblocks(&lfs) => 0;
lfs_file_close(&lfs, &file) => 0; lfs_file_close(&lfs, &file) => 0;
lfs_unmount(&lfs) => 0; lfs_unmount(&lfs) => 0;
@@ -337,6 +351,8 @@ code = '''
count += 1; count += 1;
} }
err => LFS_ERR_NOSPC; err => LFS_ERR_NOSPC;
// note that lfs_fs_findfreeblocks should not error here
lfs_fs_findfreeblocks(&lfs) => 0;
lfs_file_close(&lfs, &file) => 0; lfs_file_close(&lfs, &file) => 0;
lfs_remove(&lfs, "exhaustion") => 0; lfs_remove(&lfs, "exhaustion") => 0;
@@ -435,6 +451,8 @@ code = '''
break; break;
} }
} }
// note that lfs_fs_findfreeblocks should not error here
lfs_fs_findfreeblocks(&lfs) => 0;
lfs_file_close(&lfs, &file) => 0; lfs_file_close(&lfs, &file) => 0;
lfs_unmount(&lfs) => 0; lfs_unmount(&lfs) => 0;