4fe0738ff4
These are really just different flavors of test.py and test_runner.c
without support for power-loss testing, but with support for measuring
the cumulative number of bytes read, programmed, and erased.
Note that the existing define parameterization should work perfectly
fine for running benchmarks across various dimensions:
./scripts/bench.py \
runners/bench_runner \
bench_file_read \
-gnor \
-DSIZE='range(0,131072,1024)'
Also added a couple basic benchmarks as a starting point.
110 lines
2.8 KiB
TOML
110 lines
2.8 KiB
TOML
|
|
|
|
# deterministic prng
|
|
code = '''
|
|
static uint32_t xorshift32(uint32_t *state) {
|
|
uint32_t x = *state;
|
|
x ^= x << 13;
|
|
x ^= x >> 17;
|
|
x ^= x << 5;
|
|
*state = x;
|
|
return x;
|
|
}
|
|
'''
|
|
|
|
[cases.bench_file_read]
|
|
# 0 = in-order
|
|
# 1 = reversed-order
|
|
# 2 = random-order
|
|
defines.ORDER = [0, 1, 2]
|
|
defines.SIZE = '128*1024'
|
|
defines.CHUNK_SIZE = 64
|
|
code = '''
|
|
lfs_t lfs;
|
|
lfs_format(&lfs, cfg) => 0;
|
|
lfs_mount(&lfs, cfg) => 0;
|
|
lfs_size_t chunks = (SIZE+CHUNK_SIZE-1)/CHUNK_SIZE;
|
|
|
|
// first write the file
|
|
lfs_file_t file;
|
|
uint8_t buffer[CHUNK_SIZE];
|
|
lfs_file_open(&lfs, &file, "file",
|
|
LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
|
|
for (lfs_size_t i = 0; i < chunks; i++) {
|
|
uint32_t chunk_prng = i;
|
|
for (lfs_size_t j = 0; j < CHUNK_SIZE; j++) {
|
|
buffer[j] = xorshift32(&chunk_prng);
|
|
}
|
|
|
|
lfs_file_write(&lfs, &file, buffer, CHUNK_SIZE) => CHUNK_SIZE;
|
|
}
|
|
lfs_file_write(&lfs, &file, buffer, CHUNK_SIZE) => CHUNK_SIZE;
|
|
lfs_file_close(&lfs, &file) => 0;
|
|
|
|
// then read the file
|
|
BENCH_START();
|
|
lfs_file_open(&lfs, &file, "file", LFS_O_RDONLY) => 0;
|
|
|
|
uint32_t prng = 42;
|
|
for (lfs_size_t i = 0; i < chunks; i++) {
|
|
lfs_off_t i_
|
|
= (ORDER == 0) ? i
|
|
: (ORDER == 1) ? (chunks-1-i)
|
|
: xorshift32(&prng) % chunks;
|
|
lfs_file_seek(&lfs, &file, i_*CHUNK_SIZE, LFS_SEEK_SET)
|
|
=> i_*CHUNK_SIZE;
|
|
lfs_file_read(&lfs, &file, buffer, CHUNK_SIZE) => CHUNK_SIZE;
|
|
|
|
uint32_t chunk_prng = i_;
|
|
for (lfs_size_t j = 0; j < CHUNK_SIZE; j++) {
|
|
assert(buffer[j] == xorshift32(&chunk_prng));
|
|
}
|
|
}
|
|
|
|
lfs_file_close(&lfs, &file) => 0;
|
|
BENCH_STOP();
|
|
|
|
lfs_unmount(&lfs) => 0;
|
|
'''
|
|
|
|
[cases.bench_file_write]
|
|
# 0 = in-order
|
|
# 1 = reversed-order
|
|
# 2 = random-order
|
|
defines.ORDER = [0, 1, 2]
|
|
defines.SIZE = '128*1024'
|
|
defines.CHUNK_SIZE = 64
|
|
code = '''
|
|
lfs_t lfs;
|
|
lfs_format(&lfs, cfg) => 0;
|
|
lfs_mount(&lfs, cfg) => 0;
|
|
lfs_size_t chunks = (SIZE+CHUNK_SIZE-1)/CHUNK_SIZE;
|
|
|
|
BENCH_START();
|
|
lfs_file_t file;
|
|
lfs_file_open(&lfs, &file, "file",
|
|
LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
|
|
|
|
uint8_t buffer[CHUNK_SIZE];
|
|
uint32_t prng = 42;
|
|
for (lfs_size_t i = 0; i < chunks; i++) {
|
|
lfs_off_t i_
|
|
= (ORDER == 0) ? i
|
|
: (ORDER == 1) ? (chunks-1-i)
|
|
: xorshift32(&prng) % chunks;
|
|
uint32_t chunk_prng = i_;
|
|
for (lfs_size_t j = 0; j < CHUNK_SIZE; j++) {
|
|
buffer[j] = xorshift32(&chunk_prng);
|
|
}
|
|
|
|
lfs_file_seek(&lfs, &file, i_*CHUNK_SIZE, LFS_SEEK_SET)
|
|
=> i_*CHUNK_SIZE;
|
|
lfs_file_write(&lfs, &file, buffer, CHUNK_SIZE) => CHUNK_SIZE;
|
|
}
|
|
|
|
lfs_file_close(&lfs, &file) => 0;
|
|
BENCH_STOP();
|
|
|
|
lfs_unmount(&lfs) => 0;
|
|
'''
|