Skip to content

Commit 5f5da46

Browse files
committed
[lit] Add LIT_CURRENT_TESTCASE environment variable when running tests (llvm#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. (cherry picked from commit 3f6cbde)
1 parent 301e2d3 commit 5f5da46

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

llvm/utils/lit/lit/TestRunner.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1124,6 +1124,8 @@ def executeScriptInternal(
11241124
results = []
11251125
timeoutInfo = None
11261126
shenv = ShellEnvironment(cwd, test.config.environment)
1127+
shenv.env["LIT_CURRENT_TESTCASE"] = test.getFullName()
1128+
11271129
exitCode, timeoutInfo = executeShCmd(
11281130
cmd, shenv, results, timeout=litConfig.maxIndividualTestTime
11291131
)
@@ -1323,11 +1325,13 @@ def executeScript(test, litConfig, tmpBase, commands, cwd):
13231325
# run on clang with no real loss.
13241326
command = litConfig.valgrindArgs + command
13251327

1328+
env = dict(test.config.environment)
1329+
env["LIT_CURRENT_TESTCASE"] = test.getFullName()
13261330
try:
13271331
out, err, exitCode = lit.util.executeCommand(
13281332
command,
13291333
cwd=cwd,
1330-
env=test.config.environment,
1334+
env=env,
13311335
timeout=litConfig.maxIndividualTestTime,
13321336
)
13331337
return (out, err, exitCode, None)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
## Tests that the LIT_CURRENT_TESTCASE variable is set to the name of the currently executing testcase
2+
3+
## Check default environment.
4+
# RUN: bash -c 'echo $LIT_CURRENT_TESTCASE' | FileCheck --match-full-lines %s
5+
#
6+
# CHECK: shtest-env :: env-current-testcase.txt

llvm/utils/lit/tests/Inputs/shtest-env-positive/env-no-subcommand.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
## Tests the env command in various scenarios: without arguments, setting, unsetting, and mixing envrionment variables.
2+
# FIXME: All of these tests are broken and will not even call FileCheck.
23

34
## Check default environment.
45
# RUN: env | FileCheck -check-prefix=NO-ARGS %s

llvm/utils/lit/tests/shtest-env-positive.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
## Test the env command's successful executions.
99

10-
# CHECK: -- Testing: 9 tests{{.*}}
10+
# CHECK: -- Testing: 10 tests{{.*}}
1111

1212
# CHECK: PASS: shtest-env :: env-args-last-is-assign.txt ({{[^)]*}})
1313
# CHECK: env FOO=1
@@ -39,6 +39,11 @@
3939
# CHECK-NOT: # error:
4040
# CHECK: --
4141

42+
# CHECK: PASS: shtest-env :: env-current-testcase.txt ({{[^)]*}})
43+
# CHECK: # executed command: bash -c 'echo $LIT_CURRENT_TESTCASE'
44+
# CHECK-NOT: # error:
45+
# CHECK: --
46+
4247
# CHECK: PASS: shtest-env :: env-no-subcommand.txt ({{[^)]*}})
4348
# CHECK: env | {{.*}}
4449
# CHECK: # executed command: env
@@ -65,6 +70,6 @@
6570
# CHECK-NOT: # error:
6671
# CHECK: --
6772

68-
# CHECK: Total Discovered Tests: 9
69-
# CHECK: Passed: 9 {{\([0-9]*\.[0-9]*%\)}}
73+
# CHECK: Total Discovered Tests: 10
74+
# CHECK: Passed: 10 {{\([0-9]*\.[0-9]*%\)}}
7075
# CHECK-NOT: {{.}}

0 commit comments

Comments
 (0)