Skip to content

Commit 5f9eea2

Browse files
yonghong-songNobody
authored and
Nobody
committed
selftests/bpf: add BTF_KIND_DECL_TAG typedef example in tag.c
Change value type in progs/tag.c to a typedef with a btf_decl_tag. With `bpftool btf dump file tag.o`, we have ... [14] TYPEDEF 'value_t' type_id=17 [15] DECL_TAG 'tag1' type_id=14 component_idx=-1 [16] DECL_TAG 'tag2' type_id=14 component_idx=-1 [17] STRUCT '(anon)' size=8 vlen=2 'a' type_id=2 bits_offset=0 'b' type_id=2 bits_offset=32 ... The btf_tag selftest also succeeded: $ ./test_progs -t tag #21 btf_tag:OK Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED Signed-off-by: Yonghong Song <[email protected]>
1 parent 40d8abc commit 5f9eea2

File tree

1 file changed

+7
-2
lines changed
  • tools/testing/selftests/bpf/progs

1 file changed

+7
-2
lines changed

tools/testing/selftests/bpf/progs/tag.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,23 @@ struct key_t {
2424
int c;
2525
} __tag1 __tag2;
2626

27+
typedef struct {
28+
int a;
29+
int b;
30+
} value_t __tag1 __tag2;
31+
2732
struct {
2833
__uint(type, BPF_MAP_TYPE_HASH);
2934
__uint(max_entries, 3);
3035
__type(key, struct key_t);
31-
__type(value, __u64);
36+
__type(value, value_t);
3237
} hashmap1 SEC(".maps");
3338

3439

3540
static __noinline int foo(int x __tag1 __tag2) __tag1 __tag2
3641
{
3742
struct key_t key;
38-
__u64 val = 1;
43+
value_t val = {};
3944

4045
key.a = key.b = key.c = x;
4146
bpf_map_update_elem(&hashmap1, &key, &val, 0);

0 commit comments

Comments
 (0)