diff mbox series

[bpf-next,06/10] selftests/bpf: Test BTF_KIND_DECL_TAG for deduplication

Message ID 20211110052012.371411-1-yhs@fb.com (mailing list archive)
State Superseded
Delegated to: BPF
Headers show
Series Support BTF_KIND_TYPE_TAG for btf_type_tag attributes | expand

Checks

Context Check Description
bpf/vmtest-bpf-next-PR success PR summary
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 7 maintainers not CCed: songliubraving@fb.com linux-kselftest@vger.kernel.org shuah@kernel.org john.fastabend@gmail.com kpsingh@kernel.org netdev@vger.kernel.org kafai@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/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch warning WARNING: Missing commit description - Add an appropriate one WARNING: line length of 107 exceeds 80 columns WARNING: line length of 81 exceeds 80 columns WARNING: line length of 86 exceeds 80 columns
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-next success VM_Test

Commit Message

Yonghong Song Nov. 10, 2021, 5:20 a.m. UTC
Signed-off-by: Yonghong Song <yhs@fb.com>
---
 tools/testing/selftests/bpf/prog_tests/btf.c | 46 ++++++++++++++++++--
 1 file changed, 42 insertions(+), 4 deletions(-)

Comments

Andrii Nakryiko Nov. 11, 2021, 6:49 p.m. UTC | #1
On Tue, Nov 9, 2021 at 9:21 PM Yonghong Song <yhs@fb.com> wrote:
>
> Signed-off-by: Yonghong Song <yhs@fb.com>
> ---
>  tools/testing/selftests/bpf/prog_tests/btf.c | 46 ++++++++++++++++++--
>  1 file changed, 42 insertions(+), 4 deletions(-)
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/btf.c b/tools/testing/selftests/bpf/prog_tests/btf.c
> index ebd0ead5f4bc..91b19c41729f 100644
> --- a/tools/testing/selftests/bpf/prog_tests/btf.c
> +++ b/tools/testing/selftests/bpf/prog_tests/btf.c
> @@ -6889,15 +6889,16 @@ const struct btf_dedup_test dedup_tests[] = {
>                         BTF_RESTRICT_ENC(8),                                            /* [11] restrict */
>                         BTF_FUNC_PROTO_ENC(1, 2),                                       /* [12] func_proto */
>                                 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
> -                               BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 8),
> +                               BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 18),
>                         BTF_FUNC_ENC(NAME_TBD, 12),                                     /* [13] func */
>                         BTF_TYPE_FLOAT_ENC(NAME_TBD, 2),                                /* [14] float */
>                         BTF_DECL_TAG_ENC(NAME_TBD, 13, -1),                             /* [15] decl_tag */
>                         BTF_DECL_TAG_ENC(NAME_TBD, 13, 1),                              /* [16] decl_tag */
>                         BTF_DECL_TAG_ENC(NAME_TBD, 7, -1),                              /* [17] decl_tag */
> +                       BTF_TYPE_TAG_ENC(NAME_TBD, 8),                                  /* [18] type_tag */
>                         BTF_END_RAW,
>                 },
> -               BTF_STR_SEC("\0A\0B\0C\0D\0E\0F\0G\0H\0I\0J\0K\0L\0M\0N\0O\0P\0Q"),
> +               BTF_STR_SEC("\0A\0B\0C\0D\0E\0F\0G\0H\0I\0J\0K\0L\0M\0N\0O\0P\0Q\0R"),
>         },
>         .expect = {
>                 .raw_types = {
> @@ -6918,15 +6919,16 @@ const struct btf_dedup_test dedup_tests[] = {
>                         BTF_RESTRICT_ENC(8),                                            /* [11] restrict */
>                         BTF_FUNC_PROTO_ENC(1, 2),                                       /* [12] func_proto */
>                                 BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
> -                               BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 8),
> +                               BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 18),
>                         BTF_FUNC_ENC(NAME_TBD, 12),                                     /* [13] func */
>                         BTF_TYPE_FLOAT_ENC(NAME_TBD, 2),                                /* [14] float */
>                         BTF_DECL_TAG_ENC(NAME_TBD, 13, -1),                             /* [15] decl_tag */
>                         BTF_DECL_TAG_ENC(NAME_TBD, 13, 1),                              /* [16] decl_tag */
>                         BTF_DECL_TAG_ENC(NAME_TBD, 7, -1),                              /* [17] decl_tag */
> +                       BTF_TYPE_TAG_ENC(NAME_TBD, 8),                                  /* [18] type_tag */
>                         BTF_END_RAW,
>                 },
> -               BTF_STR_SEC("\0A\0B\0C\0D\0E\0F\0G\0H\0I\0J\0K\0L\0M\0N\0O\0P\0Q"),
> +               BTF_STR_SEC("\0A\0B\0C\0D\0E\0F\0G\0H\0I\0J\0K\0L\0M\0N\0O\0P\0Q\0R"),
>         },
>         .opts = {
>                 .dont_resolve_fwds = false,
> @@ -7254,6 +7256,42 @@ const struct btf_dedup_test dedup_tests[] = {
>                 .dont_resolve_fwds = false,
>         },
>  },
> +{
> +       .descr = "dedup: btf_tag_type",
> +       .input = {
> +               .raw_types = {
> +                       /* int */
> +                       BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),  /* [1] */
> +                       /* tag: tag1, tag2 */
> +                       BTF_TYPE_TAG_ENC(NAME_NTH(1), 1),               /* [2] */
> +                       BTF_TYPE_TAG_ENC(NAME_NTH(2), 2),               /* [3] */
> +                       BTF_PTR_ENC(3),                                 /* [4] */
> +                       /* tag: tag1, tag2 */
> +                       BTF_TYPE_TAG_ENC(NAME_NTH(1), 1),               /* [5] */
> +                       BTF_TYPE_TAG_ENC(NAME_NTH(2), 5),               /* [6] */
> +                       BTF_PTR_ENC(6),                                 /* [7] */
> +                       /* tag: tag1 */
> +                       BTF_TYPE_TAG_ENC(NAME_NTH(1), 1),               /* [8] */
> +                       BTF_PTR_ENC(8),                                 /* [9] */
> +                       BTF_END_RAW,
> +               },
> +               BTF_STR_SEC("\0tag1\0tag2"),
> +       },

