[llvm] [lit] Add LIT_CURRENT_TESTCASE environment variable when running tests (PR #168762)

via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 19 11:21:50 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-testing-tools

Author: Andrew Haberlandt (ndrewh)

<details>
<summary>Changes</summary>

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/168762.diff


1 Files Affected:

- (modified) llvm/utils/lit/lit/TestRunner.py (+5-1) 


``````````diff
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)

``````````

</details>


https://github.com/llvm/llvm-project/pull/168762


More information about the llvm-commits mailing list