github.com/google/syzkaller@v0.0.0-20240517125934-c0f1611a36d6/pkg/report/bsd_test.go (about) 1 // Copyright 2018 syzkaller project authors. All rights reserved. 2 // Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. 3 4 package report 5 6 import ( 7 "fmt" 8 "testing" 9 10 "github.com/google/syzkaller/pkg/symbolizer" 11 ) 12 13 type symbolizeLineTest struct { 14 line string 15 result string 16 } 17 18 func testSymbolizeLine(t *testing.T, ctor fn, tests []symbolizeLineTest) { 19 symbols := map[string][]symbolizer.Symbol{ 20 "closef": { 21 {Addr: 0x815088a0, Size: 0x12f}, 22 }, 23 "sleep_finish_all": { 24 {Addr: 0x81237520, Size: 0x173}, 25 }, 26 } 27 symb := func(bin string, pc uint64) ([]symbolizer.Frame, error) { 28 if bin != "bsd.gdb" { 29 return nil, fmt.Errorf("unknown pc 0x%x", pc) 30 } 31 32 switch pc & 0xffffffff { 33 case 0x8150894f: 34 return []symbolizer.Frame{ 35 { 36 Func: "closef", 37 File: "/bsd/src/kern_descrip.c", 38 Line: 1241, 39 }, 40 }, nil 41 case 0x81237542: 42 return []symbolizer.Frame{ 43 { 44 Func: "sleep_finish_timeout", 45 File: "/bsd/src/kern_synch.c", 46 Line: 336, 47 Inline: true, 48 }, 49 { 50 Func: "sleep_finish_all", 51 File: "/bsd/src/kern_synch.c", 52 Line: 157, 53 }, 54 }, nil 55 default: 56 return nil, fmt.Errorf("unknown pc 0x%x", pc) 57 } 58 } 59 reporter, _, err := ctor(&config{ 60 kernelSrc: "/bsd/src2", 61 kernelBuildSrc: "/bsd/src", 62 }) 63 if err != nil { 64 t.Fatal(err) 65 } 66 bsd := reporter.(*bsd) 67 bsd.symbols = symbols 68 bsd.kernelObject = "bsd.gdb" 69 for i, test := range tests { 70 t.Run(fmt.Sprint(i), func(t *testing.T) { 71 result := bsd.symbolizeLine(symb, []byte(test.line)) 72 if test.result != string(result) { 73 t.Errorf("want %q\n\t get %q", test.result, string(result)) 74 } 75 }) 76 } 77 }