test_shrink.toml 3.6 KB

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