From 8bd6226f19ad50d7930b45533b6d2c60cb809f9a Mon Sep 17 00:00:00 2001 From: Tom Stellard Date: Tue, 12 Dec 2023 13:17:30 -0800 Subject: [PATCH 1/3] [llvm] Add support for running tests as root 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. --- .../tools/llvm-ar/error-opening-permission.test | 1 + llvm/test/tools/llvm-dwarfdump/X86/output.s | 1 + llvm/test/tools/llvm-ifs/fail-file-write.test | 1 + .../llvm-ranlib/error-opening-permission.test | 1 + llvm/utils/lit/lit/llvm/config.py | 15 +++++++++++++++ 5 files changed, 19 insertions(+) diff --git a/llvm/test/tools/llvm-ar/error-opening-permission.test b/llvm/test/tools/llvm-ar/error-opening-permission.test index 4107bdfc044fe..b42f95329a3c7 100644 --- a/llvm/test/tools/llvm-ar/error-opening-permission.test +++ b/llvm/test/tools/llvm-ar/error-opening-permission.test @@ -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 diff --git a/llvm/test/tools/llvm-dwarfdump/X86/output.s b/llvm/test/tools/llvm-dwarfdump/X86/output.s index 37132eb55ca55..e7c9234ed74cf 100644 --- a/llvm/test/tools/llvm-dwarfdump/X86/output.s +++ b/llvm/test/tools/llvm-dwarfdump/X86/output.s @@ -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 diff --git a/llvm/test/tools/llvm-ifs/fail-file-write.test b/llvm/test/tools/llvm-ifs/fail-file-write.test index d5232070c1d03..f13500f226205 100644 --- a/llvm/test/tools/llvm-ifs/fail-file-write.test +++ b/llvm/test/tools/llvm-ifs/fail-file-write.test @@ -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 diff --git a/llvm/test/tools/llvm-ranlib/error-opening-permission.test b/llvm/test/tools/llvm-ranlib/error-opening-permission.test index 1b1bb0def78d7..be56962112e6b 100644 --- a/llvm/test/tools/llvm-ranlib/error-opening-permission.test +++ b/llvm/test/tools/llvm-ranlib/error-opening-permission.test @@ -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 diff --git a/llvm/utils/lit/lit/llvm/config.py b/llvm/utils/lit/lit/llvm/config.py index 79094b839e772..d87d0bf92cd9d 100644 --- a/llvm/utils/lit/lit/llvm/config.py +++ b/llvm/utils/lit/lit/llvm/config.py @@ -5,6 +5,7 @@ import subprocess import sys import errno +import getpass import lit.util from lit.llvm.subst import FindTool @@ -12,6 +13,17 @@ lit_path_displayed = False +def user_is_root(): + # getpass.getuser() can throw an exception in some cases: + # See https://github.com/python/cpython/issues/76912 + try: + if getpass.getuser() == 'root': + return True + except: + pass + + return False + class LLVMConfig(object): def __init__(self, lit_config, config): @@ -154,6 +166,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. From e6a1787cc26c565614984d805420a10fdb76e268 Mon Sep 17 00:00:00 2001 From: Tom Stellard Date: Tue, 12 Dec 2023 22:31:45 -0800 Subject: [PATCH 2/3] Fix python formatting --- llvm/utils/lit/lit/llvm/config.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/llvm/utils/lit/lit/llvm/config.py b/llvm/utils/lit/lit/llvm/config.py index d87d0bf92cd9d..742a56a7bc4e9 100644 --- a/llvm/utils/lit/lit/llvm/config.py +++ b/llvm/utils/lit/lit/llvm/config.py @@ -13,11 +13,12 @@ lit_path_displayed = False + def user_is_root(): # getpass.getuser() can throw an exception in some cases: # See https://github.com/python/cpython/issues/76912 try: - if getpass.getuser() == 'root': + if getpass.getuser() == "root": return True except: pass @@ -167,7 +168,7 @@ def __init__(self, lit_config, config): features.add('target=powerpc64le-linux') if not user_is_root(): - features.add('non-root-user') + features.add("non-root-user") use_gmalloc = lit_config.params.get("use_gmalloc", None) if lit.util.pythonize_bool(use_gmalloc): From 5d8526298370da3c6198d5c82f768f968ce21e7e Mon Sep 17 00:00:00 2001 From: Tom Stellard Date: Wed, 3 Jan 2024 22:23:46 -0800 Subject: [PATCH 3/3] lit: use getuid --- llvm/utils/lit/lit/llvm/config.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/llvm/utils/lit/lit/llvm/config.py b/llvm/utils/lit/lit/llvm/config.py index 742a56a7bc4e9..8b0f2e6295ad1 100644 --- a/llvm/utils/lit/lit/llvm/config.py +++ b/llvm/utils/lit/lit/llvm/config.py @@ -5,7 +5,6 @@ import subprocess import sys import errno -import getpass import lit.util from lit.llvm.subst import FindTool @@ -15,10 +14,9 @@ def user_is_root(): - # getpass.getuser() can throw an exception in some cases: - # See https://github.com/python/cpython/issues/76912 + # os.getuid() is not available on all platforms try: - if getpass.getuser() == "root": + if os.getuid() == 0: return True except: pass