Skip to content

Commit 35b60fe

Browse files
[𝘀𝗽𝗿] initial version
Created using spr 1.3.7
2 parents f03ccef + 01f79b9 commit 35b60fe

File tree

9 files changed

+57
-8
lines changed

9 files changed

+57
-8
lines changed

llvm/utils/lit/lit/TestRunner.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -602,16 +602,30 @@ 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
623+
elif cmd.args[1] == "-s":
624+
if new_limit != resource.RLIM_INFINITY:
625+
new_limit = new_limit * 1024
626+
shenv.ulimit["RLIMIT_STACK"] = new_limit
627+
elif cmd.args[1] == "-f":
628+
shenv.ulimit["RLIMIT_FSIZE"] = new_limit
615629
else:
616630
raise InternalShellError(
617631
cmd, "'ulimit' does not support option: %s" % cmd.args[1]
@@ -811,6 +825,10 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
811825
not_args = []
812826
not_count = 0
813827
not_crash = False
828+
829+
# Expand all late substitutions.
830+
args = _expandLateSubstitutions(j, args, cmd_shenv.cwd)
831+
814832
while True:
815833
if args[0] == "env":
816834
# Create a copy of the global environment and modify it for
@@ -860,9 +878,6 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
860878
# Ensure args[0] is hashable.
861879
args[0] = expand_glob(args[0], cmd_shenv.cwd)[0]
862880

863-
# Expand all late substitutions.
864-
args = _expandLateSubstitutions(j, args, cmd_shenv.cwd)
865-
866881
inproc_builtin = inproc_builtins.get(args[0], None)
867882
if inproc_builtin and (args[0] != "echo" or len(cmd.commands) == 1):
868883
# env calling an in-process builtin is useless, so we take the safe

llvm/utils/lit/lit/builtin_commands/_launch_with_limit.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ def main(argv):
1717
resource.setrlimit(resource.RLIMIT_AS, limit)
1818
elif limit_str == "RLIMIT_NOFILE":
1919
resource.setrlimit(resource.RLIMIT_NOFILE, limit)
20+
elif limit_str == "RLIMIT_STACK":
21+
resource.setrlimit(resource.RLIMIT_STACK, limit)
22+
elif limit_str == "RLIMIT_FSIZE":
23+
resource.setrlimit(resource.RLIMIT_FSIZE, limit)
2024
process_output = subprocess.run(command_args)
2125
sys.exit(process_output.returncode)
2226

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
## Tests that readfile works with the env builtin.
2+
# RUN: echo -n "hello" > %t.1
3+
# RUN: env TEST=%{readfile:%t.1} python3 -c "import os; print(os.environ['TEST'])"
4+
5+
## Fail the test so we can assert on the output.
6+
# RUN: not echo return

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22

33
print("RLIMIT_AS=" + str(resource.getrlimit(resource.RLIMIT_AS)[0]))
44
print("RLIMIT_NOFILE=" + str(resource.getrlimit(resource.RLIMIT_NOFILE)[0]))
5+
print("RLIMIT_STACK=" + str(resource.getrlimit(resource.RLIMIT_STACK)[0]))
6+
print("RLIMIT_FSIZE=" + str(resource.getrlimit(resource.RLIMIT_FSIZE)[0]))
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# RUN: ulimit -n 50
2+
# RUN: ulimit -s 256
3+
# RUN: ulimit -f 5
24
# RUN: %{python} %S/print_limits.py
35
# Fail the test so that we can assert on the output.
46
# RUN: not echo return
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-readfile-external.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# UNSUPPORTED: system-windows
77
# RUN: env LIT_USE_INTERNAL_SHELL=0 not %{lit} -a -v %{inputs}/shtest-readfile | FileCheck -match-full-lines -DTEMP_PATH=%S/Inputs/shtest-readfile/Output %s
88

9-
# CHECK: -- Testing: 4 tests{{.*}}
9+
# CHECK: -- Testing: 5 tests{{.*}}
1010

1111
# CHECK-LABEL: FAIL: shtest-readfile :: absolute-paths.txt ({{[^)]*}})
1212
# CHECK: echo $(cat [[TEMP_PATH]]/absolute-paths.txt.tmp) && test -e [[TEMP_PATH]]/absolute-paths.txt.tmp {{.*}}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@
55

66
# RUN: env LIT_USE_INTERNAL_SHELL=1 not %{lit} -a -v %{inputs}/shtest-readfile | FileCheck -match-full-lines -DTEMP_PATH=%S%{fs-sep}Inputs%{fs-sep}shtest-readfile%{fs-sep}Output %s
77

8-
# CHECK: -- Testing: 4 tests{{.*}}
8+
# CHECK: -- Testing: 5 tests{{.*}}
99

1010
# CHECK-LABEL: FAIL: shtest-readfile :: absolute-paths.txt ({{[^)]*}})
1111
# CHECK: echo hello
1212
# CHECK: # executed command: echo '%{readfile:[[TEMP_PATH]]{{[\\\/]}}absolute-paths.txt.tmp}'
1313

14+
# CHECK-LABEL: FAIL: shtest-readfile :: env.txt ({{[^)]*}})
15+
# CHECK: env TEST=hello python3 -c "import os; print(os.environ['TEST'])"
16+
# CHECK: # | hello
17+
1418
# CHECK-LABEL: FAIL: shtest-readfile :: file-does-not-exist.txt ({{[^)]*}})
1519
# CHECK: # executed command: @echo 'echo %{readfile:/file/does/not/exist}'
1620
# CHECK: # | File specified in readfile substitution does not exist: {{.*}}/file/does/not/exist

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,25 @@
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
1818
# CHECK: 'ulimit' requires two arguments
1919

2020
# CHECK-LABEL: FAIL: shtest-ulimit :: ulimit_okay.txt ({{[^)]*}})
2121
# CHECK: ulimit -n 50
22+
# CHECK: ulimit -s 256
23+
# CHECK: ulimit -f 5
2224
# CHECK: RLIMIT_NOFILE=50
25+
# CHECK: RLIMIT_STACK=262144
26+
# CHECK: RLIMIT_FSIZE=5
2327

2428
# CHECK-LABEL: FAIL: shtest-ulimit :: ulimit_reset.txt ({{[^)]*}})
2529
# 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)