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