Commit Graph

306 Commits

Author SHA1 Message Date
Eli Schwartz a21af43200
micro-optimize: define typing-only objects in TYPE_CHECKING
Union types that exist solely for use as annotations don't need to be
created in normal runs.
2023-02-01 17:01:30 -05:00
Eli Schwartz 680b5ff819
treewide: add future annotations import 2023-02-01 17:01:30 -05:00
Eli Schwartz 8d39c9273b mtest: do not warn when the TAP stream version is 12
Partial rollback of commit b7a5c384a1. The
rationale was based on a confusing wording of the TAP14 spec, which is
under discussion for clarification / amendment.

TAP14 doesn't (shouldn't) really say that missing a version line is
potentially an error. Rather, this is the correct way to denote TAP12,
which a TAP14 harness may not understand or try to parse. The intention
was never to suggest that harnesses "should" take exception to the
missing version line on the grounds that one should really add a version
line.

So, stop emitting an annoying warning for something that's valid usage.
Meson understands TAP12 and that's okay.

However, we do need to keep the part of that commit which set the
version to 12 if it was otherwise unspecified. But instead of
distinguishing between None and a version, just default to 12.
2023-01-22 18:45:35 -08:00
Eli Schwartz 40315e6ebb
mtest: simplify deprecated access to current loop
These functions constantly want the current asyncio loop, and we run a
function call each time to get it. And the function call is a deprecated
one. Python 3.7 brings the more explicit get_running_loop for use when
we know we're inside one, with the aim of getting rid of get_event_loop
once support for python <3.7 disappears. Meson no longer supports python
<3.7 either.

Switch to the new API, and save the reference for reuse instead of
constantly re-calculating it.
2023-01-04 16:46:52 -05:00
Eli Schwartz ab8081fab6
mtest: clean up asyncio event loop instantiation
Fix a TODO comment about moving to asyncio.run, now that we use
sufficiently new python to do it.

Note that we create an event loop for Windows using the new python
defaults, but in a completely different part of the code from where we
need to use it. Since asyncio.run creates the loop on its own, we need
to set the default policy instead -- which we probably should have done
all along.
2023-01-04 16:46:51 -05:00
Eli Schwartz 56312c0579
mtest: delay creation of asyncio lock until event loop exists
In https://bugs.python.org/issue42392 this stopped implicitly creating
an event loop if none exists. We created it before running _run_tests(),
so it would auto-create an event loop and set the default, which means
we cannot create one explicitly on our own schedule or we end up with
two of them.

Delay this until we actually start the logger. This happens inside the
actual testsuite loop, so it finds the running loop and doesn't create a
new one, even on python <3.10.
2023-01-04 16:46:51 -05:00
Eli Schwartz b7a5c384a1 mtest: handle TAP tests with unknown version.
TAP 14 states:
> Harnesses may treat any TAP stream lacking a version as a failed test.

TAP 13 states:
> In the absence of any version line version 12 is assumed. It is an
> error to explicitly specify any version lower than 13.

So, modern TAP is saying that we should treat a missing version as a
test definition bug, it's no longer okay to use a missing version as
saying "let's use TAP 12". But, we can choose whether to treat it that
way or error out.

Let's do a diagnostic, as we do elsewhere. But allow TAP streams that
aren't well defined, if they used to be well defined (back in TAP 12).
2022-12-17 00:26:38 +02:00
Eli Schwartz d0054f2c3c
mtest: warn on invalid TAP output
In commit a7e458effa we stopped erroring
out on invalid TAP stream contents, with the rationale that "prove" has
become more lenient.

A close reading of the TAP spec indicates why, though:

> A TAP parser is required to not consider an unknown line as an error but
> may optionally choose to capture said line and hand it to the test
> harness, which may have custom behavior attached. This is to allow for
> forward compatability. Test::Harness silently ignores incorrect lines,
> but will become more stringent in the future. TAP::Harness reports TAP
> syntax errors at the end of a test run.

The goal of treating unknown lines as an error in the TAP parser is not
because unknown lines are fine and dandy. The goal is to allow
implementing future versions of TAP, and handling it via existing
parsers. Since Meson has both a parser and a harness, let's do exactly
that -- pass these lines as a distinctive status to the test harness,
then have the test harness complain.
2022-12-05 15:46:46 -05:00
Eli Schwartz 7c9705b801
mtest: early return when parsing blank lines in TAP
Just like comment lines, blank lines do nothing. Before commit
a7e458effa we ended off the parser by
returning if the line was blank, because we needed to in order to catch
non-blank lines as errors. But really, we should have always returned
much earlier and not wasted time attempting to process anything.
2022-12-05 15:46:46 -05:00
Jussi Pakkanen 3ae89a7150 Handle freezing tests. Fixes #10752. 2022-11-21 16:44:24 +02:00
Eli Schwartz 462759dd33
mtest: implement a maxfail option
This allows early exit of the project tests once a certain number of
failures are detected. For example `meson test --maxfail=1` will abort
as soon as a single test fails.

Currently running tests are marked as failed via INTERRUPT.

Resolves #9352
2022-09-23 16:10:32 -04:00
Dylan Baker b8e53ed5ea pylint: enable use-dict-literal 2022-09-19 20:57:52 -04:00
Dylan Baker 798b6c5624 pylint: enable use-list-literal 2022-09-19 20:57:52 -04:00
Andres Freund 628effb369 mtest: Run ninja build.ninja before loading tests
When the build definition has changed since the last ninja invocation meson
test operated on an outdated list of tests and their dependencies. That could
lead to some tests not being run / not all dependencies being built. This was
particularly confusing because the user would see the output of
reconfiguration and rebuilding, and the next mtest invocation would have the
updated configuration.

One issue with this is that that we will now output more useless ninja output
when nothing needs to be done (the "Entering directory" part is not repeated,
as we happen to be in the build directory already). It likely is worth
removing that output, perhaps by testing if anything needs to be done with
ninja -n, but that seems better addressed separately.

Fixes: #9852
2022-09-04 19:05:14 -04:00
Andres Freund f501e3b187 mtest: pull detection of ninja into TestHarness
A later commit will add a second invocation of ninja, no point in having the
detection code twice.

This changes the exit code in case ninja isn't found from 125 to 127, which
seems more appropriate given the justification for returning 125 (to make git
bisect run skip that commit). If we can't find ninja we'll not succeed in
other commits either.
2022-09-04 19:05:14 -04:00
Andres Freund 2096e394fc mtest: Move loading of test data into its own function
A subsequent commit will do a bit more during test data loading, making a
dedicated function seem advisable.

The diff looks a bit odd, using git show --diff-algorithm=patience
will make it clearer.
2022-09-04 19:05:14 -04:00
Dimitri John Ledkov c3cc66a1cc mesonbuild/mtest.py: filter more invalid googletest JUnit4 attributes
googletest 1.12.1 generates new JUnit4 invalid attributes file and
line.

Maybe all gtest "invalid" attributes are actually valid JUnit5
attributes, and maybe schema should be upgraded to JUni5.

Signed-off-by: Dimitri John Ledkov <dimitri.ledkov@canonical.com>
2022-08-12 21:16:07 +03:00
Hemmo Nieminen 952dd7773d mtest: unify parsed and non-parsed output handling
Use the same routines to handle output both when parsing the output and
when not. Also fixes broken stderr handling for parsed tests.
2022-08-07 20:48:42 +03:00
Elliott Sales de Andrade 27626124d0 Inline try_wait_one using asyncio.wait_for
Although the former accepts multiple awaitables, it is only ever called
with a single one, so just use `wait_for` instead.

Additionally, the `try_wait_one` fails in Python 3.11, as
`Process.wait()` returns a coroutine, and `asyncio.wait` only accepts
tasks, so it errors out.
2022-08-01 15:51:16 -04:00
Xavier Claessens 57909b53d6 Improve WINEPATH reduction
- Remove duplicated code in mdevenv.py
- Change the limit to 1024 instead of 2048 which is what has been
  tested.
- Skip shortening if it is already short enough.
- Skip shortening with wine >= 6.4 which does not seems to have that
  limitation any more.
- Downgrade exception to warning in the case WINEPATH cannot be
  shortened under 1024 chars, it is possible that it will still work.
