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-18 01:57:12 +0300
committerChristopher Haster <chaster@utexas.edu>2017-09-18 02:07:08 +0300
commita83b2fe4638c92ce6cc475a3c7cc75ca431bb6b8 (patch)
treea622035202d3c8cff388d02dcf5e54552bcd6c95 /tests
parenta8fa5e6571b23458264f24c618d75e19c1aa297d (diff)
Added checks for out-of-bound seeks
- out-of-bound read results in eof - out-of-bound write will fill missing area with zeros The write behaviour matches expected posix behaviour, but was under consideration for not being dropped, since littlefs does not support holes, and support of out-of-band seeks adds complexity. However, it turned out filling with zeros was trivial, and only cost an extra 74 bytes of flash (0.48%).
Diffstat (limited to 'tests')
-rwxr-xr-xtests/test_seek.sh38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/test_seek.sh b/tests/test_seek.sh
index 1f70ee3..8b90928 100755
--- a/tests/test_seek.sh
+++ b/tests/test_seek.sh
@@ -305,5 +305,43 @@ tests/test.py << TEST
lfs_unmount(&lfs) => 0;
TEST
+echo "--- Out-of-bounds seek ---"
+tests/test.py << TEST
+ lfs_mount(&lfs, &cfg) => 0;
+ lfs_file_open(&lfs, &file[0], "hello/kitty42", LFS_O_RDWR) => 0;
+
+ size = strlen("kittycatcat");
+ lfs_file_size(&lfs, &file[0]) => $LARGESIZE*size;
+ lfs_file_seek(&lfs, &file[0],
+ ($LARGESIZE+$SMALLSIZE)*size, LFS_SEEK_SET) => 0;
+ lfs_file_read(&lfs, &file[0], buffer, size) => 0;
+
+ memcpy(buffer, "porcupineee", size);
+ lfs_file_write(&lfs, &file[0], buffer, size) => size;
+
+ lfs_file_seek(&lfs, &file[0],
+ ($LARGESIZE+$SMALLSIZE)*size, LFS_SEEK_SET) =>
+ ($LARGESIZE+$SMALLSIZE+1)*size;
+ lfs_file_read(&lfs, &file[0], buffer, size) => size;
+ memcmp(buffer, "porcupineee", size) => 0;
+
+ lfs_file_seek(&lfs, &file[0],
+ $LARGESIZE*size, LFS_SEEK_SET) =>
+ ($LARGESIZE+$SMALLSIZE+1)*size;
+ lfs_file_read(&lfs, &file[0], buffer, size) => size;
+ memcmp(buffer, "\0\0\0\0\0\0\0\0\0\0\0", size) => 0;
+
+ lfs_file_seek(&lfs, &file[0],
+ -(($LARGESIZE+$SMALLSIZE)*size), LFS_SEEK_CUR) => LFS_ERR_INVAL;
+ lfs_file_tell(&lfs, &file[0]) => ($LARGESIZE+1)*size;
+
+ lfs_file_seek(&lfs, &file[0],
+ -(($LARGESIZE+2*$SMALLSIZE)*size), LFS_SEEK_END) => LFS_ERR_INVAL;
+ lfs_file_tell(&lfs, &file[0]) => ($LARGESIZE+1)*size;
+
+ lfs_file_close(&lfs, &file[0]) => 0;
+ lfs_unmount(&lfs) => 0;
+TEST
+
echo "--- Results ---"
tests/stats.py