1 /* 2 * Runner for littlefs tests 3 * 4 * Copyright (c) 2022, The littlefs authors. 5 * SPDX-License-Identifier: BSD-3-Clause 6 */ 7 #ifndef TEST_RUNNER_H 8 #define TEST_RUNNER_H 9 10 11 // override LFS_TRACE 12 void test_trace(const char *fmt, ...); 13 14 #define LFS_TRACE_(fmt, ...) \ 15 test_trace("%s:%d:trace: " fmt "%s\n", \ 16 __FILE__, \ 17 __LINE__, \ 18 __VA_ARGS__) 19 #define LFS_TRACE(...) LFS_TRACE_(__VA_ARGS__, "") 20 #define LFS_EMUBD_TRACE(...) LFS_TRACE_(__VA_ARGS__, "") 21 22 23 // note these are indirectly included in any generated files 24 #include "bd/lfs_emubd.h" 25 #include <stdio.h> 26 27 // give source a chance to define feature macros 28 #undef _FEATURES_H 29 #undef _STDIO_H 30 31 32 // generated test configurations 33 struct lfs_config; 34 35 enum test_flags { 36 TEST_REENTRANT = 0x1, 37 }; 38 typedef uint8_t test_flags_t; 39 40 typedef struct test_define { 41 intmax_t (*cb)(void *data); 42 void *data; 43 } test_define_t; 44 45 struct test_case { 46 const char *name; 47 const char *path; 48 test_flags_t flags; 49 size_t permutations; 50 51 const test_define_t *defines; 52 53 bool (*filter)(void); 54 void (*run)(struct lfs_config *cfg); 55 }; 56 57 struct test_suite { 58 const char *name; 59 const char *path; 60 test_flags_t flags; 61 62 const char *const *define_names; 63 size_t define_count; 64 65 const struct test_case *cases; 66 size_t case_count; 67 }; 68 69 70 // deterministic prng for pseudo-randomness in testes 71 uint32_t test_prng(uint32_t *state); 72 73 #define TEST_PRNG(state) test_prng(state) 74 75 76 // access generated test defines 77 intmax_t test_define(size_t define); 78 79 #define TEST_DEFINE(i) test_define(i) 80 81 // a few preconfigured defines that control how tests run 82 83 #define READ_SIZE_i 0 84 #define PROG_SIZE_i 1 85 #define ERASE_SIZE_i 2 86 #define ERASE_COUNT_i 3 87 #define BLOCK_SIZE_i 4 88 #define BLOCK_COUNT_i 5 89 #define CACHE_SIZE_i 6 90 #define LOOKAHEAD_SIZE_i 7 91 #define BLOCK_CYCLES_i 8 92 #define ERASE_VALUE_i 9 93 #define ERASE_CYCLES_i 10 94 #define BADBLOCK_BEHAVIOR_i 11 95 #define POWERLOSS_BEHAVIOR_i 12 96 #define DISK_VERSION_i 13 97 98 #define READ_SIZE TEST_DEFINE(READ_SIZE_i) 99 #define PROG_SIZE TEST_DEFINE(PROG_SIZE_i) 100 #define ERASE_SIZE TEST_DEFINE(ERASE_SIZE_i) 101 #define ERASE_COUNT TEST_DEFINE(ERASE_COUNT_i) 102 #define BLOCK_SIZE TEST_DEFINE(BLOCK_SIZE_i) 103 #define BLOCK_COUNT TEST_DEFINE(BLOCK_COUNT_i) 104 #define CACHE_SIZE TEST_DEFINE(CACHE_SIZE_i) 105 #define LOOKAHEAD_SIZE TEST_DEFINE(LOOKAHEAD_SIZE_i) 106 #define BLOCK_CYCLES TEST_DEFINE(BLOCK_CYCLES_i) 107 #define ERASE_VALUE TEST_DEFINE(ERASE_VALUE_i) 108 #define ERASE_CYCLES TEST_DEFINE(ERASE_CYCLES_i) 109 #define BADBLOCK_BEHAVIOR TEST_DEFINE(BADBLOCK_BEHAVIOR_i) 110 #define POWERLOSS_BEHAVIOR TEST_DEFINE(POWERLOSS_BEHAVIOR_i) 111 #define DISK_VERSION TEST_DEFINE(DISK_VERSION_i) 112 113 #define TEST_IMPLICIT_DEFINES \ 114 TEST_DEF(READ_SIZE, PROG_SIZE) \ 115 TEST_DEF(PROG_SIZE, ERASE_SIZE) \ 116 TEST_DEF(ERASE_SIZE, 0) \ 117 TEST_DEF(ERASE_COUNT, (1024*1024)/ERASE_SIZE) \ 118 TEST_DEF(BLOCK_SIZE, ERASE_SIZE) \ 119 TEST_DEF(BLOCK_COUNT, ERASE_COUNT/lfs_max(BLOCK_SIZE/ERASE_SIZE,1)) \ 120 TEST_DEF(CACHE_SIZE, lfs_max(64,lfs_max(READ_SIZE,PROG_SIZE))) \ 121 TEST_DEF(LOOKAHEAD_SIZE, 16) \ 122 TEST_DEF(BLOCK_CYCLES, -1) \ 123 TEST_DEF(ERASE_VALUE, 0xff) \ 124 TEST_DEF(ERASE_CYCLES, 0) \ 125 TEST_DEF(BADBLOCK_BEHAVIOR, LFS_EMUBD_BADBLOCK_PROGERROR) \ 126 TEST_DEF(POWERLOSS_BEHAVIOR, LFS_EMUBD_POWERLOSS_NOOP) \ 127 TEST_DEF(DISK_VERSION, 0) 128 129 #define TEST_GEOMETRY_DEFINE_COUNT 4 130 #define TEST_IMPLICIT_DEFINE_COUNT 14 131 132 133 #endif 134