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