2022-06-17 11:53:38 -04:00
Hemmo Nieminen e8a3f4d38c mtest: do not process zero byte reads in read_decode()
AsyncIO.StreamReader.readuntil() occasionally raises IncompleteRead
exception before a byte of data has been read. Do not process the "read"
data in those cases.
2022-06-09 18:58:33 -04:00
Hemmo Nieminen 657a6eeb81 mtest: enable access to the console logger instance
Store a reference to the console logger instance in a test harness'
member variable to allow accessing it (and its logging utilities) from
any other functions in test harness.

This added functionality will be used in future commits.
2022-06-09 18:58:33 -04:00
Hemmo Nieminen 4304df30c2 mtest: store all test results directly to TestRun
Store return code, test result and additional error directly to the
relevant TestRun instance. This reduces the number of individual
arguments to other relevant functions that need to be passed around and
thus simplifies the code. The test output (and error) were earlier
similarly moved to be stored directly to the TestRun instance for the
same reason.
2022-06-09 18:58:33 -04:00
Hemmo Nieminen 702f3fe15f mtest: store test output directly to a TestRun object
By storing test output directly to the TestRun instance we avoid the
need to pass the outputs around in individual function arguments thus
simplifying the code.

The amount of individual arguments will be further reduced in a
future commit.
2022-06-09 18:58:33 -04:00
Hemmo Nieminen a0eb04788d mtest: print only one empty line before test summary 2022-06-09 18:58:33 -04:00
Hemmo Nieminen 565b12183f mtest: improve text test log formatting
Write additional metadata such as exit details and try to visually
differentiate the tests better from each other in the (textual) test
logs.
2022-06-09 18:58:33 -04:00
Hemmo Nieminen e9f77dc072 mtest: differentiate stdout and stderr in test log text files
Make --no-stdsplit option affect test log text files as well. This means
that if the option --no-stdsplit is used only "output" is seen not only
on the console but in the test log text file as well.
2022-06-09 18:58:33 -04:00
Hemmo Nieminen 5b0629dc11 mtest: print "live" test output when verbose with only 1 test
Since running only one test sort of implies --num-processes=1 the "live"
output of the test should be printed out when --verbose option has been
given and running only a single test.
2022-06-09 18:58:33 -04:00
Hemmo Nieminen d6e1b72db0 mtest: remove unused arguments from read_decode_lines()
The only time the argument would matter (console_mode ==
ConsoleUser.STDOUT) never happens as the only time the function is
ever called is when parsing of the output is needed which in turns
implies that console_mode != ConsoleUser.STDOUT.
2022-06-09 18:58:33 -04:00
Hemmo Nieminen cb0cbb3e5e mtest: introduce get_test_num_prefix() helper function 2022-06-09 18:58:33 -04:00
Hemmo Nieminen e3b4065b0c mtest: split TestRun's get_details() to multiple functions
These new functions will be used individually in later commits.
2022-06-09 18:58:33 -04:00
Hemmo Nieminen 9f26eae541 mtest: make ConsoleLogger's detail property a function
As fetching the returned data is non-trivial (we e.g. iterate over all
subtest results) it is best not to hide that fact from the caller of the
property / function.
2022-06-09 18:58:33 -04:00
Hemmo Nieminen 64d204710f mtest: show "timed out" messages with --print-errorlogs option 2022-06-09 18:58:33 -04:00
Hemmo Nieminen 478ac7f6cc mtest: fix a couple of minor whitespace / typing issues 2022-06-09 18:58:33 -04:00
Paolo Bonzini a7e458effa mtest: ignore invalid input
TAP version 14 introduced subtests, that are supposedly backward compatible
because "TAP13 specifies that non-TAP output should be ignored".  Meson
reported TAP syntax errors based on behavior of "prove" at the time,
but it seems that now "prove" has become a lot more lenient; it even
accepts the following completely bogus input just fine:

---
ok 1
    ok 2
x
1..1
---

So do the same and make Meson's parser accept invalid TAP input silently.

