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-04-01 18:44:17 +0300
committerChristopher Haster <chaster@utexas.edu>2017-04-18 09:44:01 +0300
commit8a674524fcec8db761bc7c3818df58609a28623c (patch)
tree12bf67d9720ebe01c68a2d14a0f83d6507d050db /tests
parentca01b72a35f1d8e8bd541dd7e40c1905f0f207f4 (diff)
Added full dir list and rudimentary block allocator
In writing the initial allocator, I ran into the rather difficult problem of trying to iterate through the entire filesystem cheaply and with only constant memory consumption (which prohibits recursive functions). The solution was to simply thread all directory blocks onto a massive linked-list that spans the entire filesystem. With the linked-list it was easy to create a traverse function for all blocks in use on the filesystem (which has potential for other utility), and add the rudimentary block allocator using a bit-vector. While the linked-list may add complexity (especially where needing to maintain atomic operations), the linked-list helps simplify what is currently the most expensive operation in the filesystem, with no cost to space (the linked-list can reuse the pointers used for chained directory blocks).
Diffstat (limited to 'tests')
-rwxr-xr-xtests/test.py2
-rwxr-xr-xtests/test_alloc.sh114
-rwxr-xr-xtests/test_dirs.sh1
3 files changed, 115 insertions, 2 deletions
diff --git a/tests/test.py b/tests/test.py
index 045a26f..aa125c7 100755
--- a/tests/test.py
+++ b/tests/test.py
@@ -11,7 +11,7 @@ def generate(test):
lines = []
for line in re.split('(?<=[;{}])\n', test.read()):
- match = re.match('(?: *\n)*( *)(.*)=>(.*);', line, re.MULTILINE)
+ match = re.match('(?: *\n)*( *)(.*)=>(.*);', line, re.DOTALL | re.MULTILINE)
if match:
tab, test, expect = match.groups()
lines.append(tab+'res = {test};'.format(test=test.strip()))
diff --git a/tests/test_alloc.sh b/tests/test_alloc.sh
new file mode 100755
index 0000000..9604edd
--- /dev/null
+++ b/tests/test_alloc.sh
@@ -0,0 +1,114 @@
+#!/bin/bash
+set -eu
+
+echo "=== Allocator tests ==="
+rm -rf blocks
+tests/test.py << TEST
+ lfs_format(&lfs, &config) => 0;
+TEST
+
+SIZE=15000
+
+lfs_mkdir() {
+tests/test.py << TEST
+ lfs_mount(&lfs, &config) => 0;
+ lfs_mkdir(&lfs, "$1") => 0;
+ lfs_unmount(&lfs) => 0;
+TEST
+}
+
+lfs_remove() {
+tests/test.py << TEST
+ lfs_mount(&lfs, &config) => 0;
+ lfs_remove(&lfs, "$1/eggs") => 0;
+ lfs_remove(&lfs, "$1/bacon") => 0;
+ lfs_remove(&lfs, "$1/pancakes") => 0;
+ lfs_remove(&lfs, "$1") => 0;
+ lfs_unmount(&lfs) => 0;
+TEST
+}
+
+lfs_alloc_singleproc() {
+tests/test.py << TEST
+ const char *names[] = {"bacon", "eggs", "pancakes"};
+ lfs_mount(&lfs, &config) => 0;
+ for (int n = 0; n < sizeof(names)/sizeof(names[0]); n++) {
+ sprintf((char*)buffer, "$1/%s", names[n]);
+ lfs_file_open(&lfs, &file[n], (char*)buffer,
+ LFS_O_WRONLY | LFS_O_CREAT | LFS_O_APPEND) => 0;
+ }
+ for (int n = 0; n < sizeof(names)/sizeof(names[0]); n++) {
+ size = strlen(names[n]);
+ for (int i = 0; i < $SIZE; i++) {
+ lfs_file_write(&lfs, &file[n], names[n], size) => size;
+ }
+ }
+ for (int n = 0; n < sizeof(names)/sizeof(names[0]); n++) {
+ lfs_file_close(&lfs, &file[n]) => 0;
+ }
+ lfs_unmount(&lfs) => 0;
+TEST
+}
+
+lfs_alloc_multiproc() {
+for name in bacon eggs pancakes
+do
+tests/test.py << TEST
+ lfs_mount(&lfs, &config) => 0;
+ lfs_file_open(&lfs, &file[0], "$1/$name",
+ LFS_O_WRONLY | LFS_O_CREAT | LFS_O_APPEND) => 0;
+ size = strlen("$name");
+ memcpy(buffer, "$name", size);
+ for (int i = 0; i < $SIZE; i++) {
+ lfs_file_write(&lfs, &file[0], buffer, size) => size;
+ }
+ lfs_file_close(&lfs, &file[0]) => 0;
+ lfs_unmount(&lfs) => 0;
+TEST
+done
+}
+
+lfs_verify() {
+for name in bacon eggs pancakes
+do
+tests/test.py << TEST
+ lfs_mount(&lfs, &config) => 0;
+ lfs_file_open(&lfs, &file[0], "$1/$name", LFS_O_RDONLY) => 0;
+ size = strlen("$name");
+ for (int i = 0; i < $SIZE; i++) {
+ lfs_file_read(&lfs, &file[0], buffer, size) => size;
+ memcmp(buffer, "$name", size) => 0;
+ }
+ lfs_file_close(&lfs, &file[0]) => 0;
+ lfs_unmount(&lfs) => 0;
+TEST
+done
+}
+
+echo "--- Single-process allocation test ---"
+lfs_mkdir singleproc
+lfs_alloc_singleproc singleproc
+lfs_verify singleproc
+
+echo "--- Multi-process allocation test ---"
+lfs_mkdir multiproc
+lfs_alloc_multiproc multiproc
+lfs_verify multiproc
+lfs_verify singleproc
+
+echo "--- Single-process reuse test ---"
+lfs_remove singleproc
+lfs_mkdir singleprocreuse
+lfs_alloc_singleproc singleprocreuse
+lfs_verify singleprocreuse
+lfs_verify multiproc
+
+echo "--- Multi-process reuse test ---"
+lfs_remove multiproc
+lfs_mkdir multiprocreuse
+lfs_alloc_singleproc multiprocreuse
+lfs_verify multiprocreuse
+lfs_verify singleprocreuse
+
+echo "--- Results ---"
+tests/stats.py
diff --git a/tests/test_dirs.sh b/tests/test_dirs.sh
index 685bf16..0d891f5 100755
--- a/tests/test_dirs.sh
+++ b/tests/test_dirs.sh
@@ -118,7 +118,6 @@ tests/test.py << TEST
sprintf((char*)buffer, "test%d", i);
lfs_dir_read(&lfs, &dir[0], &info) => 1;
strcmp(info.name, (char*)buffer) => 0;
- info.type => LFS_TYPE_DIR;
}
lfs_dir_read(&lfs, &dir[0], &info) => 0;
lfs_unmount(&lfs) => 0;