github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/pkg/agent/ebpfspy/symtab/simple_test.go (about)

     1  package symtab
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"testing"
     7  )
     8  
     9  func TestResolving(t *testing.T) {
    10  	sym := NewSimpleSymbolTable([]SimpleSymbolTableEntry{
    11  		{0x1000, 0x1200, "0x1000"},
    12  		{0x1200, 0x1300, "0x1200"},
    13  		{0x1300, 0x3000, "0x1300"},
    14  	})
    15  	expect := func(expected string, at uint64) {
    16  		s := sym.Resolve(at)
    17  		if s != expected {
    18  			t.Fatalf("Expected %s got %s", expected, s)
    19  		}
    20  	}
    21  	bases := []uint64{0, 0x4000}
    22  	cases := []struct {
    23  		expected string
    24  		addr     uint64
    25  	}{
    26  		{"", 0xef},
    27  		{"0x1000", 0x1000},
    28  		{"0x1000", 0x1100},
    29  		{"0x1000", 0x11FF},
    30  		{"0x1200", 0x1200},
    31  		{"0x1200", 0x12FF},
    32  		{"0x1300", 0x1300},
    33  		{"0x1300", 0x2FFF},
    34  		{"", 0x3000},
    35  		{"", 0x4000},
    36  	}
    37  	for _, base := range bases {
    38  		for _, c := range cases {
    39  			t.Run(fmt.Sprintf("base %x c %v", base, c), func(t *testing.T) {
    40  				sym.Rebase(base)
    41  				expect(c.expected, base+c.addr)
    42  			})
    43  		}
    44  	}
    45  }