Added BENCH/TEST_PRNG, replacing other ad-hoc sources of randomness

When you add a function to every benchmark suite, you know if should
probably be provided by the benchmark runner itself. That being said,
randomness in tests/benchmarks is a bit tricky because it needs to be
strictly controlled and reproducible.

No global state is used, allowing tests/benches to maintain multiple
randomness stream which can be useful for checking results during a run.

There's an argument for having global prng state in that the prng could
be preserved across power-loss, but I have yet to see a use for this,
and it would add a significant requirement to any future test/bench runner.
This commit is contained in:
Christopher Haster
2022-11-30 11:23:04 -06:00
parent d8e7ffb7fd
commit b0382fa891
10 changed files with 134 additions and 124 deletions
+2 -2
View File
@@ -77,13 +77,13 @@ code = '''
lfs_mount(&lfs, cfg) => 0;
}
srand(1);
uint32_t prng = 1;
const char alpha[] = "abcdefghijklmnopqrstuvwxyz";
for (unsigned i = 0; i < CYCLES; i++) {
// create random path
char full_path[256];
for (unsigned d = 0; d < DEPTH; d++) {
sprintf(&full_path[2*d], "/%c", alpha[rand() % FILES]);
sprintf(&full_path[2*d], "/%c", alpha[TEST_PRNG(&prng) % FILES]);
}
// if it does not exist, we create it, else we destroy