-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
RT_utilities.spin2
817 lines (694 loc) · 34.3 KB
/
RT_utilities.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
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
'' =================================================================================================
''
'' File....... RT_utilites.spin2
'' Purpose.... This object provides commonly used regression test parts to each test object
'' Author..... Stephen M Moraco
'' -- see below for terms of use
'' Started.... AUG 2023
'' Updated.... 20 DEC 2023
''
'' =================================================================================================
CON
MAX_FILES_OPEN = 2 ' ensure is same default as FLASH F/S!!!
TEST_SIGNATURE = $12345678
OBJ
flash : "flash_fs" | MAX_FILES_OPEN = MAX_FILES_OPEN
VAR { test stats vars }
LONG numberTests[8]
LONG subTestPer[8]
LONG passCount[8]
LONG failCount[8]
LONG passCountSub[8]
LONG failCountSub[8]
LONG varSignature[8]
BYTE versionString[10] ' "flash_fs v"
BYTE vDigits[5+1] ' "x.x.x", 0
byte filename[128]
pub null()
'' This is not an application
'' (invoke format() or mount() to use the flash file system)
pri initIfNotAlready()
if varSignature[cogId()] <> TEST_SIGNATURE
numberTests[cogId()] := 0
subTestPer[cogId()] := 1
passCount[cogId()] := 0
failCount[cogId()] := 0
passCountSub[cogId()] := 0
failCountSub[cogId()] := 0
strcopy(@versionString, @"flash_fs vx.x.x",15)
varSignature[cogId()] := TEST_SIGNATURE
debug("* init VAR")
flash.TEST_enableRTdebug() ' turn on extra debug output
pub showChipAndDriverVersion() | snHi, snLo, version, hundreds, tens, units
debug(" ")
debug("* Environment: Chip S/N and Driver Version")
snHi, snLo := flash.serial_number()
debug(" CHIP Serial Number: ", uhex_long_(snHi), "-", uhex_long_(snLo))
version := flash.version()
' brute force... (someone didn't import a string formatter, I wonder who that was?)
hundreds := version / 100
BYTE[@vDigits][0] := "0" + hundreds
tens := (version - (hundreds * 100)) / 10
BYTE[@vDigits][2] := "0" + tens
units := version - (hundreds * 100) - (tens * 10)
BYTE[@vDigits][4] := "0" + units
debug (" Driver: ", zstr_(@versionString))
pub startTestGroup(pDesciption)
' show test-group heading
initIfNotAlready()
showSubTestResults()
debug(" ") ' blank line
debug(" ") ' blank line
debug(" ------------------------------------------------------------") ' blank line
debug("* Test Group: ", zstr_(pDesciption))
pub startTest(pDesciption) | ecGot, ecExpected, passScaled, failScaled, total
' if prior sub tests show sub tests results
initIfNotAlready()
showSubTestResults()
numberTests[cogId()]++
' now show new test info
debug(" ") ' blank line
debug("* Test #", udec_(numberTests[cogId()]), ": ", zstr_(pDesciption))
pub showSubTestResults() | passScaled, failScaled, total, pPassFail
if failCountSub[cogId()] <> 0 or passCountSub[cogId()] <> 0
total := (passCountSub[cogId()] + failCountSub[cogId()]) / subTestPer[cogId()]
passScaled := passCountSub[cogId()] / subTestPer[cogId()]
failScaled := total - passScaled ' >= 0 ? total - passScaled : 0
debug(" Sub-Test Results: count=", udec_(total), ", Pass: ", udec_(passScaled), ", Fail: ", udec_(failScaled))
if failScaled < 0
debug(" Sub-Test (", udec(passCountSub[cogId()], failCountSub[cogId()]), ")")
if failCountSub[cogId()] <> 0
failCount[cogId()]++
else
passCount[cogId()]++
pPassFail := failCountSub[cogId()] <> 0 ? @"FAIL" : @"pass"
debug(" -> ", zstr_(pPassFail))
passCountSub[cogId()] := 0
failCountSub[cogId()] := 0
pub ShowTestEndCounts() | pMsg
' show summary of all tests
debug(" ") ' blank line
debug("* ", udec_(numberTests[cogId()]), " Tests - Pass: ", udec_(passCount[cogId()]), ", Fail: ", udec_(failCount[cogId()]))
if numberTests[cogId()] <> passCount[cogId()] + failCount[cogId()]
pMsg := (numberTests[cogId()] > passCount[cogId()] + failCount[cogId()]) ? @"missing" : @"extra"
debug("* BAD TEST COUNTS: ", udec_(numberTests[cogId()]), " <> ", udec_(passCount[cogId()] + failCount[cogId()]), " (", zstr_(pMsg), " ", udec_(abs(numberTests[cogId()] - (passCount[cogId()] + failCount[cogId()]))), " tests)")
pub ShowMultiCogTestEndCounts() | pMsg, totalTests, totalPasses, totalFails, cogIdx
' show summary of all tests
' gather totals
repeat 8 with cogIdx
totalTests += numberTests[cogIdx]
totalPasses += passCount[cogIdx]
totalFails += failCount[cogIdx]
' report totals
debug(" ") ' blank line
debug("* TOTALs ", udec_(totalTests), " Tests - Pass: ", udec_(totalPasses), ", Fail: ", udec_(totalFails))
if totalTests <> totalPasses + totalFails
pMsg := (totalTests > totalPasses + totalFails) ? @"missing" : @"extra"
debug("* TOTALs BAD TEST COUNTS: ", udec_(totalTests), " <> ", udec_(totalPasses + totalFails), " (", zstr_(pMsg), " ", udec_(abs(totalTests - (totalPasses + totalFails))), " tests)")
pub setCheckCountPerTest(countTests)
'' set the number of subtests per record/group
''
'' @param countTests - the number of checks per item tested
subTestPer[cogId()] := countTests
pub evaluateSubStatus(result, pMessage, expectedResult) | ecGot, ecExpected, bPassed, pPassFail
ecGot := flash.string_for_error(result)
ecExpected := flash.string_for_error(expectedResult)
bPassed := result == expectedResult
pPassFail := !bPassed ? @"Sub-FAIL" : @"pass"
ifnot bPassed
failCountSub[cogId()]++
else
passCountSub[cogId()]++
ifnot bPassed ' only shou result on failure
ifnot bPassed
debug(" Status: ", zstr_(ecGot), "(", sdec_(result), "), (expected ", zstr_(ecExpected), "(", sdec_(expectedResult), "))")
else
debug(" Status: ", zstr_(ecGot), "(", sdec_(result), ")")
debug(" -> ", zstr_(pPassFail))
pub evaluateSubValue(result, pMessage, expectedResult) | bPassed, pPassFail
bPassed := result == expectedResult
pPassFail := !bPassed ? @"Sub-FAIL" : @"pass"
ifnot bPassed
failCountSub[cogId()]++
else
passCountSub[cogId()]++
ifnot bPassed ' only shou result on failure
debug(" Sub-Test: ", zstr_(pMessage))
ifnot bPassed
debug(" Value: ", uhex_long_(result), " (expected ", uhex_long_(expectedResult), ")")
else
debug(" Value: ", uhex_long_(result))
debug(" -> ", zstr_(pPassFail))
pub evaluateResultNegError(result, expectedResult) | ecGot, ecExpected, bPassed, pPassFail
bPassed := result == expectedResult
pPassFail := !bPassed ? @"FAIL" : @"pass"
if result > 0
ifnot bPassed
if expectedResult < 0
ecExpected := flash.string_for_error(expectedResult)
debug(" Result: ", sdec_(result), " (expected ", zstr_(ecExpected), ")")
else
debug(" Result: ", udec_(result), " (expected ", udec_(expectedResult), ")")
failCount[cogId()]++
else
debug(" Result: ", udec_(result))
passCount[cogId()]++
else
ecGot := flash.string_for_error(result)
ecExpected := flash.string_for_error(expectedResult)
ifnot bPassed
debug(" ECode: ", zstr_(ecGot), " (expected ", zstr_(ecExpected), ")")
failCount[cogId()]++
else
debug(" ECode: ", zstr_(ecGot))
passCount[cogId()]++
debug(" -> ", zstr_(pPassFail))
pub evaluateSingleValue(result, pMessage, expectedResult) | bPassed, pPassFail
bPassed := result == expectedResult
pPassFail := !bPassed ? @"FAIL" : @"pass"
ifnot bPassed
debug(" ", zstr_(pMessage), ": ", sdec_long_(result), " (expected ", sdec_long_(expectedResult), ")")
failCount[cogId()]++
else
debug(" ", zstr_(pMessage), ": ", sdec_long_(result))
passCount[cogId()]++
debug(" -> ", zstr_(pPassFail))
pub evaluateHandle(resultHandle, pMessage) | bPassed, pPassFail
bPassed := resultHandle >= 0
pPassFail := !bPassed ? @"FAIL" : @"pass"
ifnot bPassed
debug(" ", zstr_(pMessage), ": ", sdec_long_(resultHandle), " (expected >= 0)")
failCount[cogId()]++
else
debug(" ", zstr_(pMessage), ": ", sdec_long_(resultHandle))
passCount[cogId()]++
debug(" -> ", zstr_(pPassFail))
pub evaluateFSStats(pMessage, expectedFileCount, expectedBlocksUsed) | blocksUsed, blocksFree, fileCount, bPassed, pPassFail
'' Report on expected vs. actual filesystem stats
''
'' @param pMessage - intro message
'' @param expectedFileCount - count of files expected
'' @param expectedBlocksUsed - count of blocks used expected
' Local Variables:
' @local blocksUsed -
' @local blocksFree -
' @local fileCount -
debug("* ", zstr_(pMessage))
blocksUsed, blocksFree, fileCount := flash.stats()
debug(" # FileSystem: ", udec_(blocksUsed, blocksFree, fileCount))
bPassed := expectedFileCount == fileCount and expectedBlocksUsed == blocksUsed
if fileCount <> expectedFileCount
debug(" # files: ", udec_(fileCount), " (expected ", udec_(expectedFileCount), ")")
else
debug(" # files: ", udec_(fileCount))
if blocksUsed <> expectedBlocksUsed
debug(" # blocks used: ", udec_(blocksUsed), " (expected ", udec_(expectedBlocksUsed), ")")
else
debug(" # blocks used: ", udec_(blocksUsed))
pPassFail := !bPassed ? @"FAIL" : @"pass"
ifnot bPassed
failCount[cogId()]++
else
passCount[cogId()]++
debug(" -> ", zstr_(pPassFail))
pub evaluateFileStats(pfilename, expectedBlockCount, expectedBytesUsed) | bytesUsed, bytesFree, blockCount, bPassed, pPassFail
'' Report on expected vs. actual file stats
''
'' @param pfilename - name of file
'' @param expectedBlockCount - size in blocks expected
'' @param expectedBytesUsed - size in bytes expected
' Local Variables:
' @local bytesUsed -
' @local bytesFree -
' @local blockCount -
showFileChain(pFilename)
bytesUsed, bytesFree, blockCount := flash.TEST_count_file_bytes(pFilename)
if bytesUsed < 0
debug(" # Error: ", zstr_(flash.string_for_error(bytesUsed)))
bPassed := false
else
bPassed := expectedBlockCount == blockCount and expectedBytesUsed == bytesUsed
if blockCount <> expectedBlockCount
debug(" # blocks: ", udec_(blockCount), " (expected ", udec_(expectedBlockCount), ")")
else
debug(" # blocks: ", udec_(blockCount))
if bytesUsed <> expectedBytesUsed
debug(" # bytes used: ", udec_(bytesUsed), " (expected ", udec_(expectedBytesUsed), ")")
else
debug(" # bytes used: ", udec_(bytesUsed))
pPassFail := !bPassed ? @"FAIL" : @"pass"
ifnot bPassed
failCount[cogId()]++
else
passCount[cogId()]++
debug(" -> ", zstr_(pPassFail))
pub evaluateFileStatsRange(pfilename, expectedBlockCount, exptecedMinBytesUsed, expectedBytesUsed) | bytesUsed, bytesFree, blockCount, maxBytesUsed, bPassed, pPassFail
'' Report file stistics against expectation
''
'' @param pfilename - address of filename zstring
'' @param expectedBlockCount - expected size of file in blocks
'' @param exptecedMinBytesUsed - minimum size of file in bytes
'' @param expectedBytesUsed - expected size of file in bytes
' Local Variables:
' @local bytesUsed -
' @local bytesFree -
' @local blockCount -
' @local maxBytesUsed -
showFileChain(pFilename)
bytesUsed, bytesFree, blockCount := flash.TEST_count_file_bytes(pFilename)
maxBytesUsed := flash.BYTES_IN_HEAD_BLOCK
maxBytesUsed += (flash.BYTES_IN_BODY_BLOCK * (expectedBlockCount - 1))
if bytesUsed < 0
debug(" # Error: ", zstr_(flash.string_for_error(bytesUsed)))
bPassed := false
else
bPassed := expectedBlockCount == blockCount and bytesUsed >= exptecedMinBytesUsed and bytesUsed <= maxBytesUsed
if blockCount <> expectedBlockCount
debug(" # blocks: ", udec_(blockCount), " (expected ", udec_(expectedBlockCount), ")")
else
debug(" # blocks: ", udec_(blockCount))
if bytesUsed < exptecedMinBytesUsed or bytesUsed > maxBytesUsed
debug(" # bytes used: ", udec_(bytesUsed), " (expected ", udec_(expectedBytesUsed), " [", udec_(exptecedMinBytesUsed), "-", udec_(maxBytesUsed), "])")
else
debug(" # bytes used: ", udec_(bytesUsed), ", ", udec(expectedBytesUsed))
pPassFail := !bPassed ? @"FAIL" : @"pass"
ifnot bPassed
failCount[cogId()]++
else
passCount[cogId()]++
debug(" -> ", zstr_(pPassFail))
pub showFileDetails(pFilename) | bytesUsed, bytes_free, block_count
debug(" ") ' blank line
'debug("* showFileDetails()...ENTRY")
bytesUsed, bytes_free, block_count := flash.TEST_count_file_bytes(pFilename)
if bytesUsed < 0
debug(" File: [", zstr_(pFilename), "]")
debug(" # Error: ", zstr_(flash.string_for_error(bytesUsed)))
else
debug(" File: [", zstr_(pFilename), "], ", udec(bytesUsed, bytes_free, block_count))
'debug("* showFileDetails()...EXIT")
pub showPendingCommitChain(handle) | pFilename, pSignatureAr, signatureCount, status
pFilename := flash.TEST_filename_for_handle(handle)
status := flash.error()
if pFilename == 0
debug(" # getFnFmHndl Error: ", zstr_(flash.string_for_error(status)))
debug(" ") ' blank line
debug(" File: [", zstr_(pFilename), "] pending commit")
pSignatureAr, signatureCount := flash.TEST_getCommitBlockSignatures(handle)
if signatureCount > 0
debug(" # ", udec_(signatureCount / 2), " Blocks in chain:")
showSignatureChain(pSignatureAr, signatureCount, handle)
else
debug(" # 0 Blocks in commit")
pub showFileChain(pFilename) | pSignatureAr, signatureCount
debug(" File: [", zstr_(pFilename), "]")
pSignatureAr, signatureCount := flash.TEST_getFileBlockSignatures(pFilename)
if signatureCount > 0
debug(" # ", udec_(signatureCount / 2), " Blocks in file:")
showSignatureChain(pSignatureAr, signatureCount, -1)
else
debug(" # 0 Blocks in file ???")
CON
MAX_FILE_BLOCKS = 50
MAX_FILENAME_LEN = 127
DAT
fileblockAddrAr LONG 0[MAX_FILE_BLOCKS * 3] ' addr, sig[0], sig[1]
badlockAddrAr LONG 0[MAX_FILE_BLOCKS * 3] ' addr, sig[0], sig[1]
filenameBuff BYTE 0[MAX_FILENAME_LEN + 1]
pub showMountSignatures() | fileLen, badLen, fileCt, blockIdx
fileLen, badLen := flash.TEST_dumpMountMap(@fileblockAddrAr, @badlockAddrAr)
blockIdx := 0
fileCt := 0
repeat
' show file lists
if LONG[@fileblockAddrAr][blockIdx] <> 0
' if we have a file
if LONG[@fileblockAddrAr][blockIdx] <> 0
flash.TEST_filename_for_block_addr(LONG[@fileblockAddrAr][blockIdx], @filenameBuff, MAX_FILENAME_LEN + 1)
debug("dmm: file #", udec_(++fileCt), " of ", udec_(fileLen), " [", zstr_(@filenameBuff), "]")
repeat
if LONG[@fileblockAddrAr][blockIdx] <> 0
' count longs in this set
showSignature(LONG[@fileblockAddrAr][blockIdx], LONG[@fileblockAddrAr][blockIdx+1], LONG[@fileblockAddrAr][blockIdx+2])
blockIdx += 3
else
'debug(" ")
blockIdx += 1 ' skip end of file
quit
else
quit
debug(" ")
debug("dmm: ", udec_(badLen), " bad blocks")
blockIdx := 0
repeat
' show bad block list
if LONG[@badlockAddrAr][blockIdx] <> 0
' count longs in this set
showSignature(LONG[@badlockAddrAr][blockIdx], LONG[@badlockAddrAr][blockIdx+1], LONG[@badlockAddrAr][blockIdx+2])
blockIdx += 3
else
quit
PUB bytesSkipped(pFilename) : bytes_skipped | pSignatureAr, signatureCount, dataOfs
pSignatureAr, signatureCount := flash.TEST_getFileBlockSignatures(pFilename)
if signatureCount > 0
bytes_skipped := LONG[pSignatureAr][0+1].[11..0]
pub showSignature(block_address, signature, signature1) | pBlockType, pLifeCycle, nextIdOrEndPtr, blockID, dataOfs, pModified, bIsOldFormat
bIsOldFormat := signature.[2] == 0 ? true: false
dataOfs := bIsOldFormat == false ? signature1.[11..0] : 0
nextIdOrEndPtr := signature.[31..20]
blockID := signature.[19..8]
pModified := signature.[3] == 0 ? @" MODIFIED" : @" "
case signature.[7..5]
%000:
pLifeCycle := @"canceled-0"
%001:
pLifeCycle := @"canceled-1"
%010:
pLifeCycle := @"canceled-2"
%011:
pLifeCycle := @"ACTIVE-3"
%100:
pLifeCycle := @"canceled-4"
%101:
pLifeCycle := @"ACTIVE-5"
%110:
pLifeCycle := @"ACTIVE-6"
%111:
pLifeCycle := @"erased"
case signature.[1..0]
%00: pBlockType := @"HEAD/last"
%01: pBlockType := @"HEAD/more"
%10: pBlockType := @"BODY/last"
%11: pBlockType := @"BODY/more"
if signature.[1]
if signature.[0]
' show body more block
debug(" [", uhex_word_(block_address), "] ", zstr_(pBlockType), ", thisID=",udec_(blockID), ", nextId=", udec_(nextIdOrEndPtr), ", lifeCycle [", zstr_(pLifeCycle), "], sig=[", uhex_long_(signature), "] ", zstr_(pModified))
else
' show body last block
debug(" [", uhex_word_(block_address), "] ", zstr_(pBlockType), ", thisID=",udec_(blockID), ", endPtr=", uhex_word_(nextIdOrEndPtr), ", lifeCycle [", zstr_(pLifeCycle), "], sig=[", uhex_long_(signature), "] ", zstr_(pModified))
elseif bIsOldFormat
' OLD v1.4 format header block
if signature.[0]
' show head more block
debug(" [", uhex_word_(block_address), "] ", zstr_(pBlockType), ", thisID=",udec_(blockID), ", nextId=", udec_(nextIdOrEndPtr), ", lifeCycle [", zstr_(pLifeCycle), "], sig=[", uhex_long_(signature), "] ", zstr_(pModified))
else
' show head last block
debug(" [", uhex_word_(block_address), "] ", zstr_(pBlockType), ", thisID=",udec_(blockID), ", endPtr=", uhex_word_(nextIdOrEndPtr), ", lifeCycle [", zstr_(pLifeCycle), "], sig=[", uhex_long_(signature), "] ", zstr_(pModified))
else
' NEW v2.x format header block
if signature.[0]
' show head more block
debug(" [", uhex_word_(block_address), "] ", zstr_(pBlockType), ", thisID=",udec_(blockID), ", dataOfs=", udec_(dataOfs), ", nextId=", udec_(nextIdOrEndPtr), ", lifeCycle [", zstr_(pLifeCycle), "], sig=[", uhex_long_(signature), "] ", zstr_(pModified))
else
' show head last block
debug(" [", uhex_word_(block_address), "] ", zstr_(pBlockType), ", thisID=",udec_(blockID), ", dataOfs=", uhex_word_(dataOfs), ", endPtr=", uhex_word_(nextIdOrEndPtr), ", lifeCycle [", zstr_(pLifeCycle), "], sig=[", uhex_long_(signature), "] ", zstr_(pModified))
pub showSignatureChain(pSignatureAr, signatureCount, possHandle) | signature, signatureIdx, pBlockType, pLifeCycle, nextIdOrEndPtr, blockID, blockAddr, dataOfs, pModified, bIsOldFormat
if signatureCount > 0
repeat signatureIdx from 0 to signatureCount -1 step 2
signature := LONG[pSignatureAr][signatureIdx]
bIsOldFormat := signature.[2] == 0 ? true: false
dataOfs := bIsOldFormat == false ? LONG[pSignatureAr][signatureIdx+1].[11..0] : 0
nextIdOrEndPtr := signature.[31..20]
blockID := signature.[19..8]
pModified := signature.[3] == 0 ? @" MODIFIED" : @" "
blockAddr := flash.TEST_getBlockAddressForId(blockID, possHandle)
case signature.[7..5]
%000:
pLifeCycle := @"canceled-0"
%001:
pLifeCycle := @"canceled-1"
%010:
pLifeCycle := @"canceled-2"
%011:
pLifeCycle := @"ACTIVE-3"
%100:
pLifeCycle := @"canceled-4"
%101:
pLifeCycle := @"ACTIVE-5"
%110:
pLifeCycle := @"ACTIVE-6"
%111:
pLifeCycle := @"erased"
case signature.[1..0]
%00: pBlockType := @"HEAD/last"
%01: pBlockType := @"HEAD/more"
%10: pBlockType := @"BODY/last"
%11: pBlockType := @"BODY/more"
if signature.[1]
if signature.[0]
' show body more block
debug(" ", udec_(signatureIdx/2+1), ": [", uhex_word_(blockAddr), "] ", zstr_(pBlockType), ", thisID=",udec_(blockID), ", nextId=", udec_(nextIdOrEndPtr), ", lifeCycle [", zstr_(pLifeCycle), "], sig=[", uhex_long_(signature), "] ", zstr_(pModified))
else
' show body last block
debug(" ", udec_(signatureIdx/2+1), ": [", uhex_word_(blockAddr), "] ", zstr_(pBlockType), ", thisID=",udec_(blockID), ", endPtr=", uhex_word_(nextIdOrEndPtr), ", lifeCycle [", zstr_(pLifeCycle), "], sig=[", uhex_long_(signature), "] ", zstr_(pModified))
elseif bIsOldFormat
' OLD format header block
if signature.[0]
' show head more block
debug(" ", udec_(signatureIdx/2+1), ": [", uhex_word_(blockAddr), "] ", zstr_(pBlockType), ", thisID=",udec_(blockID), ", nextId=", udec_(nextIdOrEndPtr), ", lifeCycle [", zstr_(pLifeCycle), "], sig=[", uhex_long_(signature), "] ", zstr_(pModified))
else
' show head last block
debug(" ", udec_(signatureIdx/2+1), ": [", uhex_word_(blockAddr), "] ", zstr_(pBlockType), ", thisID=",udec_(blockID), ", endPtr=", uhex_word_(nextIdOrEndPtr), ", lifeCycle [", zstr_(pLifeCycle), "], sig=[", uhex_long_(signature), "] ", zstr_(pModified))
else
' NEW format header block
if signature.[0]
' show head more block
debug(" ", udec_(signatureIdx/2+1), ": [", uhex_word_(blockAddr), "] ", zstr_(pBlockType), ", thisID=",udec_(blockID), ", dataOfs=", udec_(dataOfs), ", nextId=", udec_(nextIdOrEndPtr), ", lifeCycle [", zstr_(pLifeCycle), "], sig=[", uhex_long_(signature), "] ", zstr_(pModified))
else
' show head last block
debug(" ", udec_(signatureIdx/2+1), ": [", uhex_word_(blockAddr), "] ", zstr_(pBlockType), ", thisID=",udec_(blockID), ", dataOfs=", uhex_word_(dataOfs), ", endPtr=", uhex_word_(nextIdOrEndPtr), ", lifeCycle [", zstr_(pLifeCycle), "], sig=[", uhex_long_(signature), "] ", zstr_(pModified))
pub showError(pCaller, errorCode)
debug("EEEE ", zstr_(pCaller), " error: ", zstr_(flash.string_for_error(errorCode)))
pub ShowStats() | blocksUsed, blocksFree, fileCount
blocksUsed, blocksFree, fileCount := flash.stats()
debug(udec(blocksUsed, blocksFree, fileCount))
pub showFiles() | blockID, byteCount, byte Buff[30], BlocksUsed
debug(" ") ' blank line
debug(" All Files:")
blockID := 0 'strictly speaking only needed for flexspin, but it helps to remind us that blockID must be initialized to 0
repeat
flash.directory(@blockID, @filename, @byteCount) 'get next file
BlocksUsed := blockCountForFileSize(byteCount)
if filename[0] 'is there a filename?
ReadFile(@filename, @Buff, 30) 'read file
if isZstr(@Buff, 30)
debug(zstr_(@filename), udec(byteCount, blockID, BlocksUsed), zstr(@Buff)) 'show filename, bytes, blockID, and file contents
else
debug(zstr_(@filename), udec(byteCount, blockID, BlocksUsed), ", @Buff={binary data}") 'show filename, bytes, blockID, and file contents
else
quit 'no more files, quit
pub isBinaryFile(pFilename) : bIsBinaryStatus | pFileType
pFileType := fileTypePtr(pFilename)
bIsBinaryStatus := strcomp(pFileType, @"bin")
pub isStringsFile(pFilename) : bIsBinaryStatus | pFileType
pFileType := fileTypePtr(pFilename)
bIsBinaryStatus := strcomp(pFileType, @"zstr")
pub fileTypePtr(pFilename) : pFileType | byteIdx
repeat byteIdx from 0 to strsize(pFilename) - 1
if pFilename[byteIdx] == "."
return @pFilename[byteIdx + 1]
pub isZstr(pBffr, count) : bIsStringStatus | bytIdx
bIsStringStatus := false
repeat bytIdx from 0 to count - 1
if pBffr[bytIdx] == 0
return true
if pBffr[bytIdx] < 32 or pBffr[bytIdx] > 126
return
pub ReadFile(pFilename, pStr, maxlen) | handle, byteCount
if isStringsFile(pFilename)
handle := flash.open(pFilename,"R") 'open file for reading
if handle >= 0
byteCount := flash.rd_str(handle, pStr, maxlen) 'read bytes of zstring
if byteCount < 0
showError(@"rd_str()", byteCount)
'debug("- read str(", udec_(byteCount), ")=[", zstr_(pStr), "]") 'show filename, bytes, blockID, and file contents
flash.close(handle) 'close file
else
bytefill(pStr, $ff, maxlen)
pub ensureEmptyDirectory() | blockID, byteCount, bPassed, pPassFail
'' validate that directory is empty!
flash.directory(@blockID, @filename, @byteCount) 'get first file
bPassed := true
if filename[0] 'is there a filename?
bPassed := false
pPassFail := !bPassed ? @"FAIL" : @"pass"
ifnot bPassed
debug(" # Error Found file: [", zstr_(@filename), "] (expected: no files)")
failCount[cogId()]++
else
passCount[cogId()]++
debug(" -> ", zstr_(pPassFail))
pub blockCountForFileSize(fileSizeInBytes) : blockCount | remainingSize, overflowBodyCount
' return number of blocks for given file size
blockCount := 1 ' head block
if fileSizeInBytes > flash.BYTES_IN_HEAD_BLOCK
remainingSize := fileSizeInBytes - flash.BYTES_IN_HEAD_BLOCK
blockCount += remainingSize / flash.BYTES_IN_BODY_BLOCK ' body blocks
overflowBodyCount := remainingSize +// flash.BYTES_IN_BODY_BLOCK ' final bytes in tail block
'debug("blockCountForFileSize() # remainByt: ", udec_(remainingSize), ", ovflwByt: ", udec_(overflowBodyCount))
if overflowBodyCount > 0
blockCount++
'debug("blockCountForFileSize() # bytes: ", udec_(fileSizeInBytes), ", blocks: ", udec_(blockCount))
pub bytesAllocatedFor(sizeInBytes) : maxAllocationBytes | bodyBlocks
' return max allocation size for circular file
maxAllocationBytes := flash.BYTES_IN_HEAD_BLOCK
if sizeInBytes > flash.BYTES_IN_HEAD_BLOCK
bodyBlocks := ((sizeInBytes - flash.BYTES_IN_HEAD_BLOCK) + (flash.BYTES_IN_BODY_BLOCK - 1)) / flash.BYTES_IN_BODY_BLOCK
maxAllocationBytes += bodyBlocks * flash.BYTES_IN_BODY_BLOCK
pub bytesAllocatedInBlocks(numberBlocks) : sizeInBytes
' return max number of bytes stored in given amount of blocks
sizeInBytes := flash.BYTES_IN_HEAD_BLOCK
if numberBlocks > 1
sizeInBytes += (numberBlocks - 1) * flash.BYTES_IN_BODY_BLOCK
pub bytesInLastBlock(totalBytes) : bytesInLast
bytesInLast := totalBytes
if totalBytes > flash.BYTES_IN_HEAD_BLOCK
bytesInLast -= flash.BYTES_IN_HEAD_BLOCK
if bytesInLast > flash.BYTES_IN_BODY_BLOCK
bytesInLast := bytesInLast +// flash.BYTES_IN_BODY_BLOCK
pub checkMatchingEntries(pDirEntries) | blockID, byteCount, bPassed, pPassFail, refFileCount, foundFileCount, pCurrRefDir, pRefFilename, refByteCount, refBlocks, calcBlocks, bBadEntry
{
' structure for directory checking
' (pDirEntries := @dirEntr1)
dirEntr1 LONG @testfile1 ' pointer to filename
fileBytes1 LONG 10 ' length in bytes
fileBlocks1 LONG 1 ' number of blocks allocated
dirEntr2 LONG @testfile2 ' pointer to filename
fileBytes2 LONG 20 ' length in bytes
fileBlocks2 LONG 1 ' number of blocks allocated
dirEnd LONG 0 ' ptr = NULL, no more entries
}
bPassed := true
pCurrRefDir := pDirEntries
refFileCount := 0
foundFileCount := 0
blockID := 0 ' start seach at beginning
repeat
pRefFilename := LONG[pCurrRefDir][0] ' get pointer to reference filename -OR- NULL
refByteCount := LONG[pCurrRefDir][1] ' get byte count
refBlocks := LONG[pCurrRefDir][2] ' get block count
flash.directory(@blockID, @filename, @byteCount) 'get next file
if pRefFilename == 0 ' if not beyond last REF entry
'debug(" - end of table entries!")
else
refFileCount++
if filename[0] == 0 'is there a filename?
'debug(" - end of directory entries!")
else
foundFileCount++
if pRefFilename == 0 && filename[0] == 0
quit
if pRefFilename <> 0 && filename[0] <> 0
calcBlocks := blockCountForFileSize(byteCount)
'debug(" read ->: [", zstr_(@filename), "], bytes=(", udec_(Bytes), "), blocks(", udec_(calcBlocks), ")")
'debug(" load ->: [", zstr_(pRefFilename), "], bytes=(", udec_(refByteCount), "), blocks(", udec_(refBlocks), ")")
bBadEntry := false
' ensure all three values match
if strcomp(@filename, pRefFilename) == false
debug(" - BAD filenames!")
bBadEntry := true
if byteCount <> refByteCount
debug(" - BAD byte count!")
bBadEntry := true
if calcBlocks <> refBlocks
debug(" - BAD block count!")
bBadEntry := true
' checked, now summarize findings iff bad
if bBadEntry
debug(" # Found: [", zstr_(@filename), "], bytes=(", udec_(byteCount), "), blocks(", udec_(calcBlocks), ")")
debug(" # Expected: [", zstr_(pRefFilename), "], bytes=(", udec_(refByteCount), "), blocks(", udec_(refBlocks), ")")
bPassed := false
if pRefFilename <> 0 ' if not beyond last REF entry
pCurrRefDir := @LONG[pCurrRefDir][3]
if foundFileCount <> refFileCount
debug(" # Found ", udec_(foundFileCount), " files (expected ", udec_(refFileCount), ")")
bPassed := false
pPassFail := !bPassed ? @"FAIL" : @"pass"
ifnot bPassed
failCount[cogId()]++
else
passCount[cogId()]++
debug(" -> ", zstr_(pPassFail))
' -------
' dbgMemDump(@"TASK Stack", pStack, (nStackLongCt + 1) * 4)
pub dbgMemDumpAbs(pMessage, pBytes, lenBytes) | rowCount, rowLen, pCurrByte, lastRowByteCount, bytesSoFar
'' Dump rows of hex values with address preceeding
if pMessage
debug("** ", zstr_(pMessage), ":")
rowCount := lenBytes / 16
lastRowByteCount := lenBytes - (rowCount * 16)
pCurrByte := pBytes
bytesSoFar := 0
' emit full lines
if rowCount > 0
repeat rowCount
dbgMemDumpRowAbs(pCurrByte, 16)
pCurrByte += 16
bytesSoFar += 16
if bytesSoFar < lenBytes
' emit last line
dbgMemDumpRowAbs(pCurrByte, lastRowByteCount)
pri dbgMemDumpRowAbs(pBytes, lenBytes)
' emit address followed by bytes
debug(" ", uhex_long_(pBytes), ": ", uhex_byte_array_(pBytes, lenBytes))
pub dbgMemDump(pMessage, pBytes, lenBytes) | rowCount, rowLen, pCurrByte, lastRowByteCount, bytesSoFar, offset
if pMessage
debug("** ", zstr_(pMessage), ":")
offset := 0
rowCount := lenBytes / 16
lastRowByteCount := lenBytes - (rowCount * 16)
pCurrByte := pBytes
bytesSoFar := 0
' emit full lines
if rowCount > 0
repeat rowCount
dbgMemDumpRow(pCurrByte, 16, offset)
offset += 16
pCurrByte += 16
bytesSoFar += 16
if bytesSoFar < lenBytes
' emit last line
dbgMemDumpRow(pCurrByte, lastRowByteCount, offset)
pri dbgMemDumpRow(pBytes, lenBytes, offset)
' emit address followed by bytes
debug(" ", uhex_long_(offset), ": ", uhex_byte_array_(pBytes, lenBytes))
pub record_crc(p_record_buffer, record_length) : crc
' Calculate and return the CRC for this pointed to block
'
' @param p_block_buffer - the address of the 4KB buffer for the file associated with this handle
' @returns crc - the calculated CRC for the block
return getcrc(p_record_buffer, $AD0424F3 rev 31, record_length - 4) 'compute CRC of a buffered block
pub dumpFileHeads() | blockID, byteCount, pBlock
debug(" ") ' blank line
debug(" All File heads:")
repeat
flash.directory(@blockID, @filename, @byteCount) 'get next file
if filename[0] 'is there a filename?
pBlock := flash.TEST_getHead4kBlock(@filename)
dbgMemDump(@filename, pBlock, 64)
debug(" ") ' blank line
else
quit 'no more files, quit
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.
=================================================================================================
}}