History

selftests/bpf: Add selftest for calling global functions from freplace

Add a selftest that calls a global function with a context object parameter from an freplace function to check that the program context type is correctly converted to the freplace target when fetching the context type from the kernel BTF. v2: - Trim includes - Get rid of global function - Use __noinline

Toke Høiland-Jørgensen committed 4 years ago

Commit 2cf7b7f1 parent f858c2b2 files · +32 −0Browse files

Unified · Split

2 files
  1. tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c +14 −0
  2. tools/testing/selftests/bpf/progs/freplace_global_func.c +18 −0
tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c+14−0
@@ -395,6 +395,18 @@ static void test_func_map_prog_compatibility(void) · 394 unmodified lines
395395 "./test_attach_probe.o");
396396 }
397397
398+static void test_func_replace_global_func(void)
399+{
400+ const char *prog_name[] = {
401+ "freplace/test_pkt_access",
402+ };
403+
404+ test_fexit_bpf2bpf_common("./freplace_global_func.o",
405+ "./test_pkt_access.o",
406+ ARRAY_SIZE(prog_name),
407+ prog_name, false, NULL);
408+}
409+
398410 /* NOTE: affect other tests, must run in serial mode */
399411 void serial_test_fexit_bpf2bpf(void)
400412 {
@@ -416,4 +428,6 @@ void serial_test_fexit_bpf2bpf(void) · 15 unmodified lines
416428 test_func_replace_multi();
417429 if (test__start_subtest("fmod_ret_freplace"))
418430 test_fmod_ret_freplace();
431+ if (test__start_subtest("func_replace_global_func"))
432+ test_func_replace_global_func();
419433 }
tools/testing/selftests/bpf/progs/freplace_global_func.c+18−0
@@ -0,0 +1,18 @@
1+// SPDX-License-Identifier: GPL-2.0
2+#include <linux/bpf.h>
3+#include <bpf/bpf_helpers.h>
4+
5+__noinline
6+int test_ctx_global_func(struct __sk_buff *skb)
7+{
8+ volatile int retval = 1;
9+ return retval;
10+}
11+
12+SEC("freplace/test_pkt_access")
13+int new_test_pkt_access(struct __sk_buff *skb)
14+{
15+ return test_ctx_global_func(skb);
16+}
17+
18+char _license[] SEC("license") = "GPL";

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t