...
1
2
3
4 package xxhash
5
6 import (
7 "os/exec"
8 "sort"
9 "strings"
10 "testing"
11 )
12
13 func TestStringAllocs(t *testing.T) {
14 longStr := strings.Repeat("a", 1000)
15 t.Run("Sum64String", func(t *testing.T) {
16 testAllocs(t, func() {
17 sink = Sum64String(longStr)
18 })
19 })
20 t.Run("Digest.WriteString", func(t *testing.T) {
21 testAllocs(t, func() {
22 d := New()
23 d.WriteString(longStr)
24 sink = d.Sum64()
25 })
26 })
27 }
28
29
30
31 func TestInlining(t *testing.T) {
32 funcs := map[string]struct{}{
33 "Sum64String": {},
34 "(*Digest).WriteString": {},
35 }
36
37 cmd := exec.Command("go", "test", "-gcflags=-m", "-run", "xxxx")
38 out, err := cmd.CombinedOutput()
39 if err != nil {
40 t.Log(string(out))
41 t.Fatal(err)
42 }
43
44 for _, line := range strings.Split(string(out), "\n") {
45 parts := strings.Split(line, ": can inline")
46 if len(parts) < 2 {
47 continue
48 }
49 delete(funcs, strings.TrimSpace(parts[1]))
50 }
51
52 var failed []string
53 for fn := range funcs {
54 failed = append(failed, fn)
55 }
56 sort.Strings(failed)
57 for _, fn := range failed {
58 t.Errorf("function %s not inlined", fn)
59 }
60 }
61
View as plain text