[llvm] [lit] Add LIT_CURRENT_TESTCASE environment variable when running tests (PR #168762)
Andrew Haberlandt via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 19 11:21:15 PST 2025
https://github.com/ndrewh created https://github.com/llvm/llvm-project/pull/168762
I'm not aware of any way for `%run` wrapper scripts like `iosssim_run.py` ([ref](https://github.com/llvm/llvm-project/blob/d2c7c6064259320def7a74e111079725958697d4/compiler-rt/test/sanitizer_common/ios_commands/iossim_run.py#L4)) to know what testcase they are currently running. This can be useful if these wrappers need to create a (potentially remote) temporary directory for each test case.
This adds the `LIT_CURRENT_TESTCASE` environment variable to both the internal shell and the external shell, containing the full name of the current test being run.
>From 271130cc0a9dd1a4d3dfa2c1463c0e77c607c3c2 Mon Sep 17 00:00:00 2001
From: Andrew Haberlandt <ahaberlandt at apple.com>
Date: Wed, 19 Nov 2025 11:12:06 -0800
Subject: [PATCH] [lit] Add LIT_CURRENT_TESTCASE environment variable when
running tests
---
llvm/utils/lit/lit/TestRunner.py | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/llvm/utils/lit/lit/TestRunner.py b/llvm/utils/lit/lit/TestRunner.py
index 64148c6098327..9525320f133c6 100644
--- a/llvm/utils/lit/lit/TestRunner.py
+++ b/llvm/utils/lit/lit/TestRunner.py
@@ -1226,6 +1226,8 @@ def executeScriptInternal(
results = []
timeoutInfo = None
shenv = ShellEnvironment(cwd, test.config.environment)
+ shenv.env["LIT_CURRENT_TESTCASE"] = test.getFullName()
+
exitCode, timeoutInfo = executeShCmd(
cmd, shenv, results, timeout=litConfig.maxIndividualTestTime
)
@@ -1425,11 +1427,13 @@ def executeScript(test, litConfig, tmpBase, commands, cwd):
# run on clang with no real loss.
command = litConfig.valgrindArgs + command
+ env = dict(test.config.environment)
+ env["LIT_CURRENT_TESTCASE"] = test.getFullName()
try:
out, err, exitCode = lit.util.executeCommand(
command,
cwd=cwd,
- env=test.config.environment,
+ env=env,
timeout=litConfig.maxIndividualTestTime,
)
return (out, err, exitCode, None)
More information about the llvm-commits
mailing list