diff mbox series

[bpf-next,3/6] selftests/bpf: add non-standardly sized enum tests for btf_dump

Message ID 20221208185703.2681797-4-andrii@kernel.org (mailing list archive)
State Superseded
Delegated to: BPF
Headers show
Series BTF-to-C dumper fixes and improvements | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for bpf-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 11 maintainers not CCed: linux-kselftest@vger.kernel.org kpsingh@kernel.org haoluo@google.com song@kernel.org yhs@fb.com martin.lau@linux.dev sdf@google.com john.fastabend@gmail.com shuah@kernel.org jolsa@kernel.org mykolal@fb.com
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch warning WARNING: Prefer __mode(byte) over __attribute__((mode(byte))) WARNING: Prefer __mode(word) over __attribute__((mode(word)))
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-next-PR success PR summary
bpf/vmtest-bpf-next-VM_Test-1 success Logs for ShellCheck
bpf/vmtest-bpf-next-VM_Test-7 success Logs for llvm-toolchain
bpf/vmtest-bpf-next-VM_Test-8 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-2 success Logs for build for aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-3 success Logs for build for aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-5 success Logs for build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-6 success Logs for build for x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-4 success Logs for build for s390x with gcc
bpf/vmtest-bpf-next-VM_Test-9 success Logs for test_maps on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-10 success Logs for test_maps on aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-12 success Logs for test_maps on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-13 success Logs for test_maps on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-14 success Logs for test_progs on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-17 success Logs for test_progs on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-18 success Logs for test_progs on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-19 success Logs for test_progs_no_alu32 on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-22 success Logs for test_progs_no_alu32 on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-24 success Logs for test_progs_no_alu32_parallel on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-25 success Logs for test_progs_no_alu32_parallel on aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-27 success Logs for test_progs_no_alu32_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-28 success Logs for test_progs_no_alu32_parallel on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-29 success Logs for test_progs_parallel on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-30 success Logs for test_progs_parallel on aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-32 success Logs for test_progs_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-33 success Logs for test_progs_parallel on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-34 success Logs for test_verifier on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-35 success Logs for test_verifier on aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-37 success Logs for test_verifier on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-38 success Logs for test_verifier on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-15 success Logs for test_progs on aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-20 success Logs for test_progs_no_alu32 on aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-23 success Logs for test_progs_no_alu32 on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-26 success Logs for test_progs_no_alu32_parallel on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-21 success Logs for test_progs_no_alu32 on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-36 success Logs for test_verifier on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-11 success Logs for test_maps on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-31 success Logs for test_progs_parallel on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-16 success Logs for test_progs on s390x with gcc

Commit Message

Andrii Nakryiko Dec. 8, 2022, 6:57 p.m. UTC
Add few custom enum definitions testing mode(byte) and mode(word)
attributes.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
 .../bpf/progs/btf_dump_test_case_syntax.c     | 36 +++++++++++++++++++
 1 file changed, 36 insertions(+)

Comments

Eduard Zingerman Dec. 9, 2022, 5:32 p.m. UTC | #1
On Thu, 2022-12-08 at 10:57 -0800, Andrii Nakryiko wrote:
> Add few custom enum definitions testing mode(byte) and mode(word)
> attributes.
> 
> Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
> ---
>  .../bpf/progs/btf_dump_test_case_syntax.c     | 36 +++++++++++++++++++
>  1 file changed, 36 insertions(+)
> 
> diff --git a/tools/testing/selftests/bpf/progs/btf_dump_test_case_syntax.c b/tools/testing/selftests/bpf/progs/btf_dump_test_case_syntax.c
> index 4ee4748133fe..26fffb02ed10 100644
> --- a/tools/testing/selftests/bpf/progs/btf_dump_test_case_syntax.c
> +++ b/tools/testing/selftests/bpf/progs/btf_dump_test_case_syntax.c
> @@ -25,6 +25,39 @@ typedef enum {
>  	H = 2,
>  } e3_t;
>  
> +/* ----- START-EXPECTED-OUTPUT ----- */
> +/*
> + *enum e_byte {
> + *	EBYTE_1 = 0,
> + *	EBYTE_2 = 1,
> + *} __attribute__((mode(byte)));
> + *
> + */
> +/* ----- END-EXPECTED-OUTPUT ----- */
> +enum e_byte {
> +	EBYTE_1,
> +	EBYTE_2,
> +} __attribute__((mode(byte)));
> +
> +/* ----- START-EXPECTED-OUTPUT ----- */
> +/*
> + *enum e_word {
> + *	EWORD_1 = 0LL,
> + *	EWORD_2 = 1LL,
> + *} __attribute__((mode(word)));
> + *
> + */
> +/* ----- END-EXPECTED-OUTPUT ----- */
> +enum e_word {
> +	EWORD_1,
> +	EWORD_2,
> +} __attribute__((mode(word))); /* force to use 8-byte backing for this enum */
> +
> +/* ----- START-EXPECTED-OUTPUT ----- */
> +enum e_big {
> +	EBIG_1 = 1000000000000ULL,
> +};
> +
>  typedef int int_t;
>  

