Skip to content

Commit 7387863

Browse files
[lit] Add support for setting limits to unlimited
This is used by a couple compiler-rt tests. Pull Request: llvm#165123
1 parent b8cce14 commit 7387863

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

llvm/utils/lit/lit/TestRunner.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -602,18 +602,28 @@ def executeBuiltinUlimit(cmd, shenv):
602602
"""executeBuiltinUlimit - Change the current limits."""
603603
if os.name != "posix":
604604
raise InternalShellError(cmd, "'ulimit' not supported on this system")
605+
# Import resource here after we confirm we are on a POSIX system as the
606+
# module does not exist on Windows.
607+
import resource
605608
if len(cmd.args) != 3:
606609
raise InternalShellError(cmd, "'ulimit' requires two arguments")
607610
try:
608-
new_limit = int(cmd.args[2])
611+
if cmd.args[2] == "unlimited":
612+
new_limit = resource.RLIM_INFINITY
613+
else:
614+
new_limit = int(cmd.args[2])
609615
except ValueError as err:
610616
raise InternalShellError(cmd, "Error: 'ulimit': %s" % str(err))
611617
if cmd.args[1] == "-v":
612-
shenv.ulimit["RLIMIT_AS"] = new_limit * 1024
618+
if new_limit != resource.RLIM_INFINITY:
619+
new_limit = new_limit * 1024
620+
shenv.ulimit["RLIMIT_AS"] = new_limit
613621
elif cmd.args[1] == "-n":
614622
shenv.ulimit["RLIMIT_NOFILE"] = new_limit
615623
elif cmd.args[1] == "-s":
616-
shenv.ulimit["RLIMIT_STACK"] = new_limit * 1024
624+
if new_limit != resource.RLIM_INFINITY:
625+
new_limit = new_limit * 1024
626+
shenv.ulimit["RLIMIT_STACK"] = new_limit
617627
elif cmd.args[1] == "-f":
618628
shenv.ulimit["RLIMIT_FSIZE"] = new_limit
619629
else:
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# RUN: ulimit -f 5
2+
# RUN: %{python} %S/print_limits.py
3+
# RUN: ulimit -f unlimited
4+
# RUN: %{python} %S/print_limits.py
5+
# Fail the test so that we can assert on the output.
6+
# RUN: not echo return

llvm/utils/lit/tests/shtest-ulimit.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# RUN: not %{lit} -a -v %{inputs}/shtest-ulimit --order=lexical \
1212
# RUN: | FileCheck -DBASE_NOFILE_LIMIT=%{readfile:%t.nofile_limit} %s
1313

14-
# CHECK: -- Testing: 3 tests{{.*}}
14+
# CHECK: -- Testing: 4 tests{{.*}}
1515

1616
# CHECK-LABEL: FAIL: shtest-ulimit :: ulimit-bad-arg.txt ({{[^)]*}})
1717
# CHECK: ulimit -n
@@ -27,3 +27,9 @@
2727

2828
# CHECK-LABEL: FAIL: shtest-ulimit :: ulimit_reset.txt ({{[^)]*}})
2929
# CHECK: RLIMIT_NOFILE=[[BASE_NOFILE_LIMIT]]
30+
31+
# CHECK-LABEL: FAIL: shtest-ulimit :: ulimit_unlimited.txt ({{[^)]*}})
32+
# CHECK: ulimit -f 5
33+
# CHECK: RLIMIT_FSIZE=5
34+
# CHECK: ulimit -f unlimited
35+
# CHECK: RLIMIT_FSIZE=-1

0 commit comments

Comments
 (0)