Skip to content

Commit

Permalink
tests fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
  • Loading branch information
olsajiri committed Dec 25, 2024
1 parent 38c0478 commit 52a4d4c
Showing 1 changed file with 69 additions and 47 deletions.
116 changes: 69 additions & 47 deletions pkg/sensors/tracing/kprobe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4327,64 +4327,73 @@ spec:
}

func TestLoadKprobeSensor(t *testing.T) {
var sensorProgs = []tus.SensorProg{
// kprobe
0: tus.SensorProg{Name: "generic_kprobe_event", Type: ebpf.Kprobe},
1: tus.SensorProg{Name: "generic_kprobe_setup_event", Type: ebpf.Kprobe},
2: tus.SensorProg{Name: "generic_kprobe_process_event", Type: ebpf.Kprobe},
3: tus.SensorProg{Name: "generic_kprobe_filter_arg", Type: ebpf.Kprobe},
4: tus.SensorProg{Name: "generic_kprobe_process_filter", Type: ebpf.Kprobe},
5: tus.SensorProg{Name: "generic_kprobe_actions", Type: ebpf.Kprobe},
6: tus.SensorProg{Name: "generic_kprobe_output", Type: ebpf.Kprobe},
// retkprobe
7: tus.SensorProg{Name: "generic_retkprobe_event", Type: ebpf.Kprobe},
8: tus.SensorProg{Name: "generic_retkprobe_filter_arg", Type: ebpf.Kprobe},
9: tus.SensorProg{Name: "generic_retkprobe_actions", Type: ebpf.Kprobe},
10: tus.SensorProg{Name: "generic_retkprobe_output", Type: ebpf.Kprobe},
}
var (
sensorProgs []tus.SensorProg
sensorMaps []tus.SensorMap
)

var sensorMaps = []tus.SensorMap{
// all kprobe programs
tus.SensorMap{Name: "process_call_heap", Progs: []uint{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}},
if bpf.HasKprobeSession() {
t.Skip("KRAVA")
} else {
sensorProgs = []tus.SensorProg{
// kprobe
0: tus.SensorProg{Name: "generic_kprobe_event", Type: ebpf.Kprobe},
1: tus.SensorProg{Name: "generic_kprobe_setup_event", Type: ebpf.Kprobe},
2: tus.SensorProg{Name: "generic_kprobe_process_event", Type: ebpf.Kprobe},
3: tus.SensorProg{Name: "generic_kprobe_filter_arg", Type: ebpf.Kprobe},
4: tus.SensorProg{Name: "generic_kprobe_process_filter", Type: ebpf.Kprobe},
5: tus.SensorProg{Name: "generic_kprobe_actions", Type: ebpf.Kprobe},
6: tus.SensorProg{Name: "generic_kprobe_output", Type: ebpf.Kprobe},
// retkprobe
7: tus.SensorProg{Name: "generic_retkprobe_event", Type: ebpf.Kprobe},
8: tus.SensorProg{Name: "generic_retkprobe_filter_arg", Type: ebpf.Kprobe},
9: tus.SensorProg{Name: "generic_retkprobe_actions", Type: ebpf.Kprobe},
10: tus.SensorProg{Name: "generic_retkprobe_output", Type: ebpf.Kprobe},
}

// all but generic_kprobe_output
tus.SensorMap{Name: "kprobe_calls", Progs: []uint{0, 1, 2, 3, 4, 5}},
sensorMaps = []tus.SensorMap{
// all kprobe programs
tus.SensorMap{Name: "process_call_heap", Progs: []uint{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}},

// generic_retkprobe_event
tus.SensorMap{Name: "retkprobe_calls", Progs: []uint{7, 8, 9}},
// all but generic_kprobe_output
tus.SensorMap{Name: "kprobe_calls", Progs: []uint{0, 1, 2, 3, 4, 5}},

// generic_kprobe_process_filter,generic_kprobe_filter_arg,
// generic_kprobe_actions,generic_kprobe_output
tus.SensorMap{Name: "filter_map", Progs: []uint{3, 4, 5}},
// generic_retkprobe_event
tus.SensorMap{Name: "retkprobe_calls", Progs: []uint{7, 8, 9}},

// generic_kprobe_actions
tus.SensorMap{Name: "override_tasks", Progs: []uint{5}},
// generic_kprobe_process_filter,generic_kprobe_filter_arg,
// generic_kprobe_actions,generic_kprobe_output
tus.SensorMap{Name: "filter_map", Progs: []uint{3, 4, 5}},

// all kprobe but generic_kprobe_process_filter,generic_retkprobe_event
tus.SensorMap{Name: "config_map", Progs: []uint{0, 1, 2}},
// generic_kprobe_actions
tus.SensorMap{Name: "override_tasks", Progs: []uint{5}},

// generic_kprobe_process_event*,generic_kprobe_actions,retkprobe
tus.SensorMap{Name: "fdinstall_map", Progs: []uint{1, 2, 5, 7, 9}},
// all kprobe but generic_kprobe_process_filter,generic_retkprobe_event
tus.SensorMap{Name: "config_map", Progs: []uint{0, 1, 2}},

// generic_kprobe_event
tus.SensorMap{Name: "tg_conf_map", Progs: []uint{0}},
}
// generic_kprobe_process_event*,generic_kprobe_actions,retkprobe
tus.SensorMap{Name: "fdinstall_map", Progs: []uint{1, 2, 5, 7, 9}},

if kernels.EnableLargeProgs() {
// shared with base sensor
sensorMaps = append(sensorMaps, tus.SensorMap{Name: "execve_map", Progs: []uint{4, 5, 6, 7, 9}})
// generic_kprobe_event
tus.SensorMap{Name: "tg_conf_map", Progs: []uint{0}},
}

// generic_kprobe_process_event*,generic_kprobe_output,generic_retkprobe_output
sensorMaps = append(sensorMaps, tus.SensorMap{Name: "tcpmon_map", Progs: []uint{1, 2, 6, 10}})
if kernels.EnableLargeProgs() {
// shared with base sensor
sensorMaps = append(sensorMaps, tus.SensorMap{Name: "execve_map", Progs: []uint{4, 5, 6, 7, 9}})

// generic_kprobe_process_event*,generic_kprobe_actions,retkprobe
sensorMaps = append(sensorMaps, tus.SensorMap{Name: "socktrack_map", Progs: []uint{1, 2, 5, 7, 9}})
} else {
// shared with base sensor
sensorMaps = append(sensorMaps, tus.SensorMap{Name: "execve_map", Progs: []uint{4, 7}})
// generic_kprobe_process_event*,generic_kprobe_output,generic_retkprobe_output
sensorMaps = append(sensorMaps, tus.SensorMap{Name: "tcpmon_map", Progs: []uint{1, 2, 6, 10}})

// generic_kprobe_output,generic_retkprobe_output
sensorMaps = append(sensorMaps, tus.SensorMap{Name: "tcpmon_map", Progs: []uint{6, 10}})
// generic_kprobe_process_event*,generic_kprobe_actions,retkprobe
sensorMaps = append(sensorMaps, tus.SensorMap{Name: "socktrack_map", Progs: []uint{1, 2, 5, 7, 9}})
} else {
// shared with base sensor
sensorMaps = append(sensorMaps, tus.SensorMap{Name: "execve_map", Progs: []uint{4, 7}})

// generic_kprobe_output,generic_retkprobe_output
sensorMaps = append(sensorMaps, tus.SensorMap{Name: "tcpmon_map", Progs: []uint{6, 10}})
}
}

readHook := `
Expand Down Expand Up @@ -6957,14 +6966,27 @@ spec:
fmt.Printf("Failed to execute test binary: %s\n", err)
}

expected := strings.NewReader(` # HELP tetragon_missed_prog_probes_total The total number of Tetragon probe missed by program.
var expected *strings.Reader

if bpf.HasKprobeSession() {
expected = strings.NewReader(` # HELP tetragon_missed_prog_probes_total The total number of Tetragon probe missed by program.
# TYPE tetragon_missed_prog_probes_total counter
tetragon_missed_prog_probes_total{attach="acct_process",policy="__base__"} 0
tetragon_missed_prog_probes_total{attach="kprobe_session (2 functions)",policy="syswritefollowfdpsswd"} 2
tetragon_missed_prog_probes_total{attach="sched/sched_process_exec",policy="__base__"} 0
tetragon_missed_prog_probes_total{attach="security_bprm_committing_creds",policy="__base__"} 0
tetragon_missed_prog_probes_total{attach="wake_up_new_task",policy="__base__"} 0
`)
} else {
expected = strings.NewReader(` # HELP tetragon_missed_prog_probes_total The total number of Tetragon probe missed by program.
# TYPE tetragon_missed_prog_probes_total counter
tetragon_missed_prog_probes_total{attach="acct_process",policy="__base__"} 0
tetragon_missed_prog_probes_total{attach="kprobe_multi (2 functions)",policy="syswritefollowfdpsswd"} 1
tetragon_missed_prog_probes_total{attach="sched/sched_process_exec",policy="__base__"} 0
tetragon_missed_prog_probes_total{attach="security_bprm_committing_creds",policy="__base__"} 0
tetragon_missed_prog_probes_total{attach="wake_up_new_task",policy="__base__"} 0
`)
}

assert.NoError(t, testutil.GatherAndCompare(metricsconfig.GetRegistry(), expected,
prometheus.BuildFQName(consts.MetricsNamespace, "", "missed_prog_probes_total")))
Expand Down

0 comments on commit 52a4d4c

Please sign in to comment.