test: fix tests on i386 and arm (#50)
fixes #48
Steven Allen authored 4 years ago
Harshavardhana committed 4 years ago
51 | 51 | import ( |
52 | 52 | "encoding/hex" |
53 | 53 | "fmt" |
54 | "runtime" | |
54 | 55 | "strings" |
55 | 56 | "testing" |
56 | 57 | ) |
2209 | 2210 | func TestGolden(t *testing.T) { |
2210 | 2211 | blockfuncSaved := blockfunc |
2211 | 2212 | |
2213 | defer func() { | |
2214 | blockfunc = blockfuncSaved | |
2215 | }() | |
2216 | ||
2217 | if true { | |
2218 | blockfunc = blockfuncGeneric | |
2219 | for _, g := range golden { | |
2220 | s := fmt.Sprintf("%x", Sum256([]byte(g.in))) | |
2221 | if Sum256([]byte(g.in)) != g.out { | |
2222 | t.Fatalf("Generic: Sum256 function: sha256(%s) = %s want %s", g.in, s, hex.EncodeToString(g.out[:])) | |
2223 | } | |
2224 | } | |
2225 | } | |
2226 | ||
2227 | if runtime.GOARCH == "386" || runtime.GOARCH == "arm" { | |
2228 | // doesn't support anything but the generic version. | |
2229 | return | |
2230 | } | |
2231 | ||
2212 | 2232 | if sha && ssse3 && sse41 { |
2213 | 2233 | blockfunc = blockfuncSha |
2214 | 2234 | for _, g := range golden { |
2245 | 2265 | } |
2246 | 2266 | } |
2247 | 2267 | } |
2248 | if true { | |
2249 | blockfunc = blockfuncGeneric | |
2250 | for _, g := range golden { | |
2251 | s := fmt.Sprintf("%x", Sum256([]byte(g.in))) | |
2252 | if Sum256([]byte(g.in)) != g.out { | |
2253 | t.Fatalf("Generic: Sum256 function: sha256(%s) = %s want %s", g.in, s, hex.EncodeToString(g.out[:])) | |
2254 | } | |
2255 | } | |
2256 | } | |
2257 | ||
2258 | blockfunc = blockfuncSaved | |
2259 | 2268 | } |
2260 | 2269 | |
2261 | 2270 | func TestSize(t *testing.T) { |