Fixes: #10032
2022-05-24 20:15:34 +03:00
Eli Schwartz 9fe18a63b1 mtest: stop disrespecting the gdb config file
This was added in commit 01be50fdd9 with
zero explanation as a side effect of moving code around. It seems like a
really bad idea and it causes people to view debugging Meson projects on
e.g. debuginfod systems as "painful".
2022-05-17 22:54:53 +03:00
Eli Schwartz 4680c09aac mtest: fix logic bug that broke tests where the cmd is a Windows found program
In this case, the test fname might have an implicit extension and cannot
be found by `os.path.isfile()`.

We cannot use `shutil.which()` to handle platform differences, because
not all test fnames are executable -- for example Java jars.

The test representation does have an "is built" attribute which in
theory should work here, because all built targets definitely have their
full filename known to Meson, but it turns out to be misnamed. Rename it
correctly and add an actual "is built" attribute to check.

Tests which aren't built by Meson can be assumed to exist without
consulting their existence on the filesystem.

Fixes #10027
2022-03-14 01:48:16 +02:00
Jussi Pakkanen 008b1cef50
Merge pull request #10004 from bonzini/mtest-tap-stderr
mtest: print stderr of TAP/Rust tests in verbose/non-parallel mode
2022-02-27 22:12:58 +02:00
Paolo Bonzini 02b739feae mtest: refactor common condition into a property of TestRun
For a test to be displayed to stdout without buffering, it has to be
1) in verbose mode 2) not executed in parallel with others
3) not parsed, i.e. not TAP or Rust.  Include these three
conditions in a new property of stdout and use it in the
three places where it matters: when printing the initial
and final delimiters of the output, and when deciding the
console mode to use.

Suggested-by: Jussi Pakkanen <jpakkane@gmail.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2022-02-20 14:09:48 +01:00
Eli Schwartz c85f7a39a8 mtest: raise informative error message when test program doesn't exist
If --no-rebuild is used, the test program might not exist, spawning a
FileNotFoundError inside a long traceback rooted in subprocess.Popen
trying to run that test program. Current versions of Meson even say it's
an "unhandled python exception".

But we can do one better and actually tell the user what is wrong, why,
and what to do to fix it. And we can do so before getting waist deep in
partially running tests.

Fixes #10006
2022-02-20 14:21:31 +02:00
Paolo Bonzini c3f145ca2b mtest: print stderr of TAP/Rust tests in verbose/non-parallel mode
Verbose, non-parallel tests generally print their output as they run, rather than
after they finish.  This however is not the case if stdout of the test is parsed
as is the case for TAP and Rust tests.  In this case, the output during the run
is the list of the subtests, but stderr still has to be printed after the test
finishes.
2022-02-20 09:07:40 +01:00
Paolo Bonzini 3f3439522c mtest: support for forcibly verbose logging of some tests
Store in TestSerialisation whether a particular test must always be logged
verbosely.  This is particularly useful for long-running tests or when a
single Meson test() is wrapping an external test harness.  In this case,
TAP can be used by the external harness and Meson will log each subtest as
it runs.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2022-02-01 09:05:26 +01:00
William Toohey bad383f6b3 Activate VS env when running `meson test` 2021-12-11 21:26:36 +02:00
Eli Schwartz 5b7d4f8bd3
rename exe_runner to exe_wrapper everywhere
I don't understand the purpose of this confusing API naming split.
2021-12-05 11:39:20 -05:00
Paolo Bonzini 83f8b7c1b1 mtest: add an ASCII-only version of the spinner
While the horizontal line and the other pictograms in mtest have an ASCII-only
version, the spinner does not.  This causes mtest to fail with a
UnicodeEncodeError exception on non-Unicode locales.

Fixes: #9538
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2021-11-16 01:54:33 +02:00
Paolo Bonzini a077aaad99 mtest: accept very long lines
Unless parsing TAP output, there is no strict requirement for
"meson test" to process test output one line at a time; it simply
looks nicer to not print a partial line if it can be avoided.

However, in the case of extremely long lines StreamReader.readline
can fail with a ValueError.  Use readuntil('\n') instead and
just process whatever pieces of the line it returns.

