Commit Graph

306 Commits

Author SHA1 Message Date
Sam James 6f426e02d1 mtest: refactor get_wrapper slightly
--wrapper and --gdb are mutually exclusive per run(), so make get_wrapper
reflect this (which would've saved me some time earlier with trying to
make the two work together for something else, when it turns out that's
impossible).

As suggested by Eli.
2025-04-02 23:50:38 +03:00
Sam James 80116498d0 mtest: set VALGRIND_OPTS to fail tests on errors
We currently suggest that users run `meson test --wrapper valgrind`, but
this doesn't do what one might expect: Valgrind doesn't error out on
violations/issues it detects.

In the past, we had special handling for Valgrind in tests, see
1f76b76a84 but it was later dropped in
951262d759.

This is similar to what we do for {A,UB,M}SAN_OPTIONS to give sensible
behaviour that users expect out-of-the-box.

Only do this if we see 'valgrind' in the wrapper command to avoid
polluting logs. We may want to do that for the sanitizers variables
in future too.

Note that we're not adding --exit-on-first-error=yes here, as there
may be several issues in an application, or a test may be rather slow,
and so on. But --error-exitcode=1 to simply make Valgrind's exit status
reflect whether an error was found is uncontroversial.

Bug: https://github.com/mesonbuild/meson/issues/4727
Bug: https://github.com/mesonbuild/meson/issues/1105
Bug: https://github.com/mesonbuild/meson/issues/1175
Bug: https://github.com/mesonbuild/meson/issues/13745
2025-04-02 23:50:38 +03:00
Dylan Baker 4fa5292545 coredata: replace get_option with optstore.get_value_for
This is an old method, that is now just a wrapper around the OptionStore
method, that doesn't add any value. It's also an option related method
attached to the CoreData instead of the OptionStore, so useless and a
layering violation.
2025-03-10 14:14:25 -04:00
Patrick Steinhardt de7d8f9e48 test: fix hang when running tests that need parsing with `--interactive`
When running tests with `--interactive` we don't redirect stdin, stdout
or stderr and instead pass them on to the user's console. This redirect
causes us to hang in case the test in question needs parsing, like it is
the case for TAP output, because we cannot read the process's stdout.

Fix this hang by not parsing output when running in interactive mode.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
2025-02-27 15:25:57 -05:00
Patrick Steinhardt 7fd17ab128 mtest: introduce ignored tests
When running tests in interactive mode then the standard file streams
will remain connected to the executing terminal so that the user can
interact with the tests. This has the consequence that Meson itself does
not have access to those streams anymore, which is problematic for any
of the test types that require parsing, like for example with the TAP
protocol. This means that Meson is essentially flying blind in those
cases because the test result cannot be determined by parsing the exit
code of the test, but can only reliably be derived from the parsed
output.

One obvious solution to this problem would be to splice the test output
so that both Meson and the user's terminal have access to it. But when
running in interactive mode it is quite likely that the test itself will
actually be driven from the command line, and the chance is high that
the resulting data on stdout cannot be parsed as properly anymore. This
is for example the case in the Git project, where interactive mode is
typically used to drop the user into a shell or invoke a debugger.

So continuing to treat the output as properly formatted output that can
be parsed is likely a dead end in many use cases. Instead, we introduce
a new "IGNORED" test result: when executing tests in interactive mode,
and when the test type indicates that it requires parsing, we will not
try to parse the test at all but mark the test result as ignored
instead.

Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Patrick Steinhardt <ps@pks.im>
2025-02-27 15:25:57 -05:00
Patrick Steinhardt 4526a75e25 mtest: move `console_mode` property into TestRun class
Move the `console_mode` property into the TestRun Class. This will be
required by a subsequent commit where we start to ignore test results
for parsed interactive tests.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
2025-02-27 15:25:57 -05:00
Patrick Steinhardt 23a9a25779 mtest: filter summary lines without any results
After a test run finishes we print a summary that sums up test counts by
type, e.g. failed or skipped tests. In many cases though it is expected
that most of the counts will be zero, and thus the summary is needlessly
cluttered with irrelevant lines. This list of mostly-irrelevant results
will grow in a subsequent commit where we introduce "Ignored" test
results.

