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

Function TestUprobeProgramCall

link/uprobe_test.go:303–373  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

301}
302
303func TestUprobeProgramCall(t *testing.T) {
304 testutils.SkipOnOldKernel(t, "4.14", "uprobe on v4.9 returns EIO on vimto")
305
306 tests := []struct {
307 name string
308 elf string
309 args []string
310 sym string
311 }{
312 {
313 "bash",
314 "/bin/bash",
315 []string{"--help"},
316 "main",
317 },
318 {
319 "go-binary",
320 path.Join(build.Default.GOROOT, "bin/go"),
321 []string{"version"},
322 "main.main",
323 },
324 }
325
326 for _, tt := range tests {
327 t.Run(tt.name, func(t *testing.T) {
328 if tt.name == "go-binary" {
329 // https://github.com/cilium/ebpf/issues/406
330 testutils.SkipOnOldKernel(t, "4.14", "uprobes on Go binaries silently fail on kernel < 4.14")
331 }
332
333 m, p := newUpdaterMapProg(t, ebpf.Kprobe, 0)
334
335 // Load the executable.
336 ex, err := OpenExecutable(tt.elf)
337 qt.Assert(t, qt.IsNil(err))
338
339 // Open Uprobe on the executable for the given symbol
340 // and attach it to the ebpf program created above.
341 u, err := ex.Uprobe(tt.sym, p, nil)
342 if errors.Is(err, ErrNoSymbol) {
343 // Assume bash::main and go::main.main always exists
344 // and skip the test if the symbol can't be found as
345 // certain OS (eg. Debian) strip binaries.
346 t.Skipf("executable %s appear to be stripped, skipping", tt.elf)
347 }
348 qt.Assert(t, qt.IsNil(err))
349
350 // Trigger ebpf program call.
351 trigger := func(t *testing.T) {
352 qt.Assert(t, qt.IsNil(exec.Command(tt.elf, tt.args...).Run()))
353 }
354 trigger(t)
355
356 // Assert that the value got incremented to at least 1, while allowing
357 // for bigger values, because we could race with other bash execution.
358 assertMapValueGE(t, m, 0, 1)
359
360 // Detach the Uprobe.

Callers

nothing calls this directly

Calls 11

SkipOnOldKernelFunction · 0.92
newUpdaterMapProgFunction · 0.85
OpenExecutableFunction · 0.85
assertMapValueGEFunction · 0.85
assertMapValueFunction · 0.85
IsNilMethod · 0.80
RunMethod · 0.65
CloseMethod · 0.65
UpdateMethod · 0.65
UprobeMethod · 0.45
IsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…