Skip to content

Commit 0521654

Browse files
authored
[llvm] Add support for running tests as root (#75285)
There are a few test that check access permissions, so they need to be disabled when running the tests as root. The most common use case for running tests as root is inside of a container. GitHub Actions, for example, only supports running the root user inside of containers, so this change is necessary in order to run the tests inside of a container running in the GitHub Actions environment.
1 parent 0b45c77 commit 0521654

File tree

5 files changed

+18
-0
lines changed

5 files changed

+18
-0
lines changed

llvm/test/tools/llvm-ar/error-opening-permission.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## Unsupported on windows as marking files "unreadable"
22
## is non-trivial on windows.
33
# UNSUPPORTED: system-windows
4+
# REQUIRES: non-root-user
45

56
# RUN: rm -rf %t && mkdir -p %t
67
# RUN: echo file1 > %t/1.txt

llvm/test/tools/llvm-dwarfdump/X86/output.s

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# REQUIRES: non-root-user
12
# RUN: rm -f %t1.txt %t2.txt %t3.txt
23
# RUN: llvm-mc %S/brief.s -filetype obj -triple x86_64-apple-darwin -o %t.o
34

llvm/test/tools/llvm-ifs/fail-file-write.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## Test failing to write output file on non-windows platforms.
22

33
# UNSUPPORTED: system-windows
4+
# REQUIRES: non-root-user
45
# RUN: rm -rf %t.TestDir
56
# RUN: mkdir %t.TestDir
67
# RUN: touch %t.TestDir/Output.TestFile

llvm/test/tools/llvm-ranlib/error-opening-permission.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## Unsupported on windows as marking files "unreadable" is non-trivial on windows.
22
# UNSUPPORTED: system-windows
3+
# REQUIRES: non-root-user
34

45
# RUN: rm -rf %t && split-file %s %t && cd %t
56
# RUN: yaml2obj 1.yaml -o 1.o

llvm/utils/lit/lit/llvm/config.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@
1313
lit_path_displayed = False
1414

1515

16+
def user_is_root():
17+
# os.getuid() is not available on all platforms
18+
try:
19+
if os.getuid() == 0:
20+
return True
21+
except:
22+
pass
23+
24+
return False
25+
26+
1627
class LLVMConfig(object):
1728
def __init__(self, lit_config, config):
1829
self.lit_config = lit_config
@@ -154,6 +165,9 @@ def __init__(self, lit_config, config):
154165
if re.match(r'^ppc64le.*-linux', target_triple):
155166
features.add('target=powerpc64le-linux')
156167

168+
if not user_is_root():
169+
features.add("non-root-user")
170+
157171
use_gmalloc = lit_config.params.get("use_gmalloc", None)
158172
if lit.util.pythonize_bool(use_gmalloc):
159173
# Allow use of an explicit path for gmalloc library.

0 commit comments

Comments
 (0)