Skip to contentSkip to conversation

perf: fix some tests for musl

PATCH Superseded Martin Kaiser 3 participants 10 messages Apr 27 – Apr 28 perf events

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover perf: fix some tests for musl

Martin Kaiser (3):
perf test: fix nanosleep check in the ftrace test perf test: fix sys_enter_openat event test for musl perf test: fix "trace summary" test for musl-based systems

 tools/perf/tests/openat-syscall-tp-fields.c | 3 ++-
 tools/perf/tests/shell/ftrace.sh            | 7 ++++---
 tools/perf/tests/shell/trace_summary.sh     | 2 +-
 3 files changed, 7 insertions(+), 5 deletions(-)
Signature · 1 line
2.43.7
#1 lore raw

PATCH 1/3 perf test: fix nanosleep check in the ftrace test

The perf ftrace test case runs

perf ftrace profile --graph-opts depth=5 sleep 0.1

and checks that the output contains a *clock_nanosleep function with a count of 1.

This fails on a risc-v system that uses musl as its C library. musl's nanosleep syscall wrapper uses either the nanosleep or the clock_nanosleep syscall.

Filter for sys_*nanosleep to allow both syscalls.

---
 tools/perf/tests/shell/ftrace.sh | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
tools/perf/tests/shell/ftrace.sh +4 -3
index 7f8aafcbb761..9f6e590f6437 100755
@@ -71,9 +71,10 @@ test_ftrace_profile() {
     grep ^# "${output}"
     time_re="[[:space:]]+1[[:digit:]]{5}\.[[:digit:]]{3}"
     # 100283.000 100283.000 100283.000          1   __x64_sys_clock_nanosleep
-    # Check for one *clock_nanosleep line with a Count of just 1 that takes a bit more than 0.1 seconds
-    # Strip the _x64_sys part to work with other architectures
-    grep -E "^${time_re}${time_re}${time_re}[[:space:]]+1[[:space:]]+.*clock_nanosleep" "${output}"
+    # Check for one *sys_*nanosleep line with a Count of just 1 that takes a bit more than 0.1 seconds
+    # Strip the _x64_ part to work with other architectures, strip the clock part to support
+    # C libraries that use the nanosleep syscall instead of clock_nanosleep
+    grep -E "^${time_re}${time_re}${time_re}[[:space:]]+1[[:space:]]+.*sys_.*nanosleep" "${output}"
     echo "perf ftrace profile test  [Success]"
 }
 
Signature · 1 line
2.43.7
maintainer Acked-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] perf test: fix nanosleep check in the ftrace test

Quoted 7 lines · Martin Kaiser

The perf ftrace test case runs

perf ftrace profile --graph-opts depth=5 sleep 0.1

and checks that the output contains a *clock_nanosleep function with a count of 1.

Quoted 7 lines

This fails on a risc-v system that uses musl as its C library. musl's nanosleep syscall wrapper uses either the nanosleep or the clock_nanosleep syscall.

Filter for sys_*nanosleep to allow both syscalls.

Thanks,
Namhyung

Quoted 25 lines
---
 tools/perf/tests/shell/ftrace.sh | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
tools/perf/tests/shell/ftrace.sh +4 -3
index 7f8aafcbb761..9f6e590f6437 100755
@@ -71,9 +71,10 @@ test_ftrace_profile() {
     grep ^# "${output}"
     time_re="[[:space:]]+1[[:digit:]]{5}\.[[:digit:]]{3}"
     # 100283.000 100283.000 100283.000          1   __x64_sys_clock_nanosleep
-    # Check for one *clock_nanosleep line with a Count of just 1 that takes a bit more than 0.1 seconds
-    # Strip the _x64_sys part to work with other architectures
-    grep -E "^${time_re}${time_re}${time_re}[[:space:]]+1[[:space:]]+.*clock_nanosleep" "${output}"
+    # Check for one *sys_*nanosleep line with a Count of just 1 that takes a bit more than 0.1 seconds
+    # Strip the _x64_ part to work with other architectures, strip the clock part to support
+    # C libraries that use the nanosleep syscall instead of clock_nanosleep
+    grep -E "^${time_re}${time_re}${time_re}[[:space:]]+1[[:space:]]+.*sys_.*nanosleep" "${output}"
     echo "perf ftrace profile test  [Success]"
 }
 
Signature · 1 line
2.43.7
#3 lore raw

PATCH 2/3 perf test: fix sys_enter_openat event test for musl

In reply to Martin Kaiser

The "syscalls:sys_enter_openat event fields" test calls

openat(AT_FDCWD, "/etc/passwd", O_RDONLY | O_DIRECTORY)

