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
395 "./test_attach_probe.o");395 "./test_attach_probe.o");
396}396}
397 397
398static 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
398/* NOTE: affect other tests, must run in serial mode */410/* NOTE: affect other tests, must run in serial mode */
399void serial_test_fexit_bpf2bpf(void)411void serial_test_fexit_bpf2bpf(void)
400{412{
@@ -416,4 +428,6 @@ void serial_test_fexit_bpf2bpf(void) · 15 unmodified lines
416 test_func_replace_multi();428 test_func_replace_multi();
417 if (test__start_subtest("fmod_ret_freplace"))429 if (test__start_subtest("fmod_ret_freplace"))
418 test_fmod_ret_freplace();430 test_fmod_ret_freplace();
431 if (test__start_subtest("func_replace_global_func"))
432 test_func_replace_global_func();
419}433}
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
6int test_ctx_global_func(struct __sk_buff *skb)
7{
8 volatile int retval = 1;
9 return retval;
10}
11
12SEC("freplace/test_pkt_access")
13int new_test_pkt_access(struct __sk_buff *skb)
14{
15 return test_ctx_global_func(skb);
16}
17
18char _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