[lit] Support more ulimit options

These are the other options used in compiler-rt that we also need to
support.

Reviewers: arichardson, petrhosek, ilovepi

Reviewed By: ilovepi, arichardson

Pull Request: https://github.com/llvm/llvm-project/pull/165122
This commit is contained in:
Aiden Grossman 2025-10-27 10:43:56 -07:00 committed by GitHub
parent 43f119baa6
commit 8f1c72dcd3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 16 additions and 0 deletions

View File

@ -612,6 +612,10 @@ def executeBuiltinUlimit(cmd, shenv):
shenv.ulimit["RLIMIT_AS"] = new_limit * 1024
elif cmd.args[1] == "-n":
shenv.ulimit["RLIMIT_NOFILE"] = new_limit
elif cmd.args[1] == "-s":
shenv.ulimit["RLIMIT_STACK"] = new_limit * 1024
elif cmd.args[1] == "-f":
shenv.ulimit["RLIMIT_FSIZE"] = new_limit
else:
raise InternalShellError(
cmd, "'ulimit' does not support option: %s" % cmd.args[1]

View File

@ -17,6 +17,10 @@ def main(argv):
resource.setrlimit(resource.RLIMIT_AS, limit)
elif limit_str == "RLIMIT_NOFILE":
resource.setrlimit(resource.RLIMIT_NOFILE, limit)
elif limit_str == "RLIMIT_STACK":
resource.setrlimit(resource.RLIMIT_STACK, limit)
elif limit_str == "RLIMIT_FSIZE":
resource.setrlimit(resource.RLIMIT_FSIZE, limit)
process_output = subprocess.run(command_args)
sys.exit(process_output.returncode)

View File

@ -2,3 +2,5 @@ import resource
print("RLIMIT_AS=" + str(resource.getrlimit(resource.RLIMIT_AS)[0]))
print("RLIMIT_NOFILE=" + str(resource.getrlimit(resource.RLIMIT_NOFILE)[0]))
print("RLIMIT_STACK=" + str(resource.getrlimit(resource.RLIMIT_STACK)[0]))
print("RLIMIT_FSIZE=" + str(resource.getrlimit(resource.RLIMIT_FSIZE)[0]))

View File

@ -1,4 +1,6 @@
# RUN: ulimit -n 50
# RUN: ulimit -s 256
# RUN: ulimit -f 5
# RUN: %{python} %S/print_limits.py
# Fail the test so that we can assert on the output.
# RUN: not echo return

View File

@ -19,7 +19,11 @@
# CHECK-LABEL: FAIL: shtest-ulimit :: ulimit_okay.txt ({{[^)]*}})
# CHECK: ulimit -n 50
# CHECK: ulimit -s 256
# CHECK: ulimit -f 5
# CHECK: RLIMIT_NOFILE=50
# CHECK: RLIMIT_STACK=262144
# CHECK: RLIMIT_FSIZE=5
# CHECK-LABEL: FAIL: shtest-ulimit :: ulimit_reset.txt ({{[^)]*}})
# CHECK: RLIMIT_NOFILE=[[BASE_NOFILE_LIMIT]]