Prepare for this by filtering results. Instead of unconditionally
printing every result, we will now only print those results where we
have at least one counted test. The exception is "Ok:" and "Fail:",
which will always be printed.

Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Patrick Steinhardt <ps@pks.im>
2025-02-27 15:25:57 -05:00
Patrick Steinhardt d3c8639975 mtest: add option to slice tests
Executing tests can take a very long time. As an example, the Git test
suite on Windows takes around 4 hours to execute. The Git project has
been working around the issue by splitting up CI jobs into multiple
slices: one job creates the build artifacts, and then we spawn N test
jobs with those artifacts, where each test job executes 1/Nth of the
tests.

This can be scripted rather easily by using `meson test --list`,
selecting every Nth line, but there may be other projects that have a
similar need. Wire up a new option "--slice i/n" to `meson test` that
does implements this logic.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
2025-02-27 15:25:05 -05:00
gerioldman 2450342535 Interpret TAP bailout output without test plan or test line as error 2025-01-08 12:05:47 +02:00
Eli Schwartz eb1e52afa1
mtest: fix rebuilding all before running tests
Inconsistency in the original implementation of commit
79e2c52a15.

If an explicit list of targets is passed on the CLI, then that is passed
to rebuild_deps. If not, we pass every loaded test to rebuild_deps
instead. This means we cannot distinguish between "trying to run all
tests" and "trying to run specific tests". We then load all the deps for
all tests, and try to build them all as explicit arguments to the
underlying ninja.

There are two situations where this falls flat:

- given underspecified deps
- given all (selected?) tests legitimately happen to have no
  dependencies

In both cases, we calculate that there are no deps to rebuild, we run
ninja without any targets, and this invokes the default "all" rule and
maybe builds a few thousand targets that this specific test run does not
need.

Additionally, in large projects which define many tests with many
dependencies, we could end up overflowing ARG_MAX when processing *all*
tests.

Instead, pass no tests to rebuild_deps. We then specially handle this by
directly running the relevant ninja target for "all test deps", which is
overall more elegant than specifying many many dependencies by name.

Given a subset of tests to guarantee the freshness of, we instead skip
running ninja at all if there are indeed no test dependencies.
2025-01-07 20:16:05 -05:00
Paolo Bonzini 1c8b523c86 mtest: tap: accept out-of-order or partly-numbered tests
Resolves: #13802
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2024-12-19 09:44:15 -08:00
Paolo Bonzini 8b9846d9a9 mtest: move determine_worker_count to utils, generalize
It is useful to apply a limit to the number of processes even outside "meson test",
and specifically for clang tools.  In preparation for this, generalize
determine_worker_count() to accept a variable MESON_NUM_PROCESSES instead of
MESON_TESTTHREADS, and use it throughout instead of multiprocessing.cpu_count().

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2024-12-19 09:25:20 -08:00
Paolo Bonzini eb35d1a05f mtest: do not import from mintro
import mintro and its attendant module dependency tree just
so we can programmatically get filenames which are documented
as a stable API in https://mesonbuild.com/IDE-integration.html.

Suggested-by: Eli Schwartz <eschwartz93@gmail.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2024-12-19 09:25:20 -08:00
Paolo Bonzini 2fd0dacf06 mtest: rust: allow parsing doctest output
Doctests have a slightly different output compared to what "protocol: rust"
supports:

  running 2 tests
  test ../doctest1.rs - my_func (line 7) ... ignored
  test ../doctest1.rs - (line 3) ... ok

  test result: ok. 1 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out; finished in 0.12s