Something is off with this test, when executed on my little-endian
machine the output looks as follows:

# ./test_progs -n 23/1
--- -	2022-12-09 17:22:03.412602033 +0000
+++ /tmp/btf_dump_test_case_syntax.output.Z28uhX	2022-12-09 17:22:03.403945082 +0000
@@ -23,13 +23,13 @@
 } __attribute__((mode(byte)));
 
 enum e_word {
-	EWORD_1 = 0LL,
-	EWORD_2 = 1LL,
+	EWORD_1 = 0,
+	EWORD_2 = 1,
 } __attribute__((mode(word)));
 
 enum e_big {
-	EBIG_1 = 1000000000000ULL,
-};
+	EBIG_1 = 3567587328,
+} __attribute__((mode(word)));

But this is not related to your changes, here is a raw dump:

$ bpftool btf dump file ./btf_dump_test_case_syntax.bpf.o 

[10] ENUM 'e_big' encoding=UNSIGNED size=8 vlen=1
        'EBIG_1' val=3567587328

>  typedef volatile const int * volatile const crazy_ptr_t;
> @@ -224,6 +257,9 @@ struct root_struct {
>  	enum e2 _2;
>  	e2_t _2_1;
>  	e3_t _2_2;
> +	enum e_byte _100;
> +	enum e_word _101;
> +	enum e_big _102;
>  	struct struct_w_typedefs _3;
>  	anon_struct_t _7;
>  	struct struct_fwd *_8;
Andrii Nakryiko Dec. 12, 2022, 6:45 p.m. UTC | #2
On Fri, Dec 9, 2022 at 9:32 AM Eduard Zingerman <eddyz87@gmail.com> wrote:
>
> On Thu, 2022-12-08 at 10:57 -0800, Andrii Nakryiko wrote:
> > Add few custom enum definitions testing mode(byte) and mode(word)
> > attributes.
> >
> > Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
> > ---
> >  .../bpf/progs/btf_dump_test_case_syntax.c     | 36 +++++++++++++++++++
> >  1 file changed, 36 insertions(+)
> >
> > diff --git a/tools/testing/selftests/bpf/progs/btf_dump_test_case_syntax.c b/tools/testing/selftests/bpf/progs/btf_dump_test_case_syntax.c
> > index 4ee4748133fe..26fffb02ed10 100644
> > --- a/tools/testing/selftests/bpf/progs/btf_dump_test_case_syntax.c
> > +++ b/tools/testing/selftests/bpf/progs/btf_dump_test_case_syntax.c
> > @@ -25,6 +25,39 @@ typedef enum {
> >       H = 2,
> >  } e3_t;
> >
> > +/* ----- START-EXPECTED-OUTPUT ----- */
> > +/*
> > + *enum e_byte {
> > + *   EBYTE_1 = 0,
> > + *   EBYTE_2 = 1,
> > + *} __attribute__((mode(byte)));
> > + *
> > + */
> > +/* ----- END-EXPECTED-OUTPUT ----- */
> > +enum e_byte {
> > +     EBYTE_1,
> > +     EBYTE_2,
> > +} __attribute__((mode(byte)));
> > +
> > +/* ----- START-EXPECTED-OUTPUT ----- */
> > +/*
> > + *enum e_word {
> > + *   EWORD_1 = 0LL,
> > + *   EWORD_2 = 1LL,
> > + *} __attribute__((mode(word)));
> > + *
> > + */
> > +/* ----- END-EXPECTED-OUTPUT ----- */
> > +enum e_word {
> > +     EWORD_1,
> > +     EWORD_2,
> > +} __attribute__((mode(word))); /* force to use 8-byte backing for this enum */
> > +
> > +/* ----- START-EXPECTED-OUTPUT ----- */
> > +enum e_big {
> > +     EBIG_1 = 1000000000000ULL,
> > +};
> > +
> >  typedef int int_t;
> >
>
> Something is off with this test, when executed on my little-endian
> machine the output looks as follows:
>
> # ./test_progs -n 23/1
> --- -   2022-12-09 17:22:03.412602033 +0000
> +++ /tmp/btf_dump_test_case_syntax.output.Z28uhX        2022-12-09 17:22:03.403945082 +0000
> @@ -23,13 +23,13 @@
>  } __attribute__((mode(byte)));
>
>  enum e_word {
> -       EWORD_1 = 0LL,
> -       EWORD_2 = 1LL,
> +       EWORD_1 = 0,
> +       EWORD_2 = 1,
>  } __attribute__((mode(word)));
>
>  enum e_big {
> -       EBIG_1 = 1000000000000ULL,
> -};
> +       EBIG_1 = 3567587328,
> +} __attribute__((mode(word)));
>

