summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/bpf/prog_tests/aggregate_ret.c
blob: 07d9d6e1d6b8872b5e7663d5252a080e75e8eb8e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2026 Meta Platforms, Inc. and affiliates. */
#include <test_progs.h>
#include <bpf/btf.h>
#include "aggregate_ret_func.skel.h"
#include "aggregate_ret_kfunc.skel.h"
#include "aggregate_ret_kfunc_arena.skel.h"

static bool testmod_has_arena_tagged_member(void)
{
	struct btf *vmlinux_btf, *module_btf = NULL;
	const struct btf_type *t;
	bool tagged = false;
	__s32 id;

	vmlinux_btf = btf__load_vmlinux_btf();
	if (!vmlinux_btf)
		return false;

	module_btf = btf__load_module_btf("bpf_testmod", vmlinux_btf);
	if (!module_btf)
		goto out;

	/* prog_test_ret_arena::a is 'void __arena_tag *': PTR -> TYPE_TAG -> void */
	id = btf__find_by_name_kind(module_btf, "prog_test_ret_arena", BTF_KIND_STRUCT);
	if (id <= 0)
		goto out;

	t = btf__type_by_id(module_btf, btf_members(btf__type_by_id(module_btf, id))[0].type);
	if (!t || !btf_is_ptr(t))
		goto out;

	t = btf__type_by_id(module_btf, t->type);
	tagged = t && btf_is_type_tag(t) &&
		 !strcmp(btf__name_by_offset(module_btf, t->name_off), "arena");

out:
	btf__free(module_btf);
	btf__free(vmlinux_btf);

	return tagged;
}

void test_aggregate_ret(void)
{
	RUN_TESTS(aggregate_ret_func);
	RUN_TESTS(aggregate_ret_kfunc);

	if (testmod_has_arena_tagged_member())
		RUN_TESTS(aggregate_ret_kfunc_arena);
	else
		test__skip();
}