Fixes: #8591
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2021-10-28 15:32:46 -04:00
Eli Schwartz 8947352889 fix various flake8 whitespace errors 2021-10-27 09:51:52 -04:00
Paolo Bonzini 8945c53711 mtest: limit "magic" CTRL+C behavior to process group leaders
If meson is not a process group leader, a SIGINT will be delivered also to
its parent process (and possibly other processes).  The parent process then
will probably exit and mtest will continue running in the background, without
any way to interrupt the run completely.

To fix this, treat SIGINT and SIGTERM the same way unless mtest is a
process group leader.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2021-10-18 15:16:10 -04:00
Eli Schwartz b2ddda7013
fix incorrect porting from % formatting to .format method
(var,) is the correct way to pass values to a percent formatted string,
but not to .format so we would end up printing something like:

unexpected input at line (4,)

Upgrade to an f-string and insert the correct value correctly.
2021-10-04 16:29:30 -04:00
Eli Schwartz e8a85fa8a2
various python neatness cleanups
All changes were created by running

"pyupgrade --py3-only"

and committing the results. Although this has been performed in the
past, newer versions of pyupgrade can automatically catch more
opportunities, notably list comprehensions can use generators instead,
in the following cases:
- unpacking into function arguments as function(*generator)
- unpacking into assignments of the form x, y = generator
- as the argument to some builtin functions such as min/max/sorted

Also catch a few creeping cases of new code added using older styles.
2021-10-04 16:29:30 -04:00
Paolo Bonzini 65b144bc85 Revert "mtest: fix test output issues (in console)"
This reverts commit 5fcb0e6525.
The commit is a massive change that should have been split in
separate pieces, and it also removes a few features:

* in verbose mode, subtests are not printed as they happen

* in non-verbose mode the progress report does not include the
number of subtests that have been run

* in non-parallel mode, output is batched rather than printed as
it happens

Furthermore, none of these changes are not documented in the release
notes.  Revert so that each proposal can be tested, evaluated and
documented individually.
2021-09-29 21:47:31 +03:00
Hemmo Nieminen 5fcb0e6525 mtest: fix test output issues (in console)
This change set aims to fix various "issues" seen with the current
implementation. The changes can be summarized with the following list:

* Replace emojis and spinners with multiline status displaying the name
  and running time of each currently running test.
