Skip to contentSkip to conversation

perf/tests: convert Perl test helpers to Python

RFC PATCH Superseded Breno Rodrigues Alves 3 participants 27 messages Oct 18 – Oct 21

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover perf/tests: convert Perl test helpers to Python

This series converts five Perl test helpers in tools/ to Python 3, continuing the Perl-to-Python conversion effort for the kernel's auxiliary scripts.

Each conversion is a faithful 1:1 port: same CLI, same output, same exit codes. All use only the Python standard library.

The five scripts are:

  - prefix.pl                      -> prefix.py
  - check_all_patterns_found.pl    -> check_all_patterns_found.py
  - check_no_patterns_found.pl     -> check_no_patterns_found.py
  - check_all_lines_matched.pl     -> check_all_lines_matched.py
  - check_errors_whitelisted.pl    -> check_errors_whitelisted.py

All five were verified byte-for-byte identical to their Perl counterparts on synthetic inputs.

These files are used by perf test shell scripts to validate test output; they have no dependency on the perf binary or its Python bindings, so they can be converted independently.

Breno Rodrigues Alves (5):
perf/kselftest: convert prefix.pl to Python perf/tests: convert check_all_patterns_found.pl to Python perf/tests: convert check_no_patterns_found.pl to Python perf/tests: convert check_all_lines_matched.pl to Python perf/tests: convert check_errors_whitelisted.pl to Python

Breno Rodrigues Alves (5):
perf/kselftest: convert prefix.pl to Python perf/tests: convert check_all_patterns_found.pl to Python perf/tests: convert check_no_patterns_found.pl to Python perf/tests: convert check_all_lines_matched.pl to Python perf/tests: convert check_errors_whitelisted.pl to Python

 .../shell/common/check_all_lines_matched.py   | 45 +++++++++++++++
 .../shell/common/check_all_patterns_found.py  | 35 ++++++++++++
 .../shell/common/check_errors_whitelisted.py  | 55 +++++++++++++++++++
 .../shell/common/check_no_patterns_found.py   | 35 ++++++++++++
 tools/testing/selftests/kselftest/prefix.py   | 24 ++++++++
 5 files changed, 194 insertions(+)
 create mode 100755 tools/perf/tests/shell/common/check_all_lines_matched.py
 create mode 100755 tools/perf/tests/shell/common/check_all_patterns_found.py
 create mode 100755 tools/perf/tests/shell/common/check_errors_whitelisted.py
 create mode 100755 tools/perf/tests/shell/common/check_no_patterns_found.py
 create mode 100755 tools/testing/selftests/kselftest/prefix.py
Signature · 1 line
2.43.0
#1 lore raw

RFC PATCH 1/5 perf/kselftest: convert prefix.pl to Python

Faithful re-implementation of tools/testing/selftests/kselftest/ prefix.pl in Python 3 (stdlib only). Same unbuffered stdin-to-stdout processing, same "# " prefix behavior.

Verified byte-for-byte identical to the Perl version.

---
 tools/testing/selftests/kselftest/prefix.py | 24 +++++++++++++++++++++
 1 file changed, 24 insertions(+)
 create mode 100755 tools/testing/selftests/kselftest/prefix.py
tools/testing/selftests/kselftest/prefix.py new file +24 -0
new file mode 100755
index 000000000..2bf16b37d
@@ -0,0 +1,24 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0
+# Prefix all lines with "# ", unbuffered.
+
+import sys
+
+
+def main():
+    needed = True
+    while True:
+        char = sys.stdin.buffer.read(1)
+        if not char:
+            return 0
+        if needed:
+            sys.stdout.buffer.write(b"# ")
+            needed = False
+        sys.stdout.buffer.write(char)
+        sys.stdout.buffer.flush()
+        if char == b"\n":
+            needed = True
+
+
+if __name__ == "__main__":
+    sys.exit(main())
\ No newline at end of file
Signature · 1 line
2.43.0
#2 lore raw

Re: [RFC PATCH 1/5] perf/kselftest: convert prefix.pl to Python

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] selftests: prefix.py is unused and not installed by Makefile or runner.sh - [Low] selftests…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] selftests: prefix.py is unused and not installed by Makefile or runner.sh
- [Low] selftests: missing trailing newline at end of prefix.py
--

commit f99bbafab30726cd18857c0cc9a21eeae2499158
Author: Breno Rodrigues Alves <[email protected]>

perf/kselftest: convert prefix.pl to Python

This commit adds a Python 3 re-implementation of tools/testing/selftests/kselftest/prefix.pl to prefix input lines with "# " in an unbuffered manner.

Quoted 6 lines
tools/testing/selftests/kselftest/prefix.py new file +0 -0
new file mode 100755
index 0000000000000..2bf16b37dee63

tools/testing/selftests/kselftest/prefix.py line 8

Quoted 8 lines
tools/testing/selftests/kselftest/prefix.py new file +8 -0
@@ -0,0 +1,24 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0
+# Prefix all lines with "# ", unbuffered.
+
+import sys
+
+
+def main():

[Severity: Medium]
Should tools/testing/selftests/kselftest/runner.sh and tools/testing/selftests/Makefile also be updated to use and install prefix.py, and remove prefix.pl?

Currently, tap_prefix() in tools/testing/selftests/kselftest/runner.sh still checks for /usr/bin/perl and invokes prefix.pl:

tap_prefix()

{
	if [ ! -x /usr/bin/perl ]; then
		sed -e 's/^/# /'
	else
		"$BASE_DIR"/kselftest/prefix.pl
	fi
}

And the install target in tools/testing/selftests/Makefile still only installs prefix.pl:

	install -m 744 kselftest/prefix.pl $(INSTALL_PATH)/kselftest/

Without updating those callers, prefix.py is never executed or installed.

Quoted 7 lines
tools/testing/selftests/kselftest/prefix.py new file +7 -0
+    needed = True
+    while True:
+        char = sys.stdin.buffer.read(1)
+        if not char:
+            return 0
+        if needed:
+            sys.stdout.buffer.write(b"# ")

tools/testing/selftests/kselftest/prefix.py line 24

Quoted 10 lines
tools/testing/selftests/kselftest/prefix.py new file +9 -0
+            needed = False
+        sys.stdout.buffer.write(char)
+        sys.stdout.buffer.flush()
+        if char == b"\n":
+            needed = True
+
+
+if __name__ == "__main__":
+    sys.exit(main())
\ No newline at end of file

[Severity: Low]
Could a trailing newline be added at the end of
tools/testing/selftests/kselftest/prefix.py?

[]

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#3 lore raw

RFC PATCH 2/5 perf/tests: convert check_all_patterns_found.pl to Python

In reply to Breno Rodrigues Alves

Faithful re-implementation of tools/perf/tests/shell/common/ check_all_patterns_found.pl in Python 3 (stdlib only). Same regex matching, same TESTLOG_VERBOSITY/TESTLOG_ERR_MSG_MAX_LINES environment handling, same exit codes.

Verified byte-for-byte identical to the Perl version.

---
 .../shell/common/check_all_patterns_found.py  | 35 +++++++++++++++++++
 1 file changed, 35 insertions(+)
 create mode 100755 tools/perf/tests/shell/common/check_all_patterns_found.py
tools/perf/tests/shell/common/check_all_patterns_found.py new file +35 -0
new file mode 100755
index 000000000..3eb907af3
@@ -0,0 +1,35 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0
+
+import os
+import re
+import sys
+
+
+def main(argv):
+    quiet = True
+    try:
+        if int(os.environ.get("TESTLOG_VERBOSITY", "0")) >= 2:
+            quiet = False
+    except ValueError:
+        pass
+
+    found = set()
+    for line in sys.stdin:
+        line = line.rstrip("\n")
+        for r in argv:
+            if re.search(r, line):
+                found.add(r)
+
+    passed = True
+    for r in argv:
+        if r not in found:
+            if not quiet:
+                print(f'Regexp not found: "{r}"')
+            passed = False
+
+    return 0 if passed else 1
+
+
+if __name__ == "__main__":
+    sys.exit(main(sys.argv[1:]))
\ No newline at end of file
Signature · 1 line
2.43.0
#4 lore raw

Re: [RFC PATCH 2/5] perf/tests: convert check_all_patterns_found.pl to Python

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] perf/tests: check_all_patterns_found.py added without updating callers --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] perf/tests: check_all_patterns_found.py added without updating callers --

commit 069a51b64d65753bb41f5e2b0b33fd3d38c715f2
Author: Breno Rodrigues Alves <[email protected]>

perf/tests: convert check_all_patterns_found.pl to Python

This commit adds a Python 3 implementation of check_all_patterns_found.pl under tools/perf/tests/shell/common/check_all_patterns_found.py.

Quoted 32 lines

perf/tests: convert check_all_patterns_found.pl to Python

Faithful re-implementation of tools/perf/tests/shell/common/ check_all_patterns_found.pl in Python 3 (stdlib only). Same regex matching, same TESTLOG_VERBOSITY/TESTLOG_ERR_MSG_MAX_LINES environment handling, same exit codes.

Verified byte-for-byte identical to the Perl version.

tools/perf/tests/shell/common/check_all_patterns_found.py new file +15 -0
new file mode 100755
index 0000000000000..3eb907af3d6b2
@@ -0,0 +1,35 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0
+
+import os
+import re
+import sys
+
+
+def main(argv):
+    quiet = True
+    try:
+        if int(os.environ.get("TESTLOG_VERBOSITY", "0")) >= 2:
+            quiet = False
+    except ValueError:
+        pass

[ ... ]

tools/perf/tests/shell/common/check_all_patterns_found.py line 35

Quoted 3 lines
tools/perf/tests/shell/common/check_all_patterns_found.py new file +2 -0
+if __name__ == "__main__":
+    sys.exit(main(sys.argv[1:]))
\ No newline at end of file

[Severity: Medium]
Should the callers, tools/perf/Makefile.perf, and the old Perl script be updated as part of this conversion?

This commit adds tools/perf/tests/shell/common/check_all_patterns_found.py, but tools/perf/tests/shell/common/check_all_patterns_found.pl is not removed, and none of the subsequent patches in this series update the callers or build system.

All 37 call sites across the 6 test scripts in tools/perf/tests/shell/base_probe/ (test_adding_blacklisted.sh, test_adding_kernel.sh, test_basic.sh, test_invalid_options.sh) and tools/perf/tests/shell/base_report/ (setup.sh, test_basic.sh) still invoke the Perl script directly:

    "$DIR_PATH/../common/check_all_patterns_found.pl" \

