Skip to content

Commit

Permalink
Extended alloc tests to test some properties of lfs_fs_findfreeblocks
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
geky committed Sep 21, 2023
1 parent dbe4598 commit 63e4408
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/test_alloc.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"};
lfs_file_t files[FILES];
Expand All @@ -24,6 +25,9 @@ code = '''
LFS_O_WRONLY | LFS_O_CREAT | LFS_O_APPEND) => 0;
}
for (int n = 0; n < FILES; n++) {
if (GC) {
lfs_fs_findfreeblocks(&lfs) => 0;
}
size_t size = strlen(names[n]);
for (lfs_size_t i = 0; i < SIZE; i += size) {
lfs_file_write(&lfs, &files[n], names[n], size) => size;
Expand Down Expand Up @@ -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"};

Expand All @@ -75,6 +80,9 @@ code = '''
uint8_t buffer[1024];
memcpy(buffer, names[n], 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_close(&lfs, &file) => 0;
Expand Down Expand Up @@ -247,6 +255,9 @@ code = '''
}
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_unmount(&lfs) => 0;

Expand Down Expand Up @@ -298,6 +309,9 @@ code = '''
}
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_unmount(&lfs) => 0;

Expand Down Expand Up @@ -337,6 +351,8 @@ code = '''
count += 1;
}
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_remove(&lfs, "exhaustion") => 0;
Expand Down Expand Up @@ -435,6 +451,8 @@ code = '''
break;
}
}
// note that lfs_fs_findfreeblocks should not error here
lfs_fs_findfreeblocks(&lfs) => 0;
lfs_file_close(&lfs, &file) => 0;

lfs_unmount(&lfs) => 0;
Expand Down

0 comments on commit 63e4408

Please sign in to comment.