* The test output (especially in verbose mode or when multiple failing
  tests' output gets printed out) can get confusing. Try to make the
  output easier to read and grasp. Most notable change here is the
  addition of the test number to the beginning of each printed line.
* Print exit details (i.e. exit code) of the test in verbose mode.
* Try to make the verbose "live" output from tests to match the look and
  feel of otherwise produced (verbose) test output.
2021-09-25 13:42:45 +03:00
Dylan Baker e049494890 mtest: Allow gtest protocol test to fail more gracefully
Currently, if the test fails to produce XML (or valid XML) then the test
fails with a backtrace. It's actually pretty easy to get into this
situation, a total failure of the test will result in no XML being
written (this can happen, for example, if rpaths to gtest are not
correctly set up). If we can't read the test, go ahead and complete
using `TestRunExitCode.complete()`, which will fail for the bad exit
code.
2021-09-20 19:38:42 -07:00
Paolo Bonzini 5215f4fa98 cleanup self.options.wd
It is never None and always an absolute path
2021-07-07 18:00:37 +02:00
Paolo Bonzini b44a51d0fd resolve symlinks passed to -C
"meson setup" is resolving symlinks for the build directory in
validate_core_dirs.  For consistency with it, do the same when
the build directory is passed via -C to devenv, dist, init, install
and test.

This ensures for example that the path to test dependencies is
computed correctly in "meson test".

Fixes: #8765
2021-07-07 18:00:37 +02:00
Daniel Mensinger 3e396b3782
fix: Always explicitly set encoding for text files (fixes #8263) 2021-06-29 11:28:08 +02:00
Paolo Bonzini ea48edbb0f mtest: timeout if the write side of pipes does not close
If a test program forks a child, the pipes might remain open and
"await stdo_task"/"await stde_task" will never complete in
SingleTestRunner._run_cmd().

Instead, catch them in TestSubprocess.wait() so that the whole
process group is killed.

Fixes: #8533
Reported-by: Bastien Nocera <hadess@hadess.net>
2021-03-23 00:07:14 +02:00
Paolo Bonzini 13d3fbbf3e mtest: remove pointless try/except from try_wait_one
asyncio.wait does not return an asyncio.TimeoutError, so there is no
exception to catch.
2021-03-23 00:07:14 +02:00
Dylan Baker 40e3577a65 split program related classes and functions out of dependencies
Dependencies is already a large and complicated package without adding
programs to the list. This also allows us to untangle a bit of spaghetti
that we have.
2021-03-19 08:47:10 -04:00
Eli Schwartz 6a0fabc647
mass rewrite of string formatting to use f-strings everywhere
performed by running "pyupgrade --py36-plus" and committing the results
2021-03-04 17:16:11 -05:00
Eli Schwartz 4340bf34fa
various python neatness cleanups
All changes were created by running

"pyupgrade --py3-only --keep-percent-format"

and committing the results. I have not touched string formatting for
now.

- use set literals
- simplify .format() parameter naming
- remove __future__
- remove default "r" mode for open()
- use OSError rather than compatibility aliases
- remove stray parentheses in function(generator) scopes
2021-03-04 17:11:26 -05:00
Paolo Bonzini 0c663d056a mtest: create separate runners for multiple repeats
Reusing the runners for multiple repeats of the test run gets in the
way of the progress report, which stores runners in an OrderedSet.
Instead, create a separate SingleTestRunner object for each repeat.

While at it, fix the "duplicate suite" assertion as it can fire
with TAP tests and --repeat=N.

Fixes: #8405
2021-03-02 00:57:57 +02:00
Luke Drummond 79f7328d6a [TAP] Fix TAP parser when test exits with status
Some time between 0.56 and 0.57 the TAP parser broke when a test exits
with a nonzero status.
The TAP protocol does not specify this behaviour - giving latitude to
implementers, and meson's previous behaviour was to report the exit
status gracefully.

This patch restores the old behaviour and adds a regression test
2021-02-19 17:17:20 +02:00
Paolo Bonzini 2b48d75c7e mtest: use / as path separator for ninja targets
os.path.relpath(f, wd) returns path with \ seperator on Windows, but ninja
targets always uses / separator.

See for example https://gitlab.freedesktop.org/ocrete/libnice/-/jobs/7348274.

Analyzed-by: Xavier Claessens <xavier.claessens@collabora.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2021-02-17 12:10:05 -05:00
Paolo Bonzini b1efd03619 mtest: include classname in <testcase> JUnit element
It looks like GitLab ignores the suite name and actually uses
the classname.  Adjust the output accordingly.

Fixes: #8316
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2021-02-10 15:01:57 +01:00
Paolo Bonzini 6c40b134df mtest: cancel stdout/stderr tasks on timeout
Avoid that the tasks linger and SingleTestRunner.run() never terminates.

In order to do this, we need read_decode() and read_decode_lines() to be
cancellable, and to handle the CancelledError gracefully while returning
the output they have collected so far.

For read_decode(), this means always operating on a line-by-line basis,
even if console_mode is not ConsoleUser.STDOUT.  For read_decode_lines(),
instead, we cannot return an iterator.  Rather, read_decode_lines()
returns the output directly (similar to read_decode) and communication
with the parser is mediated by an asyncio.Queue.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2021-02-10 12:01:55 +01:00
Paolo Bonzini c6b135c1f9 mtest: clean up conditions on whether tests are run in parallel
This makes non-parallel tests emit their output on the fly,
similar to ninja console jobs.  It also cleans up the code
a bit, avoiding the repetition of "self.options.num_processes"
tests.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2021-02-10 10:58:21 +01:00
Paolo Bonzini 711d9feb4e mtest: fix nits in printing test stdout
- Ensure the output is terminated with a \n even if the test does not
  include one.

- Ensure that stdout is flushed for each reported result

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2021-02-10 10:57:55 +01:00
Paolo Bonzini 3506d8daf2 mtest: TestSetup can have [] as an exe_wrapper
Fix "meson test --wrapper foo --setup bar", it should work just fine
if the setup does not define a wrapper.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2021-02-09 18:51:05 +01:00
Paolo Bonzini b1a9578091 mtest: run the test output parser as a task
Start the parsing of the output early; this avoids a deadlock
if the test writes to stdout but no one reads from it.  It
also reports TAP or Rust subtest results as they happen,
which was the intention all along.

While at it, use a consistent naming conventions for coroutines
vs tasks.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2021-02-09 18:50:21 +01:00
Paolo Bonzini 8b94aa578a mtest: hide infinite timeout from the progress report
Avoid printing something like "30/-1s" when tests are run without
a timeout or with --timeout-multiplier 0.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2021-02-09 18:42:26 +01:00
Paolo Bonzini c7c2bc8db1 interpreter, mtest: introduce add_test_setup(exclude_suites: ...)
This new keyword argument makes it possible to run specific
test setups only on a subset of the tests.  For example, to
mark some tests as slow and avoid running them by default:

    add_test_setup('quick', exclude_suites: ['slow'], is_default: true)
    add_test_setup('slow')

It will then be possible to run the slow tests with either
`meson test --setup slow` or `meson test --suite slow`.
2021-02-02 11:23:33 +01:00
Paolo Bonzini e7b587c81f mtest: extract get_test_setup, rename merge_suite_options
merge_suite_options is really about test setups, so rename
accordingly.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2021-02-02 11:22:58 +01:00
Paolo Bonzini 26a3148e19 mtest: load build data early
This will be needed to exclude testsuites from test setups (which
are stored in the build data).  While at it, since a chdir is
needed simplify a bit the loading of tests and benchmarks.
2021-02-02 11:21:11 +01:00
Paolo Bonzini 0aeb2074b9 mtest: compute logfile name early
Do this before overriding self.options.setup with the default setup.
2021-02-02 11:20:49 +01:00
Paolo Bonzini 203f368949 mtest: remove useless argument 2021-02-02 10:06:55 +01:00
Jussi Pakkanen f0fbb31ccf
Merge pull request #8200 from bonzini/mtest-asyncio-logs
mtest: improvements to logging
2021-01-30 09:52:43 +00:00
Xavier Claessens e4137ae3ec test: Make timeout <= 0 infinite duraction 2021-01-27 08:26:20 -05:00
Paolo Bonzini 12b3d05d1e mtest: log individual TAP subtests 2021-01-22 12:18:59 +01:00
Paolo Bonzini 7b02abeac6 mtest: infrastructure to print subtest results 2021-01-22 12:18:59 +01:00
Paolo Bonzini bb9d8b5b80 mtest: move --print-errorlogs output during the test run
Print the (shortened) output of the failed tests as they happen.
If neither --verbose nor --print-errorlogs was specified, omit the
summary of failures, because it is pretty much the same as the earlier
output of "meson test".
2021-01-22 12:18:59 +01:00
Paolo Bonzini 4d6a0cc174 mtest: log test start in verbose mode
In non-parallel verbose mode the output of the test/benchmark
is not buffered, therefore the command line is only printed by
ConsoleLogger for failing tests and only after the test has run.

Verbose mode is designed mostly for CI systems, where output must
be human readable but is generally consumed from a browser with "Find"
commands rather than from a terminal.  With this usecase in mind, it
is better to provide as much detail as possible, so add more output
and just tell the user which tests have started.  Do so, using the
recently introduced TestResult.RUNNING state.
2021-01-22 12:18:59 +01:00
Paolo Bonzini 959e4b3a5e mtest: call TestLogger.start_test when TestRun is in the RUNNING state 2021-01-22 12:18:59 +01:00
Paolo Bonzini 289cc2e2c5 mtest: use buffered stdout/stderr in parallel mode
Similar to ninja, buffer stdout/stderr even in verbose mode if more than one test is
being run in parallel.
2021-01-22 12:18:59 +01:00
Paolo Bonzini a0da710172 mtest: quote environment variable values and command line arguments 2021-01-22 12:18:59 +01:00
Paolo Bonzini 04bab9d595 mtest: include full environment in the TestRun object
Ensure that all the required modifications are included in the logs.
This makes it possible for users to cut-and-paste from the logs when
trying to reproduce failures outside Meson.
2021-01-22 12:18:59 +01:00
Paolo Bonzini 111f22a4f8 mtest: make log output more suitable for console
Right now the same code is used to print the logs for both the console
and the text log.  Differentiating them lets the important bits of
the console output stand out, and makes the console output a bit more
readable.
2021-01-22 12:18:59 +01:00
Paolo Bonzini a118cae9d2 mtest: small refactoring of log printing
Start moving console-specific code to ConsoleLogger, as well
as moving code out of get_log().
2021-01-22 12:18:59 +01:00
Paolo Bonzini 2386f336f1 mtest: log in verbose mode, but not in gdb mode
This is now possible because all stdout/stderr goes through asyncio pipes.
However, logs make little sense in gdb mode.
2021-01-22 12:18:59 +01:00
Paolo Bonzini 2e982a3864 mtest: collect stdout/stderr even in verbose mode
Using verbose mode dropped stdout/stderr from the logs, because
it was not captured.

Now that we can easily stick code in the middle of the reading of
stdout/stderr, use that to print stdout and stderr on the fly
while also capturing them for the logs.  The output is line-buffered.

As a side effect, this also fixes a possible deadlock due to
not using ensure_future around stdo_task and stde_task.  In
particular:

- the stdo_task coroutine would not terminate until the test closed
stdo_task

- the stde_task coroutine would not start until the stdo_task
coroutine finished

Therefore, the test could get stuck waiting for its parent to
read the contents of stderr, but that would not happen because
Meson was still in the stdo_task coroutine.
2021-01-20 15:06:59 +01:00
Paolo Bonzini e7c8555575 mtest: move I/O handling to TestSubprocess
Move the logic to start the read/decode
tasks to TestSubprocess and keep SingleTestRunner simple.

The lines() inner function is tweaked to produce stdout as a future.
This removes the nonlocal access (which is not possible anymore
when the code is moved out of _run_cmd), and also lets _run_cmd
use "await stdo_task" for both parsed and unparsed output.
2021-01-15 15:58:53 +01:00
Paolo Bonzini 401464c61a mtest: tweak the gathering of stdo_task/stde_task results
After the next patch, we will need to complete parse_task before
stdo_task (because parse_task will not set the "stdo" variable
anymore but it will still collect stdout just like now).  Do
the change now to isolate the more complicated changes.
2021-01-15 10:03:54 +01:00
Paolo Bonzini 90ea0dc583 mtest: disable the progress report in gdb mode
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2021-01-15 10:03:54 +01:00
Paolo Bonzini c1c1408fae mtest: introduce ConsoleUser
This new enum can be used by TestSubprocess and TestHarness to
understand (at a higher level) how SingleTestRunner sets up
stdout/stderr redirection.
2021-01-15 10:03:54 +01:00
Paolo Bonzini 1f52e2fa45 mtest: turn TestRun into a hierarchy
Make SimpleTestRunner oblivious of the various test protocols.  All
the different "complete_*" and "parse_*" methods move to the
subclasses of TestRun.
2021-01-15 10:03:54 +01:00
Paolo Bonzini 9e42048e3c mtest: pass command line to TestRun.start
The command line is already available when the test is started.  Pass it to
TestRun.start instead of TestRun.complete*.
2021-01-15 10:03:54 +01:00
Paolo Bonzini 1f5634f15d mtest: add complete_skip to TestRun 2021-01-15 10:03:54 +01:00
Paolo Bonzini c544529faa mtest: simplify complete_exitcode
There is no need anymore to pass the JUnit XML down to complete_exitcode.  Just
set self.junit in complete_gtest instead.
2021-01-15 10:03:54 +01:00
Paolo Bonzini 51e1f01c85 mtest: store the environment in the TestRun
The test_env was lost from the TestRun object in commit
30741a0f2 ("mtest: create TestRun object early on").  Fix
things.
2021-01-15 10:03:54 +01:00
Paolo Bonzini 458c3125e0 mtest: do not print time out message twice
Rebase mistake in "mtest: move timeout message to ConsoleLogger".
2021-01-15 10:03:54 +01:00