-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
RT_read_write_block_tests.spin2
217 lines (171 loc) · 8.1 KB
/
RT_read_write_block_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
'' =================================================================================================
''
'' File....... RT_read_write_block_tests.spin2
'' Purpose.... This object exercises the multi-byte reads/writes (records or blocks) 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"
CON
RECORD_LEN = 88 ' just for fun, tiny but even number of longs
RECORD_DATA_LEN = RECORD_LEN - 12
DAT
testfile BYTE "rwblocks.bin", 0
testfile2 BYTE "rw2blocks.bin", 0
testfile3 BYTE "rw3blocks.bin", 0
record
recordMARK LONG $beadfeed ' visual start of record marker
recordID LONG 0
recordData LONG 0[RECORD_DATA_LEN/4]
recordCRC LONG 0
recordEnd
writeLength LONG 0
PUB go() | status, handle, testValue, expectedValue, pFilename, bytePattern
status := flash.format() ' Comment out this line to not erase all files
if status < 0
utils.showError(@"format()", status)
return
status := flash.mount()
if status < 0
utils.showError(@"mount()", status)
return
utils.ShowStats() ' should have empty filesystem
utils.showFiles()
utils.showChipAndDriverVersion()
testWriteRecords(@testfile, 10, 1, 0)
testWriteRecords(@testfile2, 45, 2, 1) ' tail last record in 2nd block
testWriteRecords(@testfile3, 92, 3, 3) ' tail of last record in 3rd block
utils.ShowTestEndCounts()
debug("* Test Complete")
pri testWriteRecords(pFilename, recordCount, fileCount, blocksAllocated) | status, handle, testValue, expectedValue, recordNbr, wrLength, rdLength, pBlock, expectedFileSize, expectedFileBlocks, calcCRC, sizeUnused, allocatedFileSize
' ----------------------------------
' TEST
' open file for write
' ensure returns SUCCESS
utils.startTest(@"Open File for write")
handle := flash.open(pFilename,"w")
utils.evaluateResultNegError(handle, flash.SUCCESS)
utils.startTest(@"Write Records")
utils.setCheckCountPerTest(2)
status := flash.SUCCESS
repeat recordNbr from 1 to recordCount
testValue := $40 + recordNbr ' A, B, C, etc.
recordId := recordNbr
bytefill(@recordData, testValue, RECORD_DATA_LEN)
recordCRC := utils.record_crc(@record, RECORD_LEN)
'debug("* write rcd #", udec_(recordNbr), " of 10")
'utils.dbgMemDump(@"Record", @record, RECORD_LEN)
writeLength := flash.write(handle, @record, RECORD_LEN)
utils.evaluateSubValue(writeLength, @"write()", RECORD_LEN)
status := flash.error()
utils.evaluateSubStatus(status, @"write()", flash.SUCCESS)
if status <> flash.SUCCESS
quit ' abort on first failure
utils.startTest(@"ensure no errors on Record 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)
{
' AUGH dump head block to see if content is correct
pBlock := flash.TEST_getHead4kBlock(pFilename)
' reuse status for a minute
status := ((4 * RECORD_LEN + 64) + 32) & $FFFF_FFF0 ' ensure multiple of 16 bytes
utils.dbgMemDump(@"Records file Head block", pBlock, status)
status := flash.SUCCESS ' clear our temp use
'}
expectedFileSize := recordCount * RECORD_LEN
expectedFileBlocks := utils.blockCountForFileSize(expectedFileSize)
' get filesystem stats and verify against expectation
utils.startTest(@"Ensure expected file system changes")
utils.evaluateFSStats(@"post file write", fileCount, expectedFileBlocks + blocksAllocated)
' get single file stats and verify against expectation
utils.startTest(@"Ensure expected file stats")
utils.evaluateFileStats(pFilename, expectedFileBlocks, expectedFileSize)
utils.startTest(@"Ensure expected unused bytes stats")
sizeUnused := flash.file_size_unused(pFilename)
expectedFileSize := recordCount * RECORD_LEN
allocatedFileSize := flash.BYTES_IN_HEAD_BLOCK
if expectedFileBlocks > 2
allocatedFileSize += (flash.BYTES_IN_BODY_BLOCK * 2)
elseif expectedFileBlocks > 1
allocatedFileSize += flash.BYTES_IN_BODY_BLOCK
utils.evaluateSingleValue(sizeUnused, @"file_size_unused()", allocatedFileSize - expectedFileSize)
utils.startTest(@"Ensure no error on size unused call")
status := flash.error()
utils.evaluateResultNegError(status, flash.SUCCESS)
'debug("* holding...")
'repeat ' hold here
' open file for read
utils.startTest(@"Open File for read")
handle := flash.open(pFilename,"r")
utils.evaluateResultNegError(handle, flash.SUCCESS)
' seek to various locations and read longs validating for correct value
utils.startTest(@"read expected RECORDs")
utils.setCheckCountPerTest(3)
repeat recordNbr from 1 to recordCount
rdLength := flash.read(handle, @record, RECORD_LEN)
if rdLength <> RECORD_LEN
status := flash.error()
quit
' ensure length is same as expected
utils.evaluateSubValue(rdLength, @"read()", RECORD_LEN)
' ensure record ID is same as expected
utils.evaluateSubValue(recordId, @"recordId", recordNbr)
' ensure record CRC is same as expected
calcCRC := utils.record_crc(@record, RECORD_LEN)
utils.evaluateSubValue(calcCRC, @"recordCRC", recordCRC)
utils.startTest(@"ensure no errors on reads")
utils.evaluateResultNegError(status, flash.SUCCESS)
' read past end of file to verify read returns error
utils.startTest(@"BAD: read one more Record than written")
utils.setCheckCountPerTest(2)
rdLength := flash.read(handle, @record, RECORD_LEN)
utils.evaluateSubValue(rdLength, @"read()", 0)
status := flash.error()
utils.evaluateSubStatus(status, @"read()", flash.E_END_OF_FILE)
' close file
utils.startTest(@"Close read file")
status := flash.close(handle)
utils.evaluateResultNegError(status, flash.SUCCESS)
utils.showFiles()
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.
=================================================================================================
}}