xref: /linux/tools/testing/selftests/bpf/prog_tests/refcounted_kptr.c (revision a1c613ae4c322ddd58d5a8539dbfba2a0380a8c0)
16147f151SDave Marchevsky // SPDX-License-Identifier: GPL-2.0
26147f151SDave Marchevsky /* Copyright (c) 2023 Meta Platforms, Inc. and affiliates. */
36147f151SDave Marchevsky 
46147f151SDave Marchevsky #include <test_progs.h>
56147f151SDave Marchevsky #include <network_helpers.h>
66147f151SDave Marchevsky 
76147f151SDave Marchevsky #include "refcounted_kptr.skel.h"
86147f151SDave Marchevsky #include "refcounted_kptr_fail.skel.h"
96147f151SDave Marchevsky 
test_refcounted_kptr(void)106147f151SDave Marchevsky void test_refcounted_kptr(void)
116147f151SDave Marchevsky {
12*ba2464c8SDave Marchevsky 	RUN_TESTS(refcounted_kptr);
136147f151SDave Marchevsky }
146147f151SDave Marchevsky 
test_refcounted_kptr_fail(void)156147f151SDave Marchevsky void test_refcounted_kptr_fail(void)
166147f151SDave Marchevsky {
17*ba2464c8SDave Marchevsky 	RUN_TESTS(refcounted_kptr_fail);
186147f151SDave Marchevsky }
19fdf48dc2SDave Marchevsky 
test_refcounted_kptr_wrong_owner(void)20fdf48dc2SDave Marchevsky void test_refcounted_kptr_wrong_owner(void)
21fdf48dc2SDave Marchevsky {
22*ba2464c8SDave Marchevsky 	LIBBPF_OPTS(bpf_test_run_opts, opts,
23*ba2464c8SDave Marchevsky 		    .data_in = &pkt_v4,
24*ba2464c8SDave Marchevsky 		    .data_size_in = sizeof(pkt_v4),
25*ba2464c8SDave Marchevsky 		    .repeat = 1,
26*ba2464c8SDave Marchevsky 	);
27*ba2464c8SDave Marchevsky 	struct refcounted_kptr *skel;
28*ba2464c8SDave Marchevsky 	int ret;
29*ba2464c8SDave Marchevsky 
30*ba2464c8SDave Marchevsky 	skel = refcounted_kptr__open_and_load();
31*ba2464c8SDave Marchevsky 	if (!ASSERT_OK_PTR(skel, "refcounted_kptr__open_and_load"))
32*ba2464c8SDave Marchevsky 		return;
33*ba2464c8SDave Marchevsky 
34*ba2464c8SDave Marchevsky 	ret = bpf_prog_test_run_opts(bpf_program__fd(skel->progs.rbtree_wrong_owner_remove_fail_a1), &opts);
35*ba2464c8SDave Marchevsky 	ASSERT_OK(ret, "rbtree_wrong_owner_remove_fail_a1");
36*ba2464c8SDave Marchevsky 	ASSERT_OK(opts.retval, "rbtree_wrong_owner_remove_fail_a1 retval");
37*ba2464c8SDave Marchevsky 
38*ba2464c8SDave Marchevsky 	ret = bpf_prog_test_run_opts(bpf_program__fd(skel->progs.rbtree_wrong_owner_remove_fail_b), &opts);
39*ba2464c8SDave Marchevsky 	ASSERT_OK(ret, "rbtree_wrong_owner_remove_fail_b");
40*ba2464c8SDave Marchevsky 	ASSERT_OK(opts.retval, "rbtree_wrong_owner_remove_fail_b retval");
41*ba2464c8SDave Marchevsky 
42*ba2464c8SDave Marchevsky 	ret = bpf_prog_test_run_opts(bpf_program__fd(skel->progs.rbtree_wrong_owner_remove_fail_a2), &opts);
43*ba2464c8SDave Marchevsky 	ASSERT_OK(ret, "rbtree_wrong_owner_remove_fail_a2");
44*ba2464c8SDave Marchevsky 	ASSERT_OK(opts.retval, "rbtree_wrong_owner_remove_fail_a2 retval");
45*ba2464c8SDave Marchevsky 	refcounted_kptr__destroy(skel);
46fdf48dc2SDave Marchevsky }
47