test_runner.h 3.2 KB

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