Skip to content

Commit 8d35348

Browse files
ndrewhgithub-actions[bot]
authored andcommitted
Automerge: [lit] Add LIT_CURRENT_TESTCASE environment variable when running tests (#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.
2 parents b5da38c + 3f6cbde commit 8d35348

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
@@ -1226,6 +1226,8 @@ def executeScriptInternal(
12261226
results = []
12271227
timeoutInfo = None
12281228
shenv = ShellEnvironment(cwd, test.config.environment)
1229+
shenv.env["LIT_CURRENT_TESTCASE"] = test.getFullName()
1230+
12291231
exitCode, timeoutInfo = executeShCmd(
12301232
cmd, shenv, results, timeout=litConfig.maxIndividualTestTime
12311233
)
@@ -1425,11 +1427,13 @@ def executeScript(test, litConfig, tmpBase, commands, cwd):
14251427
# run on clang with no real loss.
14261428
command = litConfig.valgrindArgs + command
14271429

1430+
env = dict(test.config.environment)
1431+
env["LIT_CURRENT_TESTCASE"] = test.getFullName()
14281432
try:
14291433
out, err, exitCode = lit.util.executeCommand(
14301434
command,
14311435
cwd=cwd,
1432-
env=test.config.environment,
1436+
env=env,
14331437
timeout=litConfig.maxIndividualTestTime,
14341438
)
14351439
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: 10 tests{{.*}}
10+
# CHECK: -- Testing: 11 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-i.txt ({{[^)]*}})
4348
# CHECK: env -i | {{.*}}
4449
# CHECK: # executed command: env -i
@@ -71,6 +76,6 @@
7176
# CHECK-NOT: # error:
7277
# CHECK: --
7378

74-
# CHECK: Total Discovered Tests: 10
75-
# CHECK: Passed: 10 {{\([0-9]*\.[0-9]*%\)}}
79+
# CHECK: Total Discovered Tests: 11
80+
# CHECK: Passed: 11 {{\([0-9]*\.[0-9]*%\)}}
7681
# CHECK-NOT: {{.}}

0 commit comments

Comments
 (0)