diff mbox series

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

Message ID 20240830173406.1581007-1-eddyz87@gmail.com (mailing list archive)
State Accepted
Commit 217c4dfec4a6ad6f0c5c3cc6559d1c09aa9f3065
Delegated to: BPF
Headers show
Series [bpf-next] selftests/bpf: check if distilled base inherits source endianness | expand

Checks

Context Check Description
bpf/vmtest-bpf-next-VM_Test-0 success Logs for Lint
bpf/vmtest-bpf-next-VM_Test-2 success Logs for Unittests
bpf/vmtest-bpf-next-VM_Test-1 success Logs for ShellCheck
bpf/vmtest-bpf-next-VM_Test-4 success Logs for aarch64-gcc / build / build for aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-5 success Logs for aarch64-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-3 success Logs for Validate matrix.py
bpf/vmtest-bpf-next-VM_Test-11 success Logs for s390x-gcc / build / build for s390x with gcc
bpf/vmtest-bpf-next-VM_Test-12 success Logs for s390x-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-10 success Logs for aarch64-gcc / veristat
bpf/vmtest-bpf-next-VM_Test-16 success Logs for s390x-gcc / veristat
bpf/vmtest-bpf-next-VM_Test-18 success Logs for x86_64-gcc / build / build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-17 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-19 success Logs for x86_64-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-27 success Logs for x86_64-llvm-17 / build / build for x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-28 success Logs for x86_64-llvm-17 / build-release / build for x86_64 with llvm-17-O2
bpf/vmtest-bpf-next-VM_Test-34 success Logs for x86_64-llvm-18 / build / build for x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-33 success Logs for x86_64-llvm-17 / veristat
bpf/vmtest-bpf-next-VM_Test-35 success Logs for x86_64-llvm-18 / build-release / build for x86_64 with llvm-18-O2
bpf/vmtest-bpf-next-VM_Test-41 success Logs for x86_64-llvm-18 / veristat
bpf/vmtest-bpf-next-PR fail PR summary
bpf/vmtest-bpf-next-VM_Test-7 fail Logs for aarch64-gcc / test (test_progs, false, 360) / test_progs on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-6 success Logs for aarch64-gcc / test (test_maps, false, 360) / test_maps on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-9 success Logs for aarch64-gcc / test (test_verifier, false, 360) / test_verifier on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-8 fail Logs for aarch64-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-13 fail Logs for s390x-gcc / test (test_progs, false, 360) / test_progs on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-14 fail Logs for s390x-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-15 success Logs for s390x-gcc / test (test_verifier, false, 360) / test_verifier on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-20 success Logs for x86_64-gcc / test (test_maps, false, 360) / test_maps on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-21 fail Logs for x86_64-gcc / test (test_progs, false, 360) / test_progs on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-22 fail Logs for x86_64-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-24 success Logs for x86_64-gcc / test (test_progs_parallel, true, 30) / test_progs_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-23 success Logs for x86_64-gcc / test (test_progs_no_alu32_parallel, true, 30) / test_progs_no_alu32_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-25 success Logs for x86_64-gcc / test (test_verifier, false, 360) / test_verifier on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-26 success Logs for x86_64-gcc / veristat / veristat on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-32 success Logs for x86_64-llvm-17 / test (test_verifier, false, 360) / test_verifier on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-31 fail Logs for x86_64-llvm-17 / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-29 success Logs for x86_64-llvm-17 / test (test_maps, false, 360) / test_maps on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-30 fail Logs for x86_64-llvm-17 / test (test_progs, false, 360) / test_progs on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-36 success Logs for x86_64-llvm-18 / test (test_maps, false, 360) / test_maps on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-38 fail Logs for x86_64-llvm-18 / test (test_progs_cpuv4, false, 360) / test_progs_cpuv4 on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-37 fail Logs for x86_64-llvm-18 / test (test_progs, false, 360) / test_progs on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-39 fail Logs for x86_64-llvm-18 / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-40 success Logs for x86_64-llvm-18 / test (test_verifier, false, 360) / test_verifier on x86_64 with llvm-18
netdev/tree_selection success Clearly marked for bpf-next
netdev/apply fail Patch does not apply to bpf-next-0

Commit Message

Eduard Zingerman Aug. 30, 2024, 5:34 p.m. UTC
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@gmail.com>
---
 .../selftests/bpf/prog_tests/btf_distill.c    | 73 +++++++++++++++++++
 1 file changed, 73 insertions(+)

Comments

Eduard Zingerman Aug. 30, 2024, 5:36 p.m. UTC | #1
On Fri, 2024-08-30 at 10:34 -0700, Eduard Zingerman 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@gmail.com>
> ---

Note: this would fail on CI unless [1] is applied.

[1] https://lore.kernel.org/bpf/20240830095150.278881-1-tony.ambardar@gmail.com/
Andrii Nakryiko Aug. 30, 2024, 5:51 p.m. UTC | #2
On Fri, Aug 30, 2024 at 10:34 AM Eduard Zingerman <eddyz87@gmail.com> 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@gmail.com>
> ---
>  .../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);

[...]
Alan Maguire Aug. 30, 2024, 5:52 p.m. UTC | #3
On 30/08/2024 18:34, Eduard Zingerman 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@gmail.com>

One small thing below, but

Reviewed-by: Alan Maguire <alan.maguire@oracle.com>
Tested-by: Alan Maguire <alan.maguire@oracle.com>

Thanks!

> ---
>  .../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());
> +	inverse_endianness = is_host_big_endian() ? BTF_LITTLE_ENDIAN : BTF_BIG_ENDIAN;
> +	base = btf__new_empty();


nit: I think you could avoid the need for is_host_big_endian() by doing
this:

inverse_endianness = btf__endianness(base) == BTF_LITTLE_ENDIAN ?
		     BTF_BIG_ENDIAN : BTF_LITTLE_ENDIAN;


> +	btf__set_endianness(base, inverse_endianness);
> +	if (!ASSERT_OK_PTR(base, "empty_main_btf"))
> +		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);
> +	VALIDATE_RAW_BTF(
> +		split,
> +		"[1] INT 'int' size=4 bits_offset=0 nr_bits=32 encoding=SIGNED",
> +		"[2] PTR '(anon)' type_id=1");
> +	if (!ASSERT_EQ(0, btf__distill_base(split, &new_base, &new_split),
> +		       "distilled_base") ||
> +	    !ASSERT_OK_PTR(new_base, "distilled_base") ||
> +	    !ASSERT_OK_PTR(new_split, "distilled_split") ||
> +	    !ASSERT_EQ(2, btf__type_cnt(new_base), "distilled_base_type_cnt"))
> +		goto cleanup;
> +	VALIDATE_RAW_BTF(
> +		new_split,
> +		"[1] INT 'int' size=4 bits_offset=0 nr_bits=32 encoding=SIGNED",
> +		"[2] PTR '(anon)' type_id=1");
> +
> +	raw_data = btf__raw_data(new_base, &size);
> +	if (!ASSERT_OK_PTR(raw_data, "btf__raw_data #1"))
> +		goto cleanup;
> +	new_base1 = btf__new(raw_data, size);
> +	if (!ASSERT_OK_PTR(new_base1, "new_base1 = btf__new()"))
> +		goto cleanup;
> +	raw_data = btf__raw_data(new_split, &size);
> +	if (!ASSERT_OK_PTR(raw_data, "btf__raw_data #2"))
> +		goto cleanup;
> +	new_split1 = btf__new_split(raw_data, size, new_base1);
> +	if (!ASSERT_OK_PTR(new_split1, "new_split1 = btf__new()"))
> +		goto cleanup;
> +
> +	ASSERT_EQ(btf__endianness(new_base1), inverse_endianness, "new_base1 endianness");
> +	ASSERT_EQ(btf__endianness(new_split1), inverse_endianness, "new_split1 endianness");
> +	VALIDATE_RAW_BTF(
> +		new_split1,
> +		"[1] INT 'int' size=4 bits_offset=0 nr_bits=32 encoding=SIGNED",
> +		"[2] PTR '(anon)' type_id=1");
> +cleanup:
> +	btf__free(new_split1);
> +	btf__free(new_base1);
> +	btf__free(new_split);
> +	btf__free(new_base);
> +	btf__free(split);
> +	btf__free(base);
> +}
> +
>  void test_btf_distill(void)
>  {
>  	if (test__start_subtest("distilled_base"))
> @@ -549,4 +620,6 @@ void test_btf_distill(void)
>  		test_distilled_base_multi_err2();
>  	if (test__start_subtest("distilled_base_vmlinux"))
>  		test_distilled_base_vmlinux();
> +	if (test__start_subtest("distilled_endianness"))
> +		test_distilled_endianness();
>  }
Eduard Zingerman Aug. 30, 2024, 5:53 p.m. UTC | #4
On Fri, 2024-08-30 at 10:51 -0700, Andrii Nakryiko wrote:

