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