test_shrink.toml 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. # simple shrink
  2. [cases.test_shrink_simple]
  3. defines.BLOCK_COUNT = [10, 15, 20]
  4. defines.AFTER_BLOCK_COUNT = [5, 10, 15, 19]
  5. if = "AFTER_BLOCK_COUNT <= BLOCK_COUNT"
  6. code = '''
  7. lfs_t lfs;
  8. lfs_format(&lfs, cfg) => 0;
  9. lfs_mount(&lfs, cfg) => 0;
  10. lfs_fs_grow(&lfs, AFTER_BLOCK_COUNT) => 0;
  11. lfs_unmount(&lfs);
  12. if (BLOCK_COUNT != AFTER_BLOCK_COUNT) {
  13. lfs_mount(&lfs, cfg) => LFS_ERR_INVAL;
  14. }
  15. lfs_t lfs2 = lfs;
  16. struct lfs_config cfg2 = *cfg;
  17. cfg2.block_count = AFTER_BLOCK_COUNT;
  18. lfs2.cfg = &cfg2;
  19. lfs_mount(&lfs2, &cfg2) => 0;
  20. lfs_unmount(&lfs2) => 0;
  21. '''
  22. # shrinking full
  23. [cases.test_shrink_full]
  24. defines.BLOCK_COUNT = [10, 15, 20]
  25. defines.AFTER_BLOCK_COUNT = [5, 7, 10, 12, 15, 17, 20]
  26. defines.FILES_COUNT = [7, 8, 9, 10]
  27. if = "AFTER_BLOCK_COUNT <= BLOCK_COUNT && FILES_COUNT + 2 < BLOCK_COUNT"
  28. code = '''
  29. lfs_t lfs;
  30. lfs_format(&lfs, cfg) => 0;
  31. // create FILES_COUNT files of BLOCK_SIZE - 50 bytes (to avoid inlining)
  32. lfs_mount(&lfs, cfg) => 0;
  33. for (int i = 0; i < FILES_COUNT + 1; i++) {
  34. lfs_file_t file;
  35. char path[1024];
  36. sprintf(path, "file_%03d", i);
  37. lfs_file_open(&lfs, &file, path,
  38. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  39. char wbuffer[BLOCK_SIZE];
  40. memset(wbuffer, 'b', BLOCK_SIZE);
  41. // Ensure one block is taken per file, but that files are not inlined.
  42. lfs_size_t size = BLOCK_SIZE - 0x40;
  43. sprintf(wbuffer, "Hi %03d", i);
  44. lfs_file_write(&lfs, &file, wbuffer, size) => size;
  45. lfs_file_close(&lfs, &file) => 0;
  46. }
  47. int err = lfs_fs_grow(&lfs, AFTER_BLOCK_COUNT);
  48. if (err == 0) {
  49. for (int i = 0; i < FILES_COUNT + 1; i++) {
  50. lfs_file_t file;
  51. char path[1024];
  52. sprintf(path, "file_%03d", i);
  53. lfs_file_open(&lfs, &file, path,
  54. LFS_O_RDONLY ) => 0;
  55. lfs_size_t size = BLOCK_SIZE - 0x40;
  56. char wbuffer[size];
  57. char wbuffer_ref[size];
  58. // Ensure one block is taken per file, but that files are not inlined.
  59. memset(wbuffer_ref, 'b', size);
  60. sprintf(wbuffer_ref, "Hi %03d", i);
  61. lfs_file_read(&lfs, &file, wbuffer, BLOCK_SIZE) => size;
  62. lfs_file_close(&lfs, &file) => 0;
  63. for (lfs_size_t j = 0; j < size; j++) {
  64. wbuffer[j] => wbuffer_ref[j];
  65. }
  66. }
  67. } else {
  68. assert(err == LFS_ERR_NOTEMPTY);
  69. }
  70. lfs_unmount(&lfs) => 0;
  71. if (err == 0 ) {
  72. if ( AFTER_BLOCK_COUNT != BLOCK_COUNT ) {
  73. lfs_mount(&lfs, cfg) => LFS_ERR_INVAL;
  74. }
  75. lfs_t lfs2 = lfs;
  76. struct lfs_config cfg2 = *cfg;
  77. cfg2.block_count = AFTER_BLOCK_COUNT;
  78. lfs2.cfg = &cfg2;
  79. lfs_mount(&lfs2, &cfg2) => 0;
  80. for (int i = 0; i < FILES_COUNT + 1; i++) {
  81. lfs_file_t file;
  82. char path[1024];
  83. sprintf(path, "file_%03d", i);
  84. lfs_file_open(&lfs2, &file, path,
  85. LFS_O_RDONLY ) => 0;
  86. lfs_size_t size = BLOCK_SIZE - 0x40;
  87. char wbuffer[size];
  88. char wbuffer_ref[size];
  89. // Ensure one block is taken per file, but that files are not inlined.
  90. memset(wbuffer_ref, 'b', size);
  91. sprintf(wbuffer_ref, "Hi %03d", i);
  92. lfs_file_read(&lfs2, &file, wbuffer, BLOCK_SIZE) => size;
  93. lfs_file_close(&lfs2, &file) => 0;
  94. for (lfs_size_t j = 0; j < size; j++) {
  95. wbuffer[j] => wbuffer_ref[j];
  96. }
  97. }
  98. lfs_unmount(&lfs2);
  99. }
  100. '''