-
Notifications
You must be signed in to change notification settings - Fork 711
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
link: add test for uprobe multi link
This commit adds test for uprobe multi link. Signed-off-by: Jiri Olsa <jolsa@kernel.org>
- Loading branch information
Showing
2 changed files
with
198 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
package link | ||
|
||
import ( | ||
"errors" | ||
"os/exec" | ||
"testing" | ||
|
||
"github.com/cilium/ebpf" | ||
"github.com/cilium/ebpf/internal/testutils" | ||
"github.com/cilium/ebpf/internal/unix" | ||
) | ||
|
||
func TestUprobeMulti(t *testing.T) { | ||
testutils.SkipIfNotSupported(t, haveBPFLinkUprobeMulti()) | ||
|
||
prog := mustLoadProgram(t, ebpf.Kprobe, ebpf.AttachTraceUprobeMulti, "") | ||
|
||
um, err := bashEx.UprobeMulti([]string{"bash_logout", "main"}, prog, nil) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer um.Close() | ||
|
||
testLink(t, um, prog) | ||
} | ||
|
||
func TestUprobeMultiInput(t *testing.T) { | ||
testutils.SkipIfNotSupported(t, haveBPFLinkUprobeMulti()) | ||
|
||
prog := mustLoadProgram(t, ebpf.Kprobe, ebpf.AttachTraceUprobeMulti, "") | ||
|
||
// One of Symbols or Addresses must be given. | ||
_, err := bashEx.UprobeMulti([]string{}, prog, nil) | ||
if !errors.Is(err, errInvalidInput) { | ||
t.Fatalf("expected errInvalidInput, got: %v", err) | ||
} | ||
|
||
// One Symbol, two cookies.. | ||
_, err = bashEx.UprobeMulti([]string{}, prog, &UprobeMultiOptions{ | ||
Offsets: []uint64{1}, | ||
Cookies: []uint64{2, 3}, | ||
}) | ||
if !errors.Is(err, errInvalidInput) { | ||
t.Fatalf("expected errInvalidInput, got: %v", err) | ||
} | ||
} | ||
|
||
func TestUprobeMultiErrors(t *testing.T) { | ||
testutils.SkipIfNotSupported(t, haveBPFLinkUprobeMulti()) | ||
|
||
prog := mustLoadProgram(t, ebpf.Kprobe, ebpf.AttachTraceUprobeMulti, "") | ||
|
||
// Wrong offset | ||
um, err := bashEx.UprobeMulti([]string{}, prog, &UprobeMultiOptions{Offsets: []uint64{1<<64 - 1}}) | ||
if !errors.Is(err, unix.EINVAL) { | ||
um.Close() | ||
t.Skipf("need kernel change, skipping for now, expected EINVAL, got: %s", err) | ||
} | ||
} | ||
|
||
func TestUprobeMultiCookie(t *testing.T) { | ||
testutils.SkipIfNotSupported(t, haveBPFLinkUprobeMulti()) | ||
|
||
prog := mustLoadProgram(t, ebpf.Kprobe, ebpf.AttachTraceUprobeMulti, "") | ||
|
||
um, err := bashEx.UprobeMulti([]string{"bash_logout", "main"}, prog, | ||
&UprobeMultiOptions{ | ||
Cookies: []uint64{1, 2}, | ||
}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
_ = um.Close() | ||
} | ||
|
||
func TestUprobeMultiProgramCall(t *testing.T) { | ||
testutils.SkipIfNotSupported(t, haveBPFLinkUprobeMulti()) | ||
|
||
args := []string{"--help"} | ||
elf := "/bin/bash" | ||
|
||
m, p := newUpdaterMapIncProg(t, ebpf.Kprobe, ebpf.AttachTraceUprobeMulti) | ||
|
||
// Load the executable. | ||
ex, err := OpenExecutable(elf) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
// Open UprobeMulti on the executable for the given symbol | ||
// and attach it to the ebpf program created above. | ||
um, err := ex.UprobeMulti([]string{"main", "_start"}, p, nil) | ||
if errors.Is(err, ErrNoSymbol) { | ||
// Assume bash::main and go::main.main always exists | ||
// and skip the test if the symbol can't be found as | ||
// certain OS (eg. Debian) strip binaries. | ||
t.Skipf("executable %s appear to be stripped, skipping", elf) | ||
} | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
// Trigger ebpf program call. | ||
trigger := func(t *testing.T) { | ||
if err := exec.Command(elf, args...).Run(); err != nil { | ||
t.Fatal(err) | ||
} | ||
} | ||
trigger(t) | ||
|
||
// Assert that the value at index 0 has been updated to 2. | ||
assertMapValue(t, m, 0, 2) | ||
|
||
// Detach the Uprobe. | ||
if err := um.Close(); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
// Reset map value to 0 at index 0. | ||
if err := m.Update(uint32(0), uint32(0), ebpf.UpdateExist); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
// Retrigger the ebpf program call. | ||
trigger(t) | ||
|
||
// Assert that this time the value has not been updated. | ||
assertMapValue(t, m, 0, 0) | ||
} | ||
|
||
func TestHaveBPFLinkUprobeMulti(t *testing.T) { | ||
testutils.CheckFeatureTest(t, haveBPFLinkUprobeMulti) | ||
} |