From 94564fa227e3876af9d7996c1c0646d782f94141 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=9D=80=EB=B9=88?= Date: Sat, 6 Apr 2024 17:15:16 +0000 Subject: [PATCH] chore: Move mock struct to test file (#3177) --- ebpf/symtab/table.go | 36 ----------------------------------- ebpf/symtab/table_test.go | 40 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 37 deletions(-) diff --git a/ebpf/symtab/table.go b/ebpf/symtab/table.go index 1583e59f18..1f18815bf9 100644 --- a/ebpf/symtab/table.go +++ b/ebpf/symtab/table.go @@ -4,42 +4,6 @@ import ( "sort" ) -type SymTab struct { - Symbols []Sym - base uint64 -} - -type Sym struct { - Start uint64 - Name string -} - -func NewSymTab(symbols []Sym) *SymTab { - return &SymTab{Symbols: symbols} -} - -func (t *SymTab) Rebase(base uint64) { - t.base = base -} - -func (t *SymTab) Resolve(addr uint64) *Sym { - if len(t.Symbols) == 0 { - return nil - } - addr -= t.base - if addr < t.Symbols[0].Start { - return nil - } - i := sort.Search(len(t.Symbols), func(i int) bool { - return addr < t.Symbols[i].Start - }) - i-- - return &t.Symbols[i] -} -func (t *SymTab) Length() int { - return len(t.Symbols) -} - type SymbolTab struct { symbols []Symbol base uint64 diff --git a/ebpf/symtab/table_test.go b/ebpf/symtab/table_test.go index 552a6d010f..a3f646f7a4 100644 --- a/ebpf/symtab/table_test.go +++ b/ebpf/symtab/table_test.go @@ -1,13 +1,51 @@ package symtab import ( + "sort" "testing" "github.com/stretchr/testify/require" ) +type MockSymTab struct { + Symbols []MockSym + base uint64 +} + +type MockSym struct { + Start uint64 + Name string +} + +func NewSymTab(symbols []MockSym) *MockSymTab { + return &MockSymTab{Symbols: symbols} +} + +func (t *MockSymTab) Rebase(base uint64) { + t.base = base +} + +func (t *MockSymTab) Resolve(addr uint64) *MockSym { + if len(t.Symbols) == 0 { + return nil + } + addr -= t.base + if addr < t.Symbols[0].Start { + return nil + } + i := sort.Search(len(t.Symbols), func(i int) bool { + return addr < t.Symbols[i].Start + }) + i-- + return &t.Symbols[i] +} + +func (t *MockSymTab) Length() int { + return len(t.Symbols) +} + func TestSymTab(t *testing.T) { - sym := NewSymTab([]Sym{ + sym := NewSymTab([]MockSym{ {0x1000, "0x1000"}, {0x1200, "0x1200"}, {0x1300, "0x1300"},