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) diff --git a/llvm/utils/lit/tests/Inputs/shtest-env-positive/env-current-testcase.txt b/llvm/utils/lit/tests/Inputs/shtest-env-positive/env-current-testcase.txt new file mode 100644 index 0000000000000..37c36814ccbbb --- /dev/null +++ b/llvm/utils/lit/tests/Inputs/shtest-env-positive/env-current-testcase.txt @@ -0,0 +1,6 @@ +## Tests that the LIT_CURRENT_TESTCASE variable is set to the name of the currently executing testcase + +## Check default environment. +# RUN: bash -c 'echo $LIT_CURRENT_TESTCASE' | FileCheck --match-full-lines %s +# +# CHECK: shtest-env :: env-current-testcase.txt diff --git a/llvm/utils/lit/tests/Inputs/shtest-env-positive/env-no-subcommand.txt b/llvm/utils/lit/tests/Inputs/shtest-env-positive/env-no-subcommand.txt index 761a8061a0b0d..dded9069c44f2 100644 --- a/llvm/utils/lit/tests/Inputs/shtest-env-positive/env-no-subcommand.txt +++ b/llvm/utils/lit/tests/Inputs/shtest-env-positive/env-no-subcommand.txt @@ -1,4 +1,5 @@ ## Tests the env command in various scenarios: without arguments, setting, unsetting, and mixing envrionment variables. +# FIXME: All of these tests are broken and will not even call FileCheck. ## Check default environment. # RUN: env | FileCheck -check-prefix=NO-ARGS %s diff --git a/llvm/utils/lit/tests/shtest-env-positive.py b/llvm/utils/lit/tests/shtest-env-positive.py index 089acd308c5c5..62e15dd9ad492 100644 --- a/llvm/utils/lit/tests/shtest-env-positive.py +++ b/llvm/utils/lit/tests/shtest-env-positive.py @@ -7,7 +7,7 @@ ## Test the env command's successful executions. -# CHECK: -- Testing: 10 tests{{.*}} +# CHECK: -- Testing: 11 tests{{.*}} # CHECK: PASS: shtest-env :: env-args-last-is-assign.txt ({{[^)]*}}) # CHECK: env FOO=1 @@ -39,6 +39,11 @@ # CHECK-NOT: # error: # CHECK: -- +# CHECK: PASS: shtest-env :: env-current-testcase.txt ({{[^)]*}}) +# CHECK: # executed command: bash -c 'echo $LIT_CURRENT_TESTCASE' +# CHECK-NOT: # error: +# CHECK: -- + # CHECK: PASS: shtest-env :: env-i.txt ({{[^)]*}}) # CHECK: env -i | {{.*}} # CHECK: # executed command: env -i @@ -71,6 +76,6 @@ # CHECK-NOT: # error: # CHECK: -- -# CHECK: Total Discovered Tests: 10 -# CHECK: Passed: 10 {{\([0-9]*\.[0-9]*%\)}} +# CHECK: Total Discovered Tests: 11 +# CHECK: Passed: 11 {{\([0-9]*\.[0-9]*%\)}} # CHECK-NOT: {{.}}