diff --git a/compiler-rt/test/fuzzer/merge-posix.test b/compiler-rt/test/fuzzer/merge-posix.test index 2721668fb9706..6e37651e6fd29 100644 --- a/compiler-rt/test/fuzzer/merge-posix.test +++ b/compiler-rt/test/fuzzer/merge-posix.test @@ -14,10 +14,10 @@ RUN: echo ....U. > %tmp/T2/2 RUN: echo ...Z.. > %tmp/T2/3 RUN: echo ...Z.. > %tmp/T2/4 RUN: echo ....E. > %tmp/T2/5 -RUN: echo .....R > %tmp/T2/6 +RUN: %python -c "print('.....R' + 'X' * 4096, end='')" > %tmp/T2/6 # Check that we can report an error if file size exceeded -RUN: (ulimit -f 1; not %run %t-FullCoverageSetTest -merge=1 %tmp/T1 %tmp/T2 2>&1 | FileCheck %s --check-prefix=SIGXFSZ) +RUN: (ulimit -f 4; not %run %t-FullCoverageSetTest -merge=1 %tmp/T1 %tmp/T2 2>&1 | FileCheck %s --check-prefix=SIGXFSZ) SIGXFSZ: ERROR: libFuzzer: file size exceeded # Check that we honor TMPDIR diff --git a/compiler-rt/test/sanitizer_common/TestCases/Posix/posix_spawn.c b/compiler-rt/test/sanitizer_common/TestCases/Posix/posix_spawn.c index ea58b92af6097..1a66a6166dd1d 100644 --- a/compiler-rt/test/sanitizer_common/TestCases/Posix/posix_spawn.c +++ b/compiler-rt/test/sanitizer_common/TestCases/Posix/posix_spawn.c @@ -6,8 +6,12 @@ #include #include #include +#include +#include #include +extern char **environ; + int main(int argc, char **argv) { if (argc > 1) { // CHECK: SPAWNED @@ -23,11 +27,22 @@ int main(int argc, char **argv) { argv[0], "2", "3", "4", "2", "3", "4", "2", "3", "4", "2", "3", "4", "2", "3", "4", "2", "3", "4", NULL, }; - char *const env[] = { + char *env[] = { "A=B", "A=B", "A=B", "A=B", "A=B", "A=B", "A=B", "A=B", "A=B", "A=B", "A=B", "A=B", "A=B", "A=B", "A=B", "A=B", "A=B", "A=B", "A=B", NULL, }; + // When this test runs with a runtime (e.g. ASAN), the spawned process needs + // to use the same runtime search path as the parent. Otherwise, it might + // try to load a runtime that doesn't work and crash before hitting main(), + // failing the test. We technically should forward the variable for the + // current platform, but some platforms have multiple such variables and + // it's quite difficult to plumb this through the lit config. + for (char **e = environ; *e; e++) + if (strncmp(*e, "DYLD_LIBRARY_PATH=", sizeof("DYLD_LIBRARY_PATH=") - 1) == + 0) + env[0] = *e; + pid_t pid; int s = posix_spawn(&pid, argv[0], &file_actions, &attr, args, env); assert(!s); diff --git a/llvm/utils/lit/lit/TestRunner.py b/llvm/utils/lit/lit/TestRunner.py index 4ca98f013fe7a..cc8715563ea27 100644 --- a/llvm/utils/lit/lit/TestRunner.py +++ b/llvm/utils/lit/lit/TestRunner.py @@ -1124,6 +1124,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 ) @@ -1323,11 +1325,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 863fbda8c5b6d..716b5ff1dd9a3 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: 9 tests{{.*}} +# CHECK: -- Testing: 10 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-no-subcommand.txt ({{[^)]*}}) # CHECK: env | {{.*}} # CHECK: # executed command: env @@ -65,6 +70,6 @@ # CHECK-NOT: # error: # CHECK: -- -# CHECK: Total Discovered Tests: 9 -# CHECK: Passed: 9 {{\([0-9]*\.[0-9]*%\)}} +# CHECK: Total Discovered Tests: 10 +# CHECK: Passed: 10 {{\([0-9]*\.[0-9]*%\)}} # CHECK-NOT: {{.}}