selftests/bpf: Add a test where map key_type_id with decl_tag type
authorYonghong Song <yhs@fb.com>
Tue, 30 May 2023 20:50:34 +0000 (13:50 -0700)
committerMartin KaFai Lau <martin.lau@kernel.org>
Tue, 30 May 2023 21:34:46 +0000 (14:34 -0700)
Add two selftests where map creation key/value type_id's are
decl_tags. Without previous patch, kernel warnings will
appear similar to the one in the previous patch. With the previous
patch, both kernel warnings are silenced.

Signed-off-by: Yonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/r/20230530205034.266643-1-yhs@fb.com
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
tools/testing/selftests/bpf/prog_tests/btf.c

index 210d643..4e0cdb5 100644 (file)
@@ -3991,6 +3991,46 @@ static struct btf_raw_test raw_tests[] = {
        .err_str = "Invalid arg#1",
 },
 {
+       .descr = "decl_tag test #18, decl_tag as the map key type",
+       .raw_types = {
+               BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),  /* [1] */
+               BTF_STRUCT_ENC(0, 2, 8),                        /* [2] */
+               BTF_MEMBER_ENC(NAME_TBD, 1, 0),
+               BTF_MEMBER_ENC(NAME_TBD, 1, 32),
+               BTF_DECL_TAG_ENC(NAME_TBD, 2, -1),              /* [3] */
+               BTF_END_RAW,
+       },
+       BTF_STR_SEC("\0m1\0m2\0tag"),
+       .map_type = BPF_MAP_TYPE_HASH,
+       .map_name = "tag_type_check_btf",
+       .key_size = 8,
+       .value_size = 4,
+       .key_type_id = 3,
+       .value_type_id = 1,
+       .max_entries = 1,
+       .map_create_err = true,
+},
+{
+       .descr = "decl_tag test #19, decl_tag as the map value type",
+       .raw_types = {
+               BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),  /* [1] */
+               BTF_STRUCT_ENC(0, 2, 8),                        /* [2] */
+               BTF_MEMBER_ENC(NAME_TBD, 1, 0),
+               BTF_MEMBER_ENC(NAME_TBD, 1, 32),
+               BTF_DECL_TAG_ENC(NAME_TBD, 2, -1),              /* [3] */
+               BTF_END_RAW,
+       },
+       BTF_STR_SEC("\0m1\0m2\0tag"),
+       .map_type = BPF_MAP_TYPE_HASH,
+       .map_name = "tag_type_check_btf",
+       .key_size = 4,
+       .value_size = 8,
+       .key_type_id = 1,
+       .value_type_id = 3,
+       .max_entries = 1,
+       .map_create_err = true,
+},
+{
        .descr = "type_tag test #1",
        .raw_types = {
                BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),  /* [1] */