Skip to content

Commit

Permalink
selftests/bpf: Add BTF_KIND_DECL_TAG typedef example in tag.c
Browse files Browse the repository at this point in the history
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 <yhs@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20211021195643.4020315-1-yhs@fb.com
  • Loading branch information
Yonghong Song authored and Alexei Starovoitov committed Oct 23, 2021
1 parent 557c8c4 commit 8c18ea2
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions tools/testing/selftests/bpf/progs/tag.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,23 @@ struct key_t {
int c;
} __tag1 __tag2;

typedef struct {
int a;
int b;
} value_t __tag1 __tag2;

struct {
__uint(type, BPF_MAP_TYPE_HASH);
__uint(max_entries, 3);
__type(key, struct key_t);
__type(value, __u64);
__type(value, value_t);
} hashmap1 SEC(".maps");


static __noinline int foo(int x __tag1 __tag2) __tag1 __tag2
{
struct key_t key;
__u64 val = 1;
value_t val = {};

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

0 comments on commit 8c18ea2

Please sign in to comment.