On 12/13/24 3:29 PM, Amery Hung wrote:
+void test_struct_ops_refcounted(void) +{ + if (test__start_subtest("refcounted")) + refcounted(); + if (test__start_subtest("refcounted_fail__ref_leak")) + refcounted_fail__ref_leak();
test_loader.c could make writing this test easier and it can also test the verifier failure message. e.g. for the ref_leak test, the following should do:
RUN_TESTS(struct_ops_refcounted_fail__ref_leak); The same for the other subtests in this patch.
+ if (test__start_subtest("refcounted_fail__global_subprog")) + refcounted_fail__global_subprog(); +}
[ ... ]
diff --git a/tools/testing/selftests/bpf/progs/struct_ops_refcounted_fail__ref_leak.c b/tools/testing/selftests/bpf/progs/struct_ops_refcounted_fail__ref_leak.c new file mode 100644 index 000000000000..6e82859eb187 --- /dev/null +++ b/tools/testing/selftests/bpf/progs/struct_ops_refcounted_fail__ref_leak.c @@ -0,0 +1,17 @@ +#include <vmlinux.h> +#include <bpf/bpf_tracing.h> +#include "../bpf_testmod/bpf_testmod.h" + +char _license[] SEC("license") = "GPL"; +
+#include "bpf_misc.h" +__failure __msg("Unreleased reference")
+SEC("struct_ops/test_refcounted") +int BPF_PROG(test_refcounted, int dummy, + struct task_struct *task) +{ + return 0; +} + +SEC(".struct_ops.link") +struct bpf_testmod_ops testmod_ref_acquire = { + .test_refcounted = (void *)test_refcounted, +};
[ I will stop here for today and will continue the rest tomorrow. ]