runners: Moved test/bench defines into test/bench_defines.h

The big TEST_IMPLICIT_DEFINES and TEST_CFG macros have been a big
pain-in-the-ass to maintain. Mostly due to C preprocessor annoyances
(bleh escaped newlines) and no-ifdef workarounds, which make a real mess
of things.

This does two things:

1. Moves all the defines out of test_runner.h and into test_defines.h
   (same for benches).

2. Inverts the include logic such that test_defines.h gets included many
   times with various "query macros" defined.

   Currently just two, but can easily add more:

   1. TEST_DEFINE(name, value) - name and default value for a define
   2. TEST_CFG(name, value) - name and value for a cfg field

   This seems to work surprisingly well. It solves all of the above C
   preprocessor issues, and provides a flexible method for defining test
   defines.

   Note an important part of making this work is that test_defines.h
   expands to an empty string by default.
This commit is contained in:
Christopher Haster
2026-01-08 03:07:28 -06:00
parent d3b1bf2a88
commit 1b70c1f199
6 changed files with 220 additions and 204 deletions
+18 -15
View File
@@ -122,26 +122,23 @@ typedef struct bench_id {
// implicit defines declared here
#define BENCH_DEFINE(k, v) \
intmax_t k;
BENCH_IMPLICIT_DEFINES
intmax_t k;
#include "bench_defines.h"
#undef BENCH_DEFINE
#define BENCH_DEFINE(k, v) \
intmax_t bench_define_##k(void *data, size_t i) { \
(void)data; \
(void)i; \
return v; \
}
BENCH_IMPLICIT_DEFINES
intmax_t bench_define_##k(void *data, size_t i) { \
(void)data; \
(void)i; \
return v; \
}
#include "bench_defines.h"
#undef BENCH_DEFINE
const bench_define_t bench_implicit_defines[] = {
#define BENCH_DEFINE(k, v) \
{#k, &k, bench_define_##k, NULL, 1},
BENCH_IMPLICIT_DEFINES
{#k, &k, bench_define_##k, NULL, 1},
#include "bench_defines.h"
#undef BENCH_DEFINE
};
const size_t bench_implicit_define_count
@@ -1351,14 +1348,20 @@ void perm_run(
.prog = lfs3_emubd_prog,
.erase = lfs3_emubd_erase,
.sync = lfs3_emubd_sync,
BENCH_CFG
#define BENCH_CFG(k, v) \
.k = v,
#include "bench_defines.h"
#undef BENCH_CFG
};
struct lfs3_emubd_cfg bdcfg = {
.read_sleep = bench_read_sleep,
.prog_sleep = bench_prog_sleep,
.erase_sleep = bench_erase_sleep,
BENCH_BDCFG
#define BENCH_BDCFG(k, v) \
.k = v,
#include "bench_defines.h"
#undef BENCH_CFG
};
int err = lfs3_emubd_createcfg(&cfg, bench_disk_path, &bdcfg);