Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/bpf: Factor out many args tests from tracing_struct

Factor out many args tests from tracing_struct and rename some function names
to make more sense. Meanwhile, remove unnecessary skeleton detach operation
as it will be covered by skeleton destroy operation.

Signed-off-by: Pu Lehui <pulehui@huawei.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Link: https://lore.kernel.org/bpf/20240702121944.1091530-3-pulehui@huaweicloud.com

authored by

Pu Lehui and committed by
Daniel Borkmann
5d52ad36 6801b0ae

+86 -58
+26 -4
tools/testing/selftests/bpf/prog_tests/tracing_struct.c
··· 3 3 4 4 #include <test_progs.h> 5 5 #include "tracing_struct.skel.h" 6 + #include "tracing_struct_many_args.skel.h" 6 7 7 - static void test_fentry(void) 8 + static void test_struct_args(void) 8 9 { 9 10 struct tracing_struct *skel; 10 11 int err; ··· 56 55 57 56 ASSERT_EQ(skel->bss->t6, 1, "t6 ret"); 58 57 58 + destroy_skel: 59 + tracing_struct__destroy(skel); 60 + } 61 + 62 + static void test_struct_many_args(void) 63 + { 64 + struct tracing_struct_many_args *skel; 65 + int err; 66 + 67 + skel = tracing_struct_many_args__open_and_load(); 68 + if (!ASSERT_OK_PTR(skel, "tracing_struct_many_args__open_and_load")) 69 + return; 70 + 71 + err = tracing_struct_many_args__attach(skel); 72 + if (!ASSERT_OK(err, "tracing_struct_many_args__attach")) 73 + goto destroy_skel; 74 + 75 + ASSERT_OK(trigger_module_test_read(256), "trigger_read"); 76 + 59 77 ASSERT_EQ(skel->bss->t7_a, 16, "t7:a"); 60 78 ASSERT_EQ(skel->bss->t7_b, 17, "t7:b"); 61 79 ASSERT_EQ(skel->bss->t7_c, 18, "t7:c"); ··· 94 74 ASSERT_EQ(skel->bss->t8_g, 23, "t8:g"); 95 75 ASSERT_EQ(skel->bss->t8_ret, 156, "t8 ret"); 96 76 97 - tracing_struct__detach(skel); 98 77 destroy_skel: 99 - tracing_struct__destroy(skel); 78 + tracing_struct_many_args__destroy(skel); 100 79 } 101 80 102 81 void test_tracing_struct(void) 103 82 { 104 - test_fentry(); 83 + if (test__start_subtest("struct_args")) 84 + test_struct_args(); 85 + if (test__start_subtest("struct_many_args")) 86 + test_struct_many_args(); 105 87 }
-54
tools/testing/selftests/bpf/progs/tracing_struct.c
··· 18 18 int b[]; 19 19 }; 20 20 21 - struct bpf_testmod_struct_arg_4 { 22 - u64 a; 23 - int b; 24 - }; 25 - 26 21 long t1_a_a, t1_a_b, t1_b, t1_c, t1_ret, t1_nregs; 27 22 __u64 t1_reg0, t1_reg1, t1_reg2, t1_reg3; 28 23 long t2_a, t2_b_a, t2_b_b, t2_c, t2_ret; ··· 25 30 long t4_a_a, t4_b, t4_c, t4_d, t4_e_a, t4_e_b, t4_ret; 26 31 long t5_ret; 27 32 int t6; 28 - long t7_a, t7_b, t7_c, t7_d, t7_e, t7_f_a, t7_f_b, t7_ret; 29 - long t8_a, t8_b, t8_c, t8_d, t8_e, t8_f_a, t8_f_b, t8_g, t8_ret; 30 - 31 33 32 34 SEC("fentry/bpf_testmod_test_struct_arg_1") 33 35 int BPF_PROG2(test_struct_arg_1, struct bpf_testmod_struct_arg_2, a, int, b, int, c) ··· 127 135 int BPF_PROG2(test_struct_arg_11, struct bpf_testmod_struct_arg_3 *, a) 128 136 { 129 137 t6 = a->b[0]; 130 - return 0; 131 - } 132 - 133 - SEC("fentry/bpf_testmod_test_struct_arg_7") 134 - int BPF_PROG2(test_struct_arg_12, __u64, a, void *, b, short, c, int, d, 135 - void *, e, struct bpf_testmod_struct_arg_4, f) 136 - { 137 - t7_a = a; 138 - t7_b = (long)b; 139 - t7_c = c; 140 - t7_d = d; 141 - t7_e = (long)e; 142 - t7_f_a = f.a; 143 - t7_f_b = f.b; 144 - return 0; 145 - } 146 - 147 - SEC("fexit/bpf_testmod_test_struct_arg_7") 148 - int BPF_PROG2(test_struct_arg_13, __u64, a, void *, b, short, c, int, d, 149 - void *, e, struct bpf_testmod_struct_arg_4, f, int, ret) 150 - { 151 - t7_ret = ret; 152 - return 0; 153 - } 154 - 155 - SEC("fentry/bpf_testmod_test_struct_arg_8") 156 - int BPF_PROG2(test_struct_arg_14, __u64, a, void *, b, short, c, int, d, 157 - void *, e, struct bpf_testmod_struct_arg_4, f, int, g) 158 - { 159 - t8_a = a; 160 - t8_b = (long)b; 161 - t8_c = c; 162 - t8_d = d; 163 - t8_e = (long)e; 164 - t8_f_a = f.a; 165 - t8_f_b = f.b; 166 - t8_g = g; 167 - return 0; 168 - } 169 - 170 - SEC("fexit/bpf_testmod_test_struct_arg_8") 171 - int BPF_PROG2(test_struct_arg_15, __u64, a, void *, b, short, c, int, d, 172 - void *, e, struct bpf_testmod_struct_arg_4, f, int, g, 173 - int, ret) 174 - { 175 - t8_ret = ret; 176 138 return 0; 177 139 } 178 140
+60
tools/testing/selftests/bpf/progs/tracing_struct_many_args.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + #include <vmlinux.h> 3 + #include <bpf/bpf_tracing.h> 4 + #include <bpf/bpf_helpers.h> 5 + 6 + struct bpf_testmod_struct_arg_4 { 7 + u64 a; 8 + int b; 9 + }; 10 + 11 + long t7_a, t7_b, t7_c, t7_d, t7_e, t7_f_a, t7_f_b, t7_ret; 12 + long t8_a, t8_b, t8_c, t8_d, t8_e, t8_f_a, t8_f_b, t8_g, t8_ret; 13 + 14 + SEC("fentry/bpf_testmod_test_struct_arg_7") 15 + int BPF_PROG2(test_struct_many_args_1, __u64, a, void *, b, short, c, int, d, 16 + void *, e, struct bpf_testmod_struct_arg_4, f) 17 + { 18 + t7_a = a; 19 + t7_b = (long)b; 20 + t7_c = c; 21 + t7_d = d; 22 + t7_e = (long)e; 23 + t7_f_a = f.a; 24 + t7_f_b = f.b; 25 + return 0; 26 + } 27 + 28 + SEC("fexit/bpf_testmod_test_struct_arg_7") 29 + int BPF_PROG2(test_struct_many_args_2, __u64, a, void *, b, short, c, int, d, 30 + void *, e, struct bpf_testmod_struct_arg_4, f, int, ret) 31 + { 32 + t7_ret = ret; 33 + return 0; 34 + } 35 + 36 + SEC("fentry/bpf_testmod_test_struct_arg_8") 37 + int BPF_PROG2(test_struct_many_args_3, __u64, a, void *, b, short, c, int, d, 38 + void *, e, struct bpf_testmod_struct_arg_4, f, int, g) 39 + { 40 + t8_a = a; 41 + t8_b = (long)b; 42 + t8_c = c; 43 + t8_d = d; 44 + t8_e = (long)e; 45 + t8_f_a = f.a; 46 + t8_f_b = f.b; 47 + t8_g = g; 48 + return 0; 49 + } 50 + 51 + SEC("fexit/bpf_testmod_test_struct_arg_8") 52 + int BPF_PROG2(test_struct_many_args_4, __u64, a, void *, b, short, c, int, d, 53 + void *, e, struct bpf_testmod_struct_arg_4, f, int, g, 54 + int, ret) 55 + { 56 + t8_ret = ret; 57 + return 0; 58 + } 59 + 60 + char _license[] SEC("license") = "GPL";