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
path: root/tests
diff options
context:
space:
mode:
authorChristopher Haster <chaster@utexas.edu>2017-09-17 20:53:18 +0300
committerChristopher Haster <chaster@utexas.edu>2017-09-18 00:51:04 +0300
commit0982020fb389ac07a6a2cef5d3d8f45c304e1cc4 (patch)
treef026c7eca8611f1c04f676db3e24a04fd5a4d11c /tests
parentc2283a2753619d82a1fdf27d799cd53f2eef9a80 (diff)
Fixed issue with cold-write after seek to block boundary
This off-by-one error was caused by a slight difference between the pos argument to lfs_index_find and lfs_index_extend. When pos is on a block boundary, lfs_index_extend expects block to point before pos, as it would when writing a file linearly. But when seeking to that pos, the lfs_index_find to warm things up just supplies the block it expects pos to be in. Fixed the off-by-one error and added a test case for several of these cold seek+writes.
Diffstat (limited to 'tests')
-rwxr-xr-xtests/test_seek.sh28
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/test_seek.sh b/tests/test_seek.sh
index 8c00938..1f70ee3 100755
--- a/tests/test_seek.sh
+++ b/tests/test_seek.sh
@@ -277,5 +277,33 @@ tests/test.py << TEST
lfs_unmount(&lfs) => 0;
TEST
+echo "--- Boundary seek and write ---"
+tests/test.py << TEST
+ lfs_mount(&lfs, &cfg) => 0;
+ lfs_file_open(&lfs, &file[0], "hello/kitty42", LFS_O_RDWR) => 0;
+
+ size = strlen("hedgehoghog");
+ const lfs_soff_t offsets[] = {512, 1020, 513, 1021, 511, 1019};
+
+ for (int i = 0; i < sizeof(offsets) / sizeof(offsets[0]); i++) {
+ lfs_soff_t off = offsets[i];
+ memcpy(buffer, "hedgehoghog", size);
+ lfs_file_seek(&lfs, &file[0], off, LFS_SEEK_SET) >= 0 => 1;
+ lfs_file_write(&lfs, &file[0], buffer, size) => size;
+ lfs_file_seek(&lfs, &file[0], off, LFS_SEEK_SET) => off+size;
+ lfs_file_read(&lfs, &file[0], buffer, size) => size;
+ memcmp(buffer, "hedgehoghog", size) => 0;
+
+ lfs_file_seek(&lfs, &file[0], 0, LFS_SEEK_SET) => off+size;
+ lfs_file_read(&lfs, &file[0], buffer, size) => size;
+ memcmp(buffer, "kittycatcat", size) => 0;
+
+ lfs_file_sync(&lfs, &file[0]) => 0;
+ }
+
+ lfs_file_close(&lfs, &file[0]) => 0;
+ lfs_unmount(&lfs) => 0;
+TEST
+
echo "--- Results ---"
tests/stats.py