perf: fix some tests for musl
v2 cover perf: fix some tests for musl
Fix some perf tests for systems that use musl instead of glibc.
v2:
- add Namhyung's Acked-by for patch 1
- stricter flags check for patch 2
- more generic workload in patch 3
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 | 5 ++++- tools/perf/tests/shell/ftrace.sh | 7 ++++--- tools/perf/tests/shell/trace_summary.sh | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-)
Signature · 1 line
2.43.7
PATCH v2 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.
---
v2:
- add Acked-by
tools/perf/tests/shell/ftrace.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
tools/perf/tests/shell/ftrace.sh +4 -3
@@ -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
PATCH v2 2/3 perf test: fix sys_enter_openat event test for musl
In reply to Martin KaiserThe "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, the access mode flags must be unchanged.
---
v2:
- check that access mode is unchanged
tools/perf/tests/openat-syscall-tp-fields.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
tools/perf/tests/openat-syscall-tp-fields.c +4 -1
@@ -120,7 +120,10 @@ 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, +access mode must be unchanged */ +if ((tp_flags &O_ACCMODE ) != (flags &O_ACCMODE ) || + (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
Ian Rogers
reviewerRe: [PATCH v2 2/3] perf test: fix sys_enter_openat event test for musl
Quoted 25 lines · 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, the access mode flags must be unchanged.
Signed-off-by Martin Kaiser <[email protected]>---
v2:
- check that access mode is unchangedtools/perf/tests/openat-syscall-tp-fields.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)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 6 lines
tools/perf/tests/openat-syscall-tp-fields.c +2
-1@@ -120,7 +120,10 @@ 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, +access mode must be unchanged */
I think normal style would be:
``` /* * C library ... */ ```
tools/perf/tests/openat-syscall-tp-fields.c static int test__syscall_openat_tp_fields(struct test_suite *test __maybe_unused · line 126
Quoted 2 lines
tools/perf/tests/openat-syscall-tp-fields.c +2
-0+if ((tp_flags &O_ACCMODE ) != (flags &O_ACCMODE ) || + (tp_flags & flags) != flags) {
How can this second condition be true given the first condition?
Thanks,
Ian
Quoted 6 lines
tools/perf/tests/openat-syscall-tp-fields.c +0
-1pr_debug ("%s: Expected flags=%#x, got %#x\n" , __func__, flags, tp_flags); goto out_delete_evlist; --2.43.7
Re: [PATCH v2 2/3] perf test: fix sys_enter_openat event test for musl
Thus wrote Ian Rogers ([email protected]):
Quoted 33 lines · Martin Kaiser
Quoted 25 lines
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, the access mode flags must be unchanged.
Signed-off-by Martin Kaiser <[email protected]>---
v2:
- check that access mode is unchangedtools/perf/tests/openat-syscall-tp-fields.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)tools/perf/tests/openat-syscall-tp-fields.c +0
-0tools/perf/tests/openat-syscall-tp-fields.c static int test__syscall_openat_tp_fields(struct test_suite *test __maybe_unused · line 124
Quoted 6 lines
tools/perf/tests/openat-syscall-tp-fields.c +2
-1@@ -120,7 +120,10 @@ 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, +access mode must be unchanged */
Quoted 6 lines
I think normal style would be:
``` /* * C library ... */ ```
Ok, will fix this if we need another version.
Quoted 4 lines
tools/perf/tests/openat-syscall-tp-fields.c static int test__syscall_openat_tp_fields(struct test_suite *test __maybe_unused · line 126
Quoted 2 lines
tools/perf/tests/openat-syscall-tp-fields.c +2
-0+if ((tp_flags &O_ACCMODE ) != (flags &O_ACCMODE ) || + (tp_flags & flags) != flags) {How can this second condition be true given the first condition?
Sorry if I am missing something obvious.
The O_ACCMODE check verifies that the two lower bits (access mode flags) in the syscall and in the recorded event are identical.
The second check tests that all flags from the syscall are also set in the event. Additional flags in the event are ok.
For tp_flags == 0x0 and flags == 0x4, the first condition is false, the second one is true.
Best regards,
Martin
Quoted 8 lines
Thanks,
IanQuoted 5 lines
tools/perf/tests/openat-syscall-tp-fields.c +0
-1pr_debug ("%s: Expected flags=%#x, got %#x\n" , __func__, flags, tp_flags); goto out_delete_evlist; --2.43.7
PATCH v2 3/3 perf test: fix "trace summary" test for musl-based systems
In reply to Martin KaiserThe 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 "cat /dev/null" instead of "true". This creates the required events regardless of the C library and it works for cat from busybox or from coreutils.
---
v2:
- use cat /dev/null, this works for busybox and coreutils
tools/perf/tests/shell/trace_summary.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
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="cat /dev/null" search="^\s*(open|read|close).*[0-9]+%$" echo "testing: perf trace ${args} -- ${workload}"
Signature · 1 line
2.43.7
Re: [PATCH v2 3/3] perf test: fix "trace summary" test for musl-based systems
Quoted 39 lines · Martin Kaiser
The trace summary test calls
/bin/trueand 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.soroot@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 "cat
/dev/null" instead of "true". This creates the required events regardless of the C library and it works for cat from busybox or from coreutils.Signed-off-by Martin Kaiser <[email protected]>---
v2:
- use cat/dev/null, this works for busybox and coreutilstools/perf/tests/shell/trace_summary.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/perf/tests/shell/trace_summary.sh +0
-0
tools/perf/tests/shell/trace_summary.sh OUTPUT=$(mktemp /tmp/perf_trace_test.XXXXX) · line 17
Quoted 5 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="cat /dev/null"
Could we capture why the unusual workload in a comment, I know it is in the commit message.
Thanks,
Ian
Quoted 6 lines
tools/perf/tests/shell/trace_summary.sh +0
-1search="^\s*(open|read|close).*[0-9]+%$" echo "testing: perf trace ${args} -- ${workload}" --2.43.7
Quoted 11 lines · Martin Kaiser
Fix some perf tests for systems that use musl instead of glibc.
v2:
- add Namhyung's Acked-by for patch 1
- stricter flags check for patch 2
- more generic workload in patch 3Martin Kaiser (3):
perf test: fix nanosleep check in the ftrace test perf test: fixsys_enter_openatevent test for musl perf test: fix "trace summary" test for musl-based systems
Thanks,
Namhyung
Quoted 9 lines
tools/perf/tests/openat-syscall-tp-fields.c | 5 ++++- tools/perf/tests/shell/ftrace.sh | 7 ++++--- tools/perf/tests/shell/trace_summary.sh | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-)Signature · 1 line
2.43.7