diff --git a/llvm/utils/lit/lit/reports.py b/llvm/utils/lit/lit/reports.py --- a/llvm/utils/lit/lit/reports.py +++ b/llvm/utils/lit/lit/reports.py @@ -68,6 +68,18 @@ file.write('\n') +def escape_control_chars(s): + escape_dict = {chr(c): '\\x' + hex(c)[2:] for c in range(32) if chr(c) not in ('\t', '\n', '\r')} + try: + s = s.translate(str.maketrans(escape_dict)) + except AttributeError: + # python 2.7 string.translate() does not support multi-character + # replacing, so fall back to multiple str.replace() calls. + for k, v in escape_dict.items(): + s = s.replace(k, v) + return s + + class XunitReport(object): def __init__(self, output_file): self.output_file = output_file @@ -114,6 +126,11 @@ output = test.result.output.replace(']]>', ']]]]>') if isinstance(output, bytes): output.decode("utf-8", 'ignore') + + # The Jenkins JUnit XML parser throws an exception if the output + # contains control characters like \x1b (e.g. if there is some + # -fcolor-diagnostics output). + output = escape_control_chars(output) file.write(output) file.write(']]>\n\n') elif test.result.code in self.skipped_codes: