template.fmt 1.8 KB

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