Skip to content

Selftests global tags ordering#11484

Closed
eddyz87 wants to merge 5 commits intokernel-patches:bpf-next_basefrom
eddyz87:selftests-global-tags-ordering
Closed

Selftests global tags ordering#11484
eddyz87 wants to merge 5 commits intokernel-patches:bpf-next_basefrom
eddyz87:selftests-global-tags-ordering

Conversation

@eddyz87
Copy link
Copy Markdown
Collaborator

@eddyz87 eddyz87 commented Mar 20, 2026

No description provided.

@kernel-patches-daemon-bpf kernel-patches-daemon-bpf Bot force-pushed the bpf-next_base branch 12 times, most recently from 434ad19 to 2c59812 Compare March 25, 2026 15:55
@eddyz87 eddyz87 force-pushed the selftests-global-tags-ordering branch 3 times, most recently from 4e65c57 to 6a47829 Compare March 26, 2026 17:35
@kernel-patches-daemon-bpf kernel-patches-daemon-bpf Bot force-pushed the bpf-next_base branch 3 times, most recently from 7d66a13 to 5968176 Compare March 29, 2026 17:03
@eddyz87 eddyz87 force-pushed the selftests-global-tags-ordering branch 2 times, most recently from 392934f to 922889c Compare March 30, 2026 23:43
@eddyz87 eddyz87 force-pushed the selftests-global-tags-ordering branch from 922889c to 4fc8fc8 Compare March 31, 2026 19:13
@kernel-patches-daemon-bpf kernel-patches-daemon-bpf Bot force-pushed the bpf-next_base branch 8 times, most recently from 9ebb4fa to 0ba7f87 Compare April 3, 2026 15:28
@kernel-patches-daemon-bpf kernel-patches-daemon-bpf Bot force-pushed the bpf-next_base branch 5 times, most recently from 9192b33 to 7347239 Compare April 10, 2026 19:47
eddyz87 added 5 commits April 10, 2026 13:58
Impose global ordering for all decl tags used by test_loader.c based
tests: __success, __failure, __msg, etc. The tags are now sorted by
testing framework to be processed in the same order they appear in the
C source code of the test.

The ordering is necessary for gcc-bpf. Neither GCC nor the C standard
defines the order in which function attributes are consumed.
While Clang tends to preserve tags definition order in the output BTF,
GCC does not. This inconsistency causes BPF tests with multiple __msg
entries to fail when compiled with GCC.

This is based on a patch [1] from Cupertino Miranda (see patch kernel-patches#3) and
includes some additional cleanups for test_loader.c decl tags
declaration and processing (see patches #1, #2, kernel-patches#4).

[1] https://lore.kernel.org/bpf/20260305130035.192080-1-cupertino.miranda@oracle.com/

Changelog:
v2: https://lore.kernel.org/bpf/20260330-selftests-global-tags-ordering-v2-0-c0ac61e81098@gmail.com/
v2 -> v3:
- fixed free(tmp) call in collect_decl_tags() (Puranjay, bot)
- naming nit in compile_regex() (Mykyta)

v1: https://lore.kernel.org/bpf/20260326-selftests-global-tags-ordering-v1-0-5dd2ced5d9ad@gmail.com/
v1 -> v2:
- refactoring str_has_pfx() usages missing from v1 (Puranjay)
- removed realloc_or_free() (Andrii)
- fixed qsort(NULL, ...) usage (Puranjay)
- skip_decl_tag_pfx() returns NULL if tag does not start from
  "comment:" (Puranjay)

--- b4-submit-tracking ---
{
  "series": {
    "revision": 2,
    "change-id": "20260326-selftests-global-tags-ordering-8f324323d9c8",
    "prefixes": ["bpf-next"]
  }
}
__jited_unpriv was using "test_jited=" as its tag name, same as the
priv variant __jited. Fix by using "test_jited_unpriv=".

Fixes: 7d743e4 ("selftests/bpf: __jited test tag to check disassembly after jit")
Acked-by: Ihor Solodrai <ihor.solodrai@linux.dev>
Reviewed-by: Puranjay Mohan <puranjay@kernel.org>
Signed-off-by: Eduard Zingerman <eddyz87@gmail.com>
Change str_has_pfx() to return a pointer to the first character after
the prefix, thus eliminating the repetitive (s + sizeof(PFX) - 1)
patterns.

Acked-by: Ihor Solodrai <ihor.solodrai@linux.dev>
Acked-by: Mykyta Yatsenko <yatsenko@meta.com>
Reviewed-by: Puranjay Mohan <puranjay@kernel.org>
Signed-off-by: Eduard Zingerman <eddyz87@gmail.com>
Impose global ordering for all decl tags used by test_loader.c based
tests (__success, __failure, __msg, etc):
- change every tag to expand as
  __attribute__((btf_decl_tag("comment:" XSTR(__COUNTER__) ...)))
- change parse_test_spec() to collect all decl tags before
  processing and sort them using strverscmp().

The ordering is necessary for gcc-bpf.
Neither GCC nor the C standard defines the order in which function
attributes are consumed. While Clang tends to preserve definition order,
GCC may process them out of sequence. This inconsistency causes BPF
tests with multiple __msg entries to fail when compiled with GCC.

Signed-off-by: Cupertino Miranda <cupertino.miranda@oracle.com>
Reviewed-by: Puranjay Mohan <puranjay@kernel.org>
Signed-off-by: Eduard Zingerman <eddyz87@gmail.com>
After str_has_pfx() refactoring each TEST_TAG_* / TEST_BTF_PATH
constant is used exactly once. Since constant definitions are not
shared between BPF-side bpf_misc.h and userspace side test_loader.c,
there is no need in the additional redirection layer.

Acked-by: Ihor Solodrai <ihor.solodrai@linux.dev>
Reviewed-by: Puranjay Mohan <puranjay@kernel.org>
Signed-off-by: Eduard Zingerman <eddyz87@gmail.com>
@eddyz87 eddyz87 force-pushed the selftests-global-tags-ordering branch from b7c00a3 to 04b0fd1 Compare April 10, 2026 20:58
@kernel-patches-daemon-bpf kernel-patches-daemon-bpf Bot force-pushed the bpf-next_base branch 18 times, most recently from d7f44a8 to 9604fd1 Compare April 15, 2026 16:03
@kernel-patches-daemon-bpf
Copy link
Copy Markdown

Automatically cleaning up stale PR; feel free to reopen if needed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant