diff mbox series

[bpf-next,4/5] selftests/bpf: add BTF_KIND_DECL_TAG typedef example in tag.c

Message ID 20211021195643.4020315-1-yhs@fb.com (mailing list archive)
State Accepted
Delegated to: BPF
Headers show
Series bpf: add support for BTF_KIND_DECL_TAG typedef | expand

Checks

Context Check Description
netdev/cover_letter success Series has a cover letter
netdev/fixes_present success Fixes tag not required for -next series
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for bpf-next
netdev/subject_prefix success Link
netdev/cc_maintainers warning 7 maintainers not CCed: john.fastabend@gmail.com linux-kselftest@vger.kernel.org netdev@vger.kernel.org songliubraving@fb.com kafai@fb.com kpsingh@kernel.org shuah@kernel.org
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success No Fixes tag
netdev/checkpatch warning WARNING: do not add new typedefs
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/header_inline success No static functions without inline keyword in header files
bpf/vmtest-bpf-next success VM_Test
bpf/vmtest-bpf-next-PR success PR summary

Commit Message

Yonghong Song Oct. 21, 2021, 7:56 p.m. UTC
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>
---
 tools/testing/selftests/bpf/progs/tag.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/progs/tag.c b/tools/testing/selftests/bpf/progs/tag.c
index 672d19e7b120..1792f4eda095 100644
--- a/tools/testing/selftests/bpf/progs/tag.c
+++ b/tools/testing/selftests/bpf/progs/tag.c
@@ -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);