Debian Codegraph @

btf/ext_info_test.go

raw symbols SCIP
1 package btf
2
3 import (
4 "bytes"
5 "encoding/binary"
6 "strings"
7 "testing"
8
9 "github.com/cilium/ebpf/internal"
10
11 "github.com/go-quicktest/qt"
12 )
13
14 func TestParseExtInfoBigRecordSize(t *testing.T) {
15 rd := strings.NewReader("\xff\xff\xff\xff\x00\x00\x00\x000709171295166016")
16 table, err := readStringTable(bytes.NewReader([]byte{0}), nil)
17 if err != nil {
18 t.Fatal(err)
19 }
20
21 if _, err := parseFuncInfos(rd, internal.NativeEndian, table); err == nil {
22 t.Error("Parsing func info with large record size doesn't return an error")
23 }
24
25 if _, err := parseLineInfos(rd, internal.NativeEndian, table); err == nil {
26 t.Error("Parsing line info with large record size doesn't return an error")
27 }
28 }
29
30 func BenchmarkParseLineInfoRecords(b *testing.B) {
31 size := uint32(binary.Size(bpfLineInfo{}))
32 count := uint32(4096)
33 buf := make([]byte, size*count)
34
35 b.ReportAllocs()
36
37 for b.Loop() {
38 parseLineInfoRecords(bytes.NewReader(buf), internal.NativeEndian, size, count, true)
39 }
40 }
41
42 func TestParseLineInfoRecordsAllocations(t *testing.T) {
43 size := uint32(binary.Size(bpfLineInfo{}))
44 count := uint32(4096)
45 buf := make([]byte, size*count)
46
47 allocs := testing.AllocsPerRun(5, func() {
48 parseLineInfoRecords(bytes.NewReader(buf), internal.NativeEndian, size, count, true)
49 })
50
51 // 9 is the number of allocations on go 1.26
52 // what we want to test is that we are not allocating
53 // once per record
54 qt.Assert(t, qt.IsTrue(allocs <= 9))
55 }