Source file
src/runtime/vdso_linux_test.go
1
2
3
4
5
6
7 package runtime_test
8
9 import (
10 "runtime"
11 "testing"
12 )
13
14
15 func gnuHash(s string) uint32 {
16 h := uint32(5381)
17 for _, r := range s {
18 h = (h << 5) + h + uint32(r)
19 }
20 return h
21 }
22
23
24 func symHash(s string) uint32 {
25 var h, g uint32
26 for _, r := range s {
27 h = (h << 4) + uint32(r)
28 g = h & 0xf0000000
29 if g != 0 {
30 h ^= g >> 24
31 }
32 h &^= g
33 }
34 return h
35 }
36
37 func TestVDSOHash(t *testing.T) {
38 for _, sym := range runtime.VDSOSymbolKeys() {
39 name := sym.Name()
40 t.Run(name, func(t *testing.T) {
41 want := symHash(name)
42 if sym.SymHash() != want {
43 t.Errorf("SymHash got %#x want %#x", sym.SymHash(), want)
44 }
45
46 want = gnuHash(name)
47 if sym.GNUHash() != want {
48 t.Errorf("GNUHash got %#x want %#x", sym.GNUHash(), want)
49 }
50 })
51 }
52 }
53
View as plain text