]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
selftests/bpf: Add BTF_KIND_TYPE_TAG unit tests
authorYonghong Song <yhs@fb.com>
Fri, 12 Nov 2021 01:26:30 +0000 (17:26 -0800)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 12 Nov 2021 01:41:11 +0000 (17:41 -0800)
Add BTF_KIND_TYPE_TAG unit tests.

Signed-off-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20211112012630.1506095-1-yhs@fb.com
tools/testing/selftests/bpf/prog_tests/btf.c
tools/testing/selftests/bpf/test_btf.h

index 1e8b36d74df240ce311f956a889cf858d49dee22..88510a2d98584ae8cb0ea361a3e93de1299baa66 100644 (file)
@@ -3939,6 +3939,23 @@ static struct btf_raw_test raw_tests[] = {
        .btf_load_err = true,
        .err_str = "Invalid component_idx",
 },
+{
+       .descr = "type_tag test #1",
+       .raw_types = {
+               BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),  /* [1] */
+               BTF_TYPE_TAG_ENC(NAME_TBD, 1),                  /* [2] */
+               BTF_PTR_ENC(2),                                 /* [3] */
+               BTF_END_RAW,
+       },
+       BTF_STR_SEC("\0tag"),
+       .map_type = BPF_MAP_TYPE_ARRAY,
+       .map_name = "tag_type_check_btf",
+       .key_size = sizeof(int),
+       .value_size = 4,
+       .key_type_id = 1,
+       .value_type_id = 1,
+       .max_entries = 1,
+},
 
 }; /* struct btf_raw_test raw_tests[] */
 
@@ -7222,6 +7239,7 @@ static int btf_type_size(const struct btf_type *t)
        case BTF_KIND_TYPEDEF:
        case BTF_KIND_FUNC:
        case BTF_KIND_FLOAT:
+       case BTF_KIND_TYPE_TAG:
                return base_size;
        case BTF_KIND_INT:
                return base_size + sizeof(__u32);
index 32c7a57867da23b6cd60ed01b75fc3cd13e4793c..128989bed8b735f51a7216c75d8f7fed92e93663 100644 (file)
@@ -72,4 +72,7 @@
 #define BTF_DECL_TAG_ENC(value, type, component_idx)   \
        BTF_TYPE_ENC(value, BTF_INFO_ENC(BTF_KIND_DECL_TAG, 0, 0), type), (component_idx)
 
+#define BTF_TYPE_TAG_ENC(value, type)  \
+       BTF_TYPE_ENC(value, BTF_INFO_ENC(BTF_KIND_TYPE_TAG, 0, 0), type)
+
 #endif /* _TEST_BTF_H */