Re: [PATCH bpf-next] selftests/bpf: check if distilled base inherits source endianness

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Aug 30, 2024 at 10:34 AM Eduard Zingerman <eddyz87@xxxxxxxxx> wrote:
>
> Create a BTF with endianness different from host, make a distilled
> base/split BTF pair from it, dump as raw bytes, import again and
> verify that endianness is preserved.
>
> Signed-off-by: Eduard Zingerman <eddyz87@xxxxxxxxx>
> ---
>  .../selftests/bpf/prog_tests/btf_distill.c    | 73 +++++++++++++++++++
>  1 file changed, 73 insertions(+)
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/btf_distill.c b/tools/testing/selftests/bpf/prog_tests/btf_distill.c
> index bfbe795823a2..810b2e434562 100644
> --- a/tools/testing/selftests/bpf/prog_tests/btf_distill.c
> +++ b/tools/testing/selftests/bpf/prog_tests/btf_distill.c
> @@ -535,6 +535,77 @@ static void test_distilled_base_vmlinux(void)
>         btf__free(vmlinux_btf);
>  }
>
> +static bool is_host_big_endian(void)
> +{
> +       return htons(0x1234) == 0x1234;
> +}
> +
> +/* Split and new base BTFs should inherit endianness from source BTF. */
> +static void test_distilled_endianness(void)
> +{
> +       struct btf *base = NULL, *split = NULL, *new_base = NULL, *new_split = NULL;
> +       struct btf *new_base1 = NULL, *new_split1 = NULL;
> +       enum btf_endianness inverse_endianness;
> +       const void *raw_data;
> +       __u32 size;
> +
> +       printf("is_host_big_endian? %d\n", is_host_big_endian());

removed printf

> +       inverse_endianness = is_host_big_endian() ? BTF_LITTLE_ENDIAN : BTF_BIG_ENDIAN;
> +       base = btf__new_empty();
> +       btf__set_endianness(base, inverse_endianness);
> +       if (!ASSERT_OK_PTR(base, "empty_main_btf"))

moved check before set_endianness

applied to bpf-next after Tony's endianness fix, thanks!

> +               return;
> +       btf__add_int(base, "int", 4, BTF_INT_SIGNED);   /* [1] int */
> +       VALIDATE_RAW_BTF(
> +               base,
> +               "[1] INT 'int' size=4 bits_offset=0 nr_bits=32 encoding=SIGNED");
> +       split = btf__new_empty_split(base);
> +       if (!ASSERT_OK_PTR(split, "empty_split_btf"))
> +               goto cleanup;
> +       btf__add_ptr(split, 1);

[...]





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux