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