-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
RT_read_seek_tests.spin2
388 lines (312 loc) · 14.9 KB
/
RT_read_seek_tests.spin2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
'' =================================================================================================
''
'' File....... RT_read_seek_tests.spin2
'' Purpose.... This object exercises the read and seek behaviors of the flash filesystem
'' Author..... Stephen M Moraco
'' -- see below for terms of use
'' Started.... AUG 2023
'' Updated.... 19 DEC 2023
''
'' =================================================================================================
CON
_CLKFREQ = 320_000_000
{
' debug via serial to RPi (using RPi gateway pins)
' USES LED1 (56) and LED2 (57) pins
DEBUG_PIN_TX = 57 ' GRY GPIO 10
DEBUG_PIN_RX = 56 ' WHT GPIO 8 (gnd is BLK GPIO 6)
DEBUG_WINDOWS_OFF = -1 ' no debug windows showing
DEBUG_BAUD = 2_000_000 ' comms at 2Mbit
'}
OBJ
flash : "flash_fs"
utils : "RT_utilities"
DAT
testfile BYTE "seekLongs.bin", 0
testfile2 BYTE "seekLongs2blk.bin", 0
testfile3 BYTE "seekLongs3blk.bin", 0
testfile4 BYTE "seekLongs3blkFull.bin", 0
pBlock LONG 0
expectedFileSize LONG 0
status LONG 0
handle LONG 0
longValue LONG 0
byteOffset LONG 0
fileSizeBlocks LONG 0
endPosition LONG 0
PUB go() | nbrLongs
status := flash.format() ' Comment out this line to not erase all files
if status <> flash.SUCCESS
utils.showError(@"format()", status)
return
status := flash.mount()
if status <> flash.SUCCESS
utils.showError(@"mount()", status)
return
utils.ShowStats() ' should have empty filesystem
utils.showFiles()
utils.showChipAndDriverVersion()
utils.startTest(@"BAD: Read when file doesn't exist")
handle := flash.open(@testfile,"r")
utils.evaluateResultNegError(handle, flash.E_FILE_NOT_FOUND)
' fill head block with longs (only block file)
utils.startTestGroup(@"Head block only - filled with longs")
nbrLongs := flash.LONGS_IN_HEAD_BLOCK
writeAddressedLongs(@testfile, nbrLongs, 0, 0)
verifyAddressedLongs(@testfile, nbrLongs)
' fill head block + 2 longs with longs (2 block file)
utils.startTestGroup(@"Head block + body block - head full, body has 2 longs")
nbrLongs := flash.LONGS_IN_HEAD_BLOCK + 2
writeAddressedLongs(@testfile2, nbrLongs, 1, 1)
verifyAddressedLongs(@testfile2, nbrLongs)
' fill head block + body block + 2 longs with longs (3 block file)
utils.startTestGroup(@"Head block + 2x body block - head full, body full, 2nd body has 2 longs")
nbrLongs := flash.LONGS_IN_HEAD_BLOCK + flash.LONGS_IN_BODY_BLOCK + 2
writeAddressedLongs(@testfile3, nbrLongs, 2, 3)
verifyAddressedLongs(@testfile3, nbrLongs)
' fill head block + 2x body block with longs (full 3 block file)
utils.startTestGroup(@"Head block + 2x body block - all blocks full")
nbrLongs := flash.LONGS_IN_HEAD_BLOCK + (flash.LONGS_IN_BODY_BLOCK * 2)
writeAddressedLongs(@testfile4, nbrLongs, 3, 6)
verifyAddressedLongs(@testfile4, nbrLongs)
utils.startTestGroup(@"Seek position-relative tests")
verifyRelativeSeekLongs(@testfile4, nbrLongs)
utils.startTestGroup(@"New file_size for handle and max seek tests")
verifyMaxSeek(@testfile4)
utils.showFiles()
'utils.dumpFileHeads()
utils.ShowTestEndCounts()
debug("* Test Complete")
pri writeAddressedLongs(pFilename, count, startingFileCount, startingBlockCount) | dumpSize
' ----------------------------------
' TEST
' open file for read
' ensure returns error (doesn't exist)
' open file for write
' ensure returns SUCCESS
utils.startTest(@"Open File for write")
handle := flash.open(pFilename,"w")
utils.evaluateResultNegError(handle, flash.SUCCESS)
' attempt seek and verify that seek on write-only file returns error
utils.startTest(@"BAD: seek on write-only file")
utils.setCheckCountPerTest(2)
endPosition := flash.seek(handle, 0, flash.SK_FILE_START)
utils.evaluateSubValue(endPosition, @"seek()", flash.E_FILE_MODE)
status := flash.error()
utils.evaluateSubStatus(status, @"seek()", flash.E_FILE_MODE)
' write a fixed length file of longs where value of LONG is offset into file
expectedFileSize := 0
utils.startTest(@"Write N of longs")
utils.setCheckCountPerTest(1)
repeat longValue from 0 to count - 1
status := flash.wr_long(handle, longValue)
expectedFileSize += 4
utils.evaluateSubStatus(status, @"wr_long()", flash.SUCCESS)
utils.startTest(@"ensure no errors on writes")
utils.evaluateResultNegError(status, flash.SUCCESS)
' dump commit chain
utils.showPendingCommitChain(handle)
' close file
utils.startTest(@"Close written file")
status := flash.close(handle)
utils.evaluateResultNegError(status, flash.SUCCESS)
utils.showFileDetails(pFilename)
dumpSize := expectedFileSize
if count > flash.LONGS_IN_HEAD_BLOCK + flash.LONGS_IN_BODY_BLOCK
dumpSize -= (flash.LONGS_IN_HEAD_BLOCK * 4) + (flash.LONGS_IN_BODY_BLOCK * 4)
elseif count > flash.LONGS_IN_HEAD_BLOCK
dumpSize -= flash.LONGS_IN_HEAD_BLOCK * 4
' show whole block if head block
if expectedFileSize ==flash.LONGS_IN_HEAD_BLOCK * 4
dumpSize := 4096
' get filesystem stats and verify against expectation
fileSizeBlocks := utils.blockCountForFileSize(expectedFileSize)
utils.startTest(@"Ensure expected file system changes")
utils.evaluateFSStats(@"post file write", startingFileCount+1, startingBlockCount+fileSizeBlocks)
' get single file stats and verify against expectation
utils.startTest(@"Ensure expected file stats")
utils.evaluateFileStats(pFilename, fileSizeBlocks, expectedFileSize)
{
' AUGH dump head block to see if content is correct
pBlock := flash.TEST_getTail4kBlock(pFilename)
' reuse status for a minute
status := dumpSize & $FFFF_FFF0 ' ensure muiple of 16 bytes (if in head show name)
utils.dbgMemDump(@"Longs file Tail block", pBlock, status)
status := flash.SUCCESS ' clear our temp use
'}
pri verifyAddressedLongs(pFilename, count) | relativeOfs
' open file for read
utils.startTest(@"Open File for read")
utils.setCheckCountPerTest(2)
handle := flash.open(pFilename,"r")
utils.evaluateSubValue(handle, @"Open()", 0)
status := flash.error()
utils.evaluateSubStatus(handle, @"Open()", flash.SUCCESS)
' seek to various locations and read longs validating for correct value
utils.startTest(@"read 1st LONG")
utils.setCheckCountPerTest(2)
endPosition := flash.seek(handle, 0, flash.SK_FILE_START)
utils.evaluateSubValue(endPosition, @"seek()", 0)
status := flash.error()
if status == flash.SUCCESS
longValue := flash.rd_long(handle)
status := flash.error()
utils.evaluateSubValue(longValue, @"rd_long", 0)
utils.startTest(@"ensure no errors on read 1st")
utils.evaluateResultNegError(status, flash.SUCCESS)
utils.startTest(@"read 20 longs randomly ensure offset is value of LONG")
utils.setCheckCountPerTest(2)
repeat 20
byteOffset := (GETRND() +// count) * 4
'debug(" Offset: ", udec_(byteOffset), " (", udec_(byteOffset / 4), " of ", udec_(count), ")")
endPosition := flash.seek(handle, byteOffset, flash.SK_FILE_START)
utils.evaluateSubValue(endPosition, @"seek()", byteOffset)
status := flash.error()
if status <> flash.SUCCESS
quit
longValue := flash.rd_long(handle)
status := flash.error()
if status <> flash.SUCCESS
quit
utils.evaluateSubValue(longValue, @"rd_long", byteOffset / 4)
utils.startTest(@"ensure no errors on read mid")
utils.evaluateResultNegError(status, flash.SUCCESS)
utils.startTest(@"read last LONG")
utils.setCheckCountPerTest(2)
endPosition := flash.seek(handle, (count - 1) * 4, flash.SK_FILE_START)
utils.evaluateSubValue(endPosition, @"seek()", (count - 1) * 4)
status := flash.error()
if status == flash.SUCCESS
longValue := flash.rd_long(handle)
status := flash.error()
utils.evaluateSubValue(longValue, @"rd_long", count - 1)
utils.startTest(@"ensure no errors on read last")
utils.evaluateResultNegError(status, flash.SUCCESS)
' seek past end of file to verify seek returns error
utils.startTest(@"BAD: see beyond end of file")
utils.setCheckCountPerTest(2)
endPosition := flash.seek(handle, (count + 2) * 4, flash.SK_FILE_START)
utils.evaluateSubValue(endPosition, @"seek()", flash.E_FILE_SEEK)
status := flash.error()
utils.evaluateSubStatus(status, @"seek()", flash.E_FILE_SEEK)
' close file
utils.startTest(@"Close file we were reading")
status := flash.close(handle)
utils.evaluateResultNegError(status, flash.SUCCESS)
pri verifyRelativeSeekLongs(pFilename, longsInFile) | priorByteOfs, newByteOfs, relativeOfs
utils.startTest(@"Open File for read")
utils.setCheckCountPerTest(2)
handle := flash.open(pFilename,"r")
utils.evaluateSubValue(handle, @"open()", 0)
status := flash.error()
utils.evaluateSubStatus(status, @"open()", flash.SUCCESS)
' seek to various locations and read longs validating for correct value
utils.startTest(@"read 1st LONG")
utils.setCheckCountPerTest(2)
endPosition := flash.seek(handle, 0, flash.SK_FILE_START)
utils.evaluateSubValue(endPosition, @"seek()", 0)
status := flash.error()
if status == flash.SUCCESS
longValue := flash.rd_long(handle)
status := flash.error()
utils.evaluateSubValue(longValue, @"rd_long", 0)
utils.startTest(@"ensure no errors on read rel 1st")
utils.evaluateResultNegError(status, flash.SUCCESS)
utils.startTest(@"initial seek before reads")
utils.setCheckCountPerTest(2)
priorByteOfs := (GETRND() +// longsInFile) * 4
'debug(" filePos: ", sdec_(priorByteOfs))
endPosition := flash.seek(handle, priorByteOfs, flash.SK_FILE_START)
utils.evaluateSubValue(endPosition, @"seek()", priorByteOfs)
status := flash.error()
utils.evaluateSubStatus(status, @"seek()", flash.SUCCESS)
utils.startTest(@"read 10 longs seeking relative to current location")
utils.setCheckCountPerTest(1)
repeat 10
newByteOfs := (GETRND() +// longsInFile) * 4
relativeOfs := newByteOfs - priorByteOfs
'debug(" rndOffset: ", udec_(newByteOfs), " [relOffset: ", sdec_(relativeOfs), " fm prior: ", udec_(priorByteOfs), "] (", udec_(newByteOfs / 4), " of ", udec_(longsInFile), ")")
endPosition := flash.seek(handle, relativeOfs, flash.SK_CURRENT_POSN)
status := flash.error()
if status <> flash.SUCCESS
debug("seek() returned errorcode!")
quit
longValue := flash.rd_long(handle)
status := flash.error()
if status <> flash.SUCCESS
debug("error() after seek() returned errorcode!")
quit
utils.evaluateSubValue(longValue, @"rd_long", newByteOfs / 4)
priorByteOfs := newByteOfs + 4
utils.startTest(@"ensure no errors on read rel mid")
utils.evaluateResultNegError(status, flash.SUCCESS)
utils.startTest(@"read last LONG")
utils.setCheckCountPerTest(2)
endPosition := flash.seek(handle, (longsInFile - 1) * 4, flash.SK_FILE_START)
utils.evaluateSubValue(endPosition, @"seek()", (longsInFile - 1) * 4)
status := flash.error()
if status == flash.SUCCESS
longValue := flash.rd_long(handle)
status := flash.error()
utils.evaluateSubValue(longValue, @"rd_long", longsInFile - 1)
utils.startTest(@"ensure no errors on read rel last")
utils.evaluateResultNegError(status, flash.SUCCESS)
' seek past end of file to verify seek returns error
utils.startTest(@"BAD: seek beyond end of file")
utils.setCheckCountPerTest(1)
endPosition := flash.seek(handle, (longsInFile + 2) * 4, flash.SK_FILE_START)
utils.evaluateSubValue(endPosition, @"seek()", flash.E_FILE_SEEK)
status := flash.error()
utils.evaluateSubStatus(status, @"seek()", flash.E_FILE_SEEK)
' close file
utils.startTest(@"Close file we were reading")
status := flash.close(handle)
utils.evaluateResultNegError(status, flash.SUCCESS)
pri verifyMaxSeek(pFilename) | lenBytes, hLenBytes
utils.startTest(@"Open File for read")
utils.setCheckCountPerTest(2)
handle := flash.open(pFilename,"r")
status := flash.error()
utils.evaluateSubValue(handle, @"open()", 0)
utils.evaluateSubStatus(status, @"open()", flash.SUCCESS)
utils.startTest(@"Determine size of file (by handle) in bytes ")
hLenBytes := flash.file_size_for_handle(handle)
status := flash.error()
utils.evaluateResultNegError(status, flash.SUCCESS)
utils.startTest(@"Determine size of file (by name) in bytes")
lenBytes := flash.file_size(pFilename)
status := flash.error()
utils.evaluateResultNegError(handle, flash.SUCCESS)
utils.startTest(@"Ensure the sizes match")
utils.evaluateResultNegError(hLenBytes, lenBytes)
utils.startTest(@"Seek to end of file returning position and ckeck length returned is file size")
endPosition := flash.seek(handle, POSX, flash.SK_FILE_START)
status := flash.error()
utils.evaluateSubValue(endPosition, @"seek()", lenBytes)
utils.evaluateSubStatus(status, @"seek()", flash.SUCCESS)
' close file
utils.startTest(@"Close file we were reading")
status := flash.close(handle)
utils.evaluateResultNegError(status, flash.SUCCESS)
con { license }
{{
=================================================================================================
Terms of Use: MIT License
Copyright (c) 2023 Iron Sheep Productions, LLC
Permission is hereby granted, free of charge, to any person obtaining a copy of this
software and associated documentation files (the "Software"), to deal in the Software
without restriction, including without limitation the rights to use, copy, modify,
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be included in all copies
or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
=================================================================================================
}}