selftests/bpf: Add ptr32 test. Signed-off-by: Alexei Starovoitov <ast@kernel.org>
diff --git a/tools/testing/selftests/bpf/prog_tests/ptr32.c b/tools/testing/selftests/bpf/prog_tests/ptr32.c new file mode 100644 index 0000000..c08cdf5 --- /dev/null +++ b/tools/testing/selftests/bpf/prog_tests/ptr32.c
@@ -0,0 +1,35 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2023 Meta Platforms, Inc. and affiliates. */ + +#include <test_progs.h> +#include <network_helpers.h> + +#include "ptr32.skel.h" + +static void test_ptr32_basic(void) +{ + LIBBPF_OPTS(bpf_test_run_opts, opts, + .data_in = &pkt_v4, + .data_size_in = sizeof(pkt_v4), + .repeat = 1, + ); + struct ptr32 *skel; + int ret; + + skel = ptr32__open_and_load(); + if (!ASSERT_OK_PTR(skel, "rbtree__open_and_load")) + return; + + ret = bpf_prog_test_run_opts(bpf_program__fd(skel->progs.ptr32_basic), &opts); + ASSERT_OK(ret, "ret"); + ASSERT_OK(opts.retval, "retval"); + + ptr32__destroy(skel); +} + +void test_ptr32_success(void) +{ + if (test__start_subtest("ptr32_basic")) + test_ptr32_basic(); +} +
diff --git a/tools/testing/selftests/bpf/progs/ptr32.c b/tools/testing/selftests/bpf/progs/ptr32.c new file mode 100644 index 0000000..80622f7 --- /dev/null +++ b/tools/testing/selftests/bpf/progs/ptr32.c
@@ -0,0 +1,35 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2023 Meta Platforms, Inc. and affiliates. */ +#include <vmlinux.h> +#include <bpf/bpf_tracing.h> +#include <bpf/bpf_helpers.h> +#include <bpf/bpf_core_read.h> +#include "bpf_experimental.h" + +#define _32 __attribute__((address_space(271))) __attribute__((btf_type_tag("ptr32"))) + +struct list_node { + struct list_node _32* next; + struct list_node _32* _32* pprev; + int sz; +}; + +void _32* bpf_alloc32(__u32 size) __ksym; + +void set(struct list_node _32* node) +{ + node->next = bpf_alloc32(sizeof(*node)); + node->sz = sizeof(*node); + *node->pprev = node; + node += 1ull<<20; + node->sz = sizeof(*node); +} + +SEC("tc") +int ptr32_basic(void *ctx) +{ + set(bpf_alloc32(128)); + return 0; +} + +char _license[] SEC("license") = "GPL";