test_relocations.toml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. # specific corner cases worth explicitly testing for
  2. [cases.dangling_split_dir]
  3. defines.ITERATIONS = 20
  4. defines.COUNT = 10
  5. defines.BLOCK_CYCLES = [8, 1]
  6. code = '''
  7. lfs_t lfs;
  8. lfs_format(&lfs, cfg) => 0;
  9. // fill up filesystem so only ~16 blocks are left
  10. lfs_mount(&lfs, cfg) => 0;
  11. lfs_file_t file;
  12. lfs_file_open(&lfs, &file, "padding", LFS_O_CREAT | LFS_O_WRONLY) => 0;
  13. uint8_t buffer[512];
  14. memset(buffer, 0, 512);
  15. while (BLOCK_COUNT - lfs_fs_size(&lfs) > 16) {
  16. lfs_file_write(&lfs, &file, buffer, 512) => 512;
  17. }
  18. lfs_file_close(&lfs, &file) => 0;
  19. // make a child dir to use in bounded space
  20. lfs_mkdir(&lfs, "child") => 0;
  21. lfs_unmount(&lfs) => 0;
  22. lfs_mount(&lfs, cfg) => 0;
  23. for (unsigned j = 0; j < ITERATIONS; j++) {
  24. for (unsigned i = 0; i < COUNT; i++) {
  25. char path[1024];
  26. sprintf(path, "child/test%03d_loooooooooooooooooong_name", i);
  27. lfs_file_open(&lfs, &file, path, LFS_O_CREAT | LFS_O_WRONLY) => 0;
  28. lfs_file_close(&lfs, &file) => 0;
  29. }
  30. lfs_dir_t dir;
  31. struct lfs_info info;
  32. lfs_dir_open(&lfs, &dir, "child") => 0;
  33. lfs_dir_read(&lfs, &dir, &info) => 1;
  34. lfs_dir_read(&lfs, &dir, &info) => 1;
  35. for (unsigned i = 0; i < COUNT; i++) {
  36. char path[1024];
  37. sprintf(path, "test%03d_loooooooooooooooooong_name", i);
  38. lfs_dir_read(&lfs, &dir, &info) => 1;
  39. strcmp(info.name, path) => 0;
  40. }
  41. lfs_dir_read(&lfs, &dir, &info) => 0;
  42. lfs_dir_close(&lfs, &dir) => 0;
  43. if (j == (unsigned)ITERATIONS-1) {
  44. break;
  45. }
  46. for (unsigned i = 0; i < COUNT; i++) {
  47. char path[1024];
  48. sprintf(path, "child/test%03d_loooooooooooooooooong_name", i);
  49. lfs_remove(&lfs, path) => 0;
  50. }
  51. }
  52. lfs_unmount(&lfs) => 0;
  53. lfs_mount(&lfs, cfg) => 0;
  54. lfs_dir_t dir;
  55. struct lfs_info info;
  56. lfs_dir_open(&lfs, &dir, "child") => 0;
  57. lfs_dir_read(&lfs, &dir, &info) => 1;
  58. lfs_dir_read(&lfs, &dir, &info) => 1;
  59. for (unsigned i = 0; i < COUNT; i++) {
  60. char path[1024];
  61. sprintf(path, "test%03d_loooooooooooooooooong_name", i);
  62. lfs_dir_read(&lfs, &dir, &info) => 1;
  63. strcmp(info.name, path) => 0;
  64. }
  65. lfs_dir_read(&lfs, &dir, &info) => 0;
  66. lfs_dir_close(&lfs, &dir) => 0;
  67. for (unsigned i = 0; i < COUNT; i++) {
  68. char path[1024];
  69. sprintf(path, "child/test%03d_loooooooooooooooooong_name", i);
  70. lfs_remove(&lfs, path) => 0;
  71. }
  72. lfs_unmount(&lfs) => 0;
  73. '''
  74. [cases.outdated_head]
  75. defines.ITERATIONS = 20
  76. defines.COUNT = 10
  77. defines.BLOCK_CYCLES = [8, 1]
  78. code = '''
  79. lfs_t lfs;
  80. lfs_format(&lfs, cfg) => 0;
  81. // fill up filesystem so only ~16 blocks are left
  82. lfs_mount(&lfs, cfg) => 0;
  83. lfs_file_t file;
  84. lfs_file_open(&lfs, &file, "padding", LFS_O_CREAT | LFS_O_WRONLY) => 0;
  85. uint8_t buffer[512];
  86. memset(buffer, 0, 512);
  87. while (BLOCK_COUNT - lfs_fs_size(&lfs) > 16) {
  88. lfs_file_write(&lfs, &file, buffer, 512) => 512;
  89. }
  90. lfs_file_close(&lfs, &file) => 0;
  91. // make a child dir to use in bounded space
  92. lfs_mkdir(&lfs, "child") => 0;
  93. lfs_unmount(&lfs) => 0;
  94. lfs_mount(&lfs, cfg) => 0;
  95. for (unsigned j = 0; j < ITERATIONS; j++) {
  96. for (unsigned i = 0; i < COUNT; i++) {
  97. char path[1024];
  98. sprintf(path, "child/test%03d_loooooooooooooooooong_name", i);
  99. lfs_file_open(&lfs, &file, path, LFS_O_CREAT | LFS_O_WRONLY) => 0;
  100. lfs_file_close(&lfs, &file) => 0;
  101. }
  102. lfs_dir_t dir;
  103. struct lfs_info info;
  104. lfs_dir_open(&lfs, &dir, "child") => 0;
  105. lfs_dir_read(&lfs, &dir, &info) => 1;
  106. lfs_dir_read(&lfs, &dir, &info) => 1;
  107. for (unsigned i = 0; i < COUNT; i++) {
  108. char path[1024];
  109. sprintf(path, "test%03d_loooooooooooooooooong_name", i);
  110. lfs_dir_read(&lfs, &dir, &info) => 1;
  111. strcmp(info.name, path) => 0;
  112. info.size => 0;
  113. sprintf(path, "child/test%03d_loooooooooooooooooong_name", i);
  114. lfs_file_open(&lfs, &file, path, LFS_O_WRONLY) => 0;
  115. lfs_file_write(&lfs, &file, "hi", 2) => 2;
  116. lfs_file_close(&lfs, &file) => 0;
  117. }
  118. lfs_dir_read(&lfs, &dir, &info) => 0;
  119. lfs_dir_rewind(&lfs, &dir) => 0;
  120. lfs_dir_read(&lfs, &dir, &info) => 1;
  121. lfs_dir_read(&lfs, &dir, &info) => 1;
  122. for (unsigned i = 0; i < COUNT; i++) {
  123. char path[1024];
  124. sprintf(path, "test%03d_loooooooooooooooooong_name", i);
  125. lfs_dir_read(&lfs, &dir, &info) => 1;
  126. strcmp(info.name, path) => 0;
  127. info.size => 2;
  128. sprintf(path, "child/test%03d_loooooooooooooooooong_name", i);
  129. lfs_file_open(&lfs, &file, path, LFS_O_WRONLY) => 0;
  130. lfs_file_write(&lfs, &file, "hi", 2) => 2;
  131. lfs_file_close(&lfs, &file) => 0;
  132. }
  133. lfs_dir_read(&lfs, &dir, &info) => 0;
  134. lfs_dir_rewind(&lfs, &dir) => 0;
  135. lfs_dir_read(&lfs, &dir, &info) => 1;
  136. lfs_dir_read(&lfs, &dir, &info) => 1;
  137. for (unsigned i = 0; i < COUNT; i++) {
  138. char path[1024];
  139. sprintf(path, "test%03d_loooooooooooooooooong_name", i);
  140. lfs_dir_read(&lfs, &dir, &info) => 1;
  141. strcmp(info.name, path) => 0;
  142. info.size => 2;
  143. }
  144. lfs_dir_read(&lfs, &dir, &info) => 0;
  145. lfs_dir_close(&lfs, &dir) => 0;
  146. for (unsigned i = 0; i < COUNT; i++) {
  147. char path[1024];
  148. sprintf(path, "child/test%03d_loooooooooooooooooong_name", i);
  149. lfs_remove(&lfs, path) => 0;
  150. }
  151. }
  152. lfs_unmount(&lfs) => 0;
  153. '''
  154. # reentrant testing for relocations, this is the same as the
  155. # orphan testing, except here we also set block_cycles so that
  156. # almost every tree operation needs a relocation
  157. [cases.reentrant_relocations]
  158. reentrant = true
  159. # TODO fix this case, caused by non-DAG trees
  160. if = '!(DEPTH == 3 && CACHE_SIZE != 64)'
  161. defines = [
  162. {FILES=6, DEPTH=1, CYCLES=20, BLOCK_CYCLES=1},
  163. {FILES=26, DEPTH=1, CYCLES=20, BLOCK_CYCLES=1},
  164. {FILES=3, DEPTH=3, CYCLES=20, BLOCK_CYCLES=1},
  165. ]
  166. code = '''
  167. lfs_t lfs;
  168. int err = lfs_mount(&lfs, cfg);
  169. if (err) {
  170. lfs_format(&lfs, cfg) => 0;
  171. lfs_mount(&lfs, cfg) => 0;
  172. }
  173. srand(1);
  174. const char alpha[] = "abcdefghijklmnopqrstuvwxyz";
  175. for (unsigned i = 0; i < CYCLES; i++) {
  176. // create random path
  177. char full_path[256];
  178. for (unsigned d = 0; d < DEPTH; d++) {
  179. sprintf(&full_path[2*d], "/%c", alpha[rand() % FILES]);
  180. }
  181. // if it does not exist, we create it, else we destroy
  182. struct lfs_info info;
  183. int res = lfs_stat(&lfs, full_path, &info);
  184. if (res == LFS_ERR_NOENT) {
  185. // create each directory in turn, ignore if dir already exists
  186. for (unsigned d = 0; d < DEPTH; d++) {
  187. char path[1024];
  188. strcpy(path, full_path);
  189. path[2*d+2] = '\0';
  190. err = lfs_mkdir(&lfs, path);
  191. assert(!err || err == LFS_ERR_EXIST);
  192. }
  193. for (unsigned d = 0; d < DEPTH; d++) {
  194. char path[1024];
  195. strcpy(path, full_path);
  196. path[2*d+2] = '\0';
  197. lfs_stat(&lfs, path, &info) => 0;
  198. assert(strcmp(info.name, &path[2*d+1]) == 0);
  199. assert(info.type == LFS_TYPE_DIR);
  200. }
  201. } else {
  202. // is valid dir?
  203. assert(strcmp(info.name, &full_path[2*(DEPTH-1)+1]) == 0);
  204. assert(info.type == LFS_TYPE_DIR);
  205. // try to delete path in reverse order, ignore if dir is not empty
  206. for (unsigned d = DEPTH-1; d+1 > 0; d--) {
  207. char path[1024];
  208. strcpy(path, full_path);
  209. path[2*d+2] = '\0';
  210. err = lfs_remove(&lfs, path);
  211. assert(!err || err == LFS_ERR_NOTEMPTY);
  212. }
  213. lfs_stat(&lfs, full_path, &info) => LFS_ERR_NOENT;
  214. }
  215. }
  216. lfs_unmount(&lfs) => 0;
  217. '''
  218. # reentrant testing for relocations, but now with random renames!
  219. [cases.reentrant_relocations_renames]
  220. reentrant = true
  221. # TODO fix this case, caused by non-DAG trees
  222. if = '!(DEPTH == 3 && CACHE_SIZE != 64)'
  223. defines = [
  224. {FILES=6, DEPTH=1, CYCLES=20, BLOCK_CYCLES=1},
  225. {FILES=26, DEPTH=1, CYCLES=20, BLOCK_CYCLES=1},
  226. {FILES=3, DEPTH=3, CYCLES=20, BLOCK_CYCLES=1},
  227. ]
  228. code = '''
  229. lfs_t lfs;
  230. int err = lfs_mount(&lfs, cfg);
  231. if (err) {
  232. lfs_format(&lfs, cfg) => 0;
  233. lfs_mount(&lfs, cfg) => 0;
  234. }
  235. srand(1);
  236. const char alpha[] = "abcdefghijklmnopqrstuvwxyz";
  237. for (unsigned i = 0; i < CYCLES; i++) {
  238. // create random path
  239. char full_path[256];
  240. for (unsigned d = 0; d < DEPTH; d++) {
  241. sprintf(&full_path[2*d], "/%c", alpha[rand() % FILES]);
  242. }
  243. // if it does not exist, we create it, else we destroy
  244. struct lfs_info info;
  245. int res = lfs_stat(&lfs, full_path, &info);
  246. assert(!res || res == LFS_ERR_NOENT);
  247. if (res == LFS_ERR_NOENT) {
  248. // create each directory in turn, ignore if dir already exists
  249. for (unsigned d = 0; d < DEPTH; d++) {
  250. char path[1024];
  251. strcpy(path, full_path);
  252. path[2*d+2] = '\0';
  253. err = lfs_mkdir(&lfs, path);
  254. assert(!err || err == LFS_ERR_EXIST);
  255. }
  256. for (unsigned d = 0; d < DEPTH; d++) {
  257. char path[1024];
  258. strcpy(path, full_path);
  259. path[2*d+2] = '\0';
  260. lfs_stat(&lfs, path, &info) => 0;
  261. assert(strcmp(info.name, &path[2*d+1]) == 0);
  262. assert(info.type == LFS_TYPE_DIR);
  263. }
  264. } else {
  265. assert(strcmp(info.name, &full_path[2*(DEPTH-1)+1]) == 0);
  266. assert(info.type == LFS_TYPE_DIR);
  267. // create new random path
  268. char new_path[256];
  269. for (unsigned d = 0; d < DEPTH; d++) {
  270. sprintf(&new_path[2*d], "/%c", alpha[rand() % FILES]);
  271. }
  272. // if new path does not exist, rename, otherwise destroy
  273. res = lfs_stat(&lfs, new_path, &info);
  274. assert(!res || res == LFS_ERR_NOENT);
  275. if (res == LFS_ERR_NOENT) {
  276. // stop once some dir is renamed
  277. for (unsigned d = 0; d < DEPTH; d++) {
  278. char path[1024];
  279. strcpy(&path[2*d], &full_path[2*d]);
  280. path[2*d+2] = '\0';
  281. strcpy(&path[128+2*d], &new_path[2*d]);
  282. path[128+2*d+2] = '\0';
  283. err = lfs_rename(&lfs, path, path+128);
  284. assert(!err || err == LFS_ERR_NOTEMPTY);
  285. if (!err) {
  286. strcpy(path, path+128);
  287. }
  288. }
  289. for (unsigned d = 0; d < DEPTH; d++) {
  290. char path[1024];
  291. strcpy(path, new_path);
  292. path[2*d+2] = '\0';
  293. lfs_stat(&lfs, path, &info) => 0;
  294. assert(strcmp(info.name, &path[2*d+1]) == 0);
  295. assert(info.type == LFS_TYPE_DIR);
  296. }
  297. lfs_stat(&lfs, full_path, &info) => LFS_ERR_NOENT;
  298. } else {
  299. // try to delete path in reverse order,
  300. // ignore if dir is not empty
  301. for (unsigned d = DEPTH-1; d+1 > 0; d--) {
  302. char path[1024];
  303. strcpy(path, full_path);
  304. path[2*d+2] = '\0';
  305. err = lfs_remove(&lfs, path);
  306. assert(!err || err == LFS_ERR_NOTEMPTY);
  307. }
  308. lfs_stat(&lfs, full_path, &info) => LFS_ERR_NOENT;
  309. }
  310. }
  311. }
  312. lfs_unmount(&lfs) => 0;
  313. '''