You seem to have too old Clang which doesn't emit ENUM64 types, try upgrading?


> But this is not related to your changes, here is a raw dump:
>
> $ bpftool btf dump file ./btf_dump_test_case_syntax.bpf.o
>
> [10] ENUM 'e_big' encoding=UNSIGNED size=8 vlen=1
>         'EBIG_1' val=3567587328
>
> >  typedef volatile const int * volatile const crazy_ptr_t;
> > @@ -224,6 +257,9 @@ struct root_struct {
> >       enum e2 _2;
> >       e2_t _2_1;
> >       e3_t _2_2;
> > +     enum e_byte _100;
> > +     enum e_word _101;
> > +     enum e_big _102;
> >       struct struct_w_typedefs _3;
> >       anon_struct_t _7;
> >       struct struct_fwd *_8;
>
Eduard Zingerman Dec. 12, 2022, 6:48 p.m. UTC | #3
On Mon, 2022-12-12 at 10:45 -0800, Andrii Nakryiko wrote:
> On Fri, Dec 9, 2022 at 9:32 AM Eduard Zingerman <eddyz87@gmail.com> wrote:
> > 
> > On Thu, 2022-12-08 at 10:57 -0800, Andrii Nakryiko wrote:
> > > Add few custom enum definitions testing mode(byte) and mode(word)
> > > attributes.
> > > 
> > > Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
> > > ---
> > >  .../bpf/progs/btf_dump_test_case_syntax.c     | 36 +++++++++++++++++++
> > >  1 file changed, 36 insertions(+)
> > > 
> > > diff --git a/tools/testing/selftests/bpf/progs/btf_dump_test_case_syntax.c b/tools/testing/selftests/bpf/progs/btf_dump_test_case_syntax.c
> > > index 4ee4748133fe..26fffb02ed10 100644
> > > --- a/tools/testing/selftests/bpf/progs/btf_dump_test_case_syntax.c
> > > +++ b/tools/testing/selftests/bpf/progs/btf_dump_test_case_syntax.c
> > > @@ -25,6 +25,39 @@ typedef enum {
> > >       H = 2,
> > >  } e3_t;
> > > 
> > > +/* ----- START-EXPECTED-OUTPUT ----- */
> > > +/*
> > > + *enum e_byte {
> > > + *   EBYTE_1 = 0,
> > > + *   EBYTE_2 = 1,
> > > + *} __attribute__((mode(byte)));
> > > + *
> > > + */
> > > +/* ----- END-EXPECTED-OUTPUT ----- */
> > > +enum e_byte {
> > > +     EBYTE_1,
> > > +     EBYTE_2,
> > > +} __attribute__((mode(byte)));
> > > +
> > > +/* ----- START-EXPECTED-OUTPUT ----- */
> > > +/*
> > > + *enum e_word {
> > > + *   EWORD_1 = 0LL,
> > > + *   EWORD_2 = 1LL,
> > > + *} __attribute__((mode(word)));
> > > + *
> > > + */
> > > +/* ----- END-EXPECTED-OUTPUT ----- */
> > > +enum e_word {
> > > +     EWORD_1,
> > > +     EWORD_2,
> > > +} __attribute__((mode(word))); /* force to use 8-byte backing for this enum */
> > > +
> > > +/* ----- START-EXPECTED-OUTPUT ----- */
> > > +enum e_big {
> > > +     EBIG_1 = 1000000000000ULL,
> > > +};
> > > +
> > >  typedef int int_t;
> > > 
> > 
> > Something is off with this test, when executed on my little-endian
> > machine the output looks as follows:
> > 
> > # ./test_progs -n 23/1
> > --- -   2022-12-09 17:22:03.412602033 +0000
> > +++ /tmp/btf_dump_test_case_syntax.output.Z28uhX        2022-12-09 17:22:03.403945082 +0000
> > @@ -23,13 +23,13 @@
> >  } __attribute__((mode(byte)));
> > 
> >  enum e_word {
> > -       EWORD_1 = 0LL,
> > -       EWORD_2 = 1LL,
> > +       EWORD_1 = 0,
> > +       EWORD_2 = 1,
> >  } __attribute__((mode(word)));
> > 
> >  enum e_big {
> > -       EBIG_1 = 1000000000000ULL,
> > -};
> > +       EBIG_1 = 3567587328,
> > +} __attribute__((mode(word)));
> > 
> 
> You seem to have too old Clang which doesn't emit ENUM64 types, try upgrading?

