Skip to content

Commit

Permalink
[llvm] Add support for running tests as root (#75285)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tstellar authored Jan 4, 2024
1 parent 0b45c77 commit 0521654
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions llvm/test/tools/llvm-ar/error-opening-permission.test
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Unsupported on windows as marking files "unreadable"
## is non-trivial on windows.
# UNSUPPORTED: system-windows
# REQUIRES: non-root-user

# RUN: rm -rf %t && mkdir -p %t
# RUN: echo file1 > %t/1.txt
Expand Down
1 change: 1 addition & 0 deletions llvm/test/tools/llvm-dwarfdump/X86/output.s
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# REQUIRES: non-root-user
# RUN: rm -f %t1.txt %t2.txt %t3.txt
# RUN: llvm-mc %S/brief.s -filetype obj -triple x86_64-apple-darwin -o %t.o

Expand Down
1 change: 1 addition & 0 deletions llvm/test/tools/llvm-ifs/fail-file-write.test
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Test failing to write output file on non-windows platforms.

# UNSUPPORTED: system-windows
# REQUIRES: non-root-user
# RUN: rm -rf %t.TestDir
# RUN: mkdir %t.TestDir
# RUN: touch %t.TestDir/Output.TestFile
Expand Down
1 change: 1 addition & 0 deletions llvm/test/tools/llvm-ranlib/error-opening-permission.test
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## Unsupported on windows as marking files "unreadable" is non-trivial on windows.
# UNSUPPORTED: system-windows
# REQUIRES: non-root-user

# RUN: rm -rf %t && split-file %s %t && cd %t
# RUN: yaml2obj 1.yaml -o 1.o
Expand Down
14 changes: 14 additions & 0 deletions llvm/utils/lit/lit/llvm/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@
lit_path_displayed = False


def user_is_root():
# os.getuid() is not available on all platforms
try:
if os.getuid() == 0:
return True
except:
pass

return False


class LLVMConfig(object):
def __init__(self, lit_config, config):
self.lit_config = lit_config
Expand Down Expand Up @@ -154,6 +165,9 @@ def __init__(self, lit_config, config):
if re.match(r'^ppc64le.*-linux', target_triple):
features.add('target=powerpc64le-linux')

if not user_is_root():
features.add("non-root-user")

use_gmalloc = lit_config.params.get("use_gmalloc", None)
if lit.util.pythonize_bool(use_gmalloc):
# Allow use of an explicit path for gmalloc library.
Expand Down

0 comments on commit 0521654

Please sign in to comment.