forked from krhancoc/syzkaller
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bsd_test.go
77 lines (71 loc) · 1.66 KB
/
bsd_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
// 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"
)
type symbolizeLineTest struct {
line string
result string
}
func testSymbolizeLine(t *testing.T, ctor fn, tests []symbolizeLineTest) {
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{
{
Func: "closef",
File: "/bsd/src/kern_descrip.c",
Line: 1241,
},
}, nil
case 0x81237542:
return []symbolizer.Frame{
{
Func: "sleep_finish_timeout",
File: "/bsd/src/kern_synch.c",
Line: 336,
Inline: true,
},
{
Func: "sleep_finish_all",
File: "/bsd/src/kern_synch.c",
Line: 157,
},
}, nil
default:
return nil, fmt.Errorf("unknown pc 0x%x", pc)
}
}
reporter, _, err := ctor(&config{
kernelSrc: "/bsd/src2",
kernelBuildSrc: "/bsd/src",
})
if err != nil {
t.Fatal(err)
}
bsd := reporter.(*bsd)
bsd.symbols = symbols
bsd.kernelObject = "bsd.gdb"
for i, test := range tests {
t.Run(fmt.Sprint(i), func(t *testing.T) {
result := bsd.symbolizeLine(symb, []byte(test.line))
if test.result != string(result) {
t.Errorf("want %q\n\t get %q", test.result, string(result))
}
})
}
}