template.fmt 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. const struct lfs_config cfg = {{
  58. .context = &bd,
  59. .read = &lfs_emubd_read,
  60. .prog = &lfs_emubd_prog,
  61. .erase = &lfs_emubd_erase,
  62. .sync = &lfs_emubd_sync,
  63. .read_size = LFS_READ_SIZE,
  64. .prog_size = LFS_PROG_SIZE,
  65. .block_size = LFS_BLOCK_SIZE,
  66. .block_count = LFS_BLOCK_COUNT,
  67. }};
  68. // Entry point
  69. int main() {{
  70. lfs_emubd_create(&cfg, "blocks");
  71. {tests}
  72. lfs_emubd_destroy(&cfg);
  73. }}