/
vdso_test.go
74 lines (64 loc) · 1.41 KB
/
vdso_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package internal
import (
"errors"
"os"
"testing"
)
func TestAuxvVDSOMemoryAddress(t *testing.T) {
av, err := os.Open("../testdata/auxv.bin")
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { av.Close() })
addr, err := vdsoMemoryAddress(av)
if err != nil {
t.Fatal(err)
}
expected := uint64(0x7ffd377e5000)
if addr != expected {
t.Errorf("Expected vDSO memory address %x, got %x", expected, addr)
}
}
func TestAuxvNoVDSO(t *testing.T) {
// Copy of auxv.bin with the vDSO pointer removed.
av, err := os.Open("../testdata/auxv_no_vdso.bin")
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { av.Close() })
_, err = vdsoMemoryAddress(av)
if want, got := errAuxvNoVDSO, err; !errors.Is(got, want) {
t.Fatalf("expected error '%v', got: %v", want, got)
}
}
func TestLinuxVersionCodeEmbedded(t *testing.T) {
tests := []struct {
file string
version uint32
}{
{
"../testdata/vdso.bin",
uint32(328828), // 5.4.124
},
{
"../testdata/vdso_multiple_notes.bin",
uint32(328875), // Container Optimized OS v85 with a 5.4.x kernel
},
}
for _, test := range tests {
t.Run(test.file, func(t *testing.T) {
vdso, err := os.Open(test.file)
if err != nil {
t.Fatal(err)
}
defer vdso.Close()
vc, err := vdsoLinuxVersionCode(vdso)
if err != nil {
t.Fatal(err)
}
if vc != test.version {
t.Errorf("Expected version code %d, got %d", test.version, vc)
}
})
}
}