]> git.baikalelectronics.ru Git - kernel.git/commitdiff
selftests/bpf: Add BTF_KIND_FLOAT to test_core_reloc_size
authorIlya Leoshkevich <iii@linux.ibm.com>
Tue, 9 Mar 2021 00:56:48 +0000 (01:56 +0100)
committerAlexei Starovoitov <ast@kernel.org>
Tue, 9 Mar 2021 18:59:46 +0000 (10:59 -0800)
Verify that bpf_core_field_size() is working correctly with floats.
Also document the required clang version.

Suggested-by: John Fastabend <john.fastabend@gmail.com>
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20210309005649.162480-2-iii@linux.ibm.com
tools/testing/selftests/bpf/README.rst
tools/testing/selftests/bpf/prog_tests/core_reloc.c
tools/testing/selftests/bpf/progs/core_reloc_types.h
tools/testing/selftests/bpf/progs/test_core_reloc_size.c

index dbc8f6cc5c67e0dc2e57ef5ed4ae53fc216a5e57..3464161c8eea3262fc00983dead5249ad571ebb3 100644 (file)
@@ -170,3 +170,12 @@ failures:
 .. _2: https://reviews.llvm.org/D85174
 .. _3: https://reviews.llvm.org/D83878
 .. _4: https://reviews.llvm.org/D83242
+
+Floating-point tests and Clang version
+======================================
+
+Certain selftests, e.g. core_reloc, require support for the floating-point
+types, which was introduced in `Clang 13`__. The older Clang versions will
+either crash when compiling these tests, or generate an incorrect BTF.
+
+__  https://reviews.llvm.org/D83289
index 06eb956ff7bbd154c28fe3d883ca877efb107afd..d94dcead72e63317a95701cadcf88c9f10dec408 100644 (file)
@@ -266,6 +266,7 @@ static int duration = 0;
                .arr_elem_sz = sizeof(((type *)0)->arr_field[0]),       \
                .ptr_sz = 8, /* always 8-byte pointer for BPF */        \
                .enum_sz = sizeof(((type *)0)->enum_field),             \
+               .float_sz = sizeof(((type *)0)->float_field),           \
        }
 
 #define SIZE_CASE(name) {                                              \
index 9a2850850121316480347cb40044e69093250783..9982eb969048dba8e63b4a0893d210f9e0ef3922 100644 (file)
@@ -807,6 +807,7 @@ struct core_reloc_size_output {
        int arr_elem_sz;
        int ptr_sz;
        int enum_sz;
+       int float_sz;
 };
 
 struct core_reloc_size {
@@ -816,6 +817,7 @@ struct core_reloc_size {
        int arr_field[4];
        void *ptr_field;
        enum { VALUE = 123 } enum_field;
+       float float_field;
 };
 
 struct core_reloc_size___diff_sz {
@@ -825,6 +827,7 @@ struct core_reloc_size___diff_sz {
        char arr_field[10];
        void *ptr_field;
        enum { OTHER_VALUE = 0xFFFFFFFFFFFFFFFF } enum_field;
+       double float_field;
 };
 
 /* Error case of two candidates with the fields (int_field) at the same
@@ -839,6 +842,7 @@ struct core_reloc_size___err_ambiguous1 {
        int arr_field[4];
        void *ptr_field;
        enum { VALUE___1 = 123 } enum_field;
+       float float_field;
 };
 
 struct core_reloc_size___err_ambiguous2 {
@@ -850,6 +854,7 @@ struct core_reloc_size___err_ambiguous2 {
        int arr_field[4];
        void *ptr_field;
        enum { VALUE___2 = 123 } enum_field;
+       float float_field;
 };
 
 /*
index d7fb6cfc7891228ac7643dd5dae3181800b5afce..7b2d576aeea1a1c9bb7005d52e863030c76d9897 100644 (file)
@@ -21,6 +21,7 @@ struct core_reloc_size_output {
        int arr_elem_sz;
        int ptr_sz;
        int enum_sz;
+       int float_sz;
 };
 
 struct core_reloc_size {
@@ -30,6 +31,7 @@ struct core_reloc_size {
        int arr_field[4];
        void *ptr_field;
        enum { VALUE = 123 } enum_field;
+       float float_field;
 };
 
 SEC("raw_tracepoint/sys_enter")
@@ -45,6 +47,7 @@ int test_core_size(void *ctx)
        out->arr_elem_sz = bpf_core_field_size(in->arr_field[0]);
        out->ptr_sz = bpf_core_field_size(in->ptr_field);
        out->enum_sz = bpf_core_field_size(in->enum_field);
+       out->float_sz = bpf_core_field_size(in->float_field);
 
        return 0;
 }