Files
littlefs/runners/test_defines.h
T
Christopher Haster 1b70c1f199 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.
2026-02-10 15:22:38 -06:00

74 lines
4.1 KiB
C

// 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