MCPcopy
hub / github.com/cilium/ebpf / TestKprobeMultiProgramCall

Function TestKprobeMultiProgramCall

link/kprobe_multi_test.go:123–164  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

121}
122
123func TestKprobeMultiProgramCall(t *testing.T) {
124 testutils.SkipIfNotSupported(t, features.HaveBPFLinkKprobeMulti())
125
126 m, p := newUpdaterMapProg(t, ebpf.Kprobe, ebpf.AttachTraceKprobeMulti)
127
128 // Use actual syscall names with platform prefix.
129 // For simplicity, just assert the increment happens with any symbol in the array.
130 prefix := linux.PlatformPrefix()
131 opts := KprobeMultiOptions{
132 Symbols: []string{prefix + "sys_getpid", prefix + "sys_gettid"},
133 }
134 km, err := KprobeMulti(p, opts)
135 if err != nil {
136 t.Fatal(err)
137 }
138
139 // Trigger ebpf program call.
140 unix.Getpid()
141 unix.Gettid()
142
143 // Assert that the value got incremented to at least 2, while allowing
144 // for bigger values, because we could race with other getpid/gettid
145 // callers.
146 assertMapValueGE(t, m, 0, 2)
147
148 // Close the link.
149 if err := km.Close(); err != nil {
150 t.Fatal(err)
151 }
152
153 // Reset map value to 0 at index 0.
154 if err := m.Update(uint32(0), uint32(0), ebpf.UpdateExist); err != nil {
155 t.Fatal(err)
156 }
157
158 // Retrigger the ebpf program call.
159 unix.Getpid()
160 unix.Gettid()
161
162 // Assert that this time the value has not been updated.
163 assertMapValue(t, m, 0, 0)
164}
165
166func TestKprobeSession(t *testing.T) {
167 testutils.SkipIfNotSupported(t, features.HaveBPFLinkKprobeSession())

Callers

nothing calls this directly

Calls 11

SkipIfNotSupportedFunction · 0.92
HaveBPFLinkKprobeMultiFunction · 0.92
PlatformPrefixFunction · 0.92
GetpidFunction · 0.92
GettidFunction · 0.92
newUpdaterMapProgFunction · 0.85
KprobeMultiFunction · 0.85
assertMapValueGEFunction · 0.85
assertMapValueFunction · 0.85
CloseMethod · 0.65
UpdateMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…