Can you please add a test for two more situations:

First, like this:

tag1 -> tag2 -> int
tag1 -> int

tag1's shouldn't be deduped

Second, like this

tag1 -> tag2 -> int
tag2 -> tag1 -> int

Nothing gets deduped.

Actually, also third situation:

tag1 -> int
tag1 -> long

Nothing gets deduped.

That will document expected behavior.

Thanks.

> +       .expect = {
> +               .raw_types = {
> +                       BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),  /* [1] */
> +                       BTF_TYPE_TAG_ENC(NAME_NTH(1), 1),               /* [2] */
> +                       BTF_TYPE_TAG_ENC(NAME_NTH(2), 2),               /* [3] */
> +                       BTF_PTR_ENC(3),                                 /* [4] */
> +                       BTF_PTR_ENC(2),                                 /* [5] */
> +                       BTF_END_RAW,
> +               },
> +               BTF_STR_SEC("\0tag1\0tag2"),
> +       },
> +       .opts = {
> +               .dont_resolve_fwds = false,
> +       },
> +},
>
>  };
>
> --
> 2.30.2
>
Yonghong Song Nov. 11, 2021, 7:13 p.m. UTC | #2
On 11/11/21 10:49 AM, Andrii Nakryiko wrote:
> On Tue, Nov 9, 2021 at 9:21 PM Yonghong Song <yhs@fb.com> wrote:
>>
>> Signed-off-by: Yonghong Song <yhs@fb.com>
>> ---
>>   tools/testing/selftests/bpf/prog_tests/btf.c | 46 ++++++++++++++++++--
>>   1 file changed, 42 insertions(+), 4 deletions(-)
>>
>> diff --git a/tools/testing/selftests/bpf/prog_tests/btf.c b/tools/testing/selftests/bpf/prog_tests/btf.c
>> index ebd0ead5f4bc..91b19c41729f 100644
>> --- a/tools/testing/selftests/bpf/prog_tests/btf.c
>> +++ b/tools/testing/selftests/bpf/prog_tests/btf.c
>> @@ -6889,15 +6889,16 @@ const struct btf_dedup_test dedup_tests[] = {
>>                          BTF_RESTRICT_ENC(8),                                            /* [11] restrict */
>>                          BTF_FUNC_PROTO_ENC(1, 2),                                       /* [12] func_proto */
>>                                  BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
>> -                               BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 8),
>> +                               BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 18),
>>                          BTF_FUNC_ENC(NAME_TBD, 12),                                     /* [13] func */
>>                          BTF_TYPE_FLOAT_ENC(NAME_TBD, 2),                                /* [14] float */
>>                          BTF_DECL_TAG_ENC(NAME_TBD, 13, -1),                             /* [15] decl_tag */
>>                          BTF_DECL_TAG_ENC(NAME_TBD, 13, 1),                              /* [16] decl_tag */
>>                          BTF_DECL_TAG_ENC(NAME_TBD, 7, -1),                              /* [17] decl_tag */
>> +                       BTF_TYPE_TAG_ENC(NAME_TBD, 8),                                  /* [18] type_tag */
>>                          BTF_END_RAW,
>>                  },
>> -               BTF_STR_SEC("\0A\0B\0C\0D\0E\0F\0G\0H\0I\0J\0K\0L\0M\0N\0O\0P\0Q"),
>> +               BTF_STR_SEC("\0A\0B\0C\0D\0E\0F\0G\0H\0I\0J\0K\0L\0M\0N\0O\0P\0Q\0R"),
>>          },
>>          .expect = {
>>                  .raw_types = {
>> @@ -6918,15 +6919,16 @@ const struct btf_dedup_test dedup_tests[] = {
>>                          BTF_RESTRICT_ENC(8),                                            /* [11] restrict */
>>                          BTF_FUNC_PROTO_ENC(1, 2),                                       /* [12] func_proto */
>>                                  BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
>> -                               BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 8),
>> +                               BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 18),
>>                          BTF_FUNC_ENC(NAME_TBD, 12),                                     /* [13] func */
>>                          BTF_TYPE_FLOAT_ENC(NAME_TBD, 2),                                /* [14] float */
>>                          BTF_DECL_TAG_ENC(NAME_TBD, 13, -1),                             /* [15] decl_tag */
>>                          BTF_DECL_TAG_ENC(NAME_TBD, 13, 1),                              /* [16] decl_tag */
>>                          BTF_DECL_TAG_ENC(NAME_TBD, 7, -1),                              /* [17] decl_tag */
>> +                       BTF_TYPE_TAG_ENC(NAME_TBD, 8),                                  /* [18] type_tag */
>>                          BTF_END_RAW,
>>                  },
>> -               BTF_STR_SEC("\0A\0B\0C\0D\0E\0F\0G\0H\0I\0J\0K\0L\0M\0N\0O\0P\0Q"),
>> +               BTF_STR_SEC("\0A\0B\0C\0D\0E\0F\0G\0H\0I\0J\0K\0L\0M\0N\0O\0P\0Q\0R"),
>>          },
>>          .opts = {
>>                  .dont_resolve_fwds = false,
>> @@ -7254,6 +7256,42 @@ const struct btf_dedup_test dedup_tests[] = {
>>                  .dont_resolve_fwds = false,
>>          },
>>   },
>> +{
>> +       .descr = "dedup: btf_tag_type",
>> +       .input = {
>> +               .raw_types = {
>> +                       /* int */
>> +                       BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),  /* [1] */
>> +                       /* tag: tag1, tag2 */
>> +                       BTF_TYPE_TAG_ENC(NAME_NTH(1), 1),               /* [2] */
>> +                       BTF_TYPE_TAG_ENC(NAME_NTH(2), 2),               /* [3] */
>> +                       BTF_PTR_ENC(3),                                 /* [4] */
>> +                       /* tag: tag1, tag2 */
>> +                       BTF_TYPE_TAG_ENC(NAME_NTH(1), 1),               /* [5] */
>> +                       BTF_TYPE_TAG_ENC(NAME_NTH(2), 5),               /* [6] */
>> +                       BTF_PTR_ENC(6),                                 /* [7] */
>> +                       /* tag: tag1 */
>> +                       BTF_TYPE_TAG_ENC(NAME_NTH(1), 1),               /* [8] */
>> +                       BTF_PTR_ENC(8),                                 /* [9] */
>> +                       BTF_END_RAW,
>> +               },
>> +               BTF_STR_SEC("\0tag1\0tag2"),
>> +       },
> 
> Can you please add a test for two more situations:
> 
> First, like this:
> 
> tag1 -> tag2 -> int
> tag1 -> int
> 
> tag1's shouldn't be deduped
> 
> Second, like this
> 
> tag1 -> tag2 -> int
> tag2 -> tag1 -> int
> 
> Nothing gets deduped.
> 
> Actually, also third situation:
> 
> tag1 -> int
> tag1 -> long
> 
> Nothing gets deduped.
> 
> That will document expected behavior.

