[PATCH bpf-next v3 1/2] selftests/bpf: Fix uprobe_autoattach test

From: Tiezhu Yang

Date: Mon Nov 30 2026 - 00:05:50 EST


Commit bc72742bebec ("selftests/bpf: Validate arch-specific argument
registers limits") originally included the header "progs/bpf_misc.h"
in prog_tests/uprobe_autoattach.c so that FUNC_REG_ARG_CNT is defined
when checking argument assertions (arg4 through arg8).

Commit 8c2b5e90505e ("selftests/bpf: add bpf_for_each(), bpf_for(),
and bpf_repeat() macros") removed this include, causing the macro
FUNC_REG_ARG_CNT to evaluate to 0 in the preprocessor and silently
skipping all assertions beyond arg3 on every architecture.

Define a[FUNC_REG_ARG_CNT] in progs/test_uprobe_autoattach.c so the
skeleton takes the size of a[] from BTF, and iterate over the array
size of skel->bss->a in prog_tests/uprobe_autoattach.c rather than
relying on user-space preprocessor macros. Also use snprintf() to
keep the original "arg1".."arg8" subtest names in verbose output.

Here are the test results on LoongArch (default FUNC_REG_ARG_CNT
is 5).

Before:
$ sudo ./test_progs -v -t uprobe_autoattach
...
test_uprobe_autoattach:PASS:arg1 0 nsec
test_uprobe_autoattach:PASS:arg2 0 nsec
test_uprobe_autoattach:PASS:arg3 0 nsec
#659 uprobe_autoattach:OK

After:
$ sudo ./test_progs -v -t uprobe_autoattach
...
test_uprobe_autoattach:PASS:arg1 0 nsec
test_uprobe_autoattach:PASS:arg2 0 nsec
test_uprobe_autoattach:PASS:arg3 0 nsec
test_uprobe_autoattach:PASS:arg4 0 nsec
test_uprobe_autoattach:PASS:arg5 0 nsec
#659 uprobe_autoattach:OK

Fixes: 8c2b5e90505e ("selftests/bpf: add bpf_for_each(), bpf_for(), and bpf_repeat() macros")
Suggested-by: Alexei Starovoitov <ast@xxxxxxxxxx>
Signed-off-by: Tiezhu Yang <yangtiezhu@xxxxxxxxxxx>
---
.../bpf/prog_tests/uprobe_autoattach.c | 25 +++++--------------
.../bpf/progs/test_uprobe_autoattach.c | 2 +-
2 files changed, 7 insertions(+), 20 deletions(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/uprobe_autoattach.c b/tools/testing/selftests/bpf/prog_tests/uprobe_autoattach.c
index d5b3377aa33c..f8f486a443b6 100644
--- a/tools/testing/selftests/bpf/prog_tests/uprobe_autoattach.c
+++ b/tools/testing/selftests/bpf/prog_tests/uprobe_autoattach.c
@@ -17,7 +17,8 @@ void test_uprobe_autoattach(void)
{
const char *devnull_str = "/dev/null";
struct test_uprobe_autoattach *skel;
- int trigger_ret;
+ char buf[8];
+ int trigger_ret, i;
FILE *devnull;

skel = test_uprobe_autoattach__open_and_load();
@@ -49,24 +50,10 @@ void test_uprobe_autoattach(void)
"check_uretprobe_byname2_rc");
ASSERT_EQ(skel->bss->uretprobe_byname2_ran, 4, "check_uretprobe_byname2_ran");

- ASSERT_EQ(skel->bss->a[0], 1, "arg1");
- ASSERT_EQ(skel->bss->a[1], 2, "arg2");
- ASSERT_EQ(skel->bss->a[2], 3, "arg3");
-#if FUNC_REG_ARG_CNT > 3
- ASSERT_EQ(skel->bss->a[3], 4, "arg4");
-#endif
-#if FUNC_REG_ARG_CNT > 4
- ASSERT_EQ(skel->bss->a[4], 5, "arg5");
-#endif
-#if FUNC_REG_ARG_CNT > 5
- ASSERT_EQ(skel->bss->a[5], 6, "arg6");
-#endif
-#if FUNC_REG_ARG_CNT > 6
- ASSERT_EQ(skel->bss->a[6], 7, "arg7");
-#endif
-#if FUNC_REG_ARG_CNT > 7
- ASSERT_EQ(skel->bss->a[7], 8, "arg8");
-#endif
+ for (i = 0; i < ARRAY_SIZE(skel->bss->a); i++) {
+ snprintf(buf, sizeof(buf), "arg%d", i + 1);
+ ASSERT_EQ(skel->bss->a[i], i + 1, buf);
+ }

fclose(devnull);
cleanup:
diff --git a/tools/testing/selftests/bpf/progs/test_uprobe_autoattach.c b/tools/testing/selftests/bpf/progs/test_uprobe_autoattach.c
index da4bf89d004c..e59a4b8d1891 100644
--- a/tools/testing/selftests/bpf/progs/test_uprobe_autoattach.c
+++ b/tools/testing/selftests/bpf/progs/test_uprobe_autoattach.c
@@ -20,7 +20,7 @@ int uretprobe_byname2_ran = 0;

int test_pid;

-int a[8];
+int a[FUNC_REG_ARG_CNT];

/* This program cannot auto-attach, but that should not stop other
* programs from attaching.
--
2.42.0