1 // SPDX-License-Identifier: GPL-2.0 2 /* Copyright (c) 2019 Facebook */ 3 #include <test_progs.h> 4 5 /* that's kernel internal BPF_MAX_TRAMP_PROGS define */ 6 #define CNT 38 7 8 void serial_test_fexit_stress(void) 9 { 10 int fexit_fd[CNT] = {}; 11 int link_fd[CNT] = {}; 12 int err, i; 13 14 const struct bpf_insn trace_program[] = { 15 BPF_MOV64_IMM(BPF_REG_0, 0), 16 BPF_EXIT_INSN(), 17 }; 18 19 LIBBPF_OPTS(bpf_prog_load_opts, trace_opts, 20 .expected_attach_type = BPF_TRACE_FEXIT, 21 ); 22 23 LIBBPF_OPTS(bpf_test_run_opts, topts); 24 25 err = libbpf_find_vmlinux_btf_id("bpf_fentry_test1", 26 trace_opts.expected_attach_type); 27 if (!ASSERT_GT(err, 0, "find_vmlinux_btf_id")) 28 goto out; 29 trace_opts.attach_btf_id = err; 30 31 for (i = 0; i < CNT; i++) { 32 fexit_fd[i] = bpf_prog_load(BPF_PROG_TYPE_TRACING, NULL, "GPL", 33 trace_program, 34 sizeof(trace_program) / sizeof(struct bpf_insn), 35 &trace_opts); 36 if (!ASSERT_GE(fexit_fd[i], 0, "fexit load")) 37 goto out; 38 link_fd[i] = bpf_link_create(fexit_fd[i], 0, BPF_TRACE_FEXIT, NULL); 39 if (!ASSERT_GE(link_fd[i], 0, "fexit attach")) 40 goto out; 41 } 42 43 err = bpf_prog_test_run_opts(fexit_fd[0], &topts); 44 ASSERT_OK(err, "bpf_prog_test_run_opts"); 45 46 out: 47 for (i = 0; i < CNT; i++) { 48 if (link_fd[i]) 49 close(link_fd[i]); 50 if (fexit_fd[i]) 51 close(fexit_fd[i]); 52 } 53 } 54