1b70c1f199
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.
112 lines
2.6 KiB
C
112 lines
2.6 KiB
C
/*
|
|
* Runner for littlefs benchmarks
|
|
*
|
|
* Copyright (c) 2022, The littlefs authors.
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
*/
|
|
#ifndef BENCH_RUNNER_H
|
|
#define BENCH_RUNNER_H
|
|
|
|
|
|
// override LFS3_TRACE
|
|
void bench_trace(const char *fmt, ...);
|
|
|
|
#define LFS3_TRACE_(fmt, ...) \
|
|
bench_trace("%s:%d:trace: " fmt "%s\n", \
|
|
__FILE__, \
|
|
__LINE__, \
|
|
__VA_ARGS__)
|
|
#define LFS3_TRACE(...) LFS3_TRACE_(__VA_ARGS__, "")
|
|
#define LFS3_EMUBD_TRACE(...) LFS3_TRACE_(__VA_ARGS__, "")
|
|
|
|
// BENCH_START/BENCH_STOP macros measure readed/proged/erased bytes
|
|
// through emubd
|
|
void bench_start(const char *m, uintmax_t n);
|
|
void bench_stop(const char *m);
|
|
|
|
#define BENCH_START(m, n) bench_start(m, n)
|
|
#define BENCH_STOP(m) bench_stop(m)
|
|
|
|
// BENCH_RESULT/BENCH_FRESULT allow for explicit non-io measurements
|
|
void bench_result(const char *m, uintmax_t n, uintmax_t result);
|
|
void bench_fresult(const char *m, uintmax_t n, double result);
|
|
|
|
#define BENCH_RESULT(m, n, result) bench_result(m, n, result)
|
|
#define BENCH_FRESULT(m, n, result) bench_fresult(m, n, result)
|
|
|
|
|
|
// note these are indirectly included in any generated files
|
|
#include "bd/lfs3_emubd.h"
|
|
#include <stdio.h>
|
|
|
|
// give source a chance to define feature macros
|
|
#undef _FEATURES_H
|
|
#undef _STDIO_H
|
|
|
|
|
|
// generated bench configurations
|
|
struct lfs3_cfg;
|
|
|
|
enum bench_flags {
|
|
BENCH_INTERNAL = 0x1,
|
|
};
|
|
typedef uint8_t bench_flags_t;
|
|
|
|
typedef struct bench_define {
|
|
const char *name;
|
|
intmax_t *define;
|
|
intmax_t (*cb)(void *data, size_t i);
|
|
void *data;
|
|
size_t permutations;
|
|
} bench_define_t;
|
|
|
|
struct bench_case {
|
|
const char *name;
|
|
const char *path;
|
|
bench_flags_t flags;
|
|
|
|
const bench_define_t *defines;
|
|
size_t permutations;
|
|
|
|
bool (*if_)(void);
|
|
void (*run)(struct lfs3_cfg *cfg);
|
|
};
|
|
|
|
struct bench_suite {
|
|
const char *name;
|
|
const char *path;
|
|
bench_flags_t flags;
|
|
|
|
const bench_define_t *defines;
|
|
size_t define_count;
|
|
|
|
const struct bench_case *cases;
|
|
size_t case_count;
|
|
};
|
|
|
|
extern const struct bench_suite *const bench_suites[];
|
|
extern const size_t bench_suite_count;
|
|
|
|
|
|
// deterministic prng for pseudo-randomness in benches
|
|
uint32_t bench_prng(uint32_t *state);
|
|
|
|
#define BENCH_PRNG(state) bench_prng(state)
|
|
|
|
// generation of specific permutations of an array for exhaustive benching
|
|
size_t bench_factorial(size_t x);
|
|
void bench_permutation(size_t i, uint32_t *buffer, size_t size);
|
|
|
|
#define BENCH_FACTORIAL(x) bench_factorial(x)
|
|
#define BENCH_PERMUTATION(i, buffer, size) bench_permutation(i, buffer, size)
|
|
|
|
|
|
// declare implicit defines as global intmax_ts
|
|
#define BENCH_DEFINE(k, v) \
|
|
extern intmax_t k;
|
|
#include "bench_defines.h"
|
|
#undef BENCH_DEFINE
|
|
|
|
|
|
#endif
|