2148
|
1 |
"{ Encoding: utf8 }"
|
|
2 |
|
2098
|
3 |
"{ Package: 'stx:goodies/regression' }"
|
|
4 |
|
|
5 |
"{ NameSpace: RegressionTests }"
|
|
6 |
|
|
7 |
TestCase subclass:#CRCTests
|
|
8 |
instanceVariableNames:''
|
|
9 |
classVariableNames:''
|
|
10 |
poolDictionaries:''
|
2136
|
11 |
category:'tests-Regression-Files and Encodings'
|
2098
|
12 |
!
|
|
13 |
|
|
14 |
!CRCTests class methodsFor:'documentation'!
|
|
15 |
|
|
16 |
documentation
|
|
17 |
"
|
|
18 |
documentation to be added.
|
|
19 |
|
|
20 |
[author:]
|
|
21 |
Claus Gittinger
|
|
22 |
|
|
23 |
[instance variables:]
|
|
24 |
|
|
25 |
[class variables:]
|
|
26 |
|
|
27 |
[see also:]
|
|
28 |
|
|
29 |
"
|
|
30 |
! !
|
|
31 |
|
|
32 |
!CRCTests methodsFor:'tests'!
|
|
33 |
|
|
34 |
test01_crc32
|
|
35 |
"the default ccitt crc32"
|
|
36 |
|
2107
|
37 |
CRC32Stream flushCrcTables.
|
|
38 |
|
2098
|
39 |
self assert:(CRC32Stream new hashValueOf:'') = 0.
|
2107
|
40 |
self assert:(CRC32Stream new hashValueOf:'a') = 16rE8B7BE43.
|
2098
|
41 |
self assert:(CRC32Stream new hashValueOf:'resume') = 16r60C1D0A0.
|
|
42 |
self assert:(CRC32Stream new hashValueOf:#[1 2 3 4 5 6 7]) = 16r70E46888.
|
|
43 |
self assert:(CRC32Stream new hashValueOf:(ByteArray new:40 withAll:16rFF)) = 16r8CD04C73.
|
|
44 |
self assert:(CRC32Stream new hashValueOf:'123456789') = 16rCBF43926.
|
2107
|
45 |
self assert:(CRC32Stream new hashValueOf:'Lammert Bies') = 16r43C04CA6.
|
|
46 |
self assert:(CRC32Stream new hashValueOf:' ') = 16rE96CCF45.
|
2098
|
47 |
|
|
48 |
"Created: / 16-03-2019 / 23:22:34 / Claus Gittinger"
|
2107
|
49 |
"Modified (comment): / 17-03-2019 / 14:08:26 / Claus Gittinger"
|
2098
|
50 |
!
|
|
51 |
|
2106
|
52 |
test02_crc32c
|
|
53 |
"the Castagnoli crc32"
|
2098
|
54 |
|
2107
|
55 |
CRC32Stream flushCrcTables.
|
|
56 |
|
2098
|
57 |
self assert:(CRC32Stream newCrc32c hashValueOf:'') = 0.
|
|
58 |
self assert:(CRC32Stream newCrc32c hashValueOf:'a') = 16rC1D04330.
|
|
59 |
self assert:(CRC32Stream newCrc32c hashValueOf:'123456789') = 16rE3069283.
|
|
60 |
self assert:(CRC32Stream newCrc32c hashValueOf:(ByteArray new:32 withAll:0)) = 16r8A9136AA.
|
|
61 |
self assert:(CRC32Stream newCrc32c hashValueOf:(ByteArray new:32 withAll:16rFF)) = 16r62a8ab43.
|
|
62 |
self assert:(CRC32Stream newCrc32c hashValueOf:((0 to:31) asByteArray)) = 16r46dd794e.
|
2107
|
63 |
self assert:(CRC32Stream newCrc32c hashValueOf:(ByteArray new:1000000)) = 16r71AF9A4E.
|
2098
|
64 |
|
2106
|
65 |
"Created: / 16-03-2019 / 23:39:52 / Claus Gittinger"
|
2107
|
66 |
"Modified: / 17-03-2019 / 16:56:14 / Claus Gittinger"
|
2106
|
67 |
!
|
|
68 |
|
|
69 |
test03_crc16
|
2148
|
70 |
"the crc16 variants"
|
2108
|
71 |
|
2148
|
72 |
self skipIf:true description:'fails, by order of cg - skip'.
|
|
73 |
|
|
74 |
"/ 1..9 testVector from
|
|
75 |
"/ https://www.lammertbies.nl/comm/info/crc-calculation.html
|
2108
|
76 |
|
2106
|
77 |
CRC16Stream flushCrcTables.
|
|
78 |
"/ CRCStream flushCrcTables.
|
|
79 |
"/ CRC32Stream flushCrcTables.
|
2107
|
80 |
self assert:(CRC16Stream newKERMIT hashValueOf:'') = 0.
|
|
81 |
self assert:(CRC16Stream newKERMIT hashValueOf:'a') = 16r8F72.
|
2148
|
82 |
self assert:(CRC16Stream newKERMIT hashValueOf:'abc') = 16rE958.
|
2107
|
83 |
self assert:(CRC16Stream newKERMIT hashValueOf:' ') = 16r0221.
|
|
84 |
self assert:(CRC16Stream newKERMIT hashValueOf:'123456789') = 16r8921.
|
2148
|
85 |
self assert:(CRC16Stream newKERMIT hashValueOf:'Lammert Bies') = 16rF80D.
|
|
86 |
self assert:(CRC16Stream newKERMIT hashValueOf:#[16r06 16r00 16r0c 16rf0 16r00 16r04 16r00 16r55 16r88 16r73 16rc9 16r00 16r00 16r05 16r21]
|
|
87 |
) = 16r2098.
|
2107
|
88 |
|
|
89 |
self assert:(CRC16Stream newDNP hashValueOf:'') = 16rFFFF.
|
|
90 |
self assert:(CRC16Stream newDNP hashValueOf:'a') = 16r50B3.
|
2148
|
91 |
self assert:(CRC16Stream newDNP hashValueOf:'abc') = 16r57E9.
|
2107
|
92 |
self assert:(CRC16Stream newDNP hashValueOf:' ') = 16r50D6.
|
|
93 |
self assert:(CRC16Stream newDNP hashValueOf:'123456789') = 16r82EA.
|
2148
|
94 |
self assert:(CRC16Stream newDNP hashValueOf:'Lammert Bies') = 16r4583.
|
2149
|
95 |
self assert:(CRC16Stream newDNP hashValueOf:#[16r06 16r00 16r0c 16rf0 16r00 16r04 16r00 16r55 16r88 16r73 16rc9 16r00 16r00 16r05 16r21]) = 16r7482.
|
2107
|
96 |
|
2148
|
97 |
self assert:(CRC16Stream newMODBUS hashValueOf:'') = 16rFFFF.
|
2107
|
98 |
self assert:(CRC16Stream newMODBUS hashValueOf:'a') = 16rA87E.
|
2148
|
99 |
self assert:(CRC16Stream newMODBUS hashValueOf:'abc') = 16r5749.
|
2107
|
100 |
self assert:(CRC16Stream newMODBUS hashValueOf:' ') = 16r98BE.
|
|
101 |
self assert:(CRC16Stream newMODBUS hashValueOf:'123456789') = 16r4B37.
|
2148
|
102 |
self assert:(CRC16Stream newMODBUS hashValueOf:'Lammert Bies') = 16rB45C.
|
|
103 |
self assert:(CRC16Stream newMODBUS hashValueOf:#[16r06 16r00 16r0c 16rf0 16r00 16r04 16r00 16r55 16r88 16r73 16rc9 16r00 16r00 16r05 16r21]
|
|
104 |
) = 16rF50C.
|
|
105 |
|
|
106 |
self assert:(CRC16Stream newXMODEM hashValueOf:'') = 0.
|
|
107 |
self assert:(CRC16Stream newXMODEM hashValueOf:'a') = 16r7C87.
|
|
108 |
self assert:(CRC16Stream newXMODEM hashValueOf:'abc') = 16r9dd6.
|
|
109 |
self assert:(CRC16Stream newXMODEM hashValueOf:' ') = 16r2462.
|
|
110 |
self assert:(CRC16Stream newXMODEM hashValueOf:'123456789') = 16r31C3.
|
|
111 |
self assert:(CRC16Stream newXMODEM hashValueOf:'Lammert Bies') = 16rCEC8.
|
2149
|
112 |
self assert:(CRC16Stream newXMODEM hashValueOf:#[16r06 16r00 16r0c 16rf0 16r00 16r04 16r00 16r55 16r88 16r73 16rc9 16r00 16r00 16r05 16r21]) = 16r3B38.
|
2107
|
113 |
|
|
114 |
self assert:(CRC16Stream newCRC_16 hashValueOf:'') = 0.
|
2148
|
115 |
self assert:(CRC16Stream newCRC_16 hashValueOf:'a') = 16rE8C1.
|
|
116 |
self assert:(CRC16Stream newCRC_16 hashValueOf:'abc') = 16r9738.
|
|
117 |
self assert:(CRC16Stream newCRC_16 hashValueOf:' ') = 16rD801.
|
|
118 |
self assert:(CRC16Stream newCRC_16 hashValueOf:'123456789') = 16rBB3D.
|
|
119 |
self assert:(CRC16Stream newCRC_16 hashValueOf:'Lammert Bies') = 16rB638.
|
2149
|
120 |
self assert:(CRC16Stream newCRC_16 hashValueOf:#[16r06 16r00 16r0c 16rf0 16r00 16r04 16r00 16r55 16r88 16r73 16rc9 16r00 16r00 16r05 16r21]) = 16r4A4C.
|
2107
|
121 |
|
2148
|
122 |
"/ CCITT with 0xFFFF as start
|
|
123 |
self assert:(CRC16Stream newCCITT hashValueOf:'') = 16rFFFF.
|
2107
|
124 |
self assert:(CRC16Stream newCCITT hashValueOf:'a') = 16r9D77.
|
2148
|
125 |
self assert:(CRC16Stream newCCITT hashValueOf:'abc') = 16r514A.
|
2107
|
126 |
self assert:(CRC16Stream newCCITT hashValueOf:' ') = 16rC592.
|
2148
|
127 |
self assert:(CRC16Stream newCCITT hashValueOf:'123456789') = 16r29B1.
|
|
128 |
self assert:(CRC16Stream newCCITT hashValueOf:'Lammert Bies') = 16r4A31.
|
|
129 |
self assert:(CRC16Stream newCCITT hashValueOf:#[16r06 16r00 16r0c 16rf0 16r00 16r04 16r00 16r55 16r88 16r73 16rc9 16r00 16r00 16r05 16r21]
|
|
130 |
) = 16r75FB.
|
|
131 |
|
|
132 |
"/ CCITT with 0x1D0F as start
|
|
133 |
self assert:(CRC16Stream newCCITT_1D0F hashValueOf:'') = 16r1D0F.
|
|
134 |
self assert:(CRC16Stream newCCITT_1D0F hashValueOf:'a') = 16rB01B.
|
|
135 |
self assert:(CRC16Stream newCCITT_1D0F hashValueOf:'abc') = 16r8CDA.
|
|
136 |
self assert:(CRC16Stream newCCITT_1D0F hashValueOf:' ') = 16rE8FE.
|
|
137 |
self assert:(CRC16Stream newCCITT_1D0F hashValueOf:'123456789') = 16rE5CC.
|
|
138 |
self assert:(CRC16Stream newCCITT_1D0F hashValueOf:'Lammert Bies') = 16r67A2.
|
2149
|
139 |
self assert:(CRC16Stream newCCITT_1D0F hashValueOf:#[16r06 16r00 16r0c 16rf0 16r00 16r04 16r00 16r55 16r88 16r73 16rc9 16r00 16r00 16r05 16r21]) = 16rFCD4.
|
2106
|
140 |
|
|
141 |
"Created: / 16-03-2019 / 23:40:26 / Claus Gittinger"
|
2108
|
142 |
"Modified: / 19-03-2019 / 11:23:27 / Stefan Reise"
|
2149
|
143 |
"Modified (format): / 24-03-2019 / 21:03:06 / Claus Gittinger"
|
2148
|
144 |
!
|
|
145 |
|
|
146 |
test04_crc8
|
|
147 |
"the crc8 variants"
|
|
148 |
|
|
149 |
self skipIf:true description:'fails, by order of cg - skip'.
|
|
150 |
|
|
151 |
CRC8Stream flushCrcTables.
|
|
152 |
|
|
153 |
"/ test vectors from AUTOSAR_SWS_CRCLibrary.pdf
|
|
154 |
self assert:(CRC8Stream newSAE_J1850 hashValueOf:'') = 0.
|
|
155 |
self assert:(CRC8Stream newSAE_J1850 hashValueOf:#[0 0 0 0] ) = 16r59.
|
|
156 |
self assert:(CRC8Stream newSAE_J1850 hashValueOf:#[16rF2 16r01 16r83]) = 16r37.
|
|
157 |
self assert:(CRC8Stream newSAE_J1850 hashValueOf:#[16r0F 16rAA 16r99 16r55]) = 16r79.
|
|
158 |
self assert:(CRC8Stream newSAE_J1850 hashValueOf:#[16r00 16rFF 16r55 16r11]) = 16rB8.
|
|
159 |
self assert:(CRC8Stream newSAE_J1850 hashValueOf:#[16r33 16r22 16r55 16rAA 16rBB 16rCC 16rDD 16rEE 16rFF]) = 16rCB.
|
|
160 |
self assert:(CRC8Stream newSAE_J1850 hashValueOf:#[16r92 16r6B 16r55]) = 16r8C.
|
|
161 |
self assert:(CRC8Stream newSAE_J1850 hashValueOf:#[16rFF 16rFF 16rFF 16rFF]) = 16r74.
|
|
162 |
|
2150
|
163 |
"/ test vectors from AUTOSAR_SWS_CRCLibrary.pdf
|
|
164 |
"/ self assert:(CRC8Stream new_2F hashValueOf:'') = 0.
|
|
165 |
self assert:(CRC8Stream new_2F hashValueOf:#[0 0 0 0] ) = 16r12.
|
|
166 |
self assert:(CRC8Stream new_2F hashValueOf:#[16rF2 16r01 16r83]) = 16rC2.
|
|
167 |
self assert:(CRC8Stream new_2F hashValueOf:#[16r0F 16rAA 16r99 16r55]) = 16rC6.
|
|
168 |
self assert:(CRC8Stream new_2F hashValueOf:#[16r00 16rFF 16r55 16r11]) = 16r77.
|
|
169 |
self assert:(CRC8Stream new_2F hashValueOf:#[16r33 16r22 16r55 16rAA 16rBB 16rCC 16rDD 16rEE 16rFF]) = 16r11.
|
|
170 |
self assert:(CRC8Stream new_2F hashValueOf:#[16r92 16r6B 16r55]) = 16r33.
|
|
171 |
self assert:(CRC8Stream new_2F hashValueOf:#[16rFF 16rFF 16rFF 16rFF]) = 16r6C.
|
|
172 |
|
2148
|
173 |
"Created: / 24-03-2019 / 12:03:54 / Claus Gittinger"
|
2150
|
174 |
"Modified: / 25-03-2019 / 14:25:02 / Claus Gittinger"
|
2132
|
175 |
!
|
|
176 |
|
|
177 |
test99_speed
|
2134
|
178 |
|oneTest speedTest|
|
2132
|
179 |
|
|
180 |
self skipIf:true description:'speedtest; not part of automated test suite'.
|
|
181 |
|
2134
|
182 |
oneTest := [:name :hashStream :n :s |
|
2132
|
183 |
|l t nMb|
|
|
184 |
|
|
185 |
l := s size.
|
|
186 |
t := Time millisecondsToRun:[
|
|
187 |
n timesRepeat:[
|
2134
|
188 |
hashStream nextPutAll:s
|
2132
|
189 |
].
|
|
190 |
].
|
|
191 |
t := (t / 1000) asFloat.
|
|
192 |
nMb := n*l/1024/1024.
|
2134
|
193 |
Transcript showCR:'%1: %2 (chunk size %3)' with:name with:(hashStream hashValue hexPrintString) with:l.
|
2132
|
194 |
Transcript showCR:' %1 seconds for %2 Mb' with:t with:(nMb asFixedPoint:2).
|
|
195 |
Transcript showCR:' %1 Mb/s' with:((nMb / t) asFixedPoint:2).
|
|
196 |
].
|
|
197 |
|
2134
|
198 |
speedTest := [:name :hashStreamMaker |
|
|
199 |
Transcript showCR:'-----------------------'.
|
|
200 |
oneTest
|
|
201 |
value:name value:(hashStreamMaker value) value:2000000
|
|
202 |
value:'1234567890'.
|
|
203 |
oneTest
|
|
204 |
value:name value:(hashStreamMaker value) value:2000000
|
|
205 |
value:'12345678901234567890123456789012345678901234567890'.
|
|
206 |
oneTest
|
|
207 |
value:name value:(hashStreamMaker value) value:200000
|
|
208 |
value:('12345678901234567890123456789012345678901234567890' ,* 20).
|
|
209 |
oneTest
|
|
210 |
value:name value:(hashStreamMaker value) value:20000
|
|
211 |
value:('12345678901234567890123456789012345678901234567890' ,* 1000).
|
|
212 |
].
|
2132
|
213 |
|
|
214 |
speedTest
|
2134
|
215 |
value:'crc32' value:[CRC32Stream new].
|
2132
|
216 |
speedTest
|
2134
|
217 |
value:'crc32 castagnoli' value:[CRC32Stream newCastagnoli].
|
2132
|
218 |
|
|
219 |
"Created: / 23-03-2019 / 09:53:58 / Claus Gittinger"
|
2134
|
220 |
"Modified: / 23-03-2019 / 14:41:14 / Claus Gittinger"
|
2098
|
221 |
! !
|
|
222 |
|
|
223 |
!CRCTests class methodsFor:'documentation'!
|
|
224 |
|
|
225 |
version_CVS
|
|
226 |
^ '$Header$'
|
|
227 |
! !
|
|
228 |
|