1
2
3
4
5 package cryptotest
6
7 import (
8 "crypto/internal/boring"
9 "crypto/internal/impl"
10 "internal/goarch"
11 "internal/goos"
12 "internal/testenv"
13 "strings"
14 "testing"
15 )
16
17
18
19
20 func TestAllImplementations(t *testing.T, pkg string, f func(t *testing.T)) {
21
22 if boring.Enabled {
23 f(t)
24 return
25 }
26
27 impls := impl.List(pkg)
28 if len(impls) == 0 {
29 f(t)
30 return
31 }
32
33 t.Cleanup(func() { impl.Reset(pkg) })
34
35 for _, name := range impls {
36 if available := impl.Select(pkg, name); available {
37 t.Run(name, f)
38 } else {
39 t.Run(name, func(t *testing.T) {
40
41
42 if flagshipBuilder() {
43 t.Error("builder doesn't support CPU features needed to test this implementation")
44 } else {
45 t.Skip("implementation not supported")
46 }
47 })
48 }
49 }
50
51
52 impl.Select(pkg, "")
53 t.Run("Base", f)
54 }
55
56 func flagshipBuilder() bool {
57 builder := testenv.Builder()
58 if builder == "" {
59 return false
60 }
61 switch goarch.GOARCH {
62 case "amd64":
63 return strings.Contains(builder, "_avx512")
64 case "arm64":
65
66 return goos.GOOS == "darwin"
67 default:
68
69 return goos.GOOS == "linux"
70 }
71 }
72
View as plain text