From 335875f94a4841d2a1a98f540f66425ed1cf308d Mon Sep 17 00:00:00 2001 From: Andrew Haberlandt Date: Mon, 17 Nov 2025 10:28:26 -0800 Subject: [PATCH 1/4] [compiler-rt] [libFuzzer] Fix merge-posix.test file size test (#168137) This test uses `ulimit -f 1` to test what libFuzzer does when trying to create a file > **_1KB_**. However, the none of the input files used by this test are actually >= 1KB, so there's no reason to expect this test to pass. This test appears to be passing on accident since the "control file" happens to be > 1KB, but this is not always the case depending upon the length of the path where the test is run from. This modifies the test to ensure that one of the input file is actually >1KB. (cherry picked from commit c4be17a8877ba406bcda63c5398bc09ebb32598a) --- compiler-rt/test/fuzzer/merge-posix.test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler-rt/test/fuzzer/merge-posix.test b/compiler-rt/test/fuzzer/merge-posix.test index 2721668fb9706..5e342142216f8 100644 --- a/compiler-rt/test/fuzzer/merge-posix.test +++ b/compiler-rt/test/fuzzer/merge-posix.test @@ -14,7 +14,7 @@ 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' * 1024, 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) From 301e2d3863e45d9e8bc956b18ef53a7e21297b22 Mon Sep 17 00:00:00 2001 From: Andrew Haberlandt Date: Wed, 19 Nov 2025 08:32:21 -0800 Subject: [PATCH 2/4] [compiler-rt] [libFuzzer] Fix merge-posix test (again) (#168639) (cherry picked from commit c6775e2eb6b94fd60453d207902cf961195bf780) --- compiler-rt/test/fuzzer/merge-posix.test | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler-rt/test/fuzzer/merge-posix.test b/compiler-rt/test/fuzzer/merge-posix.test index 5e342142216f8..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: %python -c "print('.....R' + 'X' * 1024, end='')" > %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 From 5f5da466c698fc37275da435a655d4fe673ef9d6 Mon Sep 17 00:00:00 2001 From: Andrew Haberlandt Date: Wed, 19 Nov 2025 15:06:18 -0800 Subject: [PATCH 3/4] [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. (cherry picked from commit 3f6cbdea4fecf11ffa4fa29151c69f53c7a59bf7) --- llvm/utils/lit/lit/TestRunner.py | 6 +++++- .../shtest-env-positive/env-current-testcase.txt | 6 ++++++ .../Inputs/shtest-env-positive/env-no-subcommand.txt | 1 + llvm/utils/lit/tests/shtest-env-positive.py | 11 ++++++++--- 4 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 llvm/utils/lit/tests/Inputs/shtest-env-positive/env-current-testcase.txt 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: {{.}} From 642b5826a690bb43c04ddca0b1e84441e30b86dd Mon Sep 17 00:00:00 2001 From: Andrew Haberlandt Date: Thu, 20 Nov 2025 10:40:13 -0800 Subject: [PATCH 4/4] [sanitizer_common] posix_spawn test should forward DYLD_LIBRARY_PATH (#168795) This test explicitly sets the environment for a spawned process. Without DYLD_LIBRARY_PATH, the spawned process may use a ASAN runtime other than the one that was used by the parent process That other runtime library may not work at all, or may not be in the default search path. Either case can cause the spawned process to die before it makes it to main, thus failing the test. The compiler-rt lit config sets the library path variable [here](https://github.com/llvm/llvm-project/blob/main/compiler-rt/test/lit.common.cfg.py#L84) (i.e. to ensure that just-built runtimes are used for tests, in the case of a standalone compiler-rt build), and that is currently used by the parent process but not the spawned ones. My change only forwards the variable for Darwin (DYLD_LIBRARY_PATH), but we **_ought_** to also forward the variable for other platforms. However, it's not clear that there's any good way to plumb this into the test, since some platforms actually have multiple library path variables which would need to be forwarded (see: SunOS [here](https://github.com/llvm/llvm-project/blob/main/compiler-rt/test/lit.common.cfg.py#L102)). I considered adding a substitution variable for the library path variable, but that doesn't really work if there's multiple such variables. (cherry picked from commit b5c0fcdadeed8803addf8d2aec6142fb9d8a5660) --- .../TestCases/Posix/posix_spawn.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) 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);