1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2023 Meta Platforms, Inc. and affiliates. */
3 
4 #include <test_progs.h>
5 #include <network_helpers.h>
6 
7 #include "local_kptr_stash.skel.h"
8 static void test_local_kptr_stash_simple(void)
9 {
10 	LIBBPF_OPTS(bpf_test_run_opts, opts,
11 		    .data_in = &pkt_v4,
12 		    .data_size_in = sizeof(pkt_v4),
13 		    .repeat = 1,
14 	);
15 	struct local_kptr_stash *skel;
16 	int ret;
17 
18 	skel = local_kptr_stash__open_and_load();
19 	if (!ASSERT_OK_PTR(skel, "local_kptr_stash__open_and_load"))
20 		return;
21 
22 	ret = bpf_prog_test_run_opts(bpf_program__fd(skel->progs.stash_rb_nodes), &opts);
23 	ASSERT_OK(ret, "local_kptr_stash_add_nodes run");
24 	ASSERT_OK(opts.retval, "local_kptr_stash_add_nodes retval");
25 
26 	local_kptr_stash__destroy(skel);
27 }
28 
29 static void test_local_kptr_stash_unstash(void)
30 {
31 	LIBBPF_OPTS(bpf_test_run_opts, opts,
32 		    .data_in = &pkt_v4,
33 		    .data_size_in = sizeof(pkt_v4),
34 		    .repeat = 1,
35 	);
36 	struct local_kptr_stash *skel;
37 	int ret;
38 
39 	skel = local_kptr_stash__open_and_load();
40 	if (!ASSERT_OK_PTR(skel, "local_kptr_stash__open_and_load"))
41 		return;
42 
43 	ret = bpf_prog_test_run_opts(bpf_program__fd(skel->progs.stash_rb_nodes), &opts);
44 	ASSERT_OK(ret, "local_kptr_stash_add_nodes run");
45 	ASSERT_OK(opts.retval, "local_kptr_stash_add_nodes retval");
46 
47 	ret = bpf_prog_test_run_opts(bpf_program__fd(skel->progs.unstash_rb_node), &opts);
48 	ASSERT_OK(ret, "local_kptr_stash_add_nodes run");
49 	ASSERT_EQ(opts.retval, 42, "local_kptr_stash_add_nodes retval");
50 
51 	local_kptr_stash__destroy(skel);
52 }
53 
54 void test_local_kptr_stash_success(void)
55 {
56 	if (test__start_subtest("local_kptr_stash_simple"))
57 		test_local_kptr_stash_simple();
58 	if (test__start_subtest("local_kptr_stash_unstash"))
59 		test_local_kptr_stash_unstash();
60 }
61