Generated v2 prefixes

This commit is contained in:
geky-bot
2023-05-04 18:31:30 +00:00
67 changed files with 26771 additions and 5203 deletions
+146 -116
View File
@@ -1,17 +1,20 @@
[[case]] # simple file test
[cases.test_files_simple]
code = '''
lfs2_format(&lfs2, &cfg) => 0;
lfs2_mount(&lfs2, &cfg) => 0;
lfs2_t lfs2;
lfs2_format(&lfs2, cfg) => 0;
lfs2_mount(&lfs2, cfg) => 0;
lfs2_file_t file;
lfs2_file_open(&lfs2, &file, "hello",
LFS2_O_WRONLY | LFS2_O_CREAT | LFS2_O_EXCL) => 0;
size = strlen("Hello World!")+1;
lfs2_size_t size = strlen("Hello World!")+1;
uint8_t buffer[1024];
strcpy((char*)buffer, "Hello World!");
lfs2_file_write(&lfs2, &file, buffer, size) => size;
lfs2_file_close(&lfs2, &file) => 0;
lfs2_unmount(&lfs2) => 0;
lfs2_mount(&lfs2, &cfg) => 0;
lfs2_mount(&lfs2, cfg) => 0;
lfs2_file_open(&lfs2, &file, "hello", LFS2_O_RDONLY) => 0;
lfs2_file_read(&lfs2, &file, buffer, size) => size;
assert(strcmp((char*)buffer, "Hello World!") == 0);
@@ -19,21 +22,24 @@ code = '''
lfs2_unmount(&lfs2) => 0;
'''
[[case]] # larger files
define.SIZE = [32, 8192, 262144, 0, 7, 8193]
define.CHUNKSIZE = [31, 16, 33, 1, 1023]
[cases.test_files_large]
defines.SIZE = [32, 8192, 262144, 0, 7, 8193]
defines.CHUNKSIZE = [31, 16, 33, 1, 1023]
code = '''
lfs2_format(&lfs2, &cfg) => 0;
lfs2_t lfs2;
lfs2_format(&lfs2, cfg) => 0;
// write
lfs2_mount(&lfs2, &cfg) => 0;
lfs2_mount(&lfs2, cfg) => 0;
lfs2_file_t file;
lfs2_file_open(&lfs2, &file, "avacado",
LFS2_O_WRONLY | LFS2_O_CREAT | LFS2_O_EXCL) => 0;
srand(1);
uint32_t prng = 1;
uint8_t buffer[1024];
for (lfs2_size_t i = 0; i < SIZE; i += CHUNKSIZE) {
lfs2_size_t chunk = lfs2_min(CHUNKSIZE, SIZE-i);
for (lfs2_size_t b = 0; b < chunk; b++) {
buffer[b] = rand() & 0xff;
buffer[b] = TEST_PRNG(&prng) & 0xff;
}
lfs2_file_write(&lfs2, &file, buffer, chunk) => chunk;
}
@@ -41,15 +47,15 @@ code = '''
lfs2_unmount(&lfs2) => 0;
// read
lfs2_mount(&lfs2, &cfg) => 0;
lfs2_mount(&lfs2, cfg) => 0;
lfs2_file_open(&lfs2, &file, "avacado", LFS2_O_RDONLY) => 0;
lfs2_file_size(&lfs2, &file) => SIZE;
srand(1);
prng = 1;
for (lfs2_size_t i = 0; i < SIZE; i += CHUNKSIZE) {
lfs2_size_t chunk = lfs2_min(CHUNKSIZE, SIZE-i);
lfs2_file_read(&lfs2, &file, buffer, chunk) => chunk;
for (lfs2_size_t b = 0; b < chunk; b++) {
assert(buffer[b] == (rand() & 0xff));
assert(buffer[b] == (TEST_PRNG(&prng) & 0xff));
}
}
lfs2_file_read(&lfs2, &file, buffer, CHUNKSIZE) => 0;
@@ -57,22 +63,25 @@ code = '''
lfs2_unmount(&lfs2) => 0;
'''
[[case]] # rewriting files
define.SIZE1 = [32, 8192, 131072, 0, 7, 8193]
define.SIZE2 = [32, 8192, 131072, 0, 7, 8193]
define.CHUNKSIZE = [31, 16, 1]
[cases.test_files_rewrite]
defines.SIZE1 = [32, 8192, 131072, 0, 7, 8193]
defines.SIZE2 = [32, 8192, 131072, 0, 7, 8193]
defines.CHUNKSIZE = [31, 16, 1]
code = '''
lfs2_format(&lfs2, &cfg) => 0;
lfs2_t lfs2;
lfs2_format(&lfs2, cfg) => 0;
// write
lfs2_mount(&lfs2, &cfg) => 0;
lfs2_mount(&lfs2, cfg) => 0;
lfs2_file_t file;
uint8_t buffer[1024];
lfs2_file_open(&lfs2, &file, "avacado",
LFS2_O_WRONLY | LFS2_O_CREAT | LFS2_O_EXCL) => 0;
srand(1);
uint32_t prng = 1;
for (lfs2_size_t i = 0; i < SIZE1; i += CHUNKSIZE) {
lfs2_size_t chunk = lfs2_min(CHUNKSIZE, SIZE1-i);
for (lfs2_size_t b = 0; b < chunk; b++) {
buffer[b] = rand() & 0xff;
buffer[b] = TEST_PRNG(&prng) & 0xff;
}
lfs2_file_write(&lfs2, &file, buffer, chunk) => chunk;
}
@@ -80,15 +89,15 @@ code = '''
lfs2_unmount(&lfs2) => 0;
// read
lfs2_mount(&lfs2, &cfg) => 0;
lfs2_mount(&lfs2, cfg) => 0;
lfs2_file_open(&lfs2, &file, "avacado", LFS2_O_RDONLY) => 0;
lfs2_file_size(&lfs2, &file) => SIZE1;
srand(1);
prng = 1;
for (lfs2_size_t i = 0; i < SIZE1; i += CHUNKSIZE) {
lfs2_size_t chunk = lfs2_min(CHUNKSIZE, SIZE1-i);
lfs2_file_read(&lfs2, &file, buffer, chunk) => chunk;
for (lfs2_size_t b = 0; b < chunk; b++) {
assert(buffer[b] == (rand() & 0xff));
assert(buffer[b] == (TEST_PRNG(&prng) & 0xff));
}
}
lfs2_file_read(&lfs2, &file, buffer, CHUNKSIZE) => 0;
@@ -96,13 +105,13 @@ code = '''
lfs2_unmount(&lfs2) => 0;
// rewrite
lfs2_mount(&lfs2, &cfg) => 0;
lfs2_mount(&lfs2, cfg) => 0;
lfs2_file_open(&lfs2, &file, "avacado", LFS2_O_WRONLY) => 0;
srand(2);
prng = 2;
for (lfs2_size_t i = 0; i < SIZE2; i += CHUNKSIZE) {
lfs2_size_t chunk = lfs2_min(CHUNKSIZE, SIZE2-i);
for (lfs2_size_t b = 0; b < chunk; b++) {
buffer[b] = rand() & 0xff;
buffer[b] = TEST_PRNG(&prng) & 0xff;
}
lfs2_file_write(&lfs2, &file, buffer, chunk) => chunk;
}
@@ -110,27 +119,27 @@ code = '''
lfs2_unmount(&lfs2) => 0;
// read
lfs2_mount(&lfs2, &cfg) => 0;
lfs2_mount(&lfs2, cfg) => 0;
lfs2_file_open(&lfs2, &file, "avacado", LFS2_O_RDONLY) => 0;
lfs2_file_size(&lfs2, &file) => lfs2_max(SIZE1, SIZE2);
srand(2);
prng = 2;
for (lfs2_size_t i = 0; i < SIZE2; i += CHUNKSIZE) {
lfs2_size_t chunk = lfs2_min(CHUNKSIZE, SIZE2-i);
lfs2_file_read(&lfs2, &file, buffer, chunk) => chunk;
for (lfs2_size_t b = 0; b < chunk; b++) {
assert(buffer[b] == (rand() & 0xff));
assert(buffer[b] == (TEST_PRNG(&prng) & 0xff));
}
}
if (SIZE1 > SIZE2) {
srand(1);
prng = 1;
for (lfs2_size_t b = 0; b < SIZE2; b++) {
rand();
TEST_PRNG(&prng);
}
for (lfs2_size_t i = SIZE2; i < SIZE1; i += CHUNKSIZE) {
lfs2_size_t chunk = lfs2_min(CHUNKSIZE, SIZE1-i);
lfs2_file_read(&lfs2, &file, buffer, chunk) => chunk;
for (lfs2_size_t b = 0; b < chunk; b++) {
assert(buffer[b] == (rand() & 0xff));
assert(buffer[b] == (TEST_PRNG(&prng) & 0xff));
}
}
}
@@ -139,22 +148,25 @@ code = '''
lfs2_unmount(&lfs2) => 0;
'''
[[case]] # appending files
define.SIZE1 = [32, 8192, 131072, 0, 7, 8193]
define.SIZE2 = [32, 8192, 131072, 0, 7, 8193]
define.CHUNKSIZE = [31, 16, 1]
[cases.test_files_append]
defines.SIZE1 = [32, 8192, 131072, 0, 7, 8193]
defines.SIZE2 = [32, 8192, 131072, 0, 7, 8193]
defines.CHUNKSIZE = [31, 16, 1]
code = '''
lfs2_format(&lfs2, &cfg) => 0;
lfs2_t lfs2;
lfs2_format(&lfs2, cfg) => 0;
// write
lfs2_mount(&lfs2, &cfg) => 0;
lfs2_mount(&lfs2, cfg) => 0;
lfs2_file_t file;
uint8_t buffer[1024];
lfs2_file_open(&lfs2, &file, "avacado",
LFS2_O_WRONLY | LFS2_O_CREAT | LFS2_O_EXCL) => 0;
srand(1);
uint32_t prng = 1;
for (lfs2_size_t i = 0; i < SIZE1; i += CHUNKSIZE) {
lfs2_size_t chunk = lfs2_min(CHUNKSIZE, SIZE1-i);
for (lfs2_size_t b = 0; b < chunk; b++) {
buffer[b] = rand() & 0xff;
buffer[b] = TEST_PRNG(&prng) & 0xff;
}
lfs2_file_write(&lfs2, &file, buffer, chunk) => chunk;
}
@@ -162,15 +174,15 @@ code = '''
lfs2_unmount(&lfs2) => 0;
// read
lfs2_mount(&lfs2, &cfg) => 0;
lfs2_mount(&lfs2, cfg) => 0;
lfs2_file_open(&lfs2, &file, "avacado", LFS2_O_RDONLY) => 0;
lfs2_file_size(&lfs2, &file) => SIZE1;
srand(1);
prng = 1;
for (lfs2_size_t i = 0; i < SIZE1; i += CHUNKSIZE) {
lfs2_size_t chunk = lfs2_min(CHUNKSIZE, SIZE1-i);
lfs2_file_read(&lfs2, &file, buffer, chunk) => chunk;
for (lfs2_size_t b = 0; b < chunk; b++) {
assert(buffer[b] == (rand() & 0xff));
assert(buffer[b] == (TEST_PRNG(&prng) & 0xff));
}
}
lfs2_file_read(&lfs2, &file, buffer, CHUNKSIZE) => 0;
@@ -178,13 +190,13 @@ code = '''
lfs2_unmount(&lfs2) => 0;
// append
lfs2_mount(&lfs2, &cfg) => 0;
lfs2_mount(&lfs2, cfg) => 0;
lfs2_file_open(&lfs2, &file, "avacado", LFS2_O_WRONLY | LFS2_O_APPEND) => 0;
srand(2);
prng = 2;
for (lfs2_size_t i = 0; i < SIZE2; i += CHUNKSIZE) {
lfs2_size_t chunk = lfs2_min(CHUNKSIZE, SIZE2-i);
for (lfs2_size_t b = 0; b < chunk; b++) {
buffer[b] = rand() & 0xff;
buffer[b] = TEST_PRNG(&prng) & 0xff;
}
lfs2_file_write(&lfs2, &file, buffer, chunk) => chunk;
}
@@ -192,23 +204,23 @@ code = '''
lfs2_unmount(&lfs2) => 0;
// read
lfs2_mount(&lfs2, &cfg) => 0;
lfs2_mount(&lfs2, cfg) => 0;
lfs2_file_open(&lfs2, &file, "avacado", LFS2_O_RDONLY) => 0;
lfs2_file_size(&lfs2, &file) => SIZE1 + SIZE2;
srand(1);
prng = 1;
for (lfs2_size_t i = 0; i < SIZE1; i += CHUNKSIZE) {
lfs2_size_t chunk = lfs2_min(CHUNKSIZE, SIZE1-i);
lfs2_file_read(&lfs2, &file, buffer, chunk) => chunk;
for (lfs2_size_t b = 0; b < chunk; b++) {
assert(buffer[b] == (rand() & 0xff));
assert(buffer[b] == (TEST_PRNG(&prng) & 0xff));
}
}
srand(2);
prng = 2;
for (lfs2_size_t i = 0; i < SIZE2; i += CHUNKSIZE) {
lfs2_size_t chunk = lfs2_min(CHUNKSIZE, SIZE2-i);
lfs2_file_read(&lfs2, &file, buffer, chunk) => chunk;
for (lfs2_size_t b = 0; b < chunk; b++) {
assert(buffer[b] == (rand() & 0xff));
assert(buffer[b] == (TEST_PRNG(&prng) & 0xff));
}
}
lfs2_file_read(&lfs2, &file, buffer, CHUNKSIZE) => 0;
@@ -216,22 +228,25 @@ code = '''
lfs2_unmount(&lfs2) => 0;
'''
[[case]] # truncating files
define.SIZE1 = [32, 8192, 131072, 0, 7, 8193]
define.SIZE2 = [32, 8192, 131072, 0, 7, 8193]
define.CHUNKSIZE = [31, 16, 1]
[cases.test_files_truncate]
defines.SIZE1 = [32, 8192, 131072, 0, 7, 8193]
defines.SIZE2 = [32, 8192, 131072, 0, 7, 8193]
defines.CHUNKSIZE = [31, 16, 1]
code = '''
lfs2_format(&lfs2, &cfg) => 0;
lfs2_t lfs2;
lfs2_format(&lfs2, cfg) => 0;
// write
lfs2_mount(&lfs2, &cfg) => 0;
lfs2_mount(&lfs2, cfg) => 0;
lfs2_file_t file;
uint8_t buffer[1024];
lfs2_file_open(&lfs2, &file, "avacado",
LFS2_O_WRONLY | LFS2_O_CREAT | LFS2_O_EXCL) => 0;
srand(1);
uint32_t prng = 1;
for (lfs2_size_t i = 0; i < SIZE1; i += CHUNKSIZE) {
lfs2_size_t chunk = lfs2_min(CHUNKSIZE, SIZE1-i);
for (lfs2_size_t b = 0; b < chunk; b++) {
buffer[b] = rand() & 0xff;
buffer[b] = TEST_PRNG(&prng) & 0xff;
}
lfs2_file_write(&lfs2, &file, buffer, chunk) => chunk;
}
@@ -239,15 +254,15 @@ code = '''
lfs2_unmount(&lfs2) => 0;
// read
lfs2_mount(&lfs2, &cfg) => 0;
lfs2_mount(&lfs2, cfg) => 0;
lfs2_file_open(&lfs2, &file, "avacado", LFS2_O_RDONLY) => 0;
lfs2_file_size(&lfs2, &file) => SIZE1;
srand(1);
prng = 1;
for (lfs2_size_t i = 0; i < SIZE1; i += CHUNKSIZE) {
lfs2_size_t chunk = lfs2_min(CHUNKSIZE, SIZE1-i);
lfs2_file_read(&lfs2, &file, buffer, chunk) => chunk;
for (lfs2_size_t b = 0; b < chunk; b++) {
assert(buffer[b] == (rand() & 0xff));
assert(buffer[b] == (TEST_PRNG(&prng) & 0xff));
}
}
lfs2_file_read(&lfs2, &file, buffer, CHUNKSIZE) => 0;
@@ -255,13 +270,13 @@ code = '''
lfs2_unmount(&lfs2) => 0;
// truncate
lfs2_mount(&lfs2, &cfg) => 0;
lfs2_mount(&lfs2, cfg) => 0;
lfs2_file_open(&lfs2, &file, "avacado", LFS2_O_WRONLY | LFS2_O_TRUNC) => 0;
srand(2);
prng = 2;
for (lfs2_size_t i = 0; i < SIZE2; i += CHUNKSIZE) {
lfs2_size_t chunk = lfs2_min(CHUNKSIZE, SIZE2-i);
for (lfs2_size_t b = 0; b < chunk; b++) {
buffer[b] = rand() & 0xff;
buffer[b] = TEST_PRNG(&prng) & 0xff;
}
lfs2_file_write(&lfs2, &file, buffer, chunk) => chunk;
}
@@ -269,15 +284,15 @@ code = '''
lfs2_unmount(&lfs2) => 0;
// read
lfs2_mount(&lfs2, &cfg) => 0;
lfs2_mount(&lfs2, cfg) => 0;
lfs2_file_open(&lfs2, &file, "avacado", LFS2_O_RDONLY) => 0;
lfs2_file_size(&lfs2, &file) => SIZE2;
srand(2);
prng = 2;
for (lfs2_size_t i = 0; i < SIZE2; i += CHUNKSIZE) {
lfs2_size_t chunk = lfs2_min(CHUNKSIZE, SIZE2-i);
lfs2_file_read(&lfs2, &file, buffer, chunk) => chunk;
for (lfs2_size_t b = 0; b < chunk; b++) {
assert(buffer[b] == (rand() & 0xff));
assert(buffer[b] == (TEST_PRNG(&prng) & 0xff));
}
}
lfs2_file_read(&lfs2, &file, buffer, CHUNKSIZE) => 0;
@@ -285,33 +300,36 @@ code = '''
lfs2_unmount(&lfs2) => 0;
'''
[[case]] # reentrant file writing
define.SIZE = [32, 0, 7, 2049]
define.CHUNKSIZE = [31, 16, 65]
[cases.test_files_reentrant_write]
defines.SIZE = [32, 0, 7, 2049]
defines.CHUNKSIZE = [31, 16, 65]
reentrant = true
code = '''
err = lfs2_mount(&lfs2, &cfg);
lfs2_t lfs2;
int err = lfs2_mount(&lfs2, cfg);
if (err) {
lfs2_format(&lfs2, &cfg) => 0;
lfs2_mount(&lfs2, &cfg) => 0;
lfs2_format(&lfs2, cfg) => 0;
lfs2_mount(&lfs2, cfg) => 0;
}
lfs2_file_t file;
uint8_t buffer[1024];
err = lfs2_file_open(&lfs2, &file, "avacado", LFS2_O_RDONLY);
assert(err == LFS2_ERR_NOENT || err == 0);
if (err == 0) {
// can only be 0 (new file) or full size
size = lfs2_file_size(&lfs2, &file);
lfs2_size_t size = lfs2_file_size(&lfs2, &file);
assert(size == 0 || size == SIZE);
lfs2_file_close(&lfs2, &file) => 0;
}
// write
lfs2_file_open(&lfs2, &file, "avacado", LFS2_O_WRONLY | LFS2_O_CREAT) => 0;
srand(1);
uint32_t prng = 1;
for (lfs2_size_t i = 0; i < SIZE; i += CHUNKSIZE) {
lfs2_size_t chunk = lfs2_min(CHUNKSIZE, SIZE-i);
for (lfs2_size_t b = 0; b < chunk; b++) {
buffer[b] = rand() & 0xff;
buffer[b] = TEST_PRNG(&prng) & 0xff;
}
lfs2_file_write(&lfs2, &file, buffer, chunk) => chunk;
}
@@ -320,12 +338,12 @@ code = '''
// read
lfs2_file_open(&lfs2, &file, "avacado", LFS2_O_RDONLY) => 0;
lfs2_file_size(&lfs2, &file) => SIZE;
srand(1);
prng = 1;
for (lfs2_size_t i = 0; i < SIZE; i += CHUNKSIZE) {
lfs2_size_t chunk = lfs2_min(CHUNKSIZE, SIZE-i);
lfs2_file_read(&lfs2, &file, buffer, chunk) => chunk;
for (lfs2_size_t b = 0; b < chunk; b++) {
assert(buffer[b] == (rand() & 0xff));
assert(buffer[b] == (TEST_PRNG(&prng) & 0xff));
}
}
lfs2_file_read(&lfs2, &file, buffer, CHUNKSIZE) => 0;
@@ -333,8 +351,8 @@ code = '''
lfs2_unmount(&lfs2) => 0;
'''
[[case]] # reentrant file writing with syncs
define = [
[cases.test_files_reentrant_write_sync]
defines = [
# append (O(n))
{MODE='LFS2_O_APPEND', SIZE=[32, 0, 7, 2049], CHUNKSIZE=[31, 16, 65]},
# truncate (O(n^2))
@@ -344,24 +362,27 @@ define = [
]
reentrant = true
code = '''
err = lfs2_mount(&lfs2, &cfg);
lfs2_t lfs2;
int err = lfs2_mount(&lfs2, cfg);
if (err) {
lfs2_format(&lfs2, &cfg) => 0;
lfs2_mount(&lfs2, &cfg) => 0;
lfs2_format(&lfs2, cfg) => 0;
lfs2_mount(&lfs2, cfg) => 0;
}
lfs2_file_t file;
uint8_t buffer[1024];
err = lfs2_file_open(&lfs2, &file, "avacado", LFS2_O_RDONLY);
assert(err == LFS2_ERR_NOENT || err == 0);
if (err == 0) {
// with syncs we could be any size, but it at least must be valid data
size = lfs2_file_size(&lfs2, &file);
lfs2_size_t size = lfs2_file_size(&lfs2, &file);
assert(size <= SIZE);
srand(1);
uint32_t prng = 1;
for (lfs2_size_t i = 0; i < size; i += CHUNKSIZE) {
lfs2_size_t chunk = lfs2_min(CHUNKSIZE, size-i);
lfs2_file_read(&lfs2, &file, buffer, chunk) => chunk;
for (lfs2_size_t b = 0; b < chunk; b++) {
assert(buffer[b] == (rand() & 0xff));
assert(buffer[b] == (TEST_PRNG(&prng) & 0xff));
}
}
lfs2_file_close(&lfs2, &file) => 0;
@@ -370,17 +391,17 @@ code = '''
// write
lfs2_file_open(&lfs2, &file, "avacado",
LFS2_O_WRONLY | LFS2_O_CREAT | MODE) => 0;
size = lfs2_file_size(&lfs2, &file);
lfs2_size_t size = lfs2_file_size(&lfs2, &file);
assert(size <= SIZE);
srand(1);
uint32_t prng = 1;
lfs2_size_t skip = (MODE == LFS2_O_APPEND) ? size : 0;
for (lfs2_size_t b = 0; b < skip; b++) {
rand();
TEST_PRNG(&prng);
}
for (lfs2_size_t i = skip; i < SIZE; i += CHUNKSIZE) {
lfs2_size_t chunk = lfs2_min(CHUNKSIZE, SIZE-i);
for (lfs2_size_t b = 0; b < chunk; b++) {
buffer[b] = rand() & 0xff;
buffer[b] = TEST_PRNG(&prng) & 0xff;
}
lfs2_file_write(&lfs2, &file, buffer, chunk) => chunk;
lfs2_file_sync(&lfs2, &file) => 0;
@@ -390,12 +411,12 @@ code = '''
// read
lfs2_file_open(&lfs2, &file, "avacado", LFS2_O_RDONLY) => 0;
lfs2_file_size(&lfs2, &file) => SIZE;
srand(1);
prng = 1;
for (lfs2_size_t i = 0; i < SIZE; i += CHUNKSIZE) {
lfs2_size_t chunk = lfs2_min(CHUNKSIZE, SIZE-i);
lfs2_file_read(&lfs2, &file, buffer, chunk) => chunk;
for (lfs2_size_t b = 0; b < chunk; b++) {
assert(buffer[b] == (rand() & 0xff));
assert(buffer[b] == (TEST_PRNG(&prng) & 0xff));
}
}
lfs2_file_read(&lfs2, &file, buffer, CHUNKSIZE) => 0;
@@ -403,19 +424,22 @@ code = '''
lfs2_unmount(&lfs2) => 0;
'''
[[case]] # many files
define.N = 300
[cases.test_files_many]
defines.N = 300
code = '''
lfs2_format(&lfs2, &cfg) => 0;
lfs2_t lfs2;
lfs2_format(&lfs2, cfg) => 0;
// create N files of 7 bytes
lfs2_mount(&lfs2, &cfg) => 0;
lfs2_mount(&lfs2, cfg) => 0;
for (int i = 0; i < N; i++) {
lfs2_file_t file;
char path[1024];
sprintf(path, "file_%03d", i);
lfs2_file_open(&lfs2, &file, path,
LFS2_O_WRONLY | LFS2_O_CREAT | LFS2_O_EXCL) => 0;
char wbuffer[1024];
size = 7;
snprintf(wbuffer, size, "Hi %03d", i);
lfs2_size_t size = 7;
sprintf(wbuffer, "Hi %03d", i);
lfs2_file_write(&lfs2, &file, wbuffer, size) => size;
lfs2_file_close(&lfs2, &file) => 0;
@@ -428,25 +452,28 @@ code = '''
lfs2_unmount(&lfs2) => 0;
'''
[[case]] # many files with power cycle
define.N = 300
[cases.test_files_many_power_cycle]
defines.N = 300
code = '''
lfs2_format(&lfs2, &cfg) => 0;
lfs2_t lfs2;
lfs2_format(&lfs2, cfg) => 0;
// create N files of 7 bytes
lfs2_mount(&lfs2, &cfg) => 0;
lfs2_mount(&lfs2, cfg) => 0;
for (int i = 0; i < N; i++) {
lfs2_file_t file;
char path[1024];
sprintf(path, "file_%03d", i);
lfs2_file_open(&lfs2, &file, path,
LFS2_O_WRONLY | LFS2_O_CREAT | LFS2_O_EXCL) => 0;
char wbuffer[1024];
size = 7;
snprintf(wbuffer, size, "Hi %03d", i);
lfs2_size_t size = 7;
sprintf(wbuffer, "Hi %03d", i);
lfs2_file_write(&lfs2, &file, wbuffer, size) => size;
lfs2_file_close(&lfs2, &file) => 0;
lfs2_unmount(&lfs2) => 0;
char rbuffer[1024];
lfs2_mount(&lfs2, &cfg) => 0;
lfs2_mount(&lfs2, cfg) => 0;
lfs2_file_open(&lfs2, &file, path, LFS2_O_RDONLY) => 0;
lfs2_file_read(&lfs2, &file, rbuffer, size) => size;
assert(strcmp(rbuffer, wbuffer) == 0);
@@ -455,22 +482,25 @@ code = '''
lfs2_unmount(&lfs2) => 0;
'''
[[case]] # many files with power loss
define.N = 300
[cases.test_files_many_power_loss]
defines.N = 300
reentrant = true
code = '''
err = lfs2_mount(&lfs2, &cfg);
lfs2_t lfs2;
int err = lfs2_mount(&lfs2, cfg);
if (err) {
lfs2_format(&lfs2, &cfg) => 0;
lfs2_mount(&lfs2, &cfg) => 0;
lfs2_format(&lfs2, cfg) => 0;
lfs2_mount(&lfs2, cfg) => 0;
}
// create N files of 7 bytes
for (int i = 0; i < N; i++) {
lfs2_file_t file;
char path[1024];
sprintf(path, "file_%03d", i);
err = lfs2_file_open(&lfs2, &file, path, LFS2_O_WRONLY | LFS2_O_CREAT);
char wbuffer[1024];
size = 7;
snprintf(wbuffer, size, "Hi %03d", i);
lfs2_size_t size = 7;
sprintf(wbuffer, "Hi %03d", i);
if ((lfs2_size_t)lfs2_file_size(&lfs2, &file) != size) {
lfs2_file_write(&lfs2, &file, wbuffer, size) => size;
}