and verifies that the flags of the captured event are matching. This fails for musl, where the openat syscall wrapper always adds O_LARGEFILE.

Update the check to allow for additional flags. Fail the test only if one of our flags is missing.

---
 tools/perf/tests/openat-syscall-tp-fields.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/tests/openat-syscall-tp-fields.c +2 -1
index 2a139d2781a8..366b3bf39def 100644
@@ -120,7 +120,8 @@ static int test__syscall_openat_tp_fields(struct test_suite *test __maybe_unused
 
 				tp_flags = evsel__intval(evsel, &sample, "flags");
 				perf_sample__exit(&sample);
-				if (flags != tp_flags) {
+				/* C library wrapper may set additional flags */
+				if ((tp_flags & flags) != flags) {
 					pr_debug("%s: Expected flags=%#x, got %#x\n",
 						 __func__, flags, tp_flags);
 					goto out_delete_evlist;
Signature · 1 line
2.43.7
#4 lore raw

Re: [PATCH 2/3] perf test: fix sys_enter_openat event test for musl

Sashiko AI review found 1 potential issue(s): - [Medium] The updated bitwise check `(tp_flags & flags) != flags` fails to verify the `O_RDONLY` access mode and permits arbitrary unrelated flags…

Sashiko AI review found 1 potential issue(s):
- [Medium] The updated bitwise check (tp_flags & flags) != flags fails to verify the O_RDONLY access mode and permits arbitrary unrelated flags, severely weakening the test. --

commit 0700122c98ba7f263a329cd8f9fbeef95b67603e
Author: Martin Kaiser <[email protected]>

perf test: fix sys_enter_openat event test for musl

This commit updates the sys_enter_openat test to allow additional flags in the captured event. It replaces the strict equality check with a bitwise mask check to accommodate the O_LARGEFILE flag implicitly added by musl libc.

Quoted 3 lines
tools/perf/tests/openat-syscall-tp-fields.c +0 -0

[ ... ]

tools/perf/tests/openat-syscall-tp-fields.c static int test__syscall_openat_tp_fields(struct test_suite *test __maybe_unused · line 124

Quoted 7 lines
tools/perf/tests/openat-syscall-tp-fields.c +2 -1
@@ -120,7 +120,8 @@ static int test__syscall_openat_tp_fields(struct test_suite *test __maybe_unused
 
 				tp_flags = evsel__intval(evsel, &sample, "flags");
 				perf_sample__exit(&sample);
-				if (flags != tp_flags) {
+				/* C library wrapper may set additional flags */
+				if ((tp_flags & flags) != flags) {

Does this check still verify the O_RDONLY access mode?

Since O_RDONLY is defined as 0, the flags variable evaluates to exactly O_DIRECTORY. This means the condition functionally becomes (tp_flags & O_DIRECTORY) != O_DIRECTORY.

Does this unintentionally permit other access modes like O_WRONLY or O_RDWR, and ignore other unrelated flags as long as O_DIRECTORY is set?

Quoted 3 lines
tools/perf/tests/openat-syscall-tp-fields.c +0 -0
 					pr_debug("%s: Expected flags=%#x, got %#x\n",
 						 __func__, flags, tp_flags);
 					goto out_delete_evlist;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
maintainer Acked-by
#5 lore raw

Re: [PATCH 2/3] perf test: fix sys_enter_openat event test for musl

Quoted 29 lines · On Mon, Apr 27, 2026 at 09:49:37AM +0000, [email protected] wrote:

Sashiko AI review found 1 potential issue(s):
- [Medium] The updated bitwise check (tp_flags & flags) != flags fails to verify the O_RDONLY access mode and permits arbitrary unrelated flags, severely weakening the test. --

commit 0700122c98ba7f263a329cd8f9fbeef95b67603e
Author: Martin Kaiser <[email protected]>

perf test: fix sys_enter_openat event test for musl

This commit updates the sys_enter_openat test to allow additional flags in the captured event. It replaces the strict equality check with a bitwise mask check to accommodate the O_LARGEFILE flag implicitly added by musl libc.

Quoted 3 lines
tools/perf/tests/openat-syscall-tp-fields.c +0 -0

[ ... ]

tools/perf/tests/openat-syscall-tp-fields.c static int test__syscall_openat_tp_fields(struct test_suite *test __maybe_unused · line 124

Quoted 7 lines
tools/perf/tests/openat-syscall-tp-fields.c +2 -1
@@ -120,7 +120,8 @@ static int test__syscall_openat_tp_fields(struct test_suite *test __maybe_unused
 
 				tp_flags = evsel__intval(evsel, &sample, "flags");
 				perf_sample__exit(&sample);
-				if (flags != tp_flags) {
+				/* C library wrapper may set additional flags */
+				if ((tp_flags & flags) != flags) {

Does this check still verify the O_RDONLY access mode?

Quoted 6 lines

Since O_RDONLY is defined as 0, the flags variable evaluates to exactly O_DIRECTORY. This means the condition functionally becomes (tp_flags & O_DIRECTORY) != O_DIRECTORY.

Does this unintentionally permit other access modes like O_WRONLY or O_RDWR, and ignore other unrelated flags as long as O_DIRECTORY is set?

I think it's ok for tp_flags to have more flags.

Thanks,
Namhyung

Quoted 7 lines
Quoted 4 lines
tools/perf/tests/openat-syscall-tp-fields.c +0 -0
 					pr_debug("%s: Expected flags=%#x, got %#x\n",
 						 __func__, flags, tp_flags);
 					goto out_delete_evlist;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#6 lore raw

Re: [PATCH 2/3] perf test: fix sys_enter_openat event test for musl

Thus wrote Namhyung Kim ([email protected]):

Quoted 30 lines · On Mon, Apr 27, 2026 at 09:49:37AM +0000, [email protected] wrote:
Quoted 28 lines

Sashiko AI review found 1 potential issue(s):
- [Medium] The updated bitwise check (tp_flags & flags) != flags fails to verify the O_RDONLY access mode and permits arbitrary unrelated flags, severely weakening the test. --

commit 0700122c98ba7f263a329cd8f9fbeef95b67603e
Author: Martin Kaiser <[email protected]>

perf test: fix sys_enter_openat event test for musl

This commit updates the sys_enter_openat test to allow additional flags in the captured event. It replaces the strict equality check with a bitwise mask check to accommodate the O_LARGEFILE flag implicitly added by musl libc.

Quoted 3 lines
tools/perf/tests/openat-syscall-tp-fields.c +0 -0

[ ... ]

tools/perf/tests/openat-syscall-tp-fields.c static int test__syscall_openat_tp_fields(struct test_suite *test __maybe_unused · line 124

Quoted 7 lines
tools/perf/tests/openat-syscall-tp-fields.c +2 -1
@@ -120,7 +120,8 @@ static int test__syscall_openat_tp_fields(struct test_suite *test __maybe_unused
 
 				tp_flags = evsel__intval(evsel, &sample, "flags");
 				perf_sample__exit(&sample);
-				if (flags != tp_flags) {
+				/* C library wrapper may set additional flags */
+				if ((tp_flags & flags) != flags) {

Does this check still verify the O_RDONLY access mode?

Quoted 8 lines
Quoted 6 lines

Since O_RDONLY is defined as 0, the flags variable evaluates to exactly O_DIRECTORY. This means the condition functionally becomes (tp_flags & O_DIRECTORY) != O_DIRECTORY.

Does this unintentionally permit other access modes like O_WRONLY or O_RDWR, and ignore other unrelated flags as long as O_DIRECTORY is set?

I think it's ok for tp_flags to have more flags.

I added another check for the access mode flags in v2. This addresses the sashiko comment and allows for additional flags in the syscall wrapper.

Best regards,
Martin

Quoted 12 lines

Thanks,
Namhyung

Quoted 6 lines
Quoted 3 lines
tools/perf/tests/openat-syscall-tp-fields.c +0 -0
 					pr_debug("%s: Expected flags=%#x, got %#x\n",
 						 __func__, flags, tp_flags);
 					goto out_delete_evlist;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#7 lore raw

PATCH 3/3 perf test: fix "trace summary" test for musl-based systems

In reply to Martin Kaiser

The trace summary test calls /bin/true and filters for open, read and close events. These events are coming from shared library loads.

On a musl system, the loader and libc may point to the same file. true needs only libc, no further shared libraries are loaded at startup. The test fails since no open, read and close events are captured.

root@host:~# ldd /bin/true
	/lib/ld-musl-riscv64.so.1 (0x3fb8882000)
	libc.so => /lib/ld-musl-riscv64.so.1 (0x3fb8882000)
root@host:~# file /lib/ld-musl-riscv64.so.1
/lib/ld-musl-riscv64.so.1: symbolic link to /usr/lib/libc.so
root@host:~# strace -f /bin/true
execve("/bin/true", ["/bin/true", ...], ... /* 18 vars */) = 1
set_tid_address(0x3fa1f7bf70)           = 330
mprotect(0x2ad6b8e000, 12288, PROT_READ) = 0
exit_group(0)                           = ?
+++ exited with 0 +++

Run "ps --help" instead of "true". ps needs at least libprocps and we'll get the events that are needed for the test.

---
 tools/perf/tests/shell/trace_summary.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/tests/shell/trace_summary.sh +1 -1
index 22e2651d5919..03be213bb7bf 100755
@@ -14,7 +14,7 @@ OUTPUT=$(mktemp /tmp/perf_trace_test.XXXXX)
 
 test_perf_trace() {
     args=$1
-    workload="true"
+    workload="ps --help"
     search="^\s*(open|read|close).*[0-9]+%$"
 
     echo "testing: perf trace ${args} -- ${workload}"
Signature · 1 line
2.43.7
#8 lore raw

Re: [PATCH 3/3] perf test: fix "trace summary" test for musl-based systems

Sashiko AI review found 1 potential issue(s): - [Medium] The `ps --help` test workload is brittle and will continue to fail on many musl-based systems that use BusyBox. --

Sashiko AI review found 1 potential issue(s):
- [Medium] The ps --help test workload is brittle and will continue to fail on many musl-based systems that use BusyBox. --

commit 41e18297314ee059526c7fb6d14d02d61ba92d64
Author: Martin Kaiser <[email protected]>

perf test: fix "trace summary" test for musl-based systems

This commit updates the trace summary test to use ps --help instead of true. The goal is to ensure the test workload triggers open, read, and close events from dynamic library loading on musl-based systems.

tools/perf/tests/shell/trace_summary.sh OUTPUT=$(mktemp /tmp/perf_trace_test.XXXXX) · line 17

Quoted 9 lines
tools/perf/tests/shell/trace_summary.sh +1 -1
@@ -14,7 +14,7 @@ OUTPUT=$(mktemp /tmp/perf_trace_test.XXXXX)
 
 test_perf_trace() {
     args=$1
-    workload="true"
+    workload="ps --help"

Will this workload still fail on musl-based systems that use BusyBox?

Many musl-based distributions, such as Alpine Linux or OpenWrt, frequently use BusyBox to provide standard utilities. BusyBox's ps is typically statically linked or links only to libc, without depending on libprocps.

Furthermore, running ps --help in BusyBox generally prints the usage string and exits without performing file I/O, which means no open, read, or close events will be generated.

Would a command that natively performs file I/O, such as cat /dev/null or dd if=/dev/null of=/dev/null, be more robust here?

Quoted 1 line
tools/perf/tests/shell/trace_summary.sh +0 -0
     search="^\s*(open|read|close).*[0-9]+%$"
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
maintainer
#9 lore raw

Re: [PATCH 3/3] perf test: fix "trace summary" test for musl-based systems

Quoted 29 lines · On Mon, Apr 27, 2026 at 09:57:44AM +0000, [email protected] wrote:

Sashiko AI review found 1 potential issue(s):
- [Medium] The ps --help test workload is brittle and will continue to fail on many musl-based systems that use BusyBox. --

commit 41e18297314ee059526c7fb6d14d02d61ba92d64
Author: Martin Kaiser <[email protected]>

perf test: fix "trace summary" test for musl-based systems

This commit updates the trace summary test to use ps --help instead of true. The goal is to ensure the test workload triggers open, read, and close events from dynamic library loading on musl-based systems.

tools/perf/tests/shell/trace_summary.sh OUTPUT=$(mktemp /tmp/perf_trace_test.XXXXX) · line 17

Quoted 9 lines
tools/perf/tests/shell/trace_summary.sh +1 -1
@@ -14,7 +14,7 @@ OUTPUT=$(mktemp /tmp/perf_trace_test.XXXXX)
 
 test_perf_trace() {
     args=$1
-    workload="true"
+    workload="ps --help"

Will this workload still fail on musl-based systems that use BusyBox?

Many musl-based distributions, such as Alpine Linux or OpenWrt, frequently use BusyBox to provide standard utilities. BusyBox's ps is typically statically linked or links only to libc, without depending on libprocps.

Quoted 6 lines

Furthermore, running ps --help in BusyBox generally prints the usage string and exits without performing file I/O, which means no open, read, or close events will be generated.

Would a command that natively performs file I/O, such as cat /dev/null or dd if=/dev/null of=/dev/null, be more robust here?

Sounds right, it'd be nice if the workload doesn't print anything like above.

Thanks,
Namhyung

Quoted 5 lines
Quoted 2 lines
tools/perf/tests/shell/trace_summary.sh +0 -0
     search="^\s*(open|read|close).*[0-9]+%$"
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3