test_runner.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #ifndef TEST_RUNNER_H
  2. #define TEST_RUNNER_H
  3. // override LFS_TRACE
  4. void test_trace(const char *fmt, ...);
  5. #define LFS_TRACE_(fmt, ...) \
  6. test_trace("%s:%d:trace: " fmt "%s\n", \
  7. __FILE__, \
  8. __LINE__, \
  9. __VA_ARGS__)
  10. #define LFS_TRACE(...) LFS_TRACE_(__VA_ARGS__, "")
  11. #define LFS_TESTBD_TRACE(...) LFS_TRACE_(__VA_ARGS__, "")
  12. // note these are indirectly included in any generated files
  13. #include "bd/lfs_testbd.h"
  14. #include <stdio.h>
  15. // give source a chance to define feature macros
  16. #undef _FEATURES_H
  17. #undef _STDIO_H
  18. // generated test configurations
  19. struct lfs_config;
  20. enum test_flags {
  21. TEST_REENTRANT = 0x1,
  22. };
  23. typedef uint8_t test_flags_t;
  24. typedef struct test_define {
  25. intmax_t (*cb)(void *data);
  26. void *data;
  27. } test_define_t;
  28. struct test_case {
  29. const char *name;
  30. const char *path;
  31. test_flags_t flags;
  32. size_t permutations;
  33. const test_define_t *defines;
  34. bool (*filter)(void);
  35. void (*run)(struct lfs_config *cfg);
  36. };
  37. struct test_suite {
  38. const char *name;
  39. const char *path;
  40. test_flags_t flags;
  41. const char *const *define_names;
  42. size_t define_count;
  43. const struct test_case *cases;
  44. size_t case_count;
  45. };
  46. // access generated test defines
  47. //intmax_t test_predefine(size_t define);
  48. intmax_t test_define(size_t define);
  49. // a few preconfigured defines that control how tests run
  50. #define READ_SIZE_i 0
  51. #define PROG_SIZE_i 1
  52. #define BLOCK_SIZE_i 2
  53. #define BLOCK_COUNT_i 3
  54. #define CACHE_SIZE_i 4
  55. #define LOOKAHEAD_SIZE_i 5
  56. #define BLOCK_CYCLES_i 6
  57. #define ERASE_VALUE_i 7
  58. #define ERASE_CYCLES_i 8
  59. #define BADBLOCK_BEHAVIOR_i 9
  60. #define POWERLOSS_BEHAVIOR_i 10
  61. #define READ_SIZE test_define(READ_SIZE_i)
  62. #define PROG_SIZE test_define(PROG_SIZE_i)
  63. #define BLOCK_SIZE test_define(BLOCK_SIZE_i)
  64. #define BLOCK_COUNT test_define(BLOCK_COUNT_i)
  65. #define CACHE_SIZE test_define(CACHE_SIZE_i)
  66. #define LOOKAHEAD_SIZE test_define(LOOKAHEAD_SIZE_i)
  67. #define BLOCK_CYCLES test_define(BLOCK_CYCLES_i)
  68. #define ERASE_VALUE test_define(ERASE_VALUE_i)
  69. #define ERASE_CYCLES test_define(ERASE_CYCLES_i)
  70. #define BADBLOCK_BEHAVIOR test_define(BADBLOCK_BEHAVIOR_i)
  71. #define POWERLOSS_BEHAVIOR test_define(POWERLOSS_BEHAVIOR_i)
  72. #define TEST_IMPLICIT_DEFINES \
  73. TEST_DEFINE(READ_SIZE, PROG_SIZE) \
  74. TEST_DEFINE(PROG_SIZE, BLOCK_SIZE) \
  75. TEST_DEFINE(BLOCK_SIZE, 0) \
  76. TEST_DEFINE(BLOCK_COUNT, (1024*1024)/BLOCK_SIZE) \
  77. TEST_DEFINE(CACHE_SIZE, lfs_max(64,lfs_max(READ_SIZE,PROG_SIZE))) \
  78. TEST_DEFINE(LOOKAHEAD_SIZE, 16) \
  79. TEST_DEFINE(BLOCK_CYCLES, -1) \
  80. TEST_DEFINE(ERASE_VALUE, 0xff) \
  81. TEST_DEFINE(ERASE_CYCLES, 0) \
  82. TEST_DEFINE(BADBLOCK_BEHAVIOR, LFS_TESTBD_BADBLOCK_PROGERROR) \
  83. TEST_DEFINE(POWERLOSS_BEHAVIOR, LFS_TESTBD_POWERLOSS_NOOP)
  84. #define TEST_GEOMETRY_DEFINE_COUNT 4
  85. #define TEST_IMPLICIT_DEFINE_COUNT 11
  86. #endif