Will do.

> 
> Thanks.
> 
>> +       .expect = {
>> +               .raw_types = {
>> +                       BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),  /* [1] */
>> +                       BTF_TYPE_TAG_ENC(NAME_NTH(1), 1),               /* [2] */
>> +                       BTF_TYPE_TAG_ENC(NAME_NTH(2), 2),               /* [3] */
>> +                       BTF_PTR_ENC(3),                                 /* [4] */
>> +                       BTF_PTR_ENC(2),                                 /* [5] */
>> +                       BTF_END_RAW,
>> +               },
>> +               BTF_STR_SEC("\0tag1\0tag2"),
>> +       },
>> +       .opts = {
>> +               .dont_resolve_fwds = false,
>> +       },
>> +},
>>
>>   };
>>
>> --
>> 2.30.2
>>
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/prog_tests/btf.c b/tools/testing/selftests/bpf/prog_tests/btf.c
index ebd0ead5f4bc..91b19c41729f 100644
--- a/tools/testing/selftests/bpf/prog_tests/btf.c
+++ b/tools/testing/selftests/bpf/prog_tests/btf.c
@@ -6889,15 +6889,16 @@  const struct btf_dedup_test dedup_tests[] = {
 			BTF_RESTRICT_ENC(8),						/* [11] restrict */
 			BTF_FUNC_PROTO_ENC(1, 2),					/* [12] func_proto */
 				BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
-				BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 8),
+				BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 18),
 			BTF_FUNC_ENC(NAME_TBD, 12),					/* [13] func */
 			BTF_TYPE_FLOAT_ENC(NAME_TBD, 2),				/* [14] float */
 			BTF_DECL_TAG_ENC(NAME_TBD, 13, -1),				/* [15] decl_tag */
 			BTF_DECL_TAG_ENC(NAME_TBD, 13, 1),				/* [16] decl_tag */
 			BTF_DECL_TAG_ENC(NAME_TBD, 7, -1),				/* [17] decl_tag */
