template.fmt 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. void test_log(const char *s, uintmax_t v) {{
  9. printf("%s: %jd\n", s, v);
  10. }}
  11. 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. printf("\033[31m%s:%u: assert %s failed, expected %jd\033[0m\n",
  27. file, line, s, 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. int test_count(void *p, lfs_block_t b) {{
  34. unsigned *u = (unsigned*)p;
  35. *u += 1;
  36. return 0;
  37. }}
  38. // lfs declarations
  39. lfs_t lfs;
  40. lfs_emubd_t bd;
  41. lfs_file_t file[4];
  42. lfs_dir_t dir[4];
  43. struct lfs_info info;
  44. uint8_t buffer[1024];
  45. uint8_t wbuffer[1024];
  46. uint8_t rbuffer[1024];
  47. lfs_size_t size;
  48. lfs_size_t wsize;
  49. lfs_size_t rsize;
  50. uintmax_t res;
  51. #ifndef LFS_READ_SIZE
  52. #define LFS_READ_SIZE 64
  53. #endif
  54. #ifndef LFS_PROG_SIZE
  55. #define LFS_PROG_SIZE 64
  56. #endif
  57. #ifndef LFS_BLOCK_SIZE
  58. #define LFS_BLOCK_SIZE 512
  59. #endif
  60. #ifndef LFS_BLOCK_COUNT
  61. #define LFS_BLOCK_COUNT 1024
  62. #endif
  63. #ifndef LFS_LOOKAHEAD
  64. #define LFS_LOOKAHEAD 128
  65. #endif
  66. const struct lfs_config cfg = {{
  67. .context = &bd,
  68. .read = &lfs_emubd_read,
  69. .prog = &lfs_emubd_prog,
  70. .erase = &lfs_emubd_erase,
  71. .sync = &lfs_emubd_sync,
  72. .read_size = LFS_READ_SIZE,
  73. .prog_size = LFS_PROG_SIZE,
  74. .block_size = LFS_BLOCK_SIZE,
  75. .block_count = LFS_BLOCK_COUNT,
  76. .lookahead = LFS_LOOKAHEAD,
  77. }};
  78. // Entry point
  79. int main() {{
  80. lfs_emubd_create(&cfg, "blocks");
  81. {tests}
  82. lfs_emubd_destroy(&cfg);
  83. }}