template.fmt 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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_log(const char *s, uintmax_t v) {{
  9. printf("%s: %jd\n", s, v);
  10. }}
  11. static void test_assert(const char *file, unsigned line,
  12. const char *s, uintmax_t v, uintmax_t e) {{
  13. static const char *last[6] = {{0, 0}};
  14. if (v != e || !(last[0] == s || last[1] == s ||
  15. last[2] == s || last[3] == s ||
  16. last[4] == s || last[5] == s)) {{
  17. test_log(s, v);
  18. last[0] = last[1];
  19. last[1] = last[2];
  20. last[2] = last[3];
  21. last[3] = last[4];
  22. last[4] = last[5];
  23. last[5] = s;
  24. }}
  25. if (v != e) {{
  26. fprintf(stderr, "\033[31m%s:%u: assert %s failed with %jd, "
  27. "expected %jd\033[0m\n", file, line, s, v, e);
  28. exit(-2);
  29. }}
  30. }}
  31. #define test_assert(s, v, e) test_assert(__FILE__, __LINE__, s, v, e)
  32. // utility functions for traversals
  33. static int __attribute__((used)) test_count(void *p, lfs_block_t b) {{
  34. (void)b;
  35. unsigned *u = (unsigned*)p;
  36. *u += 1;
  37. return 0;
  38. }}
  39. // lfs declarations
  40. lfs_t lfs;
  41. lfs_emubd_t bd;
  42. lfs_file_t file[4];
  43. lfs_dir_t dir[4];
  44. struct lfs_info info;
  45. uint8_t buffer[1024];
  46. uint8_t wbuffer[1024];
  47. uint8_t rbuffer[1024];
  48. lfs_size_t size;
  49. lfs_size_t wsize;
  50. lfs_size_t rsize;
  51. uintmax_t test;
  52. #ifndef LFS_READ_SIZE
  53. #define LFS_READ_SIZE 16
  54. #endif
  55. #ifndef LFS_PROG_SIZE
  56. #define LFS_PROG_SIZE LFS_READ_SIZE
  57. #endif
  58. #ifndef LFS_CACHE_SIZE
  59. #define LFS_CACHE_SIZE 64
  60. #endif
  61. #ifndef LFS_BLOCK_SIZE
  62. #define LFS_BLOCK_SIZE 512
  63. #endif
  64. #ifndef LFS_BLOCK_COUNT
  65. #define LFS_BLOCK_COUNT 1024
  66. #endif
  67. #ifndef LFS_LOOKAHEAD
  68. #define LFS_LOOKAHEAD 128
  69. #endif
  70. const struct lfs_config cfg = {{
  71. .context = &bd,
  72. .read = &lfs_emubd_read,
  73. .prog = &lfs_emubd_prog,
  74. .erase = &lfs_emubd_erase,
  75. .sync = &lfs_emubd_sync,
  76. .name_size = 255,
  77. .read_size = LFS_READ_SIZE,
  78. .prog_size = LFS_PROG_SIZE,
  79. .cache_size = LFS_CACHE_SIZE,
  80. .block_size = LFS_BLOCK_SIZE,
  81. .block_count = LFS_BLOCK_COUNT,
  82. .lookahead = LFS_LOOKAHEAD,
  83. }};
  84. // Entry point
  85. int main(void) {{
  86. lfs_emubd_create(&cfg, "blocks");
  87. {tests}
  88. lfs_emubd_destroy(&cfg);
  89. }}