runners: Reworked test/bench for out-of-tree extensions

The main changes:

- Added TEST_DEFINES and BENCH_DEFINES to allow overriding the default
  test/bench define header:

    -DTEST_DEFINES=my_test_defines.h

  Note these are VERY different from LFS_DEFINES upstream. They aren't a
  typical header file, and are included multiple times with various
  query macros.

  It's hacky, but works surprisingly well.

  Or maybe I'll just do anything to avoid having to write multiline
  macros. Ugh, backslashes.

- Moved more logic into bench/test_defines.h, including everything
  needed to integrate other filesystems out-of-tree.

  This mostly meant moving all of the cfg initialization logic into its
  own query macro (replacing the BENCH/TEST_CFG field macros).

But this also includes a bunch of small tweaks encountered while trying
to get external benchmarks running again.

The external benchmarks include several other filesystems (littlefs2,
SPIFFS, Yaffs2), and I'm hoping this injectable/queryable header thing
will do a good job at avoiding a maintenance headache. (At least a
better job than forking bench_runner.c, which was the previous
solution.)
This commit is contained in:
Christopher Haster
2026-01-30 13:15:04 -06:00
parent 91cbcfd389
commit 4405ad47e4
11 changed files with 409 additions and 310 deletions
+29 -2
View File
@@ -7,6 +7,24 @@
#ifndef TEST_RUNNER_H
#define TEST_RUNNER_H
#define TEST_STRINGIFY_(x) #x
#define TEST_STRINGIFY(x) TEST_STRINGIFY_(x)
// the default TEST_DEFINES path can be overridden to add shims for
// other filesystems out-of-tree
//
// note this is an unusual header file! instead of being included once,
// TEST_DEFINES is included several times with various "query macros"
// defined before inclusion:
//
// - TEST_INCLUDE - common includes (optional)
// - TEST_DEFINE(name, value) - name and default values for test defines
// - TEST_CFG[+_CFG] - struct lfs3_cfg definition
// - TEST_BDCFG[+_CFG] - struct lfs3_*bd_cfg definition
//
#ifndef TEST_DEFINES
#define TEST_DEFINES runners/test_defines.h
#endif
// default to using emubd for tests
#if !defined(TEST_EMUBD) && !defined(TEST_KIWIBD)
@@ -39,11 +57,16 @@ void test_trace(const char *fmt, ...);
// note these are indirectly included in any generated files
#define TEST_INCLUDE
#include TEST_STRINGIFY(TEST_DEFINES)
#undef TEST_INCLUDE
#ifndef TEST_KIWIBD
#include "bd/lfs3_emubd.h"
#else
#include "bd/lfs3_kiwibd.h"
#endif
#include "lfs3_util.h"
#include <stdio.h>
#include <stdint.h>
@@ -80,7 +103,7 @@ struct test_case {
size_t permutations;
bool (*if_)(void);
void (*run)(struct lfs3_cfg *cfg);
void (*run)(const struct lfs3_cfg *cfg);
};
struct test_suite {
@@ -136,18 +159,22 @@ size_t test_heap(void);
size_t test_heap_current(void);
void test_heap_pause(void);
void test_heap_resume(void);
void test_heap_inc(size_t size);
void test_heap_dec(size_t size);
#define TEST_HEAP() test_heap()
#define TEST_HEAP_CURRENT() test_heap_current()
#define TEST_HEAP_PAUSE() test_heap_pause()
#define TEST_HEAP_RESUME() test_heap_resume()
#define TEST_HEAP_INC(size) test_heap_inc(size)
#define TEST_HEAP_DEC(size) test_heap_dec(size)
#endif
// declare implicit defines as global intmax_ts
#define TEST_DEFINE(k, v) \
extern intmax_t k;
#include "test_defines.h"
#include TEST_STRINGIFY(TEST_DEFINES)
#undef TEST_DEFINE