You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
838 lines
27 KiB
838 lines
27 KiB
[[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
|
|
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
|
|
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;
|
|
}
|
|
'''
|
|
|
|
|