test_files.toml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  1. [[case]] # simple file test
  2. code = '''
  3. lfs_format(&lfs, &cfg) => 0;
  4. lfs_mount(&lfs, &cfg) => 0;
  5. lfs_file_open(&lfs, &file, "hello",
  6. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  7. size = strlen("Hello World!")+1;
  8. strcpy((char*)buffer, "Hello World!");
  9. lfs_file_write(&lfs, &file, buffer, size) => size;
  10. lfs_file_close(&lfs, &file) => 0;
  11. lfs_unmount(&lfs) => 0;
  12. lfs_mount(&lfs, &cfg) => 0;
  13. lfs_file_open(&lfs, &file, "hello", LFS_O_RDONLY) => 0;
  14. lfs_file_read(&lfs, &file, buffer, size) => size;
  15. assert(strcmp((char*)buffer, "Hello World!") == 0);
  16. lfs_file_close(&lfs, &file) => 0;
  17. lfs_unmount(&lfs) => 0;
  18. '''
  19. [[case]] # larger files
  20. code = '''
  21. lfs_format(&lfs, &cfg) => 0;
  22. // write
  23. lfs_mount(&lfs, &cfg) => 0;
  24. lfs_file_open(&lfs, &file, "avacado",
  25. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  26. srand(1);
  27. for (lfs_size_t i = 0; i < SIZE; i += CHUNKSIZE) {
  28. lfs_size_t chunk = lfs_min(CHUNKSIZE, SIZE-i);
  29. for (lfs_size_t b = 0; b < chunk; b++) {
  30. buffer[b] = rand() & 0xff;
  31. }
  32. lfs_file_write(&lfs, &file, buffer, chunk) => chunk;
  33. }
  34. lfs_file_close(&lfs, &file) => 0;
  35. lfs_unmount(&lfs) => 0;
  36. // read
  37. lfs_mount(&lfs, &cfg) => 0;
  38. lfs_file_open(&lfs, &file, "avacado", LFS_O_RDONLY) => 0;
  39. lfs_file_size(&lfs, &file) => SIZE;
  40. srand(1);
  41. for (lfs_size_t i = 0; i < SIZE; i += CHUNKSIZE) {
  42. lfs_size_t chunk = lfs_min(CHUNKSIZE, SIZE-i);
  43. lfs_file_read(&lfs, &file, buffer, chunk) => chunk;
  44. for (lfs_size_t b = 0; b < chunk; b++) {
  45. assert(buffer[b] == (rand() & 0xff));
  46. }
  47. }
  48. lfs_file_read(&lfs, &file, buffer, CHUNKSIZE) => 0;
  49. lfs_file_close(&lfs, &file) => 0;
  50. lfs_unmount(&lfs) => 0;
  51. '''
  52. define.SIZE = [32, 8192, 262144, 0, 7, 8193]
  53. define.CHUNKSIZE = [31, 16, 33, 1, 1023]
  54. [[case]] # rewriting files
  55. code = '''
  56. lfs_format(&lfs, &cfg) => 0;
  57. // write
  58. lfs_mount(&lfs, &cfg) => 0;
  59. lfs_file_open(&lfs, &file, "avacado",
  60. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  61. srand(1);
  62. for (lfs_size_t i = 0; i < SIZE1; i += CHUNKSIZE) {
  63. lfs_size_t chunk = lfs_min(CHUNKSIZE, SIZE1-i);
  64. for (lfs_size_t b = 0; b < chunk; b++) {
  65. buffer[b] = rand() & 0xff;
  66. }
  67. lfs_file_write(&lfs, &file, buffer, chunk) => chunk;
  68. }
  69. lfs_file_close(&lfs, &file) => 0;
  70. lfs_unmount(&lfs) => 0;
  71. // read
  72. lfs_mount(&lfs, &cfg) => 0;
  73. lfs_file_open(&lfs, &file, "avacado", LFS_O_RDONLY) => 0;
  74. lfs_file_size(&lfs, &file) => SIZE1;
  75. srand(1);
  76. for (lfs_size_t i = 0; i < SIZE1; i += CHUNKSIZE) {
  77. lfs_size_t chunk = lfs_min(CHUNKSIZE, SIZE1-i);
  78. lfs_file_read(&lfs, &file, buffer, chunk) => chunk;
  79. for (lfs_size_t b = 0; b < chunk; b++) {
  80. assert(buffer[b] == (rand() & 0xff));
  81. }
  82. }
  83. lfs_file_read(&lfs, &file, buffer, CHUNKSIZE) => 0;
  84. lfs_file_close(&lfs, &file) => 0;
  85. lfs_unmount(&lfs) => 0;
  86. // rewrite
  87. lfs_mount(&lfs, &cfg) => 0;
  88. lfs_file_open(&lfs, &file, "avacado", LFS_O_WRONLY) => 0;
  89. srand(2);
  90. for (lfs_size_t i = 0; i < SIZE2; i += CHUNKSIZE) {
  91. lfs_size_t chunk = lfs_min(CHUNKSIZE, SIZE2-i);
  92. for (lfs_size_t b = 0; b < chunk; b++) {
  93. buffer[b] = rand() & 0xff;
  94. }
  95. lfs_file_write(&lfs, &file, buffer, chunk) => chunk;
  96. }
  97. lfs_file_close(&lfs, &file) => 0;
  98. lfs_unmount(&lfs) => 0;
  99. // read
  100. lfs_mount(&lfs, &cfg) => 0;
  101. lfs_file_open(&lfs, &file, "avacado", LFS_O_RDONLY) => 0;
  102. lfs_file_size(&lfs, &file) => lfs_max(SIZE1, SIZE2);
  103. srand(2);
  104. for (lfs_size_t i = 0; i < SIZE2; i += CHUNKSIZE) {
  105. lfs_size_t chunk = lfs_min(CHUNKSIZE, SIZE2-i);
  106. lfs_file_read(&lfs, &file, buffer, chunk) => chunk;
  107. for (lfs_size_t b = 0; b < chunk; b++) {
  108. assert(buffer[b] == (rand() & 0xff));
  109. }
  110. }
  111. if (SIZE1 > SIZE2) {
  112. srand(1);
  113. for (lfs_size_t b = 0; b < SIZE2; b++) {
  114. rand();
  115. }
  116. for (lfs_size_t i = SIZE2; i < SIZE1; i += CHUNKSIZE) {
  117. lfs_size_t chunk = lfs_min(CHUNKSIZE, SIZE1-i);
  118. lfs_file_read(&lfs, &file, buffer, chunk) => chunk;
  119. for (lfs_size_t b = 0; b < chunk; b++) {
  120. assert(buffer[b] == (rand() & 0xff));
  121. }
  122. }
  123. }
  124. lfs_file_read(&lfs, &file, buffer, CHUNKSIZE) => 0;
  125. lfs_file_close(&lfs, &file) => 0;
  126. lfs_unmount(&lfs) => 0;
  127. '''
  128. define.SIZE1 = [32, 8192, 131072, 0, 7, 8193]
  129. define.SIZE2 = [32, 8192, 131072, 0, 7, 8193]
  130. define.CHUNKSIZE = [31, 16, 1, 1025]
  131. [[case]] # appending files
  132. code = '''
  133. lfs_format(&lfs, &cfg) => 0;
  134. // write
  135. lfs_mount(&lfs, &cfg) => 0;
  136. lfs_file_open(&lfs, &file, "avacado",
  137. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  138. srand(1);
  139. for (lfs_size_t i = 0; i < SIZE1; i += CHUNKSIZE) {
  140. lfs_size_t chunk = lfs_min(CHUNKSIZE, SIZE1-i);
  141. for (lfs_size_t b = 0; b < chunk; b++) {
  142. buffer[b] = rand() & 0xff;
  143. }
  144. lfs_file_write(&lfs, &file, buffer, chunk) => chunk;
  145. }
  146. lfs_file_close(&lfs, &file) => 0;
  147. lfs_unmount(&lfs) => 0;
  148. // read
  149. lfs_mount(&lfs, &cfg) => 0;
  150. lfs_file_open(&lfs, &file, "avacado", LFS_O_RDONLY) => 0;
  151. lfs_file_size(&lfs, &file) => SIZE1;
  152. srand(1);
  153. for (lfs_size_t i = 0; i < SIZE1; i += CHUNKSIZE) {
  154. lfs_size_t chunk = lfs_min(CHUNKSIZE, SIZE1-i);
  155. lfs_file_read(&lfs, &file, buffer, chunk) => chunk;
  156. for (lfs_size_t b = 0; b < chunk; b++) {
  157. assert(buffer[b] == (rand() & 0xff));
  158. }
  159. }
  160. lfs_file_read(&lfs, &file, buffer, CHUNKSIZE) => 0;
  161. lfs_file_close(&lfs, &file) => 0;
  162. lfs_unmount(&lfs) => 0;
  163. // append
  164. lfs_mount(&lfs, &cfg) => 0;
  165. lfs_file_open(&lfs, &file, "avacado", LFS_O_WRONLY | LFS_O_APPEND) => 0;
  166. srand(2);
  167. for (lfs_size_t i = 0; i < SIZE2; i += CHUNKSIZE) {
  168. lfs_size_t chunk = lfs_min(CHUNKSIZE, SIZE2-i);
  169. for (lfs_size_t b = 0; b < chunk; b++) {
  170. buffer[b] = rand() & 0xff;
  171. }
  172. lfs_file_write(&lfs, &file, buffer, chunk) => chunk;
  173. }
  174. lfs_file_close(&lfs, &file) => 0;
  175. lfs_unmount(&lfs) => 0;
  176. // read
  177. lfs_mount(&lfs, &cfg) => 0;
  178. lfs_file_open(&lfs, &file, "avacado", LFS_O_RDONLY) => 0;
  179. lfs_file_size(&lfs, &file) => SIZE1 + SIZE2;
  180. srand(1);
  181. for (lfs_size_t i = 0; i < SIZE1; i += CHUNKSIZE) {
  182. lfs_size_t chunk = lfs_min(CHUNKSIZE, SIZE1-i);
  183. lfs_file_read(&lfs, &file, buffer, chunk) => chunk;
  184. for (lfs_size_t b = 0; b < chunk; b++) {
  185. assert(buffer[b] == (rand() & 0xff));
  186. }
  187. }
  188. srand(2);
  189. for (lfs_size_t i = 0; i < SIZE2; i += CHUNKSIZE) {
  190. lfs_size_t chunk = lfs_min(CHUNKSIZE, SIZE2-i);
  191. lfs_file_read(&lfs, &file, buffer, chunk) => chunk;
  192. for (lfs_size_t b = 0; b < chunk; b++) {
  193. assert(buffer[b] == (rand() & 0xff));
  194. }
  195. }
  196. lfs_file_read(&lfs, &file, buffer, CHUNKSIZE) => 0;
  197. lfs_file_close(&lfs, &file) => 0;
  198. lfs_unmount(&lfs) => 0;
  199. '''
  200. define.SIZE1 = [32, 8192, 131072, 0, 7, 8193]
  201. define.SIZE2 = [32, 8192, 131072, 0, 7, 8193]
  202. define.CHUNKSIZE = [31, 16, 1, 1025]
  203. [[case]] # truncating files
  204. code = '''
  205. lfs_format(&lfs, &cfg) => 0;
  206. // write
  207. lfs_mount(&lfs, &cfg) => 0;
  208. lfs_file_open(&lfs, &file, "avacado",
  209. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  210. srand(1);
  211. for (lfs_size_t i = 0; i < SIZE1; i += CHUNKSIZE) {
  212. lfs_size_t chunk = lfs_min(CHUNKSIZE, SIZE1-i);
  213. for (lfs_size_t b = 0; b < chunk; b++) {
  214. buffer[b] = rand() & 0xff;
  215. }
  216. lfs_file_write(&lfs, &file, buffer, chunk) => chunk;
  217. }
  218. lfs_file_close(&lfs, &file) => 0;
  219. lfs_unmount(&lfs) => 0;
  220. // read
  221. lfs_mount(&lfs, &cfg) => 0;
  222. lfs_file_open(&lfs, &file, "avacado", LFS_O_RDONLY) => 0;
  223. lfs_file_size(&lfs, &file) => SIZE1;
  224. srand(1);
  225. for (lfs_size_t i = 0; i < SIZE1; i += CHUNKSIZE) {
  226. lfs_size_t chunk = lfs_min(CHUNKSIZE, SIZE1-i);
  227. lfs_file_read(&lfs, &file, buffer, chunk) => chunk;
  228. for (lfs_size_t b = 0; b < chunk; b++) {
  229. assert(buffer[b] == (rand() & 0xff));
  230. }
  231. }
  232. lfs_file_read(&lfs, &file, buffer, CHUNKSIZE) => 0;
  233. lfs_file_close(&lfs, &file) => 0;
  234. lfs_unmount(&lfs) => 0;
  235. // truncate
  236. lfs_mount(&lfs, &cfg) => 0;
  237. lfs_file_open(&lfs, &file, "avacado", LFS_O_WRONLY | LFS_O_TRUNC) => 0;
  238. srand(2);
  239. for (lfs_size_t i = 0; i < SIZE2; i += CHUNKSIZE) {
  240. lfs_size_t chunk = lfs_min(CHUNKSIZE, SIZE2-i);
  241. for (lfs_size_t b = 0; b < chunk; b++) {
  242. buffer[b] = rand() & 0xff;
  243. }
  244. lfs_file_write(&lfs, &file, buffer, chunk) => chunk;
  245. }
  246. lfs_file_close(&lfs, &file) => 0;
  247. lfs_unmount(&lfs) => 0;
  248. // read
  249. lfs_mount(&lfs, &cfg) => 0;
  250. lfs_file_open(&lfs, &file, "avacado", LFS_O_RDONLY) => 0;
  251. lfs_file_size(&lfs, &file) => SIZE2;
  252. srand(2);
  253. for (lfs_size_t i = 0; i < SIZE2; i += CHUNKSIZE) {
  254. lfs_size_t chunk = lfs_min(CHUNKSIZE, SIZE2-i);
  255. lfs_file_read(&lfs, &file, buffer, chunk) => chunk;
  256. for (lfs_size_t b = 0; b < chunk; b++) {
  257. assert(buffer[b] == (rand() & 0xff));
  258. }
  259. }
  260. lfs_file_read(&lfs, &file, buffer, CHUNKSIZE) => 0;
  261. lfs_file_close(&lfs, &file) => 0;
  262. lfs_unmount(&lfs) => 0;
  263. '''
  264. define.SIZE1 = [32, 8192, 131072, 0, 7, 8193]
  265. define.SIZE2 = [32, 8192, 131072, 0, 7, 8193]
  266. define.CHUNKSIZE = [31, 16, 1, 1025]
  267. [[case]] # reentrant file writing
  268. code = '''
  269. err = lfs_mount(&lfs, &cfg);
  270. if (err) {
  271. lfs_format(&lfs, &cfg) => 0;
  272. lfs_mount(&lfs, &cfg) => 0;
  273. }
  274. err = lfs_file_open(&lfs, &file, "avacado", LFS_O_RDONLY);
  275. assert(err == LFS_ERR_NOENT || err == 0);
  276. if (err == 0) {
  277. // can only be 0 (new file) or full size
  278. size = lfs_file_size(&lfs, &file);
  279. assert(size == 0 || size == SIZE);
  280. lfs_file_close(&lfs, &file) => 0;
  281. }
  282. // write
  283. lfs_file_open(&lfs, &file, "avacado", LFS_O_WRONLY | LFS_O_CREAT) => 0;
  284. srand(1);
  285. for (lfs_size_t i = 0; i < SIZE; i += CHUNKSIZE) {
  286. lfs_size_t chunk = lfs_min(CHUNKSIZE, SIZE-i);
  287. for (lfs_size_t b = 0; b < chunk; b++) {
  288. buffer[b] = rand() & 0xff;
  289. }
  290. lfs_file_write(&lfs, &file, buffer, chunk) => chunk;
  291. }
  292. lfs_file_close(&lfs, &file) => 0;
  293. // read
  294. lfs_file_open(&lfs, &file, "avacado", LFS_O_RDONLY) => 0;
  295. lfs_file_size(&lfs, &file) => SIZE;
  296. srand(1);
  297. for (lfs_size_t i = 0; i < SIZE; i += CHUNKSIZE) {
  298. lfs_size_t chunk = lfs_min(CHUNKSIZE, SIZE-i);
  299. lfs_file_read(&lfs, &file, buffer, chunk) => chunk;
  300. for (lfs_size_t b = 0; b < chunk; b++) {
  301. assert(buffer[b] == (rand() & 0xff));
  302. }
  303. }
  304. lfs_file_read(&lfs, &file, buffer, CHUNKSIZE) => 0;
  305. lfs_file_close(&lfs, &file) => 0;
  306. lfs_unmount(&lfs) => 0;
  307. '''
  308. define.SIZE = [32, 0, 7, 2049]
  309. define.CHUNKSIZE = [31, 16, 65]
  310. reentrant = true
  311. [[case]] # reentrant file writing with syncs
  312. code = '''
  313. err = lfs_mount(&lfs, &cfg);
  314. if (err) {
  315. lfs_format(&lfs, &cfg) => 0;
  316. lfs_mount(&lfs, &cfg) => 0;
  317. }
  318. err = lfs_file_open(&lfs, &file, "avacado", LFS_O_RDONLY);
  319. assert(err == LFS_ERR_NOENT || err == 0);
  320. if (err == 0) {
  321. // with syncs we could be any size, but it at least must be valid data
  322. size = lfs_file_size(&lfs, &file);
  323. assert(size <= SIZE);
  324. srand(1);
  325. for (lfs_size_t i = 0; i < size; i += CHUNKSIZE) {
  326. lfs_size_t chunk = lfs_min(CHUNKSIZE, size-i);
  327. lfs_file_read(&lfs, &file, buffer, chunk) => chunk;
  328. for (lfs_size_t b = 0; b < chunk; b++) {
  329. assert(buffer[b] == (rand() & 0xff));
  330. }
  331. }
  332. lfs_file_close(&lfs, &file) => 0;
  333. }
  334. // write
  335. lfs_file_open(&lfs, &file, "avacado",
  336. LFS_O_WRONLY | LFS_O_CREAT | MODE) => 0;
  337. size = lfs_file_size(&lfs, &file);
  338. assert(size <= SIZE);
  339. srand(1);
  340. lfs_size_t skip = (MODE == LFS_O_APPEND) ? size : 0;
  341. for (lfs_size_t b = 0; b < skip; b++) {
  342. rand();
  343. }
  344. for (lfs_size_t i = skip; i < SIZE; i += CHUNKSIZE) {
  345. lfs_size_t chunk = lfs_min(CHUNKSIZE, SIZE-i);
  346. for (lfs_size_t b = 0; b < chunk; b++) {
  347. buffer[b] = rand() & 0xff;
  348. }
  349. lfs_file_write(&lfs, &file, buffer, chunk) => chunk;
  350. lfs_file_sync(&lfs, &file) => 0;
  351. }
  352. lfs_file_close(&lfs, &file) => 0;
  353. // read
  354. lfs_file_open(&lfs, &file, "avacado", LFS_O_RDONLY) => 0;
  355. lfs_file_size(&lfs, &file) => SIZE;
  356. srand(1);
  357. for (lfs_size_t i = 0; i < SIZE; i += CHUNKSIZE) {
  358. lfs_size_t chunk = lfs_min(CHUNKSIZE, SIZE-i);
  359. lfs_file_read(&lfs, &file, buffer, chunk) => chunk;
  360. for (lfs_size_t b = 0; b < chunk; b++) {
  361. assert(buffer[b] == (rand() & 0xff));
  362. }
  363. }
  364. lfs_file_read(&lfs, &file, buffer, CHUNKSIZE) => 0;
  365. lfs_file_close(&lfs, &file) => 0;
  366. lfs_unmount(&lfs) => 0;
  367. '''
  368. define = [
  369. # append (O(n))
  370. {MODE='LFS_O_APPEND', SIZE=[32, 0, 7, 2049], CHUNKSIZE=[31, 16, 65]},
  371. # truncate (O(n^2))
  372. {MODE='LFS_O_TRUNC', SIZE=[32, 0, 7, 200], CHUNKSIZE=[31, 16, 65]},
  373. # rewrite (O(n^2))
  374. {MODE=0, SIZE=[32, 0, 7, 200], CHUNKSIZE=[31, 16, 65]},
  375. ]
  376. reentrant = true
  377. [[case]] # many files
  378. code = '''
  379. lfs_format(&lfs, &cfg) => 0;
  380. // create N files of 7 bytes
  381. lfs_mount(&lfs, &cfg) => 0;
  382. for (int i = 0; i < N; i++) {
  383. sprintf(path, "file_%03d", i);
  384. lfs_file_open(&lfs, &file, path,
  385. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  386. char wbuffer[1024];
  387. size = 7;
  388. snprintf(wbuffer, size, "Hi %03d", i);
  389. lfs_file_write(&lfs, &file, wbuffer, size) => size;
  390. lfs_file_close(&lfs, &file) => 0;
  391. char rbuffer[1024];
  392. lfs_file_open(&lfs, &file, path, LFS_O_RDONLY) => 0;
  393. lfs_file_read(&lfs, &file, rbuffer, size) => size;
  394. assert(strcmp(rbuffer, wbuffer) == 0);
  395. lfs_file_close(&lfs, &file) => 0;
  396. }
  397. lfs_unmount(&lfs) => 0;
  398. '''
  399. define.N = 300
  400. [[case]] # many files with power cycle
  401. code = '''
  402. lfs_format(&lfs, &cfg) => 0;
  403. // create N files of 7 bytes
  404. lfs_mount(&lfs, &cfg) => 0;
  405. for (int i = 0; i < N; i++) {
  406. sprintf(path, "file_%03d", i);
  407. lfs_file_open(&lfs, &file, path,
  408. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  409. char wbuffer[1024];
  410. size = 7;
  411. snprintf(wbuffer, size, "Hi %03d", i);
  412. lfs_file_write(&lfs, &file, wbuffer, size) => size;
  413. lfs_file_close(&lfs, &file) => 0;
  414. lfs_unmount(&lfs) => 0;
  415. char rbuffer[1024];
  416. lfs_mount(&lfs, &cfg) => 0;
  417. lfs_file_open(&lfs, &file, path, LFS_O_RDONLY) => 0;
  418. lfs_file_read(&lfs, &file, rbuffer, size) => size;
  419. assert(strcmp(rbuffer, wbuffer) == 0);
  420. lfs_file_close(&lfs, &file) => 0;
  421. }
  422. lfs_unmount(&lfs) => 0;
  423. '''
  424. define.N = 300
  425. [[case]] # many files with power loss
  426. code = '''
  427. err = lfs_mount(&lfs, &cfg);
  428. if (err) {
  429. lfs_format(&lfs, &cfg) => 0;
  430. lfs_mount(&lfs, &cfg) => 0;
  431. }
  432. // create N files of 7 bytes
  433. for (int i = 0; i < N; i++) {
  434. sprintf(path, "file_%03d", i);
  435. err = lfs_file_open(&lfs, &file, path, LFS_O_WRONLY | LFS_O_CREAT);
  436. char wbuffer[1024];
  437. size = 7;
  438. snprintf(wbuffer, size, "Hi %03d", i);
  439. if ((lfs_size_t)lfs_file_size(&lfs, &file) != size) {
  440. lfs_file_write(&lfs, &file, wbuffer, size) => size;
  441. }
  442. lfs_file_close(&lfs, &file) => 0;
  443. char rbuffer[1024];
  444. lfs_file_open(&lfs, &file, path, LFS_O_RDONLY) => 0;
  445. lfs_file_read(&lfs, &file, rbuffer, size) => size;
  446. assert(strcmp(rbuffer, wbuffer) == 0);
  447. lfs_file_close(&lfs, &file) => 0;
  448. }
  449. lfs_unmount(&lfs) => 0;
  450. '''
  451. define.N = 300
  452. reentrant = true