d04b077506
- Added caching to Travis install dirs, because otherwise
pip3 install fails randomly
- Increased size of littlefs-fuse disk because test script has
a larger footprint now
- Skip a couple of reentrant tests under byte-level writes because
the tests just take too long and cause Travis to bail due to no
output for 10m
- Fixed various Valgrind errors
- Suppressed uninit checks for tests where LFS_BLOCK_ERASE_VALUE == -1.
In this case rambd goes uninitialized, which is fine for rambd's
purposes. Note I couldn't figure out how to limit this suppression
to only the malloc in rambd, this doesn't seem possible with Valgrind.
- Fixed memory leaks in exhaustion tests
- Fixed off-by-1 string null-terminator issue in paths tests
- Fixed lfs_file_sync issue caused by revealed by fixing memory leaks
in exhaustion tests. Getting ENOSPC during a file write puts the file
in a bad state where littlefs doesn't know how to write it out safely.
In this case, lfs_file_sync and lfs_file_close return 0 without
writing out state so that device-side resources can still be cleaned
up. To recover from ENOSPC, the file needs to be reopened and the
writes recreated. Not sure if there is a better way to handle this.
- Added some quality-of-life improvements to Valgrind testing
- Fit Valgrind messages into truncated output when not in verbose mode
- Turned on origin tracking
841 lines
27 KiB
TOML
841 lines
27 KiB
TOML
[[case]] # root
|
|
code = '''
|
|
lfs_format(&lfs, &cfg) => 0;
|
|
lfs_mount(&lfs, &cfg) => 0;
|
|
lfs_dir_open(&lfs, &dir, "/") => 0;
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
assert(strcmp(info.name, ".") == 0);
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
assert(strcmp(info.name, "..") == 0);
|
|
lfs_dir_read(&lfs, &dir, &info) => 0;
|
|
lfs_dir_close(&lfs, &dir) => 0;
|
|
lfs_unmount(&lfs) => 0;
|
|
'''
|
|
|
|
[[case]] # many directory creation
|
|
define.N = 'range(0, 100, 3)'
|
|
code = '''
|
|
lfs_format(&lfs, &cfg) => 0;
|
|
|
|
lfs_mount(&lfs, &cfg) => 0;
|
|
for (int i = 0; i < N; i++) {
|
|
sprintf(path, "dir%03d", i);
|
|
lfs_mkdir(&lfs, path) => 0;
|
|
}
|
|
lfs_unmount(&lfs) => 0;
|
|
|
|
lfs_mount(&lfs, &cfg) => 0;
|
|
lfs_dir_open(&lfs, &dir, "/") => 0;
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
assert(strcmp(info.name, ".") == 0);
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
assert(strcmp(info.name, "..") == 0);
|
|
for (int i = 0; i < N; i++) {
|
|
sprintf(path, "dir%03d", i);
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
assert(strcmp(info.name, path) == 0);
|
|
}
|
|
lfs_dir_read(&lfs, &dir, &info) => 0;
|
|
lfs_dir_close(&lfs, &dir) => 0;
|
|
lfs_unmount(&lfs) => 0;
|
|
'''
|
|
|
|
[[case]] # many directory removal
|
|
define.N = 'range(3, 100, 11)'
|
|
code = '''
|
|
lfs_format(&lfs, &cfg) => 0;
|
|
|
|
lfs_mount(&lfs, &cfg) => 0;
|
|
for (int i = 0; i < N; i++) {
|
|
sprintf(path, "removeme%03d", i);
|
|
lfs_mkdir(&lfs, path) => 0;
|
|
}
|
|
lfs_unmount(&lfs) => 0;
|
|
|
|
lfs_mount(&lfs, &cfg) => 0;
|
|
lfs_dir_open(&lfs, &dir, "/") => 0;
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
assert(strcmp(info.name, ".") == 0);
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
assert(strcmp(info.name, "..") == 0);
|
|
for (int i = 0; i < N; i++) {
|
|
sprintf(path, "removeme%03d", i);
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
assert(strcmp(info.name, path) == 0);
|
|
}
|
|
lfs_dir_read(&lfs, &dir, &info) => 0;
|
|
lfs_dir_close(&lfs, &dir) => 0;
|
|
lfs_unmount(&lfs);
|
|
|
|
lfs_mount(&lfs, &cfg) => 0;
|
|
for (int i = 0; i < N; i++) {
|
|
sprintf(path, "removeme%03d", i);
|
|
lfs_remove(&lfs, path) => 0;
|
|
}
|
|
lfs_unmount(&lfs);
|
|
|
|
lfs_mount(&lfs, &cfg) => 0;
|
|
lfs_dir_open(&lfs, &dir, "/") => 0;
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
assert(strcmp(info.name, ".") == 0);
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
assert(strcmp(info.name, "..") == 0);
|
|
lfs_dir_read(&lfs, &dir, &info) => 0;
|
|
lfs_dir_close(&lfs, &dir) => 0;
|
|
lfs_unmount(&lfs) => 0;
|
|
'''
|
|
|
|
[[case]] # many directory rename
|
|
define.N = 'range(3, 100, 11)'
|
|
code = '''
|
|
lfs_format(&lfs, &cfg) => 0;
|
|
|
|
lfs_mount(&lfs, &cfg) => 0;
|
|
for (int i = 0; i < N; i++) {
|
|
sprintf(path, "test%03d", i);
|
|
lfs_mkdir(&lfs, path) => 0;
|
|
}
|
|
lfs_unmount(&lfs) => 0;
|
|
|
|
lfs_mount(&lfs, &cfg) => 0;
|
|
lfs_dir_open(&lfs, &dir, "/") => 0;
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
assert(strcmp(info.name, ".") == 0);
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
assert(strcmp(info.name, "..") == 0);
|
|
for (int i = 0; i < N; i++) {
|
|
sprintf(path, "test%03d", i);
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
assert(strcmp(info.name, path) == 0);
|
|
}
|
|
lfs_dir_read(&lfs, &dir, &info) => 0;
|
|
lfs_dir_close(&lfs, &dir) => 0;
|
|
lfs_unmount(&lfs);
|
|
|
|
lfs_mount(&lfs, &cfg) => 0;
|
|
for (int i = 0; i < N; i++) {
|
|
char oldpath[128];
|
|
char newpath[128];
|
|
sprintf(oldpath, "test%03d", i);
|
|
sprintf(newpath, "tedd%03d", i);
|
|
lfs_rename(&lfs, oldpath, newpath) => 0;
|
|
}
|
|
lfs_unmount(&lfs);
|
|
|
|
lfs_mount(&lfs, &cfg) => 0;
|
|
lfs_dir_open(&lfs, &dir, "/") => 0;
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
assert(strcmp(info.name, ".") == 0);
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
assert(strcmp(info.name, "..") == 0);
|
|
for (int i = 0; i < N; i++) {
|
|
sprintf(path, "tedd%03d", i);
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
assert(strcmp(info.name, path) == 0);
|
|
}
|
|
lfs_dir_read(&lfs, &dir, &info) => 0;
|
|
lfs_dir_close(&lfs, &dir) => 0;
|
|
lfs_unmount(&lfs);
|
|
'''
|
|
|
|
[[case]] # reentrant many directory creation/rename/removal
|
|
define.N = [5, 11]
|
|
reentrant = true
|
|
if = 'LFS_CACHE_SIZE >= 4' # these just take too long with byte-level writes
|
|
code = '''
|
|
err = lfs_mount(&lfs, &cfg);
|
|
if (err) {
|
|
lfs_format(&lfs, &cfg) => 0;
|
|
lfs_mount(&lfs, &cfg) => 0;
|
|
}
|
|
|
|
for (int i = 0; i < N; i++) {
|
|
sprintf(path, "hi%03d", i);
|
|
err = lfs_mkdir(&lfs, path);
|
|
assert(err == 0 || err == LFS_ERR_EXIST);
|
|
}
|
|
|
|
for (int i = 0; i < N; i++) {
|
|
sprintf(path, "hello%03d", i);
|
|
err = lfs_remove(&lfs, path);
|
|
assert(err == 0 || err == LFS_ERR_NOENT);
|
|
}
|
|
|
|
lfs_dir_open(&lfs, &dir, "/") => 0;
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
assert(strcmp(info.name, ".") == 0);
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
assert(strcmp(info.name, "..") == 0);
|
|
for (int i = 0; i < N; i++) {
|
|
sprintf(path, "hi%03d", i);
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
assert(strcmp(info.name, path) == 0);
|
|
}
|
|
lfs_dir_read(&lfs, &dir, &info) => 0;
|
|
lfs_dir_close(&lfs, &dir) => 0;
|
|
|
|
for (int i = 0; i < N; i++) {
|
|
char oldpath[128];
|
|
char newpath[128];
|
|
sprintf(oldpath, "hi%03d", i);
|
|
sprintf(newpath, "hello%03d", i);
|
|
// YES this can overwrite an existing newpath
|
|
lfs_rename(&lfs, oldpath, newpath) => 0;
|
|
}
|
|
|
|
lfs_dir_open(&lfs, &dir, "/") => 0;
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
assert(strcmp(info.name, ".") == 0);
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
assert(strcmp(info.name, "..") == 0);
|
|
for (int i = 0; i < N; i++) {
|
|
sprintf(path, "hello%03d", i);
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
assert(strcmp(info.name, path) == 0);
|
|
}
|
|
lfs_dir_read(&lfs, &dir, &info) => 0;
|
|
lfs_dir_close(&lfs, &dir) => 0;
|
|
|
|
for (int i = 0; i < N; i++) {
|
|
sprintf(path, "hello%03d", i);
|
|
lfs_remove(&lfs, path) => 0;
|
|
}
|
|
|
|
lfs_dir_open(&lfs, &dir, "/") => 0;
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
assert(strcmp(info.name, ".") == 0);
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
assert(strcmp(info.name, "..") == 0);
|
|
lfs_dir_read(&lfs, &dir, &info) => 0;
|
|
lfs_dir_close(&lfs, &dir) => 0;
|
|
lfs_unmount(&lfs) => 0;
|
|
'''
|
|
|
|
[[case]] # file creation
|
|
define.N = 'range(3, 100, 11)'
|
|
code = '''
|
|
lfs_format(&lfs, &cfg) => 0;
|
|
|
|
lfs_mount(&lfs, &cfg) => 0;
|
|
for (int i = 0; i < N; i++) {
|
|
sprintf(path, "file%03d", i);
|
|
lfs_file_open(&lfs, &file, path,
|
|
LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
|
|
lfs_file_close(&lfs, &file) => 0;
|
|
}
|
|
lfs_unmount(&lfs) => 0;
|
|
|
|
lfs_mount(&lfs, &cfg) => 0;
|
|
lfs_dir_open(&lfs, &dir, "/") => 0;
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
assert(strcmp(info.name, ".") == 0);
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
assert(strcmp(info.name, "..") == 0);
|
|
for (int i = 0; i < N; i++) {
|
|
sprintf(path, "file%03d", i);
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(info.type == LFS_TYPE_REG);
|
|
assert(strcmp(info.name, path) == 0);
|
|
}
|
|
lfs_dir_read(&lfs, &dir, &info) => 0;
|
|
lfs_dir_close(&lfs, &dir) => 0;
|
|
lfs_unmount(&lfs);
|
|
'''
|
|
|
|
[[case]] # file removal
|
|
define.N = 'range(0, 100, 3)'
|
|
code = '''
|
|
lfs_format(&lfs, &cfg) => 0;
|
|
|
|
lfs_mount(&lfs, &cfg) => 0;
|
|
for (int i = 0; i < N; i++) {
|
|
sprintf(path, "removeme%03d", i);
|
|
lfs_file_open(&lfs, &file, path,
|
|
LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
|
|
lfs_file_close(&lfs, &file) => 0;
|
|
}
|
|
lfs_unmount(&lfs) => 0;
|
|
|
|
lfs_mount(&lfs, &cfg) => 0;
|
|
lfs_dir_open(&lfs, &dir, "/") => 0;
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
assert(strcmp(info.name, ".") == 0);
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
assert(strcmp(info.name, "..") == 0);
|
|
for (int i = 0; i < N; i++) {
|
|
sprintf(path, "removeme%03d", i);
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(info.type == LFS_TYPE_REG);
|
|
assert(strcmp(info.name, path) == 0);
|
|
}
|
|
lfs_dir_read(&lfs, &dir, &info) => 0;
|
|
lfs_dir_close(&lfs, &dir) => 0;
|
|
lfs_unmount(&lfs);
|
|
|
|
lfs_mount(&lfs, &cfg) => 0;
|
|
for (int i = 0; i < N; i++) {
|
|
sprintf(path, "removeme%03d", i);
|
|
lfs_remove(&lfs, path) => 0;
|
|
}
|
|
lfs_unmount(&lfs);
|
|
|
|
lfs_mount(&lfs, &cfg) => 0;
|
|
lfs_dir_open(&lfs, &dir, "/") => 0;
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
assert(strcmp(info.name, ".") == 0);
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
assert(strcmp(info.name, "..") == 0);
|
|
lfs_dir_read(&lfs, &dir, &info) => 0;
|
|
lfs_dir_close(&lfs, &dir) => 0;
|
|
lfs_unmount(&lfs) => 0;
|
|
'''
|
|
|
|
[[case]] # file rename
|
|
define.N = 'range(0, 100, 3)'
|
|
code = '''
|
|
lfs_format(&lfs, &cfg) => 0;
|
|
|
|
lfs_mount(&lfs, &cfg) => 0;
|
|
for (int i = 0; i < N; i++) {
|
|
sprintf(path, "test%03d", i);
|
|
lfs_file_open(&lfs, &file, path,
|
|
LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
|
|
lfs_file_close(&lfs, &file) => 0;
|
|
}
|
|
lfs_unmount(&lfs) => 0;
|
|
|
|
lfs_mount(&lfs, &cfg) => 0;
|
|
lfs_dir_open(&lfs, &dir, "/") => 0;
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
assert(strcmp(info.name, ".") == 0);
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
assert(strcmp(info.name, "..") == 0);
|
|
for (int i = 0; i < N; i++) {
|
|
sprintf(path, "test%03d", i);
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(info.type == LFS_TYPE_REG);
|
|
assert(strcmp(info.name, path) == 0);
|
|
}
|
|
lfs_dir_read(&lfs, &dir, &info) => 0;
|
|
lfs_dir_close(&lfs, &dir) => 0;
|
|
lfs_unmount(&lfs);
|
|
|
|
lfs_mount(&lfs, &cfg) => 0;
|
|
for (int i = 0; i < N; i++) {
|
|
char oldpath[128];
|
|
char newpath[128];
|
|
sprintf(oldpath, "test%03d", i);
|
|
sprintf(newpath, "tedd%03d", i);
|
|
lfs_rename(&lfs, oldpath, newpath) => 0;
|
|
}
|
|
lfs_unmount(&lfs);
|
|
|
|
lfs_mount(&lfs, &cfg) => 0;
|
|
lfs_dir_open(&lfs, &dir, "/") => 0;
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
assert(strcmp(info.name, ".") == 0);
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
assert(strcmp(info.name, "..") == 0);
|
|
for (int i = 0; i < N; i++) {
|
|
sprintf(path, "tedd%03d", i);
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(info.type == LFS_TYPE_REG);
|
|
assert(strcmp(info.name, path) == 0);
|
|
}
|
|
lfs_dir_read(&lfs, &dir, &info) => 0;
|
|
lfs_dir_close(&lfs, &dir) => 0;
|
|
lfs_unmount(&lfs);
|
|
'''
|
|
|
|
[[case]] # reentrant file creation/rename/removal
|
|
define.N = [5, 25]
|
|
reentrant = true
|
|
if = 'LFS_CACHE_SIZE >= 4' # these just take too long with byte-level writes
|
|
code = '''
|
|
err = lfs_mount(&lfs, &cfg);
|
|
if (err) {
|
|
lfs_format(&lfs, &cfg) => 0;
|
|
lfs_mount(&lfs, &cfg) => 0;
|
|
}
|
|
|
|
for (int i = 0; i < N; i++) {
|
|
sprintf(path, "hi%03d", i);
|
|
lfs_file_open(&lfs, &file, path, LFS_O_CREAT | LFS_O_WRONLY) => 0;
|
|
lfs_file_close(&lfs, &file) => 0;
|
|
}
|
|
|
|
for (int i = 0; i < N; i++) {
|
|
sprintf(path, "hello%03d", i);
|
|
err = lfs_remove(&lfs, path);
|
|
assert(err == 0 || err == LFS_ERR_NOENT);
|
|
}
|
|
|
|
lfs_dir_open(&lfs, &dir, "/") => 0;
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
assert(strcmp(info.name, ".") == 0);
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
assert(strcmp(info.name, "..") == 0);
|
|
for (int i = 0; i < N; i++) {
|
|
sprintf(path, "hi%03d", i);
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(info.type == LFS_TYPE_REG);
|
|
assert(strcmp(info.name, path) == 0);
|
|
}
|
|
lfs_dir_read(&lfs, &dir, &info) => 0;
|
|
lfs_dir_close(&lfs, &dir) => 0;
|
|
|
|
for (int i = 0; i < N; i++) {
|
|
char oldpath[128];
|
|
char newpath[128];
|
|
sprintf(oldpath, "hi%03d", i);
|
|
sprintf(newpath, "hello%03d", i);
|
|
// YES this can overwrite an existing newpath
|
|
lfs_rename(&lfs, oldpath, newpath) => 0;
|
|
}
|
|
|
|
lfs_dir_open(&lfs, &dir, "/") => 0;
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
assert(strcmp(info.name, ".") == 0);
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
assert(strcmp(info.name, "..") == 0);
|
|
for (int i = 0; i < N; i++) {
|
|
sprintf(path, "hello%03d", i);
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(info.type == LFS_TYPE_REG);
|
|
assert(strcmp(info.name, path) == 0);
|
|
}
|
|
lfs_dir_read(&lfs, &dir, &info) => 0;
|
|
lfs_dir_close(&lfs, &dir) => 0;
|
|
|
|
for (int i = 0; i < N; i++) {
|
|
sprintf(path, "hello%03d", i);
|
|
lfs_remove(&lfs, path) => 0;
|
|
}
|
|
|
|
lfs_dir_open(&lfs, &dir, "/") => 0;
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
assert(strcmp(info.name, ".") == 0);
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
assert(strcmp(info.name, "..") == 0);
|
|
lfs_dir_read(&lfs, &dir, &info) => 0;
|
|
lfs_dir_close(&lfs, &dir) => 0;
|
|
lfs_unmount(&lfs) => 0;
|
|
'''
|
|
|
|
[[case]] # nested directories
|
|
code = '''
|
|
lfs_format(&lfs, &cfg) => 0;
|
|
lfs_mount(&lfs, &cfg) => 0;
|
|
lfs_mkdir(&lfs, "potato") => 0;
|
|
lfs_file_open(&lfs, &file, "burito",
|
|
LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
|
|
lfs_file_close(&lfs, &file) => 0;
|
|
lfs_unmount(&lfs) => 0;
|
|
|
|
lfs_mount(&lfs, &cfg) => 0;
|
|
lfs_mkdir(&lfs, "potato/baked") => 0;
|
|
lfs_mkdir(&lfs, "potato/sweet") => 0;
|
|
lfs_mkdir(&lfs, "potato/fried") => 0;
|
|
lfs_unmount(&lfs) => 0;
|
|
|
|
lfs_mount(&lfs, &cfg) => 0;
|
|
lfs_dir_open(&lfs, &dir, "potato") => 0;
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(strcmp(info.name, ".") == 0);
|
|
info.type => LFS_TYPE_DIR;
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(strcmp(info.name, "..") == 0);
|
|
info.type => LFS_TYPE_DIR;
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(strcmp(info.name, "baked") == 0);
|
|
info.type => LFS_TYPE_DIR;
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(strcmp(info.name, "fried") == 0);
|
|
info.type => LFS_TYPE_DIR;
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(strcmp(info.name, "sweet") == 0);
|
|
info.type => LFS_TYPE_DIR;
|
|
lfs_dir_read(&lfs, &dir, &info) => 0;
|
|
lfs_dir_close(&lfs, &dir) => 0;
|
|
lfs_unmount(&lfs) => 0;
|
|
|
|
// try removing?
|
|
lfs_mount(&lfs, &cfg) => 0;
|
|
lfs_remove(&lfs, "potato") => LFS_ERR_NOTEMPTY;
|
|
lfs_unmount(&lfs) => 0;
|
|
|
|
// try renaming?
|
|
lfs_mount(&lfs, &cfg) => 0;
|
|
lfs_rename(&lfs, "potato", "coldpotato") => 0;
|
|
lfs_unmount(&lfs) => 0;
|
|
|
|
lfs_mount(&lfs, &cfg) => 0;
|
|
lfs_rename(&lfs, "coldpotato", "warmpotato") => 0;
|
|
lfs_rename(&lfs, "warmpotato", "hotpotato") => 0;
|
|
lfs_unmount(&lfs) => 0;
|
|
|
|
lfs_mount(&lfs, &cfg) => 0;
|
|
lfs_remove(&lfs, "potato") => LFS_ERR_NOENT;
|
|
lfs_remove(&lfs, "coldpotato") => LFS_ERR_NOENT;
|
|
lfs_remove(&lfs, "warmpotato") => LFS_ERR_NOENT;
|
|
lfs_remove(&lfs, "hotpotato") => LFS_ERR_NOTEMPTY;
|
|
lfs_unmount(&lfs) => 0;
|
|
|
|
// try cross-directory renaming
|
|
lfs_mount(&lfs, &cfg) => 0;
|
|
lfs_mkdir(&lfs, "coldpotato") => 0;
|
|
lfs_rename(&lfs, "hotpotato/baked", "coldpotato/baked") => 0;
|
|
lfs_rename(&lfs, "coldpotato", "hotpotato") => LFS_ERR_NOTEMPTY;
|
|
lfs_remove(&lfs, "coldpotato") => LFS_ERR_NOTEMPTY;
|
|
lfs_remove(&lfs, "hotpotato") => LFS_ERR_NOTEMPTY;
|
|
lfs_rename(&lfs, "hotpotato/fried", "coldpotato/fried") => 0;
|
|
lfs_rename(&lfs, "coldpotato", "hotpotato") => LFS_ERR_NOTEMPTY;
|
|
lfs_remove(&lfs, "coldpotato") => LFS_ERR_NOTEMPTY;
|
|
lfs_remove(&lfs, "hotpotato") => LFS_ERR_NOTEMPTY;
|
|
lfs_rename(&lfs, "hotpotato/sweet", "coldpotato/sweet") => 0;
|
|
lfs_rename(&lfs, "coldpotato", "hotpotato") => 0;
|
|
lfs_remove(&lfs, "coldpotato") => LFS_ERR_NOENT;
|
|
lfs_remove(&lfs, "hotpotato") => LFS_ERR_NOTEMPTY;
|
|
lfs_unmount(&lfs) => 0;
|
|
|
|
lfs_mount(&lfs, &cfg) => 0;
|
|
lfs_dir_open(&lfs, &dir, "hotpotato") => 0;
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(strcmp(info.name, ".") == 0);
|
|
info.type => LFS_TYPE_DIR;
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(strcmp(info.name, "..") == 0);
|
|
info.type => LFS_TYPE_DIR;
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(strcmp(info.name, "baked") == 0);
|
|
info.type => LFS_TYPE_DIR;
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(strcmp(info.name, "fried") == 0);
|
|
info.type => LFS_TYPE_DIR;
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(strcmp(info.name, "sweet") == 0);
|
|
info.type => LFS_TYPE_DIR;
|
|
lfs_dir_read(&lfs, &dir, &info) => 0;
|
|
lfs_dir_close(&lfs, &dir) => 0;
|
|
lfs_unmount(&lfs) => 0;
|
|
|
|
// final remove
|
|
lfs_mount(&lfs, &cfg) => 0;
|
|
lfs_remove(&lfs, "hotpotato") => LFS_ERR_NOTEMPTY;
|
|
lfs_remove(&lfs, "hotpotato/baked") => 0;
|
|
lfs_remove(&lfs, "hotpotato") => LFS_ERR_NOTEMPTY;
|
|
lfs_remove(&lfs, "hotpotato/fried") => 0;
|
|
lfs_remove(&lfs, "hotpotato") => LFS_ERR_NOTEMPTY;
|
|
lfs_remove(&lfs, "hotpotato/sweet") => 0;
|
|
lfs_remove(&lfs, "hotpotato") => 0;
|
|
lfs_unmount(&lfs) => 0;
|
|
|
|
lfs_mount(&lfs, &cfg) => 0;
|
|
lfs_dir_open(&lfs, &dir, "/") => 0;
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(strcmp(info.name, ".") == 0);
|
|
info.type => LFS_TYPE_DIR;
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(strcmp(info.name, "..") == 0);
|
|
info.type => LFS_TYPE_DIR;
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(strcmp(info.name, "burito") == 0);
|
|
info.type => LFS_TYPE_REG;
|
|
lfs_dir_read(&lfs, &dir, &info) => 0;
|
|
lfs_dir_close(&lfs, &dir) => 0;
|
|
lfs_unmount(&lfs) => 0;
|
|
'''
|
|
|
|
[[case]] # recursive remove
|
|
define.N = [10, 100]
|
|
code = '''
|
|
lfs_format(&lfs, &cfg) => 0;
|
|
lfs_mount(&lfs, &cfg) => 0;
|
|
lfs_mkdir(&lfs, "prickly-pear") => 0;
|
|
for (int i = 0; i < N; i++) {
|
|
sprintf(path, "prickly-pear/cactus%03d", i);
|
|
lfs_mkdir(&lfs, path) => 0;
|
|
}
|
|
lfs_dir_open(&lfs, &dir, "prickly-pear") => 0;
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
assert(strcmp(info.name, ".") == 0);
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
assert(strcmp(info.name, "..") == 0);
|
|
for (int i = 0; i < N; i++) {
|
|
sprintf(path, "cactus%03d", i);
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
assert(strcmp(info.name, path) == 0);
|
|
}
|
|
lfs_dir_read(&lfs, &dir, &info) => 0;
|
|
lfs_dir_close(&lfs, &dir) => 0;
|
|
lfs_unmount(&lfs);
|
|
|
|
lfs_mount(&lfs, &cfg) => 0;
|
|
lfs_remove(&lfs, "prickly-pear") => LFS_ERR_NOTEMPTY;
|
|
|
|
lfs_dir_open(&lfs, &dir, "prickly-pear") => 0;
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
assert(strcmp(info.name, ".") == 0);
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
assert(strcmp(info.name, "..") == 0);
|
|
for (int i = 0; i < N; i++) {
|
|
sprintf(path, "cactus%03d", i);
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
assert(strcmp(info.name, path) == 0);
|
|
sprintf(path, "prickly-pear/%s", info.name);
|
|
lfs_remove(&lfs, path) => 0;
|
|
}
|
|
lfs_dir_read(&lfs, &dir, &info) => 0;
|
|
lfs_dir_close(&lfs, &dir) => 0;
|
|
|
|
lfs_remove(&lfs, "prickly-pear") => 0;
|
|
lfs_remove(&lfs, "prickly-pear") => LFS_ERR_NOENT;
|
|
lfs_unmount(&lfs) => 0;
|
|
|
|
lfs_mount(&lfs, &cfg) => 0;
|
|
lfs_remove(&lfs, "prickly-pear") => LFS_ERR_NOENT;
|
|
lfs_unmount(&lfs) => 0;
|
|
'''
|
|
|
|
[[case]] # other error cases
|
|
code = '''
|
|
lfs_format(&lfs, &cfg) => 0;
|
|
lfs_mount(&lfs, &cfg) => 0;
|
|
lfs_mkdir(&lfs, "potato") => 0;
|
|
lfs_file_open(&lfs, &file, "burito",
|
|
LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
|
|
lfs_file_close(&lfs, &file) => 0;
|
|
lfs_unmount(&lfs) => 0;
|
|
|
|
lfs_mount(&lfs, &cfg) => 0;
|
|
|
|
lfs_mkdir(&lfs, "potato") => LFS_ERR_EXIST;
|
|
lfs_mkdir(&lfs, "burito") => LFS_ERR_EXIST;
|
|
lfs_file_open(&lfs, &file, "burito",
|
|
LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_EXIST;
|
|
lfs_file_open(&lfs, &file, "potato",
|
|
LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_EXIST;
|
|
lfs_dir_open(&lfs, &dir, "tomato") => LFS_ERR_NOENT;
|
|
lfs_dir_open(&lfs, &dir, "burito") => LFS_ERR_NOTDIR;
|
|
lfs_file_open(&lfs, &file, "tomato", LFS_O_RDONLY) => LFS_ERR_NOENT;
|
|
lfs_file_open(&lfs, &file, "potato", LFS_O_RDONLY) => LFS_ERR_ISDIR;
|
|
lfs_file_open(&lfs, &file, "tomato", LFS_O_WRONLY) => LFS_ERR_NOENT;
|
|
lfs_file_open(&lfs, &file, "potato", LFS_O_WRONLY) => LFS_ERR_ISDIR;
|
|
lfs_file_open(&lfs, &file, "potato",
|
|
LFS_O_WRONLY | LFS_O_CREAT) => LFS_ERR_ISDIR;
|
|
|
|
lfs_mkdir(&lfs, "/") => LFS_ERR_EXIST;
|
|
lfs_file_open(&lfs, &file, "/",
|
|
LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_EXIST;
|
|
lfs_file_open(&lfs, &file, "/", LFS_O_RDONLY) => LFS_ERR_ISDIR;
|
|
lfs_file_open(&lfs, &file, "/", LFS_O_WRONLY) => LFS_ERR_ISDIR;
|
|
lfs_file_open(&lfs, &file, "/",
|
|
LFS_O_WRONLY | LFS_O_CREAT) => LFS_ERR_ISDIR;
|
|
|
|
// check that errors did not corrupt directory
|
|
lfs_dir_open(&lfs, &dir, "/") => 0;
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
assert(strcmp(info.name, ".") == 0);
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
assert(strcmp(info.name, "..") == 0);
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(info.type == LFS_TYPE_REG);
|
|
assert(strcmp(info.name, "burito") == 0);
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
assert(strcmp(info.name, "potato") == 0);
|
|
lfs_dir_read(&lfs, &dir, &info) => 0;
|
|
lfs_dir_close(&lfs, &dir) => 0;
|
|
|
|
lfs_unmount(&lfs) => 0;
|
|
|
|
// or on disk
|
|
lfs_mount(&lfs, &cfg) => 0;
|
|
lfs_dir_open(&lfs, &dir, "/") => 0;
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
assert(strcmp(info.name, ".") == 0);
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
assert(strcmp(info.name, "..") == 0);
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(info.type == LFS_TYPE_REG);
|
|
assert(strcmp(info.name, "burito") == 0);
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
assert(strcmp(info.name, "potato") == 0);
|
|
lfs_dir_read(&lfs, &dir, &info) => 0;
|
|
lfs_dir_close(&lfs, &dir) => 0;
|
|
lfs_unmount(&lfs) => 0;
|
|
'''
|
|
|
|
[[case]] # directory seek
|
|
define.COUNT = [4, 128, 132]
|
|
code = '''
|
|
lfs_format(&lfs, &cfg) => 0;
|
|
lfs_mount(&lfs, &cfg) => 0;
|
|
lfs_mkdir(&lfs, "hello") => 0;
|
|
for (int i = 0; i < COUNT; i++) {
|
|
sprintf(path, "hello/kitty%03d", i);
|
|
lfs_mkdir(&lfs, path) => 0;
|
|
}
|
|
lfs_unmount(&lfs) => 0;
|
|
|
|
for (int j = 2; j < COUNT; j++) {
|
|
lfs_mount(&lfs, &cfg) => 0;
|
|
lfs_dir_open(&lfs, &dir, "hello") => 0;
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(strcmp(info.name, ".") == 0);
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(strcmp(info.name, "..") == 0);
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
|
|
lfs_soff_t pos;
|
|
for (int i = 0; i < j; i++) {
|
|
sprintf(path, "kitty%03d", i);
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(strcmp(info.name, path) == 0);
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
pos = lfs_dir_tell(&lfs, &dir);
|
|
assert(pos >= 0);
|
|
}
|
|
|
|
lfs_dir_seek(&lfs, &dir, pos) => 0;
|
|
sprintf(path, "kitty%03d", j);
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(strcmp(info.name, path) == 0);
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
|
|
lfs_dir_rewind(&lfs, &dir) => 0;
|
|
sprintf(path, "kitty%03d", 0);
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(strcmp(info.name, ".") == 0);
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(strcmp(info.name, "..") == 0);
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(strcmp(info.name, path) == 0);
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
|
|
lfs_dir_seek(&lfs, &dir, pos) => 0;
|
|
sprintf(path, "kitty%03d", j);
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(strcmp(info.name, path) == 0);
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
|
|
lfs_dir_close(&lfs, &dir) => 0;
|
|
lfs_unmount(&lfs) => 0;
|
|
}
|
|
'''
|
|
|
|
[[case]] # root seek
|
|
define.COUNT = [4, 128, 132]
|
|
code = '''
|
|
lfs_format(&lfs, &cfg) => 0;
|
|
lfs_mount(&lfs, &cfg) => 0;
|
|
for (int i = 0; i < COUNT; i++) {
|
|
sprintf(path, "hi%03d", i);
|
|
lfs_mkdir(&lfs, path) => 0;
|
|
}
|
|
lfs_unmount(&lfs) => 0;
|
|
|
|
for (int j = 2; j < COUNT; j++) {
|
|
lfs_mount(&lfs, &cfg) => 0;
|
|
lfs_dir_open(&lfs, &dir, "/") => 0;
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(strcmp(info.name, ".") == 0);
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(strcmp(info.name, "..") == 0);
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
|
|
lfs_soff_t pos;
|
|
for (int i = 0; i < j; i++) {
|
|
sprintf(path, "hi%03d", i);
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(strcmp(info.name, path) == 0);
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
pos = lfs_dir_tell(&lfs, &dir);
|
|
assert(pos >= 0);
|
|
}
|
|
|
|
lfs_dir_seek(&lfs, &dir, pos) => 0;
|
|
sprintf(path, "hi%03d", j);
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(strcmp(info.name, path) == 0);
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
|
|
lfs_dir_rewind(&lfs, &dir) => 0;
|
|
sprintf(path, "hi%03d", 0);
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(strcmp(info.name, ".") == 0);
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(strcmp(info.name, "..") == 0);
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(strcmp(info.name, path) == 0);
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
|
|
lfs_dir_seek(&lfs, &dir, pos) => 0;
|
|
sprintf(path, "hi%03d", j);
|
|
lfs_dir_read(&lfs, &dir, &info) => 1;
|
|
assert(strcmp(info.name, path) == 0);
|
|
assert(info.type == LFS_TYPE_DIR);
|
|
|
|
lfs_dir_close(&lfs, &dir) => 0;
|
|
lfs_unmount(&lfs) => 0;
|
|
}
|
|
'''
|
|
|