test_dirs.sh 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. #!/bin/bash
  2. set -eu
  3. LARGESIZE=128
  4. echo "=== Directory tests ==="
  5. rm -rf blocks
  6. tests/test.py << TEST
  7. lfs_format(&lfs, &config) => 0;
  8. TEST
  9. echo "--- Root directory ---"
  10. tests/test.py << TEST
  11. lfs_mount(&lfs, &config) => 0;
  12. lfs_dir_open(&lfs, &dir[0], "/") => 0;
  13. lfs_dir_close(&lfs, &dir[0]) => 0;
  14. lfs_unmount(&lfs) => 0;
  15. TEST
  16. echo "--- Directory creation ---"
  17. tests/test.py << TEST
  18. lfs_mount(&lfs, &config) => 0;
  19. lfs_mkdir(&lfs, "potato") => 0;
  20. lfs_unmount(&lfs) => 0;
  21. TEST
  22. echo "--- File creation ---"
  23. tests/test.py << TEST
  24. lfs_mount(&lfs, &config) => 0;
  25. lfs_file_open(&lfs, &file[0], "burito", LFS_O_CREAT | LFS_O_WRONLY) => 0;
  26. lfs_file_close(&lfs, &file[0]) => 0;
  27. lfs_unmount(&lfs) => 0;
  28. TEST
  29. echo "--- Directory iteration ---"
  30. tests/test.py << TEST
  31. lfs_mount(&lfs, &config) => 0;
  32. lfs_dir_open(&lfs, &dir[0], "/") => 0;
  33. lfs_dir_read(&lfs, &dir[0], &info) => 1;
  34. strcmp(info.name, ".") => 0;
  35. info.type => LFS_TYPE_DIR;
  36. lfs_dir_read(&lfs, &dir[0], &info) => 1;
  37. strcmp(info.name, "..") => 0;
  38. info.type => LFS_TYPE_DIR;
  39. lfs_dir_read(&lfs, &dir[0], &info) => 1;
  40. strcmp(info.name, "potato") => 0;
  41. info.type => LFS_TYPE_DIR;
  42. lfs_dir_read(&lfs, &dir[0], &info) => 1;
  43. strcmp(info.name, "burito") => 0;
  44. info.type => LFS_TYPE_REG;
  45. lfs_dir_read(&lfs, &dir[0], &info) => 0;
  46. lfs_dir_close(&lfs, &dir[0]) => 0;
  47. lfs_unmount(&lfs) => 0;
  48. TEST
  49. echo "--- Directory failures ---"
  50. tests/test.py << TEST
  51. lfs_mount(&lfs, &config) => 0;
  52. lfs_mkdir(&lfs, "potato") => LFS_ERROR_EXISTS;
  53. lfs_dir_open(&lfs, &dir[0], "tomato") => LFS_ERROR_NO_ENTRY;
  54. lfs_dir_open(&lfs, &dir[0], "burito") => LFS_ERROR_NOT_DIR;
  55. lfs_file_open(&lfs, &file[0], "tomato", LFS_O_RDONLY) => LFS_ERROR_NO_ENTRY;
  56. lfs_file_open(&lfs, &file[0], "potato", LFS_O_RDONLY) => LFS_ERROR_IS_DIR;
  57. lfs_unmount(&lfs) => 0;
  58. TEST
  59. echo "--- Nested directories ---"
  60. tests/test.py << TEST
  61. lfs_mount(&lfs, &config) => 0;
  62. lfs_mkdir(&lfs, "potato/baked") => 0;
  63. lfs_mkdir(&lfs, "potato/sweet") => 0;
  64. lfs_mkdir(&lfs, "potato/fried") => 0;
  65. lfs_unmount(&lfs) => 0;
  66. TEST
  67. tests/test.py << TEST
  68. lfs_mount(&lfs, &config) => 0;
  69. lfs_dir_open(&lfs, &dir[0], "potato") => 0;
  70. lfs_dir_read(&lfs, &dir[0], &info) => 1;
  71. strcmp(info.name, ".") => 0;
  72. info.type => LFS_TYPE_DIR;
  73. lfs_dir_read(&lfs, &dir[0], &info) => 1;
  74. strcmp(info.name, "..") => 0;
  75. info.type => LFS_TYPE_DIR;
  76. lfs_dir_read(&lfs, &dir[0], &info) => 1;
  77. strcmp(info.name, "baked") => 0;
  78. info.type => LFS_TYPE_DIR;
  79. lfs_dir_read(&lfs, &dir[0], &info) => 1;
  80. strcmp(info.name, "sweet") => 0;
  81. info.type => LFS_TYPE_DIR;
  82. lfs_dir_read(&lfs, &dir[0], &info) => 1;
  83. strcmp(info.name, "fried") => 0;
  84. info.type => LFS_TYPE_DIR;
  85. lfs_dir_read(&lfs, &dir[0], &info) => 0;
  86. lfs_dir_close(&lfs, &dir[0]) => 0;
  87. lfs_unmount(&lfs) => 0;
  88. TEST
  89. echo "--- Multi-block directory ---"
  90. tests/test.py << TEST
  91. lfs_mount(&lfs, &config) => 0;
  92. lfs_mkdir(&lfs, "cactus") => 0;
  93. for (int i = 0; i < $LARGESIZE; i++) {
  94. sprintf((char*)buffer, "cactus/test%d", i);
  95. lfs_mkdir(&lfs, (char*)buffer) => 0;
  96. }
  97. lfs_unmount(&lfs) => 0;
  98. TEST
  99. tests/test.py << TEST
  100. lfs_mount(&lfs, &config) => 0;
  101. lfs_dir_open(&lfs, &dir[0], "cactus") => 0;
  102. lfs_dir_read(&lfs, &dir[0], &info) => 1;
  103. strcmp(info.name, ".") => 0;
  104. info.type => LFS_TYPE_DIR;
  105. lfs_dir_read(&lfs, &dir[0], &info) => 1;
  106. strcmp(info.name, "..") => 0;
  107. info.type => LFS_TYPE_DIR;
  108. for (int i = 0; i < $LARGESIZE; i++) {
  109. sprintf((char*)buffer, "test%d", i);
  110. lfs_dir_read(&lfs, &dir[0], &info) => 1;
  111. strcmp(info.name, (char*)buffer) => 0;
  112. }
  113. lfs_dir_read(&lfs, &dir[0], &info) => 0;
  114. lfs_unmount(&lfs) => 0;
  115. TEST
  116. echo "--- Directory remove ---"
  117. tests/test.py << TEST
  118. lfs_mount(&lfs, &config) => 0;
  119. lfs_remove(&lfs, "potato") => LFS_ERROR_INVALID;
  120. lfs_remove(&lfs, "potato/sweet") => 0;
  121. lfs_remove(&lfs, "potato/baked") => 0;
  122. lfs_remove(&lfs, "potato/fried") => 0;
  123. lfs_dir_open(&lfs, &dir[0], "potato") => 0;
  124. lfs_dir_read(&lfs, &dir[0], &info) => 1;
  125. strcmp(info.name, ".") => 0;
  126. info.type => LFS_TYPE_DIR;
  127. lfs_dir_read(&lfs, &dir[0], &info) => 1;
  128. strcmp(info.name, "..") => 0;
  129. info.type => LFS_TYPE_DIR;
  130. lfs_dir_read(&lfs, &dir[0], &info) => 0;
  131. lfs_dir_close(&lfs, &dir[0]) => 0;
  132. lfs_remove(&lfs, "potato") => 0;
  133. lfs_dir_open(&lfs, &dir[0], "/") => 0;
  134. lfs_dir_read(&lfs, &dir[0], &info) => 1;
  135. strcmp(info.name, ".") => 0;
  136. info.type => LFS_TYPE_DIR;
  137. lfs_dir_read(&lfs, &dir[0], &info) => 1;
  138. strcmp(info.name, "..") => 0;
  139. info.type => LFS_TYPE_DIR;
  140. lfs_dir_read(&lfs, &dir[0], &info) => 1;
  141. strcmp(info.name, "burito") => 0;
  142. info.type => LFS_TYPE_REG;
  143. lfs_dir_read(&lfs, &dir[0], &info) => 1;
  144. strcmp(info.name, "cactus") => 0;
  145. info.type => LFS_TYPE_DIR;
  146. lfs_dir_read(&lfs, &dir[0], &info) => 0;
  147. lfs_dir_close(&lfs, &dir[0]) => 0;
  148. lfs_unmount(&lfs) => 0;
  149. TEST
  150. tests/test.py << TEST
  151. lfs_mount(&lfs, &config) => 0;
  152. lfs_dir_open(&lfs, &dir[0], "/") => 0;
  153. lfs_dir_read(&lfs, &dir[0], &info) => 1;
  154. strcmp(info.name, ".") => 0;
  155. info.type => LFS_TYPE_DIR;
  156. lfs_dir_read(&lfs, &dir[0], &info) => 1;
  157. strcmp(info.name, "..") => 0;
  158. info.type => LFS_TYPE_DIR;
  159. lfs_dir_read(&lfs, &dir[0], &info) => 1;
  160. strcmp(info.name, "burito") => 0;
  161. info.type => LFS_TYPE_REG;
  162. lfs_dir_read(&lfs, &dir[0], &info) => 1;
  163. strcmp(info.name, "cactus") => 0;
  164. info.type => LFS_TYPE_DIR;
  165. lfs_dir_read(&lfs, &dir[0], &info) => 0;
  166. lfs_dir_close(&lfs, &dir[0]) => 0;
  167. lfs_unmount(&lfs) => 0;
  168. TEST
  169. echo "--- Directory rename ---"
  170. tests/test.py << TEST
  171. lfs_mount(&lfs, &config) => 0;
  172. lfs_mkdir(&lfs, "coldpotato") => 0;
  173. lfs_mkdir(&lfs, "coldpotato/baked") => 0;
  174. lfs_mkdir(&lfs, "coldpotato/sweet") => 0;
  175. lfs_mkdir(&lfs, "coldpotato/fried") => 0;
  176. lfs_unmount(&lfs) => 0;
  177. TEST
  178. tests/test.py << TEST
  179. lfs_mount(&lfs, &config) => 0;
  180. lfs_rename(&lfs, "coldpotato", "hotpotato") => 0;
  181. lfs_unmount(&lfs) => 0;
  182. TEST
  183. tests/test.py << TEST
  184. lfs_mount(&lfs, &config) => 0;
  185. lfs_dir_open(&lfs, &dir[0], "hotpotato") => 0;
  186. lfs_dir_read(&lfs, &dir[0], &info) => 1;
  187. strcmp(info.name, ".") => 0;
  188. info.type => LFS_TYPE_DIR;
  189. lfs_dir_read(&lfs, &dir[0], &info) => 1;
  190. strcmp(info.name, "..") => 0;
  191. info.type => LFS_TYPE_DIR;
  192. lfs_dir_read(&lfs, &dir[0], &info) => 1;
  193. strcmp(info.name, "baked") => 0;
  194. info.type => LFS_TYPE_DIR;
  195. lfs_dir_read(&lfs, &dir[0], &info) => 1;
  196. strcmp(info.name, "sweet") => 0;
  197. info.type => LFS_TYPE_DIR;
  198. lfs_dir_read(&lfs, &dir[0], &info) => 1;
  199. strcmp(info.name, "fried") => 0;
  200. info.type => LFS_TYPE_DIR;
  201. lfs_dir_read(&lfs, &dir[0], &info) => 0;
  202. lfs_dir_close(&lfs, &dir[0]) => 0;
  203. lfs_unmount(&lfs) => 0;
  204. TEST
  205. tests/test.py << TEST
  206. lfs_mount(&lfs, &config) => 0;
  207. lfs_mkdir(&lfs, "warmpotato") => 0;
  208. lfs_mkdir(&lfs, "warmpotato/mushy") => 0;
  209. lfs_rename(&lfs, "hotpotato", "warmpotato") => LFS_ERROR_INVALID;
  210. lfs_remove(&lfs, "warmpotato/mushy") => 0;
  211. lfs_rename(&lfs, "hotpotato", "warmpotato") => 0;
  212. lfs_unmount(&lfs) => 0;
  213. TEST
  214. tests/test.py << TEST
  215. lfs_mount(&lfs, &config) => 0;
  216. lfs_dir_open(&lfs, &dir[0], "warmpotato") => 0;
  217. lfs_dir_read(&lfs, &dir[0], &info) => 1;
  218. strcmp(info.name, ".") => 0;
  219. info.type => LFS_TYPE_DIR;
  220. lfs_dir_read(&lfs, &dir[0], &info) => 1;
  221. strcmp(info.name, "..") => 0;
  222. info.type => LFS_TYPE_DIR;
  223. lfs_dir_read(&lfs, &dir[0], &info) => 1;
  224. strcmp(info.name, "baked") => 0;
  225. info.type => LFS_TYPE_DIR;
  226. lfs_dir_read(&lfs, &dir[0], &info) => 1;
  227. strcmp(info.name, "sweet") => 0;
  228. info.type => LFS_TYPE_DIR;
  229. lfs_dir_read(&lfs, &dir[0], &info) => 1;
  230. strcmp(info.name, "fried") => 0;
  231. info.type => LFS_TYPE_DIR;
  232. lfs_dir_read(&lfs, &dir[0], &info) => 0;
  233. lfs_dir_close(&lfs, &dir[0]) => 0;
  234. lfs_unmount(&lfs) => 0;
  235. TEST
  236. tests/test.py << TEST
  237. lfs_mount(&lfs, &config) => 0;
  238. lfs_mkdir(&lfs, "coldpotato") => 0;
  239. lfs_rename(&lfs, "warmpotato/baked", "coldpotato/baked") => 0;
  240. lfs_rename(&lfs, "warmpotato/sweet", "coldpotato/sweet") => 0;
  241. lfs_rename(&lfs, "warmpotato/fried", "coldpotato/fried") => 0;
  242. lfs_remove(&lfs, "coldpotato") => LFS_ERROR_INVALID;
  243. lfs_remove(&lfs, "warmpotato") => 0;
  244. lfs_unmount(&lfs) => 0;
  245. TEST
  246. tests/test.py << TEST
  247. lfs_mount(&lfs, &config) => 0;
  248. lfs_dir_open(&lfs, &dir[0], "coldpotato") => 0;
  249. lfs_dir_read(&lfs, &dir[0], &info) => 1;
  250. strcmp(info.name, ".") => 0;
  251. info.type => LFS_TYPE_DIR;
  252. lfs_dir_read(&lfs, &dir[0], &info) => 1;
  253. strcmp(info.name, "..") => 0;
  254. info.type => LFS_TYPE_DIR;
  255. lfs_dir_read(&lfs, &dir[0], &info) => 1;
  256. strcmp(info.name, "baked") => 0;
  257. info.type => LFS_TYPE_DIR;
  258. lfs_dir_read(&lfs, &dir[0], &info) => 1;
  259. strcmp(info.name, "sweet") => 0;
  260. info.type => LFS_TYPE_DIR;
  261. lfs_dir_read(&lfs, &dir[0], &info) => 1;
  262. strcmp(info.name, "fried") => 0;
  263. info.type => LFS_TYPE_DIR;
  264. lfs_dir_read(&lfs, &dir[0], &info) => 0;
  265. lfs_dir_close(&lfs, &dir[0]) => 0;
  266. lfs_unmount(&lfs) => 0;
  267. TEST
  268. echo "--- Results ---"
  269. tests/stats.py