@@ -137,6 +137,130 @@ code = '''
137137 lfs_unmount(&lfs) => 0;
138138'''
139139
140+ # boundary seek and reads
141+ [cases .test_seek_boundary_read ]
142+ defines.COUNT = 132
143+ code = '''
144+ lfs_t lfs;
145+ lfs_format(&lfs, cfg) => 0;
146+ lfs_mount(&lfs, cfg) => 0;
147+ lfs_file_t file;
148+ lfs_file_open(&lfs, &file, "kitty",
149+ LFS_O_WRONLY | LFS_O_CREAT | LFS_O_APPEND) => 0;
150+ size_t size = strlen("kittycatcat");
151+ uint8_t buffer[1024];
152+ memcpy(buffer, "kittycatcat", size);
153+ for (int j = 0; j < COUNT; j++) {
154+ lfs_file_write(&lfs, &file, buffer, size);
155+ }
156+ lfs_file_close(&lfs, &file) => 0;
157+ lfs_unmount(&lfs) => 0;
158+
159+ lfs_mount(&lfs, cfg) => 0;
160+ lfs_file_open(&lfs, &file, "kitty", LFS_O_RDONLY) => 0;
161+
162+ size = strlen("kittycatcat");
163+ const lfs_soff_t offsets[] = {
164+ 512,
165+ 1024-4,
166+ 512+1,
167+ 1024-4+1,
168+ 512-1,
169+ 1024-4-1,
170+
171+ 512-strlen("kittycatcat"),
172+ 1024-4-strlen("kittycatcat"),
173+ 512-strlen("kittycatcat")+1,
174+ 1024-4-strlen("kittycatcat")+1,
175+ 512-strlen("kittycatcat")-1,
176+ 1024-4-strlen("kittycatcat")-1,
177+
178+ strlen("kittycatcat")*(COUNT-2)-1,
179+ };
180+
181+ for (unsigned i = 0; i < sizeof(offsets) / sizeof(offsets[0]); i++) {
182+ lfs_soff_t off = offsets[i];
183+ // read @ offset
184+ lfs_file_seek(&lfs, &file, off, LFS_SEEK_SET) => off;
185+ lfs_file_read(&lfs, &file, buffer, size) => size;
186+ memcmp(buffer,
187+ &"kittycatcatkittycatcat"[off % strlen("kittycatcat")],
188+ size) => 0;
189+ // read after
190+ lfs_file_seek(&lfs, &file, off+strlen("kittycatcat")+1, LFS_SEEK_SET)
191+ => off+strlen("kittycatcat")+1;
192+ lfs_file_read(&lfs, &file, buffer, size) => size;
193+ memcmp(buffer,
194+ &"kittycatcatkittycatcat"[(off+1) % strlen("kittycatcat")],
195+ size) => 0;
196+ // read before
197+ lfs_file_seek(&lfs, &file, off-strlen("kittycatcat")-1, LFS_SEEK_SET)
198+ => off-strlen("kittycatcat")-1;
199+ lfs_file_read(&lfs, &file, buffer, size) => size;
200+ memcmp(buffer,
201+ &"kittycatcatkittycatcat"[(off-1) % strlen("kittycatcat")],
202+ size) => 0;
203+
204+ // read @ 0
205+ lfs_file_seek(&lfs, &file, 0, LFS_SEEK_SET) => 0;
206+ lfs_file_read(&lfs, &file, buffer, size) => size;
207+ memcmp(buffer, "kittycatcat", size) => 0;
208+
209+ // read @ offset
210+ lfs_file_seek(&lfs, &file, off, LFS_SEEK_SET) => off;
211+ lfs_file_read(&lfs, &file, buffer, size) => size;
212+ memcmp(buffer,
213+ &"kittycatcatkittycatcat"[off % strlen("kittycatcat")],
214+ size) => 0;
215+ // read after
216+ lfs_file_seek(&lfs, &file, off+strlen("kittycatcat")+1, LFS_SEEK_SET)
217+ => off+strlen("kittycatcat")+1;
218+ lfs_file_read(&lfs, &file, buffer, size) => size;
219+ memcmp(buffer,
220+ &"kittycatcatkittycatcat"[(off+1) % strlen("kittycatcat")],
221+ size) => 0;
222+ // read before
223+ lfs_file_seek(&lfs, &file, off-strlen("kittycatcat")-1, LFS_SEEK_SET)
224+ => off-strlen("kittycatcat")-1;
225+ lfs_file_read(&lfs, &file, buffer, size) => size;
226+ memcmp(buffer,
227+ &"kittycatcatkittycatcat"[(off-1) % strlen("kittycatcat")],
228+ size) => 0;
229+
230+ // sync
231+ lfs_file_sync(&lfs, &file) => 0;
232+
233+ // read @ 0
234+ lfs_file_seek(&lfs, &file, 0, LFS_SEEK_SET) => 0;
235+ lfs_file_read(&lfs, &file, buffer, size) => size;
236+ memcmp(buffer, "kittycatcat", size) => 0;
237+
238+ // read @ offset
239+ lfs_file_seek(&lfs, &file, off, LFS_SEEK_SET) => off;
240+ lfs_file_read(&lfs, &file, buffer, size) => size;
241+ memcmp(buffer,
242+ &"kittycatcatkittycatcat"[off % strlen("kittycatcat")],
243+ size) => 0;
244+ // read after
245+ lfs_file_seek(&lfs, &file, off+strlen("kittycatcat")+1, LFS_SEEK_SET)
246+ => off+strlen("kittycatcat")+1;
247+ lfs_file_read(&lfs, &file, buffer, size) => size;
248+ memcmp(buffer,
249+ &"kittycatcatkittycatcat"[(off+1) % strlen("kittycatcat")],
250+ size) => 0;
251+ // read before
252+ lfs_file_seek(&lfs, &file, off-strlen("kittycatcat")-1, LFS_SEEK_SET)
253+ => off-strlen("kittycatcat")-1;
254+ lfs_file_read(&lfs, &file, buffer, size) => size;
255+ memcmp(buffer,
256+ &"kittycatcatkittycatcat"[(off-1) % strlen("kittycatcat")],
257+ size) => 0;
258+ }
259+
260+ lfs_file_close(&lfs, &file) => 0;
261+ lfs_unmount(&lfs) => 0;
262+ '''
263+
140264# boundary seek and writes
141265[cases .test_seek_boundary_write ]
142266defines.COUNT = 132
@@ -160,31 +284,54 @@ code = '''
160284 lfs_file_open(&lfs, &file, "kitty", LFS_O_RDWR) => 0;
161285
162286 size = strlen("hedgehoghog");
163- const lfs_soff_t offsets[] = {512, 1020, 513, 1021, 511, 1019, 1441};
287+ const lfs_soff_t offsets[] = {
288+ 512,
289+ 1024-4,
290+ 512+1,
291+ 1024-4+1,
292+ 512-1,
293+ 1024-4-1,
294+
295+ 512-strlen("kittycatcat"),
296+ 1024-4-strlen("kittycatcat"),
297+ 512-strlen("kittycatcat")+1,
298+ 1024-4-strlen("kittycatcat")+1,
299+ 512-strlen("kittycatcat")-1,
300+ 1024-4-strlen("kittycatcat")-1,
301+
302+ strlen("kittycatcat")*(COUNT-2)-1,
303+ };
164304
165305 for (unsigned i = 0; i < sizeof(offsets) / sizeof(offsets[0]); i++) {
166306 lfs_soff_t off = offsets[i];
307+ // write @ offset
167308 memcpy(buffer, "hedgehoghog", size);
168309 lfs_file_seek(&lfs, &file, off, LFS_SEEK_SET) => off;
169310 lfs_file_write(&lfs, &file, buffer, size) => size;
311+
312+ // read @ offset
170313 lfs_file_seek(&lfs, &file, off, LFS_SEEK_SET) => off;
171314 lfs_file_read(&lfs, &file, buffer, size) => size;
172315 memcmp(buffer, "hedgehoghog", size) => 0;
173316
317+ // read @ 0
174318 lfs_file_seek(&lfs, &file, 0, LFS_SEEK_SET) => 0;
175319 lfs_file_read(&lfs, &file, buffer, size) => size;
176320 memcmp(buffer, "kittycatcat", size) => 0;
177321
322+ // read @ offset
178323 lfs_file_seek(&lfs, &file, off, LFS_SEEK_SET) => off;
179324 lfs_file_read(&lfs, &file, buffer, size) => size;
180325 memcmp(buffer, "hedgehoghog", size) => 0;
181326
182327 lfs_file_sync(&lfs, &file) => 0;
183328
329+ // read @ 0
184330 lfs_file_seek(&lfs, &file, 0, LFS_SEEK_SET) => 0;
185331 lfs_file_read(&lfs, &file, buffer, size) => size;
186332 memcmp(buffer, "kittycatcat", size) => 0;
187333
334+ // read @ offset
188335 lfs_file_seek(&lfs, &file, off, LFS_SEEK_SET) => off;
189336 lfs_file_read(&lfs, &file, buffer, size) => size;
190337 memcmp(buffer, "hedgehoghog", size) => 0;
0 commit comments