[llvm] [lit] Truncate process output to 10 kiB (PR #206355)

Alexis Engelke via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 29 01:12:31 PDT 2026


https://github.com/aengelke updated https://github.com/llvm/llvm-project/pull/206355

>From 7cd03d039979e3e97d717c921482ae09332c7c58 Mon Sep 17 00:00:00 2001
From: Alexis Engelke <engelke at in.tum.de>
Date: Sun, 28 Jun 2026 17:58:22 +0000
Subject: [PATCH 1/4] [spr] initial version

Created using spr 1.3.8-wip
---
 llvm/utils/lit/lit/TestRunner.py | 27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/llvm/utils/lit/lit/TestRunner.py b/llvm/utils/lit/lit/TestRunner.py
index 1b0f4ad4eebef..77ad44a17d012 100644
--- a/llvm/utils/lit/lit/TestRunner.py
+++ b/llvm/utils/lit/lit/TestRunner.py
@@ -550,20 +550,23 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
             res = 1 if res != 0 else 0
 
         # Ensure the resulting output is always of string type.
-        try:
+        # Truncate output as soon as possible so that we don't serialize/process
+        # overly large strings. 10kiB output ought to be enough.
+        def convert_output(out, limit=10 * 1024) -> str:
             if out is None:
-                out = ""
-            else:
+                return ""
+            truncated = len(out) > limit
+            out = out[:limit]
+            try:
                 out = out.decode("utf-8", errors="replace")
-        except:
-            out = str(out)
-        try:
-            if err is None:
-                err = ""
-            else:
-                err = err.decode("utf-8", errors="replace")
-        except:
-            err = str(err)
+            except:
+                out = str(out)
+            if truncated:
+                out += "\n...\ndata was truncated"
+            return out
+
+        out = convert_output(out)
+        err = convert_output(err)
 
         # Gather the redirected output files for failed commands.
         output_files = []

>From 94e7102b7fb7de77ba9bb1c301561990ddc08ebf Mon Sep 17 00:00:00 2001
From: Alexis Engelke <engelke at in.tum.de>
Date: Sun, 28 Jun 2026 19:44:15 +0000
Subject: [PATCH 2/4] debug only, should fix libcxx

Created using spr 1.3.8-wip
---
 llvm/utils/lit/lit/TestRunner.py | 31 ++++++++++++++-----------------
 1 file changed, 14 insertions(+), 17 deletions(-)

diff --git a/llvm/utils/lit/lit/TestRunner.py b/llvm/utils/lit/lit/TestRunner.py
index 77ad44a17d012..f75425b9c8927 100644
--- a/llvm/utils/lit/lit/TestRunner.py
+++ b/llvm/utils/lit/lit/TestRunner.py
@@ -550,23 +550,20 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
             res = 1 if res != 0 else 0
 
         # Ensure the resulting output is always of string type.
-        # Truncate output as soon as possible so that we don't serialize/process
-        # overly large strings. 10kiB output ought to be enough.
-        def convert_output(out, limit=10 * 1024) -> str:
+        try:
             if out is None:
-                return ""
-            truncated = len(out) > limit
-            out = out[:limit]
-            try:
+                out = ""
+            else:
                 out = out.decode("utf-8", errors="replace")
-            except:
-                out = str(out)
-            if truncated:
-                out += "\n...\ndata was truncated"
-            return out
-
-        out = convert_output(out)
-        err = convert_output(err)
+        except:
+            out = str(out)
+        try:
+            if err is None:
+                err = ""
+            else:
+                err = err.decode("utf-8", errors="replace")
+        except:
+            err = str(err)
 
         # Gather the redirected output files for failed commands.
         output_files = []
@@ -776,9 +773,9 @@ def make_tree(cmds):
             data = data.decode("utf-8", errors="replace")
             out += formatOutput(f"redirected output from '{name}'", data, limit=1024)
         if result.stdout.strip():
-            out += formatOutput("command stdout", result.stdout)
+            out += formatOutput("command stdout", result.stdout, limit=10*1024)
         if result.stderr.strip():
-            out += formatOutput("command stderr", result.stderr)
+            out += formatOutput("command stderr", result.stderr, limit=10*1024)
         if not result.stdout.strip() and not result.stderr.strip():
             out += "# note: command had no output on stdout or stderr\n"
 

>From bdfb524ef8e6120a56202eedb4cd5f3e3e8e16fc Mon Sep 17 00:00:00 2001
From: Alexis Engelke <engelke at in.tum.de>
Date: Sun, 28 Jun 2026 19:48:08 +0000
Subject: [PATCH 3/4] python format

Created using spr 1.3.8-wip
---
 llvm/utils/lit/lit/TestRunner.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/llvm/utils/lit/lit/TestRunner.py b/llvm/utils/lit/lit/TestRunner.py
index f75425b9c8927..05c1463d1cb7d 100644
--- a/llvm/utils/lit/lit/TestRunner.py
+++ b/llvm/utils/lit/lit/TestRunner.py
@@ -773,9 +773,9 @@ def make_tree(cmds):
             data = data.decode("utf-8", errors="replace")
             out += formatOutput(f"redirected output from '{name}'", data, limit=1024)
         if result.stdout.strip():
-            out += formatOutput("command stdout", result.stdout, limit=10*1024)
+            out += formatOutput("command stdout", result.stdout, limit=10240)
         if result.stderr.strip():
-            out += formatOutput("command stderr", result.stderr, limit=10*1024)
+            out += formatOutput("command stderr", result.stderr, limit=10240)
         if not result.stdout.strip() and not result.stderr.strip():
             out += "# note: command had no output on stdout or stderr\n"
 

>From 8a7dd3c96dc5ae711254ec776246108142f99742 Mon Sep 17 00:00:00 2001
From: Alexis Engelke <engelke at in.tum.de>
Date: Mon, 29 Jun 2026 08:11:50 +0000
Subject: [PATCH 4/4] make limit configurable

Created using spr 1.3.8-wip
---
 llvm/utils/lit/lit/TestRunner.py | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/llvm/utils/lit/lit/TestRunner.py b/llvm/utils/lit/lit/TestRunner.py
index 05c1463d1cb7d..a79470d6da878 100644
--- a/llvm/utils/lit/lit/TestRunner.py
+++ b/llvm/utils/lit/lit/TestRunner.py
@@ -627,7 +627,8 @@ def formatOutput(title, data, limit=None):
         return ""
     if not limit is None and len(data) > limit:
         data = data[:limit] + "\n...\n"
-        msg = "data was truncated"
+        msg = (f"data was truncated ({limit}/{len(data)})" +
+               "(change limit with -D output_limit=N)")
     else:
         msg = ""
     ndashes = 30
@@ -769,13 +770,14 @@ def make_tree(cmds):
         # Otherwise, something failed or was printed, show it.
 
         # Add the command output, if redirected.
+        outputLimit = int(litConfig.params.get("output_limit", 10240))
         for (name, path, data) in result.outputFiles:
             data = data.decode("utf-8", errors="replace")
-            out += formatOutput(f"redirected output from '{name}'", data, limit=1024)
+            out += formatOutput(f"redirected output from '{name}'", data, limit=outputLimit)
         if result.stdout.strip():
-            out += formatOutput("command stdout", result.stdout, limit=10240)
+            out += formatOutput("command stdout", result.stdout, limit=outputLimit)
         if result.stderr.strip():
-            out += formatOutput("command stderr", result.stderr, limit=10240)
+            out += formatOutput("command stderr", result.stderr, limit=outputLimit)
         if not result.stdout.strip() and not result.stderr.strip():
             out += "# note: command had no output on stdout or stderr\n"
 



More information about the llvm-commits mailing list