119ea8026Sopenharmony_ci/*
219ea8026Sopenharmony_ci * Runner for littlefs tests
319ea8026Sopenharmony_ci *
419ea8026Sopenharmony_ci * Copyright (c) 2022, The littlefs authors.
519ea8026Sopenharmony_ci * SPDX-License-Identifier: BSD-3-Clause
619ea8026Sopenharmony_ci */
719ea8026Sopenharmony_ci#ifndef TEST_RUNNER_H
819ea8026Sopenharmony_ci#define TEST_RUNNER_H
919ea8026Sopenharmony_ci
1019ea8026Sopenharmony_ci
1119ea8026Sopenharmony_ci// override LFS_TRACE
1219ea8026Sopenharmony_civoid test_trace(const char *fmt, ...);
1319ea8026Sopenharmony_ci
1419ea8026Sopenharmony_ci#define LFS_TRACE_(fmt, ...) \
1519ea8026Sopenharmony_ci    test_trace("%s:%d:trace: " fmt "%s\n", \
1619ea8026Sopenharmony_ci        __FILE__, \
1719ea8026Sopenharmony_ci        __LINE__, \
1819ea8026Sopenharmony_ci        __VA_ARGS__)
1919ea8026Sopenharmony_ci#define LFS_TRACE(...) LFS_TRACE_(__VA_ARGS__, "")
2019ea8026Sopenharmony_ci#define LFS_EMUBD_TRACE(...) LFS_TRACE_(__VA_ARGS__, "")
2119ea8026Sopenharmony_ci
2219ea8026Sopenharmony_ci
2319ea8026Sopenharmony_ci// note these are indirectly included in any generated files
2419ea8026Sopenharmony_ci#include "bd/lfs_emubd.h"
2519ea8026Sopenharmony_ci#include <stdio.h>
2619ea8026Sopenharmony_ci
2719ea8026Sopenharmony_ci// give source a chance to define feature macros
2819ea8026Sopenharmony_ci#undef _FEATURES_H
2919ea8026Sopenharmony_ci#undef _STDIO_H
3019ea8026Sopenharmony_ci
3119ea8026Sopenharmony_ci
3219ea8026Sopenharmony_ci// generated test configurations
3319ea8026Sopenharmony_cistruct lfs_config;
3419ea8026Sopenharmony_ci
3519ea8026Sopenharmony_cienum test_flags {
3619ea8026Sopenharmony_ci    TEST_REENTRANT = 0x1,
3719ea8026Sopenharmony_ci};
3819ea8026Sopenharmony_citypedef uint8_t test_flags_t;
3919ea8026Sopenharmony_ci
4019ea8026Sopenharmony_citypedef struct test_define {
4119ea8026Sopenharmony_ci    intmax_t (*cb)(void *data);
4219ea8026Sopenharmony_ci    void *data;
4319ea8026Sopenharmony_ci} test_define_t;
4419ea8026Sopenharmony_ci
4519ea8026Sopenharmony_cistruct test_case {
4619ea8026Sopenharmony_ci    const char *name;
4719ea8026Sopenharmony_ci    const char *path;
4819ea8026Sopenharmony_ci    test_flags_t flags;
4919ea8026Sopenharmony_ci    size_t permutations;
5019ea8026Sopenharmony_ci
5119ea8026Sopenharmony_ci    const test_define_t *defines;
5219ea8026Sopenharmony_ci
5319ea8026Sopenharmony_ci    bool (*filter)(void);
5419ea8026Sopenharmony_ci    void (*run)(struct lfs_config *cfg);
5519ea8026Sopenharmony_ci};
5619ea8026Sopenharmony_ci
5719ea8026Sopenharmony_cistruct test_suite {
5819ea8026Sopenharmony_ci    const char *name;
5919ea8026Sopenharmony_ci    const char *path;
6019ea8026Sopenharmony_ci    test_flags_t flags;
6119ea8026Sopenharmony_ci
6219ea8026Sopenharmony_ci    const char *const *define_names;
6319ea8026Sopenharmony_ci    size_t define_count;
6419ea8026Sopenharmony_ci
6519ea8026Sopenharmony_ci    const struct test_case *cases;
6619ea8026Sopenharmony_ci    size_t case_count;
6719ea8026Sopenharmony_ci};
6819ea8026Sopenharmony_ci
6919ea8026Sopenharmony_ci
7019ea8026Sopenharmony_ci// deterministic prng for pseudo-randomness in testes
7119ea8026Sopenharmony_ciuint32_t test_prng(uint32_t *state);
7219ea8026Sopenharmony_ci
7319ea8026Sopenharmony_ci#define TEST_PRNG(state) test_prng(state)
7419ea8026Sopenharmony_ci
7519ea8026Sopenharmony_ci
7619ea8026Sopenharmony_ci// access generated test defines
7719ea8026Sopenharmony_ciintmax_t test_define(size_t define);
7819ea8026Sopenharmony_ci
7919ea8026Sopenharmony_ci#define TEST_DEFINE(i) test_define(i)
8019ea8026Sopenharmony_ci
8119ea8026Sopenharmony_ci// a few preconfigured defines that control how tests run
8219ea8026Sopenharmony_ci
8319ea8026Sopenharmony_ci#define READ_SIZE_i          0
8419ea8026Sopenharmony_ci#define PROG_SIZE_i          1
8519ea8026Sopenharmony_ci#define ERASE_SIZE_i         2
8619ea8026Sopenharmony_ci#define ERASE_COUNT_i        3
8719ea8026Sopenharmony_ci#define BLOCK_SIZE_i         4
8819ea8026Sopenharmony_ci#define BLOCK_COUNT_i        5
8919ea8026Sopenharmony_ci#define CACHE_SIZE_i         6
9019ea8026Sopenharmony_ci#define LOOKAHEAD_SIZE_i     7
9119ea8026Sopenharmony_ci#define BLOCK_CYCLES_i       8
9219ea8026Sopenharmony_ci#define ERASE_VALUE_i        9
9319ea8026Sopenharmony_ci#define ERASE_CYCLES_i       10
9419ea8026Sopenharmony_ci#define BADBLOCK_BEHAVIOR_i  11
9519ea8026Sopenharmony_ci#define POWERLOSS_BEHAVIOR_i 12
9619ea8026Sopenharmony_ci#define DISK_VERSION_i       13
9719ea8026Sopenharmony_ci
9819ea8026Sopenharmony_ci#define READ_SIZE           TEST_DEFINE(READ_SIZE_i)
9919ea8026Sopenharmony_ci#define PROG_SIZE           TEST_DEFINE(PROG_SIZE_i)
10019ea8026Sopenharmony_ci#define ERASE_SIZE          TEST_DEFINE(ERASE_SIZE_i)
10119ea8026Sopenharmony_ci#define ERASE_COUNT         TEST_DEFINE(ERASE_COUNT_i)
10219ea8026Sopenharmony_ci#define BLOCK_SIZE          TEST_DEFINE(BLOCK_SIZE_i)
10319ea8026Sopenharmony_ci#define BLOCK_COUNT         TEST_DEFINE(BLOCK_COUNT_i)
10419ea8026Sopenharmony_ci#define CACHE_SIZE          TEST_DEFINE(CACHE_SIZE_i)
10519ea8026Sopenharmony_ci#define LOOKAHEAD_SIZE      TEST_DEFINE(LOOKAHEAD_SIZE_i)
10619ea8026Sopenharmony_ci#define BLOCK_CYCLES        TEST_DEFINE(BLOCK_CYCLES_i)
10719ea8026Sopenharmony_ci#define ERASE_VALUE         TEST_DEFINE(ERASE_VALUE_i)
10819ea8026Sopenharmony_ci#define ERASE_CYCLES        TEST_DEFINE(ERASE_CYCLES_i)
10919ea8026Sopenharmony_ci#define BADBLOCK_BEHAVIOR   TEST_DEFINE(BADBLOCK_BEHAVIOR_i)
11019ea8026Sopenharmony_ci#define POWERLOSS_BEHAVIOR  TEST_DEFINE(POWERLOSS_BEHAVIOR_i)
11119ea8026Sopenharmony_ci#define DISK_VERSION        TEST_DEFINE(DISK_VERSION_i)
11219ea8026Sopenharmony_ci
11319ea8026Sopenharmony_ci#define TEST_IMPLICIT_DEFINES \
11419ea8026Sopenharmony_ci    TEST_DEF(READ_SIZE,          PROG_SIZE) \
11519ea8026Sopenharmony_ci    TEST_DEF(PROG_SIZE,          ERASE_SIZE) \
11619ea8026Sopenharmony_ci    TEST_DEF(ERASE_SIZE,         0) \
11719ea8026Sopenharmony_ci    TEST_DEF(ERASE_COUNT,        (1024*1024)/ERASE_SIZE) \
11819ea8026Sopenharmony_ci    TEST_DEF(BLOCK_SIZE,         ERASE_SIZE) \
11919ea8026Sopenharmony_ci    TEST_DEF(BLOCK_COUNT,        ERASE_COUNT/lfs_max(BLOCK_SIZE/ERASE_SIZE,1)) \
12019ea8026Sopenharmony_ci    TEST_DEF(CACHE_SIZE,         lfs_max(64,lfs_max(READ_SIZE,PROG_SIZE))) \
12119ea8026Sopenharmony_ci    TEST_DEF(LOOKAHEAD_SIZE,     16) \
12219ea8026Sopenharmony_ci    TEST_DEF(BLOCK_CYCLES,       -1) \
12319ea8026Sopenharmony_ci    TEST_DEF(ERASE_VALUE,        0xff) \
12419ea8026Sopenharmony_ci    TEST_DEF(ERASE_CYCLES,       0) \
12519ea8026Sopenharmony_ci    TEST_DEF(BADBLOCK_BEHAVIOR,  LFS_EMUBD_BADBLOCK_PROGERROR) \
12619ea8026Sopenharmony_ci    TEST_DEF(POWERLOSS_BEHAVIOR, LFS_EMUBD_POWERLOSS_NOOP) \
12719ea8026Sopenharmony_ci    TEST_DEF(DISK_VERSION,       0)
12819ea8026Sopenharmony_ci
12919ea8026Sopenharmony_ci#define TEST_GEOMETRY_DEFINE_COUNT 4
13019ea8026Sopenharmony_ci#define TEST_IMPLICIT_DEFINE_COUNT 14
13119ea8026Sopenharmony_ci
13219ea8026Sopenharmony_ci
13319ea8026Sopenharmony_ci#endif
134