Skip to content

Commit

Permalink
Add test scenario for truncating to a block size
Browse files Browse the repository at this point in the history
When truncation is done on a file to the block size, there seems to be
an error where it points to an incorrect block. Perform a write /
truncate / readback operation to verify this issue.

Signed-off-by: Colin Foster <colin.foster@in-advantage.com>
  • Loading branch information
colin-foster-in-advantage committed Jan 26, 2023
1 parent 6a53d76 commit 7b151e1
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tests/test_truncate.toml
Original file line number Diff line number Diff line change
Expand Up @@ -437,3 +437,37 @@ code = '''
lfs_file_close(&lfs, &file) => 0;
lfs_unmount(&lfs) => 0;
'''

[[case]] # barrier truncate
code = '''
lfs_format(&lfs, &cfg) => 0;
lfs_mount(&lfs, &cfg) => 0;
lfs_file_open(&lfs, &file, "barrier",
LFS_O_RDWR | LFS_O_CREAT) => 0;
uint8_t bad_byte = 2;
uint8_t *rb = buffer + cfg.block_size;
/* Write a series of 1s to the first block */
memset(buffer, 1, cfg.block_size);
lfs_file_write(&lfs, &file, buffer,
cfg.block_size) => cfg.block_size;
/* Write a single non-one to the second block */
lfs_file_write(&lfs, &file, &bad_byte, 1) => 1;
lfs_file_close(&lfs, &file) => 0;
lfs_file_open(&lfs, &file, "barrier", LFS_O_RDWR) => 0;
lfs_file_truncate(&lfs, &file, cfg.block_size) => 0;
lfs_file_close(&lfs, &file) => 0;
/* Read the first block, which should match buffer */
lfs_file_open(&lfs, &file, "barrier", LFS_O_RDWR) => 0;
lfs_file_read(&lfs, &file, rb,
cfg.block_size) => cfg.block_size;
lfs_file_close(&lfs, &file) => 0;
lfs_unmount(&lfs) => 0;
memcmp(buffer, rb, cfg.block_size) => 0;
'''

0 comments on commit 7b151e1

Please sign in to comment.