My apologies, you are correct.

> 
> 
> > But this is not related to your changes, here is a raw dump:
> > 
> > $ bpftool btf dump file ./btf_dump_test_case_syntax.bpf.o
> > 
> > [10] ENUM 'e_big' encoding=UNSIGNED size=8 vlen=1
> >         'EBIG_1' val=3567587328
> > 
> > >  typedef volatile const int * volatile const crazy_ptr_t;
> > > @@ -224,6 +257,9 @@ struct root_struct {
> > >       enum e2 _2;
> > >       e2_t _2_1;
> > >       e3_t _2_2;
> > > +     enum e_byte _100;
> > > +     enum e_word _101;
> > > +     enum e_big _102;
> > >       struct struct_w_typedefs _3;
> > >       anon_struct_t _7;
> > >       struct struct_fwd *_8;
> >
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/progs/btf_dump_test_case_syntax.c b/tools/testing/selftests/bpf/progs/btf_dump_test_case_syntax.c
index 4ee4748133fe..26fffb02ed10 100644
--- a/tools/testing/selftests/bpf/progs/btf_dump_test_case_syntax.c
+++ b/tools/testing/selftests/bpf/progs/btf_dump_test_case_syntax.c
@@ -25,6 +25,39 @@  typedef enum {
 	H = 2,
 } e3_t;
 
+/* ----- START-EXPECTED-OUTPUT ----- */
+/*
+ *enum e_byte {
+ *	EBYTE_1 = 0,
+ *	EBYTE_2 = 1,
+ *} __attribute__((mode(byte)));
+ *
+ */
+/* ----- END-EXPECTED-OUTPUT ----- */
+enum e_byte {
+	EBYTE_1,
+	EBYTE_2,
+} __attribute__((mode(byte)));
+
+/* ----- START-EXPECTED-OUTPUT ----- */
+/*
+ *enum e_word {
+ *	EWORD_1 = 0LL,
+ *	EWORD_2 = 1LL,
+ *} __attribute__((mode(word)));
+ *
+ */
+/* ----- END-EXPECTED-OUTPUT ----- */
+enum e_word {
+	EWORD_1,
+	EWORD_2,
+} __attribute__((mode(word))); /* force to use 8-byte backing for this enum */
+
+/* ----- START-EXPECTED-OUTPUT ----- */
+enum e_big {
+	EBIG_1 = 1000000000000ULL,
+};
+
 typedef int int_t;
 
 typedef volatile const int * volatile const crazy_ptr_t;
@@ -224,6 +257,9 @@  struct root_struct {
 	enum e2 _2;
 	e2_t _2_1;
 	e3_t _2_2;
+	enum e_byte _100;
+	enum e_word _101;
+	enum e_big _102;
 	struct struct_w_typedefs _3;
 	anon_struct_t _7;
 	struct struct_fwd *_8;