-
Notifications
You must be signed in to change notification settings - Fork 2
/
openbsd_test.go
101 lines (96 loc) · 2.35 KB
/
openbsd_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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Copyright 2018 syzkaller project authors. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
package report
import (
"fmt"
"testing"
"github.com/google/syzkaller/pkg/symbolizer"
)
func TestOpenbsdSymbolizeLine(t *testing.T) {
tests := []struct {
line string
result string
}{
// Normal symbolization.
{
"closef(ffffffff,ffffffff) at closef+0xaf\n",
"closef(ffffffff,ffffffff) at closef+0xaf kern_descrip.c:1241\n",
},
// Inlined frames.
{
"sleep_finish_all(ffffffff,32) at sleep_finish_all+0x22\n",
"sleep_finish_all(ffffffff,32) at sleep_finish_all+0x22 sleep_finish_timeout kern_synch.c:336 [inline]\n" +
"sleep_finish_all(ffffffff,32) at sleep_finish_all+0x22 kern_synch.c:157\n",
},
// Missing symbol.
{
"foo(ffffffff,ffffffff) at foo+0x1e",
"foo(ffffffff,ffffffff) at foo+0x1e",
},
// Witness symbolization.
{
"#4 closef+0xaf\n",
"#4 closef+0xaf kern_descrip.c:1241\n",
},
{
"#10 closef+0xaf\n",
"#10 closef+0xaf kern_descrip.c:1241\n",
},
}
symbols := map[string][]symbolizer.Symbol{
"closef": {
{Addr: 0x815088a0, Size: 0x12f},
},
"sleep_finish_all": {
{Addr: 0x81237520, Size: 0x173},
},
}
symb := func(bin string, pc uint64) ([]symbolizer.Frame, error) {
if bin != "bsd.gdb" {
return nil, fmt.Errorf("unknown pc 0x%x", pc)
}
switch pc & 0xffffffff {
case 0x8150894f:
return []symbolizer.Frame{
{
File: "/usr/src/kern_descrip.c",
Line: 1241,
Func: "closef",
},
}, nil
case 0x81237542:
return []symbolizer.Frame{
{
Func: "sleep_finish_timeout",
File: "/usr/src/kern_synch.c",
Line: 336,
Inline: true,
},
{
Func: "sleep_finish_all",
File: "/usr/src/kern_synch.c",
Line: 157,
},
}, nil
default:
return nil, fmt.Errorf("unknown pc 0x%x", pc)
}
}
obsd := openbsd{
config: &config{
kernelSrc: "/usr/src2",
kernelBuildSrc: "/usr/src",
kernelObj: "/usr/src/sys/arch/amd64/compile/SYZKALLER/obj",
},
kernelObject: "bsd.gdb",
symbols: symbols,
}
for i, test := range tests {
t.Run(fmt.Sprint(i), func(t *testing.T) {
result := obsd.symbolizeLine(symb, []byte(test.line))
if test.result != string(result) {
t.Errorf("want %q\n\t get %q", test.result, string(result))
}
})
}
}