Add a little more parsing in order to accept this; a simple minded split()
fails to unpack the tuple.  I plan to contribute an extension of the rust
module to invoke doctests, for now this allows running rustdoc --test with
"protocol: 'rust'" and get information about the subtests:

  ▶ 4/8 ../doctest1.rs:my_func:7                     SKIP
  ▶ 4/8 ../doctest1.rs:3                             OK
  4/8 rust_unit_tests:doctests / rust doctest        OK              0.28s   1 subtests passed

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2024-12-06 09:56:12 -08:00
Jean-Bernard Berteaux a337dfe265 test: report timeout as failure 2024-10-31 10:16:37 -07:00
Marek Pikuła 1794a1e63c Extend MESON_TESTTHREADS usage
Previously, setting `MESON_TESTTHREADS` to a number lower than 1
resulted in unexpected behavior. This commit introduces test for
negative value (with fallback to 1), and fallback to core count in case
it is set to 0.

It improves experience in job-matrix type of CI workflows, where some
jobs within the matrix require single job execution, whereas others can
default to taking core count as the job count.

Signed-off-by: Marek Pikuła <m.pikula@partner.samsung.com>
2024-08-30 02:09:51 +03:00
Mateusz Patyk 541fee0c3c mtest: remove superfluous '\r' from read_decode()
On Windows, the output read from the stream has '\r\n', which in .txt,
.json and console logger (when captured to a file) translates to '\n\n'.

This results in every log line being separated by an empty line.
2024-07-28 19:03:39 +03:00
Jussi Pakkanen 0d7bb776e2 Move OptionKey in the option source file. 2024-07-11 11:53:39 +03:00
Daan De Meyer a3d3efd3cf Add meson test --max-lines
Let's allow users to configure how many lines are shown at most when
a test fails.
2024-06-17 19:30:10 +03:00
Daan De Meyer bcaab91bf6 mtest: Set MESON_TEST_ITERATION to the current iteration of the test
When running our integration tests in systemd we depend on each test
having a unique name. This is always the case unless --repeat is used,
in which case multiple tests with the same name run concurrently which
causes issues when allocating resources that use the test name as the
identifier.

Let's set MESON_TEST_ITERATION to the current iteration of the test so
we can use $TEST_NAME-$TEST_ITERATION as our test identifiers which will
avoid these issues.
2024-05-08 08:05:44 -04:00
Daan De Meyer d68306c9c8 mtest: Connect /dev/null to stdin when not running in interactive mode
This allows tests to check whether stdin is a tty to figure out if they're
running in interactive mode or not.

It also makes sure that tests that are not running in interactive mode
don't inadvertendly try to read from stdin.
2024-04-23 21:36:35 +02:00
Daan De Meyer 344a97e08a Add meson test --interactive
This is very similar to --gdb, except it doesn't spawn GDB, but
connects stdin/stdout/stderr directly to the test itself. This allows
interacting with integration tests that spawn a shell in a container
or virtual machine when the test fails.

In systemd we're migrating our integration tests to run using the
meson test runner. We want to allow interactive debugging of failed
tests directly in the virtual machine or container that is spawned
to run the test. To make this possible, we need meson test to connect
stdin/stdout/stderr of the test directly to the user's terminal, just
like is done with the --gdb option.
2024-04-23 21:36:22 +02:00
Christopher Dilks 8480f3e795 fix: set `MSAN_OPTIONS` when not set, rather than `UBSAN_OPTIONS` 2024-03-20 15:10:41 -07:00
Charles Brunet 11f2e07071 Allow using CustomTarget as test executable
Fixes #6567
2024-02-24 09:08:20 -08:00
Sam James 8ba0ea6801
mtest: set MSAN_OPTIONS to abort by default
Followup to 7b7d2e060b which handles ASAN and UBSAN.

