test_relocations.toml 11 KB

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