[llvm-branch-commits] [llvm] [lit] Implement ulimit builtin (PR #157958)
Aiden Grossman via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Sep 10 14:51:50 PDT 2025
https://github.com/boomanaiden154 updated https://github.com/llvm/llvm-project/pull/157958
>From 030af4e2e48510334aa3001275f43132a7042f5c Mon Sep 17 00:00:00 2001
From: Aiden Grossman <aidengrossman at google.com>
Date: Wed, 10 Sep 2025 21:16:59 +0000
Subject: [PATCH 1/2] formatting
Created using spr 1.3.6
---
llvm/utils/lit/lit/TestRunner.py | 11 ++++++++---
.../lit/lit/builtin_commands/_launch_with_limit.py | 5 +++--
2 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/llvm/utils/lit/lit/TestRunner.py b/llvm/utils/lit/lit/TestRunner.py
index ec44c26c29afc..8e0c0c25a4b15 100644
--- a/llvm/utils/lit/lit/TestRunner.py
+++ b/llvm/utils/lit/lit/TestRunner.py
@@ -601,6 +601,7 @@ def executeBuiltinUmask(cmd, shenv):
raise InternalShellError(cmd, "Error: 'umask': %s" % str(err))
return ShellCommandResult(cmd, "", "", 0, False)
+
def executeBuiltinUlimit(cmd, shenv):
"""executeBuiltinUlimit - Change the current limits."""
if os.name != "posix":
@@ -616,7 +617,9 @@ def executeBuiltinUlimit(cmd, shenv):
elif cmd.args[1] == "-n":
shenv.ulimit["RLIMIT_NOFILE"] = new_limit
else:
- raise InternalShellError(cmd, "'ulimit' does not support option: %s" % cmd.args[1])
+ raise InternalShellError(
+ cmd, "'ulimit' does not support option: %s" % cmd.args[1]
+ )
return ShellCommandResult(cmd, "", "", 0, False)
@@ -945,7 +948,7 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
# with some core utility distributions.
if kIsWindows:
args = quote_windows_command(args)
-
+
# Handle any resource limits. We do this by launching the command with
# a wrapper that sets the necessary limits. We use a wrapper rather than
# setting the limits in process as we cannot reraise the limits back to
@@ -954,7 +957,9 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
args.insert(0, sys.executable)
args.insert(1, os.path.join(builtin_commands_dir, "_launch_with_limit.py"))
for limit in cmd_shenv.ulimit:
- cmd_shenv.env["LIT_INTERNAL_ULIMIT_" + limit] = str(cmd_shenv.ulimit[limit])
+ cmd_shenv.env["LIT_INTERNAL_ULIMIT_" + limit] = str(
+ cmd_shenv.ulimit[limit]
+ )
try:
# TODO(boomanaiden154): We currently wrap the subprocess.Popen with
diff --git a/llvm/utils/lit/lit/builtin_commands/_launch_with_limit.py b/llvm/utils/lit/lit/builtin_commands/_launch_with_limit.py
index 0ccce8982400e..33d2d59ff0dbe 100644
--- a/llvm/utils/lit/lit/builtin_commands/_launch_with_limit.py
+++ b/llvm/utils/lit/lit/builtin_commands/_launch_with_limit.py
@@ -5,11 +5,12 @@
ULIMIT_ENV_VAR_PREFIX = "LIT_INTERNAL_ULIMIT_"
+
def main(argv):
command_args = argv[1:]
for env_var in os.environ:
if env_var.startswith(ULIMIT_ENV_VAR_PREFIX):
- limit_str = env_var[len(ULIMIT_ENV_VAR_PREFIX):]
+ limit_str = env_var[len(ULIMIT_ENV_VAR_PREFIX) :]
limit_value = int(os.environ[env_var])
limit = (limit_value, limit_value)
if limit_str == "RLIMIT_AS":
@@ -18,7 +19,7 @@ def main(argv):
resource.setrlimit(resource.RLIMIT_NOFILE, limit)
process_output = subprocess.run(command_args)
sys.exit(process_output.returncode)
-
+
if __name__ == "__main__":
main(sys.argv)
>From ef08f0859f76699661fc1b10cd2662e44d2f3a76 Mon Sep 17 00:00:00 2001
From: Aiden Grossman <aidengrossman at google.com>
Date: Wed, 10 Sep 2025 21:51:40 +0000
Subject: [PATCH 2/2] fix
Created using spr 1.3.6
---
llvm/utils/lit/lit/TestRunner.py | 1 +
1 file changed, 1 insertion(+)
diff --git a/llvm/utils/lit/lit/TestRunner.py b/llvm/utils/lit/lit/TestRunner.py
index 8e0c0c25a4b15..99f9118eae0c8 100644
--- a/llvm/utils/lit/lit/TestRunner.py
+++ b/llvm/utils/lit/lit/TestRunner.py
@@ -954,6 +954,7 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
# setting the limits in process as we cannot reraise the limits back to
# their defaults without elevated permissions.
if cmd_shenv.ulimit:
+ executable = sys.executable
args.insert(0, sys.executable)
args.insert(1, os.path.join(builtin_commands_dir, "_launch_with_limit.py"))
for limit in cmd_shenv.ulimit:
More information about the llvm-branch-commits
mailing list