+			BTF_TYPE_TAG_ENC(NAME_TBD, 8),					/* [18] type_tag */
 			BTF_END_RAW,
 		},
-		BTF_STR_SEC("\0A\0B\0C\0D\0E\0F\0G\0H\0I\0J\0K\0L\0M\0N\0O\0P\0Q"),
+		BTF_STR_SEC("\0A\0B\0C\0D\0E\0F\0G\0H\0I\0J\0K\0L\0M\0N\0O\0P\0Q\0R"),
 	},
 	.expect = {
 		.raw_types = {
@@ -6918,15 +6919,16 @@  const struct btf_dedup_test dedup_tests[] = {
 			BTF_RESTRICT_ENC(8),						/* [11] restrict */
 			BTF_FUNC_PROTO_ENC(1, 2),					/* [12] func_proto */
 				BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 1),
-				BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 8),
+				BTF_FUNC_PROTO_ARG_ENC(NAME_TBD, 18),
 			BTF_FUNC_ENC(NAME_TBD, 12),					/* [13] func */
 			BTF_TYPE_FLOAT_ENC(NAME_TBD, 2),				/* [14] float */
 			BTF_DECL_TAG_ENC(NAME_TBD, 13, -1),				/* [15] decl_tag */
 			BTF_DECL_TAG_ENC(NAME_TBD, 13, 1),				/* [16] decl_tag */
 			BTF_DECL_TAG_ENC(NAME_TBD, 7, -1),				/* [17] decl_tag */
+			BTF_TYPE_TAG_ENC(NAME_TBD, 8),					/* [18] type_tag */
 			BTF_END_RAW,
 		},
-		BTF_STR_SEC("\0A\0B\0C\0D\0E\0F\0G\0H\0I\0J\0K\0L\0M\0N\0O\0P\0Q"),
+		BTF_STR_SEC("\0A\0B\0C\0D\0E\0F\0G\0H\0I\0J\0K\0L\0M\0N\0O\0P\0Q\0R"),
 	},
 	.opts = {
 		.dont_resolve_fwds = false,
@@ -7254,6 +7256,42 @@  const struct btf_dedup_test dedup_tests[] = {
 		.dont_resolve_fwds = false,
 	},
 },
+{
+	.descr = "dedup: btf_tag_type",
+	.input = {
+		.raw_types = {
+			/* int */
+			BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
+			/* tag: tag1, tag2 */
+			BTF_TYPE_TAG_ENC(NAME_NTH(1), 1),		/* [2] */
+			BTF_TYPE_TAG_ENC(NAME_NTH(2), 2),		/* [3] */
+			BTF_PTR_ENC(3),					/* [4] */
+			/* tag: tag1, tag2 */
+			BTF_TYPE_TAG_ENC(NAME_NTH(1), 1),		/* [5] */
+			BTF_TYPE_TAG_ENC(NAME_NTH(2), 5),		/* [6] */
+			BTF_PTR_ENC(6),					/* [7] */
+			/* tag: tag1 */
+			BTF_TYPE_TAG_ENC(NAME_NTH(1), 1),		/* [8] */
+			BTF_PTR_ENC(8),					/* [9] */
+			BTF_END_RAW,
+		},
+		BTF_STR_SEC("\0tag1\0tag2"),
+	},
+	.expect = {
+		.raw_types = {
+			BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),	/* [1] */
+			BTF_TYPE_TAG_ENC(NAME_NTH(1), 1),		/* [2] */
+			BTF_TYPE_TAG_ENC(NAME_NTH(2), 2),		/* [3] */
+			BTF_PTR_ENC(3),					/* [4] */
+			BTF_PTR_ENC(2),					/* [5] */
+			BTF_END_RAW,
+		},
+		BTF_STR_SEC("\0tag1\0tag2"),
+	},
+	.opts = {
+		.dont_resolve_fwds = false,
+	},
+},
 
 };