(t *testing.T)
| 301 | } |
| 302 | |
| 303 | func 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. |
nothing calls this directly
no test coverage detected
searching dependent graphs…