github.com/google/syzkaller@v0.0.0-20240517125934-c0f1611a36d6/pkg/symbolizer/nm_test.go (about) 1 // Copyright 2016 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 symbolizer 5 6 import ( 7 "testing" 8 ) 9 10 func TestSymbols(t *testing.T) { 11 symb := NewSymbolizer(nil) 12 symbols, err := symb.ReadTextSymbols("testdata/nm.test.out") 13 if err != nil { 14 t.Fatalf("failed to read symbols: %v", err) 15 } 16 t.Logf("symbols: %+v", symbols) 17 if len(symbols) != 5 { 18 t.Fatalf("got %v symbols, want 5", len(symbols)) 19 } 20 { 21 s := symbols["barfoo"] 22 if len(s) != 1 { 23 t.Fatalf("got %v barfoo symbols, want 1", len(s)) 24 } 25 if s[0].Addr != 0x400507 { 26 t.Fatalf("bad barfoo address: 0x%x", s[0].Addr) 27 } 28 if s[0].Size != 0x30 { 29 t.Fatalf("bad barfoo size: 0x%x", s[0].Size) 30 } 31 } 32 { 33 s := symbols["foobar"] 34 if len(s) != 2 { 35 t.Fatalf("got %v foobar symbols, want 2", len(s)) 36 } 37 want := []Symbol{ 38 { 39 Addr: 0x4004fa, 40 Size: 0xd, 41 }, 42 { 43 Addr: 0x4004ed, 44 Size: 0xd, 45 }, 46 } 47 if !symcmp(want[0], s[0]) && !symcmp(want[0], s[1]) { 48 t.Fatalf("foobar symbol %+v not found", want[0]) 49 } 50 if !symcmp(want[1], s[0]) && !symcmp(want[1], s[1]) { 51 t.Fatalf("foobar symbol %+v not found", want[1]) 52 } 53 } 54 } 55 56 func symcmp(want, got Symbol) bool { 57 if want.Addr != got.Addr { 58 return false 59 } 60 if want.Size != got.Size { 61 return false 62 } 63 return true 64 }