test_runner.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. enum test_flags {
  20. TEST_REENTRANT = 0x1,
  21. };
  22. typedef uint8_t test_flags_t;
  23. struct lfs_config;
  24. struct test_case {
  25. const char *id;
  26. const char *name;
  27. const char *path;
  28. test_flags_t flags;
  29. size_t permutations;
  30. intmax_t (*const *const *defines)(void);
  31. bool (*filter)(void);
  32. void (*run)(struct lfs_config *cfg);
  33. };
  34. struct test_suite {
  35. const char *id;
  36. const char *name;
  37. const char *path;
  38. test_flags_t flags;
  39. const char *const *define_names;
  40. size_t define_count;
  41. const struct test_case *cases;
  42. size_t case_count;
  43. };
  44. // access generated test defines
  45. intmax_t test_predefine(size_t define);
  46. intmax_t test_define(size_t define);
  47. // a few preconfigured defines that control how tests run
  48. #define READ_SIZE test_predefine(0)
  49. #define PROG_SIZE test_predefine(1)
  50. #define BLOCK_SIZE test_predefine(2)
  51. #define BLOCK_COUNT test_predefine(3)
  52. #define CACHE_SIZE test_predefine(4)
  53. #define LOOKAHEAD_SIZE test_predefine(5)
  54. #define BLOCK_CYCLES test_predefine(6)
  55. #define ERASE_VALUE test_predefine(7)
  56. #define ERASE_CYCLES test_predefine(8)
  57. #define BADBLOCK_BEHAVIOR test_predefine(9)
  58. #define POWERLOSS_BEHAVIOR test_predefine(10)
  59. #define TEST_PREDEFINE_NAMES { \
  60. "READ_SIZE", \
  61. "PROG_SIZE", \
  62. "BLOCK_SIZE", \
  63. "BLOCK_COUNT", \
  64. "CACHE_SIZE", \
  65. "LOOKAHEAD_SIZE", \
  66. "BLOCK_CYCLES", \
  67. "ERASE_VALUE", \
  68. "ERASE_CYCLES", \
  69. "BADBLOCK_BEHAVIOR", \
  70. "POWERLOSS_BEHAVIOR", \
  71. }
  72. #define TEST_PREDEFINE_COUNT 11
  73. // default predefines
  74. #define TEST_DEFAULTS { \
  75. /* LOOKAHEAD_SIZE */ 16, \
  76. /* BLOCK_CYCLES */ -1, \
  77. /* ERASE_VALUE */ 0xff, \
  78. /* ERASE_CYCLES */ 0, \
  79. /* BADBLOCK_BEHAVIOR */ LFS_TESTBD_BADBLOCK_PROGERROR, \
  80. /* POWERLOSS_BEHAVIOR */ LFS_TESTBD_POWERLOSS_NOOP, \
  81. }
  82. #define TEST_DEFAULT_DEFINE_COUNT 5
  83. // test geometries
  84. #define TEST_GEOMETRIES { \
  85. /*geometry, read, write, erase, count, cache */ \
  86. {"test", { 16, 16, 512, (1024*1024)/512, 64}}, \
  87. {"eeprom", { 1, 1, 512, (1024*1024)/512, 64}}, \
  88. {"emmc", { 512, 512, 512, (1024*1024)/512, 512}}, \
  89. {"nor", { 1, 1, 4096, (1024*1024)/4096, 64}}, \
  90. {"nand", {4096, 4096, 32*1024, (1024*1024)/(32*1024), 4096}}, \
  91. }
  92. #define TEST_GEOMETRY_COUNT 5
  93. #define TEST_GEOMETRY_DEFINE_COUNT 5
  94. #endif