1289 Commits

Author SHA1 Message Date
Aiden Grossman
3fcba45de1 Revert "[lit] Avoid multiprocessing for -j1 runs (#175587)"
This reverts commit 9f1a9d24813c0c1b89d24063825a7fb8ca64a3a1.

This caused quite a few buildbot failures (see failures on the PR). It
does not look like a trivial fix to me.
2026-02-04 19:33:49 +00:00
alx32
9f1a9d2481
[lit] Avoid multiprocessing for -j1 runs (#175587)
### Problem

When running `lit` with `-j1` in a sandboxed environment (e.g., [Cursor
Sandbox Mode](https://cursor.com/blog/enterprise#sandbox-mode)), `lit`
crashes with `PermissionError: [Errno 1] Operation not permitted`
because it still attempts to create a `multiprocessing.Pool`, which
requires POSIX semaphores (`/dev/shm/sem.*`) that are blocked by the
sandbox.

**Reproducer:** Run any lit test suite with `-j1` in a [restricted
sandbox](https://cursor.com/blog/enterprise#sandbox-mode):
`LIT_OPTS="-j1 -v" ninja check-lld`

**Error trace:**
https://gist.github.com/alx32/0dc6abb45c40cf5753669e4c6cce929d

### Solution

When `workers == 1`, skip `multiprocessing.Pool` entirely and run tests
sequentially in the main process. This avoids creating POSIX semaphores
that fail in sandboxed environments.

To properly support `--max-time` in single-process mode (where we can't
terminate workers mid-test), we temporarily set `maxIndividualTestTime`
to the remaining time before the deadline. If a test times out due to
hitting the deadline, it's marked as SKIPPED to match multiprocessing
behavior.

### Testing

Added `single-process.py` test that uses strace to verify:
- With `-j1`: No `/dev/shm/sem.*` POSIX semaphores are created
- With `-j2`: Semaphores ARE created (validates the test won't XPASS)

### Historical Context

Lit previously had a "single process mode" that was:
- **Added** in Sept 2017 (42b6dcbcef4f) for debugging
- **Enhanced** in Feb 2019 (96adb78b120b) to auto-enable for `-j1`
- **Removed** in Oct 2019 (f3c329986cf4) as it "did not carry its
weight"

The original motivation was performance/debugging. The new motivation is
**compatibility with sandboxed execution environments** where
multiprocessing primitives are unavailable.


[Assisted-by](https://t.ly/Dkjjk): Cursor IDE + claude-opus-4.5-high +
gpt-5.2-xhigh
2026-02-04 11:20:28 -08:00
Aiden Grossman
8bb659fd23
[lit] Fix filter-failed-rerun.py on readonly FSes (#177075)
This test invokes lit in a directory and then tries to overwrite
fail.txt within that directory. With the project sources mounted as
read-only, fail.txt ends up being marked readonly, which causes cp to
fail without -f. Use cp -f to ensure we overwrite the existing fail.txt.
2026-01-21 02:02:30 +00:00
Aiden Grossman
fb2c5b1b2b
[lit] Remove error message for %T (#175782)
We left an error message for users of %T through the LLVM 22 branch
point to hopefully make it easier for anyone migrating versions rather
than having the checks silently fail with a %T ending up in the executed
command. Now that 22 has branched, we can remove this check as we all
downstream users should have seen the error by this point.
2026-01-13 09:29:57 -08:00
Cullen Rhodes
bd6bfba3e5 Bump version to 23.0.0-git 2026-01-13 09:34:22 +00:00
Aiden Grossman
65dbee0089
[lit] Make not still fail if the called process returns a signal
This is the behavior of the main not binary that was not preserved in
the internal shell. Make it so that the builtin not command does
actually fail if we end up with a signal rather than just a non-zero
exit code.

Reviewers: petrhosek, ilovepi, jdenny-ornl, arichardson

Pull Request: https://github.com/llvm/llvm-project/pull/174298
2026-01-05 13:34:19 -08:00
Aiden Grossman
9553f119b0
[lit] Drop shell feature from all upstream projects (#173341)
Now that no tests actually use the shell feature to conditionally run,
drop the feature altogether to prevent backslide.
2025-12-31 11:06:36 -08:00
aokblast
26cc61ef2f
[lit] Disable ulimit-nodarwin test on FreeBSD (#173155)
FreeBSD does not support using ulimit to grow up max file number per
process. This characteristic is inherited by Darwin and thus we pass
this test on FreeBSD as well.
2025-12-27 12:16:53 +00:00
Michael Buch
04ce013d7c
Reapply "[llvm][lit] Add option to run only the failed tests" (#171588)
This reverts commit 3847648e84d2ff5194f605a8a9a5c0a5e5174939.

Relands https://github.com/llvm/llvm-project/pull/158043 which got
auto-merged on a revision which wasn't approved.

The only addition to the approved version was that we adjust how we set
the time for failed tests. We used to just assign it the negative value
of the elapsed time. But if the test failed with `0` seconds (which some
of the new tests do), we would mark it `-0`. But the check for whether
something failed checks for `time < 0`. That messed with the new
`--filter-failed` option of this PR. This was only an issue on Windows
CI, but presumably can happen on any platform. Happy to do this in a
separate PR.

---- Original PR

This patch adds a new --filter-failed option to llvm-lit, which when
set, will only run the tests that have previously failed.
2025-12-12 10:29:07 +00:00
Michael Buch
3847648e84
Revert "[llvm][lit] Add option to run only the failed tests" (#171582)
Reverts llvm/llvm-project#158043

This was approved for earlier revisions but the tests were failing on
Windows. I pushed a speculative fix and that fixed the CI, which caused
auto-merge to merge the PR. But I'd like to have approval for the latest
revision. So reverting for now and resubmitting a new PR
2025-12-10 10:04:16 +00:00
Michael Buch
951795abaf
[llvm][lit] Add option to run only the failed tests (#158043)
This patch adds a new `--filter-failed` option to `llvm-lit`, which when
set, will only run the tests that have previously failed.
2025-12-10 09:30:26 +00:00
Mehdi Amini
f83f6f565f
Fix lit testing to support standalone testing (#170365)
To be able to test lit without having a configuration of LLVM, we need
to support invocations that are not going through the lit.site.cfg and
thus don't have a llvm_config set-up.
2025-12-03 14:59:34 +01:00
Tomohiro Kashiwada
c8031c3dd7
[LIT] remove to_unicode, to_string, and to_bytes helpers (#165950)
These helpers, which handle the difference between Python 2.x and Python
3.x, are no longer required.

Co-authored-by: Alexander Richardson <mail@alexrichardson.me>
2025-12-01 12:06:17 -08:00
Mehdi Amini
235d44d8b6 Fix LLVM test to use %python instead of python
This uses lit substitution, which fixes running this test on
some environment where 'python' isn't in the path.
2025-12-01 06:26:39 -08:00
Aiden Grossman
4978cd3cdf Revert "Fix LLVM test to use %python instead of python"
This reverts commit b4c30b0e1ece2bc97ef91e4bbed422c2e620be05.

This substitution is not available from within these tests.
2025-12-01 06:08:04 -08:00
Mehdi Amini
b4c30b0e1e Fix LLVM test to use %python instead of python
This uses lit substitution, which fixes running this test on
some environment where 'python' isn't in the path.
2025-12-01 05:53:02 -08:00
Mehdi Amini
577cd6fb02
[LIT] Workaround the 60 processed limit on Windows (#157759)
Python multiprocessing is limited to 60 workers at most:

6bc65c30ff/Lib/concurrent/futures/process.py (L669-L672)

The limit being per thread pool, we can work around it by using multiple
pools on windows when we want to actually use more workers.
2025-12-01 11:39:25 +00:00
David Spickett
4a567e3e7c
[llvm][utils][lit] Fix imports in ManyTests.py example (#169328)
Fixes #169297
2025-11-24 14:24:32 +00:00
Dan Liew
8bdbc57b89
[NFC][LLDB] Make it possible to detect if the compiler used in tests supports -fbounds-safety (#169112)
This patch makes it possible to detect in LLDB shell and API tests if
`-fbounds-safety` is supported by the compiler used for testing. The
motivation behind this is to allow upstreaming
https://github.com/swiftlang/llvm-project/pull/11835 but with the tests
disabled in upstream because the full implementation of -fbounds-safety
isn't available in Clang yet.

For shell tests when -fbounds-safety is available the
`clang-bounds-safety` feature is available which means tests can be
annotated with `# REQUIRES: clang-bounds-safety`.

API tests that need -fbounds-safety support in the compiler can use the
new `@skipUnlessBoundsSafety` decorator.

rdar://165225507
2025-11-21 19:01:31 -08:00
Andrew Haberlandt
3f6cbdea4f
[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](d2c7c60642/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.
2025-11-19 15:06:18 -08:00
Henrik G. Olsson
8e4209a290
[utils] don't warn when setting rlimit fails on Solaris (#167921)
Solaris doesn't define RLIMIT_NPROC, so this is expected to fail there.
This fixes a test failure in llvm/utils/lit/tests/verbosity.py on
Solaris due to this unexpected warning being included in the lit output.
2025-11-14 10:19:42 -08:00
Henrik G. Olsson
83118de722
[utils] support both files originating from split-file in DiffUpdater (#166679)
With this change DiffUpdater can update expected files even if both
files are created by split-files, if one of them ends with ".expected".
This is useful when a file is created and then modified during the test.
2025-11-13 11:57:22 -08:00
Henrik G. Olsson
61218267a5
[utils] remove flakiness in verbosity.py test case (#167801)
The rate at which lit's progress bar progresses is not deterministic.
Don't try to match the contents of the progress bar, only the fact that
it's there.
2025-11-13 01:35:52 +00:00
Henrik G. Olsson
dbf77e4f5b
[utils] revamp options controlling lit's output (#167192)
Lit has a number of options controlling the output, but they don't
compose very well. This breaks the existing options down into smaller,
orthogonal options, and makes the existing options aliases of the new
ones.

This introduces the following options:
  --test-output {off,failed,all}
  --print-result-after {off,failed,all}
  --diagnostic-level {error,warning,note}
  --terse-summary
  --no-terse-summary
  --progress-bar (mirroring --no-progress-bar)

--test-output and --print-result-after are not entirely orthogonal, as
'--test-output X' requires that --print-result-after is set to at least
X, and implicitly does so if it isn't already. Conversely,
'--print-result-after Y' requires that --test-output is at most Y, and
implicitly lowers if it is higher. This means that the following
invocations have different end results, as they are applied in order:
  '--test-output all --print-result-after off'
  '--print-result-after off --test-output all'

The following existing options are now aliases as follows:
  -q, --quiet
    '--diagnostic-level error --test-output off --terse-summary'
  -s, --succinct
    '--progress-bar --print-result-after failed'
  -v, --verbose
    '--test-output failed'
  -a, --show-all
    '--test-output all'

These where all completely separate options and would override each
other in ad-hoc ways, with no regard to the order they were given.

This fixes https://github.com/llvm/llvm-project/issues/106643 This is
based on the RFC

https://discourse.llvm.org/t/rfc-new-command-line-options-for-controlling-llvm-lit-output/
with the addition of --terse-summary, which was a behaviour of -q that
was not captured by the original RFC. This also diverges from the RFC in
that --debug is NOT folded into --diagnostic-level, because it can be
useful to debug any configuration, including those specifying
--diagnostic-level.

Example combination that is possible now but wasn't before:
'--diagnostic-level error --test-output all --progress-bar' Another use
case is aliases, where you can alias e.g:
  alias lit=llvm-lit --quiet
but still override the specified default options.
2025-11-12 15:34:21 -08:00
Tomohiro Kashiwada
dec6e7380c
[LIT][Cygwin] Mark ulimit -f unsupported for Cygwin (#165849)
Cygwin doesn't support `ulimit -f` because Windows doesn't provide such
functionality.
2025-11-04 11:38:20 +02:00
Tomohiro Kashiwada
84cc2b0ebc
[LIT] replace lit.util.mkdir with pathlib.Path.mkdir (#163948)
`lit.util.mkdir` and `lit.util.mkdir_p` were written during the Python
2.x era.
Since modern `pathlib` functions have similar functionality, we can
simply use those instead.

If you encounter a path length issue after this change, the registry
value `LongPathsEnabled` must be set as described in
https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation
. Note that the Python runtime is already marked as a `longPathAware`
executable.

**Background:**

On Cygwin, a file named `file_name.exe` can be accessed without the
suffix, simply as `file_name`, as shown below:

```
$ echo > file_name.exe

$ file file_name.exe
file_name.exe: very short file (no magic)

$ file file_name
file_name: very short file (no magic)
```

In this situation, while running `mkdir file_name` works as intended,
checking for the existence of the target before calling `mkdir`
incorrectly reports that it already exists and thus skips the directory
creation.

```
$ test -e file_name && echo exists
exists

$ mkdir file_name && echo ok
ok

$ file file_name
file_name: directory
```

Therefore, the existence pre-check should be skipped on Cygwin. Instead
of add a workaround, refactored them.
2025-11-04 11:37:58 +02:00
David Spickett
94f3eeee94
[llvm][clang] Remove handling of Python2 ConfigParser module name (#163727)
LLVM now requires Python >= 3.8, and ConfigParser was renamed to
configparser in 3.0:
https://docs.python.org/3/whatsnew/3.0.html#library-changes

A few places imported it under the Python2 name even for Python3, I have
swapped those to the Python3 name.

This was reported by https://pypi.org/project/vermin/ as the file having
incompatible versions. Since once import is 2.x and one is 3.x.
2025-10-31 09:45:55 +00:00
Aiden Grossman
1f702d4ee8 [lit] Mark ulimit test as unsupported on Solaris
160058fc19a9bcb70feb442a755229838b4dbc7a broke the Solaris bots because
they do not support RLIMIT_FSIZE despite it being in POSIX 2004. Disable
it there for now as the loss of test coverage should not be significant.
2025-10-31 00:02:59 +00:00
Aiden Grossman
28e98b8501
[lit] Expand late substitutions before running builtins
This enables the use of readfile substitutions for populating
environment variables. This is necessary in some compiler-rt tests.

Reviewers: pawosm-arm

Reviewed By: pawosm-arm

Pull Request: https://github.com/llvm/llvm-project/pull/165140
2025-10-30 11:28:11 -07:00
Aiden Grossman
160058fc19 [lit] Move ulimit_unlimited.txt test to non Darwin tests
This fails on MacOS because setting it to unlimited there just sets the
limit to the max value which causes differences that show up in the
check lines.
2025-10-30 17:47:38 +00:00
Aiden Grossman
9b02901b26
[lit] Add support for setting limits to unlimited
This is used by a couple compiler-rt tests.

Reviewers: petrhosek, ilovepi

Reviewed By: ilovepi

Pull Request: https://github.com/llvm/llvm-project/pull/165123
2025-10-30 09:27:47 -07:00
Aiden Grossman
57ff891372 [lit] Remove setting stack size in ulimit_okay.txt
This was supposed to be in 6ccd1e8626f331f2ec2b172c3e7e8fffee66ac95 but
got left out because I forgot to save the file inside of VSCode. This
was causing test failures on MacOS due to the previously mentioned
failures setting ulimit that caused the patch to be reverted in the
first place.

https://lab.llvm.org/buildbot/#/builders/190/builds/29990
2025-10-30 14:49:22 +00:00
Aiden Grossman
6ccd1e8626 Reapply "[lit] Support more ulimit options"
This reverts commit 57722ddce172f569f04a50b76ccb2fc524adf8f5.

This caused some MacOS test failures due to resource there having issues
with RLIMIT_STACK. The underlying syscall fails with EINVAL despite
the values being correct. For now, move this to the non Darwin test.
2025-10-30 14:28:33 +00:00
Björn Pettersson
44cb8c1e00
[lit] Fix to make "RUN: env PATH=..." work as intended (#165308)
There was a bug in llvm-lit related to setting PATH using env in the
internal shell.

The new PATH wasn't used when looking up the command to be executed. So
when doing things like this in a test case
  RUN: mkdir %t
  RUN: env PATH=%t program ...
the internal shell would search for "program" using the orignal PATH and
not the PATH set by env when preceeding the command.

It seems like this was a simple mistake in commit 57782eff31e9d454,
since the logic to pick a PATH from the cmd_shenv instead of shenv
actually was added in that patch, but the resulting path wasn't used.
2025-10-28 14:33:04 +01:00
Aiden Grossman
57722ddce1 Revert "[lit] Support more ulimit options"
This reverts commit 8f1c72dcd3fc4bc871bbcd06bfae76510f3714b0.

This is causing builtbot failures.

https://lab.llvm.org/buildbot/#/builders/23/builds/15030
https://lab.llvm.org/buildbot/#/builders/190/builds/29834
2025-10-27 20:07:48 +00:00
Aiden Grossman
8f1c72dcd3
[lit] Support more ulimit options
These are the other options used in compiler-rt that we also need to
support.

Reviewers: arichardson, petrhosek, ilovepi

Reviewed By: ilovepi, arichardson

Pull Request: https://github.com/llvm/llvm-project/pull/165122
2025-10-27 10:43:56 -07:00
Tomohiro Kashiwada
cae7dec112
[LIT][Cygwin] Mark ulimit -n unsupported for Cygwin (#164604)
Cygwin doesn't support `ulimit -n` because Windows doesn't provide such
functionality.
2025-10-23 09:51:57 +03:00
Aiden Grossman
f8f7f1b67c
[lit] Update shtest-ulimit.py to explicitly check default limits (#164678)
The recently added ulimit_reset.txt section in shtest-ulimit.py was
failing on some builders if the default file descriptor limit started
with 50. This patch fixes that by explicitly checking that the file
descriptor limit is equal to the default value.
2025-10-22 18:50:46 +00:00
Aiden Grossman
93dd17a0e0
[lit] Ensure ulimit does not persist across tests (#164485)
When constructing a container in a default argument in Python, we
actually end up with a reference to the same default container for every
invocation of the function. Given this happened with the ulimit variable
in ShellEnvironment, we ended up persisting limits across tests. This
would cause some LLVM tests to fail, particularly jitlink and dsymutil
tests, if they ended up running after the one clang test that uses
ulimit -v to set a maximum amount of memory that can be allocated. This
patch fixes that behavior by constructing the dict inside the function
to ensure we get a new instance and adds test coverage.
2025-10-21 16:32:10 -07:00
Tomohiro Kashiwada
d4af5e6b0b
[Unittest][Cygwin] Set $PATH when running unittests (#163947)
As the Cygwin platform requires $PATH to be set in order to run
unittests, do the same as for the regular Windows target.
2025-10-20 23:14:19 +03:00
Kunqiu Chen
6c5cb97cf4
[lit] Fix the missing comma in LIT config (#162998)
This pull request makes a minor fix to the
`llvm/utils/lit/lit/llvm/config.py` file.

The change corrects a missing comma in the list of environment
variables, ensuring that `"UBSAN_SYMBOLIZER_PATH"` and `"ASAN_OPTIONS"`
are treated as separate entries instead of a single concatenated string.

* Fixed a missing comma between `"UBSAN_SYMBOLIZER_PATH"` and
`"ASAN_OPTIONS"` in the environment variable list in
`llvm/utils/lit/lit/llvm/config.py`, preventing potential configuration
issues.
2025-10-12 14:36:25 +08:00
David Spickett
299761113d [lit][test] Relax time regex in xunit failure test
We don't care how long any of this took. Due to OS scheduling,
one or more parts of the test may be delayed for any amount of
time.
2025-10-09 09:25:11 +00:00
Aiden Grossman
7ff6973f1a
[lit] Remove support for %T
This patch removes support for %T from llvm-lit. For now we mark the
test unresolved and add an error message noting the substitution is
deprecated. This is exactly the same as the error handling for other
substitution failures. We intend to remove support for the nice error
message once 22 branches as users should have moved over by the they are
upgrading to v23.

Reviewers: petrhosek, jh7370, ilovepi, pogo59, cmtice

Reviewed By: cmtice, jh7370, ilovepi

Pull Request: https://github.com/llvm/llvm-project/pull/160028
2025-09-26 19:06:09 -07:00
Aiden Grossman
f8d547fa8a
[lit] Remove %T from tests
This patch removes %T from tests in preparation for removing the
substitution completely. Splitting this off from the actual removal to
make it easier to revert the removal of %T in case I missed something.

Reviewers: RKSimon, jh7370, cmtice, petrhosek, ilovepi, pogo59

Reviewed By: cmtice, RKSimon, jh7370

Pull Request: https://github.com/llvm/llvm-project/pull/160027
2025-09-26 15:49:56 -07:00
Aiden Grossman
876296e9b7
[lit] Allow retries for readfile tests (#160600)
This patch allows for two retry attempts for the readfile tests. This is
intended as a stop-gap until I have time to do proper investigation into
why exactly the tests are failing.
2025-09-24 21:20:39 +00:00
Martin Storsjö
6e904e89cb
[lit] [test] Fix the shtest-readfile test on Python 3.13 on Windows (#160503)
Python 3.13 considers "/file/does/not/exist" to not be an absolute path
on Windows, so the test runner does os.path.join(cwd, filePath), which
can end up with an output path such as "D:/file/does/not/exist".

Accept a potential prefix before the missing path here.

This fixes running the lit tests on Windows with Python 3.13.
2025-09-24 22:00:52 +03:00
Mark Danial
51fa119617
[AIX] Fix AIX failures due to switch to internal shell (#160566)
This PR fixes a bunch of failures on AIX that occurred due to the switch
to lit internal shell by default. The failures deal with the following:
1. unset not being supported by lit internal shell
2. A bug with echo -n on AIX when there are multiple pipes in the RUN
command
3. ulimit test case not supported on AIX due to the -v option
4. platform specific error message for missing file
2025-09-24 14:11:44 -04:00
Aiden Grossman
83268237ba
[lit] Add support for deleting symlinks to directories without -r
Before this change, rm would assume that a symlink to a directory was
actually a directory and require the recursive flag to be passed,
differing from other shells. Given the change in lit is about the same
length as the test change would be (minus tests), I think it makes sense
to just support this in the internal shell.

Reviewers: cmtice, petrhosek, ilovepi

Reviewed By: petrhosek, cmtice, ilovepi

Pull Request: https://github.com/llvm/llvm-project/pull/158464
2025-09-19 21:47:07 -07:00
Aiden Grossman
7a3fa0671b
[lit] Make builtin cat work with stdin
cat with no files passed to it is supposed to read from STDIN according
to POSIX. The builtin cat lacking this behavior led to the clang test in
dev-fd-fs.c to fail because it expected this behavior. This is a simple
modification and I do not think it is possible to rewrite the test
without this easily while preserving the semantics around named pipes.

Reviewers: petrhosek, arichardson, ilovepi, cmtice, jh7370

Reviewed By: jh7370, arichardson, ilovepi, cmtice

Pull Request: https://github.com/llvm/llvm-project/pull/158447
2025-09-19 21:43:52 -07:00
Aiden Grossman
cfabbf0f3d
[lit] Add support for readfile to external shell
This patch adds support for the new lit %{readfile:<filename>}
substitution to the external shell. The implementation currently just
appends some test commands to ensure the file exists and uses a subshell
with cat. This is intended to enable running tests using the
substitution in the external shell before we fully switch over to the
internal shell.

This code is designed to be temporary with us deleting it once
everything has migrated over to the internal shell and we are able to
remove the external shell code paths.

Reviewers: petrhosek, cmtice, pogo59, ilovepi, arichardson

Reviewed By: cmtice

Pull Request: https://github.com/llvm/llvm-project/pull/159431
2025-09-19 15:04:38 -07:00