test_alloc.toml 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  1. # allocator tests
  2. # note for these to work there are a number constraints on the device geometry
  3. if = 'LFS_BLOCK_CYCLES == -1'
  4. [[case]] # parallel allocation test
  5. define.FILES = 3
  6. define.SIZE = '(((LFS_BLOCK_SIZE-8)*(LFS_BLOCK_COUNT-6)) / FILES)'
  7. code = '''
  8. const char *names[FILES] = {"bacon", "eggs", "pancakes"};
  9. lfs_file_t files[FILES];
  10. lfs_format(&lfs, &cfg) => 0;
  11. lfs_mount(&lfs, &cfg) => 0;
  12. lfs_mkdir(&lfs, "breakfast") => 0;
  13. lfs_unmount(&lfs) => 0;
  14. lfs_mount(&lfs, &cfg) => 0;
  15. for (int n = 0; n < FILES; n++) {
  16. sprintf(path, "breakfast/%s", names[n]);
  17. lfs_file_open(&lfs, &files[n], path,
  18. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_APPEND) => 0;
  19. }
  20. for (int n = 0; n < FILES; n++) {
  21. size = strlen(names[n]);
  22. for (lfs_size_t i = 0; i < SIZE; i += size) {
  23. lfs_file_write(&lfs, &files[n], names[n], size) => size;
  24. }
  25. }
  26. for (int n = 0; n < FILES; n++) {
  27. lfs_file_close(&lfs, &files[n]) => 0;
  28. }
  29. lfs_unmount(&lfs) => 0;
  30. lfs_mount(&lfs, &cfg) => 0;
  31. for (int n = 0; n < FILES; n++) {
  32. sprintf(path, "breakfast/%s", names[n]);
  33. lfs_file_open(&lfs, &file, path, LFS_O_RDONLY) => 0;
  34. size = strlen(names[n]);
  35. for (lfs_size_t i = 0; i < SIZE; i += size) {
  36. lfs_file_read(&lfs, &file, buffer, size) => size;
  37. assert(memcmp(buffer, names[n], size) == 0);
  38. }
  39. lfs_file_close(&lfs, &file) => 0;
  40. }
  41. lfs_unmount(&lfs) => 0;
  42. '''
  43. [[case]] # serial allocation test
  44. define.FILES = 3
  45. define.SIZE = '(((LFS_BLOCK_SIZE-8)*(LFS_BLOCK_COUNT-6)) / FILES)'
  46. code = '''
  47. const char *names[FILES] = {"bacon", "eggs", "pancakes"};
  48. lfs_format(&lfs, &cfg) => 0;
  49. lfs_mount(&lfs, &cfg) => 0;
  50. lfs_mkdir(&lfs, "breakfast") => 0;
  51. lfs_unmount(&lfs) => 0;
  52. for (int n = 0; n < FILES; n++) {
  53. lfs_mount(&lfs, &cfg) => 0;
  54. sprintf(path, "breakfast/%s", names[n]);
  55. lfs_file_open(&lfs, &file, path,
  56. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_APPEND) => 0;
  57. size = strlen(names[n]);
  58. memcpy(buffer, names[n], size);
  59. for (int i = 0; i < SIZE; i += size) {
  60. lfs_file_write(&lfs, &file, buffer, size) => size;
  61. }
  62. lfs_file_close(&lfs, &file) => 0;
  63. lfs_unmount(&lfs) => 0;
  64. }
  65. lfs_mount(&lfs, &cfg) => 0;
  66. for (int n = 0; n < FILES; n++) {
  67. sprintf(path, "breakfast/%s", names[n]);
  68. lfs_file_open(&lfs, &file, path, LFS_O_RDONLY) => 0;
  69. size = strlen(names[n]);
  70. for (int i = 0; i < SIZE; i += size) {
  71. lfs_file_read(&lfs, &file, buffer, size) => size;
  72. assert(memcmp(buffer, names[n], size) == 0);
  73. }
  74. lfs_file_close(&lfs, &file) => 0;
  75. }
  76. lfs_unmount(&lfs) => 0;
  77. '''
  78. [[case]] # parallel allocation reuse test
  79. define.FILES = 3
  80. define.SIZE = '(((LFS_BLOCK_SIZE-8)*(LFS_BLOCK_COUNT-6)) / FILES)'
  81. define.CYCLES = [1, 10]
  82. code = '''
  83. const char *names[FILES] = {"bacon", "eggs", "pancakes"};
  84. lfs_file_t files[FILES];
  85. lfs_format(&lfs, &cfg) => 0;
  86. for (int c = 0; c < CYCLES; c++) {
  87. lfs_mount(&lfs, &cfg) => 0;
  88. lfs_mkdir(&lfs, "breakfast") => 0;
  89. lfs_unmount(&lfs) => 0;
  90. lfs_mount(&lfs, &cfg) => 0;
  91. for (int n = 0; n < FILES; n++) {
  92. sprintf(path, "breakfast/%s", names[n]);
  93. lfs_file_open(&lfs, &files[n], path,
  94. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_APPEND) => 0;
  95. }
  96. for (int n = 0; n < FILES; n++) {
  97. size = strlen(names[n]);
  98. for (int i = 0; i < SIZE; i += size) {
  99. lfs_file_write(&lfs, &files[n], names[n], size) => size;
  100. }
  101. }
  102. for (int n = 0; n < FILES; n++) {
  103. lfs_file_close(&lfs, &files[n]) => 0;
  104. }
  105. lfs_unmount(&lfs) => 0;
  106. lfs_mount(&lfs, &cfg) => 0;
  107. for (int n = 0; n < FILES; n++) {
  108. sprintf(path, "breakfast/%s", names[n]);
  109. lfs_file_open(&lfs, &file, path, LFS_O_RDONLY) => 0;
  110. size = strlen(names[n]);
  111. for (int i = 0; i < SIZE; i += size) {
  112. lfs_file_read(&lfs, &file, buffer, size) => size;
  113. assert(memcmp(buffer, names[n], size) == 0);
  114. }
  115. lfs_file_close(&lfs, &file) => 0;
  116. }
  117. lfs_unmount(&lfs) => 0;
  118. lfs_mount(&lfs, &cfg) => 0;
  119. for (int n = 0; n < FILES; n++) {
  120. sprintf(path, "breakfast/%s", names[n]);
  121. lfs_remove(&lfs, path) => 0;
  122. }
  123. lfs_remove(&lfs, "breakfast") => 0;
  124. lfs_unmount(&lfs) => 0;
  125. }
  126. '''
  127. [[case]] # serial allocation reuse test
  128. define.FILES = 3
  129. define.SIZE = '(((LFS_BLOCK_SIZE-8)*(LFS_BLOCK_COUNT-6)) / FILES)'
  130. define.CYCLES = [1, 10]
  131. code = '''
  132. const char *names[FILES] = {"bacon", "eggs", "pancakes"};
  133. lfs_format(&lfs, &cfg) => 0;
  134. for (int c = 0; c < CYCLES; c++) {
  135. lfs_mount(&lfs, &cfg) => 0;
  136. lfs_mkdir(&lfs, "breakfast") => 0;
  137. lfs_unmount(&lfs) => 0;
  138. for (int n = 0; n < FILES; n++) {
  139. lfs_mount(&lfs, &cfg) => 0;
  140. sprintf(path, "breakfast/%s", names[n]);
  141. lfs_file_open(&lfs, &file, path,
  142. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_APPEND) => 0;
  143. size = strlen(names[n]);
  144. memcpy(buffer, names[n], size);
  145. for (int i = 0; i < SIZE; i += size) {
  146. lfs_file_write(&lfs, &file, buffer, size) => size;
  147. }
  148. lfs_file_close(&lfs, &file) => 0;
  149. lfs_unmount(&lfs) => 0;
  150. }
  151. lfs_mount(&lfs, &cfg) => 0;
  152. for (int n = 0; n < FILES; n++) {
  153. sprintf(path, "breakfast/%s", names[n]);
  154. lfs_file_open(&lfs, &file, path, LFS_O_RDONLY) => 0;
  155. size = strlen(names[n]);
  156. for (int i = 0; i < SIZE; i += size) {
  157. lfs_file_read(&lfs, &file, buffer, size) => size;
  158. assert(memcmp(buffer, names[n], size) == 0);
  159. }
  160. lfs_file_close(&lfs, &file) => 0;
  161. }
  162. lfs_unmount(&lfs) => 0;
  163. lfs_mount(&lfs, &cfg) => 0;
  164. for (int n = 0; n < FILES; n++) {
  165. sprintf(path, "breakfast/%s", names[n]);
  166. lfs_remove(&lfs, path) => 0;
  167. }
  168. lfs_remove(&lfs, "breakfast") => 0;
  169. lfs_unmount(&lfs) => 0;
  170. }
  171. '''
  172. [[case]] # exhaustion test
  173. code = '''
  174. lfs_format(&lfs, &cfg) => 0;
  175. lfs_mount(&lfs, &cfg) => 0;
  176. lfs_file_open(&lfs, &file, "exhaustion", LFS_O_WRONLY | LFS_O_CREAT);
  177. size = strlen("exhaustion");
  178. memcpy(buffer, "exhaustion", size);
  179. lfs_file_write(&lfs, &file, buffer, size) => size;
  180. lfs_file_sync(&lfs, &file) => 0;
  181. size = strlen("blahblahblahblah");
  182. memcpy(buffer, "blahblahblahblah", size);
  183. lfs_ssize_t res;
  184. while (true) {
  185. res = lfs_file_write(&lfs, &file, buffer, size);
  186. if (res < 0) {
  187. break;
  188. }
  189. res => size;
  190. }
  191. res => LFS_ERR_NOSPC;
  192. lfs_file_close(&lfs, &file) => 0;
  193. lfs_unmount(&lfs) => 0;
  194. lfs_mount(&lfs, &cfg) => 0;
  195. lfs_file_open(&lfs, &file, "exhaustion", LFS_O_RDONLY);
  196. size = strlen("exhaustion");
  197. lfs_file_size(&lfs, &file) => size;
  198. lfs_file_read(&lfs, &file, buffer, size) => size;
  199. memcmp(buffer, "exhaustion", size) => 0;
  200. lfs_file_close(&lfs, &file) => 0;
  201. lfs_unmount(&lfs) => 0;
  202. '''
  203. [[case]] # exhaustion wraparound test
  204. define.SIZE = '(((LFS_BLOCK_SIZE-8)*(LFS_BLOCK_COUNT-4)) / 3)'
  205. code = '''
  206. lfs_format(&lfs, &cfg) => 0;
  207. lfs_mount(&lfs, &cfg) => 0;
  208. lfs_file_open(&lfs, &file, "padding", LFS_O_WRONLY | LFS_O_CREAT);
  209. size = strlen("buffering");
  210. memcpy(buffer, "buffering", size);
  211. for (int i = 0; i < SIZE; i += size) {
  212. lfs_file_write(&lfs, &file, buffer, size) => size;
  213. }
  214. lfs_file_close(&lfs, &file) => 0;
  215. lfs_remove(&lfs, "padding") => 0;
  216. lfs_file_open(&lfs, &file, "exhaustion", LFS_O_WRONLY | LFS_O_CREAT);
  217. size = strlen("exhaustion");
  218. memcpy(buffer, "exhaustion", size);
  219. lfs_file_write(&lfs, &file, buffer, size) => size;
  220. lfs_file_sync(&lfs, &file) => 0;
  221. size = strlen("blahblahblahblah");
  222. memcpy(buffer, "blahblahblahblah", size);
  223. lfs_ssize_t res;
  224. while (true) {
  225. res = lfs_file_write(&lfs, &file, buffer, size);
  226. if (res < 0) {
  227. break;
  228. }
  229. res => size;
  230. }
  231. res => LFS_ERR_NOSPC;
  232. lfs_file_close(&lfs, &file) => 0;
  233. lfs_unmount(&lfs) => 0;
  234. lfs_mount(&lfs, &cfg) => 0;
  235. lfs_file_open(&lfs, &file, "exhaustion", LFS_O_RDONLY);
  236. size = strlen("exhaustion");
  237. lfs_file_size(&lfs, &file) => size;
  238. lfs_file_read(&lfs, &file, buffer, size) => size;
  239. memcmp(buffer, "exhaustion", size) => 0;
  240. lfs_file_close(&lfs, &file) => 0;
  241. lfs_remove(&lfs, "exhaustion") => 0;
  242. lfs_unmount(&lfs) => 0;
  243. '''
  244. [[case]] # dir exhaustion test
  245. code = '''
  246. lfs_format(&lfs, &cfg) => 0;
  247. lfs_mount(&lfs, &cfg) => 0;
  248. // find out max file size
  249. lfs_mkdir(&lfs, "exhaustiondir") => 0;
  250. size = strlen("blahblahblahblah");
  251. memcpy(buffer, "blahblahblahblah", size);
  252. lfs_file_open(&lfs, &file, "exhaustion", LFS_O_WRONLY | LFS_O_CREAT);
  253. int count = 0;
  254. while (true) {
  255. err = lfs_file_write(&lfs, &file, buffer, size);
  256. if (err < 0) {
  257. break;
  258. }
  259. count += 1;
  260. }
  261. err => LFS_ERR_NOSPC;
  262. lfs_file_close(&lfs, &file) => 0;
  263. lfs_remove(&lfs, "exhaustion") => 0;
  264. lfs_remove(&lfs, "exhaustiondir") => 0;
  265. // see if dir fits with max file size
  266. lfs_file_open(&lfs, &file, "exhaustion", LFS_O_WRONLY | LFS_O_CREAT);
  267. for (int i = 0; i < count; i++) {
  268. lfs_file_write(&lfs, &file, buffer, size) => size;
  269. }
  270. lfs_file_close(&lfs, &file) => 0;
  271. lfs_mkdir(&lfs, "exhaustiondir") => 0;
  272. lfs_remove(&lfs, "exhaustiondir") => 0;
  273. lfs_remove(&lfs, "exhaustion") => 0;
  274. // see if dir fits with > max file size
  275. lfs_file_open(&lfs, &file, "exhaustion", LFS_O_WRONLY | LFS_O_CREAT);
  276. for (int i = 0; i < count+1; i++) {
  277. lfs_file_write(&lfs, &file, buffer, size) => size;
  278. }
  279. lfs_file_close(&lfs, &file) => 0;
  280. lfs_mkdir(&lfs, "exhaustiondir") => LFS_ERR_NOSPC;
  281. lfs_remove(&lfs, "exhaustion") => 0;
  282. lfs_unmount(&lfs) => 0;
  283. '''
  284. [[case]] # what if we have a bad block during an allocation scan?
  285. in = "lfs.c"
  286. define.LFS_ERASE_CYCLES = 0xffffffff
  287. define.LFS_BADBLOCK_BEHAVIOR = 'LFS_TESTBD_BADBLOCK_READERROR'
  288. code = '''
  289. lfs_format(&lfs, &cfg) => 0;
  290. lfs_mount(&lfs, &cfg) => 0;
  291. // first fill to exhaustion to find available space
  292. lfs_file_open(&lfs, &file, "pacman", LFS_O_WRONLY | LFS_O_CREAT) => 0;
  293. strcpy((char*)buffer, "waka");
  294. size = strlen("waka");
  295. lfs_size_t filesize = 0;
  296. while (true) {
  297. lfs_ssize_t res = lfs_file_write(&lfs, &file, buffer, size);
  298. assert(res == (lfs_ssize_t)size || res == LFS_ERR_NOSPC);
  299. if (res == LFS_ERR_NOSPC) {
  300. break;
  301. }
  302. filesize += size;
  303. }
  304. lfs_file_close(&lfs, &file) => 0;
  305. // now fill all but a couple of blocks of the filesystem with data
  306. filesize -= 3*LFS_BLOCK_SIZE;
  307. lfs_file_open(&lfs, &file, "pacman", LFS_O_WRONLY | LFS_O_CREAT) => 0;
  308. strcpy((char*)buffer, "waka");
  309. size = strlen("waka");
  310. for (lfs_size_t i = 0; i < filesize/size; i++) {
  311. lfs_file_write(&lfs, &file, buffer, size) => size;
  312. }
  313. lfs_file_close(&lfs, &file) => 0;
  314. // also save head of file so we can error during lookahead scan
  315. lfs_block_t fileblock = file.ctz.head;
  316. lfs_unmount(&lfs) => 0;
  317. // remount to force an alloc scan
  318. lfs_mount(&lfs, &cfg) => 0;
  319. // but mark the head of our file as a "bad block", this is force our
  320. // scan to bail early
  321. lfs_testbd_setwear(&cfg, fileblock, 0xffffffff) => 0;
  322. lfs_file_open(&lfs, &file, "ghost", LFS_O_WRONLY | LFS_O_CREAT) => 0;
  323. strcpy((char*)buffer, "chomp");
  324. size = strlen("chomp");
  325. while (true) {
  326. lfs_ssize_t res = lfs_file_write(&lfs, &file, buffer, size);
  327. assert(res == (lfs_ssize_t)size || res == LFS_ERR_CORRUPT);
  328. if (res == LFS_ERR_CORRUPT) {
  329. break;
  330. }
  331. }
  332. lfs_file_close(&lfs, &file) => 0;
  333. // now reverse the "bad block" and try to write the file again until we
  334. // run out of space
  335. lfs_testbd_setwear(&cfg, fileblock, 0) => 0;
  336. lfs_file_open(&lfs, &file, "ghost", LFS_O_WRONLY | LFS_O_CREAT) => 0;
  337. strcpy((char*)buffer, "chomp");
  338. size = strlen("chomp");
  339. while (true) {
  340. lfs_ssize_t res = lfs_file_write(&lfs, &file, buffer, size);
  341. assert(res == (lfs_ssize_t)size || res == LFS_ERR_NOSPC);
  342. if (res == LFS_ERR_NOSPC) {
  343. break;
  344. }
  345. }
  346. lfs_file_close(&lfs, &file) => 0;
  347. lfs_unmount(&lfs) => 0;
  348. // check that the disk isn't hurt
  349. lfs_mount(&lfs, &cfg) => 0;
  350. lfs_file_open(&lfs, &file, "pacman", LFS_O_RDONLY) => 0;
  351. strcpy((char*)buffer, "waka");
  352. size = strlen("waka");
  353. for (lfs_size_t i = 0; i < filesize/size; i++) {
  354. uint8_t rbuffer[4];
  355. lfs_file_read(&lfs, &file, rbuffer, size) => size;
  356. assert(memcmp(rbuffer, buffer, size) == 0);
  357. }
  358. lfs_file_close(&lfs, &file) => 0;
  359. lfs_unmount(&lfs) => 0;
  360. '''
  361. # Below, I don't like these tests. They're fragile and depend _heavily_
  362. # on the geometry of the block device. But they are valuable. Eventually they
  363. # should be removed and replaced with generalized tests.
  364. [[case]] # chained dir exhaustion test
  365. define.LFS_BLOCK_SIZE = 512
  366. define.LFS_BLOCK_COUNT = 1024
  367. if = 'LFS_BLOCK_SIZE == 512 && LFS_BLOCK_COUNT == 1024'
  368. code = '''
  369. lfs_format(&lfs, &cfg) => 0;
  370. lfs_mount(&lfs, &cfg) => 0;
  371. // find out max file size
  372. lfs_mkdir(&lfs, "exhaustiondir") => 0;
  373. for (int i = 0; i < 10; i++) {
  374. sprintf(path, "dirwithanexhaustivelylongnameforpadding%d", i);
  375. lfs_mkdir(&lfs, path) => 0;
  376. }
  377. size = strlen("blahblahblahblah");
  378. memcpy(buffer, "blahblahblahblah", size);
  379. lfs_file_open(&lfs, &file, "exhaustion", LFS_O_WRONLY | LFS_O_CREAT);
  380. int count = 0;
  381. while (true) {
  382. err = lfs_file_write(&lfs, &file, buffer, size);
  383. if (err < 0) {
  384. break;
  385. }
  386. count += 1;
  387. }
  388. err => LFS_ERR_NOSPC;
  389. lfs_file_close(&lfs, &file) => 0;
  390. lfs_remove(&lfs, "exhaustion") => 0;
  391. lfs_remove(&lfs, "exhaustiondir") => 0;
  392. for (int i = 0; i < 10; i++) {
  393. sprintf(path, "dirwithanexhaustivelylongnameforpadding%d", i);
  394. lfs_remove(&lfs, path) => 0;
  395. }
  396. // see that chained dir fails
  397. lfs_file_open(&lfs, &file, "exhaustion", LFS_O_WRONLY | LFS_O_CREAT);
  398. for (int i = 0; i < count+1; i++) {
  399. lfs_file_write(&lfs, &file, buffer, size) => size;
  400. }
  401. lfs_file_sync(&lfs, &file) => 0;
  402. for (int i = 0; i < 10; i++) {
  403. sprintf(path, "dirwithanexhaustivelylongnameforpadding%d", i);
  404. lfs_mkdir(&lfs, path) => 0;
  405. }
  406. lfs_mkdir(&lfs, "exhaustiondir") => LFS_ERR_NOSPC;
  407. // shorten file to try a second chained dir
  408. while (true) {
  409. err = lfs_mkdir(&lfs, "exhaustiondir");
  410. if (err != LFS_ERR_NOSPC) {
  411. break;
  412. }
  413. lfs_ssize_t filesize = lfs_file_size(&lfs, &file);
  414. filesize > 0 => true;
  415. lfs_file_truncate(&lfs, &file, filesize - size) => 0;
  416. lfs_file_sync(&lfs, &file) => 0;
  417. }
  418. err => 0;
  419. lfs_mkdir(&lfs, "exhaustiondir2") => LFS_ERR_NOSPC;
  420. lfs_file_close(&lfs, &file) => 0;
  421. lfs_unmount(&lfs) => 0;
  422. '''
  423. [[case]] # split dir test
  424. define.LFS_BLOCK_SIZE = 512
  425. define.LFS_BLOCK_COUNT = 1024
  426. if = 'LFS_BLOCK_SIZE == 512 && LFS_BLOCK_COUNT == 1024'
  427. code = '''
  428. lfs_format(&lfs, &cfg) => 0;
  429. lfs_mount(&lfs, &cfg) => 0;
  430. // create one block hole for half a directory
  431. lfs_file_open(&lfs, &file, "bump", LFS_O_WRONLY | LFS_O_CREAT) => 0;
  432. for (lfs_size_t i = 0; i < cfg.block_size; i += 2) {
  433. memcpy(&buffer[i], "hi", 2);
  434. }
  435. lfs_file_write(&lfs, &file, buffer, cfg.block_size) => cfg.block_size;
  436. lfs_file_close(&lfs, &file) => 0;
  437. lfs_file_open(&lfs, &file, "exhaustion", LFS_O_WRONLY | LFS_O_CREAT);
  438. size = strlen("blahblahblahblah");
  439. memcpy(buffer, "blahblahblahblah", size);
  440. for (lfs_size_t i = 0;
  441. i < (cfg.block_count-4)*(cfg.block_size-8);
  442. i += size) {
  443. lfs_file_write(&lfs, &file, buffer, size) => size;
  444. }
  445. lfs_file_close(&lfs, &file) => 0;
  446. // remount to force reset of lookahead
  447. lfs_unmount(&lfs) => 0;
  448. lfs_mount(&lfs, &cfg) => 0;
  449. // open hole
  450. lfs_remove(&lfs, "bump") => 0;
  451. lfs_mkdir(&lfs, "splitdir") => 0;
  452. lfs_file_open(&lfs, &file, "splitdir/bump",
  453. LFS_O_WRONLY | LFS_O_CREAT) => 0;
  454. for (lfs_size_t i = 0; i < cfg.block_size; i += 2) {
  455. memcpy(&buffer[i], "hi", 2);
  456. }
  457. lfs_file_write(&lfs, &file, buffer, 2*cfg.block_size) => LFS_ERR_NOSPC;
  458. lfs_file_close(&lfs, &file) => 0;
  459. lfs_unmount(&lfs) => 0;
  460. '''
  461. [[case]] # outdated lookahead test
  462. define.LFS_BLOCK_SIZE = 512
  463. define.LFS_BLOCK_COUNT = 1024
  464. if = 'LFS_BLOCK_SIZE == 512 && LFS_BLOCK_COUNT == 1024'
  465. code = '''
  466. lfs_format(&lfs, &cfg) => 0;
  467. lfs_mount(&lfs, &cfg) => 0;
  468. // fill completely with two files
  469. lfs_file_open(&lfs, &file, "exhaustion1",
  470. LFS_O_WRONLY | LFS_O_CREAT) => 0;
  471. size = strlen("blahblahblahblah");
  472. memcpy(buffer, "blahblahblahblah", size);
  473. for (lfs_size_t i = 0;
  474. i < ((cfg.block_count-2)/2)*(cfg.block_size-8);
  475. i += size) {
  476. lfs_file_write(&lfs, &file, buffer, size) => size;
  477. }
  478. lfs_file_close(&lfs, &file) => 0;
  479. lfs_file_open(&lfs, &file, "exhaustion2",
  480. LFS_O_WRONLY | LFS_O_CREAT) => 0;
  481. size = strlen("blahblahblahblah");
  482. memcpy(buffer, "blahblahblahblah", size);
  483. for (lfs_size_t i = 0;
  484. i < ((cfg.block_count-2+1)/2)*(cfg.block_size-8);
  485. i += size) {
  486. lfs_file_write(&lfs, &file, buffer, size) => size;
  487. }
  488. lfs_file_close(&lfs, &file) => 0;
  489. // remount to force reset of lookahead
  490. lfs_unmount(&lfs) => 0;
  491. lfs_mount(&lfs, &cfg) => 0;
  492. // rewrite one file
  493. lfs_file_open(&lfs, &file, "exhaustion1",
  494. LFS_O_WRONLY | LFS_O_TRUNC) => 0;
  495. lfs_file_sync(&lfs, &file) => 0;
  496. size = strlen("blahblahblahblah");
  497. memcpy(buffer, "blahblahblahblah", size);
  498. for (lfs_size_t i = 0;
  499. i < ((cfg.block_count-2)/2)*(cfg.block_size-8);
  500. i += size) {
  501. lfs_file_write(&lfs, &file, buffer, size) => size;
  502. }
  503. lfs_file_close(&lfs, &file) => 0;
  504. // rewrite second file, this requires lookahead does not
  505. // use old population
  506. lfs_file_open(&lfs, &file, "exhaustion2",
  507. LFS_O_WRONLY | LFS_O_TRUNC) => 0;
  508. lfs_file_sync(&lfs, &file) => 0;
  509. size = strlen("blahblahblahblah");
  510. memcpy(buffer, "blahblahblahblah", size);
  511. for (lfs_size_t i = 0;
  512. i < ((cfg.block_count-2+1)/2)*(cfg.block_size-8);
  513. i += size) {
  514. lfs_file_write(&lfs, &file, buffer, size) => size;
  515. }
  516. lfs_file_close(&lfs, &file) => 0;
  517. lfs_unmount(&lfs) => 0;
  518. '''
  519. [[case]] # outdated lookahead and split dir test
  520. define.LFS_BLOCK_SIZE = 512
  521. define.LFS_BLOCK_COUNT = 1024
  522. if = 'LFS_BLOCK_SIZE == 512 && LFS_BLOCK_COUNT == 1024'
  523. code = '''
  524. lfs_format(&lfs, &cfg) => 0;
  525. lfs_mount(&lfs, &cfg) => 0;
  526. // fill completely with two files
  527. lfs_file_open(&lfs, &file, "exhaustion1",
  528. LFS_O_WRONLY | LFS_O_CREAT) => 0;
  529. size = strlen("blahblahblahblah");
  530. memcpy(buffer, "blahblahblahblah", size);
  531. for (lfs_size_t i = 0;
  532. i < ((cfg.block_count-2)/2)*(cfg.block_size-8);
  533. i += size) {
  534. lfs_file_write(&lfs, &file, buffer, size) => size;
  535. }
  536. lfs_file_close(&lfs, &file) => 0;
  537. lfs_file_open(&lfs, &file, "exhaustion2",
  538. LFS_O_WRONLY | LFS_O_CREAT) => 0;
  539. size = strlen("blahblahblahblah");
  540. memcpy(buffer, "blahblahblahblah", size);
  541. for (lfs_size_t i = 0;
  542. i < ((cfg.block_count-2+1)/2)*(cfg.block_size-8);
  543. i += size) {
  544. lfs_file_write(&lfs, &file, buffer, size) => size;
  545. }
  546. lfs_file_close(&lfs, &file) => 0;
  547. // remount to force reset of lookahead
  548. lfs_unmount(&lfs) => 0;
  549. lfs_mount(&lfs, &cfg) => 0;
  550. // rewrite one file with a hole of one block
  551. lfs_file_open(&lfs, &file, "exhaustion1",
  552. LFS_O_WRONLY | LFS_O_TRUNC) => 0;
  553. lfs_file_sync(&lfs, &file) => 0;
  554. size = strlen("blahblahblahblah");
  555. memcpy(buffer, "blahblahblahblah", size);
  556. for (lfs_size_t i = 0;
  557. i < ((cfg.block_count-2)/2 - 1)*(cfg.block_size-8);
  558. i += size) {
  559. lfs_file_write(&lfs, &file, buffer, size) => size;
  560. }
  561. lfs_file_close(&lfs, &file) => 0;
  562. // try to allocate a directory, should fail!
  563. lfs_mkdir(&lfs, "split") => LFS_ERR_NOSPC;
  564. // file should not fail
  565. lfs_file_open(&lfs, &file, "notasplit",
  566. LFS_O_WRONLY | LFS_O_CREAT) => 0;
  567. lfs_file_write(&lfs, &file, "hi", 2) => 2;
  568. lfs_file_close(&lfs, &file) => 0;
  569. lfs_unmount(&lfs) => 0;
  570. '''