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:
+96
-58
@@ -1,14 +1,18 @@
|
||||
[[case]] # simple truncate
|
||||
define.MEDIUMSIZE = [32, 2048]
|
||||
define.LARGESIZE = 8192
|
||||
# simple truncate
|
||||
[cases.truncate]
|
||||
defines.MEDIUMSIZE = [32, 2048]
|
||||
defines.LARGESIZE = 8192
|
||||
code = '''
|
||||
lfs_format(&lfs, &cfg) => 0;
|
||||
lfs_mount(&lfs, &cfg) => 0;
|
||||
lfs_t lfs;
|
||||
lfs_format(&lfs, cfg) => 0;
|
||||
lfs_mount(&lfs, cfg) => 0;
|
||||
lfs_file_t file;
|
||||
lfs_file_open(&lfs, &file, "baldynoop",
|
||||
LFS_O_WRONLY | LFS_O_CREAT) => 0;
|
||||
|
||||
uint8_t buffer[1024];
|
||||
strcpy((char*)buffer, "hair");
|
||||
size = strlen((char*)buffer);
|
||||
size_t size = strlen((char*)buffer);
|
||||
for (lfs_off_t j = 0; j < LARGESIZE; j += size) {
|
||||
lfs_file_write(&lfs, &file, buffer, size) => size;
|
||||
}
|
||||
@@ -17,7 +21,7 @@ code = '''
|
||||
lfs_file_close(&lfs, &file) => 0;
|
||||
lfs_unmount(&lfs) => 0;
|
||||
|
||||
lfs_mount(&lfs, &cfg) => 0;
|
||||
lfs_mount(&lfs, cfg) => 0;
|
||||
lfs_file_open(&lfs, &file, "baldynoop", LFS_O_RDWR) => 0;
|
||||
lfs_file_size(&lfs, &file) => LARGESIZE;
|
||||
|
||||
@@ -27,7 +31,7 @@ code = '''
|
||||
lfs_file_close(&lfs, &file) => 0;
|
||||
lfs_unmount(&lfs) => 0;
|
||||
|
||||
lfs_mount(&lfs, &cfg) => 0;
|
||||
lfs_mount(&lfs, cfg) => 0;
|
||||
lfs_file_open(&lfs, &file, "baldynoop", LFS_O_RDONLY) => 0;
|
||||
lfs_file_size(&lfs, &file) => MEDIUMSIZE;
|
||||
|
||||
@@ -42,17 +46,21 @@ code = '''
|
||||
lfs_unmount(&lfs) => 0;
|
||||
'''
|
||||
|
||||
[[case]] # truncate and read
|
||||
define.MEDIUMSIZE = [32, 2048]
|
||||
define.LARGESIZE = 8192
|
||||
# truncate and read
|
||||
[cases.truncate_read]
|
||||
defines.MEDIUMSIZE = [32, 2048]
|
||||
defines.LARGESIZE = 8192
|
||||
code = '''
|
||||
lfs_format(&lfs, &cfg) => 0;
|
||||
lfs_mount(&lfs, &cfg) => 0;
|
||||
lfs_t lfs;
|
||||
lfs_format(&lfs, cfg) => 0;
|
||||
lfs_mount(&lfs, cfg) => 0;
|
||||
lfs_file_t file;
|
||||
lfs_file_open(&lfs, &file, "baldyread",
|
||||
LFS_O_WRONLY | LFS_O_CREAT) => 0;
|
||||
|
||||
uint8_t buffer[1024];
|
||||
strcpy((char*)buffer, "hair");
|
||||
size = strlen((char*)buffer);
|
||||
size_t size = strlen((char*)buffer);
|
||||
for (lfs_off_t j = 0; j < LARGESIZE; j += size) {
|
||||
lfs_file_write(&lfs, &file, buffer, size) => size;
|
||||
}
|
||||
@@ -61,7 +69,7 @@ code = '''
|
||||
lfs_file_close(&lfs, &file) => 0;
|
||||
lfs_unmount(&lfs) => 0;
|
||||
|
||||
lfs_mount(&lfs, &cfg) => 0;
|
||||
lfs_mount(&lfs, cfg) => 0;
|
||||
lfs_file_open(&lfs, &file, "baldyread", LFS_O_RDWR) => 0;
|
||||
lfs_file_size(&lfs, &file) => LARGESIZE;
|
||||
|
||||
@@ -78,7 +86,7 @@ code = '''
|
||||
lfs_file_close(&lfs, &file) => 0;
|
||||
lfs_unmount(&lfs) => 0;
|
||||
|
||||
lfs_mount(&lfs, &cfg) => 0;
|
||||
lfs_mount(&lfs, cfg) => 0;
|
||||
lfs_file_open(&lfs, &file, "baldyread", LFS_O_RDONLY) => 0;
|
||||
lfs_file_size(&lfs, &file) => MEDIUMSIZE;
|
||||
|
||||
@@ -93,14 +101,18 @@ code = '''
|
||||
lfs_unmount(&lfs) => 0;
|
||||
'''
|
||||
|
||||
[[case]] # write, truncate, and read
|
||||
# write, truncate, and read
|
||||
[cases.write_truncate_read]
|
||||
code = '''
|
||||
lfs_format(&lfs, &cfg) => 0;
|
||||
lfs_mount(&lfs, &cfg) => 0;
|
||||
lfs_t lfs;
|
||||
lfs_format(&lfs, cfg) => 0;
|
||||
lfs_mount(&lfs, cfg) => 0;
|
||||
lfs_file_t file;
|
||||
lfs_file_open(&lfs, &file, "sequence",
|
||||
LFS_O_RDWR | LFS_O_CREAT | LFS_O_TRUNC) => 0;
|
||||
|
||||
size = lfs_min(lfs.cfg->cache_size, sizeof(buffer)/2);
|
||||
uint8_t buffer[1024];
|
||||
size_t size = lfs_min(lfs.cfg->cache_size, sizeof(buffer)/2);
|
||||
lfs_size_t qsize = size / 4;
|
||||
uint8_t *wb = buffer;
|
||||
uint8_t *rb = buffer + size;
|
||||
@@ -145,17 +157,21 @@ code = '''
|
||||
lfs_unmount(&lfs) => 0;
|
||||
'''
|
||||
|
||||
[[case]] # truncate and write
|
||||
define.MEDIUMSIZE = [32, 2048]
|
||||
define.LARGESIZE = 8192
|
||||
# truncate and write
|
||||
[cases.truncate_write]
|
||||
defines.MEDIUMSIZE = [32, 2048]
|
||||
defines.LARGESIZE = 8192
|
||||
code = '''
|
||||
lfs_format(&lfs, &cfg) => 0;
|
||||
lfs_mount(&lfs, &cfg) => 0;
|
||||
lfs_t lfs;
|
||||
lfs_format(&lfs, cfg) => 0;
|
||||
lfs_mount(&lfs, cfg) => 0;
|
||||
lfs_file_t file;
|
||||
lfs_file_open(&lfs, &file, "baldywrite",
|
||||
LFS_O_WRONLY | LFS_O_CREAT) => 0;
|
||||
|
||||
uint8_t buffer[1024];
|
||||
strcpy((char*)buffer, "hair");
|
||||
size = strlen((char*)buffer);
|
||||
size_t size = strlen((char*)buffer);
|
||||
for (lfs_off_t j = 0; j < LARGESIZE; j += size) {
|
||||
lfs_file_write(&lfs, &file, buffer, size) => size;
|
||||
}
|
||||
@@ -164,7 +180,7 @@ code = '''
|
||||
lfs_file_close(&lfs, &file) => 0;
|
||||
lfs_unmount(&lfs) => 0;
|
||||
|
||||
lfs_mount(&lfs, &cfg) => 0;
|
||||
lfs_mount(&lfs, cfg) => 0;
|
||||
lfs_file_open(&lfs, &file, "baldywrite", LFS_O_RDWR) => 0;
|
||||
lfs_file_size(&lfs, &file) => LARGESIZE;
|
||||
|
||||
@@ -181,7 +197,7 @@ code = '''
|
||||
lfs_file_close(&lfs, &file) => 0;
|
||||
lfs_unmount(&lfs) => 0;
|
||||
|
||||
lfs_mount(&lfs, &cfg) => 0;
|
||||
lfs_mount(&lfs, cfg) => 0;
|
||||
lfs_file_open(&lfs, &file, "baldywrite", LFS_O_RDONLY) => 0;
|
||||
lfs_file_size(&lfs, &file) => MEDIUMSIZE;
|
||||
|
||||
@@ -196,26 +212,30 @@ code = '''
|
||||
lfs_unmount(&lfs) => 0;
|
||||
'''
|
||||
|
||||
[[case]] # truncate write under powerloss
|
||||
define.SMALLSIZE = [4, 512]
|
||||
define.MEDIUMSIZE = [32, 1024]
|
||||
define.LARGESIZE = 2048
|
||||
# truncate write under powerloss
|
||||
[cases.reentrant_truncate_write]
|
||||
defines.SMALLSIZE = [4, 512]
|
||||
defines.MEDIUMSIZE = [32, 1024]
|
||||
defines.LARGESIZE = 2048
|
||||
reentrant = true
|
||||
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;
|
||||
}
|
||||
lfs_file_t file;
|
||||
err = lfs_file_open(&lfs, &file, "baldy", LFS_O_RDONLY);
|
||||
assert(!err || err == LFS_ERR_NOENT);
|
||||
if (!err) {
|
||||
size = lfs_file_size(&lfs, &file);
|
||||
size_t size = lfs_file_size(&lfs, &file);
|
||||
assert(size == 0 ||
|
||||
size == LARGESIZE ||
|
||||
size == MEDIUMSIZE ||
|
||||
size == SMALLSIZE);
|
||||
size == (size_t)LARGESIZE ||
|
||||
size == (size_t)MEDIUMSIZE ||
|
||||
size == (size_t)SMALLSIZE);
|
||||
for (lfs_off_t j = 0; j < size; j += 4) {
|
||||
uint8_t buffer[1024];
|
||||
lfs_file_read(&lfs, &file, buffer, 4) => 4;
|
||||
assert(memcmp(buffer, "hair", 4) == 0 ||
|
||||
memcmp(buffer, "bald", 4) == 0 ||
|
||||
@@ -227,8 +247,9 @@ code = '''
|
||||
lfs_file_open(&lfs, &file, "baldy",
|
||||
LFS_O_WRONLY | LFS_O_CREAT | LFS_O_TRUNC) => 0;
|
||||
lfs_file_size(&lfs, &file) => 0;
|
||||
uint8_t buffer[1024];
|
||||
strcpy((char*)buffer, "hair");
|
||||
size = strlen((char*)buffer);
|
||||
size_t size = strlen((char*)buffer);
|
||||
for (lfs_off_t j = 0; j < LARGESIZE; j += size) {
|
||||
lfs_file_write(&lfs, &file, buffer, size) => size;
|
||||
}
|
||||
@@ -262,12 +283,14 @@ code = '''
|
||||
lfs_unmount(&lfs) => 0;
|
||||
'''
|
||||
|
||||
[[case]] # more aggressive general truncation tests
|
||||
define.CONFIG = 'range(6)'
|
||||
define.SMALLSIZE = 32
|
||||
define.MEDIUMSIZE = 2048
|
||||
define.LARGESIZE = 8192
|
||||
# more aggressive general truncation tests
|
||||
[cases.aggressive_truncate]
|
||||
defines.CONFIG = [0,1,2,3,4,5]
|
||||
defines.SMALLSIZE = 32
|
||||
defines.MEDIUMSIZE = 2048
|
||||
defines.LARGESIZE = 8192
|
||||
code = '''
|
||||
lfs_t lfs;
|
||||
#define COUNT 5
|
||||
const struct {
|
||||
lfs_off_t startsizes[COUNT];
|
||||
@@ -312,16 +335,19 @@ code = '''
|
||||
const lfs_off_t *hotsizes = configs[CONFIG].hotsizes;
|
||||
const lfs_off_t *coldsizes = configs[CONFIG].coldsizes;
|
||||
|
||||
lfs_format(&lfs, &cfg) => 0;
|
||||
lfs_mount(&lfs, &cfg) => 0;
|
||||
lfs_format(&lfs, cfg) => 0;
|
||||
lfs_mount(&lfs, cfg) => 0;
|
||||
|
||||
for (unsigned i = 0; i < COUNT; i++) {
|
||||
char path[1024];
|
||||
sprintf(path, "hairyhead%d", i);
|
||||
lfs_file_t file;
|
||||
lfs_file_open(&lfs, &file, path,
|
||||
LFS_O_WRONLY | LFS_O_CREAT | LFS_O_TRUNC) => 0;
|
||||
|
||||
uint8_t buffer[1024];
|
||||
strcpy((char*)buffer, "hair");
|
||||
size = strlen((char*)buffer);
|
||||
size_t size = strlen((char*)buffer);
|
||||
for (lfs_off_t j = 0; j < startsizes[i]; j += size) {
|
||||
lfs_file_write(&lfs, &file, buffer, size) => size;
|
||||
}
|
||||
@@ -340,21 +366,25 @@ code = '''
|
||||
|
||||
lfs_unmount(&lfs) => 0;
|
||||
|
||||
lfs_mount(&lfs, &cfg) => 0;
|
||||
lfs_mount(&lfs, cfg) => 0;
|
||||
|
||||
for (unsigned i = 0; i < COUNT; i++) {
|
||||
char path[1024];
|
||||
sprintf(path, "hairyhead%d", i);
|
||||
lfs_file_t file;
|
||||
lfs_file_open(&lfs, &file, path, LFS_O_RDWR) => 0;
|
||||
lfs_file_size(&lfs, &file) => hotsizes[i];
|
||||
|
||||
size = strlen("hair");
|
||||
size_t size = strlen("hair");
|
||||
lfs_off_t j = 0;
|
||||
for (; j < startsizes[i] && j < hotsizes[i]; j += size) {
|
||||
uint8_t buffer[1024];
|
||||
lfs_file_read(&lfs, &file, buffer, size) => size;
|
||||
memcmp(buffer, "hair", size) => 0;
|
||||
}
|
||||
|
||||
for (; j < hotsizes[i]; j += size) {
|
||||
uint8_t buffer[1024];
|
||||
lfs_file_read(&lfs, &file, buffer, size) => size;
|
||||
memcmp(buffer, "\0\0\0\0", size) => 0;
|
||||
}
|
||||
@@ -367,22 +397,26 @@ code = '''
|
||||
|
||||
lfs_unmount(&lfs) => 0;
|
||||
|
||||
lfs_mount(&lfs, &cfg) => 0;
|
||||
lfs_mount(&lfs, cfg) => 0;
|
||||
|
||||
for (unsigned i = 0; i < COUNT; i++) {
|
||||
char path[1024];
|
||||
sprintf(path, "hairyhead%d", i);
|
||||
lfs_file_t file;
|
||||
lfs_file_open(&lfs, &file, path, LFS_O_RDONLY) => 0;
|
||||
lfs_file_size(&lfs, &file) => coldsizes[i];
|
||||
|
||||
size = strlen("hair");
|
||||
size_t size = strlen("hair");
|
||||
lfs_off_t j = 0;
|
||||
for (; j < startsizes[i] && j < hotsizes[i] && j < coldsizes[i];
|
||||
j += size) {
|
||||
uint8_t buffer[1024];
|
||||
lfs_file_read(&lfs, &file, buffer, size) => size;
|
||||
memcmp(buffer, "hair", size) => 0;
|
||||
}
|
||||
|
||||
for (; j < coldsizes[i]; j += size) {
|
||||
uint8_t buffer[1024];
|
||||
lfs_file_read(&lfs, &file, buffer, size) => size;
|
||||
memcmp(buffer, "\0\0\0\0", size) => 0;
|
||||
}
|
||||
@@ -393,16 +427,20 @@ code = '''
|
||||
lfs_unmount(&lfs) => 0;
|
||||
'''
|
||||
|
||||
[[case]] # noop truncate
|
||||
define.MEDIUMSIZE = [32, 2048]
|
||||
# noop truncate
|
||||
[cases.nop_truncate]
|
||||
defines.MEDIUMSIZE = [32, 2048]
|
||||
code = '''
|
||||
lfs_format(&lfs, &cfg) => 0;
|
||||
lfs_mount(&lfs, &cfg) => 0;
|
||||
lfs_t lfs;
|
||||
lfs_format(&lfs, cfg) => 0;
|
||||
lfs_mount(&lfs, cfg) => 0;
|
||||
lfs_file_t file;
|
||||
lfs_file_open(&lfs, &file, "baldynoop",
|
||||
LFS_O_RDWR | LFS_O_CREAT) => 0;
|
||||
|
||||
uint8_t buffer[1024];
|
||||
strcpy((char*)buffer, "hair");
|
||||
size = strlen((char*)buffer);
|
||||
size_t size = strlen((char*)buffer);
|
||||
for (lfs_off_t j = 0; j < MEDIUMSIZE; j += size) {
|
||||
lfs_file_write(&lfs, &file, buffer, size) => size;
|
||||
|
||||
@@ -426,7 +464,7 @@ code = '''
|
||||
lfs_unmount(&lfs) => 0;
|
||||
|
||||
// still there after reboot?
|
||||
lfs_mount(&lfs, &cfg) => 0;
|
||||
lfs_mount(&lfs, cfg) => 0;
|
||||
lfs_file_open(&lfs, &file, "baldynoop", LFS_O_RDWR) => 0;
|
||||
lfs_file_size(&lfs, &file) => MEDIUMSIZE;
|
||||
for (lfs_off_t j = 0; j < MEDIUMSIZE; j += size) {
|
||||
|
||||
Reference in New Issue
Block a user