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

Function TestUprobeMultiProgramCall

link/uprobe_multi_test.go:212–283  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

210}
211
212func TestUprobeMultiProgramCall(t *testing.T) {
213 testutils.SkipIfNotSupported(t, features.HaveBPFLinkUprobeMulti())
214
215 // We execute 'bash --help'
216 args := []string{"--help"}
217 elf := "/bin/bash"
218
219 test := func(retprobe bool, expected uint32) {
220 m, p := newUpdaterMapProg(t, ebpf.Kprobe, ebpf.AttachTraceUprobeMulti)
221
222 var err error
223
224 // Load the executable.
225 ex, err := OpenExecutable(elf)
226 if err != nil {
227 t.Fatal(err)
228 }
229
230 var um Link
231
232 // Open UprobeMulti on the executable for the given symbol
233 // and attach it to the ebpf program created above.
234 if retprobe {
235 um, err = ex.UretprobeMulti(bashSyms, p, nil)
236 } else {
237 um, err = ex.UprobeMulti(bashSyms, p, nil)
238 }
239 if errors.Is(err, ErrNoSymbol) {
240 // Assume bash_Syms symbols always exist and skip the test
241 // if the symbol can't be found as certain OS (eg. Debian)
242 // strip binaries.
243 t.Skipf("executable %s appear to be stripped, skipping", elf)
244 }
245 if err != nil {
246 t.Fatal(err)
247 }
248
249 // Trigger ebpf program call.
250 trigger := func(t *testing.T) {
251 if err := exec.Command(elf, args...).Run(); err != nil {
252 t.Fatal(err)
253 }
254 }
255 trigger(t)
256
257 // Detach link.
258 if err := um.Close(); err != nil {
259 t.Fatal(err)
260 }
261
262 assertMapValueGE(t, m, 0, expected)
263
264 // Reset map value to 0 at index 0.
265 if err := m.Update(uint32(0), uint32(0), ebpf.UpdateExist); err != nil {
266 t.Fatal(err)
267 }
268
269 // Retrigger the ebpf program call.

Callers

nothing calls this directly

Calls 12

CloseMethod · 0.95
SkipIfNotSupportedFunction · 0.92
HaveBPFLinkUprobeMultiFunction · 0.92
newUpdaterMapProgFunction · 0.85
OpenExecutableFunction · 0.85
assertMapValueGEFunction · 0.85
assertMapValueFunction · 0.85
UretprobeMultiMethod · 0.80
RunMethod · 0.65
UpdateMethod · 0.65
UprobeMultiMethod · 0.45
IsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…