Also, the install-tests target in tools/perf/Makefile.perf only installs .sh and .pl files from tests/shell/common/:

    $(INSTALL) tests/shell/common/*.sh '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/common'; \
    $(INSTALL) tests/shell/common/*.pl '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/common'; \

Without updating the test scripts and Makefile.perf, the new Python script is unused and is not installed by make install-tests.

Additionally, the commit message mentions TESTLOG_ERR_MSG_MAX_LINES handling, which is not present in either check_all_patterns_found.pl or check_all_patterns_found.py, and the new file is missing a trailing newline.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#5 lore raw

RFC PATCH 3/5 perf/tests: convert check_no_patterns_found.pl to Python

In reply to Breno Rodrigues Alves

Faithful re-implementation of tools/perf/tests/shell/common/ check_no_patterns_found.pl in Python 3 (stdlib only). Same regex matching, same environment handling, same exit codes.

Verified byte-for-byte identical to the Perl version.

---
 .../shell/common/check_no_patterns_found.py   | 35 +++++++++++++++++++
 1 file changed, 35 insertions(+)
 create mode 100755 tools/perf/tests/shell/common/check_no_patterns_found.py
tools/perf/tests/shell/common/check_no_patterns_found.py new file +35 -0
new file mode 100755
index 000000000..0e5d931b9
@@ -0,0 +1,35 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0
+
+import os
+import re
+import sys
+
+
+def main(argv):
+    quiet = True
+    try:
+        if int(os.environ.get("TESTLOG_VERBOSITY", "0")) >= 2:
+            quiet = False
+    except ValueError:
+        pass
+
+    found = set()
+    for line in sys.stdin:
+        line = line.rstrip("\n")
+        for r in argv:
+            if re.search(r, line):
+                found.add(r)
+
+    passed = True
+    for r in argv:
+        if r in found:
+            if not quiet:
+                print(f'Regexp found: "{r}"')
+            passed = False
+
+    return 0 if passed else 1
+
+
+if __name__ == "__main__":
+    sys.exit(main(sys.argv[1:]))
\ No newline at end of file
Signature · 1 line
2.43.0
#6 lore raw

Re: [RFC PATCH 3/5] perf/tests: convert check_no_patterns_found.pl to Python

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] perf tests: check_no_patterns_found.py is unused and not installed - [Low] perf tests: missing…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] perf tests: check_no_patterns_found.py is unused and not installed
- [Low] perf tests: missing EOF newline in check_no_patterns_found.py breaks PYLINT=1 --

commit d6b15fdc56a31f78fa7365cb6aafd5034b2a393d
Author: Breno Rodrigues Alves <[email protected]>

perf/tests: convert check_no_patterns_found.pl to Python

This commit adds a Python 3 implementation of check_no_patterns_found.pl under tools/perf/tests/shell/common/check_no_patterns_found.py.

tools/perf/tests/shell/common/check_no_patterns_found.py line 2

Quoted 8 lines
tools/perf/tests/shell/common/check_no_patterns_found.py new file +2 -0
new file mode 100755
index 0000000000000..0e5d931b903a2
@@ -0,0 +1,35 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0

[Severity: Medium]
Should this commit also update the existing callers, remove tools/perf/tests/shell/common/check_no_patterns_found.pl, and install the new script?

All existing call sites in the test suite still invoke check_no_patterns_found.pl:

tools/perf/tests/shell/base_probe/test_adding_kernel.sh:

	"$DIR_PATH/../common/check_no_patterns_found.pl" \
		"$RE_SEGFAULT" < $LOGS_DIR/adding_kernel_nonexisting.err

tools/perf/tests/shell/base_probe/test_basic.sh:

	"$DIR_PATH/../common/check_no_patterns_found.pl" \
		"No manual entry for" < $LOGS_DIR/basic_helpmsg.err

tools/perf/tests/shell/base_report/test_basic.sh:

	"$DIR_PATH/../common/check_no_patterns_found.pl" \
		"No manual entry for" < $LOGS_DIR/basic_helpmsg.err

In addition, the install-tests target in tools/perf/Makefile.perf only installs *.sh and *.pl files from tests/shell/common:

tools/perf/Makefile.perf:

		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/common'; \
		$(INSTALL) tests/shell/common/*.sh '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/common'; \
		$(INSTALL) tests/shell/common/*.pl '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/common'; \

Without updating the callers and Makefile.perf, check_no_patterns_found.py is never executed or installed.

[ ... ]

tools/perf/tests/shell/common/check_no_patterns_found.py line 35

Quoted 3 lines
tools/perf/tests/shell/common/check_no_patterns_found.py new file +2 -0
+if __name__ == "__main__":
+    sys.exit(main(sys.argv[1:]))
\ No newline at end of file

[Severity: Low]
Does the missing trailing newline at the end of check_no_patterns_found.py cause a build failure when building perf with PYLINT=1?

In tools/perf/tests/Build, PY_TESTS collects all *.py files under tests/shell to run pylint:

tools/perf/tests/Build:
ifdef PYLINT
PY_TESTS := $(shell find tests/shell -type f -name '*.py') PYLINT_TEST_LOGS := $(PY_TESTS:tests/shell/%=shell/%.pylint_log)

Because main() in tools/perf/tests/shell/common/check_no_patterns_found.py ends without a final newline (and without pylint directives or docstrings), pylint reports C0304 (missing-final-newline) and fails the build when PYLINT=1 is enabled.

Can a trailing newline be added at the end of the file?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
#7 lore raw

RFC PATCH 4/5 perf/tests: convert check_all_lines_matched.pl to Python

In reply to Breno Rodrigues Alves

Faithful re-implementation of tools/perf/tests/shell/common/ check_all_lines_matched.pl in Python 3 (stdlib only). Same regex matching, same environment handling, same exit codes.

Verified byte-for-byte identical to the Perl version.

---
 .../shell/common/check_all_lines_matched.py   | 45 +++++++++++++++++++
 1 file changed, 45 insertions(+)
 create mode 100755 tools/perf/tests/shell/common/check_all_lines_matched.py
tools/perf/tests/shell/common/check_all_lines_matched.py new file +45 -0
new file mode 100755
index 000000000..352a56d8b
@@ -0,0 +1,45 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0
+
+import os
+import re
+import sys
+
+
+def main(argv):
+    max_printed = 20
+    if "TESTLOG_ERR_MSG_MAX_LINES" in os.environ:
+        try:
+            max_printed = int(os.environ["TESTLOG_ERR_MSG_MAX_LINES"])
+        except ValueError:
+            pass
+
+    quiet = True
+    try:
+        if int(os.environ.get("TESTLOG_VERBOSITY", "0")) >= 2:
+            quiet = False
+    except ValueError:
+        pass
+
+    passed = True
+    lines_printed = 0
+
+    for line in sys.stdin:
+        line = line.rstrip("\n")
+        matched = False
+        for r in argv:
+            if re.search(r, line):
+                matched = True
+                break
+        if not matched:
+            show = lines_printed < max_printed
+            lines_printed += 1
+            if show and not quiet:
+                print(f'Line did not match any pattern: "{line}"')
+            passed = False
+
+    return 0 if passed else 1
+
+
+if __name__ == "__main__":
+    sys.exit(main(sys.argv[1:]))
\ No newline at end of file
Signature · 1 line
2.43.0
#8 lore raw

Re: [RFC PATCH 4/5] perf/tests: convert check_all_lines_matched.pl to Python

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] perf tests: check_all_lines_matched.py is never wired up or installed --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] perf tests: check_all_lines_matched.py is never wired up or installed --

commit d9f6b313408b62305572a2fb532ed1583f0179f7
Author: Breno Rodrigues Alves <[email protected]>

perf/tests: convert check_all_lines_matched.pl to Python

This commit adds a Python 3 implementation of tools/perf/tests/shell/common/check_all_lines_matched.pl.

Quoted 6 lines
tools/perf/tests/shell/common/check_all_lines_matched.py new file +0 -0
new file mode 100755
index 0000000000000..352a56d8b9809

tools/perf/tests/shell/common/check_all_lines_matched.py line 9

Quoted 9 lines
tools/perf/tests/shell/common/check_all_lines_matched.py new file +9 -0
@@ -0,0 +1,45 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0
+
+import os
+import re
+import sys
+
+
+def main(argv):

[Severity: Medium]
Should this commit also update the existing callers and installation rules, and remove tools/perf/tests/shell/common/check_all_lines_matched.pl?

Currently, check_all_lines_matched.py is added, but the shell test scripts still invoke check_all_lines_matched.pl (which is also not updated in the subsequent commit f4ac81889a75 in this series):

tools/perf/tests/shell/base_probe/test_adding_blacklisted.sh:

		"$DIR_PATH/../common/check_all_lines_matched.pl" \
			"$REGEX_SKIP_MESSAGE" "$REGEX_NOT_FOUND_MESSAGE" \

tools/perf/tests/shell/base_probe/test_adding_kernel.sh:

"$DIR_PATH/../common/check_all_lines_matched.pl" \
	"$RE_LINE_EMPTY" "List of pre-defined events" \

tools/perf/tests/shell/base_report/test_basic.sh:

grep -P -v '^#' $LOGS_DIR/basic_pid.log | grep -P '\s+[\d\.]+%' | \
	"$DIR_PATH/../common/check_all_lines_matched.pl" "systemd|init"

In addition, the install-tests target in tools/perf/Makefile.perf only installs *.sh and *.pl files from tests/shell/common, omitting *.py:

tools/perf/Makefile.perf:

		$(INSTALL) tests/shell/common/*.sh '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/common'; \
		$(INSTALL) tests/shell/common/*.pl '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/common'; \

[ ... ]

Quoted 3 lines
tools/perf/tests/shell/common/check_all_lines_matched.py new file +2 -0
+if __name__ == "__main__":
+    sys.exit(main(sys.argv[1:]))
\ No newline at end of file
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
#9 lore raw

RFC PATCH 5/5 perf/tests: convert check_errors_whitelisted.pl to Python

In reply to Breno Rodrigues Alves

Faithful re-implementation of tools/perf/tests/shell/common/ check_errors_whitelisted.pl in Python 3 (stdlib only). Same whitelist file handling, same regex matching, same exit codes.

Verified byte-for-byte identical to the Perl version.

---
 .../shell/common/check_errors_whitelisted.py  | 55 +++++++++++++++++++
 1 file changed, 55 insertions(+)
 create mode 100755 tools/perf/tests/shell/common/check_errors_whitelisted.py
tools/perf/tests/shell/common/check_errors_whitelisted.py new file +55 -0
new file mode 100755
index 000000000..352eb1a9d
@@ -0,0 +1,55 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0
+
+import os
+import re
+import sys
+
+
+def main(argv):
+    if argv:
+        whitelist = argv[0]
+        try:
+            with open(whitelist) as f:
+                regexps = [ln.rstrip("\n") for ln in f]
+        except OSError:
+            sys.exit(f"Checker error: Unable to open the whitelist file: {whitelist}")
+    else:
+        regexps = []
+
+    max_printed = 20
+    if "TESTLOG_ERR_MSG_MAX_LINES" in os.environ:
+        try:
+            max_printed = int(os.environ["TESTLOG_ERR_MSG_MAX_LINES"])
+        except ValueError:
+            pass
+
+    quiet = True
+    try:
+        if int(os.environ.get("TESTLOG_VERBOSITY", "0")) >= 2:
+            quiet = False
+    except ValueError:
+        pass
+
+    passed = True
+    lines_printed = 0
+
+    for line in sys.stdin:
+        line = line.rstrip("\n")
+        matched = False
+        for r in regexps:
+            if re.search(r, line):
+                matched = True
+                break
+        if not matched:
+            show = lines_printed < max_printed
+            lines_printed += 1
+            if show and not quiet:
+                print(f'Line did not match any pattern: "{line}"')
+            passed = False
+
+    return 0 if passed else 1
+
+
+if __name__ == "__main__":
+    sys.exit(main(sys.argv[1:]))
\ No newline at end of file
Signature · 1 line
2.43.0
#10 lore raw

Re: [RFC PATCH 5/5] perf/tests: convert check_errors_whitelisted.pl to Python

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] perf/tests: check_errors_whitelisted.py is unused and not installed - [Low] perf/tests: missing…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] perf/tests: check_errors_whitelisted.py is unused and not installed
- [Low] perf/tests: missing trailing newline in check_errors_whitelisted.py --

commit f4ac81889a756943e8a2c98f2bfeb3dd3b8cd1a1
Author: Breno Rodrigues Alves <[email protected]>

perf/tests: convert check_errors_whitelisted.pl to Python

This patch adds a Python 3 implementation of the error whitelist checker script in tools/perf/tests/shell/common/check_errors_whitelisted.py.

Quoted 6 lines
tools/perf/tests/shell/common/check_errors_whitelisted.py new file +0 -0
new file mode 100755
index 0000000000000..352eb1a9dd06b

tools/perf/tests/shell/common/check_errors_whitelisted.py line 9

Quoted 9 lines
tools/perf/tests/shell/common/check_errors_whitelisted.py new file +9 -0
@@ -0,0 +1,55 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0
+
+import os
+import re
+import sys
+
+
+def main(argv):

[Severity: Medium]
Is this conversion complete? While this patch adds check_errors_whitelisted.py, none of the callers in tools/perf/tests/shell/base_report/test_basic.sh are updated to use it, and instead still invoke check_errors_whitelisted.pl:

"$DIR_PATH/../common/check_errors_whitelisted.pl" \
"$DIR_PATH/stderr-whitelist.txt" < $LOGS_DIR/basic_basic.err

In addition, the install-tests target in tools/perf/Makefile.perf only installs *.sh and *.pl files from tests/shell/common/ and omits *.py files:

    $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/common'; \
    $(INSTALL) tests/shell/common/*.sh '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/common'; \
    $(INSTALL) tests/shell/common/*.pl '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/common'; \

Should test_basic.sh and Makefile.perf be updated to use and install check_errors_whitelisted.py, and should the old tools/perf/tests/shell/common/check_errors_whitelisted.pl file be removed?

[ ... ]

tools/perf/tests/shell/common/check_errors_whitelisted.py line 55

Quoted 6 lines
tools/perf/tests/shell/common/check_errors_whitelisted.py new file +5 -0
+    return 0 if passed else 1
+
+
+if __name__ == "__main__":
+    sys.exit(main(sys.argv[1:]))
\ No newline at end of file

[Severity: Low]
Could a trailing newline be added to the end of tools/perf/tests/shell/common/check_errors_whitelisted.py?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
#11 lore raw

v2 cover perf: convert Perl test helpers to Python

In reply to Breno Rodrigues Alves

v2 changes since v1:
- Restructure as 2 commits (prefix.py alone; the 4 check_*.py together, since their callers are heavily intermingled)
- Update runner.sh and kselftest/Makefile to invoke/install prefix.py
- Update Makefile.perf to install *.py (not just *.sh/*.pl)
- Update all call sites in base_probe/ and base_report/
- Remove the 5 original .pl files
- Add trailing newlines to all 5 files (pylint C0304)
- Fix the check_all_patterns_found commit message:
TESTLOG_ERR_MSG_MAX_LINES is only handled by check_all_lines_matched

This series converts five Perl test helpers in tools/ to Python 3, continuing the Perl-to-Python conversion effort for the kernel's auxiliary scripts.

Each conversion is a faithful 1:1 port: same CLI, same output, same exit codes. All use only the Python standard library.

The five scripts are:

  - prefix.pl                      -> prefix.py
  - check_all_patterns_found.pl    -> check_all_patterns_found.py
  - check_no_patterns_found.pl     -> check_no_patterns_found.py
  - check_all_lines_matched.pl     -> check_all_lines_matched.py
  - check_errors_whitelisted.pl    -> check_errors_whitelisted.py

All five were verified byte-for-byte identical to their Perl counterparts on synthetic inputs.

Breno Rodrigues Alves (2):
perf/kselftest: convert prefix.pl to Python perf/tests: convert check_*.pl helpers to Python

Breno Rodrigues Alves (2):
perf/kselftest: convert prefix.pl to Python perf/tests: convert check_*.pl helpers to Python

 tools/perf/Makefile.perf                      |  2 +-
 .../base_probe/test_adding_blacklisted.sh     |  6 +-
 .../shell/base_probe/test_adding_kernel.sh    | 44 +++++++--------
 .../perf/tests/shell/base_probe/test_basic.sh | 12 ++--
 .../shell/base_probe/test_invalid_options.sh  |  4 +-
 tools/perf/tests/shell/base_report/setup.sh   |  4 +-
 .../tests/shell/base_report/test_basic.sh     | 54 +++++++++---------
 .../shell/common/check_all_lines_matched.pl   | 39 -------------
 .../shell/common/check_all_lines_matched.py   | 45 +++++++++++++++
 .../shell/common/check_all_patterns_found.pl  | 34 ------------
 .../shell/common/check_all_patterns_found.py  | 35 ++++++++++++
 .../shell/common/check_errors_whitelisted.pl  | 51 -----------------
 .../shell/common/check_errors_whitelisted.py  | 55 +++++++++++++++++++
 .../shell/common/check_no_patterns_found.pl   | 34 ------------
 .../shell/common/check_no_patterns_found.py   | 35 ++++++++++++
 tools/testing/selftests/Makefile              |  2 +-
 tools/testing/selftests/kselftest/prefix.pl   | 24 --------
 tools/testing/selftests/kselftest/prefix.py   | 24 ++++++++
 tools/testing/selftests/kselftest/runner.sh   |  7 +--
 19 files changed, 260 insertions(+), 251 deletions(-)
 delete mode 100755 tools/perf/tests/shell/common/check_all_lines_matched.pl
 create mode 100755 tools/perf/tests/shell/common/check_all_lines_matched.py
 delete mode 100755 tools/perf/tests/shell/common/check_all_patterns_found.pl
 create mode 100755 tools/perf/tests/shell/common/check_all_patterns_found.py
 delete mode 100755 tools/perf/tests/shell/common/check_errors_whitelisted.pl
 create mode 100755 tools/perf/tests/shell/common/check_errors_whitelisted.py
 delete mode 100755 tools/perf/tests/shell/common/check_no_patterns_found.pl
 create mode 100755 tools/perf/tests/shell/common/check_no_patterns_found.py
 delete mode 100755 tools/testing/selftests/kselftest/prefix.pl
 create mode 100755 tools/testing/selftests/kselftest/prefix.py
Signature · 1 line
2.43.0
#12 lore raw

RFC PATCH v2 1/2 perf/kselftest: convert prefix.pl to Python

Faithful re-implementation of tools/testing/selftests/kselftest/ prefix.pl in Python 3 (stdlib only). Same unbuffered stdin-to-stdout processing, same "# " prefix behavior.

Update runner.sh to invoke prefix.py instead of prefix.pl, update the install target to install prefix.py, and remove the old prefix.pl.

Verified byte-for-byte identical to the Perl version.

---
 tools/testing/selftests/Makefile            |  2 +-
 tools/testing/selftests/kselftest/prefix.pl | 24 ---------------------
 tools/testing/selftests/kselftest/prefix.py | 24 +++++++++++++++++++++
 tools/testing/selftests/kselftest/runner.sh |  7 ++----
 4 files changed, 27 insertions(+), 30 deletions(-)
 delete mode 100755 tools/testing/selftests/kselftest/prefix.pl
 create mode 100755 tools/testing/selftests/kselftest/prefix.py
tools/testing/selftests/Makefile +1 -1
index bc4fdb6f5..85ed9af96 100644
@@ -285,7 +285,7 @@ ifdef INSTALL_PATH
 	mkdir -p $(INSTALL_PATH)/kselftest
 	install -m 744 kselftest/module.sh $(INSTALL_PATH)/kselftest/
 	install -m 744 kselftest/runner.sh $(INSTALL_PATH)/kselftest/
-	install -m 744 kselftest/prefix.pl $(INSTALL_PATH)/kselftest/
+	install -m 744 kselftest/prefix.py $(INSTALL_PATH)/kselftest/
 	install -m 744 kselftest/ktap_helpers.sh $(INSTALL_PATH)/kselftest/
 	install -m 744 kselftest/ksft.py $(INSTALL_PATH)/kselftest/
 	install -m 744 run_kselftest.sh $(INSTALL_PATH)/
tools/testing/selftests/kselftest/prefix.pl deleted +0 -24
deleted file mode 100755
index 12a7f4ca2..000000000
@@ -1,24 +0,0 @@
-#!/usr/bin/env perl
-# SPDX-License-Identifier: GPL-2.0
-# Prefix all lines with "# ", unbuffered. Command being piped in may need
-# to have unbuffering forced with "stdbuf -i0 -o0 -e0 $cmd".
-use strict;
-use IO::Handle;
-
-binmode STDIN;
-binmode STDOUT;
-
-STDOUT->autoflush(1);
-
-my $needed = 1;
-while (1) {
-	my $char;
-	my $bytes = sysread(STDIN, $char, 1);
-	exit 0 if ($bytes == 0);
-	if ($needed) {
-		print "# ";
-		$needed = 0;
-	}
-	print $char;
-	$needed = 1 if ($char eq "\n");
-}
tools/testing/selftests/kselftest/prefix.py new file +24 -0
new file mode 100755
index 000000000..67c4fd0b6
@@ -0,0 +1,24 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0
+# Prefix all lines with "# ", unbuffered.
+
+import sys
+
+
+def main():
+    needed = True
+    while True:
+        char = sys.stdin.buffer.read(1)
+        if not char:
+            return 0
+        if needed:
+            sys.stdout.buffer.write(b"# ")
+            needed = False
+        sys.stdout.buffer.write(char)
+        sys.stdout.buffer.flush()
+        if char == b"\n":
+            needed = True
+
+
+if __name__ == "__main__":
+    sys.exit(main())
tools/testing/selftests/kselftest/runner.sh +2 -5
index 311811dc5..b61ea6c2d 100644
@@ -29,15 +29,12 @@ TR_CMD=$(command -v tr)
 # with sed instead of unbuffered output.
 tap_prefix()
 {
-	if [ ! -x /usr/bin/perl ]; then
+	if [ ! -x /usr/bin/python3 ]; then
 		sed -e 's/^/# /'
 	else
-		"$BASE_DIR"/kselftest/prefix.pl
+		"$BASE_DIR"/kselftest/prefix.py
 	fi
 }
-
-tap_timeout()
-{
 	# Make sure tests will time out if utility is available.
 	if [ -x /usr/bin/timeout ] ; then
 		/usr/bin/timeout --foreground "$kselftest_timeout" \
Signature · 1 line
2.43.0
#13 lore raw

Re: [RFC PATCH v2 1/2] perf/kselftest: convert prefix.pl to Python

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] selftests: accidental deletion of tap_timeout() header in runner.sh --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] selftests: accidental deletion of tap_timeout() header in runner.sh --

commit 3307ba1d73611e0bd22bd59e12d190de9b29a3a2
Author: Breno Rodrigues Alves <[email protected]>

perf/kselftest: convert prefix.pl to Python

This commit replaces tools/testing/selftests/kselftest/prefix.pl with a Python 3 implementation (prefix.py) and updates runner.sh and the selftests Makefile to use and install the new script.

Quoted 12 lines
tools/testing/selftests/kselftest/runner.sh +1 -1
index 311811dc55a07..b61ea6c2de89d 100644
@@ -29,15 +29,12 @@ TR_CMD=$(command -v tr)
 # with sed instead of unbuffered output.
 tap_prefix()
 {
-	if [ ! -x /usr/bin/perl ]; then
+	if [ ! -x /usr/bin/python3 ]; then
 		sed -e 's/^/# /'
 	else

tools/testing/selftests/kselftest/runner.sh TR_CMD=$(command -v tr) · line 40

Quoted 10 lines
tools/testing/selftests/kselftest/runner.sh +1 -4
-		"$BASE_DIR"/kselftest/prefix.pl
+		"$BASE_DIR"/kselftest/prefix.py
 	fi
 }
-
-tap_timeout()
-{
 	# Make sure tests will time out if utility is available.
 	if [ -x /usr/bin/timeout ] ; then
 		/usr/bin/timeout --foreground "$kselftest_timeout" \

[Severity: Medium]
Was the removal of the tap_timeout() function header and opening brace here unintentional?

Without it, the body of tap_timeout() is left at top-level scope followed by an unmatched closing brace:

tools/testing/selftests/kselftest/runner.sh:
# Make sure tests will time out if utility is available. if [ -x /usr/bin/timeout ] ; then
/usr/bin/timeout --foreground "$kselftest_timeout" \
/usr/bin/timeout "$kselftest_timeout" $1
else
$1
fi
}

When tools/testing/selftests/kselftest/runner.sh is sourced (for example via RUN_TESTS in tools/testing/selftests/lib.mk or tools/testing/selftests/run_kselftest.sh), the shell executes the timeout logic immediately and fails with a syntax error on the closing brace.

In addition, tap_timeout() is no longer defined when run_one() invokes it:

tools/testing/selftests/kselftest/runner.sh:run_one() {
	...
		(((( tap_timeout "$cmd" 2>&1; echo $? >&3) |
			tap_prefix >&4) 3>&1) |
			(read xs; exit $xs)) 4>>"$logfile"
	...
}

—
AI reviewed your patch. Please follow the URL below to transplant the feedback or give kudos to the AI:
https://github.com/kernel-patches/vmtest/wiki

계가

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#14 lore raw

RFC PATCH v2 2/2 perf/tests: convert check_*.pl helpers to Python

In reply to Breno Rodrigues Alves

Faithful re-implementations of the four Perl test helpers in tools/perf/tests/shell/common/:
- check_all_patterns_found.pl
- check_no_patterns_found.pl
- check_all_lines_matched.pl
- check_errors_whitelisted.pl

Same CLI, same output, same exit codes. All use only the Python standard library. TESTLOG_VERBOSITY and TESTLOG_ERR_MSG_MAX_LINES environment handling is preserved.

Update all 37 call sites across base_probe/ and base_report/ to invoke the .py versions. Update Makefile.perf's install-tests target to install *.py files (in addition to *.sh) from tests/shell/common/. Remove the four old .pl files.

All four were verified byte-for-byte identical to their Perl counterparts on synthetic inputs.

---
 tools/perf/Makefile.perf                      |  2 +-
 .../base_probe/test_adding_blacklisted.sh     |  6 +-
 .../shell/base_probe/test_adding_kernel.sh    | 44 +++++++--------
 .../perf/tests/shell/base_probe/test_basic.sh | 12 ++--
 .../shell/base_probe/test_invalid_options.sh  |  4 +-
 tools/perf/tests/shell/base_report/setup.sh   |  4 +-
 .../tests/shell/base_report/test_basic.sh     | 54 +++++++++---------
 .../shell/common/check_all_lines_matched.pl   | 39 -------------
 .../shell/common/check_all_lines_matched.py   | 45 +++++++++++++++
 .../shell/common/check_all_patterns_found.pl  | 34 ------------
 .../shell/common/check_all_patterns_found.py  | 35 ++++++++++++
 .../shell/common/check_errors_whitelisted.pl  | 51 -----------------
 .../shell/common/check_errors_whitelisted.py  | 55 +++++++++++++++++++
 .../shell/common/check_no_patterns_found.pl   | 34 ------------
 .../shell/common/check_no_patterns_found.py   | 35 ++++++++++++
 15 files changed, 233 insertions(+), 221 deletions(-)
 delete mode 100755 tools/perf/tests/shell/common/check_all_lines_matched.pl
 create mode 100755 tools/perf/tests/shell/common/check_all_lines_matched.py
 delete mode 100755 tools/perf/tests/shell/common/check_all_patterns_found.pl
 create mode 100755 tools/perf/tests/shell/common/check_all_patterns_found.py
 delete mode 100755 tools/perf/tests/shell/common/check_errors_whitelisted.pl
 create mode 100755 tools/perf/tests/shell/common/check_errors_whitelisted.py
 delete mode 100755 tools/perf/tests/shell/common/check_no_patterns_found.pl
 create mode 100755 tools/perf/tests/shell/common/check_no_patterns_found.py
tools/perf/Makefile.perf +1 -1
index 29cfd44c4..c9120eab6 100644
@@ -885,7 +885,7 @@ install-tests: all install-gtk
 		$(INSTALL) tests/shell/lib/*.py -m 644 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/lib'; \
 		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/common'; \
 		$(INSTALL) tests/shell/common/*.sh '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/common'; \
-		$(INSTALL) tests/shell/common/*.pl '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/common'; \
+		$(INSTALL) tests/shell/common/*.py '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/common'; \
 		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/base_probe'; \
 		$(INSTALL) tests/shell/base_probe/*.sh '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/base_probe'; \
 		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/base_report'; \
tools/perf/tests/shell/base_probe/test_adding_blacklisted.sh +3 -3
index f74aab5c5..867545a62 100755
@@ -54,7 +54,7 @@ for BLACKFUNC in $BLACKFUNC_LIST; do
 	PERF_EXIT_CODE=$?
 
 	# check for bad DWARF polluting the result
-	"$DIR_PATH/../common/check_all_patterns_found.pl" \
+	"$DIR_PATH/../common/check_all_patterns_found.py" \
 		"$REGEX_MISSING_DECL_LINE" >/dev/null < $LOGS_DIR/adding_blacklisted.err
 
 	if [ $? -eq 0 ]; then
@@ -75,7 +75,7 @@ for BLACKFUNC in $BLACKFUNC_LIST; do
 			fi
 		fi
 	else
-		"$DIR_PATH/../common/check_all_lines_matched.pl" \
+		"$DIR_PATH/../common/check_all_lines_matched.py" \
 			"$REGEX_SKIP_MESSAGE" "$REGEX_NOT_FOUND_MESSAGE" \
 			"$REGEX_ERROR_MESSAGE" "$REGEX_SCOPE_FAIL" \
 			"$REGEX_INVALID_ARGUMENT" "$REGEX_SYMBOL_FAIL" \
@@ -100,7 +100,7 @@ fi
 $CMD_PERF list probe:\* > $LOGS_DIR/adding_blacklisted_list.log
 PERF_EXIT_CODE=$?
 
-"$DIR_PATH/../common/check_all_lines_matched.pl" \
+"$DIR_PATH/../common/check_all_lines_matched.py" \
 	"$RE_LINE_EMPTY" "List of pre-defined events" "Metric Groups:" \
 	< $LOGS_DIR/adding_blacklisted_list.log
 CHECK_EXIT_CODE=$?
tools/perf/tests/shell/base_probe/test_adding_kernel.sh +22 -22

162 lines not on this page · raw message

tools/perf/tests/shell/base_probe/test_basic.sh +6 -6
index 162838ddc..a702be734 100755
@@ -31,24 +31,24 @@ if [ "$PARAM_GENERAL_HELP_TEXT_CHECK" = "y" ]; then
 	$CMD_PERF probe --help > $LOGS_DIR/basic_helpmsg.log 2> $LOGS_DIR/basic_helpmsg.err
 	PERF_EXIT_CODE=$?
 
-	"$DIR_PATH/../common/check_all_patterns_found.pl" \
+	"$DIR_PATH/../common/check_all_patterns_found.py" \
 		"PERF-PROBE" "NAME" "SYNOPSIS" "DESCRIPTION" "OPTIONS" \
 		"PROBE\s+SYNTAX" "PROBE\s+ARGUMENT" "LINE\s+SYNTAX" \
 		< $LOGS_DIR/basic_helpmsg.log
 	CHECK_EXIT_CODE=$?
-	"$DIR_PATH/../common/check_all_patterns_found.pl" \
+	"$DIR_PATH/../common/check_all_patterns_found.py" \
 		"LAZY\s+MATCHING" "FILTER\s+PATTERN" "EXAMPLES" "SEE\s+ALSO" \
 		< $LOGS_DIR/basic_helpmsg.log
 	(( CHECK_EXIT_CODE += $? ))
-	"$DIR_PATH/../common/check_all_patterns_found.pl" \
+	"$DIR_PATH/../common/check_all_patterns_found.py" \
 		"vmlinux" "module=" "source=" "verbose" "quiet" "add=" "del=" \
 		"list.*EVENT" "line=" "vars=" "externs" < $LOGS_DIR/basic_helpmsg.log
 	(( CHECK_EXIT_CODE += $? ))
-	"$DIR_PATH/../common/check_all_patterns_found.pl" \
+	"$DIR_PATH/../common/check_all_patterns_found.py" \
 		"no-inlines" "funcs.*FILTER" "filter=FILTER" "force" "dry-run" \
 		"max-probes" "exec=" "demangle-kernel" < $LOGS_DIR/basic_helpmsg.log
 	(( CHECK_EXIT_CODE += $? ))
-	"$DIR_PATH/../common/check_no_patterns_found.pl" \
+	"$DIR_PATH/../common/check_no_patterns_found.py" \
 		"No manual entry for" < $LOGS_DIR/basic_helpmsg.err
 	(( CHECK_EXIT_CODE += $? ))
 
@@ -64,7 +64,7 @@ fi
 # without any args perf-probe should print usage
 $CMD_PERF probe 2> $LOGS_DIR/basic_usage.log > /dev/null
 
-"$DIR_PATH/../common/check_all_patterns_found.pl" \
+"$DIR_PATH/../common/check_all_patterns_found.py" \
 	"[Uu]sage" "perf probe" "verbose" "quiet" "add" "del" "force" \
 	"line" "vars" "externs" "range" < $LOGS_DIR/basic_usage.log
 CHECK_EXIT_CODE=$?
tools/perf/tests/shell/base_probe/test_invalid_options.sh +2 -2
index 44a3ae014..d88bb7ec5 100755
@@ -34,7 +34,7 @@ for opt in '-a' '-d' '-L' '-V'; do
 	! $CMD_PERF probe $opt 2> $LOGS_DIR/invalid_options_missing_argument$opt.err
 	PERF_EXIT_CODE=$?
 
-	"$DIR_PATH/../common/check_all_patterns_found.pl" \
+	"$DIR_PATH/../common/check_all_patterns_found.py" \
 		"Error: switch .* requires a value" \
 		< $LOGS_DIR/invalid_options_missing_argument$opt.err
 	CHECK_EXIT_CODE=$?
@@ -69,7 +69,7 @@ for opt in '-a xxx -d xxx' '-a xxx -L foo' '-a xxx -V foo' '-a xxx -l' '-a xxx -
 	! $CMD_PERF probe $opt > /dev/null 2> $LOGS_DIR/aux.log
 	PERF_EXIT_CODE=$?
 
-	"$DIR_PATH/../common/check_all_patterns_found.pl" \
+	"$DIR_PATH/../common/check_all_patterns_found.py" \
 		"Error: switch .+ cannot be used with switch .+" < $LOGS_DIR/aux.log
 	CHECK_EXIT_CODE=$?
 
tools/perf/tests/shell/base_report/setup.sh +2 -2
index bb49b0fab..10fe4b553 100755
@@ -26,7 +26,7 @@ SW_EVENT="cpu-clock"
 $CMD_PERF record -asdg -e $SW_EVENT -o $CURRENT_TEST_DIR/perf.data -- $CMD_LONGER_SLEEP 2> $LOGS_DIR/setup.log
 PERF_EXIT_CODE=$?
 
-"$DIR_PATH/../common/check_all_patterns_found.pl" \
+"$DIR_PATH/../common/check_all_patterns_found.py" \
 	"$RE_LINE_RECORD1" "$RE_LINE_RECORD2" < $LOGS_DIR/setup.log
 CHECK_EXIT_CODE=$?
 
@@ -41,7 +41,7 @@ echo ==================
 cat $LOGS_DIR/setup-latency.log
 echo ==================
 
-"$DIR_PATH/../common/check_all_patterns_found.pl" \
+"$DIR_PATH/../common/check_all_patterns_found.py" \
 	"$RE_LINE_RECORD1" "$RE_LINE_RECORD2" < $LOGS_DIR/setup-latency.log
 CHECK_EXIT_CODE=$?
 
tools/perf/tests/shell/base_report/test_basic.sh +27 -27

167 lines not on this page · raw message

tools/perf/tests/shell/common/check_all_lines_matched.pl deleted +0 -39
deleted file mode 100755
index fded48959..000000000
@@ -1,39 +0,0 @@
-#!/usr/bin/perl
-# SPDX-License-Identifier: GPL-2.0
-
-@regexps = @ARGV;
-
-$max_printed_lines = 20;
-$max_printed_lines = $ENV{TESTLOG_ERR_MSG_MAX_LINES} if (defined $ENV{TESTLOG_ERR_MSG_MAX_LINES});
-
-$quiet = 1;
-$quiet = 0 if (defined $ENV{TESTLOG_VERBOSITY} && $ENV{TESTLOG_VERBOSITY} ge 2);
-
-$passed = 1;
-$lines_printed = 0;
-
-while (<STDIN>)
-{
-	s/\n//;
-
-	$line_matched = 0;
-	for $r (@regexps)
-	{
-		if (/$r/)
-		{
-			$line_matched = 1;
-			last;
-		}
-	}
-
-	unless ($line_matched)
-	{
-		if ($lines_printed++ < $max_printed_lines)
-		{
-			print "Line did not match any pattern: \"$_\"\n" unless $quiet;
-		}
-		$passed = 0;
-	}
-}
-
-exit ($passed == 0);
tools/perf/tests/shell/common/check_all_lines_matched.py new file +45 -0

45 lines not on this page · raw message

tools/perf/tests/shell/common/check_all_patterns_found.pl deleted +0 -34
deleted file mode 100755
index 11bdf1d34..000000000
@@ -1,34 +0,0 @@
-#!/usr/bin/perl
-# SPDX-License-Identifier: GPL-2.0
-
-@regexps = @ARGV;
-
-$quiet = 1;
-$quiet = 0 if (defined $ENV{TESTLOG_VERBOSITY} && $ENV{TESTLOG_VERBOSITY} ge 2);
-
-%found = ();
-$passed = 1;
-
-while (<STDIN>)
-{
-	s/\n//;
-
-	for $r (@regexps)
-	{
-		if (/$r/)
-		{
-			$found{$r} = 1;	# FIXME: maybe add counters -- how many times was the regexp matched
-		}
-	}
-}
-
-for $r (@regexps)
-{
-	unless (exists $found{$r})
-	{
-		print "Regexp not found: \"$r\"\n" unless $quiet;
-		$passed = 0;
-	}
-}
-
-exit ($passed == 0);
tools/perf/tests/shell/common/check_all_patterns_found.py new file +35 -0
new file mode 100755
index 000000000..f94487f25
@@ -0,0 +1,35 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0
+
+import os
+import re
+import sys
+
+
+def main(argv):
+    quiet = True
+    try:
+        if int(os.environ.get("TESTLOG_VERBOSITY", "0")) >= 2:
+            quiet = False
+    except ValueError:
+        pass
+
+    found = set()
+    for line in sys.stdin:
+        line = line.rstrip("\n")
+        for r in argv:
+            if re.search(r, line):
+                found.add(r)
+
+    passed = True
+    for r in argv:
+        if r not in found:
+            if not quiet:
+                print(f'Regexp not found: "{r}"')
+            passed = False
+
+    return 0 if passed else 1
+
+
+if __name__ == "__main__":
+    sys.exit(main(sys.argv[1:]))
tools/perf/tests/shell/common/check_errors_whitelisted.pl deleted +0 -51

51 lines not on this page · raw message

tools/perf/tests/shell/common/check_errors_whitelisted.py new file +55 -0

55 lines not on this page · raw message

tools/perf/tests/shell/common/check_no_patterns_found.pl deleted +0 -34
deleted file mode 100755
index 770999e87..000000000
@@ -1,34 +0,0 @@
-#!/usr/bin/perl
-# SPDX-License-Identifier: GPL-2.0
-
-@regexps = @ARGV;
-
-$quiet = 1;
-$quiet = 0 if (defined $ENV{TESTLOG_VERBOSITY} && $ENV{TESTLOG_VERBOSITY} ge 2);
-
-%found = ();
-$passed = 1;
-
-while (<STDIN>)
-{
-	s/\n//;
-
-	for $r (@regexps)
-	{
-		if (/$r/)
-		{
-			$found{$r} = 1;
-		}
-	}
-}
-
-for $r (@regexps)
-{
-	if (exists $found{$r})
-	{
-		print "Regexp found: \"$r\"\n" unless $quiet;
-		$passed = 0;
-	}
-}
-
-exit ($passed == 0);
tools/perf/tests/shell/common/check_no_patterns_found.py new file +35 -0
new file mode 100755
index 000000000..0df0a4961
@@ -0,0 +1,35 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0
+
+import os
+import re
+import sys
+
+
+def main(argv):
+    quiet = True
+    try:
+        if int(os.environ.get("TESTLOG_VERBOSITY", "0")) >= 2:
+            quiet = False
+    except ValueError:
+        pass
+
+    found = set()
+    for line in sys.stdin:
+        line = line.rstrip("\n")
+        for r in argv:
+            if re.search(r, line):
+                found.add(r)
+
+    passed = True
+    for r in argv:
+        if r in found:
+            if not quiet:
+                print(f'Regexp found: "{r}"')
+            passed = False
+
+    return 0 if passed else 1
+
+
+if __name__ == "__main__":
+    sys.exit(main(sys.argv[1:]))
Signature · 1 line
2.43.0
#15 lore raw

Re: [RFC PATCH v2 2/2] perf/tests: convert check_*.pl helpers to Python

Sashiko has reviewed this patch and found no issues.
Quoted 16 lines

Faithful re-implementations of the four Perl test helpers in tools/perf/tests/shell/common/:
- check_all_patterns_found.pl
- check_no_patterns_found.pl
- check_all_lines_matched.pl
- check_errors_whitelisted.pl

Same CLI, same output, same exit codes. All use only the Python standard library. TESTLOG_VERBOSITY and TESTLOG_ERR_MSG_MAX_LINES environment handling is preserved.

Update all 37 call sites across base_probe/ and base_report/ to invoke the .py versions. Update Makefile.perf's install-tests target to install *.py files (in addition to *.sh) from tests/shell/common/. Remove the four old .pl files.

Quoted 4 lines

All four were verified byte-for-byte identical to their Perl counterparts on synthetic inputs.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#16 lore raw

v3 cover perf: convert Perl test helpers to Python

In reply to Breno Rodrigues Alves

v3 changes since v2:
- Fix accidental deletion of the tap_timeout() function header and opening brace in runner.sh (Sashiko finding). The v2 runner.sh left the body of tap_timeout() at top level with an orphan closing brace, which would fail with a shell syntax error when sourced by run_kselftest.sh.

v2 changes since v1:
- Restructure as 2 commits (prefix.py alone; the 4 check_*.py together, since their callers are heavily intermingled)
- Update runner.sh and kselftest/Makefile to invoke/install prefix.py
- Update Makefile.perf to install *.py (not just *.sh/*.pl)
- Update all call sites in base_probe/ and base_report/
- Remove the 5 original .pl files
- Add trailing newlines to all 5 files (pylint C0304)
- Fix the check_all_patterns_found commit message:
TESTLOG_ERR_MSG_MAX_LINES is only handled by check_all_lines_matched

This series converts five Perl test helpers in tools/ to Python 3, continuing the Perl-to-Python conversion effort for the kernel's auxiliary scripts.

Each conversion is a faithful 1:1 port: same CLI, same output, same exit codes. All use only the Python standard library.

The five scripts are:

  - prefix.pl                      -> prefix.py
  - check_all_patterns_found.pl    -> check_all_patterns_found.py
  - check_no_patterns_found.pl     -> check_no_patterns_found.py
  - check_all_lines_matched.pl     -> check_all_lines_matched.py
  - check_errors_whitelisted.pl    -> check_errors_whitelisted.py

All five were verified byte-for-byte identical to their Perl counterparts on synthetic inputs.

Breno Rodrigues Alves (2):
perf/kselftest: convert prefix.pl to Python perf/tests: convert check_*.pl helpers to Python

Breno Rodrigues Alves (2):
perf/kselftest: convert prefix.pl to Python perf/tests: convert check_*.pl helpers to Python

 tools/perf/Makefile.perf                      |  2 +-
 .../base_probe/test_adding_blacklisted.sh     |  6 +-
 .../shell/base_probe/test_adding_kernel.sh    | 44 +++++++--------
 .../perf/tests/shell/base_probe/test_basic.sh | 12 ++--
 .../shell/base_probe/test_invalid_options.sh  |  4 +-
 tools/perf/tests/shell/base_report/setup.sh   |  4 +-
 .../tests/shell/base_report/test_basic.sh     | 54 +++++++++---------
 .../shell/common/check_all_lines_matched.pl   | 39 -------------
 .../shell/common/check_all_lines_matched.py   | 45 +++++++++++++++
 .../shell/common/check_all_patterns_found.pl  | 34 ------------
 .../shell/common/check_all_patterns_found.py  | 35 ++++++++++++
 .../shell/common/check_errors_whitelisted.pl  | 51 -----------------
 .../shell/common/check_errors_whitelisted.py  | 55 +++++++++++++++++++
 .../shell/common/check_no_patterns_found.pl   | 34 ------------
 .../shell/common/check_no_patterns_found.py   | 35 ++++++++++++
 tools/testing/selftests/Makefile              |  2 +-
 tools/testing/selftests/kselftest/prefix.pl   | 24 --------
 tools/testing/selftests/kselftest/prefix.py   | 24 ++++++++
 tools/testing/selftests/kselftest/runner.sh   |  4 +-
 19 files changed, 260 insertions(+), 248 deletions(-)
 delete mode 100755 tools/perf/tests/shell/common/check_all_lines_matched.pl
 create mode 100755 tools/perf/tests/shell/common/check_all_lines_matched.py
 delete mode 100755 tools/perf/tests/shell/common/check_all_patterns_found.pl
 create mode 100755 tools/perf/tests/shell/common/check_all_patterns_found.py
 delete mode 100755 tools/perf/tests/shell/common/check_errors_whitelisted.pl
 create mode 100755 tools/perf/tests/shell/common/check_errors_whitelisted.py
 delete mode 100755 tools/perf/tests/shell/common/check_no_patterns_found.pl
 create mode 100755 tools/perf/tests/shell/common/check_no_patterns_found.py
 delete mode 100755 tools/testing/selftests/kselftest/prefix.pl
 create mode 100755 tools/testing/selftests/kselftest/prefix.py
Signature · 1 line
2.43.0
#17 lore raw

RFC PATCH v3 1/2 perf/kselftest: convert prefix.pl to Python

Faithful re-implementation of tools/testing/selftests/kselftest/ prefix.pl in Python 3 (stdlib only). Same unbuffered stdin-to-stdout processing, same "# " prefix behavior.

Update runner.sh to invoke prefix.py instead of prefix.pl, update the install target to install prefix.py, and remove the old prefix.pl.

Verified byte-for-byte identical to the Perl version.

---
 tools/testing/selftests/Makefile            |  2 +-
 tools/testing/selftests/kselftest/prefix.pl | 24 ---------------------
 tools/testing/selftests/kselftest/prefix.py | 24 +++++++++++++++++++++
 tools/testing/selftests/kselftest/runner.sh |  4 ++--
 4 files changed, 27 insertions(+), 27 deletions(-)
 delete mode 100755 tools/testing/selftests/kselftest/prefix.pl
 create mode 100755 tools/testing/selftests/kselftest/prefix.py
tools/testing/selftests/Makefile +1 -1
index bc4fdb6f5..85ed9af96 100644
@@ -285,7 +285,7 @@ ifdef INSTALL_PATH
 	mkdir -p $(INSTALL_PATH)/kselftest
 	install -m 744 kselftest/module.sh $(INSTALL_PATH)/kselftest/
 	install -m 744 kselftest/runner.sh $(INSTALL_PATH)/kselftest/
-	install -m 744 kselftest/prefix.pl $(INSTALL_PATH)/kselftest/
+	install -m 744 kselftest/prefix.py $(INSTALL_PATH)/kselftest/
 	install -m 744 kselftest/ktap_helpers.sh $(INSTALL_PATH)/kselftest/
 	install -m 744 kselftest/ksft.py $(INSTALL_PATH)/kselftest/
 	install -m 744 run_kselftest.sh $(INSTALL_PATH)/
tools/testing/selftests/kselftest/prefix.pl deleted +0 -24
deleted file mode 100755
index 12a7f4ca2..000000000
@@ -1,24 +0,0 @@
-#!/usr/bin/env perl
-# SPDX-License-Identifier: GPL-2.0
-# Prefix all lines with "# ", unbuffered. Command being piped in may need
-# to have unbuffering forced with "stdbuf -i0 -o0 -e0 $cmd".
-use strict;
-use IO::Handle;
-
-binmode STDIN;
-binmode STDOUT;
-
-STDOUT->autoflush(1);
-
-my $needed = 1;
-while (1) {
-	my $char;
-	my $bytes = sysread(STDIN, $char, 1);
-	exit 0 if ($bytes == 0);
-	if ($needed) {
-		print "# ";
-		$needed = 0;
-	}
-	print $char;
-	$needed = 1 if ($char eq "\n");
-}
tools/testing/selftests/kselftest/prefix.py new file +24 -0
new file mode 100755
index 000000000..67c4fd0b6
@@ -0,0 +1,24 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0
+# Prefix all lines with "# ", unbuffered.
+
+import sys
+
+
+def main():
+    needed = True
+    while True:
+        char = sys.stdin.buffer.read(1)
+        if not char:
+            return 0
+        if needed:
+            sys.stdout.buffer.write(b"# ")
+            needed = False
+        sys.stdout.buffer.write(char)
+        sys.stdout.buffer.flush()
+        if char == b"\n":
+            needed = True
+
+
+if __name__ == "__main__":
+    sys.exit(main())
tools/testing/selftests/kselftest/runner.sh +2 -2
index 311811dc5..1944c74f1 100644
@@ -29,10 +29,10 @@ TR_CMD=$(command -v tr)
 # with sed instead of unbuffered output.
 tap_prefix()
 {
-	if [ ! -x /usr/bin/perl ]; then
+	if [ ! -x /usr/bin/python3 ]; then
 		sed -e 's/^/# /'
 	else
-		"$BASE_DIR"/kselftest/prefix.pl
+		"$BASE_DIR"/kselftest/prefix.py
 	fi
 }
 
Signature · 1 line
2.43.0
#18 lore raw

Re: [RFC PATCH v3 1/2] perf/kselftest: convert prefix.pl to Python

Sashiko has reviewed this patch and found no issues.
Quoted 11 lines

Faithful re-implementation of tools/testing/selftests/kselftest/ prefix.pl in Python 3 (stdlib only). Same unbuffered stdin-to-stdout processing, same "# " prefix behavior.

Update runner.sh to invoke prefix.py instead of prefix.pl, update the install target to install prefix.py, and remove the old prefix.pl.

Verified byte-for-byte identical to the Perl version.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#19 lore raw

RFC PATCH v3 2/2 perf/tests: convert check_*.pl helpers to Python

In reply to Breno Rodrigues Alves

Faithful re-implementations of the four Perl test helpers in tools/perf/tests/shell/common/:
- check_all_patterns_found.pl
- check_no_patterns_found.pl
- check_all_lines_matched.pl
- check_errors_whitelisted.pl

Same CLI, same output, same exit codes. All use only the Python standard library. TESTLOG_VERBOSITY and TESTLOG_ERR_MSG_MAX_LINES environment handling is preserved.

Update all 37 call sites across base_probe/ and base_report/ to invoke the .py versions. Update Makefile.perf's install-tests target to install *.py files (in addition to *.sh) from tests/shell/common/. Remove the four old .pl files.

All four were verified byte-for-byte identical to their Perl counterparts on synthetic inputs.

---
 tools/perf/Makefile.perf                      |  2 +-
 .../base_probe/test_adding_blacklisted.sh     |  6 +-
 .../shell/base_probe/test_adding_kernel.sh    | 44 +++++++--------
 .../perf/tests/shell/base_probe/test_basic.sh | 12 ++--
 .../shell/base_probe/test_invalid_options.sh  |  4 +-
 tools/perf/tests/shell/base_report/setup.sh   |  4 +-
 .../tests/shell/base_report/test_basic.sh     | 54 +++++++++---------
 .../shell/common/check_all_lines_matched.pl   | 39 -------------
 .../shell/common/check_all_lines_matched.py   | 45 +++++++++++++++
 .../shell/common/check_all_patterns_found.pl  | 34 ------------
 .../shell/common/check_all_patterns_found.py  | 35 ++++++++++++
 .../shell/common/check_errors_whitelisted.pl  | 51 -----------------
 .../shell/common/check_errors_whitelisted.py  | 55 +++++++++++++++++++
 .../shell/common/check_no_patterns_found.pl   | 34 ------------
 .../shell/common/check_no_patterns_found.py   | 35 ++++++++++++
 15 files changed, 233 insertions(+), 221 deletions(-)
 delete mode 100755 tools/perf/tests/shell/common/check_all_lines_matched.pl
 create mode 100755 tools/perf/tests/shell/common/check_all_lines_matched.py
 delete mode 100755 tools/perf/tests/shell/common/check_all_patterns_found.pl
 create mode 100755 tools/perf/tests/shell/common/check_all_patterns_found.py
 delete mode 100755 tools/perf/tests/shell/common/check_errors_whitelisted.pl
 create mode 100755 tools/perf/tests/shell/common/check_errors_whitelisted.py
 delete mode 100755 tools/perf/tests/shell/common/check_no_patterns_found.pl
 create mode 100755 tools/perf/tests/shell/common/check_no_patterns_found.py
tools/perf/Makefile.perf +1 -1
index 29cfd44c4..c9120eab6 100644
@@ -885,7 +885,7 @@ install-tests: all install-gtk
 		$(INSTALL) tests/shell/lib/*.py -m 644 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/lib'; \
 		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/common'; \
 		$(INSTALL) tests/shell/common/*.sh '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/common'; \
-		$(INSTALL) tests/shell/common/*.pl '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/common'; \
+		$(INSTALL) tests/shell/common/*.py '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/common'; \
 		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/base_probe'; \
 		$(INSTALL) tests/shell/base_probe/*.sh '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/base_probe'; \
 		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/base_report'; \
tools/perf/tests/shell/base_probe/test_adding_blacklisted.sh +3 -3
index f74aab5c5..867545a62 100755
@@ -54,7 +54,7 @@ for BLACKFUNC in $BLACKFUNC_LIST; do
 	PERF_EXIT_CODE=$?
 
 	# check for bad DWARF polluting the result
-	"$DIR_PATH/../common/check_all_patterns_found.pl" \
+	"$DIR_PATH/../common/check_all_patterns_found.py" \
 		"$REGEX_MISSING_DECL_LINE" >/dev/null < $LOGS_DIR/adding_blacklisted.err
 
 	if [ $? -eq 0 ]; then
@@ -75,7 +75,7 @@ for BLACKFUNC in $BLACKFUNC_LIST; do
 			fi
 		fi
 	else
-		"$DIR_PATH/../common/check_all_lines_matched.pl" \
+		"$DIR_PATH/../common/check_all_lines_matched.py" \
 			"$REGEX_SKIP_MESSAGE" "$REGEX_NOT_FOUND_MESSAGE" \
 			"$REGEX_ERROR_MESSAGE" "$REGEX_SCOPE_FAIL" \
 			"$REGEX_INVALID_ARGUMENT" "$REGEX_SYMBOL_FAIL" \
@@ -100,7 +100,7 @@ fi
 $CMD_PERF list probe:\* > $LOGS_DIR/adding_blacklisted_list.log
 PERF_EXIT_CODE=$?
 
-"$DIR_PATH/../common/check_all_lines_matched.pl" \
+"$DIR_PATH/../common/check_all_lines_matched.py" \
 	"$RE_LINE_EMPTY" "List of pre-defined events" "Metric Groups:" \
 	< $LOGS_DIR/adding_blacklisted_list.log
 CHECK_EXIT_CODE=$?
tools/perf/tests/shell/base_probe/test_adding_kernel.sh +22 -22

162 lines not on this page · raw message

tools/perf/tests/shell/base_probe/test_basic.sh +6 -6
index 162838ddc..a702be734 100755
@@ -31,24 +31,24 @@ if [ "$PARAM_GENERAL_HELP_TEXT_CHECK" = "y" ]; then
 	$CMD_PERF probe --help > $LOGS_DIR/basic_helpmsg.log 2> $LOGS_DIR/basic_helpmsg.err
 	PERF_EXIT_CODE=$?
 
-	"$DIR_PATH/../common/check_all_patterns_found.pl" \
+	"$DIR_PATH/../common/check_all_patterns_found.py" \
 		"PERF-PROBE" "NAME" "SYNOPSIS" "DESCRIPTION" "OPTIONS" \
 		"PROBE\s+SYNTAX" "PROBE\s+ARGUMENT" "LINE\s+SYNTAX" \
 		< $LOGS_DIR/basic_helpmsg.log
 	CHECK_EXIT_CODE=$?
-	"$DIR_PATH/../common/check_all_patterns_found.pl" \
+	"$DIR_PATH/../common/check_all_patterns_found.py" \
 		"LAZY\s+MATCHING" "FILTER\s+PATTERN" "EXAMPLES" "SEE\s+ALSO" \
 		< $LOGS_DIR/basic_helpmsg.log
 	(( CHECK_EXIT_CODE += $? ))
-	"$DIR_PATH/../common/check_all_patterns_found.pl" \
+	"$DIR_PATH/../common/check_all_patterns_found.py" \
 		"vmlinux" "module=" "source=" "verbose" "quiet" "add=" "del=" \
 		"list.*EVENT" "line=" "vars=" "externs" < $LOGS_DIR/basic_helpmsg.log
 	(( CHECK_EXIT_CODE += $? ))
-	"$DIR_PATH/../common/check_all_patterns_found.pl" \
+	"$DIR_PATH/../common/check_all_patterns_found.py" \
 		"no-inlines" "funcs.*FILTER" "filter=FILTER" "force" "dry-run" \
 		"max-probes" "exec=" "demangle-kernel" < $LOGS_DIR/basic_helpmsg.log
 	(( CHECK_EXIT_CODE += $? ))
-	"$DIR_PATH/../common/check_no_patterns_found.pl" \
+	"$DIR_PATH/../common/check_no_patterns_found.py" \
 		"No manual entry for" < $LOGS_DIR/basic_helpmsg.err
 	(( CHECK_EXIT_CODE += $? ))
 
@@ -64,7 +64,7 @@ fi
 # without any args perf-probe should print usage
 $CMD_PERF probe 2> $LOGS_DIR/basic_usage.log > /dev/null
 
-"$DIR_PATH/../common/check_all_patterns_found.pl" \
+"$DIR_PATH/../common/check_all_patterns_found.py" \
 	"[Uu]sage" "perf probe" "verbose" "quiet" "add" "del" "force" \
 	"line" "vars" "externs" "range" < $LOGS_DIR/basic_usage.log
 CHECK_EXIT_CODE=$?
tools/perf/tests/shell/base_probe/test_invalid_options.sh +2 -2
index 44a3ae014..d88bb7ec5 100755
@@ -34,7 +34,7 @@ for opt in '-a' '-d' '-L' '-V'; do
 	! $CMD_PERF probe $opt 2> $LOGS_DIR/invalid_options_missing_argument$opt.err
 	PERF_EXIT_CODE=$?
 
-	"$DIR_PATH/../common/check_all_patterns_found.pl" \
+	"$DIR_PATH/../common/check_all_patterns_found.py" \
 		"Error: switch .* requires a value" \
 		< $LOGS_DIR/invalid_options_missing_argument$opt.err
 	CHECK_EXIT_CODE=$?
@@ -69,7 +69,7 @@ for opt in '-a xxx -d xxx' '-a xxx -L foo' '-a xxx -V foo' '-a xxx -l' '-a xxx -
 	! $CMD_PERF probe $opt > /dev/null 2> $LOGS_DIR/aux.log
 	PERF_EXIT_CODE=$?
 
-	"$DIR_PATH/../common/check_all_patterns_found.pl" \
+	"$DIR_PATH/../common/check_all_patterns_found.py" \
 		"Error: switch .+ cannot be used with switch .+" < $LOGS_DIR/aux.log
 	CHECK_EXIT_CODE=$?
 
tools/perf/tests/shell/base_report/setup.sh +2 -2
index bb49b0fab..10fe4b553 100755
@@ -26,7 +26,7 @@ SW_EVENT="cpu-clock"
 $CMD_PERF record -asdg -e $SW_EVENT -o $CURRENT_TEST_DIR/perf.data -- $CMD_LONGER_SLEEP 2> $LOGS_DIR/setup.log
 PERF_EXIT_CODE=$?
 
-"$DIR_PATH/../common/check_all_patterns_found.pl" \
+"$DIR_PATH/../common/check_all_patterns_found.py" \
 	"$RE_LINE_RECORD1" "$RE_LINE_RECORD2" < $LOGS_DIR/setup.log
 CHECK_EXIT_CODE=$?
 
@@ -41,7 +41,7 @@ echo ==================
 cat $LOGS_DIR/setup-latency.log
 echo ==================
 
-"$DIR_PATH/../common/check_all_patterns_found.pl" \
+"$DIR_PATH/../common/check_all_patterns_found.py" \
 	"$RE_LINE_RECORD1" "$RE_LINE_RECORD2" < $LOGS_DIR/setup-latency.log
 CHECK_EXIT_CODE=$?
 
tools/perf/tests/shell/base_report/test_basic.sh +27 -27

167 lines not on this page · raw message

tools/perf/tests/shell/common/check_all_lines_matched.pl deleted +0 -39
deleted file mode 100755
index fded48959..000000000
@@ -1,39 +0,0 @@
-#!/usr/bin/perl
-# SPDX-License-Identifier: GPL-2.0
-
-@regexps = @ARGV;
-
-$max_printed_lines = 20;
-$max_printed_lines = $ENV{TESTLOG_ERR_MSG_MAX_LINES} if (defined $ENV{TESTLOG_ERR_MSG_MAX_LINES});
-
-$quiet = 1;
-$quiet = 0 if (defined $ENV{TESTLOG_VERBOSITY} && $ENV{TESTLOG_VERBOSITY} ge 2);
-
-$passed = 1;
-$lines_printed = 0;
-
-while (<STDIN>)
-{
-	s/\n//;
-
-	$line_matched = 0;
-	for $r (@regexps)
-	{
-		if (/$r/)
-		{
-			$line_matched = 1;
-			last;
-		}
-	}
-
-	unless ($line_matched)
-	{
-		if ($lines_printed++ < $max_printed_lines)
-		{
-			print "Line did not match any pattern: \"$_\"\n" unless $quiet;
-		}
-		$passed = 0;
-	}
-}
-
-exit ($passed == 0);
tools/perf/tests/shell/common/check_all_lines_matched.py new file +45 -0

45 lines not on this page · raw message

tools/perf/tests/shell/common/check_all_patterns_found.pl deleted +0 -34
deleted file mode 100755
index 11bdf1d34..000000000
@@ -1,34 +0,0 @@
-#!/usr/bin/perl
-# SPDX-License-Identifier: GPL-2.0
-
-@regexps = @ARGV;
-
-$quiet = 1;
-$quiet = 0 if (defined $ENV{TESTLOG_VERBOSITY} && $ENV{TESTLOG_VERBOSITY} ge 2);
-
-%found = ();
-$passed = 1;
-
-while (<STDIN>)
-{
-	s/\n//;
-
-	for $r (@regexps)
-	{
-		if (/$r/)
-		{
-			$found{$r} = 1;	# FIXME: maybe add counters -- how many times was the regexp matched
-		}
-	}
-}
-
-for $r (@regexps)
-{
-	unless (exists $found{$r})
-	{
-		print "Regexp not found: \"$r\"\n" unless $quiet;
-		$passed = 0;
-	}
-}
-
-exit ($passed == 0);
tools/perf/tests/shell/common/check_all_patterns_found.py new file +35 -0
new file mode 100755
index 000000000..f94487f25
@@ -0,0 +1,35 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0
+
+import os
+import re
+import sys
+
+
+def main(argv):
+    quiet = True
+    try:
+        if int(os.environ.get("TESTLOG_VERBOSITY", "0")) >= 2:
+            quiet = False
+    except ValueError:
+        pass
+
+    found = set()
+    for line in sys.stdin:
+        line = line.rstrip("\n")
+        for r in argv:
+            if re.search(r, line):
+                found.add(r)
+
+    passed = True
+    for r in argv:
+        if r not in found:
+            if not quiet:
+                print(f'Regexp not found: "{r}"')
+            passed = False
+
+    return 0 if passed else 1
+
+
+if __name__ == "__main__":
+    sys.exit(main(sys.argv[1:]))
tools/perf/tests/shell/common/check_errors_whitelisted.pl deleted +0 -51

51 lines not on this page · raw message

tools/perf/tests/shell/common/check_errors_whitelisted.py new file +55 -0

55 lines not on this page · raw message

tools/perf/tests/shell/common/check_no_patterns_found.pl deleted +0 -34
deleted file mode 100755
index 770999e87..000000000
@@ -1,34 +0,0 @@
-#!/usr/bin/perl
-# SPDX-License-Identifier: GPL-2.0
-
-@regexps = @ARGV;
-
-$quiet = 1;
-$quiet = 0 if (defined $ENV{TESTLOG_VERBOSITY} && $ENV{TESTLOG_VERBOSITY} ge 2);
-
-%found = ();
-$passed = 1;
-
-while (<STDIN>)
-{
-	s/\n//;
-
-	for $r (@regexps)
-	{
-		if (/$r/)
-		{
-			$found{$r} = 1;
-		}
-	}
-}
-
-for $r (@regexps)
-{
-	if (exists $found{$r})
-	{
-		print "Regexp found: \"$r\"\n" unless $quiet;
-		$passed = 0;
-	}
-}
-
-exit ($passed == 0);
tools/perf/tests/shell/common/check_no_patterns_found.py new file +35 -0
new file mode 100755
index 000000000..0df0a4961
@@ -0,0 +1,35 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0
+
+import os
+import re
+import sys
+
+
+def main(argv):
+    quiet = True
+    try:
+        if int(os.environ.get("TESTLOG_VERBOSITY", "0")) >= 2:
+            quiet = False
+    except ValueError:
+        pass
+
+    found = set()
+    for line in sys.stdin:
+        line = line.rstrip("\n")
+        for r in argv:
+            if re.search(r, line):
+                found.add(r)
+
+    passed = True
+    for r in argv:
+        if r in found:
+            if not quiet:
+                print(f'Regexp found: "{r}"')
+            passed = False
+
+    return 0 if passed else 1
+
+
+if __name__ == "__main__":
+    sys.exit(main(sys.argv[1:]))
Signature · 1 line
2.43.0
#20 lore raw

Re: [RFC PATCH v3 2/2] perf/tests: convert check_*.pl helpers to Python

Sashiko has reviewed this patch and found no issues.
Quoted 16 lines

Faithful re-implementations of the four Perl test helpers in tools/perf/tests/shell/common/:
- check_all_patterns_found.pl
- check_no_patterns_found.pl
- check_all_lines_matched.pl
- check_errors_whitelisted.pl

Same CLI, same output, same exit codes. All use only the Python standard library. TESTLOG_VERBOSITY and TESTLOG_ERR_MSG_MAX_LINES environment handling is preserved.

Update all 37 call sites across base_probe/ and base_report/ to invoke the .py versions. Update Makefile.perf's install-tests target to install *.py files (in addition to *.sh) from tests/shell/common/. Remove the four old .pl files.

Quoted 4 lines

All four were verified byte-for-byte identical to their Perl counterparts on synthetic inputs.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
reviewer
#21 lore raw

Re: [RFC PATCH v3 2/2] perf/tests: convert check_*.pl helpers to Python

In reply to Breno Rodrigues Alves
Quoted 17 lines · Breno Rodrigues Alves

Faithful re-implementations of the four Perl test helpers in tools/perf/tests/shell/common/:
- check_all_patterns_found.pl
- check_no_patterns_found.pl
- check_all_lines_matched.pl
- check_errors_whitelisted.pl

Same CLI, same output, same exit codes. All use only the Python standard library. TESTLOG_VERBOSITY and TESTLOG_ERR_MSG_MAX_LINES environment handling is preserved.

Update all 37 call sites across base_probe/ and base_report/ to invoke the .py versions. Update Makefile.perf's install-tests target to install *.py files (in addition to *.sh) from tests/shell/common/. Remove the four old .pl files.

Quoted 4 lines

All four were verified byte-for-byte identical to their Perl counterparts on synthetic inputs.

Hi,

The build in perf-tools-next is now running mypy and pylint (when available) on all python scripts:
https://web.git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tree/tools/perf/tests/Build?h=perf-tools-next#n100
We disable some options:
https://web.git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tree/tools/perf/Makefile.perf?h=perf-tools-next#n317
Applying this patch breaks the build for me because of this and 1 pylint issue. I see:

```
$ make -k -C tools/perf O=/tmp/perf12 DEBUG=1 all
make: Entering directory '.../tools/perf'
  BUILD:   Doing 'make -j28' parallel build

Auto-detecting system features:
...                                   libdw: [ on  ]
...                                   glibc: [ on  ]
...                                  libelf: [ on  ]
...                                 libnuma: [ on  ]
...                  numa_num_possible_cpus: [ on  ]
...                           python-module: [ on  ]
...                             libcapstone: [ on  ]
...                               llvm-perf: [ on  ]
...                                    zlib: [ on  ]
...                                    lzma: [ on  ]
...                                     bpf: [ on  ]
...                                  libaio: [ on  ]
...                                 libzstd: [ on  ]
...                              libopenssl: [ on  ]
...                                    rust: [ on  ]

  INSTALL libsubcmd_headers
  INSTALL libperf_headers
  TEST    /tmp/perf12/tests/shell/common/check_errors_whitelisted.py.pylint_log
  INSTALL libsymbol_headers
  INSTALL libapi_headers
  INSTALL libbpf_headers
************* Module check_errors_whitelisted
tests/shell/common/check_errors_whitelisted.py:13:17: W1514: Using
open without explicitly specifying an encoding (unspecified-encoding)

------------------------------------------------------------------
Your code has been rated at 9.76/10 (previous run: 9.76/10, +0.00)

make[3]: *** [tests/Build:124:
/tmp/perf12/tests/shell/common/check_errors_whitelisted.py.pylint_log]
Error 1
make[3]: Target 'pylint' not remade because of errors.
make[2]: *** [Makefile.perf:690: pylint-tests] Error 2
make[2]: Target 'all' not remade because of errors.
make[1]: *** [Makefile.perf:343: sub-make] Error 2
make[1]: Target 'all' not remade because of errors.
make: *** [Makefile:82: all] Error 2
```

I like the change although the perf tool and kselftests may get merged through different trees. It may be better to separate the patches.

Thanks,
Ian

#22 lore raw

v4 cover perf/kselftest: convert Perl test helpers to Python

In reply to Breno Rodrigues Alves

This is v4 of the series converting the Perl test helpers to Python.

Changes since v3:
- Fixed pylint W1514 in check_errors_whitelisted.py by passing an explicit encoding to open():
open(path, encoding="utf-8", errors="surrogateescape")
"surrogateescape" preserves the byte-for-byte behavior of the Perl original, which reads raw bytes.

- Also fixed two issues found while testing the series locally:
* open() failures on the whitelist now exit with the underlying errno (matching Perl's die), e.g. ENOENT -> rc 2, instead of always rc 1.
* stdin/stdout are reconfigured with surrogateescape so that non-UTF-8 bytes in the log (e.g. oops/KASAN output) do not raise UnicodeDecodeError/UnicodeEncodeError, preserving the byte-for-byte behavior of the Perl originals.

- The series is split by tree, addressing Ian's suggestion:
* Patch 1 (kselftest:) touches only tools/testing/selftests/ and can go through the kselftest tree.
* Patch 2 (perf/tests:) touches only tools/perf/ and can go through the perf tree.

- Note on pylint-tests: it fails on tools/perf/tests/shell/lib/ perf_json_output_lint.py with:
W4904: Using deprecated class FileType of module argparse
This is pre-existing in perf-tools-next and reproduces on the base commit without this series. The four files touched by this series pass pylint 10/10 with the flags used by Makefile.perf.

Breno Rodrigues Alves (2):
kselftest: convert prefix.pl to Python perf/tests: convert check_*.pl helpers to Python

 tools/perf/Makefile.perf                      |  2 +-
 .../base_probe/test_adding_blacklisted.sh     |  6 +-
 .../shell/base_probe/test_adding_kernel.sh    | 44 +++++++-------
 .../perf/tests/shell/base_probe/test_basic.sh | 12 ++--
 .../shell/base_probe/test_invalid_options.sh  |  4 +-
 tools/perf/tests/shell/base_report/setup.sh   |  4 +-
 .../tests/shell/base_report/test_basic.sh     | 54 ++++++++---------
 .../shell/common/check_all_lines_matched.pl   | 39 -------------
 .../shell/common/check_all_lines_matched.py   | 47 +++++++++++++++
 .../shell/common/check_all_patterns_found.pl  | 34 -----------
 .../shell/common/check_all_patterns_found.py  | 37 ++++++++++++
 .../shell/common/check_errors_whitelisted.pl  | 51 ----------------
 .../shell/common/check_errors_whitelisted.py  | 58 +++++++++++++++++++
 .../shell/common/check_no_patterns_found.pl   | 34 -----------
 .../shell/common/check_no_patterns_found.py   | 37 ++++++++++++
 tools/testing/selftests/Makefile              |  2 +-
 tools/testing/selftests/kselftest/prefix.pl   | 24 --------
 tools/testing/selftests/kselftest/prefix.py   | 24 ++++++++
 tools/testing/selftests/kselftest/runner.sh   |  4 +-
 19 files changed, 269 insertions(+), 248 deletions(-)
 delete mode 100755 tools/perf/tests/shell/common/check_all_lines_matched.pl
 create mode 100755 tools/perf/tests/shell/common/check_all_lines_matched.py
 delete mode 100755 tools/perf/tests/shell/common/check_all_patterns_found.pl
 create mode 100755 tools/perf/tests/shell/common/check_all_patterns_found.py
 delete mode 100755 tools/perf/tests/shell/common/check_errors_whitelisted.pl
 create mode 100755 tools/perf/tests/shell/common/check_errors_whitelisted.py
 delete mode 100755 tools/perf/tests/shell/common/check_no_patterns_found.pl
 create mode 100755 tools/perf/tests/shell/common/check_no_patterns_found.py
 delete mode 100755 tools/testing/selftests/kselftest/prefix.pl
 create mode 100755 tools/testing/selftests/kselftest/prefix.py
Signature · 1 line
2.56.0
#23 lore raw

RFC PATCH v4 1/2 kselftest: convert prefix.pl to Python

Faithful re-implementation of tools/testing/selftests/kselftest/ prefix.pl in Python 3 (stdlib only). Same unbuffered stdin-to-stdout processing, same "# " prefix behavior.

Update runner.sh to invoke prefix.py instead of prefix.pl, update the install target to install prefix.py, and remove the old prefix.pl.

Verified byte-for-byte identical to the Perl version.

---
 tools/testing/selftests/Makefile            |  2 +-
 tools/testing/selftests/kselftest/prefix.pl | 24 ---------------------
 tools/testing/selftests/kselftest/prefix.py | 24 +++++++++++++++++++++
 tools/testing/selftests/kselftest/runner.sh |  4 ++--
 4 files changed, 27 insertions(+), 27 deletions(-)
 delete mode 100755 tools/testing/selftests/kselftest/prefix.pl
 create mode 100755 tools/testing/selftests/kselftest/prefix.py
tools/testing/selftests/Makefile +1 -1
index 2d960626750e..4bec301fe278 100644
@@ -280,7 +280,7 @@ ifdef INSTALL_PATH
 	mkdir -p $(INSTALL_PATH)/kselftest
 	install -m 744 kselftest/module.sh $(INSTALL_PATH)/kselftest/
 	install -m 744 kselftest/runner.sh $(INSTALL_PATH)/kselftest/
-	install -m 744 kselftest/prefix.pl $(INSTALL_PATH)/kselftest/
+	install -m 744 kselftest/prefix.py $(INSTALL_PATH)/kselftest/
 	install -m 744 kselftest/ktap_helpers.sh $(INSTALL_PATH)/kselftest/
 	install -m 744 kselftest/ksft.py $(INSTALL_PATH)/kselftest/
 	install -m 744 run_kselftest.sh $(INSTALL_PATH)/
tools/testing/selftests/kselftest/prefix.pl deleted +0 -24
deleted file mode 100755
index 12a7f4ca2684..000000000000
@@ -1,24 +0,0 @@
-#!/usr/bin/env perl
-# SPDX-License-Identifier: GPL-2.0
-# Prefix all lines with "# ", unbuffered. Command being piped in may need
-# to have unbuffering forced with "stdbuf -i0 -o0 -e0 $cmd".
-use strict;
-use IO::Handle;
-
-binmode STDIN;
-binmode STDOUT;
-
-STDOUT->autoflush(1);
-
-my $needed = 1;
-while (1) {
-	my $char;
-	my $bytes = sysread(STDIN, $char, 1);
-	exit 0 if ($bytes == 0);
-	if ($needed) {
-		print "# ";
-		$needed = 0;
-	}
-	print $char;
-	$needed = 1 if ($char eq "\n");
-}
tools/testing/selftests/kselftest/prefix.py new file +24 -0
new file mode 100755
index 000000000000..67c4fd0b6089
@@ -0,0 +1,24 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0
+# Prefix all lines with "# ", unbuffered.
+
+import sys
+
+
+def main():
+    needed = True
+    while True:
+        char = sys.stdin.buffer.read(1)
+        if not char:
+            return 0
+        if needed:
+            sys.stdout.buffer.write(b"# ")
+            needed = False
+        sys.stdout.buffer.write(char)
+        sys.stdout.buffer.flush()
+        if char == b"\n":
+            needed = True
+
+
+if __name__ == "__main__":
+    sys.exit(main())
tools/testing/selftests/kselftest/runner.sh +2 -2
index 311811dc55a0..1944c74f1e31 100644
@@ -29,10 +29,10 @@ TR_CMD=$(command -v tr)
 # with sed instead of unbuffered output.
 tap_prefix()
 {
-	if [ ! -x /usr/bin/perl ]; then
+	if [ ! -x /usr/bin/python3 ]; then
 		sed -e 's/^/# /'
 	else
-		"$BASE_DIR"/kselftest/prefix.pl
+		"$BASE_DIR"/kselftest/prefix.py
 	fi
 }
 
Signature · 1 line
2.56.0
#24 lore raw

Re: [RFC PATCH v4 1/2] kselftest: convert prefix.pl to Python

Sashiko has reviewed this patch and found no issues.
Quoted 11 lines

Faithful re-implementation of tools/testing/selftests/kselftest/ prefix.pl in Python 3 (stdlib only). Same unbuffered stdin-to-stdout processing, same "# " prefix behavior.

Update runner.sh to invoke prefix.py instead of prefix.pl, update the install target to install prefix.py, and remove the old prefix.pl.

Verified byte-for-byte identical to the Perl version.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#25 lore raw

RFC PATCH v4 2/2 perf/tests: convert check_*.pl helpers to Python

In reply to Breno Rodrigues Alves

Faithful re-implementations of the four Perl test helpers in tools/perf/tests/shell/common/:
- check_all_patterns_found.pl
- check_no_patterns_found.pl
- check_all_lines_matched.pl
- check_errors_whitelisted.pl

Same CLI, same output, same exit codes. All use only the Python standard library. TESTLOG_VERBOSITY and TESTLOG_ERR_MSG_MAX_LINES environment handling is preserved.

Update all 37 call sites across base_probe/ and base_report/ to invoke the .py versions. Update Makefile.perf's install-tests target to install *.py files (in addition to *.sh) from tests/shell/common/. Remove the four old .pl files.

All four were verified byte-for-byte identical to their Perl counterparts on synthetic inputs.

---
 tools/perf/Makefile.perf                      |  2 +-
 .../base_probe/test_adding_blacklisted.sh     |  6 +-
 .../shell/base_probe/test_adding_kernel.sh    | 44 +++++++-------
 .../perf/tests/shell/base_probe/test_basic.sh | 12 ++--
 .../shell/base_probe/test_invalid_options.sh  |  4 +-
 tools/perf/tests/shell/base_report/setup.sh   |  4 +-
 .../tests/shell/base_report/test_basic.sh     | 54 ++++++++---------
 .../shell/common/check_all_lines_matched.pl   | 39 -------------
 .../shell/common/check_all_lines_matched.py   | 47 +++++++++++++++
 .../shell/common/check_all_patterns_found.pl  | 34 -----------
 .../shell/common/check_all_patterns_found.py  | 37 ++++++++++++
 .../shell/common/check_errors_whitelisted.pl  | 51 ----------------
 .../shell/common/check_errors_whitelisted.py  | 58 +++++++++++++++++++
 .../shell/common/check_no_patterns_found.pl   | 34 -----------
 .../shell/common/check_no_patterns_found.py   | 37 ++++++++++++
 15 files changed, 242 insertions(+), 221 deletions(-)
 delete mode 100755 tools/perf/tests/shell/common/check_all_lines_matched.pl
 create mode 100755 tools/perf/tests/shell/common/check_all_lines_matched.py
 delete mode 100755 tools/perf/tests/shell/common/check_all_patterns_found.pl
 create mode 100755 tools/perf/tests/shell/common/check_all_patterns_found.py
 delete mode 100755 tools/perf/tests/shell/common/check_errors_whitelisted.pl
 create mode 100755 tools/perf/tests/shell/common/check_errors_whitelisted.py
 delete mode 100755 tools/perf/tests/shell/common/check_no_patterns_found.pl
 create mode 100755 tools/perf/tests/shell/common/check_no_patterns_found.py
tools/perf/Makefile.perf +1 -1
index 2d9379fea267..494a38871560 100644
@@ -982,7 +982,7 @@ install-tests: all install-gtk
 		$(INSTALL) tests/shell/lib/*.py -m 644 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/lib'; \
 		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/common'; \
 		$(INSTALL) tests/shell/common/*.sh '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/common'; \
-		$(INSTALL) tests/shell/common/*.pl '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/common'; \
+		$(INSTALL) tests/shell/common/*.py '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/common'; \
 		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/base_probe'; \
 		$(INSTALL) tests/shell/base_probe/*.sh '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/base_probe'; \
 		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell/base_report'; \
tools/perf/tests/shell/base_probe/test_adding_blacklisted.sh +3 -3
index f74aab5c5d7f..867545a62908 100755
@@ -54,7 +54,7 @@ for BLACKFUNC in $BLACKFUNC_LIST; do
 	PERF_EXIT_CODE=$?
 
 	# check for bad DWARF polluting the result
-	"$DIR_PATH/../common/check_all_patterns_found.pl" \
+	"$DIR_PATH/../common/check_all_patterns_found.py" \
 		"$REGEX_MISSING_DECL_LINE" >/dev/null < $LOGS_DIR/adding_blacklisted.err
 
 	if [ $? -eq 0 ]; then
@@ -75,7 +75,7 @@ for BLACKFUNC in $BLACKFUNC_LIST; do
 			fi
 		fi
 	else
-		"$DIR_PATH/../common/check_all_lines_matched.pl" \
+		"$DIR_PATH/../common/check_all_lines_matched.py" \
 			"$REGEX_SKIP_MESSAGE" "$REGEX_NOT_FOUND_MESSAGE" \
 			"$REGEX_ERROR_MESSAGE" "$REGEX_SCOPE_FAIL" \
 			"$REGEX_INVALID_ARGUMENT" "$REGEX_SYMBOL_FAIL" \
@@ -100,7 +100,7 @@ fi
 $CMD_PERF list probe:\* > $LOGS_DIR/adding_blacklisted_list.log
 PERF_EXIT_CODE=$?
 
-"$DIR_PATH/../common/check_all_lines_matched.pl" \
+"$DIR_PATH/../common/check_all_lines_matched.py" \
 	"$RE_LINE_EMPTY" "List of pre-defined events" "Metric Groups:" \
 	< $LOGS_DIR/adding_blacklisted_list.log
 CHECK_EXIT_CODE=$?
tools/perf/tests/shell/base_probe/test_adding_kernel.sh +22 -22

162 lines not on this page · raw message

tools/perf/tests/shell/base_probe/test_basic.sh +6 -6
index 162838ddc974..a702be7340c0 100755
@@ -31,24 +31,24 @@ if [ "$PARAM_GENERAL_HELP_TEXT_CHECK" = "y" ]; then
 	$CMD_PERF probe --help > $LOGS_DIR/basic_helpmsg.log 2> $LOGS_DIR/basic_helpmsg.err
 	PERF_EXIT_CODE=$?
 
-	"$DIR_PATH/../common/check_all_patterns_found.pl" \
+	"$DIR_PATH/../common/check_all_patterns_found.py" \
 		"PERF-PROBE" "NAME" "SYNOPSIS" "DESCRIPTION" "OPTIONS" \
 		"PROBE\s+SYNTAX" "PROBE\s+ARGUMENT" "LINE\s+SYNTAX" \
 		< $LOGS_DIR/basic_helpmsg.log
 	CHECK_EXIT_CODE=$?
-	"$DIR_PATH/../common/check_all_patterns_found.pl" \
+	"$DIR_PATH/../common/check_all_patterns_found.py" \
 		"LAZY\s+MATCHING" "FILTER\s+PATTERN" "EXAMPLES" "SEE\s+ALSO" \
 		< $LOGS_DIR/basic_helpmsg.log
 	(( CHECK_EXIT_CODE += $? ))
-	"$DIR_PATH/../common/check_all_patterns_found.pl" \
+	"$DIR_PATH/../common/check_all_patterns_found.py" \
 		"vmlinux" "module=" "source=" "verbose" "quiet" "add=" "del=" \
 		"list.*EVENT" "line=" "vars=" "externs" < $LOGS_DIR/basic_helpmsg.log
 	(( CHECK_EXIT_CODE += $? ))
-	"$DIR_PATH/../common/check_all_patterns_found.pl" \
+	"$DIR_PATH/../common/check_all_patterns_found.py" \
 		"no-inlines" "funcs.*FILTER" "filter=FILTER" "force" "dry-run" \
 		"max-probes" "exec=" "demangle-kernel" < $LOGS_DIR/basic_helpmsg.log
 	(( CHECK_EXIT_CODE += $? ))
-	"$DIR_PATH/../common/check_no_patterns_found.pl" \
+	"$DIR_PATH/../common/check_no_patterns_found.py" \
 		"No manual entry for" < $LOGS_DIR/basic_helpmsg.err
 	(( CHECK_EXIT_CODE += $? ))
 
@@ -64,7 +64,7 @@ fi
 # without any args perf-probe should print usage
 $CMD_PERF probe 2> $LOGS_DIR/basic_usage.log > /dev/null
 
-"$DIR_PATH/../common/check_all_patterns_found.pl" \
+"$DIR_PATH/../common/check_all_patterns_found.py" \
 	"[Uu]sage" "perf probe" "verbose" "quiet" "add" "del" "force" \
 	"line" "vars" "externs" "range" < $LOGS_DIR/basic_usage.log
 CHECK_EXIT_CODE=$?
tools/perf/tests/shell/base_probe/test_invalid_options.sh +2 -2
index 44a3ae014bfa..d88bb7ec5da6 100755
@@ -34,7 +34,7 @@ for opt in '-a' '-d' '-L' '-V'; do
 	! $CMD_PERF probe $opt 2> $LOGS_DIR/invalid_options_missing_argument$opt.err
 	PERF_EXIT_CODE=$?
 
-	"$DIR_PATH/../common/check_all_patterns_found.pl" \
+	"$DIR_PATH/../common/check_all_patterns_found.py" \
 		"Error: switch .* requires a value" \
 		< $LOGS_DIR/invalid_options_missing_argument$opt.err
 	CHECK_EXIT_CODE=$?
@@ -69,7 +69,7 @@ for opt in '-a xxx -d xxx' '-a xxx -L foo' '-a xxx -V foo' '-a xxx -l' '-a xxx -
 	! $CMD_PERF probe $opt > /dev/null 2> $LOGS_DIR/aux.log
 	PERF_EXIT_CODE=$?
 
-	"$DIR_PATH/../common/check_all_patterns_found.pl" \
+	"$DIR_PATH/../common/check_all_patterns_found.py" \
 		"Error: switch .+ cannot be used with switch .+" < $LOGS_DIR/aux.log
 	CHECK_EXIT_CODE=$?
 
tools/perf/tests/shell/base_report/setup.sh +2 -2
index bb49b0fabb11..10fe4b553c4e 100755
@@ -26,7 +26,7 @@ SW_EVENT="cpu-clock"
 $CMD_PERF record -asdg -e $SW_EVENT -o $CURRENT_TEST_DIR/perf.data -- $CMD_LONGER_SLEEP 2> $LOGS_DIR/setup.log
 PERF_EXIT_CODE=$?
 
-"$DIR_PATH/../common/check_all_patterns_found.pl" \
+"$DIR_PATH/../common/check_all_patterns_found.py" \
 	"$RE_LINE_RECORD1" "$RE_LINE_RECORD2" < $LOGS_DIR/setup.log
 CHECK_EXIT_CODE=$?
 
@@ -41,7 +41,7 @@ echo ==================
 cat $LOGS_DIR/setup-latency.log
 echo ==================
 
-"$DIR_PATH/../common/check_all_patterns_found.pl" \
+"$DIR_PATH/../common/check_all_patterns_found.py" \
 	"$RE_LINE_RECORD1" "$RE_LINE_RECORD2" < $LOGS_DIR/setup-latency.log
 CHECK_EXIT_CODE=$?
 
tools/perf/tests/shell/base_report/test_basic.sh +27 -27

167 lines not on this page · raw message

tools/perf/tests/shell/common/check_all_lines_matched.pl deleted +0 -39
deleted file mode 100755
index fded48959a3f..000000000000
@@ -1,39 +0,0 @@
-#!/usr/bin/perl
-# SPDX-License-Identifier: GPL-2.0
-
-@regexps = @ARGV;
-
-$max_printed_lines = 20;
-$max_printed_lines = $ENV{TESTLOG_ERR_MSG_MAX_LINES} if (defined $ENV{TESTLOG_ERR_MSG_MAX_LINES});
-
-$quiet = 1;
-$quiet = 0 if (defined $ENV{TESTLOG_VERBOSITY} && $ENV{TESTLOG_VERBOSITY} ge 2);
-
-$passed = 1;
-$lines_printed = 0;
-
-while (<STDIN>)
-{
-	s/\n//;
-
-	$line_matched = 0;
-	for $r (@regexps)
-	{
-		if (/$r/)
-		{
-			$line_matched = 1;
-			last;
-		}
-	}
-
-	unless ($line_matched)
-	{
-		if ($lines_printed++ < $max_printed_lines)
-		{
-			print "Line did not match any pattern: \"$_\"\n" unless $quiet;
-		}
-		$passed = 0;
-	}
-}
-
-exit ($passed == 0);
tools/perf/tests/shell/common/check_all_lines_matched.py new file +47 -0

47 lines not on this page · raw message

tools/perf/tests/shell/common/check_all_patterns_found.pl deleted +0 -34
deleted file mode 100755
index 11bdf1d3460a..000000000000
@@ -1,34 +0,0 @@
-#!/usr/bin/perl
-# SPDX-License-Identifier: GPL-2.0
-
-@regexps = @ARGV;
-
-$quiet = 1;
-$quiet = 0 if (defined $ENV{TESTLOG_VERBOSITY} && $ENV{TESTLOG_VERBOSITY} ge 2);
-
-%found = ();
-$passed = 1;
-
-while (<STDIN>)
-{
-	s/\n//;
-
-	for $r (@regexps)
-	{
-		if (/$r/)
-		{
-			$found{$r} = 1;	# FIXME: maybe add counters -- how many times was the regexp matched
-		}
-	}
-}
-
-for $r (@regexps)
-{
-	unless (exists $found{$r})
-	{
-		print "Regexp not found: \"$r\"\n" unless $quiet;
-		$passed = 0;
-	}
-}
-
-exit ($passed == 0);
tools/perf/tests/shell/common/check_all_patterns_found.py new file +37 -0
new file mode 100755
index 000000000000..42cf4bc2c0d4
@@ -0,0 +1,37 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0
+
+import os
+import re
+import sys
+
+
+def main(argv):
+    sys.stdin.reconfigure(encoding="utf-8", errors="surrogateescape")
+    sys.stdout.reconfigure(encoding="utf-8", errors="surrogateescape")
+    quiet = True
+    try:
+        if int(os.environ.get("TESTLOG_VERBOSITY", "0")) >= 2:
+            quiet = False
+    except ValueError:
+        pass
+
+    found = set()
+    for line in sys.stdin:
+        line = line.rstrip("\n")
+        for r in argv:
+            if re.search(r, line):
+                found.add(r)
+
+    passed = True
+    for r in argv:
+        if r not in found:
+            if not quiet:
+                print(f'Regexp not found: "{r}"')
+            passed = False
+
+    return 0 if passed else 1
+
+
+if __name__ == "__main__":
+    sys.exit(main(sys.argv[1:]))
tools/perf/tests/shell/common/check_errors_whitelisted.pl deleted +0 -51

51 lines not on this page · raw message

tools/perf/tests/shell/common/check_errors_whitelisted.py new file +58 -0

58 lines not on this page · raw message

tools/perf/tests/shell/common/check_no_patterns_found.pl deleted +0 -34
deleted file mode 100755
index 770999e87a5f..000000000000
@@ -1,34 +0,0 @@
-#!/usr/bin/perl
-# SPDX-License-Identifier: GPL-2.0
-
-@regexps = @ARGV;
-
-$quiet = 1;
-$quiet = 0 if (defined $ENV{TESTLOG_VERBOSITY} && $ENV{TESTLOG_VERBOSITY} ge 2);
-
-%found = ();
-$passed = 1;
-
-while (<STDIN>)
-{
-	s/\n//;
-
-	for $r (@regexps)
-	{
-		if (/$r/)
-		{
-			$found{$r} = 1;
-		}
-	}
-}
-
-for $r (@regexps)
-{
-	if (exists $found{$r})
-	{
-		print "Regexp found: \"$r\"\n" unless $quiet;
-		$passed = 0;
-	}
-}
-
-exit ($passed == 0);
tools/perf/tests/shell/common/check_no_patterns_found.py new file +37 -0
new file mode 100755
index 000000000000..92842ec0a1e1
@@ -0,0 +1,37 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0
+
+import os
+import re
+import sys
+
+
+def main(argv):
+    sys.stdin.reconfigure(encoding="utf-8", errors="surrogateescape")
+    sys.stdout.reconfigure(encoding="utf-8", errors="surrogateescape")
+    quiet = True
+    try:
+        if int(os.environ.get("TESTLOG_VERBOSITY", "0")) >= 2:
+            quiet = False
+    except ValueError:
+        pass
+
+    found = set()
+    for line in sys.stdin:
+        line = line.rstrip("\n")
+        for r in argv:
+            if re.search(r, line):
+                found.add(r)
+
+    passed = True
+    for r in argv:
+        if r in found:
+            if not quiet:
+                print(f'Regexp found: "{r}"')
+            passed = False
+
+    return 0 if passed else 1
+
+
+if __name__ == "__main__":
+    sys.exit(main(sys.argv[1:]))
Signature · 1 line
2.56.0
#26 lore raw

Re: [RFC PATCH v4 2/2] perf/tests: convert check_*.pl helpers to Python

Sashiko has reviewed this patch and found no issues.
Quoted 16 lines

Faithful re-implementations of the four Perl test helpers in tools/perf/tests/shell/common/:
- check_all_patterns_found.pl
- check_no_patterns_found.pl
- check_all_lines_matched.pl
- check_errors_whitelisted.pl

Same CLI, same output, same exit codes. All use only the Python standard library. TESTLOG_VERBOSITY and TESTLOG_ERR_MSG_MAX_LINES environment handling is preserved.

Update all 37 call sites across base_probe/ and base_report/ to invoke the .py versions. Update Makefile.perf's install-tests target to install *.py files (in addition to *.sh) from tests/shell/common/. Remove the four old .pl files.

Quoted 4 lines

All four were verified byte-for-byte identical to their Perl counterparts on synthetic inputs.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2