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

Function TestKprobeProgramCall

link/kprobe_test.go:268–300  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

266}
267
268func TestKprobeProgramCall(t *testing.T) {
269 m, p := newUpdaterMapProg(t, ebpf.Kprobe, 0)
270
271 // Open Kprobe on `sys_getpid` and attach it
272 // to the ebpf program created above.
273 k, err := Kprobe("sys_getpid", p, nil)
274 if err != nil {
275 t.Fatal(err)
276 }
277
278 // Trigger ebpf program call.
279 unix.Getpid()
280
281 // Assert that the value got incremented to at least 1, while allowing
282 // for bigger values, because we could race with other getpid callers.
283 assertMapValueGE(t, m, 0, 1)
284
285 // Detach the Kprobe.
286 if err := k.Close(); err != nil {
287 t.Fatal(err)
288 }
289
290 // Reset map value to 0 at index 0.
291 if err := m.Update(uint32(0), uint32(0), ebpf.UpdateExist); err != nil {
292 t.Fatal(err)
293 }
294
295 // Retrigger the ebpf program call.
296 unix.Getpid()
297
298 // Assert that this time the value has not been updated.
299 assertMapValue(t, m, 0, 0)
300}
301
302func newUpdaterMapProg(t *testing.T, typ ebpf.ProgramType, attach ebpf.AttachType) (*ebpf.Map, *ebpf.Program) {
303 // Create ebpf map. Will contain only one key with initial value 0.

Callers

nothing calls this directly

Calls 7

GetpidFunction · 0.92
newUpdaterMapProgFunction · 0.85
KprobeFunction · 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…