|
7 | 7 | #include "uprobe_multi_bench.skel.h"
|
8 | 8 | #include "uprobe_multi_usdt.skel.h"
|
9 | 9 | #include "uprobe_multi_consumers.skel.h"
|
| 10 | +#include "uprobe_multi_pid_filter.skel.h" |
10 | 11 | #include "bpf/libbpf_internal.h"
|
11 | 12 | #include "testing_helpers.h"
|
12 | 13 | #include "../sdt.h"
|
@@ -935,6 +936,70 @@ static void test_consumers(void)
|
935 | 936 | uprobe_multi_consumers__destroy(skel);
|
936 | 937 | }
|
937 | 938 |
|
| 939 | +static struct bpf_program *uprobe_multi_program(struct uprobe_multi_pid_filter *skel, int idx) |
| 940 | +{ |
| 941 | + switch (idx) { |
| 942 | + case 0: return skel->progs.uprobe_multi_0; |
| 943 | + case 1: return skel->progs.uprobe_multi_1; |
| 944 | + case 2: return skel->progs.uprobe_multi_2; |
| 945 | + } |
| 946 | + return NULL; |
| 947 | +} |
| 948 | + |
| 949 | +#define TASKS 3 |
| 950 | + |
| 951 | +static void run_pid_filter(struct uprobe_multi_pid_filter *skel, bool retprobe) |
| 952 | +{ |
| 953 | + LIBBPF_OPTS(bpf_uprobe_multi_opts, opts, .retprobe = retprobe); |
| 954 | + struct bpf_link *link[TASKS] = {}; |
| 955 | + struct child child[TASKS] = {}; |
| 956 | + int i; |
| 957 | + |
| 958 | + memset(skel->bss->test, 0, sizeof(skel->bss->test)); |
| 959 | + |
| 960 | + for (i = 0; i < TASKS; i++) { |
| 961 | + if (!ASSERT_OK(spawn_child(&child[i]), "spawn_child")) |
| 962 | + goto cleanup; |
| 963 | + skel->bss->pids[i] = child[i].pid; |
| 964 | + } |
| 965 | + |
| 966 | + for (i = 0; i < TASKS; i++) { |
| 967 | + link[i] = bpf_program__attach_uprobe_multi(uprobe_multi_program(skel, i), |
| 968 | + child[i].pid, "/proc/self/exe", |
| 969 | + "uprobe_multi_func_1", &opts); |
| 970 | + if (!ASSERT_OK_PTR(link[i], "bpf_program__attach_uprobe_multi")) |
| 971 | + goto cleanup; |
| 972 | + } |
| 973 | + |
| 974 | + for (i = 0; i < TASKS; i++) |
| 975 | + kick_child(&child[i]); |
| 976 | + |
| 977 | + for (i = 0; i < TASKS; i++) { |
| 978 | + ASSERT_EQ(skel->bss->test[i][0], 1, "pid"); |
| 979 | + ASSERT_EQ(skel->bss->test[i][1], 0, "unknown"); |
| 980 | + } |
| 981 | + |
| 982 | +cleanup: |
| 983 | + for (i = 0; i < TASKS; i++) |
| 984 | + bpf_link__destroy(link[i]); |
| 985 | + for (i = 0; i < TASKS; i++) |
| 986 | + release_child(&child[i]); |
| 987 | +} |
| 988 | + |
| 989 | +static void test_pid_filter_process(void) |
| 990 | +{ |
| 991 | + struct uprobe_multi_pid_filter *skel; |
| 992 | + |
| 993 | + skel = uprobe_multi_pid_filter__open_and_load(); |
| 994 | + if (!ASSERT_OK_PTR(skel, "uprobe_multi_pid_filter__open_and_load")) |
| 995 | + return; |
| 996 | + |
| 997 | + run_pid_filter(skel, false); |
| 998 | + run_pid_filter(skel, true); |
| 999 | + |
| 1000 | + uprobe_multi_pid_filter__destroy(skel); |
| 1001 | +} |
| 1002 | + |
938 | 1003 | static void test_bench_attach_uprobe(void)
|
939 | 1004 | {
|
940 | 1005 | long attach_start_ns = 0, attach_end_ns = 0;
|
@@ -1027,4 +1092,6 @@ void test_uprobe_multi_test(void)
|
1027 | 1092 | test_attach_uprobe_fails();
|
1028 | 1093 | if (test__start_subtest("consumers"))
|
1029 | 1094 | test_consumers();
|
| 1095 | + if (test__start_subtest("filter_fork")) |
| 1096 | + test_pid_filter_process(); |
1030 | 1097 | }
|
0 commit comments