template.fmt 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /// AUTOGENERATED TEST ///
  2. #include "lfs.h"
  3. #include "emubd/lfs_emubd.h"
  4. #include <stdio.h>
  5. #include <string.h>
  6. #include <stdlib.h>
  7. // test stuff
  8. static void test_assert(const char *file, unsigned line,
  9. const char *s, uintmax_t v, uintmax_t e) {{
  10. if (v != e) {{
  11. fprintf(stderr, "\033[97m%s:%u: \033[91m"
  12. "assert failed with %jd, expected %jd\033[0m\n"
  13. " %s\n\n", file, line, v, e, s);
  14. exit(-2);
  15. }}
  16. }}
  17. #define test_assert(v, e) \
  18. test_assert(__FILE__, __LINE__, #v " => " #e, v, e)
  19. // implicit variable for asserts
  20. uintmax_t test;
  21. // utility functions for traversals
  22. static int __attribute__((used)) test_count(void *p, lfs_block_t b) {{
  23. (void)b;
  24. unsigned *u = (unsigned*)p;
  25. *u += 1;
  26. return 0;
  27. }}
  28. // lfs declarations
  29. lfs_t lfs;
  30. lfs_emubd_t bd;
  31. // other declarations for convenience
  32. lfs_file_t file;
  33. lfs_dir_t dir;
  34. struct lfs_info info;
  35. uint8_t buffer[1024];
  36. char path[1024];
  37. // test configuration options
  38. #ifndef LFS_READ_SIZE
  39. #define LFS_READ_SIZE 16
  40. #endif
  41. #ifndef LFS_PROG_SIZE
  42. #define LFS_PROG_SIZE LFS_READ_SIZE
  43. #endif
  44. #ifndef LFS_BLOCK_SIZE
  45. #define LFS_BLOCK_SIZE 512
  46. #endif
  47. #ifndef LFS_BLOCK_COUNT
  48. #define LFS_BLOCK_COUNT 1024
  49. #endif
  50. #ifndef LFS_BLOCK_CYCLES
  51. #define LFS_BLOCK_CYCLES 1024
  52. #endif
  53. #ifndef LFS_CACHE_SIZE
  54. #define LFS_CACHE_SIZE 64
  55. #endif
  56. #ifndef LFS_LOOKAHEAD_SIZE
  57. #define LFS_LOOKAHEAD_SIZE 16
  58. #endif
  59. const struct lfs_config cfg = {{
  60. .context = &bd,
  61. .read = &lfs_emubd_read,
  62. .prog = &lfs_emubd_prog,
  63. .erase = &lfs_emubd_erase,
  64. .sync = &lfs_emubd_sync,
  65. .read_size = LFS_READ_SIZE,
  66. .prog_size = LFS_PROG_SIZE,
  67. .block_size = LFS_BLOCK_SIZE,
  68. .block_count = LFS_BLOCK_COUNT,
  69. .block_cycles = LFS_BLOCK_CYCLES,
  70. .cache_size = LFS_CACHE_SIZE,
  71. .lookahead_size = LFS_LOOKAHEAD_SIZE,
  72. }};
  73. // Entry point
  74. int main(void) {{
  75. lfs_emubd_create(&cfg, "blocks");
  76. {tests}
  77. lfs_emubd_destroy(&cfg);
  78. }}