aboutsummaryrefslogtreecommitdiff
path: root/llvm/utils/lit
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/utils/lit')
-rw-r--r--llvm/utils/lit/lit/TestRunner.py28
-rw-r--r--llvm/utils/lit/lit/builtin_commands/_launch_with_limit.py4
-rw-r--r--llvm/utils/lit/tests/Inputs/shtest-readfile/env.txt6
-rw-r--r--llvm/utils/lit/tests/Inputs/shtest-readfile/lit.cfg1
-rw-r--r--llvm/utils/lit/tests/Inputs/shtest-ulimit-nondarwin/ulimit_okay.txt1
-rw-r--r--llvm/utils/lit/tests/Inputs/shtest-ulimit-nondarwin/ulimit_unlimited.txt6
-rw-r--r--llvm/utils/lit/tests/Inputs/shtest-ulimit/print_limits.py2
-rw-r--r--llvm/utils/lit/tests/Inputs/shtest-ulimit/ulimit_okay.txt1
-rw-r--r--llvm/utils/lit/tests/shtest-readfile-external.py2
-rw-r--r--llvm/utils/lit/tests/shtest-readfile.py6
-rw-r--r--llvm/utils/lit/tests/shtest-ulimit-nondarwin.py12
-rw-r--r--llvm/utils/lit/tests/shtest-ulimit.py2
12 files changed, 61 insertions, 10 deletions
diff --git a/llvm/utils/lit/lit/TestRunner.py b/llvm/utils/lit/lit/TestRunner.py
index 9fba96a..3176b1a 100644
--- a/llvm/utils/lit/lit/TestRunner.py
+++ b/llvm/utils/lit/lit/TestRunner.py
@@ -600,18 +600,33 @@ def executeBuiltinUmask(cmd, shenv):
def executeBuiltinUlimit(cmd, shenv):
"""executeBuiltinUlimit - Change the current limits."""
- if os.name != "posix":
+ try:
+ # Try importing the resource module (available on POSIX systems) and
+ # emit an error where it does not exist (e.g., Windows).
+ import resource
+ except ImportError:
raise InternalShellError(cmd, "'ulimit' not supported on this system")
if len(cmd.args) != 3:
raise InternalShellError(cmd, "'ulimit' requires two arguments")
try:
- new_limit = int(cmd.args[2])
+ if cmd.args[2] == "unlimited":
+ new_limit = resource.RLIM_INFINITY
+ else:
+ new_limit = int(cmd.args[2])
except ValueError as err:
raise InternalShellError(cmd, "Error: 'ulimit': %s" % str(err))
if cmd.args[1] == "-v":
- shenv.ulimit["RLIMIT_AS"] = new_limit * 1024
+ if new_limit != resource.RLIM_INFINITY:
+ new_limit = new_limit * 1024
+ shenv.ulimit["RLIMIT_AS"] = new_limit
elif cmd.args[1] == "-n":
shenv.ulimit["RLIMIT_NOFILE"] = new_limit
+ elif cmd.args[1] == "-s":
+ if new_limit != resource.RLIM_INFINITY:
+ new_limit = new_limit * 1024
+ shenv.ulimit["RLIMIT_STACK"] = new_limit
+ elif cmd.args[1] == "-f":
+ shenv.ulimit["RLIMIT_FSIZE"] = new_limit
else:
raise InternalShellError(
cmd, "'ulimit' does not support option: %s" % cmd.args[1]
@@ -811,6 +826,10 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
not_args = []
not_count = 0
not_crash = False
+
+ # Expand all late substitutions.
+ args = _expandLateSubstitutions(j, args, cmd_shenv.cwd)
+
while True:
if args[0] == "env":
# Create a copy of the global environment and modify it for
@@ -860,9 +879,6 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
# Ensure args[0] is hashable.
args[0] = expand_glob(args[0], cmd_shenv.cwd)[0]
- # Expand all late substitutions.
- args = _expandLateSubstitutions(j, args, cmd_shenv.cwd)
-
inproc_builtin = inproc_builtins.get(args[0], None)
if inproc_builtin and (args[0] != "echo" or len(cmd.commands) == 1):
# env calling an in-process builtin is useless, so we take the safe
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 33d2d59..a9dc259 100644
--- a/llvm/utils/lit/lit/builtin_commands/_launch_with_limit.py
+++ b/llvm/utils/lit/lit/builtin_commands/_launch_with_limit.py
@@ -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)
diff --git a/llvm/utils/lit/tests/Inputs/shtest-readfile/env.txt b/llvm/utils/lit/tests/Inputs/shtest-readfile/env.txt
new file mode 100644
index 0000000..3e19373
--- /dev/null
+++ b/llvm/utils/lit/tests/Inputs/shtest-readfile/env.txt
@@ -0,0 +1,6 @@
+## Tests that readfile works with the env builtin.
+# RUN: echo -n "hello" > %t.1
+# RUN: env TEST=%{readfile:%t.1} %{python} -c "import os; print(os.environ['TEST'])"
+
+## Fail the test so we can assert on the output.
+# RUN: not echo return \ No newline at end of file
diff --git a/llvm/utils/lit/tests/Inputs/shtest-readfile/lit.cfg b/llvm/utils/lit/tests/Inputs/shtest-readfile/lit.cfg
index ee49667..80af27f 100644
--- a/llvm/utils/lit/tests/Inputs/shtest-readfile/lit.cfg
+++ b/llvm/utils/lit/tests/Inputs/shtest-readfile/lit.cfg
@@ -10,6 +10,7 @@ use_lit_shell = lit.util.pythonize_bool(lit_shell_env)
config.test_format = lit.formats.ShTest(execute_external=not use_lit_shell)
config.test_source_root = None
config.test_exec_root = None
+config.substitutions.append(("%{python}", '"%s"' % (sys.executable)))
# If we are testing with the external shell, remove the fake-externals from
# PATH so that we use mkdir in the tests.
diff --git a/llvm/utils/lit/tests/Inputs/shtest-ulimit-nondarwin/ulimit_okay.txt b/llvm/utils/lit/tests/Inputs/shtest-ulimit-nondarwin/ulimit_okay.txt
index dbdd003..a5fac7b 100644
--- a/llvm/utils/lit/tests/Inputs/shtest-ulimit-nondarwin/ulimit_okay.txt
+++ b/llvm/utils/lit/tests/Inputs/shtest-ulimit-nondarwin/ulimit_okay.txt
@@ -1,4 +1,5 @@
# RUN: ulimit -v 1048576
+# RUN: ulimit -s 256
# RUN: %{python} %S/../shtest-ulimit/print_limits.py
# Fail the test so that we can assert on the output.
# RUN: not echo return
diff --git a/llvm/utils/lit/tests/Inputs/shtest-ulimit-nondarwin/ulimit_unlimited.txt b/llvm/utils/lit/tests/Inputs/shtest-ulimit-nondarwin/ulimit_unlimited.txt
new file mode 100644
index 0000000..4c687e3
--- /dev/null
+++ b/llvm/utils/lit/tests/Inputs/shtest-ulimit-nondarwin/ulimit_unlimited.txt
@@ -0,0 +1,6 @@
+# RUN: ulimit -f 5
+# RUN: %{python} %S/../shtest-ulimit/print_limits.py
+# RUN: ulimit -f unlimited
+# RUN: %{python} %S/../shtest-ulimit/print_limits.py
+# Fail the test so that we can assert on the output.
+# RUN: not echo return
diff --git a/llvm/utils/lit/tests/Inputs/shtest-ulimit/print_limits.py b/llvm/utils/lit/tests/Inputs/shtest-ulimit/print_limits.py
index 632f954..c732c04 100644
--- a/llvm/utils/lit/tests/Inputs/shtest-ulimit/print_limits.py
+++ b/llvm/utils/lit/tests/Inputs/shtest-ulimit/print_limits.py
@@ -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]))
diff --git a/llvm/utils/lit/tests/Inputs/shtest-ulimit/ulimit_okay.txt b/llvm/utils/lit/tests/Inputs/shtest-ulimit/ulimit_okay.txt
index 4edf1c3..b1f2396b 100644
--- a/llvm/utils/lit/tests/Inputs/shtest-ulimit/ulimit_okay.txt
+++ b/llvm/utils/lit/tests/Inputs/shtest-ulimit/ulimit_okay.txt
@@ -1,4 +1,5 @@
# RUN: ulimit -n 50
+# 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
diff --git a/llvm/utils/lit/tests/shtest-readfile-external.py b/llvm/utils/lit/tests/shtest-readfile-external.py
index c00bff4..6fe1088 100644
--- a/llvm/utils/lit/tests/shtest-readfile-external.py
+++ b/llvm/utils/lit/tests/shtest-readfile-external.py
@@ -6,7 +6,7 @@
# UNSUPPORTED: system-windows
# 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
-# CHECK: -- Testing: 4 tests{{.*}}
+# CHECK: -- Testing: 5 tests{{.*}}
# CHECK-LABEL: FAIL: shtest-readfile :: absolute-paths.txt ({{[^)]*}})
# CHECK: echo $(cat [[TEMP_PATH]]/absolute-paths.txt.tmp) && test -e [[TEMP_PATH]]/absolute-paths.txt.tmp {{.*}}
diff --git a/llvm/utils/lit/tests/shtest-readfile.py b/llvm/utils/lit/tests/shtest-readfile.py
index 66e3a04..218da22 100644
--- a/llvm/utils/lit/tests/shtest-readfile.py
+++ b/llvm/utils/lit/tests/shtest-readfile.py
@@ -5,12 +5,16 @@
# 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
-# CHECK: -- Testing: 4 tests{{.*}}
+# CHECK: -- Testing: 5 tests{{.*}}
# CHECK-LABEL: FAIL: shtest-readfile :: absolute-paths.txt ({{[^)]*}})
# CHECK: echo hello
# CHECK: # executed command: echo '%{readfile:[[TEMP_PATH]]{{[\\\/]}}absolute-paths.txt.tmp}'
+# CHECK-LABEL: FAIL: shtest-readfile :: env.txt ({{[^)]*}})
+# CHECK: env TEST=hello {{.*}} -c "import os; print(os.environ['TEST'])"
+# CHECK: # | hello
+
# CHECK-LABEL: FAIL: shtest-readfile :: file-does-not-exist.txt ({{[^)]*}})
# CHECK: # executed command: @echo 'echo %{readfile:/file/does/not/exist}'
# CHECK: # | File specified in readfile substitution does not exist: {{.*}}/file/does/not/exist
diff --git a/llvm/utils/lit/tests/shtest-ulimit-nondarwin.py b/llvm/utils/lit/tests/shtest-ulimit-nondarwin.py
index 2d96fea..286fd3d 100644
--- a/llvm/utils/lit/tests/shtest-ulimit-nondarwin.py
+++ b/llvm/utils/lit/tests/shtest-ulimit-nondarwin.py
@@ -2,12 +2,20 @@
# ulimit does not work on non-POSIX platforms.
# These tests are specific to options that Darwin does not support.
-# UNSUPPORTED: system-windows, system-darwin, system-aix
+# UNSUPPORTED: system-windows, system-darwin, system-aix, system-solaris
# RUN: not %{lit} -a -v %{inputs}/shtest-ulimit-nondarwin | FileCheck %s
-# CHECK: -- Testing: 1 tests{{.*}}
+# CHECK: -- Testing: 2 tests{{.*}}
# CHECK-LABEL: FAIL: shtest-ulimit :: ulimit_okay.txt ({{[^)]*}})
# CHECK: ulimit -v 1048576
+# CHECK: ulimit -s 256
# CHECK: RLIMIT_AS=1073741824
+# CHECK: RLIMIT_STACK=262144
+
+# CHECK-LABEL: FAIL: shtest-ulimit :: ulimit_unlimited.txt ({{[^)]*}})
+# CHECK: ulimit -f 5
+# CHECK: RLIMIT_FSIZE=5
+# CHECK: ulimit -f unlimited
+# CHECK: RLIMIT_FSIZE=-1
diff --git a/llvm/utils/lit/tests/shtest-ulimit.py b/llvm/utils/lit/tests/shtest-ulimit.py
index 09cd475..21e5a5e 100644
--- a/llvm/utils/lit/tests/shtest-ulimit.py
+++ b/llvm/utils/lit/tests/shtest-ulimit.py
@@ -19,7 +19,9 @@
# CHECK-LABEL: FAIL: shtest-ulimit :: ulimit_okay.txt ({{[^)]*}})
# CHECK: ulimit -n 50
+# CHECK: ulimit -f 5
# CHECK: RLIMIT_NOFILE=50
+# CHECK: RLIMIT_FSIZE=5
# CHECK-LABEL: FAIL: shtest-ulimit :: ulimit_reset.txt ({{[^)]*}})
# CHECK: RLIMIT_NOFILE=[[BASE_NOFILE_LIMIT]]