[llvm] [lit] Add --wtt-output option to report results in WTT (.wtl) format (PR #211066)

Yasser Khan via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 10 13:04:05 PDT 2026


================
@@ -302,3 +302,165 @@ def _get_test_event(self, test, first_start_time):
             "dur": int(elapsed_time * 1000000.0),
             "name": test_name,
         }
+
+
+def _wtt_attr(text):
+    # Prepare text for a WTT XML attribute value: flatten newlines/tabs to
+    # spaces (raw newlines are illegal in XML attributes), drop invalid XML
+    # chars using the shared helper, then quote. quoteattr adds the quotes.
+    text = (
+        text.replace("\r\n", " ")
+        .replace("\n", " ")
+        .replace("\r", " ")
+        .replace("\t", " ")
+    )
+    return quo(remove_invalid_xml_chars(text))
+
+
+class WttReport(Report):
+    def write_results(self, tests, elapsed):
+        with open(self.output_file, "w", encoding="utf-16") as f:
+            self._write_results_to_file(tests, elapsed, f)
+
+    def _write_results_to_file(self, tests, elapsed, file):
+        tests.sort(key=by_suite_and_test_path)
+
+        machine = os.getenv("COMPUTERNAME", "")
+        pid = os.getpid()
+
+        starts = [t.result.start for t in tests if t.result and t.result.start]
+        base = min(starts) if starts else 0.0
+        base_dt = datetime.datetime.fromtimestamp(base)
+        base_time = "%d:%d:%d %d:%d:%d:%d" % (
----------------
yassermkhan wrote:

Used `strftime`, but had to manually do milliseconds since WTT expects milliseconds between 0-999

https://github.com/llvm/llvm-project/pull/211066


More information about the llvm-commits mailing list