Ported tests to new framework
This mostly required names for each test case, declarations of previously-implicit variables since the new test framework is more conservative with what it declares (the small extra effort to add declarations is well worth the simplicity and improved readability), and tweaks to work with not-really-constant defines. Also renamed test_ -> test, replacing the old ./scripts/test.py, unfortunately git seems to have had a hard time with this.
This commit is contained in:
+99
-63
@@ -1,15 +1,18 @@
|
||||
# specific corner cases worth explicitly testing for
|
||||
[[case]] # dangling split dir test
|
||||
define.ITERATIONS = 20
|
||||
define.COUNT = 10
|
||||
define.LFS_BLOCK_CYCLES = [8, 1]
|
||||
[cases.dangling_split_dir]
|
||||
defines.ITERATIONS = 20
|
||||
defines.COUNT = 10
|
||||
defines.BLOCK_CYCLES = [8, 1]
|
||||
code = '''
|
||||
lfs_format(&lfs, &cfg) => 0;
|
||||
lfs_t lfs;
|
||||
lfs_format(&lfs, cfg) => 0;
|
||||
// fill up filesystem so only ~16 blocks are left
|
||||
lfs_mount(&lfs, &cfg) => 0;
|
||||
lfs_mount(&lfs, cfg) => 0;
|
||||
lfs_file_t file;
|
||||
lfs_file_open(&lfs, &file, "padding", LFS_O_CREAT | LFS_O_WRONLY) => 0;
|
||||
uint8_t buffer[512];
|
||||
memset(buffer, 0, 512);
|
||||
while (LFS_BLOCK_COUNT - lfs_fs_size(&lfs) > 16) {
|
||||
while (BLOCK_COUNT - lfs_fs_size(&lfs) > 16) {
|
||||
lfs_file_write(&lfs, &file, buffer, 512) => 512;
|
||||
}
|
||||
lfs_file_close(&lfs, &file) => 0;
|
||||
@@ -17,18 +20,22 @@ code = '''
|
||||
lfs_mkdir(&lfs, "child") => 0;
|
||||
lfs_unmount(&lfs) => 0;
|
||||
|
||||
lfs_mount(&lfs, &cfg) => 0;
|
||||
for (int j = 0; j < ITERATIONS; j++) {
|
||||
for (int i = 0; i < COUNT; i++) {
|
||||
lfs_mount(&lfs, cfg) => 0;
|
||||
for (unsigned j = 0; j < ITERATIONS; j++) {
|
||||
for (unsigned i = 0; i < COUNT; i++) {
|
||||
char path[1024];
|
||||
sprintf(path, "child/test%03d_loooooooooooooooooong_name", i);
|
||||
lfs_file_open(&lfs, &file, path, LFS_O_CREAT | LFS_O_WRONLY) => 0;
|
||||
lfs_file_close(&lfs, &file) => 0;
|
||||
}
|
||||
|
||||
lfs_dir_t dir;
|
||||
struct lfs_info info;
|
||||
lfs_dir_open(&lfs, &dir, "child") => 0;
|
||||
lfs_dir_read(&lfs, &dir, &info) => 1;
|
||||
lfs_dir_read(&lfs, &dir, &info) => 1;
|
||||
for (int i = 0; i < COUNT; i++) {
|
||||
for (unsigned i = 0; i < COUNT; i++) {
|
||||
char path[1024];
|
||||
sprintf(path, "test%03d_loooooooooooooooooong_name", i);
|
||||
lfs_dir_read(&lfs, &dir, &info) => 1;
|
||||
strcmp(info.name, path) => 0;
|
||||
@@ -36,46 +43,54 @@ code = '''
|
||||
lfs_dir_read(&lfs, &dir, &info) => 0;
|
||||
lfs_dir_close(&lfs, &dir) => 0;
|
||||
|
||||
if (j == ITERATIONS-1) {
|
||||
if (j == (unsigned)ITERATIONS-1) {
|
||||
break;
|
||||
}
|
||||
|
||||
for (int i = 0; i < COUNT; i++) {
|
||||
for (unsigned i = 0; i < COUNT; i++) {
|
||||
char path[1024];
|
||||
sprintf(path, "child/test%03d_loooooooooooooooooong_name", i);
|
||||
lfs_remove(&lfs, path) => 0;
|
||||
}
|
||||
}
|
||||
lfs_unmount(&lfs) => 0;
|
||||
|
||||
lfs_mount(&lfs, &cfg) => 0;
|
||||
lfs_mount(&lfs, cfg) => 0;
|
||||
lfs_dir_t dir;
|
||||
struct lfs_info info;
|
||||
lfs_dir_open(&lfs, &dir, "child") => 0;
|
||||
lfs_dir_read(&lfs, &dir, &info) => 1;
|
||||
lfs_dir_read(&lfs, &dir, &info) => 1;
|
||||
for (int i = 0; i < COUNT; i++) {
|
||||
for (unsigned i = 0; i < COUNT; i++) {
|
||||
char path[1024];
|
||||
sprintf(path, "test%03d_loooooooooooooooooong_name", i);
|
||||
lfs_dir_read(&lfs, &dir, &info) => 1;
|
||||
strcmp(info.name, path) => 0;
|
||||
}
|
||||
lfs_dir_read(&lfs, &dir, &info) => 0;
|
||||
lfs_dir_close(&lfs, &dir) => 0;
|
||||
for (int i = 0; i < COUNT; i++) {
|
||||
for (unsigned i = 0; i < COUNT; i++) {
|
||||
char path[1024];
|
||||
sprintf(path, "child/test%03d_loooooooooooooooooong_name", i);
|
||||
lfs_remove(&lfs, path) => 0;
|
||||
}
|
||||
lfs_unmount(&lfs) => 0;
|
||||
'''
|
||||
|
||||
[[case]] # outdated head test
|
||||
define.ITERATIONS = 20
|
||||
define.COUNT = 10
|
||||
define.LFS_BLOCK_CYCLES = [8, 1]
|
||||
[cases.outdated_head]
|
||||
defines.ITERATIONS = 20
|
||||
defines.COUNT = 10
|
||||
defines.BLOCK_CYCLES = [8, 1]
|
||||
code = '''
|
||||
lfs_format(&lfs, &cfg) => 0;
|
||||
lfs_t lfs;
|
||||
lfs_format(&lfs, cfg) => 0;
|
||||
// fill up filesystem so only ~16 blocks are left
|
||||
lfs_mount(&lfs, &cfg) => 0;
|
||||
lfs_mount(&lfs, cfg) => 0;
|
||||
lfs_file_t file;
|
||||
lfs_file_open(&lfs, &file, "padding", LFS_O_CREAT | LFS_O_WRONLY) => 0;
|
||||
uint8_t buffer[512];
|
||||
memset(buffer, 0, 512);
|
||||
while (LFS_BLOCK_COUNT - lfs_fs_size(&lfs) > 16) {
|
||||
while (BLOCK_COUNT - lfs_fs_size(&lfs) > 16) {
|
||||
lfs_file_write(&lfs, &file, buffer, 512) => 512;
|
||||
}
|
||||
lfs_file_close(&lfs, &file) => 0;
|
||||
@@ -83,18 +98,22 @@ code = '''
|
||||
lfs_mkdir(&lfs, "child") => 0;
|
||||
lfs_unmount(&lfs) => 0;
|
||||
|
||||
lfs_mount(&lfs, &cfg) => 0;
|
||||
for (int j = 0; j < ITERATIONS; j++) {
|
||||
for (int i = 0; i < COUNT; i++) {
|
||||
lfs_mount(&lfs, cfg) => 0;
|
||||
for (unsigned j = 0; j < ITERATIONS; j++) {
|
||||
for (unsigned i = 0; i < COUNT; i++) {
|
||||
char path[1024];
|
||||
sprintf(path, "child/test%03d_loooooooooooooooooong_name", i);
|
||||
lfs_file_open(&lfs, &file, path, LFS_O_CREAT | LFS_O_WRONLY) => 0;
|
||||
lfs_file_close(&lfs, &file) => 0;
|
||||
}
|
||||
|
||||
lfs_dir_t dir;
|
||||
struct lfs_info info;
|
||||
lfs_dir_open(&lfs, &dir, "child") => 0;
|
||||
lfs_dir_read(&lfs, &dir, &info) => 1;
|
||||
lfs_dir_read(&lfs, &dir, &info) => 1;
|
||||
for (int i = 0; i < COUNT; i++) {
|
||||
for (unsigned i = 0; i < COUNT; i++) {
|
||||
char path[1024];
|
||||
sprintf(path, "test%03d_loooooooooooooooooong_name", i);
|
||||
lfs_dir_read(&lfs, &dir, &info) => 1;
|
||||
strcmp(info.name, path) => 0;
|
||||
@@ -110,7 +129,8 @@ code = '''
|
||||
lfs_dir_rewind(&lfs, &dir) => 0;
|
||||
lfs_dir_read(&lfs, &dir, &info) => 1;
|
||||
lfs_dir_read(&lfs, &dir, &info) => 1;
|
||||
for (int i = 0; i < COUNT; i++) {
|
||||
for (unsigned i = 0; i < COUNT; i++) {
|
||||
char path[1024];
|
||||
sprintf(path, "test%03d_loooooooooooooooooong_name", i);
|
||||
lfs_dir_read(&lfs, &dir, &info) => 1;
|
||||
strcmp(info.name, path) => 0;
|
||||
@@ -126,7 +146,8 @@ code = '''
|
||||
lfs_dir_rewind(&lfs, &dir) => 0;
|
||||
lfs_dir_read(&lfs, &dir, &info) => 1;
|
||||
lfs_dir_read(&lfs, &dir, &info) => 1;
|
||||
for (int i = 0; i < COUNT; i++) {
|
||||
for (unsigned i = 0; i < COUNT; i++) {
|
||||
char path[1024];
|
||||
sprintf(path, "test%03d_loooooooooooooooooong_name", i);
|
||||
lfs_dir_read(&lfs, &dir, &info) => 1;
|
||||
strcmp(info.name, path) => 0;
|
||||
@@ -135,7 +156,8 @@ code = '''
|
||||
lfs_dir_read(&lfs, &dir, &info) => 0;
|
||||
lfs_dir_close(&lfs, &dir) => 0;
|
||||
|
||||
for (int i = 0; i < COUNT; i++) {
|
||||
for (unsigned i = 0; i < COUNT; i++) {
|
||||
char path[1024];
|
||||
sprintf(path, "child/test%03d_loooooooooooooooooong_name", i);
|
||||
lfs_remove(&lfs, path) => 0;
|
||||
}
|
||||
@@ -143,45 +165,50 @@ code = '''
|
||||
lfs_unmount(&lfs) => 0;
|
||||
'''
|
||||
|
||||
[[case]] # reentrant testing for relocations, this is the same as the
|
||||
# orphan testing, except here we also set block_cycles so that
|
||||
# almost every tree operation needs a relocation
|
||||
# reentrant testing for relocations, this is the same as the
|
||||
# orphan testing, except here we also set block_cycles so that
|
||||
# almost every tree operation needs a relocation
|
||||
[cases.reentrant_relocations]
|
||||
reentrant = true
|
||||
# TODO fix this case, caused by non-DAG trees
|
||||
if = '!(DEPTH == 3 && LFS_CACHE_SIZE != 64)'
|
||||
define = [
|
||||
{FILES=6, DEPTH=1, CYCLES=20, LFS_BLOCK_CYCLES=1},
|
||||
{FILES=26, DEPTH=1, CYCLES=20, LFS_BLOCK_CYCLES=1},
|
||||
{FILES=3, DEPTH=3, CYCLES=20, LFS_BLOCK_CYCLES=1},
|
||||
if = '!(DEPTH == 3 && CACHE_SIZE != 64)'
|
||||
defines = [
|
||||
{FILES=6, DEPTH=1, CYCLES=20, BLOCK_CYCLES=1},
|
||||
{FILES=26, DEPTH=1, CYCLES=20, BLOCK_CYCLES=1},
|
||||
{FILES=3, DEPTH=3, CYCLES=20, BLOCK_CYCLES=1},
|
||||
]
|
||||
code = '''
|
||||
err = lfs_mount(&lfs, &cfg);
|
||||
lfs_t lfs;
|
||||
int err = lfs_mount(&lfs, cfg);
|
||||
if (err) {
|
||||
lfs_format(&lfs, &cfg) => 0;
|
||||
lfs_mount(&lfs, &cfg) => 0;
|
||||
lfs_format(&lfs, cfg) => 0;
|
||||
lfs_mount(&lfs, cfg) => 0;
|
||||
}
|
||||
|
||||
srand(1);
|
||||
const char alpha[] = "abcdefghijklmnopqrstuvwxyz";
|
||||
for (int i = 0; i < CYCLES; i++) {
|
||||
for (unsigned i = 0; i < CYCLES; i++) {
|
||||
// create random path
|
||||
char full_path[256];
|
||||
for (int d = 0; d < DEPTH; d++) {
|
||||
for (unsigned d = 0; d < DEPTH; d++) {
|
||||
sprintf(&full_path[2*d], "/%c", alpha[rand() % FILES]);
|
||||
}
|
||||
|
||||
// if it does not exist, we create it, else we destroy
|
||||
struct lfs_info info;
|
||||
int res = lfs_stat(&lfs, full_path, &info);
|
||||
if (res == LFS_ERR_NOENT) {
|
||||
// create each directory in turn, ignore if dir already exists
|
||||
for (int d = 0; d < DEPTH; d++) {
|
||||
for (unsigned d = 0; d < DEPTH; d++) {
|
||||
char path[1024];
|
||||
strcpy(path, full_path);
|
||||
path[2*d+2] = '\0';
|
||||
err = lfs_mkdir(&lfs, path);
|
||||
assert(!err || err == LFS_ERR_EXIST);
|
||||
}
|
||||
|
||||
for (int d = 0; d < DEPTH; d++) {
|
||||
for (unsigned d = 0; d < DEPTH; d++) {
|
||||
char path[1024];
|
||||
strcpy(path, full_path);
|
||||
path[2*d+2] = '\0';
|
||||
lfs_stat(&lfs, path, &info) => 0;
|
||||
@@ -194,7 +221,8 @@ code = '''
|
||||
assert(info.type == LFS_TYPE_DIR);
|
||||
|
||||
// try to delete path in reverse order, ignore if dir is not empty
|
||||
for (int d = DEPTH-1; d >= 0; d--) {
|
||||
for (unsigned d = DEPTH-1; d+1 > 0; d--) {
|
||||
char path[1024];
|
||||
strcpy(path, full_path);
|
||||
path[2*d+2] = '\0';
|
||||
err = lfs_remove(&lfs, path);
|
||||
@@ -207,44 +235,49 @@ code = '''
|
||||
lfs_unmount(&lfs) => 0;
|
||||
'''
|
||||
|
||||
[[case]] # reentrant testing for relocations, but now with random renames!
|
||||
# reentrant testing for relocations, but now with random renames!
|
||||
[cases.reentrant_relocations_renames]
|
||||
reentrant = true
|
||||
# TODO fix this case, caused by non-DAG trees
|
||||
if = '!(DEPTH == 3 && LFS_CACHE_SIZE != 64)'
|
||||
define = [
|
||||
{FILES=6, DEPTH=1, CYCLES=20, LFS_BLOCK_CYCLES=1},
|
||||
{FILES=26, DEPTH=1, CYCLES=20, LFS_BLOCK_CYCLES=1},
|
||||
{FILES=3, DEPTH=3, CYCLES=20, LFS_BLOCK_CYCLES=1},
|
||||
if = '!(DEPTH == 3 && CACHE_SIZE != 64)'
|
||||
defines = [
|
||||
{FILES=6, DEPTH=1, CYCLES=20, BLOCK_CYCLES=1},
|
||||
{FILES=26, DEPTH=1, CYCLES=20, BLOCK_CYCLES=1},
|
||||
{FILES=3, DEPTH=3, CYCLES=20, BLOCK_CYCLES=1},
|
||||
]
|
||||
code = '''
|
||||
err = lfs_mount(&lfs, &cfg);
|
||||
lfs_t lfs;
|
||||
int err = lfs_mount(&lfs, cfg);
|
||||
if (err) {
|
||||
lfs_format(&lfs, &cfg) => 0;
|
||||
lfs_mount(&lfs, &cfg) => 0;
|
||||
lfs_format(&lfs, cfg) => 0;
|
||||
lfs_mount(&lfs, cfg) => 0;
|
||||
}
|
||||
|
||||
srand(1);
|
||||
const char alpha[] = "abcdefghijklmnopqrstuvwxyz";
|
||||
for (int i = 0; i < CYCLES; i++) {
|
||||
for (unsigned i = 0; i < CYCLES; i++) {
|
||||
// create random path
|
||||
char full_path[256];
|
||||
for (int d = 0; d < DEPTH; d++) {
|
||||
for (unsigned d = 0; d < DEPTH; d++) {
|
||||
sprintf(&full_path[2*d], "/%c", alpha[rand() % FILES]);
|
||||
}
|
||||
|
||||
// if it does not exist, we create it, else we destroy
|
||||
struct lfs_info info;
|
||||
int res = lfs_stat(&lfs, full_path, &info);
|
||||
assert(!res || res == LFS_ERR_NOENT);
|
||||
if (res == LFS_ERR_NOENT) {
|
||||
// create each directory in turn, ignore if dir already exists
|
||||
for (int d = 0; d < DEPTH; d++) {
|
||||
for (unsigned d = 0; d < DEPTH; d++) {
|
||||
char path[1024];
|
||||
strcpy(path, full_path);
|
||||
path[2*d+2] = '\0';
|
||||
err = lfs_mkdir(&lfs, path);
|
||||
assert(!err || err == LFS_ERR_EXIST);
|
||||
}
|
||||
|
||||
for (int d = 0; d < DEPTH; d++) {
|
||||
for (unsigned d = 0; d < DEPTH; d++) {
|
||||
char path[1024];
|
||||
strcpy(path, full_path);
|
||||
path[2*d+2] = '\0';
|
||||
lfs_stat(&lfs, path, &info) => 0;
|
||||
@@ -257,7 +290,7 @@ code = '''
|
||||
|
||||
// create new random path
|
||||
char new_path[256];
|
||||
for (int d = 0; d < DEPTH; d++) {
|
||||
for (unsigned d = 0; d < DEPTH; d++) {
|
||||
sprintf(&new_path[2*d], "/%c", alpha[rand() % FILES]);
|
||||
}
|
||||
|
||||
@@ -266,7 +299,8 @@ code = '''
|
||||
assert(!res || res == LFS_ERR_NOENT);
|
||||
if (res == LFS_ERR_NOENT) {
|
||||
// stop once some dir is renamed
|
||||
for (int d = 0; d < DEPTH; d++) {
|
||||
for (unsigned d = 0; d < DEPTH; d++) {
|
||||
char path[1024];
|
||||
strcpy(&path[2*d], &full_path[2*d]);
|
||||
path[2*d+2] = '\0';
|
||||
strcpy(&path[128+2*d], &new_path[2*d]);
|
||||
@@ -278,7 +312,8 @@ code = '''
|
||||
}
|
||||
}
|
||||
|
||||
for (int d = 0; d < DEPTH; d++) {
|
||||
for (unsigned d = 0; d < DEPTH; d++) {
|
||||
char path[1024];
|
||||
strcpy(path, new_path);
|
||||
path[2*d+2] = '\0';
|
||||
lfs_stat(&lfs, path, &info) => 0;
|
||||
@@ -290,7 +325,8 @@ code = '''
|
||||
} else {
|
||||
// try to delete path in reverse order,
|
||||
// ignore if dir is not empty
|
||||
for (int d = DEPTH-1; d >= 0; d--) {
|
||||
for (unsigned d = DEPTH-1; d+1 > 0; d--) {
|
||||
char path[1024];
|
||||
strcpy(path, full_path);
|
||||
path[2*d+2] = '\0';
|
||||
err = lfs_remove(&lfs, path);
|
||||
|
||||
Reference in New Issue
Block a user