Debian Codegraph @

struct_ops_test.go

raw symbols SCIP
1 package ebpf
2
3 import (
4 "testing"
5
6 "github.com/go-quicktest/qt"
7
8 "github.com/cilium/ebpf/btf"
9 "github.com/cilium/ebpf/internal/sys"
10 "github.com/cilium/ebpf/internal/testutils"
11 )
12
13 func TestCreateStructOpsMapSpecSimple(t *testing.T) {
14 requireTestmodOps(t)
15
16 btfSpec, err := btf.LoadKernelModuleSpec("bpf_testmod")
17 qt.Assert(t, qt.IsNil(err))
18
19 var outerValueType *btf.Struct
20 qt.Assert(t, qt.IsNil(btfSpec.TypeByName(structOpsValuePrefix+"bpf_testmod_ops", &outerValueType)))
21
22 ms := &MapSpec{
23 Name: "testmod_ops",
24 Type: StructOpsMap,
25 Flags: sys.BPF_F_LINK,
26 Key: &btf.Int{Size: 4},
27 KeySize: 4,
28 Value: &btf.Struct{Name: "bpf_testmod_ops"},
29 MaxEntries: 1,
30 Contents: []MapKV{
31 {
32 Key: uint32(0),
33 Value: make([]byte, outerValueType.Size),
34 },
35 },
36 }
37
38 m, err := NewMap(ms)
39 testutils.SkipIfNotSupported(t, err)
40 qt.Assert(t, qt.IsNil(err))
41 t.Cleanup(func() { _ = m.Close() })
42 }