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. Signed-off-by: Breno Rodrigues Alves <[email protected]> --- .../shell/common/check_errors_whitelisted.py | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100755 tools/perf/tests/shell/common/check_errors_whitelisted.py diff --git a/tools/perf/tests/shell/common/check_errors_whitelisted.py b/tools/perf/tests/shell/common/check_errors_whitelisted.py new file mode 100755 index 000000000..352eb1a9d --- /dev/null +++ b/tools/perf/tests/shell/common/check_errors_whitelisted.py @@ -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 -- 2.43.0

