[libc-commits] [libc] [libc] Improve lit test discovery and execution (PR #192993)
Jeff Bailey via libc-commits
libc-commits at lists.llvm.org
Mon Apr 20 07:55:52 PDT 2026
https://github.com/kaladron created https://github.com/llvm/llvm-project/pull/192993
Updated LibcTest to support cross-compilation and custom test directories:
* Passed localConfig to _isTestExecutable to check for emulator.
* Skipped host execution permission check if emulator is set.
* Supported tests in libc.test.shared and libc.test.utils.
* Handled fallback if @BINARY@ is missing in test command template.
* Removed UnitTest from excludes in lit site config.
>From 600fbcbacd5e60050b3f1eadde1dd50e3a7d4b0a Mon Sep 17 00:00:00 2001
From: Jeff Bailey <jbailey at raspberryginger.com>
Date: Mon, 20 Apr 2026 15:55:00 +0100
Subject: [PATCH] [libc] Improve lit test discovery and execution
Updated LibcTest to support cross-compilation and custom test directories:
* Passed localConfig to _isTestExecutable to check for emulator.
* Skipped host execution permission check if emulator is set.
* Supported tests in libc.test.shared and libc.test.utils.
* Handled fallback if @BINARY@ is missing in test command template.
* Removed UnitTest from excludes in lit site config.
---
libc/test/lit.site.cfg.py.in | 4 ++--
libc/utils/libctest/format.py | 17 +++++++++++++----
2 files changed, 15 insertions(+), 6 deletions(-)
diff --git a/libc/test/lit.site.cfg.py.in b/libc/test/lit.site.cfg.py.in
index 7727f16956d73..3668a491cd05c 100644
--- a/libc/test/lit.site.cfg.py.in
+++ b/libc/test/lit.site.cfg.py.in
@@ -12,7 +12,7 @@ config.libc_crosscompiling_emulator = path(r"@CMAKE_CROSSCOMPILING_EMULATOR@")
# If no explicit test command is set, use the cross-compiling emulator.
if not config.libc_test_cmd and config.libc_crosscompiling_emulator:
- config.libc_test_cmd = config.libc_crosscompiling_emulator + " @BINARY@"
+ config.libc_test_cmd = config.libc_crosscompiling_emulator
# Add libc's utils directory to the path so we can import the test format.
site.addsitedir(os.path.join(config.libc_src_root, "utils"))
@@ -26,7 +26,7 @@ config.name = "libc"
config.test_format = libctest.LibcTest()
# excludes: A list of directories to exclude from the testsuite.
-config.excludes = ["Inputs", "CMakeLists.txt", "README.txt", "LICENSE.txt", "UnitTest"]
+config.excludes = ["Inputs", "CMakeLists.txt", "README.txt", "LICENSE.txt"]
# test_source_root: The root path where tests are located.
# test_exec_root: The root path where test executables are built.
diff --git a/libc/utils/libctest/format.py b/libc/utils/libctest/format.py
index c8280fd1b5561..4e00d997480f7 100644
--- a/libc/utils/libctest/format.py
+++ b/libc/utils/libctest/format.py
@@ -60,11 +60,11 @@ def getTestsInDirectory(self, testSuite, path_in_suite, litConfig, localConfig):
filepath = os.path.join(source_path, filename)
# Match our test executable pattern
- if self._isTestExecutable(filename, filepath):
+ if self._isTestExecutable(filename, filepath, localConfig):
# Create a test with the executable name
yield lit.Test.Test(testSuite, path_in_suite + (filename,), localConfig)
- def _isTestExecutable(self, filename, filepath):
+ def _isTestExecutable(self, filename, filepath, localConfig):
"""
Check if a file is a libc test executable we should run.
@@ -90,11 +90,16 @@ def _isTestExecutable(self, filename, filepath):
return False
elif test_name.startswith("libc.test.integration."):
pass # Accept all integration tests ending in .__build__
+ elif test_name.startswith("libc.test.shared."):
+ pass # Accept all shared tests ending in .__build__
+ elif test_name.startswith("libc.test.utils."):
+ pass # Accept all utils tests ending in .__build__
else:
return False
if not os.path.isfile(filepath):
return False
- if not kIsWindows and not os.access(filepath, os.X_OK):
+ # GPU binaries are not host-executable but run via an emulator, so ignore X_OK if emulator is set.
+ if not kIsWindows and not os.access(filepath, os.X_OK) and not getattr(localConfig, 'libc_crosscompiling_emulator', None):
return False
return True
@@ -150,7 +155,11 @@ def execute(self, test, litConfig):
test_cmd_template = getattr(test.config, "libc_test_cmd", "")
if test_cmd_template:
- test_cmd = test_cmd_template.replace("@BINARY@", test_path)
+ # Fallback to appending the binary path if @BINARY@ placeholder is missing.
+ if "@BINARY@" in test_cmd_template:
+ test_cmd = test_cmd_template.replace("@BINARY@", test_path)
+ else:
+ test_cmd = test_cmd_template + " " + test_path
cmd_args = shlex.split(test_cmd)
if not cmd_args:
cmd_args = [test_path]
More information about the libc-commits
mailing list