From 1b70c1f1997b281723fa8c9c566b9c904ea17b62 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Thu, 8 Jan 2026 03:07:28 -0600 Subject: [PATCH] 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. --- runners/bench_defines.h | 73 ++++++++++++++++++++++++++++++++++ runners/bench_runner.c | 33 +++++++++------- runners/bench_runner.h | 86 ++--------------------------------------- runners/test_defines.h | 73 ++++++++++++++++++++++++++++++++++ runners/test_runner.c | 73 +++++++++++++++++++++++----------- runners/test_runner.h | 86 ++--------------------------------------- 6 files changed, 220 insertions(+), 204 deletions(-) create mode 100644 runners/bench_defines.h create mode 100644 runners/test_defines.h diff --git a/runners/bench_defines.h b/runners/bench_defines.h new file mode 100644 index 00000000..e5e64d19 --- /dev/null +++ b/runners/bench_defines.h @@ -0,0 +1,73 @@ +// littlefs bench runner defines + + +// preconfigured defines that control how benches run +#ifdef BENCH_DEFINE + // name value (overridable) + BENCH_DEFINE(READ_SIZE, 1 ) + BENCH_DEFINE(PROG_SIZE, 1 ) + BENCH_DEFINE(BLOCK_SIZE, 4096 ) + BENCH_DEFINE(BLOCK_COUNT, DISK_SIZE/BLOCK_SIZE ) + BENCH_DEFINE(DISK_SIZE, 1024*1024 ) + BENCH_DEFINE(BLOCK_RECYCLES, -1 ) + BENCH_DEFINE(RCACHE_SIZE, LFS3_MAX(16, READ_SIZE) ) + BENCH_DEFINE(PCACHE_SIZE, LFS3_MAX(16, PROG_SIZE) ) + BENCH_DEFINE(FCACHE_SIZE, 16 ) + BENCH_DEFINE(LOOKAHEAD_SIZE, 16 ) + BENCH_DEFINE(GC_FLAGS, LFS3_GC_GC ) + BENCH_DEFINE(GC_STEPS, 0 ) + BENCH_DEFINE(GC_LOOKAHEAD_THRESH, -1 ) + BENCH_DEFINE(GC_LOOKGBMAP_THRESH, -1 ) + BENCH_DEFINE(GC_PREERASE_COUNT, -1 ) + BENCH_DEFINE(GC_COMPACT_THRESH, 0 ) + BENCH_DEFINE(SHRUB_SIZE, BLOCK_SIZE/4 ) + BENCH_DEFINE(FRAGMENT_SIZE, LFS3_MIN(BLOCK_SIZE/8, 512) ) + BENCH_DEFINE(CRYSTAL_THRESH, BLOCK_SIZE/8 ) + BENCH_DEFINE(LOOKGBMAP_THRESH, BLOCK_COUNT/4 ) + BENCH_DEFINE(ERASE_VALUE, 0xff ) + BENCH_DEFINE(ERASE_CYCLES, 0 ) + BENCH_DEFINE(BADBLOCK_BEHAVIOR, LFS3_EMUBD_BADBLOCK_PROGERROR ) + BENCH_DEFINE(POWERLOSS_BEHAVIOR, LFS3_EMUBD_POWERLOSS_ATOMIC ) + BENCH_DEFINE(EMUBD_SEED, 0 ) +#endif + + +// struct lfs3_cfg fields +#ifdef BENCH_CFG + BENCH_CFG(read_size, READ_SIZE ) + BENCH_CFG(prog_size, PROG_SIZE ) + BENCH_CFG(block_size, BLOCK_SIZE ) + BENCH_CFG(block_count, BLOCK_COUNT ) + BENCH_CFG(block_recycles, BLOCK_RECYCLES ) + BENCH_CFG(rcache_size, RCACHE_SIZE ) + BENCH_CFG(pcache_size, PCACHE_SIZE ) + BENCH_CFG(fcache_size, FCACHE_SIZE ) + BENCH_CFG(lookahead_size, LOOKAHEAD_SIZE ) + #ifdef LFS3_GBMAP + BENCH_CFG(gc_lookgbmap_thresh, GC_LOOKGBMAP_THRESH ) + BENCH_CFG(lookgbmap_thresh, LOOKGBMAP_THRESH ) + #endif + #ifdef LFS3_PREERASE + BENCH_CFG(gc_preerase_count, GC_PREERASE_COUNT ) + #endif + #ifdef LFS3_GC + BENCH_CFG(gc_flags, GC_FLAGS ) + BENCH_CFG(gc_steps, GC_STEPS ) + #endif + BENCH_CFG(gc_lookahead_thresh, GC_LOOKAHEAD_THRESH ) + BENCH_CFG(gc_compact_thresh, GC_COMPACT_THRESH ) + BENCH_CFG(shrub_size, SHRUB_SIZE ) + BENCH_CFG(fragment_size, FRAGMENT_SIZE ) + BENCH_CFG(crystal_thresh, CRYSTAL_THRESH ) +#endif + + +// struct lfs3_*bd_cfg fields +#ifdef BENCH_BDCFG + BENCH_BDCFG(erase_value, ERASE_VALUE ) + BENCH_BDCFG(erase_cycles, ERASE_CYCLES ) + BENCH_BDCFG(badblock_behavior, BADBLOCK_BEHAVIOR ) + BENCH_BDCFG(powerloss_behavior, POWERLOSS_BEHAVIOR ) + BENCH_BDCFG(seed, EMUBD_SEED ) +#endif + diff --git a/runners/bench_runner.c b/runners/bench_runner.c index 2e927174..3c7eac6b 100644 --- a/runners/bench_runner.c +++ b/runners/bench_runner.c @@ -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); diff --git a/runners/bench_runner.h b/runners/bench_runner.h index fe11ecad..983db22c 100644 --- a/runners/bench_runner.h +++ b/runners/bench_runner.h @@ -101,91 +101,11 @@ void bench_permutation(size_t i, uint32_t *buffer, size_t size); #define BENCH_PERMUTATION(i, buffer, size) bench_permutation(i, buffer, size) -// a few preconfigured defines that control how benches run -#define BENCH_IMPLICIT_DEFINES \ - /* name value (overridable) */ \ - BENCH_DEFINE(READ_SIZE, 1 ) \ - BENCH_DEFINE(PROG_SIZE, 1 ) \ - BENCH_DEFINE(BLOCK_SIZE, 4096 ) \ - BENCH_DEFINE(BLOCK_COUNT, DISK_SIZE/BLOCK_SIZE ) \ - BENCH_DEFINE(DISK_SIZE, 1024*1024 ) \ - BENCH_DEFINE(BLOCK_RECYCLES, -1 ) \ - BENCH_DEFINE(RCACHE_SIZE, LFS3_MAX(16, READ_SIZE) ) \ - BENCH_DEFINE(PCACHE_SIZE, LFS3_MAX(16, PROG_SIZE) ) \ - BENCH_DEFINE(FCACHE_SIZE, 16 ) \ - BENCH_DEFINE(LOOKAHEAD_SIZE, 16 ) \ - BENCH_DEFINE(GC_FLAGS, LFS3_GC_GC ) \ - BENCH_DEFINE(GC_STEPS, 0 ) \ - BENCH_DEFINE(GC_LOOKAHEAD_THRESH, -1 ) \ - BENCH_DEFINE(GC_LOOKGBMAP_THRESH, -1 ) \ - BENCH_DEFINE(GC_PREERASE_COUNT, -1 ) \ - BENCH_DEFINE(GC_COMPACT_THRESH, 0 ) \ - BENCH_DEFINE(SHRUB_SIZE, BLOCK_SIZE/4 ) \ - BENCH_DEFINE(FRAGMENT_SIZE, LFS3_MIN(BLOCK_SIZE/8, 512) ) \ - BENCH_DEFINE(CRYSTAL_THRESH, BLOCK_SIZE/8 ) \ - BENCH_DEFINE(LOOKGBMAP_THRESH, BLOCK_COUNT/4 ) \ - BENCH_DEFINE(ERASE_VALUE, 0xff ) \ - BENCH_DEFINE(ERASE_CYCLES, 0 ) \ - BENCH_DEFINE(BADBLOCK_BEHAVIOR, LFS3_EMUBD_BADBLOCK_PROGERROR ) \ - BENCH_DEFINE(POWERLOSS_BEHAVIOR, LFS3_EMUBD_POWERLOSS_ATOMIC ) \ - BENCH_DEFINE(EMUBD_SEED, 0 ) - -// declare defines as global intmax_ts +// declare implicit defines as global intmax_ts #define BENCH_DEFINE(k, v) \ - extern intmax_t k; - - BENCH_IMPLICIT_DEFINES + extern intmax_t k; + #include "bench_defines.h" #undef BENCH_DEFINE -// map defines to cfg struct fields -#define BENCH_CFG \ - .read_size = READ_SIZE, \ - .prog_size = PROG_SIZE, \ - .block_size = BLOCK_SIZE, \ - .block_count = BLOCK_COUNT, \ - .block_recycles = BLOCK_RECYCLES, \ - .rcache_size = RCACHE_SIZE, \ - .pcache_size = PCACHE_SIZE, \ - .fcache_size = FCACHE_SIZE, \ - .lookahead_size = LOOKAHEAD_SIZE, \ - BENCH_GBMAP_CFG \ - BENCH_PREERASE_CFG \ - BENCH_GC_CFG \ - .gc_lookahead_thresh = GC_LOOKAHEAD_THRESH, \ - .gc_compact_thresh = GC_COMPACT_THRESH, \ - .shrub_size = SHRUB_SIZE, \ - .fragment_size = FRAGMENT_SIZE, \ - .crystal_thresh = CRYSTAL_THRESH, - -#ifdef LFS3_GBMAP -#define BENCH_GBMAP_CFG \ - .gc_lookgbmap_thresh = GC_LOOKGBMAP_THRESH, \ - .lookgbmap_thresh = LOOKGBMAP_THRESH, -#else -#define BENCH_GBMAP_CFG -#endif - -#ifdef LFS3_PREERASE -#define BENCH_PREERASE_CFG \ - .gc_preerase_count = GC_PREERASE_COUNT, -#else -#define BENCH_PREERASE_CFG -#endif - -#ifdef LFS3_GC -#define BENCH_GC_CFG \ - .gc_flags = GC_FLAGS, \ - .gc_steps = GC_STEPS, -#else -#define BENCH_GC_CFG -#endif - -#define BENCH_BDCFG \ - .erase_value = ERASE_VALUE, \ - .erase_cycles = ERASE_CYCLES, \ - .badblock_behavior = BADBLOCK_BEHAVIOR, \ - .powerloss_behavior = POWERLOSS_BEHAVIOR, \ - .seed = EMUBD_SEED, - #endif diff --git a/runners/test_defines.h b/runners/test_defines.h new file mode 100644 index 00000000..afdc4a96 --- /dev/null +++ b/runners/test_defines.h @@ -0,0 +1,73 @@ +// littlefs test runner defines + + +// preconfigured defines that control how tests run +#ifdef TEST_DEFINE + // name value (overridable) + TEST_DEFINE(READ_SIZE, 1 ) + TEST_DEFINE(PROG_SIZE, 1 ) + TEST_DEFINE(BLOCK_SIZE, 4096 ) + TEST_DEFINE(BLOCK_COUNT, DISK_SIZE/BLOCK_SIZE ) + TEST_DEFINE(DISK_SIZE, 1024*1024 ) + TEST_DEFINE(BLOCK_RECYCLES, -1 ) + TEST_DEFINE(RCACHE_SIZE, LFS3_MAX(16, READ_SIZE) ) + TEST_DEFINE(PCACHE_SIZE, LFS3_MAX(16, PROG_SIZE) ) + TEST_DEFINE(FCACHE_SIZE, 16 ) + TEST_DEFINE(LOOKAHEAD_SIZE, 16 ) + TEST_DEFINE(GC_FLAGS, LFS3_GC_GC ) + TEST_DEFINE(GC_STEPS, 0 ) + TEST_DEFINE(GC_LOOKAHEAD_THRESH, -1 ) + TEST_DEFINE(GC_LOOKGBMAP_THRESH, -1 ) + TEST_DEFINE(GC_PREERASE_COUNT, -1 ) + TEST_DEFINE(GC_COMPACT_THRESH, 0 ) + TEST_DEFINE(SHRUB_SIZE, BLOCK_SIZE/4 ) + TEST_DEFINE(FRAGMENT_SIZE, LFS3_MIN(BLOCK_SIZE/8, 512) ) + TEST_DEFINE(CRYSTAL_THRESH, BLOCK_SIZE/8 ) + TEST_DEFINE(LOOKGBMAP_THRESH, BLOCK_COUNT/4 ) + TEST_DEFINE(ERASE_VALUE, 0xff ) + TEST_DEFINE(ERASE_CYCLES, 0 ) + TEST_DEFINE(BADBLOCK_BEHAVIOR, LFS3_EMUBD_BADBLOCK_PROGERROR ) + TEST_DEFINE(POWERLOSS_BEHAVIOR, LFS3_EMUBD_POWERLOSS_ATOMIC ) + TEST_DEFINE(EMUBD_SEED, 0 ) +#endif + + +// struct lfs3_cfg fields +#ifdef TEST_CFG + TEST_CFG(read_size, READ_SIZE ) + TEST_CFG(prog_size, PROG_SIZE ) + TEST_CFG(block_size, BLOCK_SIZE ) + TEST_CFG(block_count, BLOCK_COUNT ) + TEST_CFG(block_recycles, BLOCK_RECYCLES ) + TEST_CFG(rcache_size, RCACHE_SIZE ) + TEST_CFG(pcache_size, PCACHE_SIZE ) + TEST_CFG(fcache_size, FCACHE_SIZE ) + TEST_CFG(lookahead_size, LOOKAHEAD_SIZE ) + #ifdef LFS3_GBMAP + TEST_CFG(gc_lookgbmap_thresh, GC_LOOKGBMAP_THRESH ) + TEST_CFG(lookgbmap_thresh, LOOKGBMAP_THRESH ) + #endif + #ifdef LFS3_PREERASE + TEST_CFG(gc_preerase_count, GC_PREERASE_COUNT ) + #endif + #ifdef LFS3_GC + TEST_CFG(gc_flags, GC_FLAGS ) + TEST_CFG(gc_steps, GC_STEPS ) + #endif + TEST_CFG(gc_lookahead_thresh, GC_LOOKAHEAD_THRESH ) + TEST_CFG(gc_compact_thresh, GC_COMPACT_THRESH ) + TEST_CFG(shrub_size, SHRUB_SIZE ) + TEST_CFG(fragment_size, FRAGMENT_SIZE ) + TEST_CFG(crystal_thresh, CRYSTAL_THRESH ) +#endif + + +// struct lfs3_*bd_cfg fields +#ifdef TEST_BDCFG + TEST_BDCFG(erase_value, ERASE_VALUE ) + TEST_BDCFG(erase_cycles, ERASE_CYCLES ) + TEST_BDCFG(badblock_behavior, BADBLOCK_BEHAVIOR ) + TEST_BDCFG(powerloss_behavior, POWERLOSS_BEHAVIOR ) + TEST_BDCFG(seed, EMUBD_SEED ) +#endif + diff --git a/runners/test_runner.c b/runners/test_runner.c index ff1338be..4449029a 100644 --- a/runners/test_runner.c +++ b/runners/test_runner.c @@ -133,26 +133,23 @@ typedef struct test_id { // implicit defines declared here #define TEST_DEFINE(k, v) \ - intmax_t k; - - TEST_IMPLICIT_DEFINES + intmax_t k; + #include "test_defines.h" #undef TEST_DEFINE #define TEST_DEFINE(k, v) \ - intmax_t test_define_##k(void *data, size_t i) { \ - (void)data; \ - (void)i; \ - return v; \ - } - - TEST_IMPLICIT_DEFINES + intmax_t test_define_##k(void *data, size_t i) { \ + (void)data; \ + (void)i; \ + return v; \ + } + #include "test_defines.h" #undef TEST_DEFINE const test_define_t test_implicit_defines[] = { #define TEST_DEFINE(k, v) \ - {#k, &k, test_define_##k, NULL, 1}, - - TEST_IMPLICIT_DEFINES + {#k, &k, test_define_##k, NULL, 1}, + #include "test_defines.h" #undef TEST_DEFINE }; const size_t test_implicit_define_count @@ -1315,14 +1312,20 @@ static void run_powerloss_none( .prog = lfs3_emubd_prog, .erase = lfs3_emubd_erase, .sync = lfs3_emubd_sync, - TEST_CFG + #define TEST_CFG(k, v) \ + .k = v, + #include "test_defines.h" + #undef TEST_CFG }; struct lfs3_emubd_cfg bdcfg = { .read_sleep = test_read_sleep, .prog_sleep = test_prog_sleep, .erase_sleep = test_erase_sleep, - TEST_BDCFG + #define TEST_BDCFG(k, v) \ + .k = v, + #include "test_defines.h" + #undef TEST_BDCFG }; int err = lfs3_emubd_createcfg(&cfg, test_disk_path, &bdcfg); @@ -1375,7 +1378,10 @@ static void run_powerloss_linear( .prog = lfs3_emubd_prog, .erase = lfs3_emubd_erase, .sync = lfs3_emubd_sync, - TEST_CFG + #define TEST_CFG(k, v) \ + .k = v, + #include "test_defines.h" + #undef TEST_CFG }; struct lfs3_emubd_cfg bdcfg = { @@ -1387,7 +1393,10 @@ static void run_powerloss_linear( : 0, .powerloss_cb = powerloss_longjmp, .powerloss_data = &powerloss_jmp, - TEST_BDCFG + #define TEST_BDCFG(k, v) \ + .k = v, + #include "test_defines.h" + #undef TEST_BDCFG }; int err = lfs3_emubd_createcfg(&cfg, test_disk_path, &bdcfg); @@ -1451,7 +1460,10 @@ static void run_powerloss_log( .prog = lfs3_emubd_prog, .erase = lfs3_emubd_erase, .sync = lfs3_emubd_sync, - TEST_CFG + #define TEST_CFG(k, v) \ + .k = v, + #include "test_defines.h" + #undef TEST_CFG }; struct lfs3_emubd_cfg bdcfg = { @@ -1463,7 +1475,10 @@ static void run_powerloss_log( : 0, .powerloss_cb = powerloss_longjmp, .powerloss_data = &powerloss_jmp, - TEST_BDCFG + #define TEST_BDCFG(k, v) \ + .k = v, + #include "test_defines.h" + #undef TEST_BDCFG }; int err = lfs3_emubd_createcfg(&cfg, test_disk_path, &bdcfg); @@ -1527,7 +1542,10 @@ static void run_powerloss_cycles( .prog = lfs3_emubd_prog, .erase = lfs3_emubd_erase, .sync = lfs3_emubd_sync, - TEST_CFG + #define TEST_CFG(k, v) \ + .k = v, + #include "test_defines.h" + #undef TEST_CFG }; struct lfs3_emubd_cfg bdcfg = { @@ -1539,7 +1557,10 @@ static void run_powerloss_cycles( : 0, .powerloss_cb = powerloss_longjmp, .powerloss_data = &powerloss_jmp, - TEST_BDCFG + #define TEST_BDCFG(k, v) \ + .k = v, + #include "test_defines.h" + #undef TEST_BDCFG }; int err = lfs3_emubd_createcfg(&cfg, test_disk_path, &bdcfg); @@ -1701,7 +1722,10 @@ static void run_powerloss_exhaustive( .prog = lfs3_emubd_prog, .erase = lfs3_emubd_erase, .sync = lfs3_emubd_sync, - TEST_CFG + #define TEST_CFG(k, v) \ + .k = v, + #include "test_defines.h" + #undef TEST_CFG }; struct lfs3_emubd_cfg bdcfg = { @@ -1710,7 +1734,10 @@ static void run_powerloss_exhaustive( .erase_sleep = test_erase_sleep, .powerloss_cb = powerloss_exhaustive_branch, .powerloss_data = NULL, - TEST_BDCFG + #define TEST_BDCFG(k, v) \ + .k = v, + #include "test_defines.h" + #undef TEST_BDCFG }; int err = lfs3_emubd_createcfg(&cfg, test_disk_path, &bdcfg); diff --git a/runners/test_runner.h b/runners/test_runner.h index 65fc3126..b6c94bc3 100644 --- a/runners/test_runner.h +++ b/runners/test_runner.h @@ -92,91 +92,11 @@ void test_permutation(size_t i, uint32_t *buffer, size_t size); #define TEST_PERMUTATION(i, buffer, size) test_permutation(i, buffer, size) -// a few preconfigured defines that control how tests run -#define TEST_IMPLICIT_DEFINES \ - /* name value (overridable) */ \ - TEST_DEFINE(READ_SIZE, 1 ) \ - TEST_DEFINE(PROG_SIZE, 1 ) \ - TEST_DEFINE(BLOCK_SIZE, 4096 ) \ - TEST_DEFINE(BLOCK_COUNT, DISK_SIZE/BLOCK_SIZE ) \ - TEST_DEFINE(DISK_SIZE, 1024*1024 ) \ - TEST_DEFINE(BLOCK_RECYCLES, -1 ) \ - TEST_DEFINE(RCACHE_SIZE, LFS3_MAX(16, READ_SIZE) ) \ - TEST_DEFINE(PCACHE_SIZE, LFS3_MAX(16, PROG_SIZE) ) \ - TEST_DEFINE(FCACHE_SIZE, 16 ) \ - TEST_DEFINE(LOOKAHEAD_SIZE, 16 ) \ - TEST_DEFINE(GC_FLAGS, LFS3_GC_GC ) \ - TEST_DEFINE(GC_STEPS, 0 ) \ - TEST_DEFINE(GC_LOOKAHEAD_THRESH, -1 ) \ - TEST_DEFINE(GC_LOOKGBMAP_THRESH, -1 ) \ - TEST_DEFINE(GC_PREERASE_COUNT, -1 ) \ - TEST_DEFINE(GC_COMPACT_THRESH, 0 ) \ - TEST_DEFINE(SHRUB_SIZE, BLOCK_SIZE/4 ) \ - TEST_DEFINE(FRAGMENT_SIZE, LFS3_MIN(BLOCK_SIZE/8, 512) ) \ - TEST_DEFINE(CRYSTAL_THRESH, BLOCK_SIZE/8 ) \ - TEST_DEFINE(LOOKGBMAP_THRESH, BLOCK_COUNT/4 ) \ - TEST_DEFINE(ERASE_VALUE, 0xff ) \ - TEST_DEFINE(ERASE_CYCLES, 0 ) \ - TEST_DEFINE(BADBLOCK_BEHAVIOR, LFS3_EMUBD_BADBLOCK_PROGERROR ) \ - TEST_DEFINE(POWERLOSS_BEHAVIOR, LFS3_EMUBD_POWERLOSS_ATOMIC ) \ - TEST_DEFINE(EMUBD_SEED, 0 ) - -// declare defines as global intmax_ts +// declare implicit defines as global intmax_ts #define TEST_DEFINE(k, v) \ - extern intmax_t k; - - TEST_IMPLICIT_DEFINES + extern intmax_t k; + #include "test_defines.h" #undef TEST_DEFINE -// map defines to cfg struct fields -#define TEST_CFG \ - .read_size = READ_SIZE, \ - .prog_size = PROG_SIZE, \ - .block_size = BLOCK_SIZE, \ - .block_count = BLOCK_COUNT, \ - .block_recycles = BLOCK_RECYCLES, \ - .rcache_size = RCACHE_SIZE, \ - .pcache_size = PCACHE_SIZE, \ - .fcache_size = FCACHE_SIZE, \ - .lookahead_size = LOOKAHEAD_SIZE, \ - TEST_GBMAP_CFG \ - TEST_PREERASE_CFG \ - TEST_GC_CFG \ - .gc_lookahead_thresh = GC_LOOKAHEAD_THRESH, \ - .gc_compact_thresh = GC_COMPACT_THRESH, \ - .shrub_size = SHRUB_SIZE, \ - .fragment_size = FRAGMENT_SIZE, \ - .crystal_thresh = CRYSTAL_THRESH, - -#ifdef LFS3_GBMAP -#define TEST_GBMAP_CFG \ - .gc_lookgbmap_thresh = GC_LOOKGBMAP_THRESH, \ - .lookgbmap_thresh = LOOKGBMAP_THRESH, -#else -#define TEST_GBMAP_CFG -#endif - -#ifdef LFS3_PREERASE -#define TEST_PREERASE_CFG \ - .gc_preerase_count = GC_PREERASE_COUNT, -#else -#define TEST_PREERASE_CFG -#endif - -#ifdef LFS3_GC -#define TEST_GC_CFG \ - .gc_flags = GC_FLAGS, \ - .gc_steps = GC_STEPS, -#else -#define TEST_GC_CFG -#endif - -#define TEST_BDCFG \ - .erase_value = ERASE_VALUE, \ - .erase_cycles = ERASE_CYCLES, \ - .badblock_behavior = BADBLOCK_BEHAVIOR, \ - .powerloss_behavior = POWERLOSS_BEHAVIOR, \ - .seed = EMUBD_SEED, - #endif