Source file
src/simd/midway_common_test.go
1
2
3
4
5
6
7 package simd
8
9 import (
10 "fmt"
11 "strings"
12 "testing"
13 )
14
15 func TestConfigurePlainPlus(t *testing.T) {
16 for _, test := range []struct {
17 name string
18 actualMax int
19 allFeatureSize int
20 wantHWClmul bool
21 arch string
22 }{
23 {"missing feature", 256, 128, false, "amd64"},
24 {"all features", 256, 256, true, "amd64"},
25 } {
26 t.Run(test.name, func(t *testing.T) {
27 max, emulated, hwClmul := configure(test.actualMax, test.allFeatureSize, test.arch, "+")
28 if max != test.actualMax || emulated || hwClmul != test.wantHWClmul {
29 t.Errorf("configure(%d, %d, +) = (%d, %t, %t), want (%d, false, %t)",
30 test.actualMax, test.allFeatureSize, max, emulated, hwClmul,
31 test.actualMax, test.wantHWClmul)
32 }
33
34 maxWithSize, emulatedWithSize, hwClmulWithSize := configure(test.actualMax, test.allFeatureSize, test.arch, "+256")
35 if max != maxWithSize || emulated != emulatedWithSize || hwClmul != hwClmulWithSize {
36 t.Errorf("plain + result (%d, %t, %t) differs from +256 result (%d, %t, %t)",
37 max, emulated, hwClmul, maxWithSize, emulatedWithSize, hwClmulWithSize)
38 }
39 })
40 }
41 }
42
43 func TestConfigureDefault(t *testing.T) {
44 max, emulated, hwClmul := configure(256, 256, "amd64", "")
45 if max != 256 || emulated || !hwClmul {
46 t.Errorf("configure(256, 256, empty) = (%d, %t, %t), want (256, false, true)",
47 max, emulated, hwClmul)
48 }
49 }
50
51 func TestConfigureOne(t *testing.T) {
52 for _, test := range []struct {
53 actualMax int
54 allFeatureSize int
55 }{
56 {128, 0},
57 {128, 128},
58 {256, 128},
59 {256, 256},
60 {512, 256},
61 {512, 512},
62 } {
63 gotMax, gotEmulated, gotHWClmul := configure(test.actualMax, test.allFeatureSize, "amd64", "1")
64 wantMax, wantEmulated, wantHWClmul := configure(test.actualMax, test.allFeatureSize, "amd64", "+")
65 if gotMax != wantMax || gotEmulated != wantEmulated || gotHWClmul != wantHWClmul {
66 t.Errorf("configure(%d, %d, 1) = (%d, %t, %t), want plain + result (%d, %t, %t)",
67 test.actualMax, test.allFeatureSize, gotMax, gotEmulated, gotHWClmul,
68 wantMax, wantEmulated, wantHWClmul)
69 }
70 }
71 }
72
73 func TestConfigureInvalidSize(t *testing.T) {
74 for _, test := range []struct {
75 value string
76 want string
77 }{
78 {"17", "not a supported vector size"},
79 {"64", "not a supported vector size"},
80 {"127", "not a supported vector size"},
81 {"129", "not a supported vector size"},
82 {"200", "not a supported vector size"},
83 {"+17", "not a supported vector size"},
84 {"-1", "is negative"},
85 {"abc", "could not parse"},
86 } {
87 t.Run(test.value, func(t *testing.T) {
88 defer func() {
89 got := recover()
90 if got == nil {
91 t.Fatalf("configure(512, 512, %q) did not panic", test.value)
92 }
93 if message := fmt.Sprint(got); !strings.Contains(message, test.want) {
94 t.Fatalf("configure(512, 512, %q) panicked with %q, want substring %q", test.value, message, test.want)
95 }
96 }()
97 configure(512, 512, "amd64", test.value)
98 })
99 }
100 }
101
View as plain text