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