aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/symbolizer/nm_test.go
blob: 482f717fa0a66e617937d63b0548afe3896cfbdd (plain)
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
// Copyright 2016 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 symbolizer

import (
	"testing"
)

func TestSymbols(t *testing.T) {
	symb := NewSymbolizer(nil)
	symbols, err := symb.ReadTextSymbols("testdata/nm.test.out")
	if err != nil {
		t.Fatalf("failed to read symbols: %v", err)
	}
	if len(symbols) != 5 {
		t.Fatalf("got %v symbols, want 5", len(symbols))
	}
	{
		s := symbols["barfoo"]
		if len(s) != 1 {
			t.Fatalf("got %v barfoo symbols, want 1", len(s))
		}
		if s[0].Addr != 0x400507 {
			t.Fatalf("bad barfoo address: 0x%x", s[0].Addr)
		}
		if s[0].Size != 0x30 {
			t.Fatalf("bad barfoo size: 0x%x", s[0].Size)
		}
	}
	{
		s := symbols["foobar"]
		if len(s) != 2 {
			t.Fatalf("got %v foobar symbols, want 2", len(s))
		}
		want := []Symbol{
			{
				Addr: 0x4004fa,
				Size: 0x10,
			},
			{
				Addr: 0x4004ed,
				Size: 0x10,
			},
		}
		if !symcmp(want[0], s[0]) && !symcmp(want[0], s[1]) {
			t.Fatalf("foobar symbol %+v not found", want[0])
		}
		if !symcmp(want[1], s[0]) && !symcmp(want[1], s[1]) {
			t.Fatalf("foobar symbol %+v not found", want[1])
		}
	}
}

func symcmp(want, got Symbol) bool {
	if want.Addr != got.Addr {
		return false
	}
	if want.Size != got.Size {
		return false
	}
	return true
}