test_runner.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 *id;
  30. const char *name;
  31. const char *path;
  32. test_flags_t flags;
  33. size_t permutations;
  34. const test_define_t *defines;
  35. bool (*filter)(void);
  36. void (*run)(struct lfs_config *cfg);
  37. };
  38. struct test_suite {
  39. const char *id;
  40. const char *name;
  41. const char *path;
  42. test_flags_t flags;
  43. const char *const *define_names;
  44. size_t define_count;
  45. const struct test_case *cases;
  46. size_t case_count;
  47. };
  48. // access generated test defines
  49. //intmax_t test_predefine(size_t define);
  50. intmax_t test_define(size_t define);
  51. // a few preconfigured defines that control how tests run
  52. #define READ_SIZE_i 0
  53. #define PROG_SIZE_i 1
  54. #define BLOCK_SIZE_i 2
  55. #define BLOCK_COUNT_i 3
  56. #define CACHE_SIZE_i 4
  57. #define LOOKAHEAD_SIZE_i 5
  58. #define BLOCK_CYCLES_i 6
  59. #define ERASE_VALUE_i 7
  60. #define ERASE_CYCLES_i 8
  61. #define BADBLOCK_BEHAVIOR_i 9
  62. #define POWERLOSS_BEHAVIOR_i 10
  63. #define READ_SIZE test_define(READ_SIZE_i)
  64. #define PROG_SIZE test_define(PROG_SIZE_i)
  65. #define BLOCK_SIZE test_define(BLOCK_SIZE_i)
  66. #define BLOCK_COUNT test_define(BLOCK_COUNT_i)
  67. #define CACHE_SIZE test_define(CACHE_SIZE_i)
  68. #define LOOKAHEAD_SIZE test_define(LOOKAHEAD_SIZE_i)
  69. #define BLOCK_CYCLES test_define(BLOCK_CYCLES_i)
  70. #define ERASE_VALUE test_define(ERASE_VALUE_i)
  71. #define ERASE_CYCLES test_define(ERASE_CYCLES_i)
  72. #define BADBLOCK_BEHAVIOR test_define(BADBLOCK_BEHAVIOR_i)
  73. #define POWERLOSS_BEHAVIOR test_define(POWERLOSS_BEHAVIOR_i)
  74. #define TEST_IMPLICIT_DEFINES \
  75. TEST_DEFINE(READ_SIZE, PROG_SIZE) \
  76. TEST_DEFINE(PROG_SIZE, BLOCK_SIZE) \
  77. TEST_DEFINE(BLOCK_SIZE, 0) \
  78. TEST_DEFINE(BLOCK_COUNT, (1024*1024)/BLOCK_SIZE) \
  79. TEST_DEFINE(CACHE_SIZE, lfs_max(64,lfs_max(READ_SIZE,PROG_SIZE))) \
  80. TEST_DEFINE(LOOKAHEAD_SIZE, 16) \
  81. TEST_DEFINE(BLOCK_CYCLES, -1) \
  82. TEST_DEFINE(ERASE_VALUE, 0xff) \
  83. TEST_DEFINE(ERASE_CYCLES, 0) \
  84. TEST_DEFINE(BADBLOCK_BEHAVIOR, LFS_TESTBD_BADBLOCK_PROGERROR) \
  85. TEST_DEFINE(POWERLOSS_BEHAVIOR, LFS_TESTBD_POWERLOSS_NOOP)
  86. #define TEST_GEOMETRY_DEFINE_COUNT 4
  87. #define TEST_IMPLICIT_DEFINE_COUNT 11
  88. #endif