It turns out that MSAN needs the same treatment. I've checked other sanitizers
like HWASAN and TSAN - it looks like they may both need it too, but Meson doesn't
currently suppose those anyway (see https://github.com/mesonbuild/meson/pull/12648).

Signed-off-by: Sam James <sam@gentoo.org>
Signed-off-by: Eli Schwartz <eschwartz93@gmail.com>
2024-02-23 15:59:22 -05:00
Sam James 6c2c4612cc Fix comment typo
Oops.

Fixes: 7b7d2e060b
Signed-off-by: Sam James <sam@gentoo.org>
2024-02-13 00:18:38 +02:00
Dylan Baker e991c4d454 Use SPDX-License-Identifier consistently
This replaces all of the Apache blurbs at the start of each file with an
`# SPDX-License-Identifier: Apache-2.0` string. It also fixes existing
uses to be consistent in capitalization, and to be placed above any
copyright notices.

This removes nearly 3000 lines of boilerplate from the project (only
python files), which no developer cares to look at.

SPDX is in common use, particularly in the Linux kernel, and is the
recommended format for Meson's own `project(license: )` field
2023-12-13 15:19:21 -05:00
Xavier Claessens 11dec13a19 mtest: -C argument does not need type convertor
It is already done by RealPathAction and mypy started complaining about
it.
2023-11-10 14:22:30 -05:00
Luke Elliott ce691f8c98 Add comments suggesting to keep shell completion scripts up-to-date near cmd line argument code 2023-11-01 00:06:19 +02:00
Tristan Partin 46cedeb431 Support -j as a shorthand for --num-processes
We already use -j to support parallelism in meson compile. So let's add
the same for meson test and meson subprojects.
2023-10-20 12:49:38 -04:00
Sam James 7b7d2e060b mtest: set ASAN_OPTIONS and UBSAN_OPTIONS to abort by default
Do as we do for MALLOC_PERTURB and set a sensible value for both ASAN_OPTIONS
and UBSAN_OPTIONS to abort on failure and give more helpful output at the
same time. We do not set these options if the user has exported a value
themselves to allow override.

In the last week alone, I've observed two cases where people were expecting
sanitizers to abort on failure and were surprised when it didn't:
1) 252d693797
2) c47df433f7

Correct this - which is in-line with meson's DWIM/DTRT philosophy.

Signed-off-by: Sam James <sam@gentoo.org>
2023-10-19 14:47:19 -04:00
Tristan Partin 543e9ca0cf Remove XML filter from testlog.{json,txt} and std streams
This was an unintended consequence of the original patch in #11977.

Co-authored-by: Benoit Pierre <benoit.pierre@gmail.com>
2023-08-17 17:31:30 -04:00
Eli Schwartz 90ce084144
treewide: automatic rewriting of all comment-style type annotations
Performed using https://github.com/ilevkivskyi/com2ann

This has no actual effect on the codebase as type checkers (still)
support both and negligible effect on runtime performance since
__future__ annotations ameliorates that. Technically, the bytecode would
be bigger for non function-local annotations, of which we have many
either way.

So if it doesn't really matter, why do a large-scale refactor? Simple:
because people keep wanting to, but it's getting nickle-and-dimed. If
we're going to do this we might as well do it consistently in one shot,
using tooling that guarantees repeatability and correctness.

Repeat with:

```
com2ann mesonbuild/
```
2023-08-11 13:41:03 -04:00
Eli Schwartz de1cc0b02b
rewrite a couple comment-style type annotations for oddly indented dicts
Make them into real type annotations. These are the only ones that if
automatically rewritten, would cause flake8 to error out with the
message: "E128 continuation line under-indented for visual indent".
2023-08-11 13:39:07 -04:00
Eli Schwartz a01418db0a
remove useless type annotations
These annotations all had a default initializer of the correct type, or
a parent class annotation.
2023-08-11 13:37:17 -04:00
Eli Schwartz 7afc69254d
fix implicit_reexport issues and enforce them going forward
This detects cases where module A imports a function from B, and C
imports that same function from A instead of B. It's not part of the API
contract of A, and causes innocent refactoring to break things.
2023-07-19 18:31:37 -04:00
Eli Schwartz 6894bb5a30 mtest: avoid meddling with stdout by default
The original point of specifying Optional was to default to None...
oops. The practical effect of this change is that the testsuite no
longer repeatedly logs "No tests defined." in between more meaningful
output.
2023-07-18 21:58:58 -04:00
Nazir Bilal Yavuz bd3d2cf918 mtest: fix unencodable XML chars
Replace unencodable XML chars with their printable representation, so
that, xmllint can parse test outputs without error.

