Skip to content

Commit 93dd17a

Browse files
[lit] Ensure ulimit does not persist across tests (#164485)
When constructing a container in a default argument in Python, we actually end up with a reference to the same default container for every invocation of the function. Given this happened with the ulimit variable in ShellEnvironment, we ended up persisting limits across tests. This would cause some LLVM tests to fail, particularly jitlink and dsymutil tests, if they ended up running after the one clang test that uses ulimit -v to set a maximum amount of memory that can be allocated. This patch fixes that behavior by constructing the dict inside the function to ensure we get a new instance and adds test coverage.
1 parent fde69fd commit 93dd17a

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

llvm/utils/lit/lit/TestRunner.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,12 @@ class ShellEnvironment(object):
9292
we maintain a dir stack for pushd/popd.
9393
"""
9494

95-
def __init__(self, cwd, env, umask=-1, ulimit={}):
95+
def __init__(self, cwd, env, umask=-1, ulimit=None):
9696
self.cwd = cwd
9797
self.env = dict(env)
9898
self.umask = umask
9999
self.dirStack = []
100-
self.ulimit = ulimit
100+
self.ulimit = ulimit if ulimit else {}
101101

102102
def change_dir(self, newdir):
103103
if os.path.isabs(newdir):
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# RUN: %{python} %S/print_limits.py
2+
# Fail the test so that we can assert on the output.
3+
# RUN: not echo return

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
# as well.
66
# UNSUPPORTED: system-windows, system-solaris
77

8-
# RUN: not %{lit} -a -v %{inputs}/shtest-ulimit | FileCheck %s
8+
# RUN: not %{lit} -a -v %{inputs}/shtest-ulimit --order=lexical | FileCheck %s
99

10-
# CHECK: -- Testing: 2 tests{{.*}}
10+
# CHECK: -- Testing: 3 tests{{.*}}
1111

1212
# CHECK-LABEL: FAIL: shtest-ulimit :: ulimit-bad-arg.txt ({{[^)]*}})
1313
# CHECK: ulimit -n
@@ -16,3 +16,6 @@
1616
# CHECK-LABEL: FAIL: shtest-ulimit :: ulimit_okay.txt ({{[^)]*}})
1717
# CHECK: ulimit -n 50
1818
# CHECK: RLIMIT_NOFILE=50
19+
20+
# CHECK-LABEL: FAIL: shtest-ulimit :: ulimit_reset.txt ({{[^)]*}})
21+
# CHECK-NOT: RLIMIT_NOFILE=50

0 commit comments

Comments
 (0)