Thread (14 messages) 14 messages, 2 authors, 2021-02-24

Re: [PATCH v5 bpf-next 6/8] selftest/bpf: Add BTF_KIND_FLOAT tests

From: Andrii Nakryiko <hidden>
Date: 2021-02-24 21:56:36

On Tue, Feb 23, 2021 at 3:15 PM Ilya Leoshkevich [off-list ref] wrote:
Test the good variants as well as the potential malformed ones.

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Acked-by: Yonghong Song <redacted>
---
Acked-by: Andrii Nakryiko <andrii@kernel.org>
quoted hunk ↗ jump to hunk
 tools/testing/selftests/bpf/btf_helpers.c    |   4 +
 tools/testing/selftests/bpf/prog_tests/btf.c | 129 +++++++++++++++++++
 tools/testing/selftests/bpf/test_btf.h       |   3 +
 3 files changed, 136 insertions(+)
diff --git a/tools/testing/selftests/bpf/btf_helpers.c b/tools/testing/selftests/bpf/btf_helpers.c
index 48f90490f922..b692e6ead9b5 100644
--- a/tools/testing/selftests/bpf/btf_helpers.c
+++ b/tools/testing/selftests/bpf/btf_helpers.c
@@ -23,6 +23,7 @@ static const char * const btf_kind_str_mapping[] = {
        [BTF_KIND_FUNC_PROTO]   = "FUNC_PROTO",
        [BTF_KIND_VAR]          = "VAR",
        [BTF_KIND_DATASEC]      = "DATASEC",
+       [BTF_KIND_FLOAT]        = "FLOAT",
 };

 static const char *btf_kind_str(__u16 kind)
@@ -173,6 +174,9 @@ int fprintf_btf_type_raw(FILE *out, const struct btf *btf, __u32 id)
                }
                break;
        }
+       case BTF_KIND_FLOAT:
+               fprintf(out, " size=%u", t->size);
+               break;
        default:
                break;
        }
diff --git a/tools/testing/selftests/bpf/prog_tests/btf.c b/tools/testing/selftests/bpf/prog_tests/btf.c
index c29406736138..3a8ceb8db20f 100644
--- a/tools/testing/selftests/bpf/prog_tests/btf.c
+++ b/tools/testing/selftests/bpf/prog_tests/btf.c
@@ -3531,6 +3531,134 @@ static struct btf_raw_test raw_tests[] = {
        .max_entries = 1,
 },

+{
+       .descr = "float test #1, well-formed",
+       .raw_types = {
+               BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),
+                                                               /* [1] */
+               BTF_TYPE_FLOAT_ENC(NAME_TBD, 2),                /* [2] */
+               BTF_TYPE_FLOAT_ENC(NAME_TBD, 4),                /* [3] */
+               BTF_TYPE_FLOAT_ENC(NAME_TBD, 8),                /* [4] */
nit: 12-byte for completeness?

+               BTF_TYPE_FLOAT_ENC(NAME_TBD, 16),               /* [5] */
+               BTF_STRUCT_ENC(NAME_TBD, 4, 32),                /* [6] */
+               BTF_MEMBER_ENC(NAME_TBD, 2, 0),
+               BTF_MEMBER_ENC(NAME_TBD, 3, 32),
+               BTF_MEMBER_ENC(NAME_TBD, 4, 64),
+               BTF_MEMBER_ENC(NAME_TBD, 5, 128),
+               BTF_END_RAW,
+       },
+       BTF_STR_SEC("\0int\0_Float16\0float\0double\0long_double\0floats"
+                   "\0x\0y\0z\0_"),
+       .map_type = BPF_MAP_TYPE_ARRAY,
+       .map_name = "float_type_check_btf",
+       .key_size = sizeof(int),
+       .value_size = 32,
+       .key_type_id = 1,
+       .value_type_id = 6,
+       .max_entries = 1,
+},
[...]
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help