Skip to content

Commit 9b02901

Browse files
[lit] Add support for setting limits to unlimited
This is used by a couple compiler-rt tests. Reviewers: petrhosek, ilovepi Reviewed By: ilovepi Pull Request: llvm#165123
1 parent f814446 commit 9b02901

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

llvm/utils/lit/lit/TestRunner.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -600,20 +600,31 @@ def executeBuiltinUmask(cmd, shenv):
600600

601601
def executeBuiltinUlimit(cmd, shenv):
602602
"""executeBuiltinUlimit - Change the current limits."""
603-
if os.name != "posix":
603+
try:
604+
# Try importing the resource module (available on POSIX systems) and
605+
# emit an error where it does not exist (e.g., Windows).
606+
import resource
607+
except ImportError:
604608
raise InternalShellError(cmd, "'ulimit' not supported on this system")
605609
if len(cmd.args) != 3:
606610
raise InternalShellError(cmd, "'ulimit' requires two arguments")
607611
try:
608-
new_limit = int(cmd.args[2])
612+
if cmd.args[2] == "unlimited":
613+
new_limit = resource.RLIM_INFINITY
614+
else:
615+
new_limit = int(cmd.args[2])
609616
except ValueError as err:
610617
raise InternalShellError(cmd, "Error: 'ulimit': %s" % str(err))
611618
if cmd.args[1] == "-v":
612-
shenv.ulimit["RLIMIT_AS"] = new_limit * 1024
619+
if new_limit != resource.RLIM_INFINITY:
620+
new_limit = new_limit * 1024
621+
shenv.ulimit["RLIMIT_AS"] = new_limit
613622
elif cmd.args[1] == "-n":
614623
shenv.ulimit["RLIMIT_NOFILE"] = new_limit
615624
elif cmd.args[1] == "-s":
616-
shenv.ulimit["RLIMIT_STACK"] = new_limit * 1024
625+
if new_limit != resource.RLIM_INFINITY:
626+
new_limit = new_limit * 1024
627+
shenv.ulimit["RLIMIT_STACK"] = new_limit
617628
elif cmd.args[1] == "-f":
618629
shenv.ulimit["RLIMIT_FSIZE"] = new_limit
619630
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
@@ -25,3 +25,9 @@
2525

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

0 commit comments

Comments
 (0)