Closes #9894

Co-authored-by: Tristan Partin <tristan@partin.io>
2023-07-13 09:38:55 -07:00
Eli Schwartz 1a72f00252
mtest: avoid stdout when printing warnings about the lack of things to print
Since people may parse the output of `--list` as a list of tests,
putting logging info in stderr is nicer.
2023-07-10 20:10:04 -04:00
Eli Schwartz 2fd9055810
mtest: redirect automatic reconfiguring to stderr when listing tests
It is not the primary purpose of mtest, and it ends up mingled with a
list of actual tests, which isn't nice if you're trying to capture and
parse this.
2023-07-10 20:10:02 -04:00
Eli Schwartz 9d446d80db
mtest: try a bit harder to avoid weird non-parseable output at startup
In commit 628effb369 we started verifying
the build.ninja file was up to date before even `--list`ing tests,
because we could end up with incorrect information. This meant that
ninja always runs at startup, and typically returns "no work to do",
which ended up listed as "one of" the tests.

Instead of unconditionally running ninja attached to the console, first
check it in dry-run mode with stdout intercepted, to see if ninja
considers itself up to date. If it is, continue. Only if an actual
refresh is needed, do we run it while attached to the console.

In the garden path, this avoids useless information. In cases where we'd
already print a full meson reconfigure log, we continue to do so.
2023-07-10 20:08:01 -04:00
Charles Brunet e7b9dfac98 mtest: wildcard selection
Allow the use of wildcards (e.g. *) to match test names in `meson test`.

Raise an error is given test name does not match any test.

Optimize the search by looping through the list of tests only once.
2023-05-25 13:44:13 -04:00
Charles Brunet 70e2da0773 mtest: prevent parse error with gtest protocol
Replace illegal characters when reading gtest generated xml file,
to prevent a ParseError and a stacktrace.

catch et.ParseError, just in case, to prevent stopping other tests
if the xml file was malformed.
2023-04-24 15:48:31 -04:00
Josh Soref cf9fd56bc9 fix various spelling issues
Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
2023-04-11 19:21:05 -04:00
HiPhish 439a61affa Change "can not" to "cannot" throughout project
The word "cannot" expresses inability to do something whereas "can not"
expresses the ability to refrain from doing something.
2023-04-11 17:10:01 +03:00
Xavier Claessens b30cd5d2d5 Make --vsenv a readonly builtin option
We need to remember its value when reconfiguring, but the Build object
is not reused, only coredata is.

This also makes CLI more consistent by allowing `-Dvsenv=true` syntax.

Fixes: #11309
2023-03-29 09:33:41 -04:00
Eli Schwartz a024d75e15
backends: add a new "none" backend
It can only be used for projects that don't have any rules at all, i.e.
they are purely using Meson to:

- configure files
- run (script?) tests
- install files that exist by the end of the setup stage

This can be useful e.g. for Meson itself, a pure python project.
2023-03-20 17:22:50 -04:00
Eli Schwartz fccada6703
mtest: move the detection of rebuild compatibility out into the entry point
What we are mainly doing here is checking that the options make sense,
or fixing that up if they don't. And in the next commit we will want to
do that by also checking the build object.
2023-03-20 16:58:15 -04:00
Dylan Baker b2f7f2da1c mtest: fix annotaion of stdo_task and stde_task
Which are `Task`s, not `Future`s, and they return `None`, not `str`.
Spotted by newer versions of mypy
2023-02-08 15:31:58 +05:30
Eli Schwartz d6b81307f6
pylint 2.16: remove pointless parens around equality assignments
Given the construct `foo = (bar == baz)` some people like parentheses
and some do not. They're pointless and don't mean anything, though. I
don't feel this is particularly helpful to code clarity, tbh, and pylint
now notices this and warns about it in our current pylint config.

I think this is reasonable, so let's remove the odd parens.
2023-02-01 17:01:30 -05:00