...
1
2
3
4
5
6
7 package sha3_test
8
9 import (
10 "runtime"
11 "testing"
12
13 "golang.org/x/crypto/sha3"
14 )
15
16 var sink byte
17
18 func TestAllocations(t *testing.T) {
19 want := 0.0
20
21 if runtime.GOARCH == "s390x" {
22
23 want = 3.0
24 }
25
26 t.Run("New", func(t *testing.T) {
27 if allocs := testing.AllocsPerRun(10, func() {
28 h := sha3.New256()
29 b := []byte("ABC")
30 h.Write(b)
31 out := make([]byte, 0, 32)
32 out = h.Sum(out)
33 sink ^= out[0]
34 }); allocs > want {
35 t.Errorf("expected zero allocations, got %0.1f", allocs)
36 }
37 })
38 t.Run("NewShake", func(t *testing.T) {
39 if allocs := testing.AllocsPerRun(10, func() {
40 h := sha3.NewShake128()
41 b := []byte("ABC")
42 h.Write(b)
43 out := make([]byte, 0, 32)
44 out = h.Sum(out)
45 sink ^= out[0]
46 h.Read(out)
47 sink ^= out[0]
48 }); allocs > want {
49 t.Errorf("expected zero allocations, got %0.1f", allocs)
50 }
51 })
52 t.Run("Sum", func(t *testing.T) {
53 if allocs := testing.AllocsPerRun(10, func() {
54 b := []byte("ABC")
55 out := sha3.Sum256(b)
56 sink ^= out[0]
57 }); allocs > want {
58 t.Errorf("expected zero allocations, got %0.1f", allocs)
59 }
60 })
61 }
62
View as plain text