test_alloc.toml 18 KB

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