Skip to contentSkip to conversation

perf: fix some tests for musl

PATCH In review Martin Kaiser 3 participants 8 messages Apr 28 – Apr 30 perf events

lore
Share & tools
lore
#0 lore raw

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
#1 lore raw

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
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
#2 lore raw

PATCH v2 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, 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
index 2a139d2781a8..5523cf4e9321 100644
@@ -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
reviewer
#3 lore raw

Re: [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.

---
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 +0 -0
index 2a139d2781a8..5523cf4e9321 100644

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 -1
                                        pr_debug("%s: Expected flags=%#x, got %#x\n",
                                                 __func__, flags, tp_flags);
                                        goto out_delete_evlist;
--

2.43.7

#4 lore raw

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.

---
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 +0 -0
index 2a139d2781a8..5523cf4e9321 100644

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 */
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,
Ian

Quoted 5 lines
tools/perf/tests/openat-syscall-tp-fields.c +0 -1
                                        pr_debug("%s: Expected flags=%#x, got %#x\n",
                                                 __func__, flags, tp_flags);
                                        goto out_delete_evlist;
--

2.43.7

#5 lore raw

PATCH v2 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 "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
index 22e2651d5919..b80dea77cec6 100755
@@ -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
reviewer Acked-by on v2 3/3
#6 lore raw

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/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 +0 -0
index 22e2651d5919..b80dea77cec6 100755

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 -1
     search="^\s*(open|read|close).*[0-9]+%$"
 
     echo "testing: perf trace ${args} -- ${workload}"
--

2.43.7

maintainer Acked-by on the v2 series
#7 lore raw
In reply to Martin Kaiser
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 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

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