[...]

> > +/* 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

:facepalm:, sorry, my bad.

[...]
Andrii Nakryiko Aug. 30, 2024, 5:56 p.m. UTC | #5
On Fri, Aug 30, 2024 at 10:54 AM Alan Maguire <alan.maguire@oracle.com> wrote:
>
> On 30/08/2024 18:34, Eduard Zingerman 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@gmail.com>
>
> One small thing below, but
>
> Reviewed-by: Alan Maguire <alan.maguire@oracle.com>
> Tested-by: Alan Maguire <alan.maguire@oracle.com>

will add and force-push, thanks

>
> Thanks!
>
> > ---
> >  .../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());
> > +     inverse_endianness = is_host_big_endian() ? BTF_LITTLE_ENDIAN : BTF_BIG_ENDIAN;
> > +     base = btf__new_empty();
>
>
> nit: I think you could avoid the need for is_host_big_endian() by doing
> this:
>
> inverse_endianness = btf__endianness(base) == BTF_LITTLE_ENDIAN ?
>                      BTF_BIG_ENDIAN : BTF_LITTLE_ENDIAN;

good point, I'll fix it up

>
>
> > +     btf__set_endianness(base, inverse_endianness);
> > +     if (!ASSERT_OK_PTR(base, "empty_main_btf"))
> > +             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);
> > +     VALIDATE_RAW_BTF(
> > +             split,
> > +             "[1] INT 'int' size=4 bits_offset=0 nr_bits=32 encoding=SIGNED",
> > +             "[2] PTR '(anon)' type_id=1");
> > +     if (!ASSERT_EQ(0, btf__distill_base(split, &new_base, &new_split),
> > +                    "distilled_base") ||
> > +         !ASSERT_OK_PTR(new_base, "distilled_base") ||
> > +         !ASSERT_OK_PTR(new_split, "distilled_split") ||
> > +         !ASSERT_EQ(2, btf__type_cnt(new_base), "distilled_base_type_cnt"))
> > +             goto cleanup;
> > +     VALIDATE_RAW_BTF(
> > +             new_split,
> > +             "[1] INT 'int' size=4 bits_offset=0 nr_bits=32 encoding=SIGNED",
> > +             "[2] PTR '(anon)' type_id=1");
> > +
> > +     raw_data = btf__raw_data(new_base, &size);
> > +     if (!ASSERT_OK_PTR(raw_data, "btf__raw_data #1"))
> > +             goto cleanup;
> > +     new_base1 = btf__new(raw_data, size);
> > +     if (!ASSERT_OK_PTR(new_base1, "new_base1 = btf__new()"))
> > +             goto cleanup;
> > +     raw_data = btf__raw_data(new_split, &size);
> > +     if (!ASSERT_OK_PTR(raw_data, "btf__raw_data #2"))
> > +             goto cleanup;
> > +     new_split1 = btf__new_split(raw_data, size, new_base1);
> > +     if (!ASSERT_OK_PTR(new_split1, "new_split1 = btf__new()"))
> > +             goto cleanup;
> > +
> > +     ASSERT_EQ(btf__endianness(new_base1), inverse_endianness, "new_base1 endianness");
> > +     ASSERT_EQ(btf__endianness(new_split1), inverse_endianness, "new_split1 endianness");
> > +     VALIDATE_RAW_BTF(
> > +             new_split1,
> > +             "[1] INT 'int' size=4 bits_offset=0 nr_bits=32 encoding=SIGNED",
> > +             "[2] PTR '(anon)' type_id=1");
> > +cleanup:
> > +     btf__free(new_split1);
> > +     btf__free(new_base1);
> > +     btf__free(new_split);
> > +     btf__free(new_base);
> > +     btf__free(split);
> > +     btf__free(base);
> > +}
> > +
> >  void test_btf_distill(void)
> >  {
> >       if (test__start_subtest("distilled_base"))
> > @@ -549,4 +620,6 @@ void test_btf_distill(void)
> >               test_distilled_base_multi_err2();
> >       if (test__start_subtest("distilled_base_vmlinux"))
> >               test_distilled_base_vmlinux();
> > +     if (test__start_subtest("distilled_endianness"))
> > +             test_distilled_endianness();
> >  }
patchwork-bot+netdevbpf@kernel.org Aug. 30, 2024, 6 p.m. UTC | #6
Hello:

This patch was applied to bpf/bpf-next.git (master)
by Andrii Nakryiko <andrii@kernel.org>:

On Fri, 30 Aug 2024 10:34:06 -0700 you 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@gmail.com>
> ---
>  .../selftests/bpf/prog_tests/btf_distill.c    | 73 +++++++++++++++++++
>  1 file changed, 73 insertions(+)

Here is the summary with links:
  - [bpf-next] selftests/bpf: check if distilled base inherits source endianness
    https://git.kernel.org/bpf/bpf-next/c/217c4dfec4a6

You are awesome, thank you!
diff mbox series

Patch

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());
+	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"))
+		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);
+	VALIDATE_RAW_BTF(
+		split,
+		"[1] INT 'int' size=4 bits_offset=0 nr_bits=32 encoding=SIGNED",
+		"[2] PTR '(anon)' type_id=1");
+	if (!ASSERT_EQ(0, btf__distill_base(split, &new_base, &new_split),
+		       "distilled_base") ||
+	    !ASSERT_OK_PTR(new_base, "distilled_base") ||
+	    !ASSERT_OK_PTR(new_split, "distilled_split") ||
+	    !ASSERT_EQ(2, btf__type_cnt(new_base), "distilled_base_type_cnt"))
+		goto cleanup;
+	VALIDATE_RAW_BTF(
+		new_split,
+		"[1] INT 'int' size=4 bits_offset=0 nr_bits=32 encoding=SIGNED",
+		"[2] PTR '(anon)' type_id=1");
+
+	raw_data = btf__raw_data(new_base, &size);
+	if (!ASSERT_OK_PTR(raw_data, "btf__raw_data #1"))
+		goto cleanup;
+	new_base1 = btf__new(raw_data, size);
+	if (!ASSERT_OK_PTR(new_base1, "new_base1 = btf__new()"))
+		goto cleanup;
+	raw_data = btf__raw_data(new_split, &size);
+	if (!ASSERT_OK_PTR(raw_data, "btf__raw_data #2"))
+		goto cleanup;
+	new_split1 = btf__new_split(raw_data, size, new_base1);
+	if (!ASSERT_OK_PTR(new_split1, "new_split1 = btf__new()"))
+		goto cleanup;
+
+	ASSERT_EQ(btf__endianness(new_base1), inverse_endianness, "new_base1 endianness");
+	ASSERT_EQ(btf__endianness(new_split1), inverse_endianness, "new_split1 endianness");
+	VALIDATE_RAW_BTF(
+		new_split1,
+		"[1] INT 'int' size=4 bits_offset=0 nr_bits=32 encoding=SIGNED",
+		"[2] PTR '(anon)' type_id=1");
+cleanup:
+	btf__free(new_split1);
+	btf__free(new_base1);
+	btf__free(new_split);
+	btf__free(new_base);
+	btf__free(split);
+	btf__free(base);
+}
+
 void test_btf_distill(void)
 {
 	if (test__start_subtest("distilled_base"))
@@ -549,4 +620,6 @@  void test_btf_distill(void)
 		test_distilled_base_multi_err2();
 	if (test__start_subtest("distilled_base_vmlinux"))
 		test_distilled_base_vmlinux();
+	if (test__start_subtest("distilled_endianness"))
+		test_distilled_endianness();
 }