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