From 52a4d4c06e8e82545993f42e547c79994febcde9 Mon Sep 17 00:00:00 2001 From: Jiri Olsa Date: Tue, 24 Dec 2024 22:23:12 +0000 Subject: [PATCH] tests fixes Signed-off-by: Jiri Olsa --- pkg/sensors/tracing/kprobe_test.go | 116 +++++++++++++++++------------ 1 file changed, 69 insertions(+), 47 deletions(-) diff --git a/pkg/sensors/tracing/kprobe_test.go b/pkg/sensors/tracing/kprobe_test.go index 1822c482d77..bf560653416 100644 --- a/pkg/sensors/tracing/kprobe_test.go +++ b/pkg/sensors/tracing/kprobe_test.go @@ -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 := ` @@ -6957,7 +6966,19 @@ 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 @@ -6965,6 +6986,7 @@ tetragon_missed_prog_probes_total{attach="sched/sched_process_exec",policy="__ba 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")))